Search in sources :

Example 1 with IScheduler

use of org.apache.heron.spi.scheduler.IScheduler 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 IScheduler

use of org.apache.heron.spi.scheduler.IScheduler 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 3 with IScheduler

use of org.apache.heron.spi.scheduler.IScheduler 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 4 with IScheduler

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

Example 5 with IScheduler

use of org.apache.heron.spi.scheduler.IScheduler in project heron by twitter.

the class YarnSchedulerTest method delegatesToDriverOnKill.

@Test
public void delegatesToDriverOnKill() {
    HeronMasterDriver mockHeronDriver = Mockito.mock(HeronMasterDriver.class);
    HeronMasterDriverProvider.setInstance(mockHeronDriver);
    IScheduler scheduler = new YarnScheduler();
    scheduler.onKill(null);
    verify(mockHeronDriver).killTopology();
}
Also used : IScheduler(org.apache.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Aggregations

IScheduler (org.apache.heron.spi.scheduler.IScheduler)9 Test (org.junit.Test)5 Scheduler (org.apache.heron.proto.scheduler.Scheduler)4 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)3 Config (org.apache.heron.spi.common.Config)2 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 SchedulerException (org.apache.heron.spi.scheduler.SchedulerException)2 IOException (java.io.IOException)1 SystemConfig (org.apache.heron.common.config.SystemConfig)1 PackingPlans (org.apache.heron.proto.system.PackingPlans)1 SchedulerServer (org.apache.heron.scheduler.server.SchedulerServer)1 LauncherUtils (org.apache.heron.scheduler.utils.LauncherUtils)1 PackingPlanProtoDeserializer (org.apache.heron.spi.packing.PackingPlanProtoDeserializer)1 IStateManager (org.apache.heron.spi.statemgr.IStateManager)1 InOrder (org.mockito.InOrder)1