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.mapreduce;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.Path;
023import org.apache.hadoop.mapreduce.Cluster;
024import org.apache.hadoop.mapreduce.JobSubmissionFiles;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.apache.yetus.audience.InterfaceStability;
027
028/**
029 * Utility methods to interact with a job.
030 */
031@InterfaceAudience.Private
032@InterfaceStability.Evolving
033public abstract class JobUtil {
034
035  protected JobUtil() {
036    super();
037  }
038
039  /**
040   * Initializes the staging directory and returns the path.
041   * @param conf system configuration
042   * @return staging directory path
043   * @throws IOException          if the ownership on the staging directory is not as expected
044   * @throws InterruptedException if the thread getting the staging directory is interrupted
045   */
046  public static Path getStagingDir(Configuration conf) throws IOException, InterruptedException {
047    return JobSubmissionFiles.getStagingDir(new Cluster(conf), conf);
048  }
049
050  /**
051   * Initializes the staging directory and returns the qualified path.
052   * @param conf conf system configuration
053   * @return qualified staging directory path
054   * @throws IOException          if the ownership on the staging directory is not as expected
055   * @throws InterruptedException if the thread getting the staging directory is interrupted
056   */
057  public static Path getQualifiedStagingDir(Configuration conf)
058    throws IOException, InterruptedException {
059    Cluster cluster = new Cluster(conf);
060    Path stagingDir = JobSubmissionFiles.getStagingDir(cluster, conf);
061    return cluster.getFileSystem().makeQualified(stagingDir);
062  }
063
064}