Merge -c 1529534 from trunk to branch-2 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@1529535 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Arun Murthy 2013-10-05 22:21:22 +00:00
parent b5df25e3a8
commit 3fa40ca807
3 changed files with 22 additions and 2 deletions

View File

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

View File

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

View File

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