apache-spark - 如何使用 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>
解决方案
感谢@Pandey 提供的线索。答案https://stackoverflow.com/a/37980813/5634636对我有很大帮助。
TL;博士
- 如果您想在本地提交 spark 作业,答案https://stackoverflow.com/a/37980813/5634636确实有效。唯一的一点是你必须使用
cluster
模式来提交你的工作,即使用参数--deploy-mode cluster
。 - 如果要远程提交 Spark 作业,请使用 Spark 提交 API。这将有很大帮助。有关详细信息,请参阅https://www.nitendragautam.com/spark/submit-apache-spark-job-with-rest-api/。
详细说明
注意:我只在 Apache Spark 2.3.1 上测试我的方法。我不能保证它也适用于其他版本。
让我们先明确我的要求。我想要 3 个功能:
- 远程提交 Spark 作业
- 随时检查作业状态(RUNNING、ERROR、FINISHED...)
- 如果出现错误,获取错误消息
本地提交
注意:此答案仅适用于集群模式
Spark 工具spark-submit
会有所帮助。
- 要提交作业,请参阅 https://spark.apache.org/docs/2.4.0/submitting-applications.html#launching-applications-with-spark-submit
- 要检查状态,请参阅https://stackoverflow.com/a/37420931/5634636。这样,您需要一个
SubmissionID
. 这个答案https://stackoverflow.com/a/37980813/5634636告诉您如何在集群模式下获取提交 ID 。提交 id 看起来像driver-20190315142356-0004
。 - 错误消息包含在作业状态消息中。
远程提交
推荐使用 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 格式返回。 - 错误消息包含在状态消息中。
- 有关错误消息的更多信息:请注意状态ERROR和FAILED之间的区别。简而言之,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"
}
推荐阅读
- ironpython - Spotfire:使用ironpython的列的平均值,使用表达式
- javascript - 如何获得基于异步等待/承诺的响应
- c# - asp.net mvc 中某些客户端上的信号刷新问题
- node.js - 如何在节点 js 中将 gson 转换为 json?
- python - 返回“non_field_errors”:在邮递员中
- python - TensorFlow v2 替换 clip_gradients_by_norm
- jquery - 设置单选按钮 (jQuery)
- c# - 如何使用 RATE 函数在 C# 中计算有效产量?
- git-commit - git commit --squash 选项有什么作用,为什么有用?
- php - 如何修复函数以避免错误日志(未定义的偏移量:2 in ....) - 爆炸