Search in sources :

Example 81 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class AuroraLauncherTest method testLaunch.

@Test
public void testLaunch() throws Exception {
    Config config = Config.newBuilder().build();
    AuroraLauncher launcher = Mockito.spy(AuroraLauncher.class);
    launcher.initialize(config, config);
    LauncherUtils mockLauncherUtils = Mockito.mock(LauncherUtils.class);
    PowerMockito.spy(LauncherUtils.class);
    PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
    // Failed to schedule
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(false);
    Assert.assertFalse(launcher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(mockLauncherUtils).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    // Happy path
    Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(true);
    Assert.assertTrue(launcher.launch(Mockito.mock(PackingPlan.class)));
    Mockito.verify(mockLauncherUtils, Mockito.times(2)).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
    launcher.close();
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 82 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class SlurmLauncher method launch.

@Override
public boolean launch(PackingPlan packing) {
    LOG.log(Level.FINE, "Launching topology for local cluster {0}", SlurmContext.cluster(config));
    // this working directory is a shared directory among the nodes
    if (!setupWorkingDirectory()) {
        LOG.log(Level.SEVERE, "Failed to download the core and topology packages");
        return false;
    }
    LauncherUtils launcherUtils = LauncherUtils.getInstance();
    Config ytruntime = launcherUtils.createConfigWithPackingDetails(runtime, packing);
    return launcherUtils.onScheduleAsLibrary(config, ytruntime, new SlurmScheduler(topologyWorkingDirectory), packing);
}
Also used : Config(com.twitter.heron.spi.common.Config) LauncherUtils(com.twitter.heron.scheduler.utils.LauncherUtils)

Example 83 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class LocalFileSystemStateManagerTest method initSpyManager.

private static LocalFileSystemStateManager initSpyManager(String rootPath, boolean initTree) {
    Config config = Config.newBuilder().put(Key.STATEMGR_ROOT_PATH, rootPath).put(LocalFileSystemKey.IS_INITIALIZE_FILE_TREE.value(), initTree).build();
    LocalFileSystemStateManager manager = spy(new LocalFileSystemStateManager());
    manager.initialize(config);
    return manager;
}
Also used : Config(com.twitter.heron.spi.common.Config)

Example 84 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class FileResource method uploadFile.

/**
 * Endpoints for artifacts upload
 */
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
    Config config = createConfig();
    if (uploadedInputStream == null) {
        String msg = "input stream is null";
        LOG.error(msg);
        return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity(Utils.createMessage(msg)).build();
    }
    if (fileDetail == null) {
        String msg = "form data content disposition is null";
        LOG.error(msg);
        return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity(Utils.createMessage(msg)).build();
    }
    String uploadDir = config.getStringValue(FILE_SYSTEM_DIRECTORY);
    final String fileName = UUID.randomUUID() + "-" + fileDetail.getFileName();
    final String uploadedFileLocation = uploadDir + "/" + fileName;
    // save it
    try {
        FileHelper.writeToFile(uploadedInputStream, uploadedFileLocation);
    } catch (IOException e) {
        LOG.error("error uploading file {}", fileDetail.getFileName(), e);
        return Response.serverError().type(MediaType.APPLICATION_JSON).entity(Utils.createMessage(e.getMessage())).build();
    }
    String uri = String.format("http://%s:%s/api/v1/file/download/%s", getHostNameOrIP(), getPort(), fileName);
    return Response.status(Response.Status.OK).entity(uri).build();
}
Also used : Config(com.twitter.heron.spi.common.Config) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 85 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class TopologyResource method updateComponentParallelism.

protected Response updateComponentParallelism(String cluster, String role, String environment, String name, MultivaluedMap<String, String> params, List<String> components) {
    final List<Pair<String, Object>> keyValues = new ArrayList<>(Arrays.asList(Pair.create(Key.CLUSTER.value(), cluster), Pair.create(Key.ROLE.value(), role), Pair.create(Key.ENVIRON.value(), environment), Pair.create(Key.TOPOLOGY_NAME.value(), name), Pair.create(Keys.PARAM_COMPONENT_PARALLELISM, String.join(",", components))));
    // has a dry run been requested?
    if (params.containsKey(PARAM_DRY_RUN)) {
        keyValues.add(Pair.create(Key.DRY_RUN.value(), Boolean.TRUE));
    }
    final Set<Pair<String, Object>> overrides = getUpdateOverrides(params);
    // apply overrides if they exists
    if (!overrides.isEmpty()) {
        keyValues.addAll(overrides);
    }
    final Config config = createConfig(keyValues);
    getActionFactory().createRuntimeAction(config, ActionType.UPDATE).execute();
    return Response.ok().type(MediaType.APPLICATION_JSON).entity(Utils.createMessage(String.format("%s updated", name))).build();
}
Also used : Config(com.twitter.heron.spi.common.Config) ArrayList(java.util.ArrayList) Pair(com.twitter.heron.common.basics.Pair)

Aggregations

Config (com.twitter.heron.spi.common.Config)211 Test (org.junit.Test)125 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)60 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)53 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)43 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)35 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)19 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)18 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)17 HashMap (java.util.HashMap)16 Before (org.junit.Before)16 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)14 IOException (java.io.IOException)13 Resource (com.twitter.heron.spi.packing.Resource)12 URI (java.net.URI)12 HashSet (java.util.HashSet)11 CommandLine (org.apache.commons.cli.CommandLine)10 ByteAmount (com.twitter.heron.common.basics.ByteAmount)9 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)9 File (java.io.File)9