Explorar o código

MAPREDUCE-4355. Add RunningJob.getJobStatus() (kkambatl via tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1357724 13f79535-47bb-0310-9956-ffa450edef68
Alejandro Abdelnur %!s(int64=13) %!d(string=hai) anos
pai
achega
bb3f2f3133

+ 2 - 0
CHANGES.txt

@@ -8,6 +8,8 @@ Release 1.2.0 - unreleased
 
     HADOOP-8023. Add unset() method to Configuration (tucu)
 
+    MAPREDUCE-4355. Add RunningJob.getJobStatus() (kkambatl via tucu)
+
   IMPROVEMENTS
 
     HDFS-3515. Port HDFS-1457 to branch-1. (eli)

+ 6 - 0
src/mapred/org/apache/hadoop/mapred/JobClient.java

@@ -426,6 +426,12 @@ public class JobClient extends Configured implements MRConstants, Tool  {
       ensureFreshStatus();
       return status.getFailureInfo();
     }
+
+    @Override
+    public JobStatus getJobStatus() throws IOException {
+      updateStatus();
+      return status;
+    }
   }
 
   private JobSubmissionProtocol jobSubmitClient;

+ 10 - 3
src/mapred/org/apache/hadoop/mapred/RunningJob.java

@@ -128,15 +128,22 @@ public interface RunningJob {
 
   /**
    * Returns the current state of the Job.
-   * {@link JobStatus}
    * 
    * @throws IOException
    */
   public int getJobState() throws IOException;
   
   /**
-   * Kill the running job.  Blocks until all job tasks have been
-   * killed as well.  If the job is no longer running, it simply returns.
+   * Returns a snapshot of the current status, {@link JobStatus}, of the Job.
+   * Need to call again for latest information.
+   * 
+   * @throws IOException
+   */
+  public JobStatus getJobStatus() throws IOException;
+
+  /**
+   * Kill the running job. Blocks until all job tasks have been killed as well.
+   * If the job is no longer running, it simply returns.
    * 
    * @throws IOException
    */

+ 21 - 6
src/test/org/apache/hadoop/mapred/TestNetworkedJob.java

@@ -18,15 +18,16 @@
 
 package org.apache.hadoop.mapred;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
-import java.util.List;
 
-import org.apache.hadoop.mapred.JobID;
-import org.apache.hadoop.mapreduce.Job;
 import org.junit.Test;
-import static org.mockito.Mockito.*;
 
 public class TestNetworkedJob {
 
@@ -50,7 +51,6 @@ public class TestNetworkedJob {
     JobProfile mockProf = mock(JobProfile.class);
     new JobClient.NetworkedJob(mockStatus, mockProf, null);
   }
-  
 
   @SuppressWarnings("deprecation")
   @Test
@@ -96,4 +96,19 @@ public class TestNetworkedJob {
     verify(mockClient).getJobCounters(id);
   }
 
+  @Test
+  public void testGetJobStatus() throws IOException {
+    JobID id = new JobID("test", 0);
+
+    JobStatus mockStatus = mock(JobStatus.class);
+    JobProfile mockProf = mock(JobProfile.class);
+    JobSubmissionProtocol mockClient = mock(JobSubmissionProtocol.class);
+
+    when(mockProf.getJobID()).thenReturn(id);
+    when(mockClient.getJobStatus(id)).thenReturn(mockStatus);
+
+    RunningJob rj = new JobClient.NetworkedJob(mockStatus, mockProf, mockClient);
+    assertEquals("Expected getJobStatus() to return the correct status",
+        rj.getJobStatus(), mockStatus);
+  }
 }