View Javadoc

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  package org.apache.hadoop.hbase.util;
19  
20  import org.apache.hadoop.conf.Configuration;
21  import org.apache.hadoop.hbase.HBaseConfiguration;
22  import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
23  import org.apache.hadoop.mapreduce.Job;
24  import org.apache.hadoop.util.Tool;
25  import org.apache.hadoop.util.ToolRunner;
26  import org.apache.log4j.Level;
27  import org.apache.log4j.Logger;
28  
29  /**
30   * Generate a classpath string containing any jars required by mapreduce jobs. Specify
31   * additional values by providing a comma-separated list of paths via -Dtmpjars.
32   */
33  public class MapreduceDependencyClasspathTool implements Tool {
34  
35    private Configuration conf;
36  
37    @Override
38    public void setConf(Configuration conf) {
39      this.conf = conf;
40    }
41  
42    @Override
43    public Configuration getConf() {
44      return conf;
45    }
46  
47    @Override
48    public int run(String[] args) throws Exception {
49      if (args.length > 0) {
50        System.err.println("Usage: hbase mapredcp [-Dtmpjars=...]");
51        System.err.println("  Construct a CLASSPATH containing dependency jars required to run a mapreduce");
52        System.err.println("  job. By default, includes any jars detected by TableMapReduceUtils. Provide");
53        System.err.println("  additional entries by specifying a comma-separated list in tmpjars.");
54        return 0;
55      }
56  
57      Job job = new Job(getConf());
58      TableMapReduceUtil.addDependencyJars(job);
59      System.out.println(TableMapReduceUtil.buildDependencyClasspath(job.getConfiguration()));
60      return 0;
61    }
62  
63    public static void main(String[] argv) throws Exception {
64      // Silence the usual noise. This is probably fragile...
65      Logger logger = Logger.getLogger("org.apache.hadoop.hbase");
66      if (logger != null) {
67        logger.setLevel(Level.WARN);
68      }
69      System.exit(ToolRunner.run(
70        HBaseConfiguration.create(), new MapreduceDependencyClasspathTool(), argv));
71    }
72  }