diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java index 91e4c9d..b907119 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java @@ -18,6 +18,7 @@ */ package org.apache.hadoop.hbase; +import com.google.common.net.InetAddresses; import com.google.protobuf.InvalidProtocolBufferException; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; @@ -95,12 +96,25 @@ public class ServerName implements Comparable { public static final List EMPTY_SERVER_LIST = new ArrayList(0); public ServerName(final String hostname, final int port, final long startcode) { - this.hostname = hostname; + // Drop the domain is there is one; no need of it in a local cluster. With it, we get long + // unwieldy names. + this.hostname = getHostNameMinusDomain(hostname); this.port = port; this.startcode = startcode; this.servername = getServerName(hostname, port, startcode); } + /** + * @param hostname + * @return hostname minus the domain, if there is one (will do pass-through on ip addresses) + */ + static String getHostNameMinusDomain(final String hostname) { + if (InetAddresses.isInetAddress(hostname)) return hostname; + String [] parts = hostname.split("\\."); + if (parts == null || parts.length == 0) return hostname; + return parts[0]; + } + public ServerName(final String serverName) { this(parseHostname(serverName), parsePort(serverName), parseStartcode(serverName)); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java index 7d0f775..b235dab 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/JVMClusterUtil.java @@ -48,7 +48,7 @@ public class JVMClusterUtil { private final HRegionServer regionServer; public RegionServerThread(final HRegionServer r, final int index) { - super(r, "RegionServer:" + index + ";" + r.getServerName()); + super(r, "RS:" + index + ";" + r.getServerName()); this.regionServer = r; } @@ -109,7 +109,7 @@ public class JVMClusterUtil { private final HMaster master; public MasterThread(final HMaster m, final int index) { - super(m, "Master:" + index + ";" + m.getServerName()); + super(m, "M:" + index + ";" + m.getServerName()); this.master = m; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java index 52a7c1a..aabd9b6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java @@ -32,6 +32,17 @@ import org.junit.experimental.categories.Category; @Category(SmallTests.class) public class TestServerName { @Test + public void testGetHostNameMinusDomain() { + assertEquals("2607:f0d0:1002:51::4", + ServerName.getHostNameMinusDomain("2607:f0d0:1002:51::4")); + assertEquals("2607:f0d0:1002:0051:0000:0000:0000:0004", + ServerName.getHostNameMinusDomain("2607:f0d0:1002:0051:0000:0000:0000:0004")); + assertEquals("1.1.1.1", ServerName.getHostNameMinusDomain("1.1.1.1")); + assertEquals("x", ServerName.getHostNameMinusDomain("x")); + assertEquals("x", ServerName.getHostNameMinusDomain("x.y.z")); + } + + @Test public void testRegexPatterns() { assertTrue(Pattern.matches(Addressing.VALID_PORT_REGEX, "123")); assertFalse(Pattern.matches(Addressing.VALID_PORT_REGEX, ""));