You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2021/12/16 02:11:11 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #1568] Replace sessionDetail with sessionEvent

This is an automated email from the ASF dual-hosted git repository.

yao 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 bcd8c06  [KYUUBI #1568] Replace sessionDetail with sessionEvent
bcd8c06 is described below

commit bcd8c06e7f144175531cf47f9680fe60ec1cf7d7
Author: simon <zh...@cvte.com>
AuthorDate: Thu Dec 16 10:10:56 2021 +0800

    [KYUUBI #1568] Replace sessionDetail with sessionEvent
    
    ### _Why are the changes needed?_
    Replace sessionDetail with sessionEvent, because sessionEvent has more message about session.
    #1568
    
    ### _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 #1569 from simon824/api.
    
    Closes #1568
    
    00a0ddfe [simon] Replace sessionDetail with sessionEvent
    efc84a2e [simon] init
    
    Authored-by: simon <zh...@cvte.com>
    Signed-off-by: Kent Yao <ya...@apache.org>
---
 .../apache/kyuubi/events/KyuubiSessionEvent.scala  |  4 +--
 .../kyuubi/server/api/v1/SessionsResource.scala    | 20 ++++-------
 .../org/apache/kyuubi/server/api/v1/dto.scala      | 10 ------
 .../server/api/v1/SessionsResourceSuite.scala      | 39 ++++++++++++----------
 4 files changed, 29 insertions(+), 44 deletions(-)

diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala
index 60f2286..4ea76e3 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala
@@ -20,7 +20,7 @@ package org.apache.kyuubi.events
 import org.apache.kyuubi.Utils
 import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.server.KyuubiServer
-import org.apache.kyuubi.session.KyuubiSessionImpl
+import org.apache.kyuubi.session.AbstractSession
 
 /**
  * @param sessionId server session id
@@ -55,7 +55,7 @@ case class KyuubiSessionEvent(
 }
 
 object KyuubiSessionEvent {
-  def apply(session: KyuubiSessionImpl): KyuubiSessionEvent = {
+  def apply(session: AbstractSession): KyuubiSessionEvent = {
     assert(KyuubiServer.kyuubiServer != null)
     val serverIP = KyuubiServer.kyuubiServer.frontendServices.head.connectionUrl
     val sessionName: String = session.normalizedConf.getOrElse(KyuubiConf.SESSION_NAME.key, "")
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 c915fa8..24f1f27 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,10 +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.operation.OperationHandle
 import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
 import org.apache.kyuubi.server.api.ApiRequestContext
-import org.apache.kyuubi.session.SessionHandle
+import org.apache.kyuubi.session.{AbstractSession, SessionHandle}
 import org.apache.kyuubi.session.SessionHandle.parseSessionHandle
 
 @Tag(name = "Session")
@@ -57,22 +58,13 @@ private[v1] class SessionsResource extends ApiRequestContext {
     responseCode = "200",
     content = Array(new Content(
       mediaType = MediaType.APPLICATION_JSON)),
-    description = "get a session via session handle identifier")
+    description = "get a session event via session handle identifier")
   @GET
   @Path("{sessionHandle}")
-  def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): SessionDetail = {
+  def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiSessionEvent = {
     try {
-      val sessionHandle = parseSessionHandle(sessionHandleStr)
-      val session = backendService.sessionManager.getSession(sessionHandle)
-      SessionDetail(
-        session.user,
-        session.ipAddress,
-        session.createTime,
-        sessionHandle,
-        session.lastAccessTime,
-        session.lastIdleTime,
-        session.getNoOperationTime,
-        session.conf)
+      KyuubiSessionEvent(backendService.sessionManager.getSession(
+        parseSessionHandle(sessionHandleStr)).asInstanceOf[AbstractSession])
     } catch {
       case NonFatal(e) =>
         error(s"Invalid $sessionHandleStr", e)
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
index 25a107a..87f5566 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
@@ -35,16 +35,6 @@ case class InfoDetail(
     infoType: String,
     infoValue: String)
 
-case class SessionDetail(
-    user: String,
-    ipAddr: String,
-    createTime: Long,
-    sessionHandle: SessionHandle,
-    lastAccessTime: Long,
-    lastIdleTime: Long,
-    noOperationTime: Long,
-    configs: Map[String, String])
-
 case class SessionOpenRequest(
     protocolVersion: Int,
     user: String,
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
index 119843a..39f3fef 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala
@@ -23,8 +23,13 @@ import javax.ws.rs.core.{MediaType, Response}
 
 import scala.concurrent.duration._
 
+import org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2
+
 import org.apache.kyuubi.{KyuubiFunSuite, RestFrontendTestHelper}
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.events.KyuubiSessionEvent
 import org.apache.kyuubi.operation.{OperationHandle, OperationType}
+import org.apache.kyuubi.server.KyuubiServer
 import org.apache.kyuubi.session.SessionHandle
 
 class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
@@ -147,28 +152,26 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
     }
   }
 
-  test("test getSessionDetail") {
-    val requestObj = SessionOpenRequest(
-      1,
-      "admin",
-      "123456",
-      "localhost",
-      Map("testConfig" -> "testValue"))
-
-    withKyuubiRestServer { (_, _, _, webTarget) =>
-      var response: Response = webTarget.path("api/v1/sessions")
-        .request(MediaType.APPLICATION_JSON_TYPE)
-        .post(Entity.entity(requestObj, MediaType.APPLICATION_JSON_TYPE))
-
-      val sessionHandle = response.readEntity(classOf[SessionHandle])
+  test("test get session event") {
+    withKyuubiRestServer { (fe, _, _, webTarget) =>
+      val sessionManager = fe.be.sessionManager
+      val sessionHandle = sessionManager.openSession(
+        HIVE_CLI_SERVICE_PROTOCOL_V2,
+        "admin",
+        "123456",
+        "localhost",
+        Map("testConfig" -> "testValue"))
       val serializedSessionHandle = s"${sessionHandle.identifier.publicId}|" +
         s"${sessionHandle.identifier.secretId}|${sessionHandle.protocol.getValue}"
 
-      // get session detail
-      response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().get()
+      KyuubiServer.kyuubiServer = new KyuubiServer
+      KyuubiServer.kyuubiServer.initialize(KyuubiConf())
+
+      // get session event
+      var response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().get()
       assert(200 == response.getStatus)
-      val sessions = response.readEntity(classOf[SessionDetail])
-      assert(sessions.configs.nonEmpty)
+      val sessions = response.readEntity(classOf[KyuubiSessionEvent])
+      assert(sessions.conf("testConfig").equals("testValue"))
 
       // close a opened session
       response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().delete()