Search in sources :

Example 11 with Config

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());
}
Also used : Options(org.apache.commons.cli.Options) PrintStream(java.io.PrintStream) Config(com.twitter.heron.spi.common.Config) LauncherException(com.twitter.heron.spi.scheduler.LauncherException) UploaderException(com.twitter.heron.spi.uploader.UploaderException) PackingException(com.twitter.heron.spi.packing.PackingException) ParseException(org.apache.commons.cli.ParseException) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) SubmitDryRunResponse(com.twitter.heron.scheduler.dryrun.SubmitDryRunResponse) CommandLine(org.apache.commons.cli.CommandLine) Level(java.util.logging.Level) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 12 with Config

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());
}
Also used : Config(com.twitter.heron.spi.common.Config) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with Config

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());
}
Also used : Config(com.twitter.heron.spi.common.Config) IScheduler(com.twitter.heron.spi.scheduler.IScheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with Config

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));
    }
}
Also used : Config(com.twitter.heron.spi.common.Config) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with Config

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);
}
Also used : InputStream(java.io.InputStream) Config(com.twitter.heron.spi.common.Config) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Config (com.twitter.heron.spi.common.Config)87 Test (org.junit.Test)55 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)23 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)20 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)17 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)9 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)8 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)8 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)7 Before (org.junit.Before)7 HashSet (java.util.HashSet)5 ByteAmount (com.twitter.heron.common.basics.ByteAmount)4 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)4 PackingException (com.twitter.heron.spi.packing.PackingException)4 Resource (com.twitter.heron.spi.packing.Resource)4 URI (java.net.URI)4 Properties (java.util.Properties)4 CommandLine (org.apache.commons.cli.CommandLine)4 HeronTopology (com.twitter.heron.api.HeronTopology)3