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();
}
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);
}
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;
}
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();
}
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();
}
Aggregations