使用 REST 触发火花作业



我最近一直在尝试 apache 火花。我的问题更具体地触发火花工作。在这里,我发布了有关理解火花工作的问题。在弄脏了工作之后,我继续我的要求。

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

  • 与下面编写的作业类似,我需要维护几个由抽象类调用的作业可能JobScheduler

     /*Can this Code be abstracted from the application and written as 
      as a seperate job. Because my understanding is that the 
     Application code itself has to have the addJars embedded 
     which internally  sparkContext takes care.*/
     SparkConf sparkConf = new SparkConf().setAppName("MyApp").setJars(
     new String[] { "/path/to/jar/submit/cluster" })
     .setMaster("/url/of/master/node");
      sparkConf.setSparkHome("/path/to/spark/");
            sparkConf.set("spark.scheduler.mode", "FAIR");
            JavaSparkContext sc = new JavaSparkContext(sparkConf);
            sc.setLocalProperty("spark.scheduler.pool", "test");
        // Application with Algorithm , transformations
    
  • 扩展上述点具有由服务处理的多个版本的作业。

  • 或者使用 Spark 作业服务器来执行此操作。

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

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

事实证明,Spark有一个隐藏的REST API,可以提交作业,检查状态并杀死。

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

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

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

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

这里有一个很好的客户端,你可能会觉得有帮助: https://github.com/ywilkof/spark-jobs-rest-client

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

即使我有这个要求,我也可以使用 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" ]
}

最新更新