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
-
Field Summary
Modifier and TypeFieldDescriptionprotected String[]
protected org.apache.hadoop.conf.Configuration
static final int
static final int
private static final org.apache.hbase.thirdparty.org.apache.commons.cli.Option
private static final org.slf4j.Logger
static final String
protected final org.apache.hbase.thirdparty.org.apache.commons.cli.Options
private int
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addOption
(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option) protected abstract void
Override this to add command-line options usingaddOptWithArg(java.lang.String, java.lang.String)
and similar methods.protected void
addOptNoArg
(String opt, String description) protected void
addOptNoArg
(String shortOpt, String longOpt, String description) protected void
addOptWithArg
(String opt, String description) protected void
addOptWithArg
(String shortOpt, String longOpt, String description) protected void
addRequiredOption
(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option) protected void
addRequiredOptWithArg
(String opt, String description) protected void
addRequiredOptWithArg
(String shortOpt, String longOpt, String description) protected void
doStaticMain
(String[] args) Call this from the concrete tool class's main function.protected abstract int
doWork()
The "main function" of the toolorg.apache.hadoop.conf.Configuration
getConf()
double
getOptionAsDouble
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, double defaultValue) int
getOptionAsInt
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) int
getOptionAsInt
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) long
getOptionAsLong
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue) long
getOptionAsLong
(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd, String opt, int defaultValue, int radix) private boolean
isHelpCommand
(String[] args) protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser
Create the parser to use for parsing and validating the command line.protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine
static int
static long
Parse a number and enforce a range.protected void
protected void
printUsage
(String usageStr, String usageHeader, String usageFooter) protected void
processOldArgs
(List<String> args) For backward compatibility.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.int
void
setConf
(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:
getConf
in interfaceorg.apache.hadoop.conf.Configurable
-
setConf
- Specified by:
setConf
in interfaceorg.apache.hadoop.conf.Configurable
-
run
- Specified by:
run
in 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.
-