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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations