use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class SchedulerUtils method setSchedulerLocation.
/**
* Set the location of scheduler for other processes to discover
*
* @param runtime the runtime configuration
* @param schedulerEndpoint the endpoint that scheduler listens for receives requests
* @param scheduler the IScheduler to provide more info
*/
public static boolean setSchedulerLocation(Config runtime, String schedulerEndpoint, IScheduler scheduler) {
// Set scheduler location to host:port by default. Overwrite scheduler location if behind DNS.
Scheduler.SchedulerLocation.Builder builder = Scheduler.SchedulerLocation.newBuilder().setTopologyName(Runtime.topologyName(runtime)).setHttpEndpoint(schedulerEndpoint);
// Set the job link in SchedulerLocation if any
List<String> jobLinks = scheduler.getJobLinks();
// Check whether IScheduler provides valid job link
if (jobLinks != null) {
builder.addAllJobPageLink(jobLinks);
}
Scheduler.SchedulerLocation location = builder.build();
LOG.log(Level.INFO, "Setting Scheduler locations: {0}", location);
SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
Boolean result = statemgr.setSchedulerLocation(location, Runtime.topologyName(runtime));
if (result == null || !result) {
LOG.severe("Failed to set Scheduler location");
return false;
}
return true;
}
use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class AuroraSchedulerTest method testOnRestart.
@Test
public void testOnRestart() throws Exception {
Config mockConfig = Mockito.mock(Config.class);
PowerMockito.mockStatic(Config.class);
when(Config.toClusterMode(mockConfig)).thenReturn(mockConfig);
AuroraController controller = Mockito.mock(AuroraController.class);
doReturn(controller).when(scheduler).getController();
scheduler.initialize(mockConfig, Mockito.mock(Config.class));
// Construct the RestartTopologyRequest
int containerToRestart = 1;
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(containerToRestart).build();
// Failed to kill job via controller
doReturn(false).when(controller).restart(containerToRestart);
Assert.assertFalse(scheduler.onRestart(restartTopologyRequest));
Mockito.verify(controller).restart(containerToRestart);
// Happy path
doReturn(true).when(controller).restart(containerToRestart);
assertTrue(scheduler.onRestart(restartTopologyRequest));
Mockito.verify(controller, Mockito.times(2)).restart(containerToRestart);
}
use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class LibrarySchedulerClientTest method testRestartTopology.
@Test
public void testRestartTopology() throws Exception {
IScheduler scheduler = Mockito.mock(IScheduler.class);
Scheduler.RestartTopologyRequest request = Scheduler.RestartTopologyRequest.getDefaultInstance();
LibrarySchedulerClient client = new LibrarySchedulerClient(config, runtime, scheduler);
// Failure case
Mockito.when(scheduler.onRestart(request)).thenReturn(false);
Assert.assertFalse(client.restartTopology(request));
Mockito.verify(scheduler).initialize(config, runtime);
Mockito.verify(scheduler).close();
Mockito.verify(scheduler).onRestart(request);
// Success case
Mockito.when(scheduler.onRestart(request)).thenReturn(true);
Assert.assertTrue(client.restartTopology(request));
Mockito.verify(scheduler, Mockito.times(2)).initialize(config, runtime);
Mockito.verify(scheduler, Mockito.times(2)).close();
Mockito.verify(scheduler, Mockito.times(2)).onRestart(request);
}
use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class RuntimeManagerRunner method restartTopologyHandler.
/**
* Handler to restart a topology
*/
@VisibleForTesting
void restartTopologyHandler(String topologyName) throws TopologyRuntimeManagementException {
Integer containerId = Context.topologyContainerId(config);
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(topologyName).setContainerIndex(containerId).build();
// i.e. TMasterLocation does not exist
if (containerId == -1 || containerId == 0) {
// get the instance of state manager to clean state
SchedulerStateManagerAdaptor stateManager = Runtime.schedulerStateManagerAdaptor(runtime);
Boolean result = stateManager.deleteTMasterLocation(topologyName);
if (result == null || !result) {
throw new TopologyRuntimeManagementException("Failed to clear TMaster location. Check whether TMaster set it correctly.");
}
}
if (!schedulerClient.restartTopology(restartTopologyRequest)) {
throw new TopologyRuntimeManagementException(String.format("Failed to restart topology '%s'", topologyName));
}
// Clean the connection when we are done.
LOG.fine("Scheduler restarted topology successfully.");
}
use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class RuntimeManagerRunner method updateTopologyHandler.
/**
* Handler to update a topology
*/
@VisibleForTesting
void updateTopologyHandler(String topologyName, String newParallelism) throws TopologyRuntimeManagementException, PackingException, UpdateDryRunResponse {
LOG.fine(String.format("updateTopologyHandler called for %s with %s", topologyName, newParallelism));
SchedulerStateManagerAdaptor manager = Runtime.schedulerStateManagerAdaptor(runtime);
TopologyAPI.Topology topology = manager.getTopology(topologyName);
Map<String, Integer> changeRequests = parseNewParallelismParam(newParallelism);
PackingPlans.PackingPlan currentPlan = manager.getPackingPlan(topologyName);
if (!changeDetected(currentPlan, changeRequests)) {
throw new TopologyRuntimeManagementException(String.format("The component parallelism request (%s) is the same as the " + "current topology parallelism. Not taking action.", newParallelism));
}
PackingPlans.PackingPlan proposedPlan = buildNewPackingPlan(currentPlan, changeRequests, topology);
if (Context.dryRun(config)) {
PackingPlanProtoDeserializer deserializer = new PackingPlanProtoDeserializer();
PackingPlan oldPlan = deserializer.fromProto(currentPlan);
PackingPlan newPlan = deserializer.fromProto(proposedPlan);
throw new UpdateDryRunResponse(topology, config, newPlan, oldPlan, changeRequests);
}
Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(currentPlan).setProposedPackingPlan(proposedPlan).build();
LOG.fine("Sending Updating topology request: " + updateTopologyRequest);
if (!schedulerClient.updateTopology(updateTopologyRequest)) {
throw new TopologyRuntimeManagementException(String.format("Failed to update topology with Scheduler, updateTopologyRequest=" + updateTopologyRequest));
}
// Clean the connection when we are done.
LOG.fine("Scheduler updated topology successfully.");
}
Aggregations