From fb3b5d33ffb29ee8e1ffbd2eee7a603a5777ebaf Mon Sep 17 00:00:00 2001 From: Sunil G Date: Mon, 17 Jul 2017 13:35:15 +0530 Subject: [PATCH] MAPREDUCE-6889. Add Job#close API to shutdown MR client services. Contributed by Rohith Sharma K S. --- .../main/java/org/apache/hadoop/mapreduce/Job.java | 13 ++++++++++++- .../hadoop/mapreduce/TestMapperReducerCleanup.java | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java index 204876853b..5530d95b77 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java @@ -75,7 +75,7 @@ */ @InterfaceAudience.Public @InterfaceStability.Evolving -public class Job extends JobContextImpl implements JobContext { +public class Job extends JobContextImpl implements JobContext, AutoCloseable { private static final Log LOG = LogFactory.getLog(Job.class); @InterfaceStability.Evolving @@ -1553,4 +1553,15 @@ public void setReservationId(ReservationId reservationId) { this.reservationId = reservationId; } + /** + * Close the Job. + * @throws IOException if fail to close. + */ + @Override + public void close() throws IOException { + if (cluster != null) { + cluster.close(); + cluster = null; + } + } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapperReducerCleanup.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapperReducerCleanup.java index 36ec966b69..27e4e4f4d7 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapperReducerCleanup.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapreduce/TestMapperReducerCleanup.java @@ -329,6 +329,10 @@ public void testJobSuccessCleanup() throws Exception { Assert.assertTrue(reduceCleanup); Assert.assertTrue(recordReaderCleanup); Assert.assertTrue(recordWriterCleanup); + + Assert.assertNotNull(job.getCluster()); + job.close(); + Assert.assertNull(job.getCluster()); } }