[120] | 1 | /** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
| 3 | * or more contributor license agreements. See the NOTICE file |
---|
| 4 | * distributed with this work for additional information |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file |
---|
| 6 | * to you under the Apache License, Version 2.0 (the |
---|
| 7 | * "License"); you may not use this file except in compliance |
---|
| 8 | * with the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | package org.apache.hadoop.util; |
---|
| 20 | |
---|
| 21 | import org.apache.hadoop.conf.Configurable; |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * A tool interface that supports handling of generic command-line options. |
---|
| 25 | * |
---|
| 26 | * <p><code>Tool</code>, is the standard for any Map-Reduce tool/application. |
---|
| 27 | * The tool/application should delegate the handling of |
---|
| 28 | * <a href="{@docRoot}/org/apache/hadoop/util/GenericOptionsParser.html#GenericOptions"> |
---|
| 29 | * standard command-line options</a> to {@link ToolRunner#run(Tool, String[])} |
---|
| 30 | * and only handle its custom arguments.</p> |
---|
| 31 | * |
---|
| 32 | * <p>Here is how a typical <code>Tool</code> is implemented:</p> |
---|
| 33 | * <p><blockquote><pre> |
---|
| 34 | * public class MyApp extends Configured implements Tool { |
---|
| 35 | * |
---|
| 36 | * public int run(String[] args) throws Exception { |
---|
| 37 | * // <code>Configuration</code> processed by <code>ToolRunner</code> |
---|
| 38 | * Configuration conf = getConf(); |
---|
| 39 | * |
---|
| 40 | * // Create a JobConf using the processed <code>conf</code> |
---|
| 41 | * JobConf job = new JobConf(conf, MyApp.class); |
---|
| 42 | * |
---|
| 43 | * // Process custom command-line options |
---|
| 44 | * Path in = new Path(args[1]); |
---|
| 45 | * Path out = new Path(args[2]); |
---|
| 46 | * |
---|
| 47 | * // Specify various job-specific parameters |
---|
| 48 | * job.setJobName("my-app"); |
---|
| 49 | * job.setInputPath(in); |
---|
| 50 | * job.setOutputPath(out); |
---|
| 51 | * job.setMapperClass(MyApp.MyMapper.class); |
---|
| 52 | * job.setReducerClass(MyApp.MyReducer.class); |
---|
| 53 | * |
---|
| 54 | * // Submit the job, then poll for progress until the job is complete |
---|
| 55 | * JobClient.runJob(job); |
---|
| 56 | * } |
---|
| 57 | * |
---|
| 58 | * public static void main(String[] args) throws Exception { |
---|
| 59 | * // Let <code>ToolRunner</code> handle generic command-line options |
---|
| 60 | * int res = ToolRunner.run(new Configuration(), new Sort(), args); |
---|
| 61 | * |
---|
| 62 | * System.exit(res); |
---|
| 63 | * } |
---|
| 64 | * } |
---|
| 65 | * </pre></blockquote></p> |
---|
| 66 | * |
---|
| 67 | * @see GenericOptionsParser |
---|
| 68 | * @see ToolRunner |
---|
| 69 | */ |
---|
| 70 | public interface Tool extends Configurable { |
---|
| 71 | /** |
---|
| 72 | * Execute the command with the given arguments. |
---|
| 73 | * |
---|
| 74 | * @param args command specific arguments. |
---|
| 75 | * @return exit code. |
---|
| 76 | * @throws Exception |
---|
| 77 | */ |
---|
| 78 | int run(String [] args) throws Exception; |
---|
| 79 | } |
---|