1- From 6f9e3cae1bd74e7feeca428d34f078c5542dfc2c Mon Sep 17 00:00:00 2001
1+ From 958fd8f17dd203329b1da058e4714762412b4c57 Mon Sep 17 00:00:00 2001
22From: Andrew Kenworthy <
[email protected] >
33Date: Wed, 16 Apr 2025 16:43:33 +0200
44Subject: extend servername with external host and port
55
66---
7- .../hbase/shaded/protobuf/ProtobufUtil.java | 15 ++++++--
8- .../org/apache/hadoop/hbase/ServerName.java | 35 ++++++++++++++++++-
9- .../src/main/protobuf/HBase.proto | 2 ++
7+ .../hbase/shaded/protobuf/ProtobufUtil.java | 15 ++++++-
8+ .../org/apache/hadoop/hbase/ServerName.java | 43 ++++++++++++++++++-
9+ .../src/main/protobuf/HBase.proto | 2 +
1010 .../main/protobuf/RegionServerStatus.proto | 3 ++
11- hbase-protocol/src/main/protobuf/HBase.proto | 2 ++
12- .../src/main/protobuf/ZooKeeper.proto | 2 ++
11+ hbase-protocol/src/main/protobuf/HBase.proto | 2 +
12+ .../src/main/protobuf/ZooKeeper.proto | 2 +
1313 .../tmpl/master/RegionServerListTmpl.jamon | 2 +-
14- .../apache/hadoop/hbase/master/HMaster.java | 7 ++++
15- .../hadoop/hbase/master/ServerManager.java | 4 ++-
16- .../hbase/regionserver/HRegionServer.java | 16 ++++++++-
17- .../resources/hbase-webapps/master/hbck.jsp | 4 +--
18- .../hbase-webapps/master/rsgroup.jsp | 15 +++-----
19- .../resources/hbase-webapps/master/table.jsp | 30 ++++++++--------
14+ .../tmpl/regionserver/RSStatusTmpl.jamon | 2 +-
15+ .../apache/hadoop/hbase/master/HMaster.java | 7 +++
16+ .../hadoop/hbase/master/ServerManager.java | 4 +-
17+ .../hbase/regionserver/HRegionServer.java | 16 ++++++-
18+ .../resources/hbase-webapps/master/hbck.jsp | 4 +-
19+ .../hbase-webapps/master/rsgroup.jsp | 15 +++----
20+ .../resources/hbase-webapps/master/table.jsp | 30 ++++++-------
2021 .../hbase/zookeeper/MasterAddressTracker.java | 3 ++
21- 14 files changed, 107 insertions(+), 33 deletions(-)
22+ 15 files changed, 116 insertions(+), 34 deletions(-)
2223
2324diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
2425index 0fe181b503..be121ea641 100644
@@ -68,7 +69,7 @@ index 0fe181b503..be121ea641 100644
6869 // A failed parse of the znode is pretty catastrophic. Rather than loop
6970 // retrying hoping the bad bytes will changes, and rather than change
7071diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java
71- index 5223bac3e5..932865ca69 100644
72+ index 5223bac3e5..979eb4c6ae 100644
7273--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java
7374+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/ServerName.java
7475@@ -85,6 +85,8 @@ public class ServerName implements Comparable<ServerName>, Serializable {
@@ -115,7 +116,7 @@ index 5223bac3e5..932865ca69 100644
115116 /**
116117 * Retrieve an instance of ServerName. Callers should use the equals method to compare returned
117118 * instances, though we may return a shared immutable object as an internal optimization.
118- @@ -253,6 +270,22 @@ public class ServerName implements Comparable<ServerName>, Serializable {
119+ @@ -253,6 +270,30 @@ public class ServerName implements Comparable<ServerName>, Serializable {
119120 return this.address.getPort();
120121 }
121122
@@ -127,6 +128,14 @@ index 5223bac3e5..932865ca69 100644
127128+ return this.externalPort;
128129+ }
129130+
131+ + public String getDisplayHostname() {
132+ + return this.externalHostname != null && !this.externalHostname.isEmpty() ? this.externalHostname: this.getHostname();
133+ + }
134+ +
135+ + public Integer getDisplayPort() {
136+ + return this.externalPort != null && this.externalPort > 0 ? this.externalPort: this.getPort();
137+ + }
138+ +
130139+ public void setAddress(Address address) {
131140+ this.address = address;
132141+ }
@@ -192,18 +201,31 @@ index c0f40e970e..bddadf4d30 100644
192201
193202 /**
194203diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/RegionServerListTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/RegionServerListTmpl.jamon
195- index 4c9140470b..604ecd7b2a 100644
204+ index 4c9140470b..641f558d87 100644
196205--- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/RegionServerListTmpl.jamon
197206+++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/RegionServerListTmpl.jamon
198207@@ -500,7 +500,7 @@ if (totalCompactingCells > 0) {
199208 </%args>
200209 <%java>
201210 int infoPort = master.getRegionServerInfoPort(serverName);
202211- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";
203- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";
212+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";
204213 </%java>
205214
206215 <%if infoPort > 0%>
216+ diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
217+ index 23330096cf..3abe5d617d 100644
218+ --- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
219+ +++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon
220+ @@ -245,7 +245,7 @@ org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
221+ No master found
222+ <%else>
223+ <%java>
224+ - String host = masterServerName.getHostname() + ":" + infoPort;
225+ + String host = masterServerName.getDisplayHostname() + ":" + masterServerName.getDisplayPort();
226+ String url = "//" + host + "/master-status";
227+ </%java>
228+ <a href="<% url %>"><% host %></a>
207229diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
208230index 3fe5abac27..652c709ab5 100644
209231--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -279,23 +301,23 @@ index 27bcef2f06..8438378059 100644
279301 } catch (ServiceException se) {
280302 IOException ioe = ProtobufUtil.getRemoteException(se);
281303diff --git a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
282- index 38e16ca8e2..c30fd7753e 100644
304+ index 38e16ca8e2..61e4cf2b17 100644
283305--- a/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
284306+++ b/hbase-server/src/main/resources/hbase-webapps/master/hbck.jsp
285307@@ -364,9 +364,9 @@ private static String formatServerName(HMaster master,
286308 }
287309 String sn = serverName.toString();
288310 if (serverManager.isServerOnline(serverName)) {
289311- int infoPort = master.getRegionServerInfoPort(serverName);
290- + int infoPort = serverName.getExternalPort ();
312+ + int infoPort = serverName.getDisplayPort ();
291313 if (infoPort > 0) {
292314- return "<a href=" + "//" + serverName.getHostname() + ":" +
293- + return "<a href=" + "//" + serverName.getExternalHostname () + ":" +
315+ + return "<a href=" + "//" + serverName.getDisplayHostname () + ":" +
294316 infoPort + "/rs-status>" + sn + "</a>";
295317 } else {
296318 return "<b>" + sn + "</b>";
297319diff --git a/hbase-server/src/main/resources/hbase-webapps/master/rsgroup.jsp b/hbase-server/src/main/resources/hbase-webapps/master/rsgroup.jsp
298- index 6ba6f78a27..f3275b9165 100644
320+ index 6ba6f78a27..d05e1bc8f0 100644
299321--- a/hbase-server/src/main/resources/hbase-webapps/master/rsgroup.jsp
300322+++ b/hbase-server/src/main/resources/hbase-webapps/master/rsgroup.jsp
301323@@ -170,8 +170,7 @@
@@ -304,7 +326,7 @@ index 6ba6f78a27..f3275b9165 100644
304326 long startcode = serverName.getStartcode();
305327- int infoPort = master.getRegionServerInfoPort(serverName);
306328- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";%>
307- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";%>
329+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";%>
308330 <tr>
309331 <td><a href="<%= url %>"><%= serverName.getServerName() %></a></td>
310332 <td><%= new Date(startcode) %></td>
@@ -314,7 +336,7 @@ index 6ba6f78a27..f3275b9165 100644
314336 .sum();
315337- int infoPort = master.getRegionServerInfoPort(serverName);
316338- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";
317- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";
339+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";
318340
319341 if (memStoreSizeMB > 0) {
320342 memStoreSizeMBStr = TraditionalBinaryPrefix.long2String(
@@ -330,7 +352,7 @@ index 6ba6f78a27..f3275b9165 100644
330352 writeRequestCount += rm.getWriteRequestCount();
331353 }
332354- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";
333- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";
355+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";
334356 %>
335357 <tr>
336358 <td><a href="<%= url %>"><%= serverName.getServerName() %></a></td>
@@ -340,7 +362,7 @@ index 6ba6f78a27..f3275b9165 100644
340362 }
341363- int infoPort = master.getRegionServerInfoPort(serverName);
342364- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";
343- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";
365+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";
344366 if (storeUncompressedSizeMB > 0) {
345367 storeUncompressedSizeMBStr = TraditionalBinaryPrefix.long2String(
346368 (long) storeUncompressedSizeMB * TraditionalBinaryPrefix.MEGA.value, "B", 1);
@@ -350,12 +372,12 @@ index 6ba6f78a27..f3275b9165 100644
350372 }
351373- int infoPort = master.getRegionServerInfoPort(serverName);
352374- String url = "//" + serverName.getHostname() + ":" + infoPort + "/rs-status";
353- + String url = "//" + serverName.getExternalHostname () + ":" + serverName.getExternalPort () + "/rs-status";
375+ + String url = "//" + serverName.getDisplayHostname () + ":" + serverName.getDisplayPort () + "/rs-status";
354376 %>
355377 <tr>
356378 <td><a href="<%= url %>"><%= serverName.getServerName() %></a></td>
357379diff --git a/hbase-server/src/main/resources/hbase-webapps/master/table.jsp b/hbase-server/src/main/resources/hbase-webapps/master/table.jsp
358- index 56a0c8096d..49c8a69c60 100644
380+ index 56a0c8096d..01fbde1b18 100644
359381--- a/hbase-server/src/main/resources/hbase-webapps/master/table.jsp
360382+++ b/hbase-server/src/main/resources/hbase-webapps/master/table.jsp
361383@@ -93,8 +93,8 @@
@@ -374,7 +396,7 @@ index 56a0c8096d..49c8a69c60 100644
374396 }
375397
376398- final String socketAddress = serverName.getHostname() + ":" + rsInfoPort;
377- + final String socketAddress = serverName.getExternalHostname () + ":" + serverName.getExternalPort ();
399+ + final String socketAddress = serverName.getDisplayHostname () + ":" + serverName.getDisplayPort ();
378400 final String URI = "//" + socketAddress + "/region.jsp"
379401 + "?name=" + regionInfo.getEncodedName();
380402 return "<a href=\"" + URI + "\">" + serverName.getServerName() + "</a>";
@@ -383,7 +405,7 @@ index 56a0c8096d..49c8a69c60 100644
383405 ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
384406 // The host name portion should be safe, but I don't know how we handle IDNs so err on the side of failing safely.
385407- hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
386- + hostAndPort = URLEncoder.encode(metaLocation.getExternalHostname ()) + ":" + metaLocation.getExternalPort ().toString();
408+ + hostAndPort = URLEncoder.encode(metaLocation.getDisplayHostname ()) + ":" + metaLocation.getDisplayPort ().toString();
387409 if (sl != null) {
388410 Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
389411 if (map.containsKey(meta.getRegionName())) {
@@ -392,7 +414,7 @@ index 56a0c8096d..49c8a69c60 100644
392414 if (metaLocation != null) {
393415 ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
394416- hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
395- + hostAndPort = URLEncoder.encode(metaLocation.getExternalHostname ()) + ":" + metaLocation.getExternalPort ().toString();
417+ + hostAndPort = URLEncoder.encode(metaLocation.getDisplayHostname ()) + ":" + metaLocation.getDisplayPort ().toString();
396418 if (sl != null) {
397419 Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
398420 if (map.containsKey(meta.getRegionName())) {
@@ -401,7 +423,7 @@ index 56a0c8096d..49c8a69c60 100644
401423 if (metaLocation != null) {
402424 ServerMetrics sl = master.getServerManager().getLoad(metaLocation);
403425- hostAndPort = URLEncoder.encode(metaLocation.getHostname()) + ":" + master.getRegionServerInfoPort(metaLocation);
404- + hostAndPort = URLEncoder.encode(metaLocation.getExternalHostname ()) + ":" + metaLocation.getExternalPort ().toString();
426+ + hostAndPort = URLEncoder.encode(metaLocation.getDisplayHostname ()) + ":" + metaLocation.getDisplayPort ().toString();
405427 if (sl != null) {
406428 Map<byte[], RegionMetrics> map = sl.getRegionMetrics();
407429 if (map.containsKey(meta.getRegionName())) {
@@ -419,7 +441,7 @@ index 56a0c8096d..49c8a69c60 100644
419441 // This port might be wrong if RS actually ended up using something else.
420442 urlRegionServer =
421443- "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status";
422- + "//" + URLEncoder.encode(addr.getExternalHostname ()) + ":" + addr.getExternalPort ().toString() + "/rs-status";
444+ + "//" + URLEncoder.encode(addr.getDisplayHostname ()) + ":" + addr.getDisplayPort ().toString() + "/rs-status";
423445 if(sl != null) {
424446 Integer i = regDistribution.get(addr);
425447 if (null == i) i = Integer.valueOf(0);
@@ -428,7 +450,7 @@ index 56a0c8096d..49c8a69c60 100644
428450 %>
429451 <td>
430452- <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %></a>
431- + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getExternalHostname ().toString()) + ":" + addr.getExternalPort ().toString() %></a>
453+ + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getDisplayHostname ().toString()) + ":" + addr.getDisplayPort ().toString() %></a>
432454 </td>
433455 <%
434456 } else {
@@ -437,7 +459,7 @@ index 56a0c8096d..49c8a69c60 100644
437459 // This port might be wrong if RS actually ended up using something else.
438460 urlRegionServer =
439461- "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status";
440- + "//" + URLEncoder.encode(addr.getExternalHostname ()) + ":" + addr.getExternalPort ().toString() + "/rs-status";
462+ + "//" + URLEncoder.encode(addr.getDisplayHostname ()) + ":" + addr.getDisplayPort ().toString() + "/rs-status";
441463 }
442464 if (numRegionsRendered < numRegionsToRender) {
443465 numRegionsRendered++;
@@ -446,7 +468,7 @@ index 56a0c8096d..49c8a69c60 100644
446468 %>
447469 <td>
448470- <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %></a>
449- + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getExternalHostname ().toString()) + ":" + addr.getExternalPort ().toString() %></a>
471+ + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getDisplayHostname ().toString()) + ":" + addr.getDisplayPort ().toString() %></a>
450472 </td>
451473 <%
452474 } else {
@@ -455,7 +477,7 @@ index 56a0c8096d..49c8a69c60 100644
455477 // This port might be wrong if RS actually ended up using something else.
456478 urlRegionServer =
457479- "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status";
458- + "//" + URLEncoder.encode(addr.getExternalHostname ()) + ":" + addr.getExternalPort ().toString() + "/rs-status";
480+ + "//" + URLEncoder.encode(addr.getDisplayHostname ()) + ":" + addr.getDisplayPort ().toString() + "/rs-status";
459481 }
460482 if (numRegionsRendered < numRegionsToRender) {
461483 numRegionsRendered++;
@@ -464,7 +486,7 @@ index 56a0c8096d..49c8a69c60 100644
464486 %>
465487 <td>
466488- <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %></a>
467- + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getExternalHostname ().toString()) + ":" + addr.getExternalPort ().toString() %></a>
489+ + <a href="<%= urlRegionServer %>"><%= addr == null? "-": StringEscapeUtils.escapeHtml4(addr.getDisplayHostname ().toString()) + ":" + addr.getDisplayPort ().toString() %></a>
468490 </td>
469491 <%
470492 } else {
@@ -473,11 +495,11 @@ index 56a0c8096d..49c8a69c60 100644
473495 for (Map.Entry<ServerName, Integer> rdEntry : regDistribution.entrySet()) {
474496 ServerName addr = rdEntry.getKey();
475497- String url = "//" + URLEncoder.encode(addr.getHostname()) + ":" + master.getRegionServerInfoPort(addr) + "/rs-status";
476- + String url = "//" + URLEncoder.encode(addr.getExternalHostname ()) + ":" + addr.getExternalPort ().toString() + "/rs-status";
498+ + String url = "//" + URLEncoder.encode(addr.getDisplayHostname ()) + ":" + addr.getDisplayPort ().toString() + "/rs-status";
477499 %>
478500 <tr>
479501- <td><a href="<%= url %>"><%= StringEscapeUtils.escapeHtml4(addr.getHostname().toString()) + ":" + master.getRegionServerInfoPort(addr) %></a></td>
480- + <td><a href="<%= url %>"><%= StringEscapeUtils.escapeHtml4(addr.getExternalHostname ().toString()) + ":" + addr.getExternalPort ().toString() %></a></td>
502+ + <td><a href="<%= url %>"><%= StringEscapeUtils.escapeHtml4(addr.getDisplayHostname ().toString()) + ":" + addr.getDisplayPort ().toString() %></a></td>
481503 <td><%= rdEntry.getValue()%></td>
482504 <%
483505 if (withReplica) {
0 commit comments