|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.kyuubi.ctl |
| 18 | + |
| 19 | +import scopt.{OParser, OParserBuilder} |
| 20 | + |
| 21 | +import org.apache.kyuubi.KYUUBI_VERSION |
| 22 | + |
| 23 | +object CommandLine { |
| 24 | + |
| 25 | + def getOptionParser(builder: OParserBuilder[CliConfig]): OParser[Unit, CliConfig] = { |
| 26 | + import builder._ |
| 27 | + OParser.sequence( |
| 28 | + programName("kyuubi-ctl"), |
| 29 | + head("kyuubi", KYUUBI_VERSION), |
| 30 | + common(builder), |
| 31 | + create(builder), |
| 32 | + get(builder), |
| 33 | + delete(builder), |
| 34 | + list(builder), |
| 35 | + checkConfig(f => { |
| 36 | + if (f.action == null) failure("Must specify action command: [create|get|delete|list].") |
| 37 | + else success |
| 38 | + }), |
| 39 | + note(""), |
| 40 | + help('h', "help").text("Show help message and exit.")) |
| 41 | + } |
| 42 | + |
| 43 | + private def common(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 44 | + import builder._ |
| 45 | + OParser.sequence( |
| 46 | + opt[String]("zk-quorum").abbr("zk") |
| 47 | + .action((v, c) => c.copy(commonOpts = c.commonOpts.copy(zkQuorum = v))) |
| 48 | + .text("The connection string for the zookeeper ensemble," + |
| 49 | + " using zk quorum manually."), |
| 50 | + opt[String]('n', "namespace") |
| 51 | + .action((v, c) => c.copy(commonOpts = c.commonOpts.copy(namespace = v))) |
| 52 | + .text("The namespace, using kyuubi-defaults/conf if absent."), |
| 53 | + opt[String]('s', "host") |
| 54 | + .action((v, c) => c.copy(commonOpts = c.commonOpts.copy(host = v))) |
| 55 | + .text("Hostname or IP address of a service."), |
| 56 | + opt[String]('p', "port") |
| 57 | + .action((v, c) => c.copy(commonOpts = c.commonOpts.copy(port = v))) |
| 58 | + .text("Listening port of a service."), |
| 59 | + opt[String]('v', "version") |
| 60 | + .action((v, c) => c.copy(commonOpts = c.commonOpts.copy(version = v))) |
| 61 | + .text("Using the compiled KYUUBI_VERSION default," + |
| 62 | + " change it if the active service is running in another."), |
| 63 | + opt[Unit]('b', "verbose") |
| 64 | + .action((_, c) => c.copy(commonOpts = c.commonOpts.copy(verbose = true))) |
| 65 | + .text("Print additional debug output.")) |
| 66 | + } |
| 67 | + |
| 68 | + private def create(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 69 | + import builder._ |
| 70 | + OParser.sequence( |
| 71 | + note(""), |
| 72 | + cmd("create") |
| 73 | + .action((_, c) => c.copy(action = ServiceControlAction.CREATE)) |
| 74 | + .children( |
| 75 | + serverCmd(builder).text("\tExpose Kyuubi server instance to another domain."))) |
| 76 | + } |
| 77 | + |
| 78 | + private def get(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 79 | + import builder._ |
| 80 | + OParser.sequence( |
| 81 | + note(""), |
| 82 | + cmd("get") |
| 83 | + .text("\tGet the service/engine node info, host and port needed.") |
| 84 | + .action((_, c) => c.copy(action = ServiceControlAction.GET)) |
| 85 | + .children( |
| 86 | + serverCmd(builder).text("\tGet Kyuubi server info of domain"), |
| 87 | + engineCmd(builder).text("\tGet Kyuubi engine info belong to a user."))) |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + private def delete(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 92 | + import builder._ |
| 93 | + OParser.sequence( |
| 94 | + note(""), |
| 95 | + cmd("delete") |
| 96 | + .text("\tDelete the specified service/engine node, host and port needed.") |
| 97 | + .action((_, c) => c.copy(action = ServiceControlAction.DELETE)) |
| 98 | + .children( |
| 99 | + serverCmd(builder).text("\tDelete the specified service node for a domain"), |
| 100 | + engineCmd(builder).text("\tDelete the specified engine node for user."))) |
| 101 | + |
| 102 | + } |
| 103 | + |
| 104 | + private def list(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 105 | + import builder._ |
| 106 | + OParser.sequence( |
| 107 | + note(""), |
| 108 | + cmd("list") |
| 109 | + .text("\tList all the service/engine nodes for a particular domain.") |
| 110 | + .action((_, c) => c.copy(action = ServiceControlAction.LIST)) |
| 111 | + .children( |
| 112 | + serverCmd(builder).text("\tList all the service nodes for a particular domain"), |
| 113 | + engineCmd(builder).text("\tList all the engine nodes for a user"))) |
| 114 | + |
| 115 | + } |
| 116 | + |
| 117 | + private def serverCmd(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 118 | + import builder._ |
| 119 | + cmd("server").action((_, c) => c.copy(service = ServiceControlObject.SERVER)) |
| 120 | + } |
| 121 | + |
| 122 | + private def engineCmd(builder: OParserBuilder[CliConfig]): OParser[_, CliConfig] = { |
| 123 | + import builder._ |
| 124 | + cmd("engine").action((_, c) => c.copy(service = ServiceControlObject.ENGINE)) |
| 125 | + .children( |
| 126 | + opt[String]('u', "user") |
| 127 | + .action((v, c) => c.copy(engineOpts = c.engineOpts.copy(user = v))) |
| 128 | + .text("The user name this engine belong to."), |
| 129 | + opt[String]("engine-type").abbr("et") |
| 130 | + .action((v, c) => c.copy(engineOpts = c.engineOpts.copy(engineType = v))) |
| 131 | + .text("The engine type this engine belong to."), |
| 132 | + opt[String]("engine-subdomain").abbr("es") |
| 133 | + .action((v, c) => c.copy(engineOpts = c.engineOpts.copy(engineSubdomain = v))) |
| 134 | + .text("The engine subdomain this engine belong to."), |
| 135 | + opt[String]("engine-share-level").abbr("esl") |
| 136 | + .action((v, c) => c.copy(engineOpts = c.engineOpts.copy(engineShareLevel = v))) |
| 137 | + .text("The engine share level this engine belong to.")) |
| 138 | + } |
| 139 | + |
| 140 | +} |
0 commit comments