From c50033d0c850a55aa013139bb3d47a28d712d64e Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Mon, 8 Oct 2012 18:17:39 +0000 Subject: [PATCH] HADOOP-8804. Improve Web UIs when the wildcard address is used. Contributed by Senthil Kumar git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1395703 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/util/StringUtils.java | 4 ++++ .../org/apache/hadoop/util/TestStringUtils.java | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 14d3bb510c..ae8e301d77 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -292,6 +292,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-8889. Upgrade to Surefire 2.12.3 (todd) + HADOOP-8804. Improve Web UIs when the wildcard address is used. + (Senthil Kumar via eli) + OPTIMIZATIONS HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java index ba32269f5f..1296767c50 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java @@ -34,6 +34,7 @@ import java.util.Locale; import java.util.StringTokenizer; +import com.google.common.net.InetAddresses; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.fs.Path; @@ -77,6 +78,9 @@ public static String stringifyException(Throwable e) { * @return the hostname to the first dot */ public static String simpleHostname(String fullHostname) { + if (InetAddresses.isInetAddress(fullHostname)) { + return fullHostname; + } int offset = fullHostname.indexOf('.'); if (offset != -1) { return fullHostname.substring(0, offset); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java index 0ab86497d3..8d2fa155e1 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestStringUtils.java @@ -282,6 +282,19 @@ public void testStringToURI() { } } + @Test + public void testSimpleHostName() { + assertEquals("Should return hostname when FQDN is specified", + "hadoop01", + StringUtils.simpleHostname("hadoop01.domain.com")); + assertEquals("Should return hostname when only hostname is specified", + "hadoop01", + StringUtils.simpleHostname("hadoop01")); + assertEquals("Should not truncate when IP address is passed", + "10.10.5.68", + StringUtils.simpleHostname("10.10.5.68")); + } + // Benchmark for StringUtils split public static void main(String []args) { final String TO_SPLIT = "foo,bar,baz,blah,blah";