首页 > 解决方案 > 如何使用 spark-submit 获取 spark SUBMISSION_ID?

问题描述

很多地方都需要SUBMISSION_ID,比如spark-submit --status和 Spark REST API。SUBMISSION_ID但是当我使用spark-submit命令提交火花作业时,我怎么能得到这个呢?

PS:

我使用python[popen][2]开始spark-submit工作。我希望SUBMISSION_ID我的 python 程序可以通过 REST API 监控 Spark 作业状态:<ip>:6066/v1/submissions/status/<SUBMISSION_ID>

标签: apache-spark

解决方案


感谢@Pandey 提供的线索。答案https://stackoverflow.com/a/37980813/5634636对我有很大帮助。

TL;博士

详细说明

注意:我只在 Apache Spark 2.3.1 上测试我的方法。我不能保证它也适用于其他版本。

让我们先明确我的要求。我想要 3 个功能:

  1. 远程提交 Spark 作业
  2. 随时检查作业状态(RUNNING、ERROR、FINISHED...)
  3. 如果出现错误,获取错误消息

本地提交

注意:此答案仅适用于集群模式

Spark 工具spark-submit会有所帮助。

远程提交

推荐使用 Spark 提交 API。Apache Spark官网上好像没有任何文档,所以有人称之为隐藏API。详情见:https ://www.nitendragautam.com/spark/submit-apache-spark-job-with-rest-api/

  • 要提交 Spark 作业,请使用提交 API
  • 要获取作业的状态,请使用 status API: http://<master-ip>:6066/v1/submissions/status/<submission-id>。提交作业时,submission-id将以 json 格式返回。
  • 错误消息包含在状态消息中。
  • 有关错误消息的更多信息:请注意状态ERRORFAILED之间的区别。简而言之,FAILED 表示在执行Spark 作业过程中出现问题(例如未捕获的异常),而 ERROR 表示在提交过程中出现问题(例如无效的 jar 路径)。错误消息包含在状态 json 中。如果要查看 FAILED 原因,可以通过http://<driver-ip>:<ui-port>/log/<submission-id>.

以下是错误状态的示例(**** 是故意写错的不正确 jar 路径):

{
  "action" : "SubmissionStatusResponse",
  "driverState" : "ERROR",
  "message" : "Exception from the cluster:\njava.io.FileNotFoundException: File hdfs:**** does not exist.\n\torg.apache.hadoop.hdfs.DistributedFileSystem.listStatusInternal(DistributedFileSystem.java:795)\n\torg.apache.hadoop.hdfs.DistributedFileSystem.access$700(DistributedFileSystem.java:106)\n\torg.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:853)\n\torg.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:849)\n\torg.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)\n\torg.apache.hadoop.hdfs.DistributedFileSystem.listStatus(DistributedFileSystem.java:860)\n\torg.apache.spark.util.Utils$.fetchHcfsFile(Utils.scala:727)\n\torg.apache.spark.util.Utils$.doFetchFile(Utils.scala:695)\n\torg.apache.spark.util.Utils$.fetchFile(Utils.scala:488)\n\torg.apache.spark.deploy.worker.DriverRunner.downloadUserJar(DriverRunner.scala:155)\n\torg.apache.spark.deploy.worker.DriverRunner.prepareAndRunDriver(DriverRunner.scala:173)\n\torg.apache.spark.deploy.worker.DriverRunner$$anon$1.run(DriverRunner.scala:92)",
  "serverSparkVersion" : "2.3.1",
  "submissionId" : "driver-20190315160943-0005",
  "success" : true,
  "workerHostPort" : "172.18.0.4:36962",
  "workerId" : "worker-20190306214522-172.18.0.4-36962"
}

推荐阅读