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