use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientFail.
@Test(expected = SchedulerException.class)
public void testGetServiceSchedulerClientFail() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
SchedulerStateManagerAdaptor statemgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
// Get a ServiceSchedulerClient
Mockito.when(config.getBooleanValue(Key.SCHEDULER_IS_SERVICE)).thenReturn(true);
// Mock the runtime object
Mockito.when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(statemgr);
Mockito.when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
// Failed to getSchedulerLocation
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(null);
try {
new SchedulerClientFactory(config, runtime).getSchedulerClient();
} finally {
Mockito.verify(statemgr).getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME));
}
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class LauncherUtilsTest method constructsConfigWithTopologyInfo.
@Test
public void constructsConfigWithTopologyInfo() throws Exception {
TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
PowerMockito.when(mockTopology.getId()).thenReturn("testTopologyId");
PowerMockito.when(mockTopology.getName()).thenReturn("testTopologyName");
SchedulerStateManagerAdaptor mockStMgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
PowerMockito.spy(TopologyUtils.class);
PowerMockito.doReturn(456).when(TopologyUtils.class, "getNumContainers", mockTopology);
Config runtime = Config.newBuilder().putAll(LauncherUtils.getInstance().createPrimaryRuntime(mockTopology)).putAll(LauncherUtils.getInstance().createAdaptorRuntime(mockStMgr)).build();
Assert.assertEquals("testTopologyId", Runtime.topologyId(runtime));
Assert.assertEquals("testTopologyName", Runtime.topologyName(runtime));
Assert.assertEquals(mockTopology, Runtime.topology(runtime));
Assert.assertEquals(mockStMgr, Runtime.schedulerStateManagerAdaptor(runtime));
Assert.assertEquals(456 + 1, Runtime.numContainers(runtime).longValue());
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class AuroraSchedulerTest method testOnSchedule.
/**
* Tests that we can schedule
*/
@Test
public void testOnSchedule() throws Exception {
AuroraController controller = Mockito.mock(AuroraController.class);
doReturn(controller).when(scheduler).getController();
SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
Config runtime = Mockito.mock(Config.class);
when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(stateManager);
when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
Config mConfig = Mockito.mock(Config.class);
PowerMockito.mockStatic(Config.class);
when(Config.toClusterMode(mConfig)).thenReturn(mConfig);
when(mConfig.getStringValue(eq(AuroraContext.JOB_TEMPLATE), anyString())).thenReturn(AURORA_PATH);
scheduler.initialize(mConfig, runtime);
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan plan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
assertTrue(plan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(plan));
// Construct valid PackingPlan
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(PackingTestUtils.testContainerPlan(CONTAINER_ID));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Failed to create job via controller
doReturn(false).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
doReturn(true).when(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
Assert.assertFalse(scheduler.onSchedule(validPlan));
Mockito.verify(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
Mockito.verify(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
// Happy path
doReturn(true).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
assertTrue(scheduler.onSchedule(validPlan));
Mockito.verify(controller, Mockito.times(2)).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
Mockito.verify(stateManager, Mockito.times(2)).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class UpdateTopologyManagerTest method requestsToAddAndRemoveContainers.
/**
* Test scalable scheduler invocation
*/
@Test
@PrepareForTest(TMasterUtils.class)
public void requestsToAddAndRemoveContainers() throws Exception {
Lock lock = mockLock(true);
SchedulerStateManagerAdaptor mockStateMgr = mockStateManager(testTopology, this.currentProtoPlan, lock);
IScalable mockScheduler = mock(IScalable.class);
UpdateTopologyManager spyUpdateManager = spyUpdateManager(mockStateMgr, mockScheduler, testTopology);
PowerMockito.spy(TMasterUtils.class);
PowerMockito.doNothing().when(TMasterUtils.class, "sendToTMaster", any(String.class), eq(TOPOLOGY_NAME), eq(mockStateMgr), any(NetworkUtils.TunnelConfig.class));
spyUpdateManager.updateTopology(currentProtoPlan, proposedProtoPlan);
verify(spyUpdateManager).deactivateTopology(eq(mockStateMgr), eq(testTopology));
verify(spyUpdateManager).reactivateTopology(eq(mockStateMgr), eq(testTopology), eq(2));
verify(mockScheduler).addContainers(expectedContainersToAdd);
verify(mockScheduler).removeContainers(expectedContainersToRemove);
verify(lock).tryLock(any(Long.class), any(TimeUnit.class));
verify(lock).unlock();
PowerMockito.verifyStatic(times(1));
TMasterUtils.transitionTopologyState(eq(TOPOLOGY_NAME), eq(TMasterUtils.TMasterCommand.DEACTIVATE), eq(mockStateMgr), eq(TopologyAPI.TopologyState.RUNNING), eq(TopologyAPI.TopologyState.PAUSED), any(NetworkUtils.TunnelConfig.class));
PowerMockito.verifyStatic(times(1));
TMasterUtils.transitionTopologyState(eq(TOPOLOGY_NAME), eq(TMasterUtils.TMasterCommand.ACTIVATE), eq(mockStateMgr), eq(TopologyAPI.TopologyState.PAUSED), eq(TopologyAPI.TopologyState.RUNNING), any(NetworkUtils.TunnelConfig.class));
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class LaunchRunner method call.
/**
* Call launcher to launch topology
*
* @throws LauncherException
* @throws PackingException
* @throws SubmitDryRunResponse
*/
public void call() throws LauncherException, PackingException, SubmitDryRunResponse {
SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
TopologyAPI.Topology topology = Runtime.topology(runtime);
String topologyName = Context.topologyName(config);
PackingPlan packedPlan = LauncherUtils.getInstance().createPackingPlan(config, runtime);
if (Context.dryRun(config)) {
throw new SubmitDryRunResponse(topology, config, packedPlan);
}
// initialize the launcher
launcher.initialize(config, runtime);
// Set topology def first since we determine whether a topology is running
// by checking the existence of topology def
// store the trimmed topology definition into the state manager
// TODO(rli): log-and-false anti-pattern is too nested on this path. will not refactor
Boolean result = statemgr.setTopology(trimTopology(topology), topologyName);
if (result == null || !result) {
throw new LauncherException(String.format("Failed to set topology definition for topology '%s'", topologyName));
}
result = statemgr.setPackingPlan(createPackingPlan(packedPlan), topologyName);
if (result == null || !result) {
statemgr.deleteTopology(topologyName);
throw new LauncherException(String.format("Failed to set packing plan for topology '%s'", topologyName));
}
// store the execution state into the state manager
ExecutionEnvironment.ExecutionState executionState = createExecutionState();
result = statemgr.setExecutionState(executionState, topologyName);
if (result == null || !result) {
statemgr.deletePackingPlan(topologyName);
statemgr.deleteTopology(topologyName);
throw new LauncherException(String.format("Failed to set execution state for topology '%s'", topologyName));
}
// launch the topology, clear the state if it fails
if (!launcher.launch(packedPlan)) {
statemgr.deleteExecutionState(topologyName);
statemgr.deletePackingPlan(topologyName);
statemgr.deleteTopology(topologyName);
throw new LauncherException(String.format("Failed to launch topology '%s'", topologyName));
}
}
Aggregations