Search in sources :

Example 16 with Scheduler

use of com.twitter.heron.proto.scheduler.Scheduler in project incubator-heron by apache.

the class SchedulerClientFactory method getSchedulerClient.

/**
 * Implementation of getSchedulerClient - Used to create objects
 * Currently it creates either HttpServiceSchedulerClient or LibrarySchedulerClient
 *
 * @return getSchedulerClient created. return null if failed to create ISchedulerClient instance
 */
public ISchedulerClient getSchedulerClient() throws SchedulerException {
    LOG.fine("Creating scheduler client");
    ISchedulerClient schedulerClient;
    if (Context.schedulerService(config)) {
        // get the instance of the state manager
        SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
        Scheduler.SchedulerLocation schedulerLocation = statemgr.getSchedulerLocation(Runtime.topologyName(runtime));
        if (schedulerLocation == null) {
            throw new SchedulerException("Failed to get scheduler location from state manager");
        }
        LOG.log(Level.FINE, "Scheduler is listening on location: {0} ", schedulerLocation.toString());
        schedulerClient = new HttpServiceSchedulerClient(config, runtime, schedulerLocation.getHttpEndpoint());
    } else {
        // create an instance of scheduler
        final IScheduler scheduler = LauncherUtils.getInstance().getSchedulerInstance(config, runtime);
        LOG.fine("Invoke scheduler as a library");
        schedulerClient = new LibrarySchedulerClient(config, runtime, scheduler);
    }
    return schedulerClient;
}
Also used : SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 17 with Scheduler

use of com.twitter.heron.proto.scheduler.Scheduler in project incubator-heron by apache.

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)

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