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.
  • Field Details

  • Constructor Details

  • Method Details

    • addOptions

      protected abstract void addOptions()
      Override this to add command-line options using addOptWithArg(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

      protected abstract int doWork() throws Exception
      The "main function" of the tool
      Throws:
      Exception
    • processOldArgs

      protected void processOldArgs(List<String> args)
      For backward compatibility. DO NOT use it for new tools. We have options in existing tools which can't be ported to Apache CLI's Option. (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 using Option. 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 before processOptions(CommandLine), which means new options' values will override old ones'.
    • getConf

      public org.apache.hadoop.conf.Configuration getConf()
      Specified by:
      getConf in interface org.apache.hadoop.conf.Configurable
    • setConf

      public void setConf(org.apache.hadoop.conf.Configuration conf)
      Specified by:
      setConf in interface org.apache.hadoop.conf.Configurable
    • run

      public int run(String[] args) throws IOException
      Specified by:
      run in interface org.apache.hadoop.util.Tool
      Throws:
      IOException
    • newParser

      protected org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLineParser 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

      protected void printUsage()
    • printUsage

      protected void printUsage(String usageStr, String usageHeader, String usageFooter)
    • addOption

      protected void addOption(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option)
    • addRequiredOption

      protected void addRequiredOption(org.apache.hbase.thirdparty.org.apache.commons.cli.Option option)
    • addRequiredOptWithArg

      protected void addRequiredOptWithArg(String opt, String description)
    • addRequiredOptWithArg

      protected void addRequiredOptWithArg(String shortOpt, String longOpt, String description)
    • addOptNoArg

      protected void addOptNoArg(String opt, String description)
    • addOptNoArg

      protected void addOptNoArg(String shortOpt, String longOpt, String description)
    • addOptWithArg

      protected void addOptWithArg(String opt, String description)
    • addOptWithArg

      protected void addOptWithArg(String shortOpt, String longOpt, String description)
    • 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

      public static long parseLong(String s, long minValue, long maxValue)
      Parse a number and enforce a range.
    • parseInt

      public static int parseInt(String s, int minValue, int maxValue)
    • doStaticMain

      protected void doStaticMain(String[] args)
      Call this from the concrete tool class's main function.