use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class RuntimeManagerMainTest method testValidateRuntimeManageNoExecState.
@Test(expected = TopologyRuntimeManagementException.class)
public void testValidateRuntimeManageNoExecState() {
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, MOCK_COMMAND);
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
when(adaptor.getExecutionState(eq(TOPOLOGY_NAME))).thenReturn(null);
runtimeManagerMain.validateRuntimeManage(adaptor, TOPOLOGY_NAME);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class RuntimeManagerRunnerTest method doUpdateTopologyHandlerTest.
private void doUpdateTopologyHandlerTest(String newParallelism, boolean expectedResult) {
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
PowerMockito.mockStatic(Runtime.class);
PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
RoundRobinPacking packing = new RoundRobinPacking();
PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
PackingPlans.PackingPlan proposedPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
Map<String, Integer> changeRequests = runner.parseNewParallelismParam(newParallelism);
when(manager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(currentPlan);
doReturn(proposedPlan).when(runner).buildNewPackingPlan(eq(currentPlan), eq(changeRequests), any(TopologyAPI.Topology.class));
Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(currentPlan).setProposedPackingPlan(proposedPlan).build();
when(client.updateTopology(updateTopologyRequest)).thenReturn(true);
try {
runner.updateTopologyHandler(TOPOLOGY_NAME, newParallelism);
} finally {
int expectedClientUpdateCalls = expectedResult ? 1 : 0;
verify(client, times(expectedClientUpdateCalls)).updateTopology(updateTopologyRequest);
}
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor 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.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class UpdateTopologyManager method updateTopology.
/**
* Scales the topology out or in based on the proposedPackingPlan
*
* @param existingProtoPackingPlan the current plan. If this isn't what's found in the state
* manager, the update will fail
* @param proposedProtoPackingPlan packing plan to change the topology to
*/
public void updateTopology(final PackingPlans.PackingPlan existingProtoPackingPlan, final PackingPlans.PackingPlan proposedProtoPackingPlan) throws ExecutionException, InterruptedException, ConcurrentModificationException {
String topologyName = Runtime.topologyName(runtime);
SchedulerStateManagerAdaptor stateManager = Runtime.schedulerStateManagerAdaptor(runtime);
Lock lock = stateManager.getLock(topologyName, IStateManager.LockName.UPDATE_TOPOLOGY);
if (lock.tryLock(5, TimeUnit.SECONDS)) {
try {
PackingPlans.PackingPlan foundPackingPlan = getPackingPlan(stateManager, topologyName);
if (!deserializer.fromProto(existingProtoPackingPlan).equals(deserializer.fromProto(foundPackingPlan))) {
throw new ConcurrentModificationException(String.format("The packing plan in state manager is not the same as the submitted existing " + "packing plan for topology %s. Another actor has changed it and has likely" + "performed an update on it. Failing this request, try again once other " + "update is complete", topologyName));
}
updateTopology(existingProtoPackingPlan, proposedProtoPackingPlan, stateManager);
} finally {
lock.unlock();
}
} else {
throw new ConcurrentModificationException(String.format("The update lock can not be obtained for topology %s. Another actor is performing an " + "update on it. Failing this request, try again once current update is complete", topologyName));
}
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientOk.
@Test
public void testGetServiceSchedulerClientOk() {
// 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);
// Get a schedulerLocation successfully
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(Scheduler.SchedulerLocation.getDefaultInstance());
Assert.assertNotNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
Aggregations