Selaa lähdekoodia

Merge -c 1529534 from trunk to branch-2.1-beta to fix YARN-1032. Fixed NPE in RackResolver. Contributed by Lohit Vijayarenu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2.1-beta@1529536 13f79535-47bb-0310-9956-ffa450edef68
Arun Murthy 11 vuotta sitten
vanhempi
commit
aba04ce0fb

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

@@ -113,6 +113,8 @@ Release 2.1.2 - UNRELEASED
     YARN-1273. Fixed Distributed-shell to account for containers that failed
     to start. (Hitesh Shah via vinodkv)
 
+    YARN-1032. Fixed NPE in RackResolver. (Lohit Vijayarenu via acmurthy)
+
 Release 2.1.1-beta - 2013-09-23
 
   INCOMPATIBLE CHANGES

+ 10 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/RackResolver.java

@@ -29,6 +29,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.net.CachedDNSToSwitchMapping;
 import org.apache.hadoop.net.DNSToSwitchMapping;
+import org.apache.hadoop.net.NetworkTopology;
 import org.apache.hadoop.net.Node;
 import org.apache.hadoop.net.NodeBase;
 import org.apache.hadoop.net.ScriptBasedMapping;
@@ -98,8 +99,15 @@ public class RackResolver {
     List <String> tmpList = new ArrayList<String>(1);
     tmpList.add(hostName);
     List <String> rNameList = dnsToSwitchMapping.resolve(tmpList);
-    String rName = rNameList.get(0);
-    LOG.info("Resolved " + hostName + " to " + rName);
+    String rName = null;
+    if (rNameList == null || rNameList.get(0) == null) {
+      rName = NetworkTopology.DEFAULT_RACK;
+      LOG.info("Couldn't resolve " + hostName + ". Falling back to "
+          + NetworkTopology.DEFAULT_RACK);
+    } else {
+      rName = rNameList.get(0);
+      LOG.info("Resolved " + hostName + " to " + rName);
+    }
     return new NodeBase(hostName, rName);
   }
 

+ 10 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestRackResolver.java

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.net.DNSToSwitchMapping;
+import org.apache.hadoop.net.NetworkTopology;
 import org.apache.hadoop.net.Node;
 import org.junit.Assert;
 import org.junit.Test;
@@ -35,6 +36,8 @@ import org.junit.Test;
 public class TestRackResolver {
 
   private static Log LOG = LogFactory.getLog(TestRackResolver.class);
+  private static final String invalidHost = "invalidHost";
+
 
   public static final class MyResolver implements DNSToSwitchMapping {
 
@@ -50,6 +53,11 @@ public class TestRackResolver {
       if (hostList.isEmpty()) {
         return returnList;
       }
+      if (hostList.get(0).equals(invalidHost)) {
+        // Simulate condition where resolving host returns null
+        return null; 
+      }
+        
       LOG.info("Received resolve request for "
           + hostList.get(0));
       if (hostList.get(0).equals("host1")
@@ -86,6 +94,8 @@ public class TestRackResolver {
     Assert.assertEquals("/rack1", node.getNetworkLocation());
     node = RackResolver.resolve("host1");
     Assert.assertEquals("/rack1", node.getNetworkLocation());
+    node = RackResolver.resolve(invalidHost);
+    Assert.assertEquals(NetworkTopology.DEFAULT_RACK, node.getNetworkLocation());
   }
 
 }