Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JobSubmission.getStagingDir incompatiblity #85

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions conduit-distcp/src/main/java/org/apache/hadoop/tools/DistCp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.apache.hadoop.tools;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Random;

Expand Down Expand Up @@ -347,15 +349,41 @@ protected Path getFileListingPath() throws IOException {
*/
private Path createMetaFolderPath() throws Exception {
Configuration configuration = getConf();
Path stagingDir = JobSubmissionFiles.getStagingDir(
new JobClient(new JobConf(configuration)), configuration);
Path stagingDir = getStagingPath(configuration);
Path metaFolderPath = new Path(stagingDir, PREFIX + String.valueOf(rand.nextInt()));
if (LOG.isDebugEnabled())
LOG.debug("Meta folder location: " + metaFolderPath);
configuration.set(DistCpConstants.CONF_LABEL_META_FOLDER, metaFolderPath.toString());
return metaFolderPath;
}

private Path getStagingPath(Configuration configuration) {
try {
LOG.info("Trying to get staging path using hadoop-2");
Class clusterClass = DistCp.class.getClassLoader().loadClass(
"org.apache.hadoop.mapreduce.Cluster");
Method method = JobSubmissionFiles.class.getMethod("getStagingDir",
clusterClass, Configuration.class);
Constructor constructor = clusterClass.getConstructor(Configuration.class);
return (Path) method.invoke(null,
constructor.newInstance(configuration), configuration);
} catch (Exception ignored) {
// fallback to hadoop-1 API
}

try {
LOG.info("Trying to get staging path using hadoop-1");
Method method = JobSubmissionFiles.class.getMethod("getStagingDir",
JobClient.class, Configuration.class);
return (Path) method.invoke(null,
new JobClient(new JobConf(configuration)), configuration);
} catch (Exception ignored) {
// do nothing
}

throw new RuntimeException("Either hadoop-1 or hadoop-2 must be in the classpath");
}

/**
* Main function of the DistCp program. Parses the input arguments (via OptionsParser),
* and invokes the DistCp::run() method, via the ToolRunner.
Expand Down