Search in sources :

Example 1 with PoliciesExecutor

use of com.microsoft.dhalion.policy.PoliciesExecutor in project incubator-heron by apache.

the class HealthManager method main.

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new DefaultParser();
    Options slaManagerCliOptions = constructCliOptions();
    // parse the help options first.
    Options helpOptions = constructHelpOptions();
    CommandLine cmd = parser.parse(helpOptions, args, true);
    if (cmd.hasOption("h")) {
        usage(slaManagerCliOptions);
        return;
    }
    try {
        cmd = parser.parse(slaManagerCliOptions, args);
    } catch (ParseException e) {
        usage(slaManagerCliOptions);
        throw new RuntimeException("Error parsing command line options: ", e);
    }
    HealthManagerMode mode = HealthManagerMode.cluster;
    if (hasOption(cmd, CliArgs.MODE)) {
        mode = HealthManagerMode.valueOf(getOptionValue(cmd, CliArgs.MODE));
    }
    Config config;
    switch(mode) {
        case cluster:
            config = Config.toClusterMode(Config.newBuilder().putAll(ConfigLoader.loadClusterConfig()).putAll(commandLineConfigs(cmd)).build());
            break;
        case local:
            if (!hasOption(cmd, CliArgs.HERON_HOME) || !hasOption(cmd, CliArgs.CONFIG_PATH)) {
                throw new IllegalArgumentException("Missing heron_home or config_path argument");
            }
            String heronHome = getOptionValue(cmd, CliArgs.HERON_HOME);
            String configPath = getOptionValue(cmd, CliArgs.CONFIG_PATH);
            config = Config.toLocalMode(Config.newBuilder().putAll(ConfigLoader.loadConfig(heronHome, configPath, null, null)).putAll(commandLineConfigs(cmd)).build());
            break;
        default:
            throw new IllegalArgumentException("Invalid mode: " + getOptionValue(cmd, CliArgs.MODE));
    }
    setupLogging(cmd, config);
    LOG.info("Static Heron config loaded successfully ");
    LOG.fine(config.toString());
    // load the default config value and override with any command line values
    String metricSourceClassName = config.getStringValue(PolicyConfigKey.METRIC_SOURCE_TYPE.key());
    metricSourceClassName = getOptionValue(cmd, CliArgs.METRIC_SOURCE_TYPE, metricSourceClassName);
    String metricsUrl = config.getStringValue(PolicyConfigKey.METRIC_SOURCE_URL.key());
    metricsUrl = getOptionValue(cmd, CliArgs.METRIC_SOURCE_URL, metricsUrl);
    AbstractModule module = buildMetricsProviderModule(metricsUrl, metricSourceClassName);
    HealthManager healthManager = new HealthManager(config, module);
    LOG.info("Initializing health manager");
    healthManager.initialize();
    LOG.info("Starting Health Manager metirc posting thread");
    HealthManagerMetrics publishingMetricsRunnable = null;
    if (hasOption(cmd, CliArgs.METRICSMGR_PORT)) {
        publishingMetricsRunnable = new HealthManagerMetrics(Integer.valueOf(getOptionValue(cmd, CliArgs.METRICSMGR_PORT)));
    }
    LOG.info("Starting Health Manager");
    PoliciesExecutor policyExecutor = new PoliciesExecutor(healthManager.healthPolicies);
    ScheduledFuture<?> future = policyExecutor.start();
    if (publishingMetricsRunnable != null) {
        new Thread(publishingMetricsRunnable).start();
    }
    try {
        future.get();
    } finally {
        policyExecutor.destroy();
        if (publishingMetricsRunnable != null) {
            publishingMetricsRunnable.close();
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) Config(com.twitter.heron.spi.common.Config) SystemConfig(com.twitter.heron.common.config.SystemConfig) AbstractModule(com.google.inject.AbstractModule) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with PoliciesExecutor

use of com.microsoft.dhalion.policy.PoliciesExecutor in project heron by twitter.

the class HealthManager method main.

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new DefaultParser();
    Options slaManagerCliOptions = constructCliOptions();
    // parse the help options first.
    Options helpOptions = constructHelpOptions();
    CommandLine cmd = parser.parse(helpOptions, args, true);
    if (cmd.hasOption("h")) {
        usage(slaManagerCliOptions);
        return;
    }
    try {
        cmd = parser.parse(slaManagerCliOptions, args);
    } catch (ParseException e) {
        usage(slaManagerCliOptions);
        throw new RuntimeException("Error parsing command line options: ", e);
    }
    HealthManagerMode mode = HealthManagerMode.cluster;
    if (hasOption(cmd, CliArgs.MODE)) {
        mode = HealthManagerMode.valueOf(getOptionValue(cmd, CliArgs.MODE));
    }
    Config config;
    switch(mode) {
        case cluster:
            config = Config.toClusterMode(Config.newBuilder().putAll(ConfigLoader.loadClusterConfig()).putAll(commandLineConfigs(cmd)).build());
            break;
        case local:
            if (!hasOption(cmd, CliArgs.HERON_HOME) || !hasOption(cmd, CliArgs.CONFIG_PATH)) {
                throw new IllegalArgumentException("Missing heron_home or config_path argument");
            }
            String heronHome = getOptionValue(cmd, CliArgs.HERON_HOME);
            String configPath = getOptionValue(cmd, CliArgs.CONFIG_PATH);
            config = Config.toLocalMode(Config.newBuilder().putAll(ConfigLoader.loadConfig(heronHome, configPath, null, null)).putAll(commandLineConfigs(cmd)).build());
            break;
        default:
            throw new IllegalArgumentException("Invalid mode: " + getOptionValue(cmd, CliArgs.MODE));
    }
    setupLogging(cmd, config);
    LOG.fine(Arrays.toString(cmd.getOptions()));
    // Add the SystemConfig into SingletonRegistry
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(Context.systemFile(config), true).putAll(Context.overrideFile(config), true).build();
    SingletonRegistry.INSTANCE.registerSingleton(SystemConfig.HERON_SYSTEM_CONFIG, systemConfig);
    LOG.info("Static Heron config loaded successfully ");
    LOG.fine(config.toString());
    // load the default config value and override with any command line values
    String metricSourceClassName = config.getStringValue(PolicyConfigKey.METRIC_SOURCE_TYPE.key());
    metricSourceClassName = getOptionValue(cmd, CliArgs.METRIC_SOURCE_TYPE, metricSourceClassName);
    String metricsUrl = config.getStringValue(PolicyConfigKey.METRIC_SOURCE_URL.key());
    metricsUrl = getOptionValue(cmd, CliArgs.METRIC_SOURCE_URL, metricsUrl);
    // metrics reporting thread
    HealthManagerMetrics publishingMetrics = new HealthManagerMetrics(Integer.valueOf(getOptionValue(cmd, CliArgs.METRICSMGR_PORT)));
    AbstractModule module = buildBaseModule(metricsUrl, metricSourceClassName, publishingMetrics);
    HealthManager healthManager = new HealthManager(config, module);
    LOG.info("Initializing health manager");
    healthManager.initialize();
    LOG.info("Starting Health Manager");
    PoliciesExecutor policyExecutor = new PoliciesExecutor(healthManager.healthPolicies);
    ScheduledFuture<?> future = policyExecutor.start();
    LOG.info("Starting Health Manager metric posting thread");
    new Thread(publishingMetrics).start();
    try {
        future.get();
    } finally {
        policyExecutor.destroy();
        publishingMetrics.close();
    }
}
Also used : Options(org.apache.commons.cli.Options) SystemConfig(org.apache.heron.common.config.SystemConfig) SystemConfig(org.apache.heron.common.config.SystemConfig) Config(org.apache.heron.spi.common.Config) AbstractModule(com.google.inject.AbstractModule) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) PoliciesExecutor(com.microsoft.dhalion.policy.PoliciesExecutor) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

AbstractModule (com.google.inject.AbstractModule)2 PoliciesExecutor (com.microsoft.dhalion.policy.PoliciesExecutor)2 CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 DefaultParser (org.apache.commons.cli.DefaultParser)2 Options (org.apache.commons.cli.Options)2 ParseException (org.apache.commons.cli.ParseException)2 SystemConfig (com.twitter.heron.common.config.SystemConfig)1 Config (com.twitter.heron.spi.common.Config)1 SystemConfig (org.apache.heron.common.config.SystemConfig)1 Config (org.apache.heron.spi.common.Config)1