scala - spark submit-read 命令行参数,它是使用 Scop 和 ConfigFactory 的配置文件 [HOCON]
问题描述
我有一个通过 spark-submit 运行的 jar,之前我使用 Argot 解析通过 ConfigFactory 解析的 HOCON 配置文件,然后我从那里读取。
* spark/bin/spark-submit --class ConsumerApp \
* --master local[2] \
* some-consumer-jar-0.1.0.jar \
* --config config.hocon
不幸的是,Argot 现在是一个死项目,要升级到当前版本的 Scala,我必须开始使用 Scopt ,但我无法理解如何使用 Scopt 解析相同的配置文件并加载到 ConfigFactory 中,而无需进行太多更改。
尝试阅读文档,但找不到太多。
当前实施
def main(args: Array[String]) {
// General bumf for our app
val parser = new ArgotParser(
programName = "generated",
compactUsage = true,
preUsage = Some("%s: Version %s, %s.".format(
generated.Settings.name,
generated.Settings.version,
generated.Settings.organization)
)
)
// Optional config argument
val config = parser.option[Config](List("config"),
"filename",
"Configuration file.") {
(c, opt) =>
val file = new File(c)
if (file.exists) {
ConfigFactory.parseFile(file)
} else {
parser.usage("Configuration file \"%s\" does not exist".format(c))
ConfigFactory.empty()
}
}
parser.parse(args)
// read the config file if --config parameter is provided else fail
val conf = config.value.getOrElse(throw new RuntimeException("--config argument must be provided"))
然后像这样读
arg1 = conf.getConfig("somelevel").getString("arg1"),
解决方案
推荐阅读
- keras - 检查目标时出错:预期 dense_1 有 4 个维度,但得到的数组形状为 (20, 1)
- r - 如何根据 A 中的哪些日期时间在 B 的开始和结束日期时间范围内连接两个表?
- python - 从 jupyter 笔记本运行破折号
- ios - SJFluidSegmentedControlBounce 修改需要独占访问错误
- python - 有没有办法避免嵌套循环
- browser-sync - 使用 browsersync 时无法从移动设备访问 http://192.168.56.1:3000
- spring-batch - 如何在 Spring Batch 中从二进制文件中读取数据
- android - 在 Android 上找不到保存的 CSV 或 TXT 文件
- ruby-on-rails - 如何将 ruby 逻辑插入到 erb 文件中 div 标签的样式属性中?
- typescript - typecirpt 我如何定义 ...props 接口?