use of org.apache.commons.cli.DefaultParser in project athenz by yahoo.
the class ZMSTLSClient method parseCommandLine.
private static CommandLine parseCommandLine(String[] args) {
Options options = new Options();
Option resource = new Option("r", "resource", true, "resource value");
resource.setRequired(true);
options.addOption(resource);
Option action = new Option("a", "action", true, "action");
action.setRequired(true);
options.addOption(action);
Option principal = new Option("u", "principal", true, "principal to check for");
principal.setRequired(true);
options.addOption(principal);
Option key = new Option("k", "key", true, "private key path");
key.setRequired(true);
options.addOption(key);
Option cert = new Option("c", "cert", true, "certficate path");
cert.setRequired(true);
options.addOption(cert);
Option trustStore = new Option("t", "trustStorePath", true, "CA TrustStore path");
trustStore.setRequired(true);
options.addOption(trustStore);
Option trustStorePassword = new Option("p", "trustStorePassword", true, "CA TrustStore password");
trustStorePassword.setRequired(true);
options.addOption(trustStorePassword);
Option zmsUrl = new Option("z", "zmsurl", true, "ZMS Server url");
zmsUrl.setRequired(true);
options.addOption(zmsUrl);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("zms-tls-client", options);
System.exit(1);
}
return cmd;
}
use of org.apache.commons.cli.DefaultParser in project athenz by yahoo.
the class InstanceClientRegister method parseCommandLine.
private static CommandLine parseCommandLine(String[] args) {
Options options = new Options();
Option domain = new Option("d", "domain", true, "domain name");
domain.setRequired(true);
options.addOption(domain);
Option service = new Option("s", "service", true, "service name");
service.setRequired(true);
options.addOption(service);
Option provider = new Option("p", "provider", true, "provider name");
provider.setRequired(true);
options.addOption(provider);
Option instance = new Option("i", "instance", true, "instance id");
instance.setRequired(true);
options.addOption(instance);
Option dnsSuffix = new Option("dns", "dnssuffix", true, "provider dns suffix");
dnsSuffix.setRequired(true);
options.addOption(dnsSuffix);
Option providerKey = new Option("pk", "providerkey", true, "provider private key path");
providerKey.setRequired(true);
options.addOption(providerKey);
Option keyId = new Option("pkid", "providerkeyid", true, "provider private key identifier");
keyId.setRequired(true);
options.addOption(keyId);
Option instanceKey = new Option("ik", "instancekey", true, "instance private key path");
instanceKey.setRequired(true);
options.addOption(instanceKey);
Option ztsUrl = new Option("z", "ztsurl", true, "ZTS Server url");
ztsUrl.setRequired(true);
options.addOption(ztsUrl);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("instance-client", options);
System.exit(1);
}
return cmd;
}
use of org.apache.commons.cli.DefaultParser in project storm by apache.
the class KafkaOffsetLagUtil method main.
public static void main(String[] args) {
try {
List<KafkaOffsetLagResult> results;
Options options = buildOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (!commandLine.hasOption(OPTION_TOPIC_LONG)) {
printUsageAndExit(options, OPTION_TOPIC_LONG + " is required");
}
if (commandLine.hasOption(OPTION_OLD_CONSUMER_LONG)) {
OldKafkaSpoutOffsetQuery oldKafkaSpoutOffsetQuery;
if (commandLine.hasOption(OPTION_GROUP_ID_LONG) || commandLine.hasOption(OPTION_BOOTSTRAP_BROKERS_LONG) || commandLine.hasOption(OPTION_SECURITY_PROTOCOL_LONG)) {
printUsageAndExit(options, OPTION_GROUP_ID_LONG + " or " + OPTION_BOOTSTRAP_BROKERS_LONG + " or " + OPTION_SECURITY_PROTOCOL_LONG + " is " + "not accepted with option " + OPTION_OLD_CONSUMER_LONG);
}
if (!commandLine.hasOption(OPTION_ZK_SERVERS_LONG) || !commandLine.hasOption(OPTION_ZK_COMMITTED_NODE_LONG)) {
printUsageAndExit(options, OPTION_ZK_SERVERS_LONG + " and " + OPTION_ZK_COMMITTED_NODE_LONG + " are required with " + OPTION_OLD_CONSUMER_LONG);
}
String[] topics = commandLine.getOptionValue(OPTION_TOPIC_LONG).split(",");
if (topics != null && topics.length > 1) {
printUsageAndExit(options, "Multiple topics not supported with option " + OPTION_OLD_CONSUMER_LONG + ". Either a single topic or a " + "wildcard string for matching topics is supported");
}
if (commandLine.hasOption(OPTION_ZK_BROKERS_ROOT_LONG)) {
if (commandLine.hasOption(OPTION_PARTITIONS_LONG) || commandLine.hasOption(OPTION_LEADERS_LONG)) {
printUsageAndExit(options, OPTION_PARTITIONS_LONG + " or " + OPTION_LEADERS_LONG + " is not accepted with " + OPTION_ZK_BROKERS_ROOT_LONG);
}
oldKafkaSpoutOffsetQuery = new OldKafkaSpoutOffsetQuery(commandLine.getOptionValue(OPTION_TOPIC_LONG), commandLine.getOptionValue(OPTION_ZK_SERVERS_LONG), commandLine.getOptionValue(OPTION_ZK_COMMITTED_NODE_LONG), commandLine.hasOption(OPTION_TOPIC_WILDCARD_LONG), commandLine.getOptionValue(OPTION_ZK_BROKERS_ROOT_LONG));
} else {
if (commandLine.hasOption(OPTION_TOPIC_WILDCARD_LONG)) {
printUsageAndExit(options, OPTION_TOPIC_WILDCARD_LONG + " is not supported without " + OPTION_ZK_BROKERS_ROOT_LONG);
}
if (!commandLine.hasOption(OPTION_PARTITIONS_LONG) || !commandLine.hasOption(OPTION_LEADERS_LONG)) {
printUsageAndExit(options, OPTION_PARTITIONS_LONG + " and " + OPTION_LEADERS_LONG + " are required if " + OPTION_ZK_BROKERS_ROOT_LONG + " is not provided");
}
String[] partitions = commandLine.getOptionValue(OPTION_PARTITIONS_LONG).split(",");
String[] leaders = commandLine.getOptionValue(OPTION_LEADERS_LONG).split(",");
if (partitions.length != leaders.length) {
printUsageAndExit(options, OPTION_PARTITIONS_LONG + " and " + OPTION_LEADERS_LONG + " need to be of same size");
}
oldKafkaSpoutOffsetQuery = new OldKafkaSpoutOffsetQuery(commandLine.getOptionValue(OPTION_TOPIC_LONG), commandLine.getOptionValue(OPTION_ZK_SERVERS_LONG), commandLine.getOptionValue(OPTION_ZK_COMMITTED_NODE_LONG), commandLine.getOptionValue(OPTION_PARTITIONS_LONG), commandLine.getOptionValue(OPTION_LEADERS_LONG));
}
results = getOffsetLags(oldKafkaSpoutOffsetQuery);
} else {
String securityProtocol = commandLine.getOptionValue(OPTION_SECURITY_PROTOCOL_LONG);
String[] oldSpoutOptions = { OPTION_TOPIC_WILDCARD_LONG, OPTION_PARTITIONS_LONG, OPTION_LEADERS_LONG, OPTION_ZK_SERVERS_LONG, OPTION_ZK_COMMITTED_NODE_LONG, OPTION_ZK_BROKERS_ROOT_LONG };
for (String oldOption : oldSpoutOptions) {
if (commandLine.hasOption(oldOption)) {
printUsageAndExit(options, oldOption + " is not accepted without " + OPTION_OLD_CONSUMER_LONG);
}
}
if (!commandLine.hasOption(OPTION_GROUP_ID_LONG) || !commandLine.hasOption(OPTION_BOOTSTRAP_BROKERS_LONG)) {
printUsageAndExit(options, OPTION_GROUP_ID_LONG + " and " + OPTION_BOOTSTRAP_BROKERS_LONG + " are required if " + OPTION_OLD_CONSUMER_LONG + " is not specified");
}
NewKafkaSpoutOffsetQuery newKafkaSpoutOffsetQuery = new NewKafkaSpoutOffsetQuery(commandLine.getOptionValue(OPTION_TOPIC_LONG), commandLine.getOptionValue(OPTION_BOOTSTRAP_BROKERS_LONG), commandLine.getOptionValue(OPTION_GROUP_ID_LONG), securityProtocol);
results = getOffsetLags(newKafkaSpoutOffsetQuery);
}
Map<String, Map<Integer, KafkaPartitionOffsetLag>> keyedResult = keyByTopicAndPartition(results);
System.out.print(JSONValue.toJSONString(keyedResult));
} catch (Exception ex) {
System.out.print("Unable to get offset lags for kafka. Reason: ");
ex.printStackTrace(System.out);
}
}
use of org.apache.commons.cli.DefaultParser in project moco by dreamhead.
the class ShutdownArgs method parse.
public static ShutdownArgs parse(final String[] args) {
try {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(createShutdownOptions(), args);
return new ShutdownArgs(StartArgsParser.getPort(cmd.getOptionValue("s")));
} catch (ParseException e) {
throw new ParseArgException("fail to parse arguments", e);
}
}
use of org.apache.commons.cli.DefaultParser in project moco by dreamhead.
the class StartArgsParser method doParse.
private StartArgs doParse(final String[] args) throws ParseException {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options(), args);
return parseArgs(cmd);
}
Aggregations