YARN-1032. Fixed NPE in RackResolver. Contributed by Lohit Vijayarenu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1529534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Arun Murthy 2013-10-05 22:20:18 +00:00
parent 25361d56cf
commit d55f3780fb
3 changed files with 22 additions and 2 deletions

View File

@ -179,6 +179,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

View File

@ -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);
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);
}

View File

@ -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")
@ -90,6 +98,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());
}
}