Search in sources :

Example 6 with ParseException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException in project hbase by apache.

the class MajorCompactorTTL method run.

@Override
public int run(String[] args) throws Exception {
    Options options = getOptions();
    final CommandLineParser cmdLineParser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = cmdLineParser.parse(options, args);
    } catch (ParseException parseException) {
        System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
        printUsage(options);
        return -1;
    }
    if (commandLine == null) {
        System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
        printUsage(options);
        return -1;
    }
    String table = commandLine.getOptionValue("table");
    int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
    int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
    int concurrency = Integer.parseInt(commandLine.getOptionValue("servers", "1"));
    long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
    boolean dryRun = commandLine.hasOption("dryRun");
    boolean skipWait = commandLine.hasOption("skipWait");
    return compactRegionsTTLOnTable(HBaseConfiguration.create(), table, concurrency, sleep, numServers, numRegions, dryRun, skipWait);
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 7 with ParseException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException in project hbase by apache.

the class RSGroupMajorCompactionTTL method run.

@Override
public int run(String[] args) throws Exception {
    Options options = getOptions();
    final CommandLineParser cmdLineParser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = cmdLineParser.parse(options, args);
    } catch (ParseException parseException) {
        System.out.println("ERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + parseException);
        printUsage(options);
        return -1;
    }
    if (commandLine == null) {
        System.out.println("ERROR: Failed parse, empty commandLine; " + Arrays.toString(args));
        printUsage(options);
        return -1;
    }
    String rsgroup = commandLine.getOptionValue("rsgroup");
    int numServers = Integer.parseInt(commandLine.getOptionValue("numservers", "-1"));
    int numRegions = Integer.parseInt(commandLine.getOptionValue("numregions", "-1"));
    int concurrency = Integer.parseInt(commandLine.getOptionValue("servers", "1"));
    long sleep = Long.parseLong(commandLine.getOptionValue("sleep", Long.toString(30000)));
    boolean dryRun = commandLine.hasOption("dryRun");
    boolean skipWait = commandLine.hasOption("skipWait");
    Configuration conf = getConf();
    return compactTTLRegionsOnGroup(conf, rsgroup, concurrency, sleep, numServers, numRegions, dryRun, skipWait);
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CommandLineParser(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 8 with ParseException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException in project hbase by apache.

the class RegionSplitter method main.

/**
 * The main function for the RegionSplitter application. Common uses:
 * <p>
 * <ul>
 * <li>create a table named 'myTable' with 60 pre-split regions containing 2
 * column families 'test' &amp; 'rs', assuming the keys are hex-encoded ASCII:
 * <ul>
 * <li>bin/hbase org.apache.hadoop.hbase.util.RegionSplitter -c 60 -f test:rs
 * myTable HexStringSplit
 * </ul>
 * <li>create a table named 'myTable' with 50 pre-split regions,
 * assuming the keys are decimal-encoded ASCII:
 * <ul>
 * <li>bin/hbase org.apache.hadoop.hbase.util.RegionSplitter -c 50
 * myTable DecimalStringSplit
 * </ul>
 * <li>perform a rolling split of 'myTable' (i.e. 60 =&gt; 120 regions), # 2
 * outstanding splits at a time, assuming keys are uniformly distributed
 * bytes:
 * <ul>
 * <li>bin/hbase org.apache.hadoop.hbase.util.RegionSplitter -r -o 2 myTable
 * UniformSplit
 * </ul>
 * </ul>
 *
 * There are three SplitAlgorithms built into RegionSplitter, HexStringSplit,
 * DecimalStringSplit, and UniformSplit. These are different strategies for
 * choosing region boundaries. See their source code for details.
 *
 * @param args
 *          Usage: RegionSplitter &lt;TABLE&gt; &lt;SPLITALGORITHM&gt;
 *          &lt;-c &lt;# regions&gt; -f &lt;family:family:...&gt; | -r
 *          [-o &lt;# outstanding splits&gt;]&gt;
 *          [-D &lt;conf.param=value&gt;]
 * @throws IOException
 *           HBase IO problem
 * @throws InterruptedException
 *           user requested exit
 * @throws ParseException
 *           problem parsing user input
 */
@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, InterruptedException, ParseException {
    Configuration conf = HBaseConfiguration.create();
    // parse user input
    Options opt = new Options();
    opt.addOption(OptionBuilder.withArgName("property=value").hasArg().withDescription("Override HBase Configuration Settings").create("D"));
    opt.addOption(OptionBuilder.withArgName("region count").hasArg().withDescription("Create a new table with a pre-split number of regions").create("c"));
    opt.addOption(OptionBuilder.withArgName("family:family:...").hasArg().withDescription("Column Families to create with new table.  Required with -c").create("f"));
    opt.addOption("h", false, "Print this usage help");
    opt.addOption("r", false, "Perform a rolling split of an existing region");
    opt.addOption(OptionBuilder.withArgName("count").hasArg().withDescription("Max outstanding splits that have unfinished major compactions").create("o"));
    opt.addOption(null, "firstrow", true, "First Row in Table for Split Algorithm");
    opt.addOption(null, "lastrow", true, "Last Row in Table for Split Algorithm");
    opt.addOption(null, "risky", false, "Skip verification steps to complete quickly. " + "STRONGLY DISCOURAGED for production systems.  ");
    CommandLine cmd = new GnuParser().parse(opt, args);
    if (cmd.hasOption("D")) {
        for (String confOpt : cmd.getOptionValues("D")) {
            String[] kv = confOpt.split("=", 2);
            if (kv.length == 2) {
                conf.set(kv[0], kv[1]);
                LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]);
            } else {
                throw new ParseException("-D option format invalid: " + confOpt);
            }
        }
    }
    if (cmd.hasOption("risky")) {
        conf.setBoolean("split.verify", false);
    }
    boolean createTable = cmd.hasOption("c") && cmd.hasOption("f");
    boolean rollingSplit = cmd.hasOption("r");
    boolean oneOperOnly = createTable ^ rollingSplit;
    if (2 != cmd.getArgList().size() || !oneOperOnly || cmd.hasOption("h")) {
        new HelpFormatter().printHelp("bin/hbase regionsplitter <TABLE> <SPLITALGORITHM>\n" + "SPLITALGORITHM is the java class name of a class implementing " + "SplitAlgorithm, or one of the special strings HexStringSplit or " + "DecimalStringSplit or UniformSplit, which are built-in split algorithms. " + "HexStringSplit treats keys as hexadecimal ASCII, and " + "DecimalStringSplit treats keys as decimal ASCII, and " + "UniformSplit treats keys as arbitrary bytes.", opt);
        return;
    }
    TableName tableName = TableName.valueOf(cmd.getArgs()[0]);
    String splitClass = cmd.getArgs()[1];
    SplitAlgorithm splitAlgo = newSplitAlgoInstance(conf, splitClass);
    if (cmd.hasOption("firstrow")) {
        splitAlgo.setFirstRow(cmd.getOptionValue("firstrow"));
    }
    if (cmd.hasOption("lastrow")) {
        splitAlgo.setLastRow(cmd.getOptionValue("lastrow"));
    }
    if (createTable) {
        conf.set("split.count", cmd.getOptionValue("c"));
        createPresplitTable(tableName, splitAlgo, cmd.getOptionValue("f").split(":"), conf);
    }
    if (rollingSplit) {
        if (cmd.hasOption("o")) {
            conf.set("split.outstanding", cmd.getOptionValue("o"));
        }
        rollingSplit(tableName, splitAlgo, conf);
    }
}
Also used : HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) TableName(org.apache.hadoop.hbase.TableName) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) GnuParser(org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Example 9 with ParseException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException in project hbase by apache.

the class AbstractHBaseTool method run.

@Override
public int run(String[] args) throws IOException {
    cmdLineArgs = args;
    Objects.requireNonNull(conf, "Tool configuration is not initialized");
    CommandLine cmd;
    List<String> argsList = new ArrayList<>(args.length);
    for (String arg : args) {
        argsList.add(arg);
    }
    // For backward compatibility of args which can't be parsed as Option. See javadoc for
    // processOldArgs(..)
    processOldArgs(argsList);
    try {
        addOptions();
        if (isHelpCommand(args)) {
            printUsage();
            return EXIT_SUCCESS;
        }
        String[] remainingArgs = new String[argsList.size()];
        argsList.toArray(remainingArgs);
        cmd = newParser().parse(options, remainingArgs);
    } catch (MissingOptionException e) {
        LOG.error(e.getMessage());
        LOG.error("Use -h or --help for usage instructions.");
        return EXIT_FAILURE;
    } catch (ParseException e) {
        LOG.error("Error when parsing command-line arguments", e);
        LOG.error("Use -h or --help for usage instructions.");
        return EXIT_FAILURE;
    }
    processOptions(cmd);
    int ret;
    try {
        ret = doWork();
    } catch (Exception e) {
        LOG.error("Error running command-line tool", e);
        return EXIT_FAILURE;
    }
    return ret;
}
Also used : CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException) MissingOptionException(org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException) IOException(java.io.IOException) MissingOptionException(org.apache.hbase.thirdparty.org.apache.commons.cli.MissingOptionException) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Example 10 with ParseException

