use of org.apache.commons.cli.Option in project flink by apache.
the class ParameterTool method fromGenericOptionsParser.
/**
* Returns {@link ParameterTool} for the arguments parsed by {@link GenericOptionsParser}
*
* @param args Input array arguments. It should be parsable by {@link GenericOptionsParser}
* @return A {@link ParameterTool}
* @throws IOException If arguments cannot be parsed by {@link GenericOptionsParser}
* @see GenericOptionsParser
* @deprecated Please use {@link org.apache.flink.hadoopcompatibility.HadoopUtils#paramsFromGenericOptionsParser(String[])}
* from project flink-hadoop-compatibility
*/
@Deprecated
@PublicEvolving
public static ParameterTool fromGenericOptionsParser(String[] args) throws IOException {
Option[] options = new GenericOptionsParser(args).getCommandLine().getOptions();
Map<String, String> map = new HashMap<String, String>();
for (Option option : options) {
String[] split = option.getValue().split("=");
map.put(split[0], split[1]);
}
return fromMap(map);
}
use of org.apache.commons.cli.Option 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.Option 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.Option 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.Option in project databus by linkedin.
the class BootstrapTableReader 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(QUERY_CONFIG_OPT_LONG_NAME).withDescription("Query Config").hasArg().withArgName("property_file").create(QUERY_CONFIG_OPT_CHAR);
Option dbOption = OptionBuilder.withLongOpt(BOOTSTRAP_DB_PROPS_OPT_LONG_NAME).withDescription("Bootstrap DB 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);
LOG.info("Using default logging settings");
}
if (cmd.hasOption(HELP_OPT_CHAR)) {
printCliHelp(options);
System.exit(0);
}
if (!cmd.hasOption(QUERY_CONFIG_OPT_CHAR)) {
throw new RuntimeException("Query 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");
}
String propFile1 = cmd.getOptionValue(QUERY_CONFIG_OPT_CHAR);
String propFile2 = cmd.getOptionValue(BOOTSTRAP_DB_PROP_OPT_CHAR);
LOG.info("Loading bootstrap DB config from properties file " + propFile2);
_sQueryConfigProps = new Properties();
FileInputStream f1 = new FileInputStream(propFile1);
try {
_sQueryConfigProps.load(f1);
} finally {
f1.close();
}
_sBootstrapConfigProps = new Properties();
FileInputStream f2 = new FileInputStream(propFile2);
try {
_sBootstrapConfigProps.load(f2);
} finally {
f2.close();
}
}
Aggregations