From 27aabcab450e628b310d7322798274163789e927 Mon Sep 17 00:00:00 2001 From: Robert Kanter Date: Wed, 18 May 2016 12:16:21 -0700 Subject: [PATCH] MAPREDUCE-6686. Add a way to download the job config from the mapred CLI (rkanter) (cherry picked from commit 992a49353f0bdbc71534bfeeb134112c5624b94b) --- .../apache/hadoop/mapreduce/tools/CLI.java | 35 +++++++++++++++++-- .../src/site/markdown/MapredCommands.md | 3 +- .../hadoop/mapreduce/TestMRJobClient.java | 28 +++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java index 41fe133ba70..a879098264f 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java @@ -39,6 +39,8 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.TIPStatus; @@ -106,6 +108,7 @@ public class CLI extends Configured implements Tool { int fromEvent = 0; int nEvents = 0; int jpvalue = 0; + String configOutFile = null; boolean getStatus = false; boolean getCounter = false; boolean killJob = false; @@ -121,6 +124,7 @@ public class CLI extends Configured implements Tool { boolean failTask = false; boolean setJobPriority = false; boolean logs = false; + boolean downloadConfig = false; if ("-submit".equals(cmd)) { if (argv.length != 2) { @@ -295,6 +299,14 @@ public class CLI extends Configured implements Tool { displayUsage(cmd); return exitCode; } + } else if ("-config".equals(cmd)) { + downloadConfig = true; + if (argv.length != 3) { + displayUsage(cmd); + return exitCode; + } + jobid = argv[1]; + configOutFile = argv[2]; } else { displayUsage(cmd); return exitCode; @@ -473,6 +485,22 @@ public class CLI extends Configured implements Tool { System.out.println(e.getMessage()); } } + } else if (downloadConfig) { + Job job = getJob(JobID.forName(jobid)); + if (job == null) { + System.out.println("Could not find job " + jobid); + } else { + String jobFile = job.getJobFile(); + if (jobFile == null || jobFile.isEmpty()) { + System.out.println("Config file for job " + jobFile + + " could not be found."); + } else { + Path configPath = new Path(jobFile); + FileSystem fs = FileSystem.get(getConf()); + fs.copyToLocalFile(configPath, new Path(configOutFile)); + exitCode = 0; + } + } } } catch (RemoteException re) { IOException unwrappedException = re.unwrapRemoteException(); @@ -549,7 +577,9 @@ public class CLI extends Configured implements Tool { } else if ("-logs".equals(cmd)) { System.err.println(prefix + "[" + cmd + " ]. " + - " is optional to get task attempt logs."); + " is optional to get task attempt logs."); + } else if ("-config".equals(cmd)) { + System.err.println(prefix + "[" + cmd + " ]"); } else { System.err.printf(prefix + " %n"); System.err.printf("\t[-submit ]%n"); @@ -571,7 +601,8 @@ public class CLI extends Configured implements Tool { "Valid values for are " + taskStates); System.err.printf("\t[-kill-task ]%n"); System.err.printf("\t[-fail-task ]%n"); - System.err.printf("\t[-logs ]%n%n"); + System.err.printf("\t[-logs ]%n"); + System.err.printf("\t[-config %n%n"); ToolRunner.printGenericCommandUsage(System.out); } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredCommands.md b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredCommands.md index e785f446f39..2925abd6acc 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredCommands.md +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/site/markdown/MapredCommands.md @@ -81,7 +81,7 @@ Copy file or directories recursively. More information can be found at Command to interact with Map Reduce Jobs. -Usage: `mapred job | [GENERIC_OPTIONS] | [-submit ] | [-status ] | [-counter ] | [-kill ] | [-events <#-of-events>] | [-history [all] [-outfile ] [-format ]] | [-list [all]] | [-kill-task ] | [-fail-task ] | [-set-priority ] | [-list-active-trackers] | [-list-blacklisted-trackers] | [-list-attempt-ids ] [-logs ]` +Usage: `mapred job | [GENERIC_OPTIONS] | [-submit ] | [-status ] | [-counter ] | [-kill ] | [-events <#-of-events>] | [-history [all] [-outfile ] [-format ]] | [-list [all]] | [-kill-task ] | [-fail-task ] | [-set-priority ] | [-list-active-trackers] | [-list-blacklisted-trackers] | [-list-attempt-ids ] [-logs ] [-config ]` | COMMAND\_OPTION | Description | |:---- |:---- | @@ -99,6 +99,7 @@ Usage: `mapred job | [GENERIC_OPTIONS] | [-submit ] | [-status ", line); + } + /** * print job events list */