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/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new a6737167c [KYUUBI #3713] kyuubi-ctl list current sessions
a6737167c is described below
commit a6737167cae4d196393a093b8a2fe6e290db3074
Author: Tianlin Liao <[email protected]>
AuthorDate: Sat Oct 29 23:45:36 2022 +0800
[KYUUBI #3713] kyuubi-ctl list current sessions
### _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.apache.org/docs/latest/develop_tools/testing.html#running-tests)
locally before make a pull request
Closes #3721 from lightning-L/kyuubi-3713.
Closes #3713
70959512 [Tianlin Liao] [KYUUBI #3713] kyuubi-ctl list current sessions
Authored-by: Tianlin Liao <[email protected]>
Signed-off-by: Fei Wang <[email protected]>
---
.../kyuubi/ctl/cli/ControlCliArguments.scala | 3 +-
.../kyuubi/ctl/cmd/list/ListSessionCommand.scala | 43 ++++++++++++++++++
.../org/apache/kyuubi/ctl/opt/CliConfig.scala | 2 +-
.../org/apache/kyuubi/ctl/opt/CommandLine.scala | 6 +++
.../scala/org/apache/kyuubi/ctl/util/Render.scala | 25 ++++++++++-
.../kyuubi/ctl/ControlCliArgumentsSuite.scala | 14 ++++--
.../org/apache/kyuubi/client/SessionRestApi.java | 47 ++++++++++++++++++++
.../server/rest/client/SessionCtlSuite.scala | 51 ++++++++++++++++++++++
.../server/rest/client/SessionRestApiSuite.scala | 50 +++++++++++++++++++++
9 files changed, 235 insertions(+), 6 deletions(-)
diff --git
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cli/ControlCliArguments.scala
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cli/ControlCliArguments.scala
index 5c55689f1..41d53b568 100644
---
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cli/ControlCliArguments.scala
+++
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cli/ControlCliArguments.scala
@@ -25,7 +25,7 @@ import org.apache.kyuubi.ctl.cmd._
import org.apache.kyuubi.ctl.cmd.create.{CreateBatchCommand,
CreateServerCommand}
import org.apache.kyuubi.ctl.cmd.delete.{DeleteBatchCommand,
DeleteEngineCommand, DeleteServerCommand}
import org.apache.kyuubi.ctl.cmd.get.{GetBatchCommand, GetEngineCommand,
GetServerCommand}
-import org.apache.kyuubi.ctl.cmd.list.{ListBatchCommand, ListEngineCommand,
ListServerCommand}
+import org.apache.kyuubi.ctl.cmd.list.{ListBatchCommand, ListEngineCommand,
ListServerCommand, ListSessionCommand}
import org.apache.kyuubi.ctl.cmd.log.LogBatchCommand
import org.apache.kyuubi.ctl.cmd.submit.SubmitBatchCommand
import org.apache.kyuubi.ctl.opt.{CliConfig, CommandLine, ControlAction,
ControlObject}
@@ -87,6 +87,7 @@ class ControlCliArguments(args: Seq[String], env: Map[String,
String] = sys.env)
case ControlObject.BATCH => new ListBatchCommand(cliConfig)
case ControlObject.ENGINE => new ListEngineCommand(cliConfig)
case ControlObject.SERVER => new ListServerCommand(cliConfig)
+ case ControlObject.SESSION => new ListSessionCommand(cliConfig)
case _ => throw new KyuubiException(s"Invalid resource:
${cliConfig.resource}")
}
case ControlAction.LOG => cliConfig.resource match {
diff --git
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListSessionCommand.scala
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListSessionCommand.scala
new file mode 100644
index 000000000..7a3668876
--- /dev/null
+++
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListSessionCommand.scala
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.ctl.cmd.list
+
+import scala.collection.JavaConverters._
+
+import org.apache.kyuubi.client.SessionRestApi
+import org.apache.kyuubi.client.api.v1.dto.SessionData
+import org.apache.kyuubi.ctl.RestClientFactory.withKyuubiRestClient
+import org.apache.kyuubi.ctl.cmd.Command
+import org.apache.kyuubi.ctl.opt.CliConfig
+import org.apache.kyuubi.ctl.util.Render
+
+class ListSessionCommand(cliConfig: CliConfig) extends
Command[Seq[SessionData]](cliConfig) {
+
+ override def validate(): Unit = {}
+
+ def doRun(): Seq[SessionData] = {
+ withKyuubiRestClient(normalizedCliConfig, null, conf) { kyuubiRestClient =>
+ val sessionRestApi = new SessionRestApi(kyuubiRestClient)
+ sessionRestApi.listSessions.asScala
+ }
+ }
+
+ def render(resp: Seq[SessionData]): Unit = {
+ info(Render.renderSessionDataListInfo(resp))
+ }
+}
diff --git
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CliConfig.scala
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CliConfig.scala
index 12bd51d6d..38284c595 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CliConfig.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CliConfig.scala
@@ -26,7 +26,7 @@ private[ctl] object ControlAction extends Enumeration {
private[ctl] object ControlObject extends Enumeration {
type ControlObject = Value
- val SERVER, ENGINE, BATCH, CONFIG = Value
+ val SERVER, ENGINE, SESSION, BATCH, CONFIG = Value
}
case class CliConfig(
diff --git
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CommandLine.scala
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CommandLine.scala
index aeab8bcdf..478c439a4 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CommandLine.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/opt/CommandLine.scala
@@ -122,6 +122,7 @@ object CommandLine extends CommonCommandLine {
.action((_, c) => c.copy(action = ControlAction.LIST))
.children(
listBatchCmd(builder).text("\tList batch session info."),
+ sessionCmd(builder).text("\tList all the live sessions"),
serverCmd(builder).text("\tList all the service nodes for a
particular domain"),
engineCmd(builder).text("\tList all the engine nodes for a user")))
@@ -155,6 +156,11 @@ object CommandLine extends CommonCommandLine {
submitBatchCmd(builder).text("\topen batch session and wait for
completion.")))
}
+ private def sessionCmd(builder: OParserBuilder[CliConfig]): OParser[_,
CliConfig] = {
+ import builder._
+ cmd("session").action((_, c) => c.copy(resource = ControlObject.SESSION))
+ }
+
private def serverCmd(builder: OParserBuilder[CliConfig]): OParser[_,
CliConfig] = {
import builder._
cmd("server").action((_, c) => c.copy(resource = ControlObject.SERVER))
diff --git a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala
index b3977b21f..1c4ea83c7 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/util/Render.scala
@@ -19,7 +19,7 @@ package org.apache.kyuubi.ctl.util
import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
-import org.apache.kyuubi.client.api.v1.dto.{Batch, Engine, GetBatchesResponse}
+import org.apache.kyuubi.client.api.v1.dto.{Batch, Engine, GetBatchesResponse,
SessionData}
import org.apache.kyuubi.ctl.util.DateTimeUtils._
import org.apache.kyuubi.ha.client.ServiceNodeInfo
@@ -42,6 +42,29 @@ private[ctl] object Render {
Tabulator.format(title, header, rows)
}
+ def renderSessionDataListInfo(sessions: Seq[SessionData]): String = {
+ val title = s"Live Session List (total ${sessions.size})"
+ val header = Array(
+ "Identifier",
+ "User",
+ "Ip Address",
+ "Conf",
+ "Create Time",
+ "Duration[ms]",
+ "Idle Time[ms]")
+ val rows = sessions.map { session =>
+ Array(
+ session.getIdentifier,
+ session.getUser,
+ session.getIpAddr,
+ session.getConf.toString,
+ millisToDateString(session.getCreateTime, "yyyy-MM-dd HH:mm:ss"),
+ session.getDuration.toString,
+ session.getIdleTime.toString)
+ }.toArray
+ Tabulator.format(title, header, rows)
+ }
+
def renderBatchListInfo(batchListInfo: GetBatchesResponse): String = {
val title = s"Batch List (from ${batchListInfo.getFrom} total
${batchListInfo.getTotal})"
val rows =
batchListInfo.getBatches.asScala.sortBy(_.getCreateTime).map(buildBatchRow).toArray
diff --git
a/kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ControlCliArgumentsSuite.scala
b/kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ControlCliArgumentsSuite.scala
index 215de65f5..ccfeef7cd 100644
---
a/kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ControlCliArgumentsSuite.scala
+++
b/kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ControlCliArgumentsSuite.scala
@@ -20,7 +20,7 @@ package org.apache.kyuubi.ctl
import org.apache.kyuubi.{KYUUBI_VERSION, KyuubiFunSuite}
import org.apache.kyuubi.ctl.RestClientFactory.withKyuubiRestClient
import org.apache.kyuubi.ctl.cli.ControlCliArguments
-import org.apache.kyuubi.ctl.opt.ControlAction
+import org.apache.kyuubi.ctl.opt.{ControlAction, ControlObject}
import org.apache.kyuubi.ha.HighAvailabilityConf.HA_NAMESPACE
class ControlCliArgumentsSuite extends KyuubiFunSuite with TestPrematureExit {
@@ -161,8 +161,14 @@ class ControlCliArgumentsSuite extends KyuubiFunSuite with
TestPrematureExit {
zkQuorum,
"--namespace",
namespace)
- val opArgs = new ControlCliArguments(args2)
+ var opArgs = new ControlCliArguments(args2)
assert(opArgs.cliConfig.action == ControlAction.LIST)
+
+ val args3 = Array(
+ "list",
+ "session")
+ opArgs = new ControlCliArguments(args3)
+ assert(opArgs.cliConfig.resource === ControlObject.SESSION)
}
test("test get/delete action arguments") {
@@ -416,7 +422,7 @@ class ControlCliArgumentsSuite extends KyuubiFunSuite with
TestPrematureExit {
| -esl, --engine-share-level <value>
| The engine share level this engine belong
to.
|
- |Command: list [batch|server|engine]
+ |Command: list [batch|session|server|engine]
|${"\t"}List information about resources.
|Command: list batch [options]
|${"\t"}List batch session info.
@@ -427,6 +433,8 @@ class ControlCliArgumentsSuite extends KyuubiFunSuite with
TestPrematureExit {
| --endTime <value> Batch end time, should be in
yyyyMMddHHmmss format.
| --from <value> Specify which record to start from
retrieving info.
| --size <value> The max number of records returned in the
query.
+ |Command: list session
+ |${"\t"}List all the live sessions
|Command: list server
|${"\t"}List all the service nodes for a particular domain
|Command: list engine [options]
diff --git
a/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/SessionRestApi.java
b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/SessionRestApi.java
new file mode 100644
index 000000000..fbb424102
--- /dev/null
+++
b/kyuubi-rest-client/src/main/java/org/apache/kyuubi/client/SessionRestApi.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.client;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.kyuubi.client.api.v1.dto.SessionData;
+
+public class SessionRestApi {
+
+ private KyuubiRestClient client;
+
+ private static final String API_BASE_PATH = "sessions";
+
+ private SessionRestApi() {}
+
+ public SessionRestApi(KyuubiRestClient client) {
+ this.client = client;
+ }
+
+ public List<SessionData> listSessions() {
+ SessionData[] result =
+ this.getClient()
+ .get(API_BASE_PATH, new HashMap<>(), SessionData[].class,
client.getAuthHeader());
+ return Arrays.asList(result);
+ }
+
+ private IRestClient getClient() {
+ return this.client.getHttpClient();
+ }
+}
diff --git
a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionCtlSuite.scala
b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionCtlSuite.scala
new file mode 100644
index 000000000..5d219de33
--- /dev/null
+++
b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionCtlSuite.scala
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.server.rest.client
+
+import org.apache.hive.service.rpc.thrift.TProtocolVersion
+
+import org.apache.kyuubi.RestClientTestHelper
+import org.apache.kyuubi.ctl.{CtlConf, TestPrematureExit}
+
+class SessionCtlSuite extends RestClientTestHelper with TestPrematureExit {
+ override def beforeAll(): Unit = {
+ super.beforeAll()
+ System.setProperty(CtlConf.CTL_REST_CLIENT_BASE_URL.key, baseUri.toString)
+ System.setProperty(CtlConf.CTL_REST_CLIENT_SPNEGO_HOST.key, "localhost")
+ }
+
+ override def afterAll(): Unit = {
+ System.clearProperty(CtlConf.CTL_REST_CLIENT_BASE_URL.key)
+ System.clearProperty(CtlConf.CTL_REST_CLIENT_SPNEGO_HOST.key)
+ System.clearProperty(CtlConf.CTL_REST_CLIENT_AUTH_SCHEMA.key)
+ super.afterAll()
+ }
+
+ test("list sessions") {
+ fe.be.sessionManager.openSession(
+ TProtocolVersion.findByValue(1),
+ "admin",
+ "123456",
+ "localhost",
+ Map("testConfig" -> "testValue"))
+
+ val args = Array("list", "session", "--authSchema", "spnego")
+ testPrematureExitForControlCli(args, "Session List (total 1)")
+ }
+
+}
diff --git
a/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionRestApiSuite.scala
b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionRestApiSuite.scala
new file mode 100644
index 000000000..1edfb5e53
--- /dev/null
+++
b/kyuubi-server/src/test/scala/org/apache/kyuubi/server/rest/client/SessionRestApiSuite.scala
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.server.rest.client
+
+import scala.collection.JavaConverters.asScalaBufferConverter
+
+import org.apache.hive.service.rpc.thrift.TProtocolVersion
+
+import org.apache.kyuubi.RestClientTestHelper
+import org.apache.kyuubi.client.{KyuubiRestClient, SessionRestApi}
+
+class SessionRestApiSuite extends RestClientTestHelper {
+ test("list session") {
+ fe.be.sessionManager.openSession(
+ TProtocolVersion.findByValue(1),
+ "admin",
+ "123456",
+ "localhost",
+ Map("testConfig" -> "testValue"))
+ val basicKyuubiRestClient: KyuubiRestClient =
+ KyuubiRestClient.builder(baseUri.toString)
+ .authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
+ .username(ldapUser)
+ .password(ldapUserPasswd)
+ .socketTimeout(30000)
+ .build()
+
+ val sessionRestApi = new SessionRestApi(basicKyuubiRestClient)
+ val sessions = sessionRestApi.listSessions().asScala
+ assert(sessions.size == 1)
+ assert(sessions(0).getUser == "admin")
+ assert(sessions(0).getIpAddr == "localhost")
+ assert(sessions(0).getConf.toString == "{testConfig=testValue}")
+ }
+}