Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.linkis.common.conf

import org.apache.linkis.common.utils.{ParameterUtils, Logging}

import org.apache.commons.lang3.StringUtils

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

def parse(args: Array[String]): DWCArgumentsParser = {
val keyValueRegex = "([^=]+)=(.+)".r
var i = 0
val optionParser = new DWCArgumentsParser
while (i < args.length - 1) {
args(i) match {
case DWC_CONF | SPRING_CONF =>
args(i + 1) match {
case keyValueRegex(key, value) =>
optionParser.setConf(args(i), key, value)
i += 1
case _ =>
throw new IllegalArgumentException("illegal commond line, format: --conf key=value.")
}
case _ =>
throw new IllegalArgumentException(s"illegal commond line, ${args(i)} cannot recognize.")
ParameterUtils.parseStartupParams(
args,
(prefix, key, value) => {
optionParser.setConf(s"--$prefix-conf", key, value)
}
i += 1
}
)
optionParser.validate()
optionParser
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.common.utils

object ParameterUtils {

private val startupConfRegex =
"""--([a-z]+)-conf\s+(\S+)=([^=]+?)(?=\s*(?:--engineconn-conf|--spring-conf|$))""".r

def parseStartupParams(args: Array[String], handler: (String, String, String) => Unit): Unit = {
val argString = args.mkString(" ")
startupConfRegex.findAllMatchIn(argString).foreach { m =>
val prefix = m.group(1).trim
val key = m.group(2).trim
val value = m.group(3).trim
prefix match {
case "engineconn" | "spring" =>
handler(prefix, key, value)
case _ =>
throw new IllegalArgumentException(s"illegal command line, $prefix cannot recognize.")
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

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

import org.apache.linkis.common.utils.{ParameterUtils, Logging}

import org.apache.commons.lang3.StringUtils

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

override def parseToObj(args: Array[String]): EngineConnArguments = {
var i = 0
val argumentsBuilder = new DefaultEngineConnArgumentsBuilder
while (i < args.length) {
args(i) match {
case ENGINE_CONN_CONF =>
addKeyValue(
args(i + 1),
(key, value) => {
argumentsBuilder.addEngineConnConf(key, value)
i += 1
}
)
case SPRING_CONF =>
addKeyValue(
args(i + 1),
(key, value) => {
argumentsBuilder.addSpringConf(key, value)
i += 1
}
)
case _ =>
throw new IllegalArgumentException(s"illegal command line, ${args(i)} cannot recognize.")
ParameterUtils.parseStartupParams(
args,
(prefix, key, value) => {
argumentsBuilder.addEngineConnConf(key, value)
}
i += 1
}
)
argumentsBuilder.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ trait ProcessEngineConnLaunch extends EngineConnLaunch with Logging {
protected def getCommandArgs: Array[String] = {
if (
request.creationDesc.properties.asScala.exists { case (k, v) =>
k.contains(" ") || (v != null && v.contains(" "))
k.contains(" ")
}
) {
throw new ErrorException(
Expand Down Expand Up @@ -223,6 +223,7 @@ trait ProcessEngineConnLaunch extends EngineConnLaunch with Logging {
engineConnConf += (ENGINE_CONN_CONTAINERIZATION_MAPPING_PORTS.key -> mappingPorts)
engineConnConf += (ENGINE_CONN_CONTAINERIZATION_MAPPING_HOST.key -> mappingHost)

engineConnConf = engineConnConf.map(m => (m._1, s""""${m._2}""""))
arguments.addEngineConnConf(engineConnConf)
EngineConnArgumentsParser.getEngineConnArgumentsParser.parseToArgs(arguments.build())
}
Expand Down
Loading