使用 REST 触发 spark 作业

Triggering spark jobs with REST

我最近一直在尝试 apache spark. My question is more specific to trigger spark jobs. 我发布了关于理解 spark 作业的问题。在工作上变得肮脏之后,我继续我的要求。

我有一个 REST 端点,我在其中公开 API 以触发作业,我使用 Spring4.0 进行 Rest 实施。现在继续,我想在 Spring 中实现作业即服务,我将在其中以编程方式提交作业,这意味着当端点被触发时,我将使用给定的参数触发作业。 我现在几乎没有设计选择。

首先,我想知道在这种情况下最好的解决方案是什么,既要执行又要扩展。

注意 :我正在使用来自 spark 的独立集群。 请帮忙。

只需使用 Spark JobServer https://github.com/spark-jobserver/spark-jobserver

制作服务需要考虑很多事情,Spark JobServer 已经涵盖了其中的大部分内容。如果您发现不够好,提出请求并向他们的系统添加代码应该很容易,而不是从头开始重新发明

事实证明,Spark 有一个隐藏的 REST API 来提交作业、检查状态和终止。

在此处查看完整示例:http://arturmkrtchyan.com/apache-spark-hidden-rest-api

以下是您可能会觉得有用的好客户:https://github.com/ywilkof/spark-jobs-rest-client

编辑:这个答案是在 2015 年给出的。现在有像 Livy 这样的选项可用。

Livy 是一个开源 REST 接口,用于从任何地方与 Apache Spark 进行交互。它支持在本地或 Apache Hadoop YARN 中运行的 Spark 上下文中执行代码片段或程序。

即使我有这个要求,我也可以使用 Livy Server 来完成,正如贡献者之一 Josemy 提到的那样。以下是我采取的步骤,希望对大家有所帮助:

Download livy zip from https://livy.apache.org/download/
Follow instructions:  https://livy.apache.org/get-started/


Upload the zip to a client.
Unzip the file
Check for the following two parameters if doesn't exists, create with right path
export SPARK_HOME=/opt/spark
export HADOOP_CONF_DIR=/opt/hadoop/etc/hadoop

Enable 8998 port on the client

Update $LIVY_HOME/conf/livy.conf with master details any other stuff needed
Note: Template are there in $LIVY_HOME/conf
Eg. livy.file.local-dir-whitelist = /home/folder-where-the-jar-will-be-kept/


Run the server
$LIVY_HOME/bin/livy-server start

Stop the server
$LIVY_HOME/bin/livy-server stop

UI: <client-ip>:8998/ui/

Submitting job:POST : http://<your client ip goes here>:8998/batches
{
  "className" :  "<ur class name will come here with package name>",
  "file"  : "your jar location",
  "args" : ["arg1", "arg2", "arg3" ]

}