001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import org.apache.hadoop.conf.Configuration;
021import org.apache.hadoop.hbase.HBaseConfiguration;
022import org.apache.hadoop.hbase.HBaseInterfaceAudience;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
025import org.apache.hadoop.util.Tool;
026import org.apache.hadoop.util.ToolRunner;
027import org.apache.log4j.Level;
028import org.apache.log4j.Logger;
029
030/**
031 * Generate a classpath string containing any jars required by mapreduce jobs. Specify
032 * additional values by providing a comma-separated list of paths via -Dtmpjars.
033 */
034@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
035public class MapreduceDependencyClasspathTool implements Tool {
036
037  private Configuration conf;
038
039  @Override
040  public void setConf(Configuration conf) {
041    this.conf = conf;
042  }
043
044  @Override
045  public Configuration getConf() {
046    return conf;
047  }
048
049  @Override
050  public int run(String[] args) throws Exception {
051    if (args.length > 0) {
052      System.err.println("Usage: hbase mapredcp [-Dtmpjars=...]");
053      System.err.println("  Construct a CLASSPATH containing dependency jars required to run a mapreduce");
054      System.err.println("  job. By default, includes any jars detected by TableMapReduceUtils. Provide");
055      System.err.println("  additional entries by specifying a comma-separated list in tmpjars.");
056      return 0;
057    }
058
059    TableMapReduceUtil.addHBaseDependencyJars(getConf());
060    System.out.println(TableMapReduceUtil.buildDependencyClasspath(getConf()));
061    return 0;
062  }
063
064  public static void main(String[] argv) throws Exception {
065    // Silence the usual noise. This is probably fragile...
066    Logger logger = Logger.getLogger("org.apache.hadoop.hbase");
067    if (logger != null) {
068      logger.setLevel(Level.WARN);
069    }
070    System.exit(ToolRunner.run(
071      HBaseConfiguration.create(), new MapreduceDependencyClasspathTool(), argv));
072  }
073}