[KYUUBI #4618][REST] Admin Resource list operations with sessionHandle filter

### _Why are the changes needed?_

Close #4618
`api/v1/admin/operations` add queryParams sessionHandle

### _How was this patch tested?_
- [x] 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 #4621 from zwangsheng/KYUUBI_4618.

Closes #4618

1f1e40213 [zwangsheng] [KYUUBI #4618][REST] Admin Resource list operations with sessionhandle filter

Authored-by: zwangsheng <2213335496@qq.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
zwangsheng 2023-03-28 09:44:49 +08:00 committed by Cheng Pan
parent 0ea5795d54
commit f3986d2d67
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
2 changed files with 18 additions and 4 deletions

View File

@ -160,7 +160,9 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
"get the list of all active operations")
@GET
@Path("operations")
def listOperations(@QueryParam("users") users: String): Seq[OperationData] = {
def listOperations(
@QueryParam("users") users: String,
@QueryParam("sessionHandle") sessionHandle: String): Seq[OperationData] = {
val userName = fe.getSessionUser(Map.empty[String, String])
val ipAddress = fe.getIpAddress
info(s"Received listing all of the active operations request from $userName/$ipAddress")
@ -173,6 +175,10 @@ private[v1] class AdminResource extends ApiRequestContext with Logging {
val usersSet = users.split(",").toSet
operations = operations.filter(operation => usersSet.contains(operation.getSession.user))
}
if (StringUtils.isNotBlank(sessionHandle)) {
operations = operations.filter(operation =>
operation.getSession.handle.equals(SessionHandle.fromUUID(sessionHandle)))
}
operations
.map(operation => ApiUtils.operationData(operation.asInstanceOf[KyuubiOperation])).toSeq
}

View File

@ -189,7 +189,7 @@ class AdminResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
"localhost",
Map("testConfig" -> "testValue"))
fe.be.openSession(
val sessionHandle = fe.be.openSession(
HIVE_CLI_SERVICE_PROTOCOL_V2,
"test_user_2",
"xxxxxx",
@ -227,8 +227,17 @@ class AdminResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
.request()
.header(AUTHORIZATION_HEADER, s"BASIC $encodeAuthorization")
.get()
val operations = response.readEntity(classOf[Seq[OperationData]])
var operations = response.readEntity(classOf[Seq[OperationData]])
assert(operations.size == 2)
response = webTarget.path("api/v1/admin/operations")
.queryParam("sessionHandle", sessionHandle.identifier)
.request()
.header(AUTHORIZATION_HEADER, s"BASIC $encodeAuthorization")
.get()
operations = response.readEntity(classOf[Seq[OperationData]])
assert(200 == response.getStatus)
assert(operations.size == 1)
}
test("list/close operations") {
@ -479,5 +488,4 @@ class AdminResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper {
}
}
}
}