use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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' & '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 => 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 <TABLE> <SPLITALGORITHM>
* <-c <# regions> -f <family:family:...> | -r
* [-o <# outstanding splits>]>
* [-D <conf.param=value>]
* @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);
}
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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;
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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;
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine in project hbase by apache.
the class LoadTestTool method newParser.
@Override
protected CommandLineParser newParser() {
// Validate in parse() to get helpful error messages instead of exploding in processOptions()
return new DefaultParser() {
@Override
public CommandLine parse(Options opts, String[] args, Properties props, boolean stop) throws ParseException {
CommandLine cl = super.parse(opts, args, props, stop);
boolean isReadWriteUpdate = cmd.hasOption(OPT_READ) || cmd.hasOption(OPT_WRITE) || cmd.hasOption(OPT_UPDATE);
boolean isInitOnly = cmd.hasOption(OPT_INIT_ONLY);
if (!isInitOnly && !isReadWriteUpdate) {
throw new MissingOptionException("Must specify either -" + OPT_INIT_ONLY + " or at least one of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
}
if (isInitOnly && isReadWriteUpdate) {
throw new AlreadySelectedException(OPT_INIT_ONLY + " cannot be specified with any of -" + OPT_READ + ", -" + OPT_WRITE + ", -" + OPT_UPDATE);
}
if (isReadWriteUpdate && !cmd.hasOption(OPT_NUM_KEYS)) {
throw new MissingOptionException(OPT_NUM_KEYS + " must be specified in read/write mode.");
}
return cl;
}
};
}
use of org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine 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);
}
}
Aggregations