You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by GitBox <gi...@apache.org> on 2021/12/07 08:20:56 UTC

[GitHub] [incubator-kyuubi] simon824 commented on a change in pull request #1517: [KYUUBI #1516] Implement api: /${version}/operations/${operation_identifier}

simon824 commented on a change in pull request #1517:
URL: https://github.com/apache/incubator-kyuubi/pull/1517#discussion_r763738070



##########
File path: kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala
##########
@@ -17,56 +17,85 @@
 
 package org.apache.kyuubi.server.api.v1
 
-import javax.ws.rs.client.Entity
+import javax.ws.rs.client.{Entity, WebTarget}
 import javax.ws.rs.core.{MediaType, Response}
 
 import org.apache.kyuubi.{KyuubiFunSuite, RestFrontendTestHelper}
-import org.apache.kyuubi.operation.{OperationHandle, OperationState, OperationType}
+import org.apache.kyuubi.operation.{OperationHandle, OperationState}
 import org.apache.kyuubi.session.SessionHandle
 
 class OperationsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
 
   test("test get an operation detail by identifier") {
-    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 opHandleStr = getOpHandleStr(webTarget, "catalogs")
+
+      var response = webTarget.path(s"api/v1/operations/$opHandleStr")
+        .request(MediaType.APPLICATION_JSON_TYPE).get()
+      val operationDetail = response.readEntity(classOf[OperationDetail])
+      assert(200 == response.getStatus)
+      assert(operationDetail.operationStatus.state == OperationState.FINISHED)
+
+      // Invalid operationHandleStr
+      val invalidOperationHandle = opHandleStr.replaceAll("GET_CATALOGS", "GET_TYPE_INFO")
+      response = webTarget.path(s"api/v1/operations/$invalidOperationHandle")
+        .request(MediaType.APPLICATION_JSON_TYPE).get()
+      assert(404 == response.getStatus)
 
-      val sessionHandle = response.readEntity(classOf[SessionHandle])
-      val serializedSessionHandle = s"${sessionHandle.identifier.publicId}|" +
-        s"${sessionHandle.identifier.secretId}|${sessionHandle.protocol.getValue}"
+    }
+  }
 
-      response = webTarget.path(s"api/v1/sessions/$serializedSessionHandle/operations/catalogs")
+  test("test apply an action for an operation") {
+    withKyuubiRestServer { (_, _, _, webTarget: WebTarget) =>
+      val opHandleStr = getOpHandleStr(webTarget, "catalogs")
+
+      var response = webTarget.path(s"api/v1/operations/$opHandleStr")
         .request(MediaType.APPLICATION_JSON_TYPE)
-        .post(Entity.entity(null, MediaType.APPLICATION_JSON_TYPE))
+        .put(Entity.entity(OpActionRequest("cancel"), MediaType.APPLICATION_JSON_TYPE))
       assert(200 == response.getStatus)
-      var operationHandle = response.readEntity(classOf[OperationHandle])
-      assert(operationHandle.typ == OperationType.GET_CATALOGS)
-
-      val serializedOperationHandle = s"${operationHandle.identifier.publicId}|" +
-        s"${operationHandle.identifier.secretId}|${operationHandle.protocol.getValue}|" +
-        s"${operationHandle.typ.toString}"
 
-      response = webTarget.path(s"api/v1/operations/$serializedOperationHandle")
+      response = webTarget.path(s"api/v1/operations/$opHandleStr")
         .request(MediaType.APPLICATION_JSON_TYPE).get()
       val operationDetail = response.readEntity(classOf[OperationDetail])
+      assert(operationDetail.operationStatus.state == OperationState.FINISHED ||
+        operationDetail.operationStatus.state == OperationState.CANCELED)
+
+      response = webTarget.path(s"api/v1/operations/$opHandleStr")
+        .request(MediaType.APPLICATION_JSON_TYPE)
+        .put(Entity.entity(OpActionRequest("close"), MediaType.APPLICATION_JSON_TYPE))
       assert(200 == response.getStatus)
-      assert(operationDetail.operationStatus.state == OperationState.FINISHED)
 
-      // Invalid operationHandleStr
-      val invalidOperationHandle = s"${operationHandle.identifier.publicId}|" +
-        s"${operationHandle.identifier.secretId}|${operationHandle.protocol.getValue}|GET_TYPE_INFO"
-      response = webTarget.path(s"api/v1/operations/$invalidOperationHandle")
+      response = webTarget.path(s"api/v1/operations/$opHandleStr")

Review comment:
       Once the operation is closed, the `Object Operation` cannot be obtained, so cannot get `OperationState` too.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org