You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by fe...@apache.org on 2023/03/09 11:35:02 UTC
[kyuubi] branch master updated: [KYUUBI #4472] add session/operation methods in AdminRestApi
This is an automated email from the ASF dual-hosted git repository.
feiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 4d630c30d [KYUUBI #4472] add session/operation methods in AdminRestApi
4d630c30d is described below
commit 4d630c30dac3c3cfba52c0ed59c01f2714ad5920
Author: Tianlin Liao <ti...@ebay.com>
AuthorDate: Thu Mar 9 19:34:54 2023 +0800
[KYUUBI #4472] add session/operation methods in AdminRestApi
### _Why are the changes needed?_
### _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/master/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #4476 from lightning-L/kyuubi-4472.
Closes #4472
329b40c81 [Tianlin Liao] minor fix
72eaa05de [Tianlin Liao] [KYUUBI #4472] add session/operation methods in AdminRestApi
Authored-by: Tianlin Liao <ti...@ebay.com>
Signed-off-by: fwang12 <fw...@ebay.com>
---
.../org/apache/kyuubi/client/AdminRestApi.java | 27 ++++++++++
.../server/rest/client/AdminRestApiSuite.scala | 62 ++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/AdminRestApi.java b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/AdminRestApi.java
index b8bfe7ee1..c81af593a 100644
--- a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/AdminRestApi.java
+++ b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/AdminRestApi.java
@@ -22,6 +22,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.kyuubi.client.api.v1.dto.Engine;
+import org.apache.kyuubi.client.api.v1.dto.OperationData;
+import org.apache.kyuubi.client.api.v1.dto.SessionData;
public class AdminRestApi {
private KyuubiRestClient client;
@@ -72,6 +74,31 @@ public class AdminRestApi {
return Arrays.asList(result);
}
+ public List<SessionData> listSessions() {
+ SessionData[] result =
+ this.getClient()
+ .get(API_BASE_PATH + "/sessions", null, SessionData[].class, client.getAuthHeader());
+ return Arrays.asList(result);
+ }
+
+ public String closeSession(String sessionHandleStr) {
+ String url = String.format("%s/sessions/%s", API_BASE_PATH, sessionHandleStr);
+ return this.getClient().delete(url, null, client.getAuthHeader());
+ }
+
+ public List<OperationData> listOperations() {
+ OperationData[] result =
+ this.getClient()
+ .get(
+ API_BASE_PATH + "/operations", null, OperationData[].class, client.getAuthHeader());
+ return Arrays.asList(result);
+ }
+
+ public String closeOperation(String operationHandleStr) {
+ String url = String.format("%s/operations/%s", API_BASE_PATH, operationHandleStr);
+ return this.getClient().delete(url, null, client.getAuthHeader());
+ }
+
private IRestClient getClient() {
return this.client.getHttpClient();
}
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/AdminRestApiSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/AdminRestApiSuite.scala
index ab1a10202..5165573ed 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/AdminRestApiSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/AdminRestApiSuite.scala
@@ -21,6 +21,8 @@ import java.util.UUID
import scala.collection.JavaConverters.asScalaBufferConverter
+import org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2
+
import org.apache.kyuubi.{KYUUBI_VERSION, RestClientTestHelper}
import org.apache.kyuubi.client.{AdminRestApi, KyuubiRestClient}
import org.apache.kyuubi.config.{KyuubiConf, KyuubiReservedKeys}
@@ -84,4 +86,64 @@ class AdminRestApiSuite extends RestClientTestHelper {
engines = adminRestApi.listEngines("spark_sql", "user", "default", "").asScala
assert(engines.size == 0)
}
+
+ test("list/close session") {
+ fe.be.sessionManager.openSession(
+ HIVE_CLI_SERVICE_PROTOCOL_V2,
+ "admin",
+ "123456",
+ "localhost",
+ Map("testConfig" -> "testValue"))
+
+ val spnegoKyuubiRestClient: KyuubiRestClient =
+ KyuubiRestClient.builder(baseUri.toString)
+ .authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.SPNEGO)
+ .spnegoHost("localhost")
+ .build()
+ val adminRestApi = new AdminRestApi(spnegoKyuubiRestClient)
+
+ // list sessions
+ var sessions = adminRestApi.listSessions().asScala
+ assert(sessions.nonEmpty)
+ assert(sessions.head.getUser == "admin")
+
+ // close session
+ val response = adminRestApi.closeSession(sessions.head.getIdentifier)
+ assert(response.contains("success"))
+
+ // list again
+ sessions = adminRestApi.listSessions().asScala
+ assert(sessions.isEmpty)
+ }
+
+ test("list/close operation") {
+ val sessionHandle = fe.be.openSession(
+ HIVE_CLI_SERVICE_PROTOCOL_V2,
+ "admin",
+ "123456",
+ "localhost",
+ Map("testConfig" -> "testValue"))
+ val operation = fe.be.getCatalogs(sessionHandle)
+
+ val spnegoKyuubiRestClient: KyuubiRestClient =
+ KyuubiRestClient.builder(baseUri.toString)
+ .authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.SPNEGO)
+ .spnegoHost("localhost")
+ .build()
+ val adminRestApi = new AdminRestApi(spnegoKyuubiRestClient)
+
+ // list operations
+ var operations = adminRestApi.listOperations().asScala
+ assert(operations.nonEmpty)
+ assert(operations.map(op => op.getIdentifier).contains(operation.identifier.toString))
+
+ // close operation
+ val response = adminRestApi.closeOperation(operation.identifier.toString)
+ assert(response.contains("success"))
+
+ // list again
+ operations = adminRestApi.listOperations().asScala
+ assert(!operations.map(op => op.getIdentifier).contains(operation.identifier.toString))
+
+ }
}