org.apache.hadoop.util
Class ToolBase

java.lang.Object
  extended by org.apache.hadoop.util.ToolBase
All Implemented Interfaces:
Configurable, Tool
Direct Known Subclasses:
CopyFiles, DFSck, FsShell, JobClient, MigrationTool

public abstract class ToolBase
extends Object
implements Tool

This is a base class to support generic commonad options. Generic command options allow a user to specify a namenode, a job tracker etc. Generic options supported are

-conf specify an application configuration file

-D use value for given property

-fs specify a namenode

-jt specify a job tracker

The general command line syntax is

bin/hadoop command [genericOptions] [commandOptions]

For every tool that inherits from ToolBase, generic options are handled by ToolBase while command options are passed to the tool. Generic options handling is implemented using Common CLI.

Tools that inherit from ToolBase in Hadoop are DFSShell, DFSck, JobClient, and CopyFiles.

Examples using generic options are

bin/hadoop dfs -fs darwin:8020 -ls /data

     list /data directory in dfs with namenode darwin:8020
 

bin/hadoop dfs -D fs.default.name=darwin:8020 -ls /data

     list /data directory in dfs with namenode darwin:8020
 

bin/hadoop dfs -conf hadoop-site.xml -ls /data

     list /data directory in dfs with conf specified in hadoop-site.xml
 

bin/hadoop job -D mapred.job.tracker=darwin:50020 -submit job.xml

     submit a job to job tracker darwin:50020
 

bin/hadoop job -jt darwin:50020 -submit job.xml

     submit a job to job tracker darwin:50020
 

bin/hadoop job -jt local -submit job.xml

     submit a job to local runner
 

Author:
hairong

Field Summary
 Configuration conf
           
 
Constructor Summary
ToolBase()
           
 
Method Summary
 int doMain(Configuration conf, String[] args)
          Work as a main program: execute a command and handle exception if any
 Configuration getConf()
          Return the configuration used by this object.
 void setConf(Configuration conf)
          Set the configuration to be used by this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.util.Tool
run
 

Field Detail

conf

public Configuration conf
Constructor Detail

ToolBase

public ToolBase()
Method Detail

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

getConf

public Configuration getConf()
Description copied from interface: Configurable
Return the configuration used by this object.

Specified by:
getConf in interface Configurable

doMain

public final int doMain(Configuration conf,
                        String[] args)
                 throws Exception
Work as a main program: execute a command and handle exception if any

Parameters:
conf - Application default configuration
args - User-specified arguments
Returns:
exit code to be passed to a caller. General contract is that code equal zero signifies a normal return, negative values signify errors, and positive non-zero values can be used to return application-specific codes.
Throws:
Exception


Copyright © 2006 The Apache Software Foundation