MAPREDUCE-6889. Add Job#close API to shutdown MR client services. Contributed by Rohith Sharma K S.

This commit is contained in:
Sunil G 2017-07-17 13:35:15 +05:30
parent 02b141ac60
commit fb3b5d33ff
2 changed files with 16 additions and 1 deletions

View File

@ -75,7 +75,7 @@
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Evolving @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); private static final Log LOG = LogFactory.getLog(Job.class);
@InterfaceStability.Evolving @InterfaceStability.Evolving
@ -1553,4 +1553,15 @@ public void setReservationId(ReservationId reservationId) {
this.reservationId = reservationId; this.reservationId = reservationId;
} }
/**
* Close the <code>Job</code>.
* @throws IOException if fail to close.
*/
@Override
public void close() throws IOException {
if (cluster != null) {
cluster.close();
cluster = null;
}
}
} }

View File

@ -329,6 +329,10 @@ public void testJobSuccessCleanup() throws Exception {
Assert.assertTrue(reduceCleanup); Assert.assertTrue(reduceCleanup);
Assert.assertTrue(recordReaderCleanup); Assert.assertTrue(recordReaderCleanup);
Assert.assertTrue(recordWriterCleanup); Assert.assertTrue(recordWriterCleanup);
Assert.assertNotNull(job.getCluster());
job.close();
Assert.assertNull(job.getCluster());
} }
} }