Skip to content

Commit 57e3733

Browse files
turboFeiulysses-you
authored andcommitted
[KYUUBI #2859][SUB-TASK][KPIP-4] Support --conf for kyuubi-ctl
### _Why are the changes needed?_ To close #2859 ### _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 - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #2875 from turboFei/kyuubi_2859_retry_delete. Closes #2859 7908d82 [Fei Wang] revert commands related 23d357d [Fei Wang] fix ut 7673001 [Fei Wang] print close resp first 76449da [Fei Wang] support --conf Authored-by: Fei Wang <fwang12@ebay.com> Signed-off-by: ulysses-you <ulyssesyou@apache.org>
1 parent eaffb27 commit 57e3733

File tree

7 files changed

+64
-3
lines changed

7 files changed

+64
-3
lines changed

docs/deployment/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ Key | Default | Meaning | Type | Since
189189
--- | --- | --- | --- | ---
190190
kyuubi.ctl.rest.auth.schema|basic|The authentication schema. Valid values are: basic, spnego.|string|1.6.0
191191
kyuubi.ctl.rest.base.url|&lt;undefined&gt;|The REST API base URL, which contains the scheme (http:// or https://), host name, port number|string|1.6.0
192+
kyuubi.ctl.rest.request.attempt.wait|PT3S|How long to wait between attempts of ctl rest request.|duration|1.6.0
193+
kyuubi.ctl.rest.request.max.attempts|3|The max attempts number for ctl rest request.|int|1.6.0
192194
kyuubi.ctl.rest.spnego.host|&lt;undefined&gt;|When auth schema is spnego, need to config spnego host.|string|1.6.0
193195

194196

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ case class CliConfig(
3636
createOpts: CreateOpts = CreateOpts(),
3737
logOpts: LogOpts = LogOpts(),
3838
batchOpts: BatchOpts = BatchOpts(),
39-
engineOpts: EngineOpts = EngineOpts())
39+
engineOpts: EngineOpts = EngineOpts(),
40+
conf: Map[String, String] = Map.empty)
4041

4142
case class CommonOpts(
4243
zkQuorum: String = null,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.apache.kyuubi.ctl
1818

1919
import scopt.{OParser, OParserBuilder}
2020

21-
import org.apache.kyuubi.KYUUBI_VERSION
21+
import org.apache.kyuubi.{KYUUBI_VERSION, KyuubiException}
2222
import org.apache.kyuubi.ctl.util.DateTimeUtils._
2323

2424
object CommandLine {
@@ -83,7 +83,15 @@ object CommandLine {
8383
.text("Password for basic authentication."),
8484
opt[String]("spnegoHost")
8585
.action((v, c) => c.copy(commonOpts = c.commonOpts.copy(spnegoHost = v)))
86-
.text("Spnego host for spnego authentication."))
86+
.text("Spnego host for spnego authentication."),
87+
opt[String]("conf")
88+
.action((v, c) => {
89+
v.split("=", 2).toSeq match {
90+
case Seq(k, v) => c.copy(conf = c.conf ++ Map(k -> v))
91+
case _ => throw new KyuubiException(s"Kyuubi config without '=': $v")
92+
}
93+
})
94+
.text("Kyuubi config property pair, formatted key=value."))
8795
}
8896

8997
private def create(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.kyuubi.ctl
1919

20+
import java.time.Duration
21+
2022
import org.apache.kyuubi.config.{ConfigBuilder, ConfigEntry, KyuubiConf, OptionalConfigEntry}
2123

2224
object CtlConf {
@@ -45,4 +47,17 @@ object CtlConf {
4547
.stringConf
4648
.createOptional
4749

50+
val CTL_REST_CLIENT_REQUEST_MAX_ATTEMPTS =
51+
buildConf("kyuubi.ctl.rest.request.max.attempts")
52+
.doc("The max attempts number for ctl rest request.")
53+
.version("1.6.0")
54+
.intConf
55+
.createWithDefault(3)
56+
57+
val CTL_REST_CLIENT_REQUEST_ATTEMPT_WAIT =
58+
buildConf("kyuubi.ctl.rest.request.attempt.wait")
59+
.doc("How long to wait between attempts of ctl rest request.")
60+
.version("1.6.0")
61+
.timeConf
62+
.createWithDefault(Duration.ofSeconds(3).toMillis)
4863
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ object RestClientFactory {
4949
val authSchema =
5050
getRestConfig("authSchema", conf.get(CTL_REST_CLIENT_AUTH_SCHEMA), cliConfig, map)
5151

52+
val maxAttempts = conf.get(CTL_REST_CLIENT_REQUEST_MAX_ATTEMPTS)
53+
val attemptWaitTime = conf.get(CTL_REST_CLIENT_REQUEST_ATTEMPT_WAIT).toInt
54+
5255
var kyuubiRestClient: KyuubiRestClient = null
5356
authSchema.toLowerCase match {
5457
case "basic" =>
@@ -59,6 +62,8 @@ object RestClientFactory {
5962
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
6063
.username(username)
6164
.password(password)
65+
.maxAttempts(maxAttempts)
66+
.attemptWaitTime(attemptWaitTime)
6267
.build()
6368
case "spnego" =>
6469
val spnegoHost =
@@ -67,6 +72,8 @@ object RestClientFactory {
6772
.apiVersion(KyuubiRestClient.ApiVersion.valueOf(version))
6873
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.SPNEGO)
6974
.spnegoHost(spnegoHost)
75+
.maxAttempts(maxAttempts)
76+
.attemptWaitTime(attemptWaitTime)
7077
.build()
7178
case _ => throw new KyuubiException(s"Unsupported auth schema: $authSchema")
7279
}

kyuubi-ctl/src/main/scala/org/apache/kyuubi/ctl/cmd/Command.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ abstract class Command(cliConfig: CliConfig) extends Logging {
3434

3535
val conf = KyuubiConf().loadFileDefaults()
3636

37+
cliConfig.conf.foreach { case (key, value) =>
38+
conf.set(key, value)
39+
}
40+
3741
val verbose = cliConfig.commonOpts.verbose
3842

3943
val normalizedCliConfig: CliConfig = useDefaultPropertyValueIfMissing()

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ class ControlCliArgumentsSuite extends KyuubiFunSuite with TestPrematureExit {
353353
| --username <value> Username for basic authentication.
354354
| --password <value> Password for basic authentication.
355355
| --spnegoHost <value> Spnego host for spnego authentication.
356+
| --conf <value> Kyuubi config property pair, formatted key=value.
356357
|
357358
|Command: create [batch|server] [options]
358359
|${"\t"}Create a resource.
@@ -439,4 +440,27 @@ class ControlCliArgumentsSuite extends KyuubiFunSuite with TestPrematureExit {
439440

440441
testHelpExit(Array("--help"), helpString)
441442
}
443+
444+
test("test kyuubi conf property") {
445+
val args = Seq(
446+
"delete",
447+
"batch",
448+
"123",
449+
"--conf",
450+
s"${CtlConf.CTL_REST_CLIENT_REQUEST_MAX_ATTEMPTS.key}=10")
451+
val opArgs = new ControlCliArguments(args)
452+
assert(opArgs.cliConfig.action.toString.equalsIgnoreCase("DELETE"))
453+
assert(opArgs.cliConfig.resource.toString.equalsIgnoreCase("BATCH"))
454+
assert(opArgs.cliConfig.batchOpts.batchId === "123")
455+
assert(opArgs.cliConfig.conf ===
456+
Map(CtlConf.CTL_REST_CLIENT_REQUEST_MAX_ATTEMPTS.key -> "10"))
457+
458+
val args2 = Seq(
459+
"delete",
460+
"batch",
461+
"123",
462+
"--conf",
463+
s"${CtlConf.CTL_REST_CLIENT_REQUEST_MAX_ATTEMPTS.key}")
464+
testPrematureExitForControlCliArgs(args2.toArray, "Kyuubi config without '='")
465+
}
442466
}

0 commit comments

Comments
 (0)