Search in sources :

Example 1 with SchedulerException

use of com.twitter.heron.spi.scheduler.SchedulerException 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 SchedulerException

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

the class RuntimeManagerMainTest method testManageTopologyFailGetSchdulerClient.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = SchedulerException.class)
public void testManageTopologyFailGetSchdulerClient() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doNothing().when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Failed to get ISchedulerClient
    doThrow(new SchedulerException("")).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) Config(com.twitter.heron.spi.common.Config) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with SchedulerException

use of com.twitter.heron.spi.scheduler.SchedulerException in project incubator-heron by apache.

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 4 with SchedulerException

use of com.twitter.heron.spi.scheduler.SchedulerException 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(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 5 with SchedulerException

use of com.twitter.heron.spi.scheduler.SchedulerException in project incubator-heron by apache.

the class RuntimeManagerMainTest method testManageTopologyFailGetSchdulerClient.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = SchedulerException.class)
public void testManageTopologyFailGetSchdulerClient() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Failed to get ISchedulerClient
    doThrow(new SchedulerException("")).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(com.twitter.heron.spi.statemgr.IStateManager) SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) Config(com.twitter.heron.spi.common.Config) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SchedulerException (com.twitter.heron.spi.scheduler.SchedulerException)6 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)4 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)4 Scheduler (com.twitter.heron.proto.scheduler.Scheduler)2 Config (com.twitter.heron.spi.common.Config)2 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2