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