27

我最近一直在尝试apache spark。我的问题更具体到触发火花工作。在这里,我发布了有关了解火花工作的问题。在工作变得肮脏之后,我转向了我的要求。

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

  • 类似于下面的书面作业,我需要维护几个由抽象类调用的作业可能是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 Job Server 来执行此操作。

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

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

4

5 回答 5

28

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

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

于 2015-10-08T20:14:49.577 回答
7

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

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

于 2015-03-11T21:05:53.227 回答
5

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

于 2017-03-24T23:19:19.967 回答
1

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

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

于 2015-11-16T14:22:49.750 回答
0

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

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" ]

}
于 2020-01-31T06:47:57.847 回答