accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch 1.7 updated: ACCUMULO-4776 Fix advertised host in monitor
Date Wed, 10 Jan 2018 23:46:01 GMT
This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch 1.7
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/1.7 by this push:
     new bad30a1  ACCUMULO-4776 Fix advertised host in monitor
bad30a1 is described below

commit bad30a1dd059006c607948c35db6feedd5ba7248
Author: Christopher Tubbs <ctubbsii@apache.org>
AuthorDate: Wed Jan 10 18:13:51 2018 -0500

    ACCUMULO-4776 Fix advertised host in monitor
    
    Use the name of the localhost from the local name service when the
    monitor binds to 0.0.0.0 instead of advertising 0.0.0.0, which other
    servers cannot connect to. This fixes log forwarding from other Accumulo
    servers to the monitor when the monitor is configured to bind to all
    interfaces.
---
 .../java/org/apache/accumulo/monitor/Monitor.java  | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
index 1fa82d3..b3e3d5c 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/Monitor.java
@@ -18,6 +18,8 @@ package org.apache.accumulo.monitor;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -480,20 +482,27 @@ public class Monitor {
       server.addServlet(ShellServlet.class, "/shell");
     server.start();
 
-    try {
-      log.debug("Using " + hostname + " to advertise monitor location in ZooKeeper");
-
-      String monitorAddress = HostAndPort.fromParts(hostname, server.getPort()).toString();
+    String advertiseHost = hostname;
+    if (advertiseHost.equals("0.0.0.0")) {
+      try {
+        advertiseHost = InetAddress.getLocalHost().getHostName();
+      } catch (UnknownHostException e) {
+        log.error("Unable to get hostname", e);
+      }
+    }
+    log.debug("Using {} to advertise monitor location in ZooKeeper", advertiseHost);
 
+    try {
+      String monitorAddress = HostAndPort.fromParts(advertiseHost, server.getPort()).toString();
       ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR,
monitorAddress.getBytes(UTF_8),
           NodeExistsPolicy.OVERWRITE);
-      log.info("Set monitor address in zookeeper to " + monitorAddress);
+      log.info("Set monitor address in zookeeper to {}", monitorAddress);
     } catch (Exception ex) {
       log.error("Unable to set monitor HTTP address in zookeeper", ex);
     }
 
-    if (null != hostname) {
-      LogService.startLogListener(Monitor.getContext().getConfiguration(), instance.getInstanceID(),
hostname);
+    if (null != advertiseHost) {
+      LogService.startLogListener(Monitor.getContext().getConfiguration(), instance.getInstanceID(),
advertiseHost);
     } else {
       log.warn("Not starting log4j listener as we could not determine address to use");
     }

-- 
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <commits@accumulo.apache.org>'].

Mime
View raw message