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 9da8e46 [KYUUBI #1092] Implement api: /sessions/${sessionhandle}
(DELETE)
9da8e46 is described below
commit 9da8e4642b5e39c91f0abb3350211c0164330fa5
Author: yanghua <[email protected]>
AuthorDate: Mon Sep 13 18:16:50 2021 +0800
[KYUUBI #1092] Implement api: /sessions/${sessionhandle} (DELETE)
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in
https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your
PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
### _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 #1093 from yanghua/KYUUBI-1092.
Closes #1092
f4e863a8 [yanghua] [KYUUBI #1092] Implement api: /sessions/${sessionhandle}
(DELETE)
Authored-by: yanghua <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
---
.../kyuubi/server/api/v1/SessionsResource.scala | 19 ++++++++++--
.../server/api/v1/SessionsResourceSuite.scala | 35 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 2 deletions(-)
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 3c5ca9d..2b7830e 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
@@ -19,11 +19,14 @@ package org.apache.kyuubi.server.api.v1
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
-import javax.ws.rs.{Consumes, GET, Path, POST, Produces}
-import javax.ws.rs.core.MediaType
+import java.util.UUID
+import javax.ws.rs.{Consumes, DELETE, GET, Path, PathParam, POST, Produces}
+import javax.ws.rs.core.{MediaType, Response}
import org.apache.hive.service.rpc.thrift.TProtocolVersion
+import org.apache.kyuubi.cli.HandleIdentifier
import org.apache.kyuubi.server.api.ApiRequestContext
+import org.apache.kyuubi.session.SessionHandle
@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class SessionsResource extends ApiRequestContext {
@@ -48,4 +51,16 @@ private[v1] class SessionsResource extends ApiRequestContext
{
request.configs)
mapper.writeValueAsString(sessionHandle)
}
+
+ @DELETE
+ @Path("{sessionHandle}")
+ def closeSession(@PathParam("sessionHandle") sessionHandleStr: String):
Response = {
+ val splitSessionHandle = sessionHandleStr.split("\\|")
+ val handleIdentifier = new HandleIdentifier(
+ UUID.fromString(splitSessionHandle(0)),
UUID.fromString(splitSessionHandle(1)))
+ val protocolVersion =
TProtocolVersion.findByValue(splitSessionHandle(2).toInt)
+ val sessionHandle = new SessionHandle(handleIdentifier, protocolVersion)
+ backendService.closeSession(sessionHandle)
+ Response.ok().build()
+ }
}
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 924a0c7..96935e6 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
@@ -68,4 +68,39 @@ class SessionsResourceSuite extends JerseyTest {
}
}
+ @Test
+ def testCloseAndCountSession: Unit = {
+ val requestObj = SessionOpenRequest(
+ 1, "admin", "123456", "localhost", Map("testConfig" -> "testValue"))
+
+ val requestObjStr = OBJECT_MAPPER.writeValueAsString(requestObj)
+
+ RestFrontendServiceSuite.withKyuubiRestServer {
+ (_, _, _) =>
+ var response = target(s"api/v1/sessions")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .post(Entity.entity(requestObjStr, MediaType.APPLICATION_JSON_TYPE))
+
+ assert(200 == response.getStatus)
+
+ val sessionHandle = OBJECT_MAPPER.readValue(
+ response.readEntity(classOf[String]), classOf[SessionHandle])
+
+ assert(sessionHandle.protocol.getValue == 1)
+ assert(sessionHandle.identifier != null)
+
+ // close a opened session
+ val serializedSessionHandle = s"${sessionHandle.identifier.publicId}|"
+
+
s"${sessionHandle.identifier.secretId}|${sessionHandle.protocol.getValue}"
+ response =
target(s"api/v1/sessions/$serializedSessionHandle").request().delete()
+ assert(200 == response.getStatus)
+
+ // verify the open session count again
+ response = target("api/v1/sessions/count").request().get()
+ val openedSessionCount = OBJECT_MAPPER.readValue(
+ response.readEntity(classOf[String]), classOf[SessionOpenCount])
+ assert(openedSessionCount.openSessionCount == 0)
+ }
+ }
+
}