From 928e6864d397b05010564321d41a47f95a2289a8 Mon Sep 17 00:00:00 2001 From: Robert Joseph Evans Date: Thu, 6 Sep 2012 22:22:01 +0000 Subject: [PATCH] svn merge -c 1381784 FIXES: MAPREDUCE-4641. Exception in commitJob marks job as successful in job history (Jason Lowe via bobby) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1381786 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../hadoop/mapreduce/v2/app/job/impl/JobImpl.java | 7 ++++--- .../mapreduce/v2/app/job/impl/TestJobImpl.java | 12 +++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 480034224a5..60d16cda91a 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -759,6 +759,9 @@ Release 0.23.3 - UNRELEASED MAPREDUCE-4633. history server doesn't set permissions on all subdirs (tgraves via bobby) + MAPREDUCE-4641. Exception in commitJob marks job as successful in job + history (Jason Lowe via bobby) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/JobImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/JobImpl.java index 7710bc55d11..65d3c6a09aa 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/JobImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/JobImpl.java @@ -759,7 +759,8 @@ public class JobImpl implements org.apache.hadoop.mapreduce.v2.app.job.Job, job.getCommitter().commitJob(job.getJobContext()); } catch (IOException e) { LOG.error("Could not do commit for Job", e); - job.logJobHistoryFinishedEvent(); + job.addDiagnostic("Job commit failed: " + e.getMessage()); + job.abortJob(org.apache.hadoop.mapreduce.JobStatus.State.FAILED); return job.finished(JobState.FAILED); } job.logJobHistoryFinishedEvent(); @@ -1199,7 +1200,7 @@ public class JobImpl implements org.apache.hadoop.mapreduce.v2.app.job.Job, } } - private void abortJob( + protected void abortJob( org.apache.hadoop.mapreduce.JobStatus.State finalState) { try { committer.abortJob(jobContext, finalState); @@ -1501,7 +1502,7 @@ public class JobImpl implements org.apache.hadoop.mapreduce.v2.app.job.Job, } } - private void addDiagnostic(String diag) { + protected void addDiagnostic(String diag) { diagnostics.add(diag); } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java index 4fea3fb233a..a52e5dd5f67 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TestJobImpl.java @@ -19,9 +19,11 @@ package org.apache.hadoop.mapreduce.v2.app.job.impl; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.IOException; @@ -91,8 +93,6 @@ public class TestJobImpl { when(mockJob.getCommitter()).thenReturn(mockCommitter); when(mockJob.getEventHandler()).thenReturn(mockEventHandler); when(mockJob.getJobContext()).thenReturn(mockJobContext); - doNothing().when(mockJob).setFinishTime(); - doNothing().when(mockJob).logJobHistoryFinishedEvent(); when(mockJob.finished(JobState.KILLED)).thenReturn(JobState.KILLED); when(mockJob.finished(JobState.FAILED)).thenReturn(JobState.FAILED); when(mockJob.finished(JobState.SUCCEEDED)).thenReturn(JobState.SUCCEEDED); @@ -103,11 +103,13 @@ public class TestJobImpl { // commitJob stubbed out, so this can't happen } doNothing().when(mockEventHandler).handle(any(JobHistoryEvent.class)); + JobState jobState = JobImpl.checkJobCompleteSuccess(mockJob); Assert.assertNotNull("checkJobCompleteSuccess incorrectly returns null " + - "for successful job", - JobImpl.checkJobCompleteSuccess(mockJob)); + "for successful job", jobState); Assert.assertEquals("checkJobCompleteSuccess returns incorrect state", - JobState.FAILED, JobImpl.checkJobCompleteSuccess(mockJob)); + JobState.FAILED, jobState); + verify(mockJob).abortJob( + eq(org.apache.hadoop.mapreduce.JobStatus.State.FAILED)); } @Test