以编程方式从另一个应用程序提交并终止Spark应用程序

问题描述 投票:5回答:6

我想知道是否可以从其他服务提交,监控和终止spark应用程序。

我的要求如下:

我写了一个服务

  1. 解析用户命令
  2. 将它们转换为已经准备好的Spark-SQL应用程序的可理解参数
  3. 使用来自spark-submitProcessBuilder将应用程序连同参数一起提交给Spark Cluster
  4. 并计划在集群模式下运行生成的应用程序驱动程序。

其他要求需要:

  • 查询应用程序状态,例如,百分比仍然存在
  • 相应地杀死查询

我在spark standalone documentation中发现的建议使用以下方法杀死应用程序:

./bin/spark-class org.apache.spark.deploy.Client kill <master url> <driver ID>

并且应该find the driver ID through the standalone Master web UI at http://<master url>:8080.

那么,我该怎么办?

相关的SO问题: Spark application finished callback Deploy Apache Spark application from another application in Java, best practice

apache-spark
6个回答
5
投票

您可以使用shell脚本来执行此操作。

部署脚本:

#!/bin/bash

spark-submit --class "xx.xx.xx" \       
        --deploy-mode cluster \
        --supervise \
        --executor-memory 6G hdfs:///spark-stat.jar > output 2>&1

cat output

你会得到这样的输出:

16/06/23 08:37:21 INFO rest.RestSubmissionClient: Submitting a request to launch an application in spark://node-1:6066.
16/06/23 08:37:22 INFO rest.RestSubmissionClient: Submission successfully created as driver-20160623083722-0026. Polling submission state...
16/06/23 08:37:22 INFO rest.RestSubmissionClient: Submitting a request for the status of submission driver-20160623083722-0026 in spark://node-1:6066.
16/06/23 08:37:22 INFO rest.RestSubmissionClient: State of driver driver-20160623083722-0026 is now RUNNING.
16/06/23 08:37:22 INFO rest.RestSubmissionClient: Driver is running on worker worker-20160621162532-192.168.1.200-7078 at 192.168.1.200:7078.
16/06/23 08:37:22 INFO rest.RestSubmissionClient: Server responded with CreateSubmissionResponse:
{
  "action" : "CreateSubmissionResponse",
  "message" : "Driver successfully submitted as driver-20160623083722-0026",
  "serverSparkVersion" : "1.6.0",
  "submissionId" : "driver-20160623083722-0026",
  "success" : true
}

在此基础上,创建您的kill驱动程序脚本

#!/bin/bash

driverid=`cat output | grep submissionId | grep -Po 'driver-\d+-\d+'`

spark-submit --master spark://node-1:6066 --kill $driverid

通过使用chmod +x确保给出脚本执行权限


4
投票

杀死火花应用程序的“肮脏”技巧是杀死名为SparkSubmit的jps。主要问题是该应用程序将被“杀死”但在spark master日志中它将显示为“已完成”...

user@user:~$ jps  
20894 Jps
20704 SparkSubmit

user@user:~$ kill 20704

说实话,我不喜欢这个解决方案,但现在是我知道杀死一个应用程序的唯一方法。

希望它可以帮助。


2
投票

这是我做的:

  1. 要提交应用程序,请使用(隐藏的)Spark REST提交API:http://arturmkrtchyan.com/apache-spark-hidden-rest-api 通过这种方式,您可以获得一个DriverID(在submissionId下),您可以使用它来杀死您的作业(您不应该杀死该应用程序,特别是如果您在独立模式下使用“监督”) 此API还允许您查询驱动程序状态
  2. 使用(也是隐藏的)UI Json API查询应用程序的状态:http://[master-node]:[master-ui-port]/json/ 此服务以JSON格式公开主UI上可用的所有信息。
  3. 您还可以使用“公共”REST API在每个工作程序上查询Master或Executor上的Applications,但这不会暴露驱动程序(至少不是Spark 1.6)

0
投票

您可以从processbuilder中发出纱线提交来列出应用程序,然后根据您可用的应用程序名称进行过滤,提取appId然后使用Yarn命令轮询状态/ kill等。


0
投票

kill -9 $(jsp | grep SparkSubmit | grep -Eo'[0-9] {1,7}')


0
投票

您可以在[spark] / work /中找到驱动程序ID。 id是目录名称。通过spark-submit杀死这份工作。

© www.soinside.com 2019 - 2024. All rights reserved.