com.cloudera.sqoop.tool
Class SqoopTool

java.lang.Object
  extended by com.cloudera.sqoop.tool.SqoopTool
Direct Known Subclasses:
BaseSqoopTool

public abstract class SqoopTool
extends java.lang.Object

Base class for Sqoop subprograms (e.g., SqoopImport, SqoopExport, etc.) Allows subprograms to configure the arguments they accept and provides an entry-point to the subprogram.


Field Summary
protected  java.lang.String[] extraArguments
          Arguments that remained unparsed after parseArguments.
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
SqoopTool()
           
SqoopTool(java.lang.String name)
           
 
Method Summary
 void appendArgs(java.lang.String[] extra)
          Append 'extra' to extraArguments.
 void applyOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out)
          Generate the SqoopOptions containing actual argument values from the extracted CommandLine arguments.
 void configureOptions(ToolOptions opts)
          Configure the command-line arguments we expect to receive.
static SqoopTool getTool(java.lang.String toolName)
           
static java.lang.String getToolDescription(java.lang.String toolName)
           
 java.lang.String getToolName()
           
static java.util.Set<java.lang.String> getToolNames()
           
 SqoopOptions parseArguments(java.lang.String[] args, org.apache.hadoop.conf.Configuration conf, SqoopOptions in, boolean useGenericOptions)
          Configures a SqoopOptions according to the specified arguments.
 void printHelp(ToolOptions opts)
          Print the help message for this tool.
abstract  int run(SqoopOptions options)
          Main body of code to run the tool.
protected  void setToolName(java.lang.String name)
           
 java.lang.String toString()
           
 void validateOptions(SqoopOptions options)
          Validates options and ensures that any required options are present and that any mutually-exclusive options are not selected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

extraArguments

protected java.lang.String[] extraArguments
Arguments that remained unparsed after parseArguments.

Constructor Detail

SqoopTool

public SqoopTool()

SqoopTool

public SqoopTool(java.lang.String name)
Method Detail

getToolNames

public static final java.util.Set<java.lang.String> getToolNames()
Returns:
the list of available tools.

getTool

public static final SqoopTool getTool(java.lang.String toolName)
Returns:
the SqoopTool instance with the provided name, or null if no such tool exists.

getToolDescription

public static final java.lang.String getToolDescription(java.lang.String toolName)
Returns:
the user-friendly description for a tool, or null if the tool cannot be found.

getToolName

public java.lang.String getToolName()

setToolName

protected void setToolName(java.lang.String name)

run

public abstract int run(SqoopOptions options)
Main body of code to run the tool.

Parameters:
options - the SqoopOptions configured via configureOptions()/applyOptions().
Returns:
an integer return code for external programs to consume. 0 represents success; nonzero means failure.

configureOptions

public void configureOptions(ToolOptions opts)
Configure the command-line arguments we expect to receive.

Parameters:
opts - a ToolOptions that should be populated with sets of RelatedOptions for the tool.

printHelp

public void printHelp(ToolOptions opts)
Print the help message for this tool.

Parameters:
opts - the configured tool options

applyOptions

public void applyOptions(org.apache.commons.cli.CommandLine in,
                         SqoopOptions out)
                  throws SqoopOptions.InvalidOptionsException
Generate the SqoopOptions containing actual argument values from the extracted CommandLine arguments.

Parameters:
in - the CLI CommandLine that contain the user's set Options.
out - the SqoopOptions with all fields applied.
Throws:
SqoopOptions.InvalidOptionsException - if there's a problem.

validateOptions

public void validateOptions(SqoopOptions options)
                     throws SqoopOptions.InvalidOptionsException
Validates options and ensures that any required options are present and that any mutually-exclusive options are not selected.

Throws:
SqoopOptions.InvalidOptionsException - if there's a problem.

parseArguments

public SqoopOptions parseArguments(java.lang.String[] args,
                                   org.apache.hadoop.conf.Configuration conf,
                                   SqoopOptions in,
                                   boolean useGenericOptions)
                            throws org.apache.commons.cli.ParseException,
                                   SqoopOptions.InvalidOptionsException
Configures a SqoopOptions according to the specified arguments. Reads a set of arguments and uses them to configure a SqoopOptions and its embedded configuration (i.e., through GenericOptionsParser.) Stores any unparsed arguments in the extraArguments field.

Parameters:
args - the arguments to parse.
conf - if non-null, set as the configuration for the returned SqoopOptions.
in - a (perhaps partially-configured) SqoopOptions. If null, then a new SqoopOptions will be used. If this has a null configuration and conf is null, then a new Configuration will be inserted in this.
useGenericOptions - if true, will also parse generic Hadoop options into the Configuration.
Returns:
a SqoopOptions that is fully configured by a given tool.
Throws:
org.apache.commons.cli.ParseException
SqoopOptions.InvalidOptionsException

appendArgs

public void appendArgs(java.lang.String[] extra)
Append 'extra' to extraArguments.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010 Cloudera, Inc.