use of org.apache.commons.cli.Options in project heron by twitter.
the class SubmitterMain method constructOptions.
// Construct all required command line options
private static Options constructOptions() {
Options options = new Options();
Option cluster = Option.builder("c").desc("Cluster name in which the topology needs to run on").longOpt("cluster").hasArgs().argName("cluster").required().build();
Option role = Option.builder("r").desc("Role under which the topology needs to run").longOpt("role").hasArgs().argName("role").required().build();
Option environment = Option.builder("e").desc("Environment under which the topology needs to run").longOpt("environment").hasArgs().argName("environment").required().build();
Option heronHome = Option.builder("d").desc("Directory where heron is installed").longOpt("heron_home").hasArgs().argName("heron home dir").required().build();
Option configFile = Option.builder("p").desc("Path of the config files").longOpt("config_path").hasArgs().argName("config path").required().build();
Option configOverrides = Option.builder("o").desc("Command line override config path").longOpt("override_config_file").hasArgs().argName("override config file").build();
Option releaseFile = Option.builder("b").desc("Release file name").longOpt("release_file").hasArgs().argName("release information").build();
Option topologyPackage = Option.builder("y").desc("tar ball containing user submitted jar/tar, defn and config").longOpt("topology_package").hasArgs().argName("topology package").required().build();
Option topologyDefn = Option.builder("f").desc("serialized file containing Topology protobuf").longOpt("topology_defn").hasArgs().argName("topology definition").required().build();
Option topologyJar = Option.builder("j").desc("user heron topology jar/pex file path").longOpt("topology_bin").hasArgs().argName("topology binary file").required().build();
Option dryRun = Option.builder("u").desc("run in dry-run mode").longOpt("dry_run").required(false).build();
Option dryRunFormat = Option.builder("t").desc("dry-run format").longOpt("dry_run_format").hasArg().required(false).build();
Option verbose = Option.builder("v").desc("Enable debug logs").longOpt("verbose").build();
options.addOption(cluster);
options.addOption(role);
options.addOption(environment);
options.addOption(heronHome);
options.addOption(configFile);
options.addOption(configOverrides);
options.addOption(releaseFile);
options.addOption(topologyPackage);
options.addOption(topologyDefn);
options.addOption(topologyJar);
options.addOption(dryRun);
options.addOption(dryRunFormat);
options.addOption(verbose);
return options;
}
use of org.apache.commons.cli.Options 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 org.apache.commons.cli.Options in project heron by twitter.
the class RuntimeManagerMain method constructOptions.
// Construct all required command line options
private static Options constructOptions() {
Options options = new Options();
Option cluster = Option.builder("c").desc("Cluster name in which the topology needs to run on").longOpt("cluster").hasArgs().argName("cluster").required().build();
Option role = Option.builder("r").desc("Role under which the topology needs to run").longOpt("role").hasArgs().argName("role").required().build();
Option environment = Option.builder("e").desc("Environment under which the topology needs to run").longOpt("environment").hasArgs().argName("environment").required().build();
Option topologyName = Option.builder("n").desc("Name of the topology").longOpt("topology_name").hasArgs().argName("topology name").required().build();
Option heronHome = Option.builder("d").desc("Directory where heron is installed").longOpt("heron_home").hasArgs().argName("heron home dir").required().build();
Option componentParallelism = Option.builder("a").desc("Component parallelism to update: <name>:<value>,<name>:<value>,...").longOpt("component_parallelism").hasArgs().argName("component parallelism").build();
Option configFile = Option.builder("p").desc("Path of the config files").longOpt("config_path").hasArgs().argName("config path").required().build();
Option configOverrides = Option.builder("o").desc("Command line override config path").longOpt("override_config_file").hasArgs().argName("override config file").build();
Option releaseFile = Option.builder("b").desc("Release file name").longOpt("release_file").hasArgs().argName("release information").build();
Option command = Option.builder("m").desc("Command to run").longOpt("command").hasArgs().required().argName("command to run").build();
Option containerId = Option.builder("i").desc("Container Id for restart command").longOpt("container_id").hasArgs().argName("container id").build();
Option dryRun = Option.builder("u").desc("run in dry-run mode").longOpt("dry_run").required(false).build();
Option dryRunFormat = Option.builder("t").desc("dry-run format").longOpt("dry_run_format").hasArg().required(false).build();
Option verbose = Option.builder("v").desc("Enable debug logs").longOpt("verbose").build();
options.addOption(cluster);
options.addOption(role);
options.addOption(environment);
options.addOption(topologyName);
options.addOption(configFile);
options.addOption(configOverrides);
options.addOption(releaseFile);
options.addOption(command);
options.addOption(heronHome);
options.addOption(containerId);
options.addOption(componentParallelism);
options.addOption(dryRun);
options.addOption(dryRunFormat);
options.addOption(verbose);
return options;
}
use of org.apache.commons.cli.Options in project heron by twitter.
the class RuntimeManagerMain method constructHelpOptions.
// construct command line help options
private static Options constructHelpOptions() {
Options options = new Options();
Option help = Option.builder("h").desc("List all options and their description").longOpt("help").build();
options.addOption(help);
return options;
}
use of org.apache.commons.cli.Options 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);
}
}
Aggregations