使用 Spark 类型安全配置提交应用程序属性文件

Ant*_*uan 1 scala typesafe-config apache-spark

拜托,我需要你的帮助,我正在尝试使用类型安全配置为我的 spark 应用程序提交一个外部配置文件。

我在我的应用程序代码中加载 application.conf 文件,如下所示:

  lazy val conf = ConfigFactory.load()
Run Code Online (Sandbox Code Playgroud)

文件内容

  ingestion{
  process {
    value = "sas"
  }
  sas {
    origin{
      value = "/route"
    }
    destination{
      value = "/route"
    }
    extension{
      value = ".sas7bdat"
    }
    file{
      value = "mytable"
    }
    month{
      value = "201010,201011"
    }
    table{
      value = "tbl"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的火花提交是

spark2-submit --class com.antonio.Main --master yarn --deploy-mode client --driver-memory 10G --driver-cores 8 --executor-memory 13G --executor-cores 4 --num-executors 10 --verbose  --files properties.conf /home/user/ingestion-1.0-SNAPSHOT-jar-with-dependencies.jar --files application.conf
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,我收到

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'ingestion'
Run Code Online (Sandbox Code Playgroud)

一切看起来都配置正确??我是不是错过了什么。

谢谢,

安东尼奥

Vla*_*eev 5

application.conf默认情况下,您必须位于类路径的根目录中ConfigFactory.load()才能找到它。或者,您可以application.conf通过系统属性修改查找文件的位置。因此,您的选择如下。

第一种选择是,将作业的根目录添加到类路径:

spark2-submit ... \
    --conf spark.driver.extraClassPath=./  \
    --conf spark.executor.extraClassPath=./  \    // if you need to load config at executors
    ...
Run Code Online (Sandbox Code Playgroud)

保持该--files选项不变。请注意,如果您在客户端模式下运行您的作业,您必须将正确的路径传递到application.conf位于驱动程序机器上的位置给spark.driver.extraClassPath选项。

第二种选择是(我认为这个更好),您可以使用config.file系统属性来影响ConfigFactory.load()查找配置文件的位置:

spark2-submit ... \
    --conf spark.driver.extraJavaOptions=-Dconfig.file=./application.conf \
    --conf spark.executor.extraJavaOptions=-Dconfig.file=./application.conf \
    ...
Run Code Online (Sandbox Code Playgroud)

关于在执行程序上加载配置和保留--files选项的评论也适用于此。

  • 感谢您的快速回答@vladimir-matveev 我刚刚使用此代码`spark2-submit --class com.demo.Main --master yarn --deploy-mode client --driver-memory 10G --driver-cores 8 --executor-memory 13G --executor-cores 4 --num-executors 10 --verbose --conf "spark.driver.extraJavaOptions=-Dconfig.file=/home/user/application.conf" --conf " spark.executor.extraJavaOptions=-Dconfig.file=/home/user/application.conf" --files "application.conf" /home/user/ingestion-1.0-SNAPSHOT-jar-with-dependencies.jar` (2认同)