Search in sources :

Example 26 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class MesosLauncherTest method testGetSchedulerCommand.

@Test
@SuppressWarnings("unchecked")
public void testGetSchedulerCommand() throws Exception {
    final String JAVA_HOME = "java_home";
    final String NATIVE_LIBRARY_PATH = "native_library_path";
    final URI mockURI = TypeUtils.getURI("file:///mock/uri");
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(MesosContext.SCHEDULER_WORKING_DIRECTORY)).thenReturn("working-dir");
    Mockito.when(config.getStringValue(MesosContext.HERON_MESOS_NATIVE_LIBRARY_PATH)).thenReturn(NATIVE_LIBRARY_PATH);
    Mockito.when(config.getStringValue(Key.JAVA_HOME)).thenReturn(JAVA_HOME);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.get(Key.TOPOLOGY_PACKAGE_URI)).thenReturn(mockURI);
    MesosLauncher launcher = Mockito.spy(MesosLauncher.class);
    String[] mockCommand = new String[] { "mock", "scheduler", "command" };
    Mockito.doReturn(mockCommand).when(launcher).schedulerCommandArgs(Mockito.anyList());
    launcher.initialize(config, runtime);
    String[] command = launcher.getSchedulerCommand();
    // Assert the content of command
    Assert.assertEquals(String.format("%s/bin/java", JAVA_HOME), command[0]);
    Assert.assertEquals(String.format("-Djava.library.path=%s", NATIVE_LIBRARY_PATH), command[1]);
    Assert.assertEquals("-cp", command[2]);
    Assert.assertEquals(String.format("-Pheron.package.topology.uri=%s", mockURI.toString()), command[5]);
    Assert.assertEquals(mockCommand[0], command[6]);
    Assert.assertEquals(mockCommand[1], command[7]);
    Assert.assertEquals(mockCommand[2], command[8]);
}
Also used : Config(com.twitter.heron.spi.common.Config) URI(java.net.URI) Test(org.junit.Test)

Example 27 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class MesosSchedulerTest method before.

