Package org.apache.hadoop.hbase.util
Class AbstractHBaseTool
java.lang.Object
org.apache.hadoop.hbase.util.AbstractHBaseTool
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable,org.apache.hadoop.util.Tool
- Direct Known Subclasses:
BackupDriver,CoprocessorValidator,CreateSnapshot,DataBlockEncodingValidator,ExportSnapshot,HFileContentValidator,HFileProcedurePrettyPrinter,RegionMover,RegionVisualizer,RestoreDriver,RowCounter,SnapshotInfo,WALProcedurePrettyPrinter
@Private
public abstract class AbstractHBaseTool
extends Object
implements org.apache.hadoop.util.Tool
Common base class used for HBase command-line tools. Simplifies workflow and command-line
argument parsing.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]protected org.apache.hadoop.conf.Configurationstatic final intstatic final intprivate static final org.apache.hbase.thirdparty.org.apache.commons.cli.Optionprivate static final org.slf4j.Loggerstatic final Stringprotected final org.apache.hbase.thirdparty.org.apache.commons.cli.Optionsprivate intstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddOption(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option) protected abstract voidOverride this to add command-line options usingaddOptWithArg(java.lang.String, java.lang.String)and similar methods.protected voidaddOptNoArg(String opt, String description) protected voidaddOptNoArg(String shortOpt, String longOpt, String description) protected voidaddOptWithArg(String opt, String description) protected voidaddOptWithArg(String shortOpt, String longOpt, String description) protected voidaddRequiredOption(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option) protected voidaddRequiredOptWithArg(String opt, String description) protected voidaddRequiredOptWithArg(String shortOpt, String longOpt, String description) protected voiddoStaticMain(String[] args) Call this from the concrete tool class's main function.protected abstract intdoWork()The "main function" of the toolorg.apache.hadoop.conf.ConfigurationgetConf()doublegetOptionAsDouble(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, double defaultValue) intgetOptionAsInt(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) intgetOptionAsInt(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) longgetOptionAsLong(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) longgetOptionAsLong(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) private booleanisHelpCommand(String[] args) protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParserCreate the parser to use for parsing and validating the command line.protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLinestatic intstatic longParse a number and enforce a range.protected voidprotected voidprintUsage(String usageStr, String usageHeader, String usageFooter) protected voidprocessOldArgs(List<String> args) For backward compatibility.protected abstract voidprocessOptions(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd) This method is called to process the options after they have been parsed.intvoidsetConf(org.apache.hadoop.conf.Configuration conf)
-
Field Details
-
EXIT_SUCCESS
- See Also:
-
EXIT_FAILURE
- See Also:
-
SHORT_HELP_OPTION
- See Also:
-
LONG_HELP_OPTION
- See Also:
-
HELP_OPTION
-
LOG
-
options
-
conf
-
cmdLineArgs
-
optionsOrder
-
optionsCount
-
-
Constructor Details
-
AbstractHBaseTool
public AbstractHBaseTool()
-
-
Method Details
-
addOptions
Override this to add command-line options usingaddOptWithArg(java.lang.String, java.lang.String)and similar methods. -
processOptions
protected abstract void processOptions(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd) This method is called to process the options after they have been parsed. -
doWork
The "main function" of the tool- Throws:
Exception
-
processOldArgs
For backward compatibility. DO NOT use it for new tools. We have options in existing tools which can't be ported to Apache CLI'sOption. (because they don't pass validation, for e.g. "-copy-to". "-" means short name which doesn't allow '-' in name). This function is to allow tools to have, for time being, parameters which can't be parsed usingOption. Overrides should consume all valid legacy arguments. If the param 'args' is not empty on return, it means there were invalid options, in which case we'll exit from the tool. Note that it's called beforeprocessOptions(CommandLine), which means new options' values will override old ones'. -
getConf
- Specified by:
getConfin interfaceorg.apache.hadoop.conf.Configurable
-
setConf
- Specified by:
setConfin interfaceorg.apache.hadoop.conf.Configurable
-
run
- Specified by:
runin interfaceorg.apache.hadoop.util.Tool- Throws:
IOException
-
newParser
Create the parser to use for parsing and validating the command line. Since commons-cli lacks the capability to validate arbitrary combination of options, it may be helpful to bake custom logic into a specialized parser implementation. See LoadTestTool for examples.- Returns:
- a new parser specific to the current tool
-
isHelpCommand
private boolean isHelpCommand(String[] args) throws org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException - Throws:
org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException
-
parseArgs
protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine parseArgs(String[] args) throws org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException - Throws:
org.apache.hbase.thirdparty.org.apache.commons.cli.ParseException
-
printUsage
-
printUsage
-
addOption
-
addRequiredOption
-
addRequiredOptWithArg
-
addRequiredOptWithArg
-
addOptNoArg
-
addOptNoArg
-
addOptWithArg
-
addOptWithArg
-
getOptionAsInt
public int getOptionAsInt(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) -
getOptionAsInt
public int getOptionAsInt(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) -
getOptionAsLong
public long getOptionAsLong(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) -
getOptionAsLong
public long getOptionAsLong(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) -
getOptionAsDouble
public double getOptionAsDouble(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, double defaultValue) -
parseLong
Parse a number and enforce a range. -
parseInt
-
doStaticMain
Call this from the concrete tool class's main function.
-