This is an automated email from the ASF dual-hosted git repository.

bowenliang 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 7979aafe5 [KYUUBI #5179] Use Iterable instead of Seq in kyuubi-ctl 
commands
7979aafe5 is described below

commit 7979aafe54282469f8885cfc367817daaea1eded
Author: liangbowen <[email protected]>
AuthorDate: Mon Aug 21 14:35:38 2023 +0800

    [KYUUBI #5179] Use Iterable instead of Seq in kyuubi-ctl commands
    
    ### _Why are the changes needed?_
    
    - Use `Iterable` instead of `Seq` in kyuubi-ctl commands for Scala  
compatibility, as
    1.  in Scala 2.13,  the `scala.Seq` is now an alias for 
`scala.collection.immutable.Seq`  (instead of `scala.collection.Seq`)
    2. in Scala 2.13, `scala.collection.mutable.ListBuffer` (or Buffers) does 
not extend `scala.collection.immutable.Seq` according to [Scala collection 
migration 
guide](https://docs.scala-lang.org/overviews/core/collections-migration-213.html)
    3. in both Scala 2.12 and 2.13, `ListBuffer` (or Buffers) extends 
`scala.collection.mutable.Iterable`
    
    ### _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
    
    - [x] [Run 
test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
 locally before make a pull request
    
    ### _Was this patch authored or co-authored using generative AI tooling?_
    
    Closes #5179 from bowenliang123/ctlcmd-iter.
    
    Closes #5179
    
    3265e3b99 [liangbowen] Use Iterable instead of Seq in kyuubi-ctl commands
    
    Authored-by: liangbowen <[email protected]>
    Signed-off-by: liangbowen <[email protected]>
---
 .../org/apache/kyuubi/ctl/cmd/create/CreateServerCommand.scala |  7 ++++---
 .../scala/org/apache/kyuubi/ctl/cmd/delete/DeleteCommand.scala |  6 +++---
 .../org/apache/kyuubi/ctl/cmd/delete/DeleteEngineCommand.scala |  2 +-
 .../main/scala/org/apache/kyuubi/ctl/cmd/get/GetCommand.scala  |  7 ++++---
 .../scala/org/apache/kyuubi/ctl/cmd/get/GetEngineCommand.scala |  2 +-
 .../scala/org/apache/kyuubi/ctl/cmd/get/GetServerCommand.scala |  2 +-
 .../apache/kyuubi/ctl/cmd/list/AdminListEngineCommand.scala    |  7 ++++---
 .../apache/kyuubi/ctl/cmd/list/AdminListServerCommand.scala    |  6 +++---
 .../scala/org/apache/kyuubi/ctl/cmd/list/ListCommand.scala     |  7 ++++---
 .../org/apache/kyuubi/ctl/cmd/list/ListServerCommand.scala     |  2 +-
 .../org/apache/kyuubi/ctl/cmd/list/ListSessionCommand.scala    |  6 +++---
 .../src/main/scala/org/apache/kyuubi/ctl/util/Render.scala     | 10 +++++-----
 12 files changed, 34 insertions(+), 30 deletions(-)

diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/create/CreateServerCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/create/CreateServerCommand.scala
index f4d4ce2ea..cbff0c15a 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/create/CreateServerCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/create/CreateServerCommand.scala
@@ -25,7 +25,8 @@ import org.apache.kyuubi.ha.HighAvailabilityConf._
 import org.apache.kyuubi.ha.client.{DiscoveryClient, DiscoveryPaths, 
ServiceNodeInfo}
 import org.apache.kyuubi.ha.client.DiscoveryClientProvider.withDiscoveryClient
 
-class CreateServerCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeInfo]](cliConfig) {
+class CreateServerCommand(cliConfig: CliConfig)
+  extends Command[Iterable[ServiceNodeInfo]](cliConfig) {
 
   def validate(): Unit = {
     if (normalizedCliConfig.resource != ControlObject.SERVER) {
@@ -49,7 +50,7 @@ class CreateServerCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeI
   /**
    * Expose Kyuubi server instance to another domain.
    */
-  def doRun(): Seq[ServiceNodeInfo] = {
+  override def doRun(): Iterable[ServiceNodeInfo] = {
     val kyuubiConf = conf
 
     kyuubiConf.setIfMissing(HA_ADDRESSES, normalizedCliConfig.zkOpts.zkQuorum)
@@ -89,7 +90,7 @@ class CreateServerCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeI
     }
   }
 
-  def render(nodes: Seq[ServiceNodeInfo]): Unit = {
+  override def render(nodes: Iterable[ServiceNodeInfo]): Unit = {
     val title = "Created zookeeper service nodes"
     info(Render.renderServiceNodesInfo(title, nodes))
   }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteCommand.scala
index ddbe083ce..113fb935c 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteCommand.scala
@@ -22,7 +22,7 @@ import org.apache.kyuubi.ctl.util.{Render, Validator}
 import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
 abstract class DeleteCommand(cliConfig: CliConfig)
-  extends Command[Seq[ServiceNodeInfo]](cliConfig) {
+  extends Command[Iterable[ServiceNodeInfo]](cliConfig) {
 
   def validate(): Unit = {
     Validator.validateZkArguments(normalizedCliConfig)
@@ -33,9 +33,9 @@ abstract class DeleteCommand(cliConfig: CliConfig)
   /**
    * Delete zookeeper service node with specified host port.
    */
-  def doRun(): Seq[ServiceNodeInfo]
+  override def doRun(): Iterable[ServiceNodeInfo]
 
-  def render(nodes: Seq[ServiceNodeInfo]): Unit = {
+  override def render(nodes: Iterable[ServiceNodeInfo]): Unit = {
     val title = "Deleted zookeeper service nodes"
     info(Render.renderServiceNodesInfo(title, nodes))
   }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteEngineCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteEngineCommand.scala
index ab6e81e24..f3117a7b1 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteEngineCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/delete/DeleteEngineCommand.scala
@@ -34,7 +34,7 @@ class DeleteEngineCommand(cliConfig: CliConfig) extends 
DeleteCommand(cliConfig)
     }
   }
 
-  def doRun(): Seq[ServiceNodeInfo] = {
+  override def doRun(): Iterable[ServiceNodeInfo] = {
     withDiscoveryClient(conf) { discoveryClient =>
       val hostPortOpt =
         Some((cliConfig.zkOpts.host, cliConfig.zkOpts.port.toInt))
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetCommand.scala 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetCommand.scala
index af8285105..5b7ada27d 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetCommand.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetCommand.scala
@@ -21,7 +21,8 @@ import org.apache.kyuubi.ctl.opt.CliConfig
 import org.apache.kyuubi.ctl.util.{Render, Validator}
 import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
-abstract class GetCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeInfo]](cliConfig) {
+abstract class GetCommand(cliConfig: CliConfig)
+  extends Command[Iterable[ServiceNodeInfo]](cliConfig) {
 
   def validate(): Unit = {
     Validator.validateZkArguments(normalizedCliConfig)
@@ -29,9 +30,9 @@ abstract class GetCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeI
     mergeArgsIntoKyuubiConf()
   }
 
-  def doRun(): Seq[ServiceNodeInfo]
+  override def doRun(): Iterable[ServiceNodeInfo]
 
-  def render(nodes: Seq[ServiceNodeInfo]): Unit = {
+  override def render(nodes: Iterable[ServiceNodeInfo]): Unit = {
     val title = "Zookeeper service nodes"
     info(Render.renderServiceNodesInfo(title, nodes))
   }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetEngineCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetEngineCommand.scala
index 13f4d00c8..0d3018372 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetEngineCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetEngineCommand.scala
@@ -31,7 +31,7 @@ class GetEngineCommand(cliConfig: CliConfig) extends 
GetCommand(cliConfig) {
     }
   }
 
-  override def doRun(): Seq[ServiceNodeInfo] = {
+  override def doRun(): Iterable[ServiceNodeInfo] = {
     CtlUtils.listZkEngineNodes(
       conf,
       normalizedCliConfig,
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetServerCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetServerCommand.scala
index faa76b219..744655fd9 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetServerCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/get/GetServerCommand.scala
@@ -21,7 +21,7 @@ import org.apache.kyuubi.ctl.util.CtlUtils
 import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
 class GetServerCommand(cliConfig: CliConfig) extends GetCommand(cliConfig) {
-  override def doRun(): Seq[ServiceNodeInfo] = {
+  override def doRun(): Iterable[ServiceNodeInfo] = {
     CtlUtils.listZkServerNodes(
       conf,
       normalizedCliConfig,
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListEngineCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListEngineCommand.scala
index bc0b16e67..acd6fe444 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListEngineCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListEngineCommand.scala
@@ -26,11 +26,12 @@ import org.apache.kyuubi.ctl.cmd.AdminCtlCommand
 import org.apache.kyuubi.ctl.opt.CliConfig
 import org.apache.kyuubi.ctl.util.Render
 
-class AdminListEngineCommand(cliConfig: CliConfig) extends 
AdminCtlCommand[Seq[Engine]](cliConfig) {
+class AdminListEngineCommand(cliConfig: CliConfig)
+  extends AdminCtlCommand[Iterable[Engine]](cliConfig) {
 
   override def validate(): Unit = {}
 
-  def doRun(): Seq[Engine] = {
+  override def doRun(): Iterable[Engine] = {
     withKyuubiRestClient(normalizedCliConfig, null, conf) { kyuubiRestClient =>
       val adminRestApi = new AdminRestApi(kyuubiRestClient)
       adminRestApi.listEngines(
@@ -41,7 +42,7 @@ class AdminListEngineCommand(cliConfig: CliConfig) extends 
AdminCtlCommand[Seq[E
     }
   }
 
-  def render(resp: Seq[Engine]): Unit = {
+  override def render(resp: Iterable[Engine]): Unit = {
     info(Render.renderEngineNodesInfo(resp))
   }
 }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListServerCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListServerCommand.scala
index a8e7e5d06..27471f6ad 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListServerCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/AdminListServerCommand.scala
@@ -27,18 +27,18 @@ import org.apache.kyuubi.ctl.opt.CliConfig
 import org.apache.kyuubi.ctl.util.Render
 
 class AdminListServerCommand(cliConfig: CliConfig)
-  extends AdminCtlCommand[Seq[ServerData]](cliConfig) {
+  extends AdminCtlCommand[Iterable[ServerData]](cliConfig) {
 
   override def validate(): Unit = {}
 
-  override def doRun(): Seq[ServerData] = {
+  override def doRun(): Iterable[ServerData] = {
     withKyuubiRestClient(normalizedCliConfig, null, conf) { kyuubiRestClient =>
       val adminRestApi = new AdminRestApi(kyuubiRestClient)
       adminRestApi.listServers().asScala
     }
   }
 
-  override def render(resp: Seq[ServerData]): Unit = {
+  override def render(resp: Iterable[ServerData]): Unit = {
     info(Render.renderServerNodesInfo(resp))
   }
 }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListCommand.scala 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListCommand.scala
index e5a3a6882..95399a2c7 100644
--- a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListCommand.scala
+++ b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListCommand.scala
@@ -21,16 +21,17 @@ import org.apache.kyuubi.ctl.opt.CliConfig
 import org.apache.kyuubi.ctl.util.{Render, Validator}
 import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
-abstract class ListCommand(cliConfig: CliConfig) extends 
Command[Seq[ServiceNodeInfo]](cliConfig) {
+abstract class ListCommand(cliConfig: CliConfig)
+  extends Command[Iterable[ServiceNodeInfo]](cliConfig) {
 
   def validate(): Unit = {
     Validator.validateZkArguments(normalizedCliConfig)
     mergeArgsIntoKyuubiConf()
   }
 
-  def doRun(): Seq[ServiceNodeInfo]
+  override def doRun(): Iterable[ServiceNodeInfo]
 
-  def render(nodes: Seq[ServiceNodeInfo]): Unit = {
+  override def render(nodes: Iterable[ServiceNodeInfo]): Unit = {
     val title = "Zookeeper service nodes"
     info(Render.renderServiceNodesInfo(title, nodes))
   }
diff --git 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListServerCommand.scala
 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListServerCommand.scala
index 56e8f4695..e6c8d6ad3 100644
--- 
a/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListServerCommand.scala
+++ 
b/kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/list/ListServerCommand.scala
@@ -21,7 +21,7 @@ import org.apache.kyuubi.ctl.util.CtlUtils
 import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
 class ListServerCommand(cliConfig: CliConfig) extends ListCommand(cliConfig) {
-  override def doRun(): Seq[ServiceNodeInfo] = {
+  override def doRun(): Iterable[ServiceNodeInfo] = {
     CtlUtils.listZkServerNodes(conf, normalizedCliConfig, None)
   }
 }
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
index 7a3668876..9d1dfead4 100644
--- 
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
@@ -26,18 +26,18 @@ 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) {
+class ListSessionCommand(cliConfig: CliConfig) extends 
Command[Iterable[SessionData]](cliConfig) {
 
   override def validate(): Unit = {}
 
-  def doRun(): Seq[SessionData] = {
+  override def doRun(): Iterable[SessionData] = {
     withKyuubiRestClient(normalizedCliConfig, null, conf) { kyuubiRestClient =>
       val sessionRestApi = new SessionRestApi(kyuubiRestClient)
       sessionRestApi.listSessions.asScala
     }
   }
 
-  def render(resp: Seq[SessionData]): Unit = {
+  override def render(resp: Iterable[SessionData]): Unit = {
     info(Render.renderSessionDataListInfo(resp))
   }
 }
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 bb6e3529d..92db46d88 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
@@ -25,15 +25,15 @@ import org.apache.kyuubi.ha.client.ServiceNodeInfo
 
 private[ctl] object Render {
 
-  def renderServiceNodesInfo(title: String, serviceNodeInfo: 
Seq[ServiceNodeInfo]): String = {
+  def renderServiceNodesInfo(title: String, serviceNodeInfo: 
Iterable[ServiceNodeInfo]): String = {
     val header = Array("Namespace", "Host", "Port", "Version")
-    val rows = serviceNodeInfo.sortBy(_.nodeName).map { sn =>
+    val rows = serviceNodeInfo.toSeq.sortBy(_.nodeName).map { sn =>
       Array(sn.namespace, sn.host, sn.port.toString, sn.version.getOrElse(""))
     }.toArray
     Tabulator.format(title, header, rows)
   }
 
-  def renderEngineNodesInfo(engineNodesInfo: Seq[Engine]): String = {
+  def renderEngineNodesInfo(engineNodesInfo: Iterable[Engine]): String = {
     val title = s"Engine Node List (total ${engineNodesInfo.size})"
     val header = Array("Namespace", "Instance", "Attributes")
     val rows = engineNodesInfo.map { engine =>
@@ -45,7 +45,7 @@ private[ctl] object Render {
     Tabulator.format(title, header, rows)
   }
 
-  def renderServerNodesInfo(serverNodesInfo: Seq[ServerData]): String = {
+  def renderServerNodesInfo(serverNodesInfo: Iterable[ServerData]): String = {
     val title = s"Server Node List (total ${serverNodesInfo.size})"
     val header = Array("Namespace", "Instance", "Attributes", "Status")
     val rows = serverNodesInfo.map { server =>
@@ -58,7 +58,7 @@ private[ctl] object Render {
     Tabulator.format(title, header, rows)
   }
 
-  def renderSessionDataListInfo(sessions: Seq[SessionData]): String = {
+  def renderSessionDataListInfo(sessions: Iterable[SessionData]): String = {
     val title = s"Live Session List (total ${sessions.size})"
     val header = Array(
       "Identifier",

Reply via email to