@InterfaceAudience.Public @InterfaceStability.Stable public interface Tool extends Configurable
Tool
, is the standard for any Map-Reduce tool/application.
The tool/application should delegate the handling of
standard command-line options to ToolRunner.run(Tool, String[])
and only handle its custom arguments.
Here is how a typical Tool
is implemented:
public class MyApp extends Configured implements Tool { public int run(String[] args) throws Exception { //Configuration
processed byToolRunner
Configuration conf = getConf(); // Create a JobConf using the processedconf
JobConf job = new JobConf(conf, MyApp.class); // Process custom command-line options Path in = new Path(args[1]); Path out = new Path(args[2]); // Specify various job-specific parameters job.setJobName("my-app"); job.setInputPath(in); job.setOutputPath(out); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); // Submit the job, then poll for progress until the job is complete RunningJob runningJob = JobClient.runJob(job); if (runningJob.isSuccessful()) { return 0; } else { return 1; } } public static void main(String[] args) throws Exception { // LetToolRunner
handle generic command-line options int res = ToolRunner.run(new Configuration(), new MyApp(), args); System.exit(res); } }
GenericOptionsParser
,
ToolRunner
Modifier and Type | Method and Description |
---|---|
int |
run(String[] args)
Execute the command with the given arguments.
|
getConf, setConf
Copyright © 2018 Apache Software Foundation. All rights reserved.