use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method testKillTopologyHandlerFailCleanState.
@Test(expected = TopologyRuntimeManagementException.class)
public void testKillTopologyHandlerFailCleanState() {
Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).build();
ISchedulerClient client = mock(ISchedulerClient.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.KILL, client);
// Failed to invoke client's killTopology
when(client.killTopology(killTopologyRequest)).thenReturn(true);
doThrow(new TopologyRuntimeManagementException("")).when(runner).cleanState(eq(TOPOLOGY_NAME), any(SchedulerStateManagerAdaptor.class));
try {
runner.killTopologyHandler(TOPOLOGY_NAME);
} finally {
verify(client).killTopology(killTopologyRequest);
}
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method testRestartTopologyHandlerFailRestartTopology.
@Test(expected = TopologyRuntimeManagementException.class)
public void testRestartTopologyHandlerFailRestartTopology() {
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.RESTART, client);
// Restart container 1, not containing TMaster
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(1).build();
when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(1);
when(client.restartTopology(restartTopologyRequest)).thenReturn(false);
try {
runner.restartTopologyHandler(TOPOLOGY_NAME);
} finally {
verify(adaptor, never()).deleteTMasterLocation(TOPOLOGY_NAME);
}
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method testKillTopologyHandlerOk.
@Test
public void testKillTopologyHandlerOk() {
Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).build();
ISchedulerClient client = mock(ISchedulerClient.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.KILL, client);
when(client.killTopology(killTopologyRequest)).thenReturn(true);
// Success case
doNothing().when(runner).cleanState(eq(TOPOLOGY_NAME), any(SchedulerStateManagerAdaptor.class));
runner.killTopologyHandler(TOPOLOGY_NAME);
verify(client).killTopology(killTopologyRequest);
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerMain method manageTopology.
/**
* Manager a topology
* 1. Instantiate necessary resources
* 2. Valid whether the runtime management is legal
* 3. Complete the runtime management for a specific command
*
*/
public void manageTopology() throws TopologyRuntimeManagementException, TMasterException, PackingException {
String topologyName = Context.topologyName(config);
// 1. Do prepare work
// create an instance of state manager
String statemgrClass = Context.stateManagerClass(config);
IStateManager statemgr;
try {
statemgr = ReflectionUtils.newInstance(statemgrClass);
} catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
throw new TopologyRuntimeManagementException(String.format("Failed to instantiate state manager class '%s'", statemgrClass), e);
}
// Put it in a try block so that we can always clean resources
try {
// initialize the statemgr
statemgr.initialize(config);
// TODO(mfu): timeout should read from config
SchedulerStateManagerAdaptor adaptor = new SchedulerStateManagerAdaptor(statemgr, 5000);
validateRuntimeManage(adaptor, topologyName);
// 2. Try to manage topology if valid
// invoke the appropriate command to manage the topology
LOG.log(Level.FINE, "Topology: {0} to be {1}ed", new Object[] { topologyName, command });
// build the runtime config
Config runtime = Config.newBuilder().put(Key.TOPOLOGY_NAME, Context.topologyName(config)).put(Key.SCHEDULER_STATE_MANAGER_ADAPTOR, adaptor).build();
// Create a ISchedulerClient basing on the config
ISchedulerClient schedulerClient = getSchedulerClient(runtime);
callRuntimeManagerRunner(runtime, schedulerClient);
} finally {
// 3. Do post work basing on the result
// Currently nothing to do here
// 4. Close the resources
SysUtils.closeIgnoringExceptions(statemgr);
}
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method testRestartTopologyHandlerSuccRestartTopology.
@Test
public void testRestartTopologyHandlerSuccRestartTopology() {
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.RESTART, client);
// Restart container 1, not containing TMaster
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(1).build();
when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(1);
// Success case
when(client.restartTopology(restartTopologyRequest)).thenReturn(true);
runner.restartTopologyHandler(TOPOLOGY_NAME);
// Should not invoke DeleteTMasterLocation
verify(adaptor, never()).deleteTMasterLocation(TOPOLOGY_NAME);
}
Aggregations