use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SubmitterMain method main.
public static void main(String[] args) throws Exception {
Options options = constructOptions();
Options helpOptions = constructHelpOptions();
CommandLineParser parser = new DefaultParser();
// parse the help options first.
CommandLine cmd = parser.parse(helpOptions, args, true);
if (cmd.hasOption("h")) {
usage(options);
return;
}
try {
// Now parse the required options
cmd = parser.parse(options, args);
} catch (ParseException e) {
usage(options);
throw new RuntimeException("Error parsing command line options: ", e);
}
Level logLevel = Level.INFO;
if (isVerbose(cmd)) {
logLevel = Level.ALL;
}
// init log
LoggingHelper.loggerInit(logLevel, false);
// load the topology definition into topology proto
TopologyAPI.Topology topology = TopologyUtils.getTopology(cmd.getOptionValue("topology_defn"));
Config config = loadConfig(cmd, topology);
LOG.fine("Static config loaded successfully");
LOG.fine(config.toString());
SubmitterMain submitterMain = new SubmitterMain(config, topology);
/* Meaning of exit status code:
- status code = 0:
program exits without error
- 0 < status code < 100:
program fails to execute before program execution. For example,
JVM cannot find or load main class
- 100 <= status code < 200:
program fails to launch after program execution. For example,
topology definition file fails to be loaded
- status code >= 200
program sends out dry-run response */
try {
submitterMain.submitTopology();
} catch (SubmitDryRunResponse response) {
LOG.log(Level.FINE, "Sending out dry-run response");
// Output may contain UTF-8 characters, so we should print using UTF-8 encoding
PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8.name());
out.print(submitterMain.renderDryRunResponse(response));
// Exit with status code 200 to indicate dry-run response is sent out
// SUPPRESS CHECKSTYLE RegexpSinglelineJava
System.exit(200);
// SUPPRESS CHECKSTYLE IllegalCatch
} catch (Exception e) {
/* Since only stderr is used (by logging), we use stdout here to
propagate error message back to Python's executor.py (invoke site). */
LOG.log(Level.FINE, "Exception when submitting topology", e);
System.out.println(e.getMessage());
// Exit with status code 100 to indicate that error has happened on user-land
// SUPPRESS CHECKSTYLE RegexpSinglelineJava
System.exit(100);
}
LOG.log(Level.FINE, "Topology {0} submitted successfully", topology.getName());
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientOk.
@Test
public void testGetServiceSchedulerClientOk() {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
SchedulerStateManagerAdaptor statemgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
// Get a ServiceSchedulerClient
Mockito.when(config.getBooleanValue(Key.SCHEDULER_IS_SERVICE)).thenReturn(true);
// Mock the runtime object
Mockito.when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(statemgr);
Mockito.when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
// Get a schedulerLocation successfully
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(Scheduler.SchedulerLocation.getDefaultInstance());
Assert.assertNotNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SchedulerClientFactoryTest method testGetLibrarySchedulerClientNotExist.
@Test(expected = SchedulerException.class)
@PrepareForTest(ReflectionUtils.class)
public void testGetLibrarySchedulerClientNotExist() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
// Return a MockScheduler
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(IScheduler.class.getName());
PowerMockito.mockStatic(ReflectionUtils.class);
PowerMockito.doReturn(Mockito.mock(IScheduler.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IScheduler.class.getName()));
// Return some scheduler class not exist
final String SCHEDULER_CLASS_NOT_EXIST = "class_not_exist";
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS_NOT_EXIST);
PowerMockito.doThrow(new ClassNotFoundException()).when(ReflectionUtils.class, "newInstance", Mockito.eq(SCHEDULER_CLASS_NOT_EXIST));
Assert.assertNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SchedulerClientFactoryTest method testGetServiceSchedulerClientFail.
@Test(expected = SchedulerException.class)
public void testGetServiceSchedulerClientFail() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
SchedulerStateManagerAdaptor statemgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
// Get a ServiceSchedulerClient
Mockito.when(config.getBooleanValue(Key.SCHEDULER_IS_SERVICE)).thenReturn(true);
// Mock the runtime object
Mockito.when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(statemgr);
Mockito.when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
// Failed to getSchedulerLocation
Mockito.when(statemgr.getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME))).thenReturn(null);
try {
new SchedulerClientFactory(config, runtime).getSchedulerClient();
} finally {
Mockito.verify(statemgr).getSchedulerLocation(Mockito.eq(TOPOLOGY_NAME));
}
}
use of com.twitter.heron.spi.common.Config in project heron by twitter.
the class SubmitDryRunRenderTest method testTableA.
@Test
public void testTableA() throws IOException {
InputStream stream = UpdateDryRunRenderTest.class.getResourceAsStream("/heron/scheduler-core/tests/resources/SubmitDryRunOutputATable.txt");
if (stream == null) {
throw new RuntimeException("Sample output file not found");
}
// Input might contain UTF-8 character, so we read stream with UTF-8 decoding
String exampleTable = IOUtils.toString(stream, StandardCharsets.UTF_8);
TopologyAPI.Topology topology = PowerMockito.mock(TopologyAPI.Topology.class);
Config config = Config.newBuilder().put(Key.PACKING_CLASS, "com.twitter.heron.packing.roundrobin.RoundRobinPacking").build();
String table = new SubmitTableDryRunRenderer(new SubmitDryRunResponse(topology, config, plan)).render();
assertEquals(exampleTable, table);
}
Aggregations