浏览代码

Merge -r 1209790:1209791 from trunk to branch-0.23. Fixes: MAPREDUCE-3479.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1209792 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 13 年之前
父节点
当前提交
c4e06b5aac

+ 2 - 0
hadoop-mapreduce-project/CHANGES.txt

@@ -181,6 +181,8 @@ Release 0.23.1 - Unreleased
     MAPREDUCE-3453. RM web ui application details page shows RM cluster about
     information. (Jonathan Eagles via sseth)
 
+    MAPREDUCE-3479. JobClient#getJob cannot find local jobs. (tomwhite)
+
 Release 0.23.0 - 2011-11-01 
 
   INCOMPATIBLE CHANGES

+ 62 - 0
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapred/TestJobClientGetJob.java

@@ -0,0 +1,62 @@
+/**
+ * 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 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 TestJobClientGetJob {
+  
+  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 testGetRunningJobFromJobClient() throws Exception {
+    JobConf conf = new JobConf();
+    conf.set("mapreduce.framework.name", "local");
+    FileInputFormat.addInputPath(conf, createTempFile("in", "hello"));
+    FileOutputFormat.setOutputPath(conf,
+        new Path(TEST_ROOT_DIR, getClass().getSimpleName()));
+    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);
+  }
+
+}

+ 4 - 0
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java

@@ -584,6 +584,10 @@ public class JobClient extends CLI {
           return job;
         }
       });
+      // update our Cluster instance with the one created by Job for submission
+      // (we can't pass our Cluster instance to Job, since Job wraps the config
+      // instance, and the two configs would then diverge)
+      cluster = job.getCluster();
       return new NetworkedJob(job);
     } catch (InterruptedException ie) {
       throw new IOException("interrupted", ie);

+ 5 - 0
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java

@@ -436,6 +436,11 @@ public class Job extends JobContextImpl implements JobContext {
     updateStatus();
     return status.isRetired();
   }
+  
+  @Private
+  public Cluster getCluster() {
+    return cluster;
+  }
 
   /** Only for mocks in unit tests. */
   @Private