Search in sources :

Example 1 with SchedulerException

use of org.apache.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(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 SchedulerException

use of org.apache.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
    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(org.apache.heron.spi.statemgr.IStateManager) SchedulerException(org.apache.heron.spi.scheduler.SchedulerException) Config(org.apache.heron.spi.common.Config) SchedulerStateManagerAdaptor(org.apache.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 org.apache.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(org.apache.heron.spi.scheduler.SchedulerException) IScheduler(org.apache.heron.spi.scheduler.IScheduler)

Aggregations

SchedulerException (org.apache.heron.spi.scheduler.SchedulerException)3 IScheduler (org.apache.heron.spi.scheduler.IScheduler)2 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)2 Scheduler (org.apache.heron.proto.scheduler.Scheduler)1 Config (org.apache.heron.spi.common.Config)1 IStateManager (org.apache.heron.spi.statemgr.IStateManager)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1