Skip to content

Commit 162e72b

Browse files
wangjunboturboFei
authored andcommitted
[KYUUBI #5797][FOLLOWUP] Desc engine command support show engine registered attributes
# 🔍 Description desc engine command support show engine registered attributes. ## Issue References 🔗 This pull request fixes #5797 ## Describe Your Solution 🔧 #5931 (comment) ## Types of changes 🔖 - [ ] Bugfix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 #### Related Unit Tests --- # Checklist 📝 - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #5948 from Kwafoor/kyuubi_5797_desc_engine_follow. Closes #5797 da89099 [wangjunbo] fix code 085ffc5 [wangjunbo] fix code d58e8ec [wangjunbo] delete empty lines cca773a [wangjunbo] fix code 9fcc2c6 [wangjunbo] delete ENGINE_NAMESPACE column 9dfb2f5 [wangjunbo] [KYUUBI #5797][FOLLOWUP] desc engine command support show engine registered attributes Authored-by: wangjunbo <wangjunbo@qiyi.com> Signed-off-by: Fei Wang <fwang12@ebay.com>
1 parent d3a3853 commit 162e72b

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.apache.kyuubi.util.{ThreadUtils, ThriftUtils}
4242
import org.apache.kyuubi.util.ThreadUtils.scheduleTolerableRunnableWithFixedDelay
4343

4444
class KyuubiSyncThriftClient private (
45+
val hostPort: (String, Int),
4546
protocol: TProtocol,
4647
engineAliveProbeProtocol: Option[TProtocol],
4748
engineAliveProbeInterval: Long,
@@ -483,6 +484,7 @@ private[kyuubi] object KyuubiSyncThriftClient extends Logging {
483484
None
484485
}
485486
new KyuubiSyncThriftClient(
487+
(host, port),
486488
tProtocol,
487489
aliveProbeProtocol,
488490
aliveProbeInterval,

kyuubi-server/src/main/scala/org/apache/kyuubi/engine/EngineRef.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import org.apache.kyuubi.engine.jdbc.JdbcProcessBuilder
3838
import org.apache.kyuubi.engine.spark.SparkProcessBuilder
3939
import org.apache.kyuubi.engine.trino.TrinoProcessBuilder
4040
import org.apache.kyuubi.ha.HighAvailabilityConf.{HA_ENGINE_REF_ID, HA_NAMESPACE}
41-
import org.apache.kyuubi.ha.client.{DiscoveryClient, DiscoveryClientProvider, DiscoveryPaths}
41+
import org.apache.kyuubi.ha.client.{DiscoveryClient, DiscoveryClientProvider, DiscoveryPaths, ServiceNodeInfo}
4242
import org.apache.kyuubi.metrics.MetricsConstants.{ENGINE_FAIL, ENGINE_TIMEOUT, ENGINE_TOTAL}
4343
import org.apache.kyuubi.metrics.MetricsSystem
4444
import org.apache.kyuubi.operation.log.OperationLog
@@ -337,6 +337,13 @@ private[kyuubi] class EngineRef(
337337
}
338338
}
339339

340+
def getServiceNode(
341+
discoveryClient: DiscoveryClient,
342+
hostPort: (String, Int)): Option[ServiceNodeInfo] = {
343+
val serviceNodes = discoveryClient.getServiceNodesInfo(engineSpace)
344+
serviceNodes.filter { sn => (sn.host, sn.port) == hostPort }.headOption
345+
}
346+
340347
def close(): Unit = {
341348
if (shareLevel == CONNECTION && builder != null) {
342349
try {

kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.apache.kyuubi.config.KyuubiReservedKeys.{KYUUBI_ENGINE_CREDENTIALS_KE
3030
import org.apache.kyuubi.engine.{EngineRef, KyuubiApplicationManager}
3131
import org.apache.kyuubi.events.{EventBus, KyuubiSessionEvent}
3232
import org.apache.kyuubi.ha.client.DiscoveryClientProvider._
33+
import org.apache.kyuubi.ha.client.ServiceNodeInfo
3334
import org.apache.kyuubi.operation.{Operation, OperationHandle}
3435
import org.apache.kyuubi.operation.log.OperationLog
3536
import org.apache.kyuubi.service.authentication.InternalSecurityAccessor
@@ -119,6 +120,12 @@ class KyuubiSessionImpl(
119120
engineLastAlive = System.currentTimeMillis()
120121
}
121122

123+
def getEngineNode: Option[ServiceNodeInfo] = {
124+
withDiscoveryClient(sessionConf) { discoveryClient =>
125+
engine.getServiceNode(discoveryClient, _client.hostPort)
126+
}
127+
}
128+
122129
private[kyuubi] def openEngineSession(extraEngineLog: Option[OperationLog] = None): Unit =
123130
handleSessionException {
124131
withDiscoveryClient(sessionConf) { discoveryClient =>

kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/command/DescribeEngine.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ import org.apache.kyuubi.sql.schema.{Column, Row, Schema}
3535
case class DescribeEngine() extends RunnableCommand {
3636

3737
override def run(kyuubiSession: KyuubiSession): Unit = {
38-
val rows = Seq(kyuubiSession).map { session =>
39-
lazy val client = session.asInstanceOf[KyuubiSessionImpl].client
38+
val rows = Seq(kyuubiSession.asInstanceOf[KyuubiSessionImpl]).map { session =>
39+
lazy val client = session.client
4040
val values = new ListBuffer[String]()
4141
values += client.engineId.getOrElse("")
4242
values += client.engineName.getOrElse("")
4343
values += client.engineUrl.getOrElse("")
44+
session.getEngineNode match {
45+
case Some(nodeInfo) =>
46+
values += s"${nodeInfo.host}:${nodeInfo.port}"
47+
values += nodeInfo.version.getOrElse("")
48+
values += nodeInfo.attributes.mkString(",")
49+
case None =>
50+
values += ("", "", "")
51+
}
4452
Row(values.toList)
4553
}
4654
iter = new IterableFetchIterator(rows)
@@ -59,6 +67,9 @@ object DescribeEngine {
5967
Seq(
6068
Column("ENGINE_ID", TTypeId.STRING_TYPE, Some("Kyuubi engine identify")),
6169
Column("ENGINE_NAME", TTypeId.STRING_TYPE, Some("Kyuubi engine name")),
62-
Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url")))
70+
Column("ENGINE_URL", TTypeId.STRING_TYPE, Some("Kyuubi engine url")),
71+
Column("ENGINE_INSTANCE", TTypeId.STRING_TYPE, Some("Kyuubi engine instance host and port")),
72+
Column("ENGINE_VERSION", TTypeId.STRING_TYPE, Some("Kyuubi engine version")),
73+
Column("ENGINE_ATTRIBUTES", TTypeId.STRING_TYPE, Some("Kyuubi engine attributes")))
6374
}
6475
}

kyuubi-server/src/test/scala/org/apache/kyuubi/operation/parser/DescribeEngineSuite.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ class DescribeEngineSuite extends ExecutedCommandExecSuite {
2525
val resultSet = statement.executeQuery(s"KYUUBI $desc ENGINE")
2626
assert(resultSet.next())
2727

28-
assert(resultSet.getMetaData.getColumnCount == 3)
28+
assert(resultSet.getMetaData.getColumnCount == 6)
2929
assert(resultSet.getMetaData.getColumnName(1) == "ENGINE_ID")
3030
assert(resultSet.getMetaData.getColumnName(2) == "ENGINE_NAME")
3131
assert(resultSet.getMetaData.getColumnName(3) == "ENGINE_URL")
32+
assert(resultSet.getMetaData.getColumnName(4) == "ENGINE_INSTANCE")
33+
assert(resultSet.getMetaData.getColumnName(5) == "ENGINE_VERSION")
34+
assert(resultSet.getMetaData.getColumnName(6) == "ENGINE_ATTRIBUTES")
3235
}
3336
}
3437
}

0 commit comments

Comments
 (0)