Class HAAdmin

All Implemented Interfaces:
Configurable, Tool

@Private public abstract class HAAdmin extends Configured implements Tool
A command-line tool for making calls in the HAServiceProtocol. For example,. this can be used to force a service to standby or active mode, or to trigger a health-check.
  • Field Details

    • FORCEACTIVE

      protected static final String FORCEACTIVE
      See Also:
    • FORCEMANUAL

      protected static final String FORCEMANUAL
      Undocumented flag which allows an administrator to use manual failover state transitions even when auto-failover is enabled. This is an unsafe operation, which is why it is not documented in the usage below.
      See Also:
    • USAGE

      protected static final Map<String,HAAdmin.UsageInfo> USAGE
    • errOut

      protected PrintStream errOut
      Output stream for errors, for use in tests
    • out

      protected PrintStream out
  • Constructor Details

    • HAAdmin

      protected HAAdmin()
    • HAAdmin

      protected HAAdmin(Configuration conf)
  • Method Details

    • getRequestSource

      protected HAServiceProtocol.RequestSource getRequestSource()
    • setRequestSource

      protected void setRequestSource(HAServiceProtocol.RequestSource requestSource)
    • resolveTarget

      protected abstract HAServiceTarget resolveTarget(String string)
    • getTargetIds

      protected Collection<String> getTargetIds(String targetNodeToActivate)
    • getUsageString

      protected String getUsageString()
    • printUsage

      protected void printUsage(PrintStream pStr, Map<String,HAAdmin.UsageInfo> helpEntries)
    • printUsage

      protected void printUsage(PrintStream pStr)
    • printUsage

      protected void printUsage(PrintStream pStr, String cmd, Map<String,HAAdmin.UsageInfo> helpEntries)
    • printUsage

      protected void printUsage(PrintStream pStr, String cmd)
    • checkManualStateManagementOK

      protected boolean checkManualStateManagementOK(HAServiceTarget target)
      Ensure that we are allowed to manually manage the HA state of the target service. If automatic failover is configured, then the automatic failover controllers should be doing state management, and it is generally an error to use the HAAdmin command line to do so.
      Parameters:
      target - the target to check
      Returns:
      true if manual state management is allowed
    • createReqInfo

      protected HAServiceProtocol.StateChangeRequestInfo createReqInfo()
    • gracefulFailoverThroughZKFCs

      protected int gracefulFailoverThroughZKFCs(HAServiceTarget toNode) throws IOException
      Initiate a graceful failover by talking to the target node's ZKFC. This sends an RPC to the ZKFC, which coordinates the failover.
      Parameters:
      toNode - the node to fail to
      Returns:
      status code (0 for success)
      Throws:
      IOException - if failover does not succeed
    • getServiceAddr

      protected String getServiceAddr(String serviceId)
      Return the serviceId as is, we are assuming it was given as a service address of form <host:ipcport>.
      Parameters:
      serviceId - serviceId.
      Returns:
      service addr.
    • setConf

      public void setConf(Configuration conf)
      Description copied from interface: Configurable
      Set the configuration to be used by this object.
      Specified by:
      setConf in interface Configurable
      Overrides:
      setConf in class Configured
      Parameters:
      conf - configuration to be used
    • run

      public int run(String[] argv) throws Exception
      Description copied from interface: Tool
      Execute the command with the given arguments.
      Specified by:
      run in interface Tool
      Parameters:
      argv - command specific arguments.
      Returns:
      exit code.
      Throws:
      Exception - command exception.
    • checkParameterValidity

      protected boolean checkParameterValidity(String[] argv, Map<String,HAAdmin.UsageInfo> helpEntries)
    • checkParameterValidity

      protected boolean checkParameterValidity(String[] argv)
    • runCmd

      protected int runCmd(String[] argv) throws Exception
      Throws:
      Exception
    • getAllServiceState

      protected int getAllServiceState()
    • confirmForceManual

      protected boolean confirmForceManual() throws IOException
      Throws:
      IOException
    • parseOpts

      protected org.apache.commons.cli.CommandLine parseOpts(String cmdName, org.apache.commons.cli.Options opts, String[] argv, Map<String,HAAdmin.UsageInfo> helpEntries)
    • parseOpts

      protected org.apache.commons.cli.CommandLine parseOpts(String cmdName, org.apache.commons.cli.Options opts, String[] argv)
    • help

      protected int help(String[] argv)
    • help

      protected int help(String[] argv, Map<String,HAAdmin.UsageInfo> helpEntries)