use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class ScaleUpResolverTest method testResolve.
@Test
public void testResolve() {
TopologyAPI.Topology topology = createTestTopology();
Config config = createConfig(topology);
PackingPlan currentPlan = createPacking(topology, config);
PackingPlanProvider packingPlanProvider = mock(PackingPlanProvider.class);
when(packingPlanProvider.get()).thenReturn(currentPlan);
ISchedulerClient scheduler = mock(ISchedulerClient.class);
when(scheduler.updateTopology(any(UpdateTopologyRequest.class))).thenReturn(true);
Instant now = Instant.now();
Collections.singletonList(new Measurement("bolt", "i1", METRIC_BACK_PRESSURE.text(), now, 123));
List<String> assignments = Collections.singletonList("bolt");
Diagnosis diagnoses = new Diagnosis(DIAGNOSIS_UNDER_PROVISIONING.text(), now, assignments, null);
List<Diagnosis> diagnosis = Collections.singletonList(diagnoses);
ExecutionContext context = mock(ExecutionContext.class);
when(context.checkpoint()).thenReturn(now);
ScaleUpResolver resolver = new ScaleUpResolver(null, packingPlanProvider, scheduler, eventManager, null);
resolver.initialize(context);
ScaleUpResolver spyResolver = spy(resolver);
doReturn(2).when(spyResolver).computeScaleUpFactor("bolt");
doReturn(currentPlan).when(spyResolver).buildNewPackingPlan(any(HashMap.class), eq(currentPlan));
Collection<Action> result = spyResolver.resolve(diagnosis);
verify(scheduler, times(1)).updateTopology(any(UpdateTopologyRequest.class));
assertEquals(1, result.size());
}
use of org.apache.heron.scheduler.client.ISchedulerClient 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));
}
// returning false. In some cases the scheduler needs to have the topology deleted.
try {
if (!launcher.launch(packedPlan)) {
throw new TopologySubmissionException(null);
}
} catch (TopologySubmissionException e) {
// Compile error message to throw.
final StringBuilder errorMessage = new StringBuilder(String.format("Failed to launch topology '%s'", topologyName));
if (e.getMessage() != null) {
errorMessage.append("\n").append(e.getMessage());
}
try {
// Clear state from the Scheduler via RPC.
Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(topologyName).build();
ISchedulerClient schedulerClient = new SchedulerClientFactory(config, runtime).getSchedulerClient();
if (!schedulerClient.killTopology(killTopologyRequest)) {
final String logMessage = String.format("Failed to remove topology '%s' from scheduler after failed submit. " + "Please re-try the kill command.", topologyName);
errorMessage.append("\n").append(logMessage);
LOG.log(Level.SEVERE, logMessage);
}
// SUPPRESS CHECKSTYLE IllegalCatch
} catch (Exception ignored) {
// The above call to clear the Scheduler may fail. This situation can be ignored.
LOG.log(Level.FINE, String.format("Failure clearing failed topology `%s` from Scheduler during `submit`", topologyName));
}
// Clear state from the State Manager.
statemgr.deleteExecutionState(topologyName);
statemgr.deletePackingPlan(topologyName);
statemgr.deleteTopology(topologyName);
throw new LauncherException(errorMessage.toString());
}
}
use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method testRestartTopologyHandlerFailDeleteTManagerLoc.
@Test(expected = TopologyRuntimeManagementException.class)
public void testRestartTopologyHandlerFailDeleteTManagerLoc() {
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.RESTART, client);
// Restart container 1, not containing TManager
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(1).build();
when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(1);
// Restart container 0, containing TManager
when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(0);
when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(adaptor);
when(adaptor.deleteTManagerLocation(TOPOLOGY_NAME)).thenReturn(false);
try {
runner.restartTopologyHandler(TOPOLOGY_NAME);
} finally {
// DeleteTManagerLocation should be invoked
verify(adaptor).deleteTManagerLocation(TOPOLOGY_NAME);
}
}
use of org.apache.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 TManager
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 DeleteTManagerLocation
verify(adaptor, never()).deleteTManagerLocation(TOPOLOGY_NAME);
}
use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method doupdateTopologyComponentParallelismTest.
private void doupdateTopologyComponentParallelismTest(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(), any(TopologyAPI.Topology.class));
Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(currentPlan).setProposedPackingPlan(proposedPlan).build();
when(client.updateTopology(updateTopologyRequest)).thenReturn(true);
try {
runner.updateTopologyComponentParallelism(TOPOLOGY_NAME, newParallelism);
} finally {
int expectedClientUpdateCalls = expectedResult ? 1 : 0;
verify(client, times(expectedClientUpdateCalls)).updateTopology(updateTopologyRequest);
}
}
Aggregations