use of org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException in project hbase by apache.

the class RESTServer method parseCommandLine.

private static void parseCommandLine(String[] args, Configuration conf) {
    Options options = new Options();
    options.addOption("p", "port", true, "Port to bind to [default: " + DEFAULT_LISTEN_PORT + "]");
    options.addOption("ro", "readonly", false, "Respond only to GET HTTP " + "method requests [default: false]");
    options.addOption("i", "infoport", true, "Port for WEB UI");
    CommandLine commandLine = null;
    try {
        commandLine = new PosixParser().parse(options, args);
    } catch (ParseException e) {
        LOG.error("Could not parse: ", e);
        printUsageAndExit(options, -1);
    }
    // check for user-defined port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("port")) {
        String val = commandLine.getOptionValue("port");
        conf.setInt("hbase.rest.port", Integer.parseInt(val));
        if (LOG.isDebugEnabled()) {
            LOG.debug("port set to " + val);
        }
    }
    // check if server should only process GET requests, if so override the conf
    if (commandLine != null && commandLine.hasOption("readonly")) {
        conf.setBoolean("hbase.rest.readonly", true);
        if (LOG.isDebugEnabled()) {
            LOG.debug("readonly set to true");
        }
    }
    // check for user-defined info server port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("infoport")) {
        String val = commandLine.getOptionValue("infoport");
        conf.setInt("hbase.rest.info.port", Integer.parseInt(val));
        if (LOG.isDebugEnabled()) {
            LOG.debug("WEB UI port set to " + val);
        }
    }
    if (commandLine != null && commandLine.hasOption("skipLogin")) {
        conf.setBoolean(SKIP_LOGIN_KEY, true);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Skipping Kerberos login for REST server");
        }
    }
    List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<>();
    if (remainingArgs.size() != 1) {
        printUsageAndExit(options, 1);
    }
    String command = remainingArgs.get(0);
    if ("start".equals(command)) {
    // continue and start container
    } else if ("stop".equals(command)) {
        System.exit(1);
    } else {
        printUsageAndExit(options, 1);
    }
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) PosixParser(org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser) ParseException(org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)

Aggregations

CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)12 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)12 Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)10 Configuration (org.apache.hadoop.conf.Configuration)7 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)7 CommandLineParser (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser)6 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)4 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)4 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)4 ArrayList (java.util.ArrayList)3 Path (org.apache.hadoop.fs.Path)3 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)3 FileSystem (org.apache.hadoop.fs.FileSystem)2 TableName (org.apache.hadoop.hbase.TableName)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Scanner (java.util.Scanner)1