Package org.apache.hadoop.util
Class GenericOptionsParser
java.lang.Object
org.apache.hadoop.util.GenericOptionsParser
- Direct Known Subclasses:
ServiceLauncher.MinimalGenericOptionsParser
GenericOptionsParser is a utility to parse command line
arguments generic to the Hadoop framework.
GenericOptionsParser recognizes several standard command
line arguments, enabling applications to easily specify a namenode, a
ResourceManager, additional configuration resources etc.
Generic Options
The supported generic options are:
-conf <configuration file> specify a configuration file
-D <property=value> use value for given property
-fs <local|namenode:port> specify a namenode
-jt <local|resourcemanager:port> specify a ResourceManager
-files <comma separated list of files> specify comma separated
files to be copied to the map reduce cluster
-libjars <comma separated list of jars> specify comma separated
jar files to include in the classpath.
-archives <comma separated list of archives> specify comma
separated archives to be unarchived on the compute machines.
The general command line syntax is:
bin/hadoop command [genericOptions] [commandOptions]
Generic command line arguments might modify
Configuration objects, given to constructors.
The functionality is implemented using Commons CLI.
Examples:
$ 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 core-site.xml -conf hdfs-site.xml -ls /data
list /data directory in dfs with multiple conf files specified.
$ bin/hadoop job -D yarn.resourcemanager.address=darwin:8032 -submit job.xml
submit a job to ResourceManager darwin:8032
$ bin/hadoop job -jt darwin:8032 -submit job.xml
submit a job to ResourceManager darwin:8032
$ bin/hadoop job -jt local -submit job.xml
submit a job to local runner
$ bin/hadoop jar -libjars testlib.jar
-archives test.tgz -files file.txt inputjar args
job submission with libjars, files and archives
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGenericOptionsParser(String[] args) Create an options parser to parse the args.GenericOptionsParser(org.apache.commons.cli.Options opts, String[] args) Create an options parser with the given options to parse the args.GenericOptionsParser(Configuration conf, String[] args) Create aGenericOptionsParserto parse only the generic Hadoop arguments.GenericOptionsParser(Configuration conf, org.apache.commons.cli.Options options, String[] args) Create aGenericOptionsParserto parse given options as well as generic Hadoop options. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.commons.cli.OptionsbuildGeneralOptions(org.apache.commons.cli.Options opts) org.apache.commons.cli.CommandLineReturns the commons-cliCommandLineobject to process the parsed arguments.Get the modified configurationstatic URL[]getLibJars(Configuration conf) If libjars are set in the conf, parse the libjars.String[]Returns an array of Strings containing only application-specific arguments.booleanQuery for the parse operation succeeding.static voidPrint the usage message for generic command-line options supported.
-
Constructor Details
-
GenericOptionsParser
Create an options parser with the given options to parse the args.- Parameters:
opts- the optionsargs- the command line arguments- Throws:
IOException- raised on errors performing I/O.
-
GenericOptionsParser
Create an options parser to parse the args.- Parameters:
args- the command line arguments- Throws:
IOException- raised on errors performing I/O.
-
GenericOptionsParser
Create aGenericOptionsParserto parse only the generic Hadoop arguments. The array of string arguments other than the generic arguments can be obtained bygetRemainingArgs().- Parameters:
conf- theConfigurationto modify.args- command-line arguments.- Throws:
IOException- raised on errors performing I/O.
-
GenericOptionsParser
public GenericOptionsParser(Configuration conf, org.apache.commons.cli.Options options, String[] args) throws IOException Create aGenericOptionsParserto parse given options as well as generic Hadoop options. The resultingCommandLineobject can be obtained bygetCommandLine().- Parameters:
conf- the configuration to modifyoptions- options built by the callerargs- User-specified arguments- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
getRemainingArgs
Returns an array of Strings containing only application-specific arguments.- Returns:
- array of
Strings containing the un-parsed arguments or empty array if commandLine was not defined.
-
getConfiguration
Get the modified configuration- Returns:
- the configuration that has the modified parameters.
-
getCommandLine
public org.apache.commons.cli.CommandLine getCommandLine()Returns the commons-cliCommandLineobject to process the parsed arguments. Note: If the object is created withGenericOptionsParser(Configuration, String[]), then returned object will only contain parsed generic options.- Returns:
CommandLinerepresenting list of arguments parsed against Options descriptor.
-
isParseSuccessful
public boolean isParseSuccessful()Query for the parse operation succeeding.- Returns:
- true if parsing the CLI was successful
-
buildGeneralOptions
protected org.apache.commons.cli.Options buildGeneralOptions(org.apache.commons.cli.Options opts) - Parameters:
opts- input opts.- Returns:
- Specify properties of each generic option.
Important: as
Optionis not thread safe, subclasses must synchronize use onOption.class
-
getLibJars
If libjars are set in the conf, parse the libjars.- Parameters:
conf- input Configuration.- Returns:
- libjar urls
- Throws:
IOException- raised on errors performing I/O.
-
printGenericCommandUsage
Print the usage message for generic command-line options supported.- Parameters:
out- stream to print the usage message to.
-