use of org.apache.commons.cli.Options in project alluxio by Alluxio.
the class ApplicationMaster method main.
/**
* @param args Command line arguments to launch application master
*/
public static void main(String[] args) {
Options options = new Options();
options.addOption("num_workers", true, "Number of Alluxio workers to launch. Default 1");
options.addOption("master_address", true, "(Required) Address to run Alluxio master");
options.addOption("resource_path", true, "(Required) HDFS path containing the Application Master");
try {
LOG.info("Starting Application Master with args {}", Arrays.toString(args));
final CommandLine cliParser = new GnuParser().parse(options, args);
YarnConfiguration conf = new YarnConfiguration();
UserGroupInformation.setConfiguration(conf);
if (UserGroupInformation.isSecurityEnabled()) {
String user = System.getenv("ALLUXIO_USER");
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
for (Token token : UserGroupInformation.getCurrentUser().getTokens()) {
ugi.addToken(token);
}
LOG.info("UserGroupInformation: " + ugi);
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
runApplicationMaster(cliParser);
return null;
}
});
} else {
runApplicationMaster(cliParser);
}
} catch (Exception e) {
LOG.error("Error running Application Master", e);
System.exit(1);
}
}
use of org.apache.commons.cli.Options in project alluxio by Alluxio.
the class AlluxioFuse method parseOptions.
/**
* Parses CLI options.
*
* @param args CLI args
* @return Alluxio-FUSE configuration options
*/
private static AlluxioFuseOptions parseOptions(String[] args) {
final Options opts = new Options();
final Option mntPoint = Option.builder("m").hasArg().required(false).longOpt("mount-point").desc("Desired local mount point for alluxio-fuse.").build();
final Option alluxioRoot = Option.builder("r").hasArg().required(false).longOpt("alluxio-root").desc("Path within alluxio that will be used as the root of the FUSE mount " + "(e.g., /users/foo; defaults to /)").build();
final Option help = Option.builder("h").required(false).desc("Print this help").build();
final Option fuseOption = Option.builder("o").valueSeparator(',').required(false).hasArgs().desc("FUSE mount options").build();
opts.addOption(mntPoint);
opts.addOption(alluxioRoot);
opts.addOption(help);
opts.addOption(fuseOption);
final CommandLineParser parser = new DefaultParser();
try {
CommandLine cli = parser.parse(opts, args);
if (cli.hasOption("h")) {
final HelpFormatter fmt = new HelpFormatter();
fmt.printHelp(AlluxioFuse.class.getName(), opts);
return null;
}
String mntPointValue = cli.getOptionValue("m");
String alluxioRootValue = cli.getOptionValue("r");
List<String> fuseOpts = new ArrayList<>();
boolean noUserMaxWrite = true;
if (cli.hasOption("o")) {
String[] fopts = cli.getOptionValues("o");
// keep the -o
for (final String fopt : fopts) {
fuseOpts.add("-o" + fopt);
if (noUserMaxWrite && fopt.startsWith("max_write")) {
noUserMaxWrite = false;
}
}
}
// from conf
if (noUserMaxWrite) {
final long maxWrite = Configuration.getLong(PropertyKey.FUSE_MAXWRITE_BYTES);
fuseOpts.add(String.format("-omax_write=%d", maxWrite));
}
if (mntPointValue == null) {
mntPointValue = Configuration.get(PropertyKey.FUSE_MOUNT_DEFAULT);
LOG.info("Mounting on default {}", mntPointValue);
}
if (alluxioRootValue == null) {
alluxioRootValue = Configuration.get(PropertyKey.FUSE_FS_ROOT);
LOG.info("Using default alluxio root {}", alluxioRootValue);
}
final boolean fuseDebug = Configuration.getBoolean(PropertyKey.FUSE_DEBUG_ENABLED);
return new AlluxioFuseOptions(mntPointValue, alluxioRootValue, fuseDebug, fuseOpts);
} catch (ParseException e) {
System.err.println("Error while parsing CLI: " + e.getMessage());
final HelpFormatter fmt = new HelpFormatter();
fmt.printHelp(AlluxioFuse.class.getName(), opts);
return null;
}
}
use of org.apache.commons.cli.Options in project opennms by OpenNMS.
the class ConfigTester method main.
public static void main(String[] argv) {
FilterDaoFactory.setInstance(new ConfigTesterFilterDao());
DataSourceFactory.setInstance(new ConfigTesterDataSource());
ConfigTester tester = BeanUtils.getBean("configTesterContext", "configTester", ConfigTester.class);
final CommandLineParser parser = new PosixParser();
final Options options = new Options();
options.addOption("h", "help", false, "print this help and exit");
options.addOption("a", "all", false, "check all supported configuration files");
options.addOption("l", "list", false, "list supported configuration files and exit");
options.addOption("v", "verbose", false, "list each configuration file as it is tested");
options.addOption("i", "ignore-unknown", false, "ignore unknown configuration files and continue processing");
final CommandLine line;
try {
line = parser.parse(options, argv, false);
} catch (ParseException e) {
System.err.println("Invalid usage: " + e.getMessage());
System.err.println("Run 'config-tester -h' for help.");
System.exit(1);
// not reached; here to eliminate warning on line being uninitialized
return;
}
final boolean ignoreUnknown = line.hasOption("i");
if ((line.hasOption('l') || line.hasOption('h') || line.hasOption('a'))) {
if (line.getArgList().size() > 0) {
System.err.println("Invalid usage: No arguments allowed when using the '-a', '-h', or '-l' options.");
System.err.println("Run 'config-tester -h' for help.");
System.exit(1);
}
} else {
if (line.getArgs().length == 0) {
System.err.println("Invalid usage: too few arguments. Use the '-h' option for help.");
System.exit(1);
}
}
boolean verbose = line.hasOption('v');
DataSourceFactory.setInstance(new ConfigTesterDataSource());
if (line.hasOption('l')) {
System.out.println("Supported configuration files: ");
for (String configFile : tester.getConfigs().keySet()) {
System.out.println(" " + configFile);
}
System.out.println("Note: not all OpenNMS configuration files are currently supported.");
} else if (line.hasOption('h')) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("config-tester -a\nOR: config-tester [config files]\nOR: config-tester -l\nOR: config-tester -h", options);
} else if (line.hasOption('a')) {
for (String configFile : tester.getConfigs().keySet()) {
tester.testConfig(configFile, verbose, ignoreUnknown);
}
} else {
for (String configFile : line.getArgs()) {
tester.testConfig(configFile, verbose, ignoreUnknown);
}
}
}
use of org.apache.commons.cli.Options in project opennms by OpenNMS.
the class Main method parseArguments.
private void parseArguments(String[] args) throws ParseException {
Options options = new Options();
options.addOption("h", "help", false, "this help");
options.addOption("d", "debug", false, "write debug messages to the log");
options.addOption("g", "gui", false, "start a GUI (default: false)");
options.addOption("i", "disable-icmp", false, "disable ICMP/ping (overrides -Dorg.opennms.netmgt.icmp.pingerClass=)");
options.addOption("l", "location", true, "the location name of this remote poller");
options.addOption("u", "url", true, "the URL for OpenNMS (example: https://server-name/opennms-remoting)");
options.addOption("n", "name", true, "the name of the user to connect as");
options.addOption("p", "password", true, "the password to use when connecting");
options.addOption("s", "scan-report", false, "perform a single scan report instead of running the polling engine");
CommandLineParser parser = new PosixParser();
CommandLine cl = parser.parse(options, args);
if (cl.hasOption("h")) {
usage(options);
System.exit(1);
}
if (cl.hasOption("d")) {
}
if (cl.hasOption("i")) {
m_disableIcmp = true;
}
if (cl.hasOption("l")) {
m_locationName = cl.getOptionValue("l");
}
if (cl.hasOption("u")) {
String arg = cl.getOptionValue("u").toLowerCase();
try {
m_uri = new URI(arg);
} catch (URISyntaxException e) {
usage(options);
e.printStackTrace();
System.exit(2);
}
} else {
usage(options);
System.exit(3);
}
if (cl.hasOption("g")) {
m_gui = true;
}
if (cl.hasOption("s")) {
m_scanReport = true;
}
if (cl.hasOption("n")) {
m_username = cl.getOptionValue("n");
m_password = cl.getOptionValue("p");
if (m_password == null) {
m_password = "";
}
}
// to optionally get it from system properties
if (m_username == null) {
m_username = System.getProperty("opennms.poller.server.username");
if (m_username != null) {
m_password = System.getProperty("opennms.poller.server.password");
if (m_password == null) {
m_password = "";
}
}
}
}
use of org.apache.commons.cli.Options in project opennms by OpenNMS.
the class Mib2Events method parseCli.
public void parseCli(String[] argv) {
Options opts = new Options();
opts.addOption("m", "mib", true, "Pathname or URL of MIB file to scan for traps");
opts.addOption("b", "ueibase", true, "Base UEI for resulting events");
opts.addOption("c", "compat", false, "Turn on compatibility mode to create output as similar to mib2opennms as possible");
CommandLineParser parser = new GnuParser();
try {
CommandLine cmd = parser.parse(opts, argv);
if (cmd.hasOption('m')) {
m_mibLocation = cmd.getOptionValue('m');
} else {
printHelp("You must specify a MIB file pathname or URL");
System.exit(1);
}
if (cmd.hasOption("b")) {
m_ueiBase = cmd.getOptionValue('b');
}
if (cmd.hasOption("c")) {
m_compat = true;
}
} catch (ParseException e) {
printHelp("Failed to parse command line options");
System.exit(1);
}
}
Aggregations