hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1353757 - in /hadoop/common/trunk/hadoop-mapreduce-project: ./ hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/ hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/had...
Date Mon, 25 Jun 2012 21:55:45 GMT
Author: tucu
Date: Mon Jun 25 21:55:44 2012
New Revision: 1353757

URL: http://svn.apache.org/viewvc?rev=1353757&view=rev
Log:
MAPREDUCE-4355. Add JobStatus getJobStatus(JobID) to JobClient. (kkambatl via tucu)

Added:
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java
Removed:
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClientGetJob.java
Modified:
    hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java

Modified: hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt?rev=1353757&r1=1353756&r2=1353757&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt Mon Jun 25 21:55:44 2012
@@ -129,6 +129,8 @@ Branch-2 ( Unreleased changes )
 
   NEW FEATURES
 
+    MAPREDUCE-4355. Add JobStatus getJobStatus(JobID) to JobClient. (kkambatl via tucu)
+
   IMPROVEMENTS
 
     MAPREDUCE-4146. Support limits on task status string length and number of

Added: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java?rev=1353757&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java
(added)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClient.java
Mon Jun 25 21:55:44 2012
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.mapred;
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.Test;
+
+public class TestJobClient {
+  
+  private static Path TEST_ROOT_DIR =
+    new Path(System.getProperty("test.build.data","/tmp"));
+  
+  private Path createTempFile(String filename, String contents)
+      throws IOException {
+    Path path = new Path(TEST_ROOT_DIR, filename);
+    Configuration conf = new Configuration();
+    FSDataOutputStream os = FileSystem.getLocal(conf).create(path);
+    os.writeBytes(contents);
+    os.close();
+    return path;
+  }
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testGetRunningJob() throws Exception {
+    JobConf conf = new JobConf();
+    conf.set("mapreduce.framework.name", "local");
+    FileInputFormat.addInputPath(conf, createTempFile("in", "hello"));
+    Path outputDir = new Path(TEST_ROOT_DIR, getClass().getSimpleName());
+    outputDir.getFileSystem(conf).delete(outputDir, true);
+    FileOutputFormat.setOutputPath(conf, outputDir);
+    JobClient jc = new JobClient(conf);
+    RunningJob runningJob = jc.submitJob(conf);
+    assertNotNull("Running job", runningJob);
+    // Check that the running job can be retrieved by ID
+    RunningJob newRunningJob = jc.getJob(runningJob.getID());
+    assertNotNull("New running job", newRunningJob);
+  }
+
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testGetJobStatus() throws Exception {
+    JobConf conf = new JobConf();
+    conf.set("mapreduce.framework.name", "local");
+    FileInputFormat.addInputPath(conf, createTempFile("in", "hello"));
+    Path outputDir = new Path(TEST_ROOT_DIR, getClass().getSimpleName());
+    outputDir.getFileSystem(conf).delete(outputDir, true);
+    FileOutputFormat.setOutputPath(conf, outputDir);
+    JobClient jc = new JobClient(conf);
+    RunningJob runningJob = jc.submitJob(conf);
+    assertNotNull("Running job", runningJob);
+    JobID jobid = runningJob.getID();
+    JobStatus jobStatus = jc.getJobStatus(jobid);
+    assertNotNull("New running job", jobStatus);
+    assertEquals("Equal JobIDs", jobid, jobStatus.getJobID());
+  }
+}

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java?rev=1353757&r1=1353756&r2=1353757&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java
(original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java
Mon Jun 25 21:55:44 2012
@@ -620,6 +620,15 @@ public class JobClient extends CLI {
     }
   }
 
+  private JobStatus getJobStatusUsingCluster(final JobID jobId)
+      throws IOException, InterruptedException {
+    return clientUgi.doAs(new PrivilegedExceptionAction<JobStatus>() {
+      public JobStatus run() throws IOException, InterruptedException {
+        return JobStatus.downgrade(cluster.getJobStatus(jobId));
+      }
+    });
+  }
+
   private Job getJobUsingCluster(final JobID jobid) throws IOException,
   InterruptedException {
     return clientUgi.doAs(new PrivilegedExceptionAction<Job>() {
@@ -628,28 +637,40 @@ public class JobClient extends CLI {
       }
     });
   }
+
   /**
-   * Get an {@link RunningJob} object to track an ongoing job.  Returns
-   * null if the id does not correspond to any known job.
+   * Get {@link JobStatus} of a job. Returns null if the id does not correspond
+   * to any known job.
    * 
-   * @param jobid the jobid of the job.
-   * @return the {@link RunningJob} handle to track the job, null if the 
+   * @param jobid
+   *          the jobid of the job.
+   * @return the {@link JobStatus} object to retrieve the job stats, null if the
    *         <code>jobid</code> doesn't correspond to any known job.
    * @throws IOException
    */
-  public RunningJob getJob(final JobID jobid) throws IOException {
+  public JobStatus getJobStatus(JobID jobId) throws IOException {
     try {
-      
-      Job job = getJobUsingCluster(jobid);
-      if (job != null) {
-        JobStatus status = JobStatus.downgrade(job.getStatus());
-        if (status != null) {
-          return new NetworkedJob(status, cluster);
-        } 
-      }
+      return getJobStatusUsingCluster(jobId);
     } catch (InterruptedException ie) {
       throw new IOException(ie);
     }
+  }
+
+  /**
+   * Get an {@link RunningJob} object to track an ongoing job. Returns null if
+   * the id does not correspond to any known job.
+   * 
+   * @param jobid
+   *          the jobid of the job.
+   * @return the {@link RunningJob} handle to track the job, null if the
+   *         <code>jobid</code> doesn't correspond to any known job.
+   * @throws IOException
+   */
+  public RunningJob getJob(JobID jobId) throws IOException {
+    JobStatus status = getJobStatus(jobId);
+    if (status != null) {
+      return new NetworkedJob(status, cluster);
+    }
     return null;
   }
 

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java?rev=1353757&r1=1353756&r2=1353757&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java
(original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java
Mon Jun 25 21:55:44 2012
@@ -173,6 +173,19 @@ public class Cluster {
   }
 
   /**
+   * Get JobStatus corresponding to jobId.
+   * 
+   * @param jobId
+   * @return object of {@link JobStatus}
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public JobStatus getJobStatus(JobID jobId) throws IOException,
+      InterruptedException {
+    return client.getJobStatus(jobId);
+  }
+
+  /**
    * Get job corresponding to jobid.
    * 
    * @param jobId
@@ -181,7 +194,7 @@ public class Cluster {
    * @throws InterruptedException
    */
   public Job getJob(JobID jobId) throws IOException, InterruptedException {
-    JobStatus status = client.getJobStatus(jobId);
+    JobStatus status = getJobStatus(jobId);
     if (status != null) {
       return Job.getInstance(this, status, new JobConf(status.getJobFile()));
     }



Mime
View raw message