use of org.apache.commons.cli.GnuParser in project jstorm by alibaba.
the class JstormMaster method init.
/**
* Parse command line options
*
* @param args Command line args
* @return Whether init successful and run should be invoked
* @throws ParseException
* @throws IOException
*/
public boolean init(String[] args) throws ParseException, IOException {
Options opts = new Options();
opts.addOption(JOYConstants.APP_ATTEMPT_ID, true, "App Attempt ID. Not to be used unless for testing purposes");
opts.addOption(JOYConstants.SHELL_SCRIPT, true, "Environment for shell script. Specified as env_key=env_val pairs");
opts.addOption(JOYConstants.CONTAINER_MEMORY, true, "Amount of memory in MB to be requested to run the shell command");
opts.addOption(JOYConstants.CONTAINER_VCORES, true, "Amount of virtual cores to be requested to run the shell command");
opts.addOption(JOYConstants.NUM_CONTAINERS, true, "No. of containers on which the shell command needs to be executed");
opts.addOption(JOYConstants.PRIORITY, true, "Application Priority. Default 0");
opts.addOption(JOYConstants.DEBUG, false, "Dump out debug information");
opts.addOption(JOYConstants.HELP, false, "Print usage");
if (args.length == 0) {
printUsage(opts);
throw new IllegalArgumentException("No args specified for application master to initialize");
}
try {
CommandLine cliParser = new GnuParser().parse(opts, args);
JstormYarnUtils.checkAndSetMasterOptions(cliParser, jstormMasterContext, this.conf);
} catch (Exception e) {
LOG.error(e);
}
return true;
}
use of org.apache.commons.cli.GnuParser in project databus by linkedin.
the class BootstrapConfigBase method loadConfigProperties.
@SuppressWarnings("static-access")
public static Properties loadConfigProperties(String[] args) throws IOException {
CommandLineParser cliParser = new GnuParser();
Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
Options options = new Options();
options.addOption(dbOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
throw new RuntimeException("BootstrapConfig: failed to parse command-line options.", pe);
}
Properties props = null;
if (cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR)) {
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
props = new Properties();
FileInputStream f = new FileInputStream(propFile);
try {
props.load(f);
} finally {
if (null != f)
f.close();
}
} else {
LOG.info("Using system properties for bootstrap DB config");
}
return props;
}
use of org.apache.commons.cli.GnuParser in project databus by linkedin.
the class BootstrapAvroFileSeederMain method parseArgs.
@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
CommandLineParser cliParser = new GnuParser();
Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
Option sourcesOption = OptionBuilder.withLongOpt(PHYSICAL_CONFIG_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(PHYSICAL_CONFIG_OPT_CHAR);
Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap producer properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
Option log4jPropsOption = OptionBuilder.withLongOpt(LOG4J_PROPS_OPT_LONG_NAME).withDescription("Log4j properties to use").hasArg().withArgName("property_file").create(LOG4J_PROPS_OPT_CHAR);
Options options = new Options();
options.addOption(helpOption);
options.addOption(sourcesOption);
options.addOption(dbOption);
options.addOption(log4jPropsOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.fatal("Bootstrap Physical Config: failed to parse command-line options.", pe);
throw new RuntimeException("Bootstrap Physical Config: failed to parse command-line options.", pe);
}
if (cmd.hasOption(LOG4J_PROPS_OPT_CHAR)) {
String log4jPropFile = cmd.getOptionValue(LOG4J_PROPS_OPT_CHAR);
PropertyConfigurator.configure(log4jPropFile);
LOG.info("Using custom logging settings from file " + log4jPropFile);
} else {
PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c} %m%n");
ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(defaultAppender);
//using info as the default log level
Logger.getRootLogger().setLevel(Level.INFO);
LOG.info("Using default logging settings. Log Level is :" + Logger.getRootLogger().getLevel());
}
if (cmd.hasOption(HELP_OPT_CHAR)) {
printCliHelp(options);
System.exit(0);
}
if (!cmd.hasOption(PHYSICAL_CONFIG_OPT_CHAR))
throw new RuntimeException("Sources Config is not provided; use --help for usage");
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
throw new RuntimeException("Bootstrap config is not provided; use --help for usage");
_sSourcesConfigFile = cmd.getOptionValue(PHYSICAL_CONFIG_OPT_CHAR);
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream fis = new FileInputStream(propFile);
try {
_sBootstrapConfigProps.load(fis);
} finally {
fis.close();
}
}
use of org.apache.commons.cli.GnuParser in project databus by linkedin.
the class BootstrapAvroRecordDumper method parseArgs.
@SuppressWarnings("static-access")
public static void parseArgs(String[] args) throws IOException {
CommandLineParser cliParser = new GnuParser();
Option outputDirOption = OptionBuilder.withLongOpt(OUTPUT_DIR_OPT_LONG_NAME).withDescription("Help screen").create(OUTPUT_DIR_OPT_CHAR);
Options options = new Options();
options.addOption(outputDirOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.fatal("Bootstrap Avro Record Dumper: failed to parse command-line options.", pe);
throw new RuntimeException("Bootstrap Avro Record Dumper: failed to parse command-line options.", pe);
}
if (cmd.hasOption(OUTPUT_DIR_OPT_CHAR)) {
outputDir = cmd.getOptionValue(OUTPUT_DIR_OPT_CHAR);
}
}
use of org.apache.commons.cli.GnuParser in project databus by linkedin.
the class BootstrapMetadata method main.
/**
*/
public static void main(String[] args) {
int exitStatus = 0;
GnuParser cmdLineParser = new GnuParser();
Options options = new Options();
options.addOption("d", "dbname", true, "database name : [bootstrap]").addOption("s", "dbhost", true, "database hostname: [localhost]").addOption("p", "dbpassword", true, "database password: [bootstrap]").addOption("u", "dbuser", true, "database user: [bootstrap] ").addOption("S", "sources", true, " <srcid,..>|<srcName substring,..,> [all]").addOption("m", "minScnType", true, "type of minScn algorithm: [catchup-forever] catchup-forever|catchup-purged|snapshot. " + "'snapshot': use when snapshot table has been purged and the size of snapshot is not large.Times-out in 5 minutes if query cannot complete. " + "'catchup-purged': use when snapshot table has been purged and a conservative value of minScn is acceptable or when 'snapshot' isn't feasible. " + "'catchup-forever': use when snapshot table has *never* been purged . " + "Note: If a source has been seeded, regardless of the minScnType, the value returned is 0.").addOption("h", "help", false, "help");
// add descriptions used in usage() 'functionName' , 'description-pairs'
String[] functionNames = { "getSources", "get sourceName, sourceId, sourceStatus from bootstrap db", "createMinScnTable", "create metadata required for minScn feature in bootstrap db if none exists", "createAllTables", "create all metadata in bootstrap db if they don't exist", "getMinScn", "[--sources <>] return minScn as seen by bootstrap service for specified sources", "computeMinScn", "[--sources <>] [--minScnType <>] return minScn using one of the algorithms specified. " + "INIT could mean failure to find a minSCN ", "computeAndSetMinScn", "[--sources <>] [--minScnType<>] set minScn using one of the algorithms specified. ", "setMinScn", "[--sources <>] INFINITY|INIT|<scn> set minScn to a desired value. " };
try {
CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false);
if (cmdLineArgs.hasOption('h')) {
usage(options, functionNames);
System.exit(0);
}
String[] fns = cmdLineArgs.getArgs();
if (fns.length < 1) {
usage(options, functionNames);
throw new Exception("Missing argument");
}
String function = fns[0];
String arg1 = (fns.length > 1) ? fns[1] : null;
if (!legitFunction(functionNames, function)) {
usage(options, functionNames);
throw new Exception("Unknown function");
}
String bootstrapHost = cmdLineArgs.getOptionValue("dbhost", DEFAULT_BOOTSTRAP_HOST);
String bootstrapDbName = cmdLineArgs.getOptionValue("dbname", DEFAULT_BOOTSTRAP_DATABASE);
String bootstrapPassword = cmdLineArgs.getOptionValue("dbpassword", DEFAULT_BOOTSTRAP_PASSWORD);
String bootstrapUser = cmdLineArgs.getOptionValue("dbuser", DEFAULT_BOOTSTRAP_USER);
_bsConn = new BootstrapConn();
_bsConn.initBootstrapConn(false, bootstrapUser, bootstrapPassword, bootstrapHost, bootstrapDbName);
_dbao = new BootstrapDBMetaDataDAO(_bsConn, bootstrapHost, bootstrapUser, bootstrapPassword, bootstrapDbName, false);
String minScnType = cmdLineArgs.getOptionValue("minScnType", DEFAULT_MINSCN_TYPE);
if (function.equals("createMinScnTable")) {
createBootstrapMinScn();
return;
} else if (function.equals("createAllTables")) {
_dbao.setupDB();
return;
}
List<SourceStatusInfo> sourceInfoList = _dbao.getSrcStatusInfoFromDB();
if (function.equalsIgnoreCase("getSources")) {
for (SourceStatusInfo s : sourceInfoList) {
StringBuilder sb = new StringBuilder();
sb.append(s.getSrcName()).append('\t').append(s.getSrcId()).append('\t').append(s.getStatus());
System.out.println(sb.toString());
}
} else {
// not getSources()
// expect srcId list; for brevity;
String mySources = cmdLineArgs.getOptionValue("sources");
String[] mySrcList = null;
if (mySources != null) {
mySrcList = mySources.split(",");
}
List<SourceStatusInfo> finalSrcIdList = (mySrcList != null) ? getFinalSrcIdList(sourceInfoList, mySrcList) : sourceInfoList;
if (function.equalsIgnoreCase("getMinScn")) {
// read minScn from minscn table;
createBootstrapMinScn();
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = _dbao.getMinScnOfSnapshots(sInfo.getSrcId());
DBHelper.commit(_bsConn.getDBConn());
if (minScn == Long.MIN_VALUE) {
System.err.println("Error: Cannot get minScn for " + sInfo.getSrcId());
} else {
printScn(minScn, sInfo, '\t');
}
}
} else if (function.equalsIgnoreCase("computeMinScn")) {
// database not affected
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = computeMinScn(minScnType, sInfo.getSrcId());
// commit select;
DBHelper.commit(_bsConn.getDBConn());
if (minScn == Long.MIN_VALUE) {
System.err.println("Error: Cannot get minScn for " + sInfo.getSrcId());
} else {
printScn(minScn, sInfo, '\t');
}
}
} else if (function.equalsIgnoreCase("setMinScn")) {
if (arg1 == null) {
throw new Exception("Missing argument for setMinScn: <scn>, INFINITY or INIT");
}
// setMinScn <scn>
// override existing scn; never fail unless update fails ; show
// warning that you should know what you are doing
createBootstrapMinScn();
long scn;
if (arg1.equalsIgnoreCase("INFINITY")) {
scn = Long.MAX_VALUE;
} else if (arg1.equalsIgnoreCase("INIT")) {
scn = BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN;
} else {
scn = Long.parseLong(arg1);
}
for (SourceStatusInfo sInfo : finalSrcIdList) {
// calls commit
_dbao.updateMinScnOfSnapshot(sInfo.getSrcId(), scn);
}
} else if (function.equalsIgnoreCase("computeAndSetMinScn")) {
// set scn iff minScn has been initialized; ensure minScn is updated
// safely according to --type
// if seeded; --type is ignored;
createBootstrapMinScn();
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = computeMinScn(minScnType, sInfo.getSrcId());
if (minScn != Long.MIN_VALUE) {
_dbao.updateMinScnOfSnapshot(sInfo.getSrcId(), minScn);
}
DBHelper.commit(_bsConn.getDBConn());
}
}
}
} catch (ParseException e) {
usage(options, functionNames);
exitStatus = 1;
} catch (Exception e) {
System.err.println("Error: " + e);
exitStatus = 1;
} finally {
if (_dbao != null)
_dbao.close();
System.exit(exitStatus);
}
}
Aggregations