[KYUUBI #1404] Decouple zookeeper persistentNode from other modules

<!--
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.
-->
Decouple zookeeper persistentNode from other modules

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [X] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1405 from hddong/decouple-persistentNode.

Closes #1404

fcdce91d [hongdongdong] [KYUUBI #1404] Decouple zookeeper persistentNode from other modules

Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com>
Signed-off-by: Kent Yao <yao@apache.org>
This commit is contained in:
hongdongdong 2021-11-23 17:10:54 +08:00 committed by Kent Yao
parent 73eeea5f5c
commit e19d463e85
No known key found for this signature in database
GPG Key ID: F7051850A0AF904D
3 changed files with 23 additions and 13 deletions

View File

@ -94,7 +94,7 @@ private[kyuubi] class ServiceControlCli extends Logging {
currentServerNodes.foreach { sn =>
info(s"Exposing server instance:${sn.instance} with version:${sn.version}" +
s" from $fromNamespace to $toNamespace")
val newNode = createServiceNode(
val newNodePath = createAndGetServiceNode(
kyuubiConf,
zc,
args.cliArgs.namespace,
@ -103,7 +103,7 @@ private[kyuubi] class ServiceControlCli extends Logging {
true)
exposedServiceNodes += sn.copy(
namespace = toNamespace,
nodeName = newNode.getActualPath.split("/").last)
nodeName = newNodePath.split("/").last)
}
}

View File

@ -197,8 +197,8 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
System.setProperty(HA_ZK_NAMESPACE.key, uniqueNamespace)
withZkClient(conf) { framework =>
createServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
val newNamespace = getUniqueNamespace()
val args = Array(
@ -260,8 +260,8 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
.set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
withZkClient(conf) { framework =>
createServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
val args = Array(
"list",
@ -289,8 +289,8 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
.set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
withZkClient(conf) { framework =>
createServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
val args = Array(
"get",
@ -322,8 +322,8 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
withZkClient(conf) { framework =>
withZkClient(conf) { zc =>
createServiceNode(conf, zc, uniqueNamespace, "localhost:10000", external = true)
createServiceNode(conf, zc, uniqueNamespace, "localhost:10001", external = true)
createAndGetServiceNode(conf, zc, uniqueNamespace, "localhost:10000", external = true)
createAndGetServiceNode(conf, zc, uniqueNamespace, "localhost:10001", external = true)
}
val args = Array(
@ -355,8 +355,8 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
.set(KyuubiConf.FRONTEND_THRIFT_BINARY_BIND_PORT, 0)
withZkClient(conf) { framework =>
createServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10000")
createAndGetServiceNode(conf, framework, uniqueNamespace, "localhost:10001")
val args = Array(
"list",

View File

@ -225,7 +225,17 @@ object ServiceDiscovery extends Logging {
}
}
def createServiceNode(
def createAndGetServiceNode(
conf: KyuubiConf,
zkClient: CuratorFramework,
namespace: String,
instance: String,
version: Option[String] = None,
external: Boolean = false): String = {
createServiceNode(conf, zkClient, namespace, instance, version, external).getActualPath
}
private def createServiceNode(
conf: KyuubiConf,
zkClient: CuratorFramework,
namespace: String,