Skip to content

Commit bcd8c06

Browse files
simon824yaooqinn
authored andcommitted
[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 00a0ddf [simon] Replace sessionDetail with sessionEvent efc84a2 [simon] init Authored-by: simon <zhangshiming@cvte.com> Signed-off-by: Kent Yao <yao@apache.org>
1 parent 11e208a commit bcd8c06

File tree

4 files changed

+29
-44
lines changed

4 files changed

+29
-44
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/events/KyuubiSessionEvent.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.kyuubi.events
2020
import org.apache.kyuubi.Utils
2121
import org.apache.kyuubi.config.KyuubiConf
2222
import org.apache.kyuubi.server.KyuubiServer
23-
import org.apache.kyuubi.session.KyuubiSessionImpl
23+
import org.apache.kyuubi.session.AbstractSession
2424

2525
/**
2626
* @param sessionId server session id
@@ -55,7 +55,7 @@ case class KyuubiSessionEvent(
5555
}
5656

5757
object KyuubiSessionEvent {
58-
def apply(session: KyuubiSessionImpl): KyuubiSessionEvent = {
58+
def apply(session: AbstractSession): KyuubiSessionEvent = {
5959
assert(KyuubiServer.kyuubiServer != null)
6060
val serverIP = KyuubiServer.kyuubiServer.frontendServices.head.connectionUrl
6161
val sessionName: String = session.normalizedConf.getOrElse(KyuubiConf.SESSION_NAME.key, "")

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/SessionsResource.scala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import io.swagger.v3.oas.annotations.tags.Tag
2929
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TProtocolVersion}
3030

3131
import org.apache.kyuubi.Utils.error
32+
import org.apache.kyuubi.events.KyuubiSessionEvent
3233
import org.apache.kyuubi.operation.OperationHandle
3334
import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
3435
import org.apache.kyuubi.server.api.ApiRequestContext
35-
import org.apache.kyuubi.session.SessionHandle
36+
import org.apache.kyuubi.session.{AbstractSession, SessionHandle}
3637
import org.apache.kyuubi.session.SessionHandle.parseSessionHandle
3738

3839
@Tag(name = "Session")
@@ -57,22 +58,13 @@ private[v1] class SessionsResource extends ApiRequestContext {
5758
responseCode = "200",
5859
content = Array(new Content(
5960
mediaType = MediaType.APPLICATION_JSON)),
60-
description = "get a session via session handle identifier")
61+
description = "get a session event via session handle identifier")
6162
@GET
6263
@Path("{sessionHandle}")
63-
def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): SessionDetail = {
64+
def sessionInfo(@PathParam("sessionHandle") sessionHandleStr: String): KyuubiSessionEvent = {
6465
try {
65-
val sessionHandle = parseSessionHandle(sessionHandleStr)
66-
val session = backendService.sessionManager.getSession(sessionHandle)
67-
SessionDetail(
68-
session.user,
69-
session.ipAddress,
70-
session.createTime,
71-
sessionHandle,
72-
session.lastAccessTime,
73-
session.lastIdleTime,
74-
session.getNoOperationTime,
75-
session.conf)
66+
KyuubiSessionEvent(backendService.sessionManager.getSession(
67+
parseSessionHandle(sessionHandleStr)).asInstanceOf[AbstractSession])
7668
} catch {
7769
case NonFatal(e) =>
7870
error(s"Invalid $sessionHandleStr", e)

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ case class InfoDetail(
3535
infoType: String,
3636
infoValue: String)
3737

38-
case class SessionDetail(
39-
user: String,
40-
ipAddr: String,
41-
createTime: Long,
42-
sessionHandle: SessionHandle,
43-
lastAccessTime: Long,
44-
lastIdleTime: Long,
45-
noOperationTime: Long,
46-
configs: Map[String, String])
47-
4838
case class SessionOpenRequest(
4939
protocolVersion: Int,
5040
user: String,

kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/SessionsResourceSuite.scala

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ import javax.ws.rs.core.{MediaType, Response}
2323

2424
import scala.concurrent.duration._
2525

26+
import org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2
27+
2628
import org.apache.kyuubi.{KyuubiFunSuite, RestFrontendTestHelper}
29+
import org.apache.kyuubi.config.KyuubiConf
30+
import org.apache.kyuubi.events.KyuubiSessionEvent
2731
import org.apache.kyuubi.operation.{OperationHandle, OperationType}
32+
import org.apache.kyuubi.server.KyuubiServer
2833
import org.apache.kyuubi.session.SessionHandle
2934

3035
class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
@@ -147,28 +152,26 @@ class SessionsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
147152
}
148153
}
149154

150-
test("test getSessionDetail") {
151-
val requestObj = SessionOpenRequest(
152-
1,
153-
"admin",
154-
"123456",
155-
"localhost",
156-
Map("testConfig" -> "testValue"))
157-
158-
withKyuubiRestServer { (_, _, _, webTarget) =>
159-
var response: Response = webTarget.path("api/v1/sessions")
160-
.request(MediaType.APPLICATION_JSON_TYPE)
161-
.post(Entity.entity(requestObj, MediaType.APPLICATION_JSON_TYPE))
162-
163-
val sessionHandle = response.readEntity(classOf[SessionHandle])
155+
test("test get session event") {
156+
withKyuubiRestServer { (fe, _, _, webTarget) =>
157+
val sessionManager = fe.be.sessionManager
158+
val sessionHandle = sessionManager.openSession(
159+
HIVE_CLI_SERVICE_PROTOCOL_V2,
160+
"admin",
161+
"123456",
162+
"localhost",
163+
Map("testConfig" -> "testValue"))
164164
val serializedSessionHandle = s"${sessionHandle.identifier.publicId}|" +
165165
s"${sessionHandle.identifier.secretId}|${sessionHandle.protocol.getValue}"
166166

167-
// get session detail
168-
response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().get()
167+
KyuubiServer.kyuubiServer = new KyuubiServer
168+
KyuubiServer.kyuubiServer.initialize(KyuubiConf())
169+
170+
// get session event
171+
var response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().get()
169172
assert(200 == response.getStatus)
170-
val sessions = response.readEntity(classOf[SessionDetail])
171-
assert(sessions.configs.nonEmpty)
173+
val sessions = response.readEntity(classOf[KyuubiSessionEvent])
174+
assert(sessions.conf("testConfig").equals("testValue"))
172175

173176
// close a opened session
174177
response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle").request().delete()

0 commit comments

Comments
 (0)