Search in sources :

Example 11 with Scheduler

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();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Command(com.twitter.heron.scheduler.Command) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with Scheduler

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);
}
Also used : Scheduler(com.twitter.heron.proto.scheduler.Scheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Example 13 with Scheduler

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;
}
Also used : Action(com.microsoft.dhalion.resolver.Action) HashMap(java.util.HashMap) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) ArrayList(java.util.ArrayList) TopologyUpdate(com.twitter.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate) Diagnosis(com.microsoft.dhalion.diagnoser.Diagnosis) Symptom(com.microsoft.dhalion.detector.Symptom) ComponentMetrics(com.microsoft.dhalion.metrics.ComponentMetrics)

Example 14 with Scheduler

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;
}
Also used : Scheduler(com.twitter.heron.proto.scheduler.Scheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 15 with Scheduler

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);
}
Also used : Scheduler(com.twitter.heron.proto.scheduler.Scheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Aggregations

Scheduler (com.twitter.heron.proto.scheduler.Scheduler)17 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)8 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)8 Test (org.junit.Test)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)3 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)2 PackingPlans (com.twitter.heron.proto.system.PackingPlans)2 Command (com.twitter.heron.scheduler.Command)2 UpdateDryRunResponse (com.twitter.heron.scheduler.dryrun.UpdateDryRunResponse)2 Config (com.twitter.heron.spi.common.Config)2 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)2 SchedulerException (com.twitter.heron.spi.scheduler.SchedulerException)2 HttpURLConnection (java.net.HttpURLConnection)2 Symptom (com.microsoft.dhalion.detector.Symptom)1 Diagnosis (com.microsoft.dhalion.diagnoser.Diagnosis)1 ComponentMetrics (com.microsoft.dhalion.metrics.ComponentMetrics)1 Action (com.microsoft.dhalion.resolver.Action)1 TopologyUpdate (com.twitter.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate)1