You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ya...@apache.org on 2021/12/24 09:02:14 UTC
[incubator-kyuubi] branch master updated: [KYUUBI #1620] Implement api: /${version}/operations/${operation_identifier}/log
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 c42f31e [KYUUBI #1620] Implement api: /${version}/operations/${operation_identifier}/log
c42f31e is described below
commit c42f31e211601aea025fe40ef8e3f0227c52c9f2
Author: simon <zh...@cvte.com>
AuthorDate: Fri Dec 24 17:02:05 2021 +0800
[KYUUBI #1620] Implement api: /${version}/operations/${operation_identifier}/log
### _Why are the changes needed?_
closes #1620
Implement api: /${version}/operations/${operation_identifier}/log
### _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 #1621 from simon824/1223.
Closes #1620
5f211473 [simon] rm
f6d0ce7c [simon] fix
346df798 [simon] operationLog
c60d3447 [simon] init
Authored-by: simon <zh...@cvte.com>
Signed-off-by: Kent Yao <ya...@apache.org>
---
.../kyuubi/operation/NoopOperationManager.scala | 15 +++++++++---
.../kyuubi/server/api/v1/OperationsResource.scala | 27 +++++++++++++++++++++-
.../org/apache/kyuubi/server/api/v1/dto.scala | 2 ++
.../server/api/v1/OperationsResourceSuite.scala | 14 +++++++++++
4 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/NoopOperationManager.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/NoopOperationManager.scala
index 961ecf7..0104403 100644
--- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/NoopOperationManager.scala
+++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/NoopOperationManager.scala
@@ -17,11 +17,13 @@
package org.apache.kyuubi.operation
-import org.apache.hive.service.rpc.thrift.TRowSet
+import java.nio.ByteBuffer
+import java.util
+
+import org.apache.hive.service.rpc.thrift.{TColumn, TRow, TRowSet, TStringColumn}
import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation
import org.apache.kyuubi.session.Session
-import org.apache.kyuubi.util.ThriftUtils
class NoopOperationManager extends OperationManager("noop") {
private val invalid = "invalid"
@@ -91,5 +93,12 @@ class NoopOperationManager extends OperationManager("noop") {
override def getOperationLogRowSet(
opHandle: OperationHandle,
order: FetchOrientation,
- maxRows: Int): TRowSet = ThriftUtils.EMPTY_ROW_SET
+ maxRows: Int): TRowSet = {
+ val logs = new util.ArrayList[String]()
+ logs.add("test")
+ val tColumn = TColumn.stringVal(new TStringColumn(logs, ByteBuffer.allocate(0)))
+ val tRow = new TRowSet(0, new util.ArrayList[TRow](logs.size()))
+ tRow.addToColumns(tColumn)
+ tRow
+ }
}
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala
index f3a5c4c..66c2943 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala
@@ -30,7 +30,7 @@ import org.apache.hive.service.rpc.thrift.TTypeQualifierValue
import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.events.KyuubiOperationEvent
-import org.apache.kyuubi.operation.KyuubiOperation
+import org.apache.kyuubi.operation.{FetchOrientation, KyuubiOperation}
import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
import org.apache.kyuubi.server.api.ApiRequestContext
@@ -121,4 +121,29 @@ private[v1] class OperationsResource extends ApiRequestContext {
s"Error getting result set metadata for operation handle $operationHandleStr")
}
}
+
+ @ApiResponse(
+ responseCode = "200",
+ content = Array(new Content(
+ mediaType = MediaType.APPLICATION_JSON)),
+ description =
+ "get operation log")
+ @GET
+ @Path("{operationHandle}/log")
+ def getOperationLog(
+ @PathParam("operationHandle") operationHandleStr: String,
+ @QueryParam("maxrows") maxRows: Int): OperationLog = {
+ try {
+ val rowSet = backendService.sessionManager.operationManager.getOperationLogRowSet(
+ parseOperationHandle(operationHandleStr),
+ FetchOrientation.FETCH_NEXT,
+ maxRows)
+ val logRowSet = rowSet.getColumns.get(0).getStringVal.getValues.asScala
+ OperationLog(logRowSet, logRowSet.size)
+ } catch {
+ case NonFatal(_) =>
+ throw new NotFoundException(
+ s"Error getting operation log for operation handle $operationHandleStr")
+ }
+ }
}
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
index 5917906..ae3bf90 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala
@@ -79,3 +79,5 @@ case class ColumnDesc(
precision: Int,
scale: Int,
comment: String)
+
+case class OperationLog(logRowSet: Seq[String], rowCount: Int)
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala
index b0bca33..7dbaf9a 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala
@@ -92,6 +92,20 @@ class OperationsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper
}
}
+ test("test get operation log") {
+ withKyuubiRestServer { (fe, _, _, webTarget: WebTarget) =>
+ val opHandleStr = getOpHandleStr(fe, OperationType.EXECUTE_STATEMENT)
+ val response = webTarget.path(
+ s"api/v1/operations/$opHandleStr/log")
+ .queryParam("maxrows", "10")
+ .request(MediaType.APPLICATION_JSON).get()
+ assert(200 == response.getStatus)
+ val logRowSet = response.readEntity(classOf[OperationLog])
+ assert(logRowSet.logRowSet.head.equals("test"))
+ assert(logRowSet.rowCount == 1)
+ }
+ }
+
def getOpHandleStr(fe: KyuubiRestFrontendService, typ: OperationType): String = {
val sessionManager = fe.be.sessionManager
val sessionHandle = sessionManager.openSession(