use of org.apache.commons.cli.Option in project databus by linkedin.
the class BootstrapSeederMain 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);
Option validationType = OptionBuilder.withLongOpt(VALIDATION_TYPE_OPT_LONG_NAME).withDescription("Type of validation algorithm , normal[cmp two sorted streams of oracle and bootstrap db] or point[entry in bootstrap checked in oracle]").hasArg().withArgName("validation_type").create(VALIDATION_TYPE_OPT_CHAR);
Option validationSamplePct = OptionBuilder.withLongOpt(VALIDATION_SAMPLE_PCT_LONG_NAME).withDescription("Validation sample pct ,0.0 to 100.00 [100.0]").hasArg().withArgName("validation_sample_pct").create(VALIDATION_SAMPLE_PCT_CHAR);
Options options = new Options();
options.addOption(helpOption);
options.addOption(sourcesOption);
options.addOption(dbOption);
options.addOption(log4jPropsOption);
options.addOption(validationType);
options.addOption(validationSamplePct);
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();
_sBootstrapConfigProps.load(new FileInputStream(propFile));
if (!cmd.hasOption(VALIDATION_TYPE_OPT_CHAR)) {
_validationType = "normal";
} else {
String vtype = cmd.getOptionValue(VALIDATION_TYPE_OPT_CHAR);
if (vtype.equals("point") || vtype.equals("normal") || vtype.equals("pointBs")) {
_validationType = vtype;
} else {
throw new RuntimeException("Validation type has to be one of 'normal' or 'point' or 'pointBs'");
}
}
if (cmd.hasOption(VALIDATION_SAMPLE_PCT_CHAR)) {
try {
_validationSamplePct = Double.parseDouble(cmd.getOptionValue(VALIDATION_SAMPLE_PCT_CHAR));
if (_validationSamplePct < 0.0 || _validationSamplePct > 100.0) {
throw new RuntimeException("Error in specifying: " + VALIDATION_SAMPLE_PCT_LONG_NAME + "Should be between 0.0 and 100.0. It was " + _validationSamplePct);
}
} catch (NumberFormatException e) {
throw new RuntimeException("Error in specifying: " + VALIDATION_SAMPLE_PCT_LONG_NAME + " Exception:" + e);
}
} else {
_validationSamplePct = 100.0;
}
}
use of org.apache.commons.cli.Option in project databus by linkedin.
the class BootstrapDBCleanerMain 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 dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap Cleaner and DB properties to use").hasArg().withArgName("property_file").create(BOOTSTRAP_DB_PROP_OPT_CHAR);
Option cmdLinePropsOption1 = OptionBuilder.withLongOpt(CLEANER_CMD_LINE_PROPS_OPT_LONG_NAME).withDescription("Cmd line override of cleaner config properties. Semicolon separated.").hasArg().withArgName("Semicolon_separated_properties").create(CLEANER_CMD_LINE_PROPS_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);
Option sourcesOption = OptionBuilder.withLongOpt(BOOTSTRAP_SOURCES_OPT_LONG_NAME).withDescription("Comma seperated list of sourceNames. If not provided, no source will be cleaned up").hasArg().withArgName("comma-seperated sources").create(BOOTSTRAP_SOURCES_PROP_OPT_CHAR);
Options options = new Options();
options.addOption(helpOption);
options.addOption(dbOption);
options.addOption(cmdLinePropsOption1);
options.addOption(log4jPropsOption);
options.addOption(sourcesOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.error("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);
LOG.info("Using default logging settings");
}
if (cmd.hasOption(HELP_OPT_CHAR)) {
printCliHelp(options);
System.exit(0);
}
if (cmd.hasOption(BOOTSTRAP_SOURCES_PROP_OPT_CHAR)) {
_sSources = new ArrayList<String>();
String srcListStr = cmd.getOptionValue(BOOTSTRAP_SOURCES_PROP_OPT_CHAR);
LOG.info("Going to run cleaner for only these sources : " + srcListStr);
String[] srcList = srcListStr.split(",");
for (String s : srcList) _sSources.add(s);
}
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
throw new RuntimeException("Bootstrap config is not provided");
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream f = new FileInputStream(propFile);
try {
_sBootstrapConfigProps.load(f);
} finally {
f.close();
}
if (cmd.hasOption(CLEANER_CMD_LINE_PROPS_OPT_CHAR)) {
String cmdLinePropString = cmd.getOptionValue(CLEANER_CMD_LINE_PROPS_OPT_CHAR);
updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
}
}
use of org.apache.commons.cli.Option in project databus by linkedin.
the class BootstrapAddSource method parseArgs.
@SuppressWarnings("static-access")
public static Config parseArgs(String[] args) throws Exception {
CommandLineParser cliParser = new GnuParser();
Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_LONG_NAME).withDescription("Help screen").create(HELP_OPT_CHAR);
Option sourceIdOption = OptionBuilder.withLongOpt(SOURCE_ID_OPT_LONG_NAME).withDescription("Source ID for which tables need to be added").hasArg().withArgName("Source ID").create(SOURCE_ID_OPT_CHAR);
Option sourceNameOption = OptionBuilder.withLongOpt(SOURCE_NAME_OPT_LONG_NAME).withDescription("Source Name for which tables need to be added").hasArg().withArgName("Source ID").create(SOURCE_NAME_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 cmdLinePropsOption = OptionBuilder.withLongOpt(CMD_LINE_PROPS_OPT_LONG_NAME).withDescription("Cmd line override of config properties. Semicolon separated.").hasArg().withArgName("Semicolon_separated_properties").create(CMD_LINE_PROPS_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(sourceIdOption);
options.addOption(sourceNameOption);
options.addOption(dbOption);
options.addOption(cmdLinePropsOption);
options.addOption(log4jPropsOption);
CommandLine cmd = null;
try {
cmd = cliParser.parse(options, args);
} catch (ParseException pe) {
LOG.error("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);
LOG.info("Using default logging settings");
}
if (cmd.hasOption(HELP_OPT_CHAR)) {
printCliHelp(options);
System.exit(0);
}
if (!cmd.hasOption(SOURCE_ID_OPT_CHAR))
throw new RuntimeException("Source ID is not provided");
if (!cmd.hasOption(SOURCE_NAME_OPT_CHAR))
throw new RuntimeException("Source Name is not provided");
if (!cmd.hasOption(BOOTSTRAP_DB_PROP_OPT_CHAR))
throw new RuntimeException("Bootstrap config is not provided");
String propFile = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile);
_sBootstrapConfigProps = new Properties();
FileInputStream f = new FileInputStream(propFile);
try {
_sBootstrapConfigProps.load(f);
} finally {
f.close();
}
if (cmd.hasOption(CMD_LINE_PROPS_OPT_CHAR)) {
String cmdLinePropString = cmd.getOptionValue(CMD_LINE_PROPS_OPT_CHAR);
updatePropsFromCmdLine(_sBootstrapConfigProps, cmdLinePropString);
}
int srcId = Integer.parseInt(cmd.getOptionValue(SOURCE_ID_OPT_CHAR));
String srcName = cmd.getOptionValue(SOURCE_NAME_OPT_CHAR);
BootstrapConfig config = new BootstrapConfig();
ConfigLoader<BootstrapReadOnlyConfig> configLoader = new ConfigLoader<BootstrapReadOnlyConfig>("bootstrap.", config);
BootstrapReadOnlyConfig staticConfig = configLoader.loadConfig(_sBootstrapConfigProps);
Config cfg = new Config();
cfg.setDbConfig(staticConfig);
cfg.setSrcId(srcId);
cfg.setSrcName(srcName);
return cfg;
}
use of org.apache.commons.cli.Option in project Cloud9 by lintool.
the class CountClueWarcRecords method run.
/**
* Runs this tool.
*/
@SuppressWarnings("static-access")
public int run(String[] args) throws Exception {
Options options = new Options();
options.addOption(new Option(ORIGINAL_OPTION, "use original ClueWeb09 distribution"));
options.addOption(new Option(REPACKED_OPTION, "use repacked SequenceFiles"));
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("path: base path for 'original', actual path for 'repacked'").create(PATH_OPTION));
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("DocnoMapping data path").create(MAPPING_OPTION));
options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("segment number (required if 'original')").create(SEGMENT_OPTION));
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output file to write the number of records").create(COUNT_OPTION));
CommandLine cmdline;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (ParseException exp) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(this.getClass().getName(), options);
ToolRunner.printGenericCommandUsage(System.out);
System.err.println("Error parsing command line: " + exp.getMessage());
return -1;
}
boolean repacked;
if (cmdline.hasOption(REPACKED_OPTION)) {
repacked = true;
} else if (cmdline.hasOption(ORIGINAL_OPTION)) {
repacked = false;
} else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(this.getClass().getName(), options);
ToolRunner.printGenericCommandUsage(System.out);
System.err.println("Expecting either -original or -repacked");
return -1;
}
if (!cmdline.hasOption(PATH_OPTION) || !cmdline.hasOption(MAPPING_OPTION) || (!repacked && !cmdline.hasOption(SEGMENT_OPTION))) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(this.getClass().getName(), options);
ToolRunner.printGenericCommandUsage(System.out);
return -1;
}
String path = cmdline.getOptionValue(PATH_OPTION);
String mappingFile = cmdline.getOptionValue(MAPPING_OPTION);
int segment = 1;
if (!repacked) {
segment = Integer.parseInt(cmdline.getOptionValue(SEGMENT_OPTION));
}
LOG.info("Tool name: " + CountClueWarcRecords.class.getSimpleName());
LOG.info(" - repacked: " + repacked);
LOG.info(" - path: " + path);
LOG.info(" - mapping file: " + mappingFile);
if (!repacked) {
LOG.info(" - segment number: " + segment);
}
FileSystem fs = FileSystem.get(getConf());
int mapTasks = 10;
JobConf conf = new JobConf(getConf(), CountClueWarcRecords.class);
conf.setJobName(CountClueWarcRecords.class.getSimpleName() + (repacked ? ":" + path : ":segment" + segment));
conf.setNumMapTasks(mapTasks);
conf.setNumReduceTasks(0);
if (repacked) {
// thinks its a MapFile.
for (FileStatus status : fs.listStatus(new Path(path))) {
FileInputFormat.addInputPath(conf, status.getPath());
}
} else {
ClueCollectionPathConstants.addEnglishCollectionPart(conf, path, segment);
}
DistributedCache.addCacheFile(new URI(mappingFile), conf);
if (repacked) {
conf.setInputFormat(SequenceFileInputFormat.class);
} else {
conf.setInputFormat(ClueWarcInputFormat.class);
}
conf.setOutputFormat(NullOutputFormat.class);
conf.setMapperClass(MyMapper.class);
RunningJob job = JobClient.runJob(conf);
Counters counters = job.getCounters();
int numDocs = (int) counters.findCounter(Records.PAGES).getCounter();
LOG.info("Read " + numDocs + " docs.");
if (cmdline.hasOption(COUNT_OPTION)) {
String f = cmdline.getOptionValue(COUNT_OPTION);
FSDataOutputStream out = fs.create(new Path(f));
out.write(new Integer(numDocs).toString().getBytes());
out.close();
}
return 0;
}
use of org.apache.commons.cli.Option in project henplus by neurolabs.
the class ConnectCommand method getHandledCommandLineOptions.
@Override
public Collection<Option> getHandledCommandLineOptions() {
final Collection<Option> result = new LinkedList<Option>();
final Option option = new Option("J", "url", true, "JDBC URL to connect to");
option.setArgName("jdbc:...");
result.add(option);
final Option option2 = new Option("U", "username", true, "Username to connect with");
option2.setArgName("username");
result.add(option2);
final Option option3 = new Option("P", "password", true, "Password to connect with");
option3.setArgName("password");
result.add(option3);
return result;
}
Aggregations