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/branches/branch-2@1395704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-10-08 18:21:09 +00:00
parent 2a2fec7128
commit 67360e4545
3 changed files with 20 additions and 0 deletions

View File

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

View File

@ -34,6 +34,7 @@ import java.util.List;
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 class StringUtils {
* @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);

View File

@ -281,6 +281,19 @@ public class TestStringUtils extends UnitTestcaseTimeLimit {
}
}
@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";