org.apache.hbase.thirdparty.org.apache.commons.cli.Option.getOpt()

Here are the examples of the java api org.apache.hbase.thirdparty.org.apache.commons.cli.Option.getOpt() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

17 Source : HBCK2.java
with Apache License 2.0
from apache

/**
 * @return List of results OR null if failed to run.
 */
private List<Boolean> bypreplaced(String[] args) throws IOException {
    // Bypreplaced has two options....
    Options options = new Options();
    // See usage for 'help' on these options.
    Option override = Option.builder("o").longOpt("override").build();
    options.addOption(override);
    Option recursive = Option.builder("r").longOpt("recursive").build();
    options.addOption(recursive);
    Option wait = Option.builder("w").longOpt("lockWait").hasArg().type(Integer.clreplaced).build();
    options.addOption(wait);
    // Parse command-line.
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args, false);
    } catch (ParseException e) {
        showErrorMessage(e.getMessage());
        return null;
    }
    long lockWait = DEFAULT_LOCK_WAIT;
    if (commandLine.hasOption(wait.getOpt())) {
        lockWait = Integer.parseInt(commandLine.getOptionValue(wait.getOpt()));
    }
    String[] pidStrs = commandLine.getArgs();
    if (pidStrs == null || pidStrs.length <= 0) {
        showErrorMessage("No pids supplied.");
        return null;
    }
    boolean overrideFlag = commandLine.hasOption(override.getOpt());
    boolean recursiveFlag = commandLine.hasOption(recursive.getOpt());
    List<Long> pids = Arrays.stream(pidStrs).map(Long::valueOf).collect(Collectors.toList());
    try (ClusterConnection connection = connect();
        Hbck hbck = connection.getHbck()) {
        checkFunctionSupported(connection, BYPreplaced);
        return hbck.bypreplacedProcedure(pids, lockWait, overrideFlag, recursiveFlag);
    }
}

16 Source : HBCK2.java
with Apache License 2.0
from apache

/**
 * Process command line general options.
 */
@Override
public int run(String[] args) throws IOException {
    // Configure Options. The below article was more helpful than the commons-cli doc:
    // https://dzone.com/articles/java-command-line-interfaces-part-1-apache-commons
    Options options = new Options();
    Option help = Option.builder("h").longOpt("help").desc("output this help message").build();
    options.addOption(help);
    Option debug = Option.builder("d").longOpt("debug").desc("run with debug output").build();
    options.addOption(debug);
    Option quorum = Option.builder("q").longOpt(HConstants.ZOOKEEPER_QUORUM).hasArg().desc("hbase ensemble").build();
    options.addOption(quorum);
    Option parent = Option.builder("z").longOpt(HConstants.ZOOKEEPER_ZNODE_PARENT).hasArg().desc("parent znode of hbase ensemble").build();
    options.addOption(parent);
    Option peerPort = Option.builder("p").longOpt(HConstants.ZOOKEEPER_CLIENT_PORT).hasArg().desc("port of hbase ensemble").type(Integer.clreplaced).build();
    options.addOption(peerPort);
    Option version = Option.builder("v").longOpt(VERSION).desc("this hbck2 version").build();
    options.addOption(version);
    Option skip = Option.builder("s").longOpt("skip").desc("skip hbase version check (PleaseHoldException)").build();
    options.addOption(skip);
    // Parse command-line.
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args, true);
    } catch (ParseException e) {
        showErrorMessage(e.getMessage());
        return EXIT_FAILURE;
    }
    // Process general options.
    if (commandLine.hasOption(version.getOpt())) {
        System.out.println(readHBCK2BuildProperties(VERSION));
        return EXIT_SUCCESS;
    }
    if (commandLine.hasOption(help.getOpt()) || commandLine.getArgList().isEmpty()) {
        showUsage(options);
        return EXIT_SUCCESS;
    }
    if (commandLine.hasOption(debug.getOpt())) {
        Configurator.setRootLevel(Level.DEBUG);
    }
    // Build up Configuration for client to use connecting to hbase zk ensemble.
    if (commandLine.hasOption(quorum.getOpt())) {
        getConf().set(HConstants.ZOOKEEPER_QUORUM, commandLine.getOptionValue(quorum.getOpt()));
    }
    if (commandLine.hasOption(peerPort.getOpt())) {
        String optionValue = commandLine.getOptionValue(peerPort.getOpt());
        if (optionValue.matches("[0-9]+")) {
            getConf().setInt(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.parseInt(optionValue));
        } else {
            showErrorMessage("Invalid client port. Please provide proper port for target hbase ensemble.");
            return EXIT_FAILURE;
        }
    }
    if (commandLine.hasOption(parent.getOpt())) {
        String optionValue = commandLine.getOptionValue(parent.getOpt());
        if (optionValue.startsWith("/")) {
            getConf().set(HConstants.ZOOKEEPER_ZNODE_PARENT, optionValue);
        } else {
            showErrorMessage("Invalid parent znode. Please provide proper parent znode of target hbase." + " Note that valid znodes must start with \"/\".");
            return EXIT_FAILURE;
        }
    }
    if (commandLine.hasOption(skip.getOpt())) {
        skipCheck = true;
    }
    return doCommandLine(commandLine, options);
}