[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 <zhangshiming@cvte.com> Signed-off-by: Kent Yao <yao@apache.org>
This commit is contained in:
parent
11e208a688
commit
bcd8c06e7f
@ -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, "")
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user