HADOOP-8372. Merging change r1336446 from trunk
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1336451 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
00f0379a54
commit
920663da2d
|
@ -300,6 +300,9 @@ Release 2.0.0 - UNRELEASED
|
||||||
HADOOP-8359. Fix javadoc warnings in Configuration. (Anupam Seth via
|
HADOOP-8359. Fix javadoc warnings in Configuration. (Anupam Seth via
|
||||||
szetszwo)
|
szetszwo)
|
||||||
|
|
||||||
|
HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname
|
||||||
|
starting with a numeric character. (Junping Du via suresh)
|
||||||
|
|
||||||
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
||||||
|
|
||||||
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
||||||
|
|
|
@ -494,7 +494,7 @@ public class NetUtils {
|
||||||
* also takes a local address and port to bind the socket to.
|
* also takes a local address and port to bind the socket to.
|
||||||
*
|
*
|
||||||
* @param socket
|
* @param socket
|
||||||
* @param address the remote address
|
* @param endpoint the remote address
|
||||||
* @param localAddr the local address to bind the socket to
|
* @param localAddr the local address to bind the socket to
|
||||||
* @param timeout timeout in milliseconds
|
* @param timeout timeout in milliseconds
|
||||||
*/
|
*/
|
||||||
|
@ -549,16 +549,11 @@ public class NetUtils {
|
||||||
* @return its IP address in the string format
|
* @return its IP address in the string format
|
||||||
*/
|
*/
|
||||||
public static String normalizeHostName(String name) {
|
public static String normalizeHostName(String name) {
|
||||||
if (Character.digit(name.charAt(0), 10) != -1) { // it is an IP
|
try {
|
||||||
|
return InetAddress.getByName(name).getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
return name;
|
return name;
|
||||||
} else {
|
}
|
||||||
try {
|
|
||||||
InetAddress ipAddress = InetAddress.getByName(name);
|
|
||||||
return ipAddress.getHostAddress();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,9 @@ import java.net.SocketException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
|
@ -42,8 +44,6 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.security.NetUtilsTestResolver;
|
import org.apache.hadoop.security.NetUtilsTestResolver;
|
||||||
import org.apache.hadoop.test.MultithreadedTestUtil.TestContext;
|
|
||||||
import org.apache.hadoop.test.MultithreadedTestUtil.TestingThread;
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -599,6 +599,26 @@ public class TestNetUtils {
|
||||||
assertEquals("scheme://host.a.b/path", uri.toString());
|
assertEquals("scheme://host.a.b/path", uri.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link NetUtils#normalizeHostNames}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNormalizeHostName() {
|
||||||
|
List<String> hosts = Arrays.asList(new String[] {"127.0.0.1",
|
||||||
|
"localhost", "3w.org", "UnknownHost"});
|
||||||
|
List<String> normalizedHosts = NetUtils.normalizeHostNames(hosts);
|
||||||
|
// when ipaddress is normalized, same address is expected in return
|
||||||
|
assertEquals(normalizedHosts.get(0), hosts.get(0));
|
||||||
|
// for normalizing a resolvable hostname, resolved ipaddress is expected in return
|
||||||
|
assertFalse(normalizedHosts.get(1).equals(hosts.get(1)));
|
||||||
|
assertEquals(normalizedHosts.get(1), hosts.get(0));
|
||||||
|
// this address HADOOP-8372: when normalizing a valid resolvable hostname start with numeric,
|
||||||
|
// its ipaddress is expected to return
|
||||||
|
assertFalse(normalizedHosts.get(2).equals(hosts.get(2)));
|
||||||
|
// return the same hostname after normalizing a irresolvable hostname.
|
||||||
|
assertEquals(normalizedHosts.get(3), hosts.get(3));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetHostNameOfIP() {
|
public void testGetHostNameOfIP() {
|
||||||
assertNull(NetUtils.getHostNameOfIP(null));
|
assertNull(NetUtils.getHostNameOfIP(null));
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class TestTableMapping {
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
mappingFile = File.createTempFile(getClass().getSimpleName(), ".txt");
|
mappingFile = File.createTempFile(getClass().getSimpleName(), ".txt");
|
||||||
Files.write("a.b.c /rack1\n" +
|
Files.write("a.b.c /rack1\n" +
|
||||||
"1.2.3\t/rack2\n", mappingFile, Charsets.UTF_8);
|
"1.2.3.4\t/rack2\n", mappingFile, Charsets.UTF_8);
|
||||||
mappingFile.deleteOnExit();
|
mappingFile.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class TestTableMapping {
|
||||||
|
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
names.add("a.b.c");
|
names.add("a.b.c");
|
||||||
names.add("1.2.3");
|
names.add("1.2.3.4");
|
||||||
|
|
||||||
List<String> result = mapping.resolve(names);
|
List<String> result = mapping.resolve(names);
|
||||||
assertEquals(names.size(), result.size());
|
assertEquals(names.size(), result.size());
|
||||||
|
@ -73,7 +73,7 @@ public class TestTableMapping {
|
||||||
|
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
names.add("a.b.c");
|
names.add("a.b.c");
|
||||||
names.add("1.2.3");
|
names.add("1.2.3.4");
|
||||||
|
|
||||||
List<String> result1 = mapping.resolve(names);
|
List<String> result1 = mapping.resolve(names);
|
||||||
assertEquals(names.size(), result1.size());
|
assertEquals(names.size(), result1.size());
|
||||||
|
@ -96,7 +96,7 @@ public class TestTableMapping {
|
||||||
|
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
names.add("a.b.c");
|
names.add("a.b.c");
|
||||||
names.add("1.2.3");
|
names.add("1.2.3.4");
|
||||||
|
|
||||||
List<String> result = mapping.resolve(names);
|
List<String> result = mapping.resolve(names);
|
||||||
assertEquals(names.size(), result.size());
|
assertEquals(names.size(), result.size());
|
||||||
|
@ -114,7 +114,7 @@ public class TestTableMapping {
|
||||||
|
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
names.add("a.b.c");
|
names.add("a.b.c");
|
||||||
names.add("1.2.3");
|
names.add("1.2.3.4");
|
||||||
|
|
||||||
List<String> result = mapping.resolve(names);
|
List<String> result = mapping.resolve(names);
|
||||||
assertEquals(names.size(), result.size());
|
assertEquals(names.size(), result.size());
|
||||||
|
@ -134,7 +134,7 @@ public class TestTableMapping {
|
||||||
|
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
names.add("a.b.c");
|
names.add("a.b.c");
|
||||||
names.add("1.2.3");
|
names.add("1.2.3.4");
|
||||||
|
|
||||||
List<String> result = mapping.resolve(names);
|
List<String> result = mapping.resolve(names);
|
||||||
assertEquals(names.size(), result.size());
|
assertEquals(names.size(), result.size());
|
||||||
|
|
Loading…
Reference in New Issue