Skip to content

Commit c521054

Browse files
cxzl25ulysses-you
authored andcommitted
[KYUUBI #2456] Supports managing engines of different share level in kyuubi-ctl
### _Why are the changes needed?_ close #2456 Now only supports the management of engines whose share level is user level. Add engine share level parameter(`--engine-share-level`). ### _How was this patch tested?_ - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [x] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2460 from cxzl25/KYUUBI-2456. Closes #2456 ec60b64 [sychen] support share level Authored-by: sychen <sychen@ctrip.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent 7cede6f commit c521054

File tree

6 files changed

+119
-10
lines changed

6 files changed

+119
-10
lines changed

docs/tools/kyuubi-ctl.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Command: get engine
5656
The engine type this engine belong to.
5757
-es, --engine-subdomain <value>
5858
The engine subdomain this engine belong to.
59+
-esl, --engine-share-level <value>
60+
The engine share level this engine belong to.
5961

6062
Command: delete [server|engine] [options]
6163
Delete the specified service/engine node, host and port needed.
@@ -68,6 +70,8 @@ Command: delete engine
6870
The engine type this engine belong to.
6971
-es, --engine-subdomain <value>
7072
The engine subdomain this engine belong to.
73+
-esl, --engine-share-level <value>
74+
The engine share level this engine belong to.
7175

7276
Command: list [server|engine] [options]
7377
List all the service/engine nodes for a particular domain.
@@ -80,6 +84,8 @@ Command: list engine
8084
The engine type this engine belong to.
8185
-es, --engine-subdomain <value>
8286
The engine subdomain this engine belong to.
87+
-esl, --engine-share-level <value>
88+
The engine share level this engine belong to.
8389

8490
-h, --help Show help message and exit.
8591
```
@@ -116,28 +122,46 @@ bin/kyuubi-ctl delete server --host XXX --port YYY
116122
```
117123
118124
## Manage kyuubi engines
119-
You can also specify the engine type(`--engine-type`), and the engine share level subdomain(`--engine-subdomain`).
125+
You can also specify the engine type(`--engine-type`), engine share level subdomain(`--engine-subdomain`) and engine share level(`--engine-share-level`).
120126
121-
If not specified, the configuration item `kyuubi.engine.type` of `kyuubi-defaults.conf` read, the default value is `SPARK_SQL`, `kyuubi.engine.share.level.subdomain`, the default value is `default`.
127+
If not specified, the configuration item `kyuubi.engine.type` of `kyuubi-defaults.conf` read, the default value is `SPARK_SQL`, `kyuubi.engine.share.level.subdomain`, the default value is `default`, `kyuubi.engine.share.level`, the default value is `USER`.
122128
123129
If the engine pool mode is enabled through `kyuubi.engine.pool.size`, the subdomain consists of `kyuubi.engine.pool.name` and a number below size, e.g. `engine-pool-0` .
124130
131+
`--engine-share-level` supports the following enum values.
132+
* CONNECTION
133+
134+
The engine Ref Id (UUID) must be specified via `--engine-subdomain`.
135+
* USER:
136+
137+
Default Value.
138+
* GROUP:
139+
140+
The `--user` parameter is the group name corresponding to the user.
141+
* SERVER:
142+
143+
The `--user` parameter is the user who started the kyuubi server.
144+
125145
### List engine
126146
List all the engine nodes for a user.
127147
```shell
128-
bin/kyuubi-ctl list egnine --user AAA
148+
bin/kyuubi-ctl list engine --user AAA
149+
```
150+
The management share level is SERVER, the user who starts the kyuubi server is A, the engine is TRINO, and the subdomain is adhoc.
151+
```shell
152+
bin/kyuubi-ctl list engine --user A --engine-type TRINO --engine-subdomain adhoc --engine-share-level SERVER
129153
```
130154
131155
### Get engine
132156
Get Kyuubi engine info belong to a user.
133157
```shell
134-
bin/kyuubi-ctl get egnine --user AAA --host XXX --port YYY
158+
bin/kyuubi-ctl get engine --user AAA --host XXX --port YYY
135159
```
136160
137161
### Delete engine
138162
Delete the specified engine node for user.
139163
140164
After the engine node is deleted, the kyuubi engine stops opening new sessions and waits for all currently open sessions to be closed before the process exits.
141165
```shell
142-
bin/kyuubi-ctl delete egnine --user AAA --host XXX --port YYY
166+
bin/kyuubi-ctl delete engine --user AAA --host XXX --port YYY
143167
```

kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/ServiceControlCli.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ package org.apache.kyuubi.ctl
2020
import scala.collection.mutable.ListBuffer
2121

2222
import org.apache.kyuubi.Logging
23-
import org.apache.kyuubi.config.KyuubiConf.ENGINE_SHARE_LEVEL_SUBDOMAIN
24-
import org.apache.kyuubi.config.KyuubiConf.ENGINE_TYPE
25-
import org.apache.kyuubi.engine.ShareLevel
23+
import org.apache.kyuubi.config.KyuubiConf.{ENGINE_SHARE_LEVEL, ENGINE_SHARE_LEVEL_SUBDOMAIN, ENGINE_TYPE}
2624
import org.apache.kyuubi.ha.HighAvailabilityConf._
2725
import org.apache.kyuubi.ha.client.{DiscoveryClientProvider, ServiceNodeInfo}
2826
import org.apache.kyuubi.ha.client.DiscoveryClient
@@ -232,10 +230,13 @@ object ServiceControlCli extends CommandLineUtils with Logging {
232230
val engineSubdomain = Some(args.cliArgs.engineSubdomain)
233231
.filter(_ != null).filter(_.nonEmpty)
234232
.getOrElse(args.conf.get(ENGINE_SHARE_LEVEL_SUBDOMAIN).getOrElse("default"))
233+
val engineShareLevel = Some(args.cliArgs.engineShareLevel)
234+
.filter(_ != null).filter(_.nonEmpty)
235+
.getOrElse(args.conf.get(ENGINE_SHARE_LEVEL))
235236
// The path of the engine defined in zookeeper comes from
236237
// org.apache.kyuubi.engine.EngineRef#engineSpace
237238
DiscoveryPaths.makePath(
238-
s"${args.cliArgs.namespace}_${args.cliArgs.version}_${ShareLevel.USER}_${engineType}",
239+
s"${args.cliArgs.namespace}_${args.cliArgs.version}_${engineShareLevel}_${engineType}",
239240
args.cliArgs.user,
240241
Array(engineSubdomain))
241242
}

kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/ServiceControlCliArguments.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class ServiceControlCliArguments(args: Seq[String], env: Map[String, String] = s
7777
.action((v, c) => c.copy(engineSubdomain = v))
7878
.text("The engine subdomain this engine belong to.")
7979

80+
val engineShareLevelOps = opt[String]("engine-share-level").abbr("esl")
81+
.action((v, c) => c.copy(engineShareLevel = v))
82+
.text("The engine share level this engine belong to.")
83+
8084
val serverCmd =
8185
cmd("server").action((_, c) => c.copy(service = ServiceControlObject.SERVER))
8286
val engineCmd =
@@ -102,6 +106,7 @@ class ServiceControlCliArguments(args: Seq[String], env: Map[String, String] = s
102106
.children(userOps)
103107
.children(engineTypeOps)
104108
.children(engineSubdomainOps)
109+
.children(engineShareLevelOps)
105110
.text("\tGet Kyuubi engine info belong to a user.")),
106111
note(""),
107112
cmd("delete")
@@ -113,6 +118,7 @@ class ServiceControlCliArguments(args: Seq[String], env: Map[String, String] = s
113118
.children(userOps)
114119
.children(engineTypeOps)
115120
.children(engineSubdomainOps)
121+
.children(engineShareLevelOps)
116122
.text("\tDelete the specified engine node for user.")),
117123
note(""),
118124
cmd("list")
@@ -124,6 +130,7 @@ class ServiceControlCliArguments(args: Seq[String], env: Map[String, String] = s
124130
.children(userOps)
125131
.children(engineTypeOps)
126132
.children(engineSubdomainOps)
133+
.children(engineShareLevelOps)
127134
.text("\tList all the engine nodes for a user")),
128135
checkConfig(f => {
129136
if (f.action == null) failure("Must specify action command: [create|get|delete|list].")

kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/ServiceControlCliArgumentsParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ abstract private[kyuubi] class ServiceControlCliArgumentsParser {
3838
version: String = null,
3939
verbose: Boolean = false,
4040
engineType: String = null,
41-
engineSubdomain: String = null)
41+
engineSubdomain: String = null,
42+
engineShareLevel: String = null)
4243

4344
/**
4445
* Cli arguments parse rules.

kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ServiceControlCliArgumentsSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ class ServiceControlCliArgumentsSuite extends KyuubiFunSuite {
379379
| The engine type this engine belong to.
380380
| -es, --engine-subdomain <value>
381381
| The engine subdomain this engine belong to.
382+
| -esl, --engine-share-level <value>
383+
| The engine share level this engine belong to.
382384
|
383385
|Command: delete [server|engine] [options]
384386
|${"\t"}Delete the specified service/engine node, host and port needed.
@@ -391,6 +393,8 @@ class ServiceControlCliArgumentsSuite extends KyuubiFunSuite {
391393
| The engine type this engine belong to.
392394
| -es, --engine-subdomain <value>
393395
| The engine subdomain this engine belong to.
396+
| -esl, --engine-share-level <value>
397+
| The engine share level this engine belong to.
394398
|
395399
|Command: list [server|engine] [options]
396400
|${"\t"}List all the service/engine nodes for a particular domain.
@@ -403,6 +407,8 @@ class ServiceControlCliArgumentsSuite extends KyuubiFunSuite {
403407
| The engine type this engine belong to.
404408
| -es, --engine-subdomain <value>
405409
| The engine subdomain this engine belong to.
410+
| -esl, --engine-share-level <value>
411+
| The engine share level this engine belong to.
406412
|
407413
| -h, --help Show help message and exit.""".stripMargin
408414

kyuubi-ctl/src/test/scala/org/apache/kyuubi/ctl/ServiceControlCliSuite.scala

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,74 @@ class ServiceControlCliSuite extends KyuubiFunSuite with TestPrematureExit {
479479
assert(getZkNamespace(new ServiceControlCliArguments(arg5)) ==
480480
s"/${namespace}_1.5.0_USER_SPARK_SQL/$user/sub_1")
481481
}
482+
483+
test("test get zk namespace for different share level engines") {
484+
val arg1 = Array(
485+
"list",
486+
"engine",
487+
"--zk-quorum",
488+
zkServer.getConnectString,
489+
"--namespace",
490+
namespace,
491+
"--user",
492+
user)
493+
assert(getZkNamespace(new ServiceControlCliArguments(arg1)) ==
494+
s"/${namespace}_${KYUUBI_VERSION}_USER_SPARK_SQL/$user/default")
495+
496+
val arg2 = Array(
497+
"list",
498+
"engine",
499+
"--zk-quorum",
500+
zkServer.getConnectString,
501+
"--namespace",
502+
namespace,
503+
"--user",
504+
user,
505+
"--engine-share-level",
506+
"CONNECTION")
507+
assert(getZkNamespace(new ServiceControlCliArguments(arg2)) ==
508+
s"/${namespace}_${KYUUBI_VERSION}_CONNECTION_SPARK_SQL/$user/default")
509+
510+
val arg3 = Array(
511+
"list",
512+
"engine",
513+
"--zk-quorum",
514+
zkServer.getConnectString,
515+
"--namespace",
516+
namespace,
517+
"--user",
518+
user,
519+
"--engine-share-level",
520+
"USER")
521+
assert(getZkNamespace(new ServiceControlCliArguments(arg3)) ==
522+
s"/${namespace}_${KYUUBI_VERSION}_USER_SPARK_SQL/$user/default")
523+
524+
val arg4 = Array(
525+
"list",
526+
"engine",
527+
"--zk-quorum",
528+
zkServer.getConnectString,
529+
"--namespace",
530+
namespace,
531+
"--user",
532+
user,
533+
"--engine-share-level",
534+
"GROUP")
535+
assert(getZkNamespace(new ServiceControlCliArguments(arg4)) ==
536+
s"/${namespace}_${KYUUBI_VERSION}_GROUP_SPARK_SQL/$user/default")
537+
538+
val arg5 = Array(
539+
"list",
540+
"engine",
541+
"--zk-quorum",
542+
zkServer.getConnectString,
543+
"--namespace",
544+
namespace,
545+
"--user",
546+
user,
547+
"--engine-share-level",
548+
"SERVER")
549+
assert(getZkNamespace(new ServiceControlCliArguments(arg5)) ==
550+
s"/${namespace}_${KYUUBI_VERSION}_SERVER_SPARK_SQL/$user/default")
551+
}
482552
}

0 commit comments

Comments
 (0)