Search in sources :

Example 1 with IScheduler

use of com.twitter.heron.spi.scheduler.IScheduler in project heron by twitter.

the class LauncherUtils method getSchedulerInstance.

/**
   * Creates and initializes scheduler instance
   *
   * @return initialized scheduler instances
   */
public IScheduler getSchedulerInstance(Config config, Config runtime) throws SchedulerException {
    String schedulerClass = Context.schedulerClass(config);
    IScheduler scheduler;
    try {
        // create an instance of scheduler
        scheduler = ReflectionUtils.newInstance(schedulerClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new SchedulerException(String.format("Failed to instantiate scheduler using class '%s'", schedulerClass));
    }
    scheduler.initialize(config, runtime);
    return scheduler;
}
Also used : SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) IScheduler(com.twitter.heron.spi.scheduler.IScheduler)

Example 2 with IScheduler

use of com.twitter.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(com.twitter.heron.proto.scheduler.Scheduler) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 3 with IScheduler

use of com.twitter.heron.spi.scheduler.IScheduler in project heron by twitter.

the class SchedulerServerTest method testSchedulerServer.

@Test
public void testSchedulerServer() throws Exception {
    int freePort = SysUtils.getFreePort();
    IScheduler scheduler = Mockito.mock(IScheduler.class);
    Config runtime = Mockito.mock(Config.class);
    SchedulerServer schedulerServer = Mockito.spy(new SchedulerServer(runtime, scheduler, freePort));
    Assert.assertEquals(NetworkUtils.getHostName(), schedulerServer.getHost());
    Assert.assertEquals(freePort, schedulerServer.getPort());
}
Also used : Config(com.twitter.heron.spi.common.Config) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Example 4 with IScheduler

use of com.twitter.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 : 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 5 with IScheduler

use of com.twitter.heron.spi.scheduler.IScheduler in project heron by twitter.

the class YarnSchedulerTest method delegatesToDriverOnSchedule.

@Test
public void delegatesToDriverOnSchedule() throws Exception {
    HeronMasterDriver mockHeronDriver = Mockito.mock(HeronMasterDriver.class);
    HeronMasterDriverProvider.setInstance(mockHeronDriver);
    Mockito.doNothing().when(mockHeronDriver).launchTMaster();
    IScheduler scheduler = new YarnScheduler();
    PackingPlan mockPacking = Mockito.mock(PackingPlan.class);
    scheduler.onSchedule(mockPacking);
    InOrder invocationOrder = Mockito.inOrder(mockHeronDriver);
    invocationOrder.verify(mockHeronDriver).scheduleHeronWorkers(mockPacking);
    invocationOrder.verify(mockHeronDriver).launchTMaster();
}
Also used : InOrder(org.mockito.InOrder) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test)

Aggregations

IScheduler (com.twitter.heron.spi.scheduler.IScheduler)18 Test (org.junit.Test)10 Scheduler (com.twitter.heron.proto.scheduler.Scheduler)8 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)6 Config (com.twitter.heron.spi.common.Config)4 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)4 SchedulerException (com.twitter.heron.spi.scheduler.SchedulerException)4 SystemConfig (com.twitter.heron.common.config.SystemConfig)2 PackingPlans (com.twitter.heron.proto.system.PackingPlans)2 SchedulerServer (com.twitter.heron.scheduler.server.SchedulerServer)2 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)2 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)2 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)2 IOException (java.io.IOException)2 InOrder (org.mockito.InOrder)2