use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class HttpServiceSchedulerClientTest method testRequestSchedulerService.
/**
* Test Request Scheduler Service
*/
@Test
public void testRequestSchedulerService() throws Exception {
HttpServiceSchedulerClient client = Mockito.spy(new HttpServiceSchedulerClient(config, runtime, SCHEDULER_HTTP_ENDPOINT));
// Failed to create new http connection
PowerMockito.spy(NetworkUtils.class);
PowerMockito.doReturn(null).when(NetworkUtils.class, "getHttpConnection", Mockito.any(String.class));
Mockito.doReturn(COMMAND_ENDPOINT).when(client).getCommandEndpoint(Mockito.any(String.class), Mockito.any(Command.class));
Assert.assertFalse(client.requestSchedulerService(Mockito.any(Command.class), Mockito.any(byte[].class)));
HttpURLConnection connection = Mockito.mock(HttpURLConnection.class);
PowerMockito.doReturn(connection).when(NetworkUtils.class, "getHttpConnection", Mockito.any(String.class));
// Failed to send http post request
PowerMockito.doReturn(false).when(NetworkUtils.class, "sendHttpPostRequest", Mockito.eq(connection), Mockito.any(String.class), Mockito.any(byte[].class));
Assert.assertFalse(client.requestSchedulerService(Mockito.any(Command.class), Mockito.any(byte[].class)));
Mockito.verify(connection).disconnect();
// Received non-ok response
PowerMockito.doReturn(true).when(NetworkUtils.class, "sendHttpPostRequest", Mockito.eq(connection), Mockito.any(String.class), Mockito.any(byte[].class));
Scheduler.SchedulerResponse notOKResponse = SchedulerUtils.constructSchedulerResponse(false);
PowerMockito.doReturn(notOKResponse.toByteArray()).when(NetworkUtils.class, "readHttpResponse", Mockito.eq(connection));
Assert.assertFalse(client.requestSchedulerService(Mockito.any(Command.class), Mockito.any(byte[].class)));
Mockito.verify(connection, Mockito.times(2)).disconnect();
// Received ok response -- success case
Scheduler.SchedulerResponse oKResponse = SchedulerUtils.constructSchedulerResponse(true);
PowerMockito.doReturn(oKResponse.toByteArray()).when(NetworkUtils.class, "readHttpResponse", Mockito.eq(connection));
Assert.assertTrue(client.requestSchedulerService(Mockito.any(Command.class), Mockito.any(byte[].class)));
Mockito.verify(connection, Mockito.times(3)).disconnect();
}
use of com.twitter.heron.proto.scheduler.Scheduler in project heron by twitter.
the class LibrarySchedulerClientTest method testKillTopology.
@Test
public void testKillTopology() throws Exception {
IScheduler scheduler = Mockito.mock(IScheduler.class);
Scheduler.KillTopologyRequest request = Scheduler.KillTopologyRequest.getDefaultInstance();
LibrarySchedulerClient client = new LibrarySchedulerClient(config, runtime, scheduler);
// Failure case
Mockito.when(scheduler.onKill(request)).thenReturn(false);
Assert.assertFalse(client.killTopology(request));
Mockito.verify(scheduler).initialize(config, runtime);
Mockito.verify(scheduler).close();
Mockito.verify(scheduler).onKill(request);
// Success case
Mockito.when(scheduler.onKill(request)).thenReturn(true);
Assert.assertTrue(client.killTopology(request));
Mockito.verify(scheduler, Mockito.times(2)).initialize(config, runtime);
Mockito.verify(scheduler, Mockito.times(2)).close();
Mockito.verify(scheduler, Mockito.times(2)).onKill(request);
}
use of com.twitter.heron.proto.scheduler.Scheduler in project incubator-heron by apache.
the class ScaleUpResolver method resolve.
@Override
public List<Action> resolve(List<Diagnosis> diagnosis) {
for (Diagnosis diagnoses : diagnosis) {
Symptom bpSymptom = diagnoses.getSymptoms().get(SYMPTOM_UNDER_PROVISIONING.text());
if (bpSymptom == null || bpSymptom.getComponents().isEmpty()) {
// nothing to fix as there is no back pressure
continue;
}
if (bpSymptom.getComponents().size() > 1) {
throw new UnsupportedOperationException("Multiple components with back pressure symptom");
}
ComponentMetrics bpComponent = bpSymptom.getComponent();
int newParallelism = computeScaleUpFactor(bpComponent);
Map<String, Integer> changeRequest = new HashMap<>();
changeRequest.put(bpComponent.getName(), newParallelism);
PackingPlan currentPackingPlan = packingPlanProvider.get();
PackingPlan newPlan = buildNewPackingPlan(changeRequest, currentPackingPlan);
if (newPlan == null) {
return null;
}
Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(getSerializedPlan(currentPackingPlan)).setProposedPackingPlan(getSerializedPlan(newPlan)).build();
LOG.info("Sending Updating topology request: " + updateTopologyRequest);
if (!schedulerClient.updateTopology(updateTopologyRequest)) {
throw new RuntimeException(String.format("Failed to update topology with Scheduler, " + "updateTopologyRequest=%s", updateTopologyRequest));
}
TopologyUpdate action = new TopologyUpdate();
LOG.info("Broadcasting topology update event");
eventManager.onEvent(action);
LOG.info("Scheduler updated topology successfully.");
List<Action> actions = new ArrayList<>();
actions.add(action);
return actions;
}
return null;
}
use of com.twitter.heron.proto.scheduler.Scheduler in project incubator-heron by apache.
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 incubator-heron by apache.
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);
}
Aggregations