hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtcarre...@apache.org
Subject hadoop git commit: MAPREDUCE-6110. JobHistoryServer CLI throws NullPointerException with job ids that do not exist. (Kai Sasaki via gtcarrera9)
Date Tue, 22 Mar 2016 21:31:19 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 4dd02f948 -> 8bbb5efbf


MAPREDUCE-6110. JobHistoryServer CLI throws NullPointerException with job ids that do not
exist. (Kai Sasaki via gtcarrera9)

(cherry picked from commit 57ead18a85e15aef1993f49157cf05aed38f1c87)


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

Branch: refs/heads/branch-2
Commit: 8bbb5efbfb4f6fc207bb325407a9f37a55f2594b
Parents: 4dd02f9
Author: Li Lu <gtcarrera9@apache.org>
Authored: Tue Mar 22 14:27:32 2016 -0700
Committer: Li Lu <gtcarrera9@apache.org>
Committed: Tue Mar 22 14:29:12 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/mapreduce/tools/CLI.java  | 48 +++++++++++++-------
 .../apache/hadoop/mapreduce/tools/TestCLI.java  | 38 +++++++++++++++-
 2 files changed, 68 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8bbb5efb/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 a8208c0..41fe133 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
@@ -402,8 +402,13 @@ public class CLI extends Configured implements Tool {
           }
         }
       } else if (listEvents) {
-        listEvents(getJob(JobID.forName(jobid)), fromEvent, nEvents);
-        exitCode = 0;
+        Job job = getJob(JobID.forName(jobid));
+        if (job == null) {
+          System.out.println("Could not find job " + jobid);
+        } else {
+          listEvents(job, fromEvent, nEvents);
+          exitCode = 0;
+        }
       } else if (listJobs) {
         listJobs(cluster);
         exitCode = 0;
@@ -417,8 +422,13 @@ public class CLI extends Configured implements Tool {
         listBlacklistedTrackers(cluster);
         exitCode = 0;
       } else if (displayTasks) {
-        displayTasks(getJob(JobID.forName(jobid)), taskType, taskState);
-        exitCode = 0;
+        Job job = getJob(JobID.forName(jobid));
+        if (job == null) {
+          System.out.println("Could not find job " + jobid);
+        } else {
+          displayTasks(getJob(JobID.forName(jobid)), taskType, taskState);
+          exitCode = 0;
+        }
       } else if(killTask) {
         TaskAttemptID taskID = TaskAttemptID.forName(taskid);
         Job job = getJob(taskID.getJobID());
@@ -444,20 +454,24 @@ public class CLI extends Configured implements Tool {
           exitCode = -1;
         }
       } else if (logs) {
-        try {
         JobID jobID = JobID.forName(jobid);
-        TaskAttemptID taskAttemptID = TaskAttemptID.forName(taskid);
-        LogParams logParams = cluster.getLogParams(jobID, taskAttemptID);
-        LogCLIHelpers logDumper = new LogCLIHelpers();
-        logDumper.setConf(getConf());
-        exitCode = logDumper.dumpAContainersLogs(logParams.getApplicationId(),
-            logParams.getContainerId(), logParams.getNodeId(),
-            logParams.getOwner());
-        } catch (IOException e) {
-          if (e instanceof RemoteException) {
-            throw e;
-          } 
-          System.out.println(e.getMessage());
+        if (getJob(jobID) == null) {
+          System.out.println("Could not find job " + jobid);
+        } else {
+          try {
+            TaskAttemptID taskAttemptID = TaskAttemptID.forName(taskid);
+            LogParams logParams = cluster.getLogParams(jobID, taskAttemptID);
+            LogCLIHelpers logDumper = new LogCLIHelpers();
+            logDumper.setConf(getConf());
+            exitCode = logDumper.dumpAContainersLogs(
+                    logParams.getApplicationId(), logParams.getContainerId(),
+                    logParams.getNodeId(), logParams.getOwner());
+          } catch (IOException e) {
+            if (e instanceof RemoteException) {
+              throw e;
+            }
+            System.out.println(e.getMessage());
+          }
         }
       }
     } catch (RemoteException re) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/8bbb5efb/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java
b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java
index 73f57d5..112f585 100644
--- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java
+++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java
@@ -87,7 +87,7 @@ public class TestCLI {
     JobID jobId = JobID.forName(jobIdStr);
     Cluster mockCluster = mock(Cluster.class);
     Job job = mock(Job.class);
-    CLI cli = spy(new CLI());
+    CLI cli = spy(new CLI(new Configuration()));
 
     doReturn(mockCluster).when(cli).createCluster();
     when(mockCluster.getJob(jobId)).thenReturn(job);
@@ -101,12 +101,18 @@ public class TestCLI {
     int retCode_invalidTaskState = cli.run(new String[] { "-list-attempt-ids",
         jobIdStr, "REDUCE", "complete" });
 
+    String jobIdStr2 = "job_1015298225799_0016";
+    int retCode_invalidJobId = cli.run(new String[] { "-list-attempt-ids",
+        jobIdStr2, "MAP", "running" });
+
     assertEquals("JOB_SETUP is an invalid input,exit code should be -1", -1,
         retCode_JOB_SETUP);
     assertEquals("JOB_CLEANUP is an invalid input,exit code should be -1", -1,
         retCode_JOB_CLEANUP);
     assertEquals("complete is an invalid input,exit code should be -1", -1,
         retCode_invalidTaskState);
+    assertEquals("Non existing job id should be skippted with -1", -1,
+        retCode_invalidJobId);
 
   }
 
@@ -176,4 +182,34 @@ public class TestCLI {
       Assert.assertTrue(end - start < ((i + 1) * sleepTime));
     }
   }
+
+  @Test
+  public void testListEvents() throws Exception {
+    Cluster mockCluster = mock(Cluster.class);
+    CLI cli = spy(new CLI(new Configuration()));
+    doReturn(mockCluster).when(cli).createCluster();
+    String jobId1 = "job_1234654654_001";
+    String jobId2 = "job_1234654656_002";
+
+    Job mockJob1 = mockJob(mockCluster, jobId1, State.RUNNING);
+
+    // Check exiting with non existing job
+    int exitCode = cli.run(new String[]{"-events", jobId2, "0", "10"});
+    assertEquals(-1, exitCode);
+  }
+
+  @Test
+  public void testLogs() throws Exception {
+    Cluster mockCluster = mock(Cluster.class);
+    CLI cli = spy(new CLI(new Configuration()));
+    doReturn(mockCluster).when(cli).createCluster();
+    String jobId1 = "job_1234654654_001";
+    String jobId2 = "job_1234654656_002";
+
+    Job mockJob1 = mockJob(mockCluster, jobId1, State.SUCCEEDED);
+
+    // Check exiting with non existing job
+    int exitCode = cli.run(new String[]{"-logs", jobId2});
+    assertEquals(-1, exitCode);
+  }
 }


Mime
View raw message