merge YARN-406 from trunk. Fix TestRackResolver to function in networks where "host1" resolves to a valid host. Contributed by Hitesh Shah.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1451392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Siddharth Seth 2013-02-28 22:18:38 +00:00
parent a8dee7c237
commit ae994bd3b6
2 changed files with 20 additions and 1 deletions

View File

@ -30,6 +30,9 @@ Release 2.0.4-beta - UNRELEASED
YARN-390. ApplicationCLI and NodeCLI hard-coded platform-specific line YARN-390. ApplicationCLI and NodeCLI hard-coded platform-specific line
separator causes test failures on Windows. (Chris Nauroth via suresh) separator causes test failures on Windows. (Chris Nauroth via suresh)
YARN-406. Fix TestRackResolver to function in networks where "host1"
resolves to a valid host. (Hitesh Shah via sseth)
Release 2.0.3-alpha - 2013-02-06 Release 2.0.3-alpha - 2013-02-06
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -18,9 +18,13 @@
package org.apache.hadoop.yarn.util; package org.apache.hadoop.yarn.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log;
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;
@ -30,9 +34,12 @@ import org.junit.Test;
public class TestRackResolver { public class TestRackResolver {
private static Log LOG = LogFactory.getLog(TestRackResolver.class);
public static final class MyResolver implements DNSToSwitchMapping { public static final class MyResolver implements DNSToSwitchMapping {
int numHost1 = 0; int numHost1 = 0;
public static String resolvedHost1 = "host1";
@Override @Override
public List<String> resolve(List<String> hostList) { public List<String> resolve(List<String> hostList) {
@ -43,7 +50,10 @@ public class TestRackResolver {
if (hostList.isEmpty()) { if (hostList.isEmpty()) {
return returnList; return returnList;
} }
if (hostList.get(0).equals("host1")) { LOG.info("Received resolve request for "
+ hostList.get(0));
if (hostList.get(0).equals("host1")
|| hostList.get(0).equals(resolvedHost1)) {
numHost1++; numHost1++;
returnList.add("/rack1"); returnList.add("/rack1");
} }
@ -62,6 +72,12 @@ public class TestRackResolver {
CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY, CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
MyResolver.class, DNSToSwitchMapping.class); MyResolver.class, DNSToSwitchMapping.class);
RackResolver.init(conf); RackResolver.init(conf);
try {
InetAddress iaddr = InetAddress.getByName("host1");
MyResolver.resolvedHost1 = iaddr.getHostAddress();
} catch (UnknownHostException e) {
// Ignore if not found
}
Node node = RackResolver.resolve("host1"); Node node = RackResolver.resolve("host1");
Assert.assertEquals("/rack1", node.getNetworkLocation()); Assert.assertEquals("/rack1", node.getNetworkLocation());
node = RackResolver.resolve("host1"); node = RackResolver.resolve("host1");