You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ul...@apache.org on 2021/12/22 06:40:20 UTC

[incubator-kyuubi] branch branch-1.4 updated: [KYUUBI #1593] use user set host or ip instead of read hostname from user set

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

ulyssesyou pushed a commit to branch branch-1.4
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/branch-1.4 by this push:
     new c6f7464  [KYUUBI #1593] use user set host or ip instead of read hostname from user set
c6f7464 is described below

commit c6f7464343c5735fb75e5bea668941ae35fcfc0d
Author: zwangsheng <22...@qq.com>
AuthorDate: Wed Dec 22 14:39:56 2021 +0800

    [KYUUBI #1593] use user set host or ip instead of read hostname from user set
    
    <!--
    Thanks for sending a pull request!
    
    Here are some tips for you:
      1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
      2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
      3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
    -->
    
    ### _Why are the changes needed?_
    <!--
    Please clarify why the changes are needed. For instance,
      1. If you add a feature, you can talk about the use case of it.
      2. If you fix a bug, you can clarify why it is a bug.
    -->
    User can select IP or hostname for binding.
    Detail #1593
    
    ### _How was this patch tested?_
    - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #1602 from zwangsheng/kyuubi/1593-01.
    
    Closes #1593
    
    8897ec46 [zwangsheng] fix test
    67452451 [zwangsheng] use use set
    76af3072 [zwangsheng] fix test
    f75d2db0 [zwangsheng] 1593
    
    Authored-by: zwangsheng <22...@qq.com>
    Signed-off-by: ulysses-you <ul...@apache.org>
    (cherry picked from commit d595eb97a1608c182a2961fd16ab2690304c2979)
    Signed-off-by: ulysses-you <ul...@apache.org>
---
 .../org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala | 12 ++++++------
 .../kyuubi/zookeeper/EmbeddedZookeeperSuite.scala       | 17 +++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala b/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
index 3301c2a..24aaba2 100644
--- a/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
+++ b/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
@@ -18,7 +18,7 @@
 package org.apache.kyuubi.zookeeper
 
 import java.io.File
-import java.net.{InetAddress, InetSocketAddress}
+import java.net.InetSocketAddress
 
 import org.apache.zookeeper.server.{NIOServerCnxnFactory, ZooKeeperServer}
 
@@ -34,6 +34,7 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
   private var dataDirectory: File = _
   // TODO: Is it right in prod?
   private val deleteDataDirectoryOnClose = true
+  private var host: String = _
 
   override def initialize(conf: KyuubiConf): Unit = synchronized {
     dataDirectory = new File(conf.get(ZK_DATA_DIR))
@@ -42,15 +43,15 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
     val maxClientCnxns = conf.get(ZK_MAX_CLIENT_CONNECTIONS)
     val minSessionTimeout = conf.get(ZK_MIN_SESSION_TIMEOUT)
     val maxSessionTimeout = conf.get(ZK_MAX_SESSION_TIMEOUT)
-    val hostname = conf.get(ZK_CLIENT_PORT_ADDRESS).map(InetAddress.getByName)
-      .getOrElse(findLocalInetAddress).getCanonicalHostName
+    host = conf.get(ZK_CLIENT_PORT_ADDRESS)
+      .getOrElse(findLocalInetAddress.getCanonicalHostName)
 
     zks = new ZooKeeperServer(dataDirectory, dataDirectory, tickTime)
     zks.setMinSessionTimeout(minSessionTimeout)
     zks.setMaxSessionTimeout(maxSessionTimeout)
 
     serverFactory = new NIOServerCnxnFactory
-    serverFactory.configure(new InetSocketAddress(hostname, clientPort), maxClientCnxns)
+    serverFactory.configure(new InetSocketAddress(host, clientPort), maxClientCnxns)
 
     super.initialize(conf)
   }
@@ -74,7 +75,6 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
 
   def getConnectString: String = synchronized {
     assert(zks != null, s"$getName is in $getServiceState")
-    s"${serverFactory.getLocalAddress.getHostName}:${serverFactory.getLocalPort}"
+    s"${host}:${serverFactory.getLocalPort}"
   }
-
 }
diff --git a/kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala b/kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala
index a081593..837e0c3 100644
--- a/kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala
+++ b/kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala
@@ -24,6 +24,7 @@ import org.apache.curator.retry.ExponentialBackoffRetry
 import org.apache.kyuubi.KyuubiFunSuite
 import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.service.ServiceState._
+import org.apache.kyuubi.zookeeper.ZookeeperConf.{ZK_CLIENT_PORT, ZK_CLIENT_PORT_ADDRESS}
 
 class EmbeddedZookeeperSuite extends KyuubiFunSuite {
 
@@ -62,4 +63,20 @@ class EmbeddedZookeeperSuite extends KyuubiFunSuite {
     assert(zkClient.getState === CuratorFrameworkState.STARTED)
     assert(zkClient.getZookeeperClient.blockUntilConnectedOrTimedOut())
   }
+
+  test("use zookeeper.embedded.client.port.address cover default hostname") {
+    var zkServer = new EmbeddedZookeeper()
+    // cover default hostname
+    var conf = KyuubiConf()
+      .set(ZK_CLIENT_PORT, 0)
+      .set(ZK_CLIENT_PORT_ADDRESS, "localhost")
+    zkServer.initialize(conf)
+    assert(zkServer.getConnectString.contains("localhost"))
+    zkServer = new EmbeddedZookeeper()
+    conf = KyuubiConf()
+      .set(ZK_CLIENT_PORT, 0)
+      .set(ZK_CLIENT_PORT_ADDRESS, "127.0.0.1")
+    zkServer.initialize(conf)
+    assert(zkServer.getConnectString.contains("127.0.0.1"))
+  }
 }