use of org.apache.commons.cli.ParseException in project java-docs-samples by GoogleCloudPlatform.
the class BookstoreClient method main.
public static void main(String[] args) throws Exception {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine params;
try {
params = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Invalid command line: " + e.getMessage());
printUsage(options);
return;
}
String address = params.getOptionValue("bookstore", DEFAULT_ADDRESS);
String apiKey = params.getOptionValue("api_key");
String authToken = params.getOptionValue("auth_token");
String operation = params.getOptionValue("operation", "list");
// Create gRPC stub.
BookstoreGrpc.BookstoreBlockingStub bookstore = createBookstoreStub(address, apiKey, authToken);
if ("list".equals(operation)) {
listShelves(bookstore);
} else if ("create".equals(operation)) {
createShelf(bookstore);
} else if ("enumerate".equals(operation)) {
enumerate(bookstore);
}
}
use of org.apache.commons.cli.ParseException in project java-docs-samples by GoogleCloudPlatform.
the class BookstoreServer method main.
public static void main(String[] args) throws Exception {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine line;
try {
line = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Invalid command line: " + e.getMessage());
printUsage(options);
return;
}
int port = DEFAULT_PORT;
if (line.hasOption("port")) {
String portOption = line.getOptionValue("port");
try {
port = Integer.parseInt(portOption);
} catch (java.lang.NumberFormatException e) {
System.err.println("Invalid port number: " + portOption);
printUsage(options);
return;
}
}
final BookstoreData data = initializeBookstoreData();
final BookstoreServer server = new BookstoreServer();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
System.out.println("Shutting down");
server.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
});
server.start(port, data);
System.out.format("Bookstore service listening on %d\n", port);
server.blockUntilShutdown();
}
use of org.apache.commons.cli.ParseException in project bookkeeper by apache.
the class AutoRecoveryMain method parseArgs.
/*
* Parse console args
*/
private static ServerConfiguration parseArgs(String[] args) throws IllegalArgumentException {
try {
BasicParser parser = new BasicParser();
CommandLine cmdLine = parser.parse(opts, args);
if (cmdLine.hasOption('h')) {
throw new IllegalArgumentException();
}
ServerConfiguration conf = new ServerConfiguration();
String[] leftArgs = cmdLine.getArgs();
if (cmdLine.hasOption('c')) {
if (null != leftArgs && leftArgs.length > 0) {
throw new IllegalArgumentException();
}
String confFile = cmdLine.getOptionValue("c");
loadConfFile(conf, confFile);
}
if (null != leftArgs && leftArgs.length > 0) {
throw new IllegalArgumentException();
}
return conf;
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
use of org.apache.commons.cli.ParseException in project bookkeeper by apache.
the class Main method parseArgs.
private static ServerConfiguration parseArgs(String[] args) throws IllegalArgumentException {
try {
BasicParser parser = new BasicParser();
CommandLine cmdLine = parser.parse(BK_OPTS, args);
if (cmdLine.hasOption('h')) {
throw new IllegalArgumentException();
}
ServerConfiguration conf = new ServerConfiguration();
if (cmdLine.hasOption('c')) {
String confFile = cmdLine.getOptionValue("c");
loadConfFile(conf, confFile);
}
if (cmdLine.hasOption("withAutoRecovery")) {
conf.setAutoRecoveryDaemonEnabled(true);
}
if (cmdLine.hasOption("r")) {
conf.setForceReadOnlyBookie(true);
}
// command line arguments overwrite settings in configuration file
if (cmdLine.hasOption('z')) {
String sZK = cmdLine.getOptionValue('z');
log.info("Get cmdline zookeeper instance: {}", sZK);
conf.setZkServers(sZK);
}
if (cmdLine.hasOption('m')) {
String sZkLedgersRootPath = cmdLine.getOptionValue('m');
log.info("Get cmdline zookeeper ledger path: {}", sZkLedgersRootPath);
conf.setZkLedgersRootPath(sZkLedgersRootPath);
}
if (cmdLine.hasOption('p')) {
String sPort = cmdLine.getOptionValue('p');
log.info("Get cmdline bookie port: {}", sPort);
Integer iPort = Integer.parseInt(sPort);
conf.setBookiePort(iPort.intValue());
}
if (cmdLine.hasOption('j')) {
String sJournalDir = cmdLine.getOptionValue('j');
log.info("Get cmdline journal dir: {}", sJournalDir);
conf.setJournalDirName(sJournalDir);
}
if (cmdLine.hasOption('i')) {
String[] sIndexDirs = cmdLine.getOptionValues('i');
log.info("Get cmdline index dirs: ");
for (String index : sIndexDirs) {
log.info("indexDir : {}", index);
}
conf.setIndexDirName(sIndexDirs);
}
if (cmdLine.hasOption('l')) {
String[] sLedgerDirs = cmdLine.getOptionValues('l');
log.info("Get cmdline ledger dirs: ");
for (String ledger : sLedgerDirs) {
log.info("ledgerdir : {}", ledger);
}
conf.setLedgerDirNames(sLedgerDirs);
}
return conf;
} catch (ParseException e) {
log.error("Error parsing command line arguments : ", e);
throw new IllegalArgumentException(e);
}
}
use of org.apache.commons.cli.ParseException in project bookkeeper by apache.
the class BookkeeperVerifierMain method main.
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption("ledger_path", true, "Hostname or IP of bookie to benchmark");
options.addOption("zookeeper", true, "Zookeeper ensemble, (default \"localhost:2181\")");
options.addOption("ensemble_size", true, "Bookkeeper client ensemble size");
options.addOption("write_quorum", true, "Bookkeeper client write quorum size");
options.addOption("ack_quorum", true, "Bookkeeper client ack quorum size");
options.addOption("duration", true, "Run duration in seconds");
options.addOption("drainTimeout", true, "Seconds to wait for in progress ops to end");
options.addOption("target_concurrent_ledgers", true, "target number ledgers to write to concurrently");
options.addOption("target_concurrent_writes", true, "target number of concurrent writes per ledger");
options.addOption("target_write_group", true, "target number of entries to write at a time");
options.addOption("target_read_group", true, "target number of entries to read at a time");
options.addOption("target_ledgers", true, "Target number of ledgers");
options.addOption("target_ledger_size", true, "Target size per ledger");
options.addOption("target_entry_size", true, "Target size per entry");
options.addOption("target_concurrent_reads", true, "Number of reads to maintain");
options.addOption("cold_to_hot_ratio", true, "Ratio of reads on open ledgers");
options.addOption("help", false, "Print this help message");
CommandLineParser parser = new PosixParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
printHelpAndExit(options, "Unable to parse command line", 1);
}
if (cmd.hasOption("help")) {
printHelpAndExit(options, "Help:", 0);
}
String ledgerPath = cmd.getOptionValue("ledger_path", "/ledgers");
String zkString = cmd.getOptionValue("zookeeper", "localhost:2181");
int ensembleSize = 0;
int writeQuorum = 0;
int ackQuorum = 0;
int duration = 0;
int drainTimeout = 0;
int targetConcurrentLedgers = 0;
int targetConcurrentWrites = 0;
int targetWriteGroup = 0;
int targetReadGroup = 0;
int targetLedgers = 0;
long targetLedgerSize = 0;
int targetEntrySize = 0;
int targetConcurrentReads = 0;
double coldToHotRatio = 0;
try {
ensembleSize = Integer.parseInt(cmd.getOptionValue("ensemble_size", "3"));
writeQuorum = Integer.parseInt(cmd.getOptionValue("write_quorum", "3"));
ackQuorum = Integer.parseInt(cmd.getOptionValue("ack_quorum", "2"));
duration = Integer.parseInt(cmd.getOptionValue("duration", "600"));
drainTimeout = Integer.parseInt(cmd.getOptionValue("drain_timeout", "10"));
targetConcurrentLedgers = Integer.parseInt(cmd.getOptionValue("target_concurrent_ledgers", "4"));
targetConcurrentWrites = Integer.parseInt(cmd.getOptionValue("target_concurrent_writes", "12"));
targetWriteGroup = Integer.parseInt(cmd.getOptionValue("target_write_group", "4"));
targetReadGroup = Integer.parseInt(cmd.getOptionValue("target_read_group", "4"));
targetLedgers = Integer.parseInt(cmd.getOptionValue("target_ledgers", "32"));
targetLedgerSize = Long.parseLong(cmd.getOptionValue("target_ledger_size", "33554432"));
targetEntrySize = Integer.parseInt(cmd.getOptionValue("target_entry_size", "16384"));
targetConcurrentReads = Integer.parseInt(cmd.getOptionValue("target_concurrent_reads", "16"));
coldToHotRatio = Double.parseDouble(cmd.getOptionValue("cold_to_hot_ratio", "0.5"));
} catch (NumberFormatException e) {
printHelpAndExit(options, "Invalid argument", 0);
}
ClientConfiguration conf = new ClientConfiguration();
conf.setZkServers(zkString);
conf.setZkLedgersRootPath(ledgerPath);
BookKeeper bkclient = new BookKeeper(conf);
BookkeeperVerifier verifier = new BookkeeperVerifier(new DirectBookkeeperDriver(bkclient), ensembleSize, writeQuorum, ackQuorum, duration, drainTimeout, targetConcurrentLedgers, targetConcurrentWrites, targetWriteGroup, targetReadGroup, targetLedgers, targetLedgerSize, targetEntrySize, targetConcurrentReads, coldToHotRatio);
try {
verifier.run();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
bkclient.close();
}
}
Aggregations