hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aajis...@apache.org
Subject hadoop git commit: MAPREDUCE-4424. 'mapred job -list' command should show the job name as well. Contributed by Avinash Kujur.
Date Fri, 20 Mar 2015 09:48:49 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 978ef11f2 -> 8041267f0


MAPREDUCE-4424. 'mapred job -list' command should show the job name as well. Contributed by
Avinash Kujur.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8041267f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8041267f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8041267f

Branch: refs/heads/trunk
Commit: 8041267f022f7d9d8c99363c37b86895dbd9ade3
Parents: 978ef11
Author: Akira Ajisaka <aajisaka@apache.org>
Authored: Fri Mar 20 18:46:51 2015 +0900
Committer: Akira Ajisaka <aajisaka@apache.org>
Committed: Fri Mar 20 18:46:51 2015 +0900

----------------------------------------------------------------------
 hadoop-mapreduce-project/CHANGES.txt            |  3 ++
 .../org/apache/hadoop/mapreduce/tools/CLI.java  | 19 +++++----
 .../hadoop/mapreduce/TestMRJobClient.java       | 43 ++++++++++++++++++++
 3 files changed, 57 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8041267f/hadoop-mapreduce-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt
index 10c9389..2a4bf0c 100644
--- a/hadoop-mapreduce-project/CHANGES.txt
+++ b/hadoop-mapreduce-project/CHANGES.txt
@@ -9,6 +9,9 @@ Trunk (Unreleased)
     MAPREDUCE-5653. DistCp does not honour config-overrides for
     mapreduce.[map,reduce].memory.mb (Ratandeep Ratti via aw)
 
+    MAPREDUCE-4424. 'mapred job -list' command should show the job name
+    as well. (Avinash Kujur via aajisaka)
+
   NEW FEATURES
 
     MAPREDUCE-778. Rumen Anonymizer. (Amar Kamat and Chris Douglas via amarrk)

http://git-wip-us.apache.org/repos/asf/hadoop/blob/8041267f/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java
----------------------------------------------------------------------
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 3630c64..c3f1564 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
@@ -616,17 +616,19 @@ public class CLI extends Configured implements Tool {
   }
 
   @Private
-  public static String headerPattern = "%23s\t%10s\t%14s\t%12s\t%12s\t%10s\t%15s\t%15s\t%8s\t%8s\t%10s\t%10s\n";
+  public static String headerPattern = "%23s\t%20s\t%10s\t%14s\t%12s\t%12s" +
+      "\t%10s\t%15s\t%15s\t%8s\t%8s\t%10s\t%10s\n";
   @Private
-  public static String dataPattern   = "%23s\t%10s\t%14d\t%12s\t%12s\t%10s\t%15s\t%15s\t%8s\t%8s\t%10s\t%10s\n";
+  public static String dataPattern   = "%23s\t%20s\t%10s\t%14d\t%12s\t%12s" +
+      "\t%10s\t%15s\t%15s\t%8s\t%8s\t%10s\t%10s\n";
   private static String memPattern   = "%dM";
   private static String UNAVAILABLE  = "N/A";
 
   @Private
   public void displayJobList(JobStatus[] jobs, PrintWriter writer) {
     writer.println("Total jobs:" + jobs.length);
-    writer.printf(headerPattern, "JobId", "State", "StartTime", "UserName",
-      "Queue", "Priority", "UsedContainers",
+    writer.printf(headerPattern, "JobId", "JobName", "State", "StartTime",
+      "UserName", "Queue", "Priority", "UsedContainers",
       "RsvdContainers", "UsedMem", "RsvdMem", "NeededMem", "AM info");
     for (JobStatus job : jobs) {
       int numUsedSlots = job.getNumUsedSlots();
@@ -634,10 +636,11 @@ public class CLI extends Configured implements Tool {
       int usedMem = job.getUsedMem();
       int rsvdMem = job.getReservedMem();
       int neededMem = job.getNeededMem();
-      writer.printf(dataPattern,
-          job.getJobID().toString(), job.getState(), job.getStartTime(),
-          job.getUsername(), job.getQueue(), 
-          job.getPriority().name(),
+      int jobNameLength = job.getJobName().length();
+      writer.printf(dataPattern, job.getJobID().toString(),
+          job.getJobName().substring(0, jobNameLength > 20 ? 20 : jobNameLength),
+          job.getState(), job.getStartTime(), job.getUsername(),
+          job.getQueue(), job.getPriority().name(),
           numUsedSlots < 0 ? UNAVAILABLE : numUsedSlots,
           numReservedSlots < 0 ? UNAVAILABLE : numReservedSlots,
           usedMem < 0 ? UNAVAILABLE : String.format(memPattern, usedMem),

http://git-wip-us.apache.org/repos/asf/hadoop/blob/8041267f/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMRJobClient.java
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMRJobClient.java
b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMRJobClient.java
index fd36285..191195b 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMRJobClient.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMRJobClient.java
@@ -531,6 +531,49 @@ public class TestMRJobClient extends ClusterMapReduceTestCase {
     verifyJobPriority(jobId, "NORMAL", conf, createJobClient());
   }
 
+  /**
+   * Test -list option displays job name.
+   * The name is capped to 20 characters for display.
+   */
+  public void testJobName() throws Exception {
+    Configuration conf = createJobConf();
+    CLI jc = createJobClient();
+    Job job = MapReduceTestUtil.createJob(conf, getInputDir(), getOutputDir(),
+        1, 1, "short_name");
+    job.setJobName("mapreduce");
+    job.setPriority(JobPriority.NORMAL);
+    job.waitForCompletion(true);
+    String jobId = job.getJobID().toString();
+    verifyJobName(jobId, "mapreduce", conf, jc);
+    Job job2 = MapReduceTestUtil.createJob(conf, getInputDir(), getOutputDir(),
+        1, 1, "long_name");
+    job2.setJobName("mapreduce_job_with_long_name");
+    job2.setPriority(JobPriority.NORMAL);
+    job2.waitForCompletion(true);
+    jobId = job2.getJobID().toString();
+    verifyJobName(jobId, "mapreduce_job_with_l", conf, jc);
+  }
+
+  protected void verifyJobName(String jobId, String name,
+      Configuration conf, CLI jc) throws Exception {
+    PipedInputStream pis = new PipedInputStream();
+    PipedOutputStream pos = new PipedOutputStream(pis);
+    int exitCode = runTool(conf, jc,
+        new String[] { "-list", "all" }, pos);
+    assertEquals("Exit code", 0, exitCode);
+    BufferedReader br = new BufferedReader(new InputStreamReader(pis));
+    String line = null;
+    while ((line = br.readLine()) != null) {
+      LOG.info("line = " + line);
+      if (!line.contains(jobId)) {
+        continue;
+      }
+      assertTrue(line.contains(name));
+      break;
+    }
+    pis.close();
+  }
+
   protected CLI createJobClient() throws IOException {
     return new CLI();
   }


Mime
View raw message