Search in sources :

Example 1 with Scheduler

use of org.apache.heron.proto.scheduler.Scheduler in project heron by twitter.

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(org.apache.heron.spi.scheduler.SchedulerException) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Scheduler(org.apache.heron.proto.scheduler.Scheduler) IScheduler(org.apache.heron.spi.scheduler.IScheduler) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 2 with Scheduler

use of org.apache.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(org.apache.heron.scheduler.Command) Scheduler(org.apache.heron.proto.scheduler.Scheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with Scheduler

use of org.apache.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 : IScheduler(org.apache.heron.spi.scheduler.IScheduler) Scheduler(org.apache.heron.proto.scheduler.Scheduler) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Example 4 with Scheduler

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

Example 5 with Scheduler

use of org.apache.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 {
    assert !potentialStaleExecutionData;
    Integer containerId = Context.topologyContainerId(config);
    Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(topologyName).setContainerIndex(containerId).build();
    // i.e. TManagerLocation 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.deleteTManagerLocation(topologyName);
        if (result == null || !result) {
            throw new TopologyRuntimeManagementException("Failed to clear TManager location. Check whether TManager 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.");
}
Also used : Scheduler(org.apache.heron.proto.scheduler.Scheduler) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Scheduler (org.apache.heron.proto.scheduler.Scheduler)9 IScheduler (org.apache.heron.spi.scheduler.IScheduler)4 Test (org.junit.Test)4 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)3 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Action (com.microsoft.dhalion.core.Action)1 Diagnosis (com.microsoft.dhalion.core.Diagnosis)1 DiagnosisTable (com.microsoft.dhalion.core.DiagnosisTable)1 HttpURLConnection (java.net.HttpURLConnection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TopologyUpdate (org.apache.heron.healthmgr.common.HealthManagerEvents.TopologyUpdate)1 Command (org.apache.heron.scheduler.Command)1 UpdateDryRunResponse (org.apache.heron.scheduler.dryrun.UpdateDryRunResponse)1 Config (org.apache.heron.spi.common.Config)1 PackingPlanProtoDeserializer (org.apache.heron.spi.packing.PackingPlanProtoDeserializer)1 SchedulerException (org.apache.heron.spi.scheduler.SchedulerException)1