This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/master by this push:
     new 46e1536d CURATOR-638: Use getHostString() to build connection string 
in EnsembleTracker (#425)
46e1536d is described below

commit 46e1536d3309adcfc10c072d84d46d6ab24eb4fc
Author: Kezhu Wang <kez...@gmail.com>
AuthorDate: Sun Jul 17 15:49:40 2022 +0800

    CURATOR-638: Use getHostString() to build connection string in 
EnsembleTracker (#425)
    
    In Kubernetes, IP addresses are not resistant to pod restart.
    `InetSocketAddress.getAddress().getHostAddress()` could target to non
    ZooKeeper pods and causes curator fail to reach ZooKeeper ensemble.
    
    Further more, this is compatible with `QuorumVerifier.toString` and
    `QuorumServer.toString`.
---
 .../java/org/apache/curator/framework/imps/EnsembleTracker.java   | 2 +-
 .../org/apache/curator/framework/imps/TestReconfiguration.java    | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
index 274a95e8..cc4bc438 100644
--- 
a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
+++ 
b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
@@ -186,7 +186,7 @@ public class EnsembleTracker implements Closeable, 
CuratorWatcher
             }
             else
             {
-                hostAddress = server.clientAddr.getAddress().getHostAddress();
+                hostAddress = server.clientAddr.getHostString();
             }
             
sb.append(hostAddress).append(":").append(server.clientAddr.getPort());
         }
diff --git 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index 435d17a7..ed58dac7 100644
--- 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -476,6 +476,14 @@ public class TestReconfiguration extends CuratorTestBase
         assertEquals("", configString);
     }
 
+    @Test
+    public void testHostname() throws Exception
+    {
+        String config = 
"server.1=localhost:2888:3888:participant;localhost:2181";
+        String configString = 
EnsembleTracker.configToConnectionString(toQuorumVerifier(config.getBytes()));
+        assertEquals("localhost:2181", configString);
+    }
+
     @Test
     public void testIPv6Wildcard1() throws Exception
     {

Reply via email to