Skip to content

Commit d595eb9

Browse files
zwangshengulysses-you
authored andcommitted
[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 8897ec4 [zwangsheng] fix test 6745245 [zwangsheng] use use set 76af307 [zwangsheng] fix test f75d2db [zwangsheng] 1593 Authored-by: zwangsheng <2213335496@qq.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 2b8304d commit d595eb9

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.kyuubi.zookeeper
1919

2020
import java.io.File
21-
import java.net.{InetAddress, InetSocketAddress}
21+
import java.net.InetSocketAddress
2222

2323
import org.apache.zookeeper.server.{NIOServerCnxnFactory, ZooKeeperServer}
2424

@@ -34,6 +34,7 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
3434
private var dataDirectory: File = _
3535
// TODO: Is it right in prod?
3636
private val deleteDataDirectoryOnClose = true
37+
private var host: String = _
3738

3839
override def initialize(conf: KyuubiConf): Unit = synchronized {
3940
dataDirectory = new File(conf.get(ZK_DATA_DIR))
@@ -42,15 +43,15 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
4243
val maxClientCnxns = conf.get(ZK_MAX_CLIENT_CONNECTIONS)
4344
val minSessionTimeout = conf.get(ZK_MIN_SESSION_TIMEOUT)
4445
val maxSessionTimeout = conf.get(ZK_MAX_SESSION_TIMEOUT)
45-
val hostname = conf.get(ZK_CLIENT_PORT_ADDRESS).map(InetAddress.getByName)
46-
.getOrElse(findLocalInetAddress).getCanonicalHostName
46+
host = conf.get(ZK_CLIENT_PORT_ADDRESS)
47+
.getOrElse(findLocalInetAddress.getCanonicalHostName)
4748

4849
zks = new ZooKeeperServer(dataDirectory, dataDirectory, tickTime)
4950
zks.setMinSessionTimeout(minSessionTimeout)
5051
zks.setMaxSessionTimeout(maxSessionTimeout)
5152

5253
serverFactory = new NIOServerCnxnFactory
53-
serverFactory.configure(new InetSocketAddress(hostname, clientPort), maxClientCnxns)
54+
serverFactory.configure(new InetSocketAddress(host, clientPort), maxClientCnxns)
5455

5556
super.initialize(conf)
5657
}
@@ -74,7 +75,6 @@ class EmbeddedZookeeper extends AbstractService("EmbeddedZookeeper") {
7475

7576
def getConnectString: String = synchronized {
7677
assert(zks != null, s"$getName is in $getServiceState")
77-
s"${serverFactory.getLocalAddress.getHostName}:${serverFactory.getLocalPort}"
78+
s"${host}:${serverFactory.getLocalPort}"
7879
}
79-
8080
}

kyuubi-zookeeper/src/test/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeperSuite.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.apache.curator.retry.ExponentialBackoffRetry
2424
import org.apache.kyuubi.KyuubiFunSuite
2525
import org.apache.kyuubi.config.KyuubiConf
2626
import org.apache.kyuubi.service.ServiceState._
27+
import org.apache.kyuubi.zookeeper.ZookeeperConf.{ZK_CLIENT_PORT, ZK_CLIENT_PORT_ADDRESS}
2728

2829
class EmbeddedZookeeperSuite extends KyuubiFunSuite {
2930

@@ -62,4 +63,20 @@ class EmbeddedZookeeperSuite extends KyuubiFunSuite {
6263
assert(zkClient.getState === CuratorFrameworkState.STARTED)
6364
assert(zkClient.getZookeeperClient.blockUntilConnectedOrTimedOut())
6465
}
66+
67+
test("use zookeeper.embedded.client.port.address cover default hostname") {
68+
var zkServer = new EmbeddedZookeeper()
69+
// cover default hostname
70+
var conf = KyuubiConf()
71+
.set(ZK_CLIENT_PORT, 0)
72+
.set(ZK_CLIENT_PORT_ADDRESS, "localhost")
73+
zkServer.initialize(conf)
74+
assert(zkServer.getConnectString.contains("localhost"))
75+
zkServer = new EmbeddedZookeeper()
76+
conf = KyuubiConf()
77+
.set(ZK_CLIENT_PORT, 0)
78+
.set(ZK_CLIENT_PORT_ADDRESS, "127.0.0.1")
79+
zkServer.initialize(conf)
80+
assert(zkServer.getConnectString.contains("127.0.0.1"))
81+
}
6582
}

0 commit comments

Comments
 (0)