[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 <2213335496@qq.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
This commit is contained in:
parent
2b8304d154
commit
d595eb97a1
@ -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}"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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"))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user