spark提交传递文件

bnlyeluc  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(381)

我想在spark提交中传递两个文件:
密钥.jks
信任.jks
位置如下:
/home/my\u user/config/key.jks
/home/my\u user/config/trustore.jks
我执行以下命令:

spark-submit --name historization \
--class com.ConsumerLauncher \
--master yarn \
--deploy-mode cluster \
--files /home/my_user/config/key.jks,/home/my_user/config/trustore.jks \
/home/my_user/jars/app.jar

我想在我的代码中为我的Kafka参数处理两个文件:

val kafkaParams = Map[String, Object](
  "bootstrap.servers" -> "myhost",
  "group.id" -> "grp-test",
  "key.deserializer" -> classOf[StringDeserializer],
  "value.deserializer" -> classOf[StringDeserializer],
  "auto.offset.reset" -> "earliest",
  "enable.auto.commit" -> (false: java.lang.Boolean),
  "security.protocol" -> "SSL",
  "ssl.truststore.password" -> "xxxx",
  "ssl.key.password" -> "xxxx",
  "ssl.keystore.password" -> "xxxx",
  //this two lines
  "ssl.truststore.location" -> "/home/my_user/config/trustore.jks",
  "ssl.keystore.location" -> "/home/my_user/config/key.jks"
  //this two line also bug
  //"ssl.truststore.location" -> getClass.getResource("/ssl/trustore.jks").getPath,
  //"ssl.keystore.location" -> getClass.getResource("/ssl/key.jks").getPath
)

不幸的是,我得到了这个错误

Caused by: java.io.FileNotFoundException: /home/my_user/config/key.jks (No such file or directory)

你知道吗?

vptzau2j

vptzau2j1#

使用--files时,文件将上载到hdfs。您现在可以这样访问:trustore.jks和key.jks

val kafkaParams = Map[String, Object](
  "bootstrap.servers" -> "myhost",
  "group.id" -> "grp-test",
  "key.deserializer" -> classOf[StringDeserializer],
  "value.deserializer" -> classOf[StringDeserializer],
  "auto.offset.reset" -> "earliest",
  "enable.auto.commit" -> (false: java.lang.Boolean),
  "security.protocol" -> "SSL",
  "ssl.truststore.password" -> "xxxx",
  "ssl.key.password" -> "xxxx",
  "ssl.keystore.password" -> "xxxx",
  //this two lines
  "ssl.truststore.location" -> "trustore.jks",
  "ssl.keystore.location" -> "key.jks"
  //this two line also bug
  //"ssl.truststore.location" -> getClass.getResource("/ssl/trustore.jks").getPath,
  //"ssl.keystore.location" -> getClass.getResource("/ssl/key.jks").getPath
)

相关问题