@Before
public void before() throws Exception {
    Config config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
    Config runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
    Properties properties = new Properties();
    properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
    Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
    mesosFramework = Mockito.mock(MesosFramework.class);
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    baseContainer = Mockito.mock(BaseContainer.class);
    scheduler = Mockito.spy(MesosScheduler.class);
    Mockito.doReturn(mesosFramework).when(scheduler).getMesosFramework();
    Mockito.doReturn(driver).when(scheduler).getSchedulerDriver(Mockito.anyString(), Mockito.eq(mesosFramework));
    Mockito.doNothing().when(scheduler).startSchedulerDriver();
    scheduler.initialize(config, runtime);
}
Also used : BaseContainer(com.twitter.heron.scheduler.mesos.framework.BaseContainer) MesosFramework(com.twitter.heron.scheduler.mesos.framework.MesosFramework) Config(com.twitter.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 28 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class MesosFrameworkTest method before.

@Before
public void before() throws Exception {
    config = Mockito.mock(Config.class);
    Mockito.when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Mockito.when(config.getStringValue(Key.ROLE)).thenReturn(ROLE);
    Mockito.when(config.getStringValue(Key.CORE_PACKAGE_URI)).thenReturn(CORE_PACKAGE_URI);
    runtime = Mockito.mock(Config.class);
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(NUM_CONTAINER);
    Properties properties = new Properties();
    properties.put(Key.TOPOLOGY_PACKAGE_URI.value(), TOPOLOGY_PACKAGE_URI);
    Mockito.when(runtime.get(Key.SCHEDULER_PROPERTIES)).thenReturn(properties);
    mesosFramework = Mockito.spy(new MesosFramework(config, runtime));
    SchedulerDriver driver = Mockito.mock(SchedulerDriver.class);
    // Register the mesos framework
    Protos.FrameworkID frameworkID = Protos.FrameworkID.newBuilder().setValue("framework-id").build();
    mesosFramework.registered(driver, frameworkID, Protos.MasterInfo.getDefaultInstance());
}
Also used : Protos(org.apache.mesos.Protos) Config(com.twitter.heron.spi.common.Config) Properties(java.util.Properties) SchedulerDriver(org.apache.mesos.SchedulerDriver) Before(org.junit.Before)

Example 29 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class UpdateTopologyManagerTest method mockRuntime.

private static Config mockRuntime(SchedulerStateManagerAdaptor stateManager) {
    Config runtime = mock(Config.class);
    when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(stateManager);
    return runtime;
}
Also used : Config(com.twitter.heron.spi.common.Config)

Example 30 with Config

use of com.twitter.heron.spi.common.Config in project heron by twitter.

the class RuntimeManagerMain method main.

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, ParseException {
    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);
    }
    Boolean verbose = false;
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
        verbose = true;
    }
    // init log
    LoggingHelper.loggerInit(logLevel, false);
    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    String heronHome = cmd.getOptionValue("heron_home");
    String configPath = cmd.getOptionValue("config_path");
    String overrideConfigFile = cmd.getOptionValue("override_config_file");
    String releaseFile = cmd.getOptionValue("release_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String commandOption = cmd.getOptionValue("command");
    String componentParallelism = cmd.getOptionValue("component_parallelism");
    // Optional argument in the case of restart
    // TODO(karthik): convert into CLI
    String containerId = Integer.toString(-1);
    if (cmd.hasOption("container_id")) {
        containerId = cmd.getOptionValue("container_id");
    }
    Boolean dryRun = false;
    if (cmd.hasOption("u")) {
        dryRun = true;
    }
    // Default dry-run output format type
    DryRunFormatType dryRunFormat = DryRunFormatType.TABLE;
    if (dryRun && cmd.hasOption("t")) {
        String format = cmd.getOptionValue("dry_run_format");
        dryRunFormat = DryRunFormatType.getDryRunFormatType(format);
        LOG.fine(String.format("Running dry-run mode using format %s", format));
    }
    Command command = Command.makeCommand(commandOption);
    // add config parameters from the command line
    Config.Builder commandLineConfig = Config.newBuilder().put(Key.CLUSTER, cluster).put(Key.ROLE, role).put(Key.ENVIRON, environ).put(Key.DRY_RUN, dryRun).put(Key.DRY_RUN_FORMAT_TYPE, dryRunFormat).put(Key.VERBOSE, verbose).put(Key.TOPOLOGY_CONTAINER_ID, containerId);
    // This is a command line option, but not a valid config key. Hence we don't use Keys
    if (componentParallelism != null) {
        commandLineConfig.put(RuntimeManagerRunner.NEW_COMPONENT_PARALLELISM_KEY, componentParallelism);
    }
    Config.Builder topologyConfig = Config.newBuilder().put(Key.TOPOLOGY_NAME, topologyName);
    // build the final config by expanding all the variables
    Config config = Config.toLocalMode(Config.newBuilder().putAll(ConfigLoader.loadConfig(heronHome, configPath, releaseFile, overrideConfigFile)).putAll(commandLineConfig.build()).putAll(topologyConfig.build()).build());
    LOG.fine("Static config loaded successfully ");
    LOG.fine(config.toString());
    /* 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 */
    /* Since only stderr is used (by logging), we use stdout here to
       propagate any message back to Python's executor.py (invoke site). */
    // Create a new instance of RuntimeManagerMain
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, command);
    try {
        runtimeManagerMain.manageTopology();
    // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (UpdateDryRunResponse 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(runtimeManagerMain.renderDryRunResponse(response));
        // SUPPRESS CHECKSTYLE RegexpSinglelineJava
        // Exit with status code 200 to indicate dry-run response is sent out
        System.exit(200);
    // SUPPRESS CHECKSTYLE IllegalCatch
    } catch (Exception e) {
        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);
    }
}
Also used : Options(org.apache.commons.cli.Options) PrintStream(java.io.PrintStream) DryRunFormatType(com.twitter.heron.common.basics.DryRunFormatType) UpdateDryRunResponse(com.twitter.heron.scheduler.dryrun.UpdateDryRunResponse) Config(com.twitter.heron.spi.common.Config) TMasterException(com.twitter.heron.spi.utils.TMasterException) PackingException(com.twitter.heron.spi.packing.PackingException) IOException(java.io.IOException) SchedulerException(com.twitter.heron.spi.scheduler.SchedulerException) ParseException(org.apache.commons.cli.ParseException) 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)

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