use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class SubmitterMainTest method testValidateSubmit.
@Test
public void testValidateSubmit() throws Exception {
SubmitterMain submitterMain = new SubmitterMain(config, topology);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
// Topology is not running
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(null);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(false);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class SubmitterMainTest method testValidateSubmitAlreadyRunning.
@Test(expected = TopologySubmissionException.class)
public void testValidateSubmitAlreadyRunning() throws Exception {
SubmitterMain submitterMain = new SubmitterMain(config, topology);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
// Topology is running
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class UpdateTopologyManagerTest method mockStateManager.
private static SchedulerStateManagerAdaptor mockStateManager(TopologyAPI.Topology topology, PackingPlans.PackingPlan packingPlan, Lock lock) {
SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
when(stateManager.getPhysicalPlan(TOPOLOGY_NAME)).thenReturn(PhysicalPlans.PhysicalPlan.getDefaultInstance());
when(stateManager.getTopology(TOPOLOGY_NAME)).thenReturn(topology);
when(stateManager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(packingPlan);
when(stateManager.getLock(eq(TOPOLOGY_NAME), eq(IStateManager.LockName.UPDATE_TOPOLOGY))).thenReturn(lock);
return stateManager;
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class UpdateTopologyManagerTest method testLockTaken.
@Test(expected = ConcurrentModificationException.class)
public void testLockTaken() throws Exception {
SchedulerStateManagerAdaptor mockStateMgr = mockStateManager(testTopology, this.currentProtoPlan, mockLock(false));
UpdateTopologyManager spyUpdateManager = spyUpdateManager(mockStateMgr, mock(IScalable.class), testTopology);
spyUpdateManager.updateTopology(currentProtoPlan, proposedProtoPlan);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor 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);
}
}
Aggregations