Skip to content

Commit 7215d4e

Browse files
authored
When submitting, parameter values containing spaces are supported (#5272)
1 parent 1996116 commit 7215d4e

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/conf/DWCArgumentsParser.scala

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

1818
package org.apache.linkis.common.conf
1919

20+
import org.apache.linkis.common.utils.{ParameterUtils, Logging}
21+
2022
import org.apache.commons.lang3.StringUtils
2123

2224
import scala.collection.JavaConverters.mapAsJavaMapConverter
@@ -34,24 +36,13 @@ object DWCArgumentsParser {
3436
def getDWCOptionMap: Map[String, String] = dwcOptionMap
3537

3638
def parse(args: Array[String]): DWCArgumentsParser = {
37-
val keyValueRegex = "([^=]+)=(.+)".r
38-
var i = 0
3939
val optionParser = new DWCArgumentsParser
40-
while (i < args.length - 1) {
41-
args(i) match {
42-
case DWC_CONF | SPRING_CONF =>
43-
args(i + 1) match {
44-
case keyValueRegex(key, value) =>
45-
optionParser.setConf(args(i), key, value)
46-
i += 1
47-
case _ =>
48-
throw new IllegalArgumentException("illegal commond line, format: --conf key=value.")
49-
}
50-
case _ =>
51-
throw new IllegalArgumentException(s"illegal commond line, ${args(i)} cannot recognize.")
40+
ParameterUtils.parseStartupParams(
41+
args,
42+
(prefix, key, value) => {
43+
optionParser.setConf(s"--$prefix-conf", key, value)
5244
}
53-
i += 1
54-
}
45+
)
5546
optionParser.validate()
5647
optionParser
5748
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
18+
package org.apache.linkis.common.utils
19+
20+
object ParameterUtils {
21+
22+
private val startupConfRegex =
23+
"""--([a-z]+)-conf\s+(\S+)=([^=]+?)(?=\s*(?:--engineconn-conf|--spring-conf|$))""".r
24+
25+
def parseStartupParams(args: Array[String], handler: (String, String, String) => Unit): Unit = {
26+
val argString = args.mkString(" ")
27+
startupConfRegex.findAllMatchIn(argString).foreach { m =>
28+
val prefix = m.group(1).trim
29+
val key = m.group(2).trim
30+
val value = m.group(3).trim
31+
prefix match {
32+
case "engineconn" | "spring" =>
33+
handler(prefix, key, value)
34+
case _ =>
35+
throw new IllegalArgumentException(s"illegal command line, $prefix cannot recognize.")
36+
}
37+
}
38+
}
39+
40+
}

linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/utils/EngineConnArguments.scala

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

1818
package org.apache.linkis.governance.common.utils
1919

20+
import org.apache.linkis.common.utils.{ParameterUtils, Logging}
21+
2022
import org.apache.commons.lang3.StringUtils
2123

2224
import scala.collection.mutable
@@ -105,31 +107,13 @@ class DefaultEngineConnArgumentsParser extends EngineConnArgumentsParser {
105107
protected val keyValueRegex = "([^=]+)=(.+)".r
106108

107109
override def parseToObj(args: Array[String]): EngineConnArguments = {
108-
var i = 0
109110
val argumentsBuilder = new DefaultEngineConnArgumentsBuilder
110-
while (i < args.length) {
111-
args(i) match {
112-
case ENGINE_CONN_CONF =>
113-
addKeyValue(
114-
args(i + 1),
115-
(key, value) => {
116-
argumentsBuilder.addEngineConnConf(key, value)
117-
i += 1
118-
}
119-
)
120-
case SPRING_CONF =>
121-
addKeyValue(
122-
args(i + 1),
123-
(key, value) => {
124-
argumentsBuilder.addSpringConf(key, value)
125-
i += 1
126-
}
127-
)
128-
case _ =>
129-
throw new IllegalArgumentException(s"illegal command line, ${args(i)} cannot recognize.")
111+
ParameterUtils.parseStartupParams(
112+
args,
113+
(prefix, key, value) => {
114+
argumentsBuilder.addEngineConnConf(key, value)
130115
}
131-
i += 1
132-
}
116+
)
133117
argumentsBuilder.build()
134118
}
135119

linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-core/src/main/scala/org/apache/linkis/ecm/core/launch/ProcessEngineConnLaunch.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ trait ProcessEngineConnLaunch extends EngineConnLaunch with Logging {
170170
protected def getCommandArgs: Array[String] = {
171171
if (
172172
request.creationDesc.properties.asScala.exists { case (k, v) =>
173-
k.contains(" ") || (v != null && v.contains(" "))
173+
k.contains(" ")
174174
}
175175
) {
176176
throw new ErrorException(
@@ -223,6 +223,7 @@ trait ProcessEngineConnLaunch extends EngineConnLaunch with Logging {
223223
engineConnConf += (ENGINE_CONN_CONTAINERIZATION_MAPPING_PORTS.key -> mappingPorts)
224224
engineConnConf += (ENGINE_CONN_CONTAINERIZATION_MAPPING_HOST.key -> mappingHost)
225225

226+
engineConnConf = engineConnConf.map(m => (m._1, s""""${m._2}""""))
226227
arguments.addEngineConnConf(engineConnConf)
227228
EngineConnArgumentsParser.getEngineConnArgumentsParser.parseToArgs(arguments.build())
228229
}

0 commit comments

Comments
 (0)