YARN 上的 Spark 和 spark-bigquery 连接器

Spark on YARN and spark-bigquery connector

我开发了一个 Scala Spark 应用程序,用于将数据直接流式传输到 Google BigQuery,使用 Spotify 的 spark-bigquery 连接器。

在本地它工作正常,我已经按照此处所述配置了我的应用程序 https://github.com/spotify/spark-bigquery

val ssc = new StreamingContext(sc, Seconds(120))
val sqlContext = new SQLContext(sc)
sqlContext.setGcpJsonKeyFile("/opt/keyfile.json")
sqlContext.setBigQueryProjectId("projectid")
sqlContext.setBigQueryGcsBucket("gcsbucketname")
sqlContext.setBigQueryDatasetLocation("US")

但是当我在我的 Spark on YARN 集群上提交应用程序时,作业无法查找 GOOGLE_APPLICATION_CREDENTIALS 环境变量...

The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.

我将根用户的 OS env var 变量设置为包含所需凭据的 .json 文件,但它仍然失败。

我也尝试过以下行

System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", "/opt/keyfile.json")

没有成功。

知道我遗漏了什么吗?

谢谢,

莱昂纳多

文档建议: “需要使用 spark.yarn.appMasterEnv.[EnvironmentVariableName] 属性 在 conf/spark-defaults.conf 文件中设置环境变量。 spark-env.sh中设置的环境变量在集群模式下不会反映在YARN Application Master进程中。"