This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 10582c8 [KYUUBI #1417] Parse instance information in a compatible way
10582c8 is described below
commit 10582c8b96475370d93b7324eecf4d642bc79f99
Author: wForget <[email protected]>
AuthorDate: Fri Nov 19 15:27:49 2021 +0800
[KYUUBI #1417] Parse instance information in a compatible way
<!--
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.
-->
Fix bug #1417.
After fix, run the `bin/kyuubi-ctl list server` command successfully.

### _How was this patch tested?_
- [X] Add some test cases that check the changes thoroughly including
negative and positive cases if possible
- [X] 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 #1418 from wForget/KYUUBI-1417.
Closes #1417
4c662617 [wForget] [KYUUBI-1417] fix checkstyle
44759fea [wForget] [KYUUBI-1417] Parse instance information in a compatible
way
Authored-by: wForget <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
---
.../apache/kyuubi/ha/client/ServiceDiscovery.scala | 22 +++++++++++++++++++---
.../kyuubi/ha/client/ServiceDiscoverySuite.scala | 17 +++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git
a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala
b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala
index 6f7483a..e4f75f5 100644
---
a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala
+++
b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.JavaConverters._
+import com.google.common.annotations.VisibleForTesting
import org.apache.curator.framework.CuratorFramework
import org.apache.curator.framework.recipes.nodes.PersistentNode
import org.apache.curator.framework.state.{ConnectionState,
ConnectionStateListener}
@@ -189,9 +190,7 @@ object ServiceDiscovery extends Logging {
hosts.asScala.takeRight(size).map { p =>
val path = ZKPaths.makePath(namespace, p)
val instance = new String(zkClient.getData.forPath(path),
StandardCharsets.UTF_8)
- val strings = instance.split(":")
- val host = strings.head
- val port = strings(1).toInt
+ val (host, port) = parseInstanceHostPort(instance)
val version =
p.split(";").find(_.startsWith("version=")).map(_.stripPrefix("version="))
val engineRefId =
p.split(";").find(_.startsWith("refId=")).map(_.stripPrefix("refId="))
info(s"Get service instance:$instance and version:$version under
$namespace")
@@ -205,6 +204,23 @@ object ServiceDiscovery extends Logging {
}
}
+ @VisibleForTesting
+ private[client] def parseInstanceHostPort(instance: String): (String, Int) =
{
+ val maybeInfos = instance.split(";")
+ .map(_.split("=", 2))
+ .filter(_.size == 2)
+ .map(i => (i(0), i(1)))
+ .toMap
+ if (maybeInfos.size > 0) {
+ (maybeInfos.get("hive.server2.thrift.bind.host").get,
+ maybeInfos.get("hive.server2.thrift.port").get.toInt)
+ } else {
+ val strings = instance.split(":")
+ (strings(0), strings(1).toInt)
+ }
+ }
+
+
def createServiceNode(
conf: KyuubiConf,
zkClient: CuratorFramework,
diff --git
a/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/ServiceDiscoverySuite.scala
b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/ServiceDiscoverySuite.scala
index 0a63e2f..be84f9e 100644
---
a/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/ServiceDiscoverySuite.scala
+++
b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/ServiceDiscoverySuite.scala
@@ -200,4 +200,21 @@ class ServiceDiscoverySuite extends KerberizedTestHelper {
}
}
}
+
+ test("parse host and port from instance string") {
+ val host = "127.0.0.1"
+ val port = 10009
+ val instance1 = s"$host:$port"
+ val (host1, port1) = ServiceDiscovery.parseInstanceHostPort(instance1)
+ assert(host === host1)
+ assert(port === port1)
+
+ val instance2 =
s"hive.server2.thrift.sasl.qop=auth;hive.server2.thrift.bind.host=$host;" +
+
s"hive.server2.transport.mode=binary;hive.server2.authentication=KERBEROS;" +
+ s"hive.server2.thrift.port=$port;" +
+ s"hive.server2.authentication.kerberos.principal=test/[email protected]"
+ val (host2, port2) = ServiceDiscovery.parseInstanceHostPort(instance2)
+ assert(host === host2)
+ assert(port === port2)
+ }
}