Search in sources :

Example 11 with Options

use of org.apache.hbase.thirdparty.org.apache.commons.cli.Options 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 12 with Options

use of org.apache.hbase.thirdparty.org.apache.commons.cli.Options 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 13 with Options

use of org.apache.hbase.thirdparty.org.apache.commons.cli.Options 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 14 with Options

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

the class AbstractHBaseTool method isHelpCommand.

private boolean isHelpCommand(String[] args) throws ParseException {
    Options helpOption = new Options().addOption(HELP_OPTION);
    // this parses the command line but doesn't throw an exception on unknown options
    CommandLine cl = new DefaultParser().parse(helpOption, args, true);
    return cl.getOptions().length != 0;
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 15 with Options

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

the class ChaosService method getOptions.

private static Options getOptions() {
    Options options = new Options();
    options.addOption(new Option("c", ChaosServiceName.CHAOSAGENT.toString().toLowerCase(), true, "expecting a start/stop argument"));
    options.addOption(new Option("D", ChaosServiceName.GENERIC.toString(), true, "generic D param"));
    LOG.info(Arrays.toString(new Collection[] { options.getOptions() }));
    return options;
}
Also used : Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) Collection(java.util.Collection) Option(org.apache.hbase.thirdparty.org.apache.commons.cli.Option)

Aggregations

Options (org.apache.hbase.thirdparty.org.apache.commons.cli.Options)19 CommandLine (org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine)14 ParseException (org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException)10 DefaultParser (org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)8 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 HelpFormatter (org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter)4 ArrayList (java.util.ArrayList)3 GnuParser (org.apache.hbase.thirdparty.org.apache.commons.cli.GnuParser)3 PosixParser (org.apache.hbase.thirdparty.org.apache.commons.cli.PosixParser)3 List (java.util.List)2 Path (org.apache.hadoop.fs.Path)2 TableName (org.apache.hadoop.hbase.TableName)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1