From dc26f2128c74fcd9fe678d783f9a5b91e2e19ca9 Mon Sep 17 00:00:00 2001 From: Simon <3656562@qq.com> Date: Tue, 4 Jan 2022 19:40:57 +0800 Subject: [PATCH] [KYUUBI #1568] [FOLLOWUP] Add getSessionEvent in session ### _Why are the changes needed?_ KyuubiSessionEvent.apply will get incorrect info. The first one is from `Session.getSessionEvent`, the second one is `KyuubiSessionEvent.apply` ![image](https://user-images.githubusercontent.com/18065113/147657104-16247260-4b50-4485-843c-f5dbb0116c99.png) ### _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 - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1644 from simon824/1229. Closes #1568 bc5e4b49 [Simon] Merge branch 'apache:master' into 1229 bb316e6a [simon] Add getSessionEvent in session Lead-authored-by: Simon <3656562@qq.com> Co-authored-by: simon Signed-off-by: Kent Yao --- .../org/apache/kyuubi/session/AbstractSession.scala | 3 +++ .../main/scala/org/apache/kyuubi/session/Session.scala | 2 ++ .../apache/kyuubi/server/api/v1/SessionsResource.scala | 10 ++++------ .../org/apache/kyuubi/session/KyuubiSessionImpl.scala | 6 +++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala index 459e4d88f..43b7b49ec 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/AbstractSession.scala @@ -22,6 +22,7 @@ import scala.collection.JavaConverters._ import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion, TRowSet, TTableSchema} import org.apache.kyuubi.{KyuubiSQLException, Logging} +import org.apache.kyuubi.events.KyuubiEvent import org.apache.kyuubi.operation.{Operation, OperationHandle} import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation import org.apache.kyuubi.operation.log.OperationLog @@ -216,4 +217,6 @@ abstract class AbstractSession( override def open(): Unit = { OperationLog.createOperationLogRootDirectory(this) } + + override def getSessionEvent: Option[KyuubiEvent] = None } diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala index e8a8e7305..46afe669d 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala @@ -19,6 +19,7 @@ package org.apache.kyuubi.session import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion, TRowSet, TTableSchema} +import org.apache.kyuubi.events.KyuubiEvent import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation import org.apache.kyuubi.operation.OperationHandle @@ -37,6 +38,7 @@ trait Session { def lastAccessTime: Long def lastIdleTime: Long def getNoOperationTime: Long + def getSessionEvent: Option[KyuubiEvent] def sessionManager: SessionManager diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala index 391151f8c..5d131bda4 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala @@ -29,11 +29,11 @@ import io.swagger.v3.oas.annotations.tags.Tag import org.apache.hive.service.rpc.thrift.{TGetInfoType, TProtocolVersion} import org.apache.kyuubi.Utils.error -import org.apache.kyuubi.events.KyuubiSessionEvent +import org.apache.kyuubi.events.KyuubiEvent import org.apache.kyuubi.operation.OperationHandle import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle import org.apache.kyuubi.server.api.ApiRequestContext -import org.apache.kyuubi.session.{AbstractSession, SessionHandle} +import org.apache.kyuubi.session.SessionHandle import org.apache.kyuubi.session.SessionHandle.parseSessionHandle @Tag(name = "Session") @@ -61,11 +61,9 @@ private[v1] class SessionsResource extends ApiRequestContext { description = "get a session event via session handle identifier") @GET @Path("{sessionHandle}") - def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiSessionEvent = { + def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiEvent = { try { - // TODO: need to use KyuubiSessionEvent in session - KyuubiSessionEvent(fe.be.sessionManager.getSession( - parseSessionHandle(sessionHandleStr)).asInstanceOf[AbstractSession]) + fe.be.sessionManager.getSession(parseSessionHandle(sessionHandleStr)).getSessionEvent.get } catch { case NonFatal(e) => error(s"Invalid $sessionHandleStr", e) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala index 0983dfd69..55b0955e6 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiSessionImpl.scala @@ -25,7 +25,7 @@ import org.apache.kyuubi.client.KyuubiSyncThriftClient import org.apache.kyuubi.config.KyuubiConf import org.apache.kyuubi.config.KyuubiConf._ import org.apache.kyuubi.engine.EngineRef -import org.apache.kyuubi.events.KyuubiSessionEvent +import org.apache.kyuubi.events.{KyuubiEvent, KyuubiSessionEvent} import org.apache.kyuubi.ha.client.ZooKeeperClientProvider._ import org.apache.kyuubi.metrics.MetricsConstants._ import org.apache.kyuubi.metrics.MetricsSystem @@ -58,6 +58,10 @@ class KyuubiSessionImpl( private val sessionEvent = KyuubiSessionEvent(this) EventLoggingService.onEvent(sessionEvent) + override def getSessionEvent: Option[KyuubiEvent] = { + Option(sessionEvent) + } + private var _client: KyuubiSyncThriftClient = _ def client: KyuubiSyncThriftClient = _client