You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/04/08 13:58:43 UTC
[incubator-streampark] branch config created (now 4a90df2c8)
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a change to branch config
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
at 4a90df2c8 [Improve] parse app config improvement
This branch includes the following new commits:
new 4a90df2c8 [Improve] parse app config improvement
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[incubator-streampark] 01/01: [Improve] parse app config improvement
Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch config
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
commit 4a90df2c843d8d036eb160d6d900b9ee7740357a
Author: benjobs <be...@apache.org>
AuthorDate: Sat Apr 8 21:58:24 2023 +0800
[Improve] parse app config improvement
---
.../apache/streampark/common/util/FileUtils.scala | 17 +++++++++
.../flink/client/bean/SubmitRequest.scala | 43 ++++++++++------------
.../flink/core/FlinkStreamingInitializer.scala | 34 ++++++++---------
3 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala b/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
index 9fb9a781a..1676d1bff 100644
--- a/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
+++ b/streampark-common/src/main/scala/org/apache/streampark/common/util/FileUtils.scala
@@ -19,6 +19,7 @@ package org.apache.streampark.common.util
import java.io._
import java.net.URL
import java.util
+import java.util.Scanner
import scala.collection.JavaConversions._
import scala.collection.mutable
@@ -133,4 +134,20 @@ object FileUtils extends org.apache.commons.io.FileUtils {
}
}
+ @throws[IOException] def readString(file: File): String = {
+ require(file != null && file.isFile)
+ val reader = new FileReader(file)
+ val scanner = new Scanner(reader)
+ val buffer = new mutable.StringBuilder()
+ if (scanner.hasNextLine) {
+ buffer.append(scanner.nextLine())
+ }
+ while (scanner.hasNextLine) {
+ buffer.append("\r\n")
+ buffer.append(scanner.nextLine())
+ }
+ Utils.close(scanner, reader)
+ buffer.toString()
+ }
+
}
diff --git a/streampark-flink/streampark-flink-client/streampark-flink-client-api/src/main/scala/org/apache/streampark/flink/client/bean/SubmitRequest.scala b/streampark-flink/streampark-flink-client/streampark-flink-client-api/src/main/scala/org/apache/streampark/flink/client/bean/SubmitRequest.scala
index 3040fe8b1..0740302d3 100644
--- a/streampark-flink/streampark-flink-client/streampark-flink-client-api/src/main/scala/org/apache/streampark/flink/client/bean/SubmitRequest.scala
+++ b/streampark-flink/streampark-flink-client/streampark-flink-client-api/src/main/scala/org/apache/streampark/flink/client/bean/SubmitRequest.scala
@@ -99,39 +99,34 @@ case class SubmitRequest(flinkVersion: FlinkVersion,
}
private[this] def getParameterMap(prefix: String = ""): Map[String, String] = {
- if (this.appConf == null) Map.empty[String, String]
- else {
+ if (this.appConf == null) {
+ return Map.empty[String, String]
+ }
+ val format = this.appConf.substring(0, 7)
+ if (format == "json://") {
+ val json = this.appConf.drop(7)
+ new ObjectMapper().readValue[JavaMap[String, String]](json, classOf[JavaMap[String, String]]).toMap.filter(_._2 != null)
+ } else {
lazy val content = DeflaterUtils.unzipString(this.appConf.trim.drop(7))
- val map = this.appConf match {
- case x if x.trim.startsWith("yaml://") => PropertiesUtils.fromYamlText(content)
- case x if x.trim.startsWith("conf://") => PropertiesUtils.fromHoconText(content)
- case x if x.trim.startsWith("prop://") => PropertiesUtils.fromPropertiesText(content)
- case x if x.trim.startsWith("hdfs://") =>
- /*
- * 如果配置文件为hdfs方式,则需要用户将hdfs相关配置文件copy到resources下...
- */
+ val map = format match {
+ case "yaml://" => PropertiesUtils.fromYamlText(content)
+ case "conf://" => PropertiesUtils.fromHoconText(content)
+ case "prop://" => PropertiesUtils.fromPropertiesText(content)
+ case "hdfs://" =>
+ // 如果配置文件为hdfs方式,则需要用户将hdfs相关配置文件copy到resources下...
val text = HdfsUtils.read(this.appConf)
val extension = this.appConf.split("\\.").last.toLowerCase
extension match {
case "yml" | "yaml" => PropertiesUtils.fromYamlText(text)
case "conf" => PropertiesUtils.fromHoconText(text)
case "properties" => PropertiesUtils.fromPropertiesText(text)
- case _ => throw new IllegalArgumentException("[StreamPark] Usage:flink.conf file error,must be properties or yml")
+ case _ => throw new IllegalArgumentException("[StreamPark] Usage: application config format error,must be [yaml|conf|properties]")
}
- case x if x.trim.startsWith("json://") =>
- val json = x.trim.drop(7)
- new ObjectMapper().readValue[JavaMap[String, String]](json, classOf[JavaMap[String, String]]).toMap.filter(_._2 != null)
- case _ => throw new IllegalArgumentException("[StreamPark] appConf format error.")
- }
- if (this.appConf.trim.startsWith("json://")) map
- else {
- prefix match {
- case "" | null => map
- case other => map
- .filter(_._1.startsWith(other)).filter(_._2.nonEmpty)
- .map(x => x._1.drop(other.length) -> x._2)
- }
+ case _ => throw new IllegalArgumentException("[StreamPark] application config format error.")
}
+ map
+ .filter(_._1.startsWith(prefix)).filter(_._2.nonEmpty)
+ .map(x => x._1.drop(prefix.length) -> x._2)
}
}
diff --git a/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkStreamingInitializer.scala b/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkStreamingInitializer.scala
index 08f7babbc..8369c7ada 100644
--- a/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkStreamingInitializer.scala
+++ b/streampark-flink/streampark-flink-shims/streampark-flink-shims-base/src/main/scala/org/apache/streampark/flink/core/FlinkStreamingInitializer.scala
@@ -98,32 +98,32 @@ private[flink] class FlinkStreamingInitializer(args: Array[String], apiType: Api
}
def parseConfig(config: String): Map[String, String] = {
- val extension = config.split("\\.").last.toLowerCase
+
lazy val content = DeflaterUtils.unzipString(config.drop(7))
+
+ def readConfig(text: String): Map[String, String] = {
+ val format = config.split("\\.").last.toLowerCase
+ format match {
+ case "yml" | "yaml" => PropertiesUtils.fromYamlText(text)
+ case "conf" => PropertiesUtils.fromHoconText(text)
+ case "properties" => PropertiesUtils.fromPropertiesText(text)
+ case _ => throw new IllegalArgumentException("[StreamPark] Usage: application config file error,must be [yaml|conf|properties]")
+ }
+ }
+
val map = config match {
case x if x.startsWith("yaml://") => PropertiesUtils.fromYamlText(content)
case x if x.startsWith("conf://") => PropertiesUtils.fromHoconText(content)
case x if x.startsWith("prop://") => PropertiesUtils.fromPropertiesText(content)
case x if x.startsWith("hdfs://") =>
- /**
- * If the configuration file with the hdfs, user will need to copy the hdfs-related configuration files under the resources dir
- */
+ // If the configuration file with the hdfs, user will need to copy the hdfs-related configuration files under the resources dir
val text = HdfsUtils.read(x)
- extension match {
- case "yml" | "yaml" => PropertiesUtils.fromYamlText(text)
- case "conf" => PropertiesUtils.fromHoconText(text)
- case "properties" => PropertiesUtils.fromPropertiesText(text)
- case _ => throw new IllegalArgumentException("[StreamPark] Usage:flink.conf file error,must be properties or yml")
- }
+ readConfig(text)
case _ =>
val configFile = new File(config)
- require(configFile.exists(), s"[StreamPark] Usage: flink.conf file $configFile is not found!!!")
- extension match {
- case "yml" | "yaml" => PropertiesUtils.fromYamlFile(configFile.getAbsolutePath)
- case "conf" => PropertiesUtils.fromHoconFile(configFile.getAbsolutePath)
- case "properties" => PropertiesUtils.fromPropertiesFile(configFile.getAbsolutePath)
- case _ => throw new IllegalArgumentException("[StreamPark] Usage:flink.conf file error,must be (yml|conf|properties)")
- }
+ require(configFile.exists(), s"[StreamPark] Usage: application config file: $configFile is not found!!!")
+ val text = FileUtils.readString(configFile)
+ readConfig(text)
}
map.filter(_._2.nonEmpty)
}