spark python 上传代码包_使用 Livy Rest API 提交 spark 批量任务 (jar,Python, streaming)...
Livy是一个开源的REST 接口,用于与Spark进行交互,它同时支持提交执行代码段和完整的程序。
image.png
Livy封装了spark-submit并支持远端执行。
启动服务器
执行以下命令,启动livy服务器。
./bin/livy-server
这里假设spark使用yarn模式,所以所有文件路径都默认位于HDFS中。如果是本地开发模式的话,直接使用本地文件即可(注意必须配置livy.conf文件,设置livy.file.local-dir-whitelist = directory,以允许文件添加到session)。
提交jar包
首先我们列出当前正在执行的任务:
curl localhost:8998/sessions | python -m json.tool % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 34 0 34 0 0 2314 0 --:--:-- --:--:-- --:--:-- 2428
{
"from": 0,
"sessions": [],
"total": 0
}
然后提交jar包,假设提交的jar包位于hdfs中,路径为/usr/lib/spark/lib/spark-examples.jar
curl -X POST --data '{"file": "/user/romain/spark-examples.jar", "className": "org.apache.spark.examples.SparkPi"}' -H "Content-Type: application/json" localhost:8998/batches
{"id":0,"state":"running","log":[]}
返回结果中包括了提交的ID,这里为0,我们可以通过下面的命令查看任务状态:
curl localhost:8998/batches/0 | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 902 0 902 0 0 91120 0 --:--:-- --:--:-- --:--:-- 97k
{
"id": 0,
"log": [
"15/10/20 16:32:21 INFO ui.SparkUI: Stopped Spark web UI at http://192.168.1.30:4040",
"15/10/20 16:32:21 INFO scheduler.DAGScheduler: Stopping DAGScheduler",
"15/10/20 16:32:21 INFO spark.MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!",
"15/10/20 16:32:21 INFO storage.MemoryStore: MemoryStore cleared",
"15/10/20 16:32:21 INFO storage.BlockManager: BlockManager stopped",
"15/10/20 16:32:21 INFO storage.BlockManagerMaster: BlockManagerMaster stopped",
"15/10/20 16:32:21 INFO scheduler.OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!",
"15/10/20 16:32:21 INFO spark.SparkContext: Successfully stopped SparkContext",
"15/10/20 16:32:21 INFO util.ShutdownHookManager: Shutdown hook called",
"15/10/20 16:32:21 INFO util.ShutdownHookManager: Deleting directory /tmp/spark-6e362908-465a-4c67-baa1-3dcf2d91449c"
],
"state": "success"
}
此外,还可以通过下面的api,获取日志信息:
curl localhost:8998/batches/0/log | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5378 0 5378 0 0 570k 0 --:--:-- --:--:-- --:--:-- 583k
{
"from": 0,
"id": 3,
"log": [
"SLF4J: Class path contains multiple SLF4J bindings.",
"SLF4J: Found binding in [jar:file:/usr/lib/zookeeper/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]",
"SLF4J: Found binding in [jar:file:/usr/lib/flume-ng/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]",
"SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.",
"SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]",
"15/10/21 01:37:27 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable",
"15/10/21 01:37:27 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032",
"15/10/21 01:37:27 INFO yarn.Client: Requesting a new application from cluster with 1 NodeManagers",
"15/10/21 01:37:27 INFO yarn.Client: Verifying our application has not requested more than the maximum memory capability of the cluster (8192 MB per container)",
"15/10/21 01:37:27 INFO yarn.Client: Will allocate AM container, with 1408 MB memory including 384 MB overhead",
"15/10/21 01:37:27 INFO yarn.Client: Setting up container launch context for our AM",
"15/10/21 01:37:27 INFO yarn.Client: Setting up the launch environment for our AM container",
"15/10/21 01:37:27 INFO yarn.Client: Preparing resources for our AM container",
....
....
"15/10/21 01:37:40 INFO yarn.Client: Application report for application_1444917524249_0004 (state: RUNNING)",
"15/10/21 01:37:41 INFO yarn.Client: Application report for application_1444917524249_0004 (state: RUNNING)",
"15/10/21 01:37:42 INFO yarn.Client: Application report for application_1444917524249_0004 (state: FINISHED)",
"15/10/21 01:37:42 INFO yarn.Client: ",
"\t client token: N/A",
"\t diagnostics: N/A",
"\t ApplicationMaster host: 192.168.1.30",
"\t ApplicationMaster RPC port: 0",
"\t queue: root.romain",
"\t start time: 1445416649481",
"\t final status: SUCCEEDED",
"\t tracking URL: http://unreal:8088/proxy/application_1444917524249_0004/A",
"\t user: romain",
"15/10/21 01:37:42 INFO util.ShutdownHookManager: Shutdown hook called",
"15/10/21 01:37:42 INFO util.ShutdownHookManager: Deleting directory /tmp/spark-26cdc4d9-071e-4420-a2f9-308a61af592c"
],
"total": 67
}
还可以在命令行中添加参数,例如这里计算一百次:
curl -X POST --data '{"file": "/usr/lib/spark/lib/spark-examples.jar", "className": "org.apache.spark.examples.SparkPi", "args": ["100"]}' -H "Content-Type: application/json" localhost:8998/batches
{"id":1,"state":"running","log":[]}
如果想终止任务,可以调用以下API:
curl -X DELETE localhost:8998/batches/1
{"msg":"deleted"}
当重复调用上述接口时,什么也不会做,因为任务已经删除了:
curl -X DELETE localhost:8998/batches/1
session not found
提交Python任务
提交Python任务和Jar包类似:
curl -X POST --data '{"file": "/user/romain/pi.py"}' -H "Content-Type: application/json" localhost:8998/batches
{"id":2,"state":"starting","log":[]}
检查任务状态:
curl localhost:8998/batches/2 | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 616 0 616 0 0 77552 0 --:--:-- --:--:-- --:--:-- 88000
{
"id": 2,
"log": [
"\t ApplicationMaster host: 192.168.1.30",
"\t ApplicationMaster RPC port: 0",
"\t queue: root.romain",
"\t start time: 1445417899564",
"\t final status: UNDEFINED",
"\t tracking URL: http://unreal:8088/proxy/application_1444917524249_0006/",
"\t user: romain",
"15/10/21 01:58:26 INFO yarn.Client: Application report for application_1444917524249_0006 (state: RUNNING)",
"15/10/21 01:58:27 INFO yarn.Client: Application report for application_1444917524249_0006 (state: RUNNING)",
"15/10/21 01:58:28 INFO yarn.Client: Application report for application_1444917524249_0006 (state: RUNNING)"
],
"state": "running"
}
获取日志信息:
curl localhost:8998/batches/2/log | python -m json.tool
spark python 上传代码包_使用 Livy Rest API 提交 spark 批量任务 (jar,Python, streaming)...相关推荐
- 使用element-ui的upload组件上传代码包时遇到的问题及总结
1.在工作中使用element-ui的upload组件时,遇到一个问题就是这个upload会自动发送一个http请求,即使你使用了http-request自定义上传覆盖默认上传函数,也会导致在控制台里 ...
- 【西瓜】抖音小程序 抖音小程序源码包1.8(xigua_dy.94864)[西瓜抖音版小程序前端上传代码包最新原版]
抖音小程序源码 可以使用抖音小程序工具导入发布小程序 ※小程序类应用受"抖音平台"影响,部分业务需提供企业资质才可上线使用 功能介绍 为西瓜同城提供抖音版小程序端,支持所有西瓜同城 ...
- 抖音python上的代码视频_资深程序员:十行Python代码教你爬取抖音视频!
环境说明 环境: python 3.7.1 centos 7.4 pip 10.0.1 部署 [root@localhost ~]# python3.7 --version Python 3.7.1 ...
- python名人名言代码打印_名人名言-免费API,收集所有免费的API
/** * Created by PhpStorm. * User: FZS * Time: 2019/3/15 17:50 */ //-------------------------------- ...
- 2018年7月份,python上传自己的包库到pypi官网的方法
最近pypi官网进行了更新,老的上传网址作废了.记录下上传到pypi的方法 0.去pypi官网注册账号,没账号是不可能上传的,想想也是那不乱套了吗,注册后会收到一个邮件需要点击然后重新登录 1.目录就 ...
- git 上传代码到指定仓库_初次使用git上传代码到github远程仓库
一.新建代码库 注册好github登录后,首先先在网页上新建代码库. 点击右上角"+"→New repository 进入如下页面:按照要求填写完成后,点击按钮创建代码库创建成功. ...
- 码云上传代码添加标签_第一次使用Git Bash Here 将本地代码上传到码云
当我们安装成功git工具时候,初次使用Git时,需要Git进行配置. 1.点击桌面上的这个图标 ,打开Git Bash:如图所示 2.配置自己的用户名和邮箱 git config --global u ...
- ubuntu tomcat上传目录权限_等了 3 年,Ubuntu Studio 终于有权限上传更新包
Ubuntu 的衍生版本 Ubuntu Studio 终于选出了两位具有上传更新包权限的开发者. 此前就有媒体报导过,Ubuntu Studio 19.04 版本可能会流产,而原因很让人诧异:社区里没 ...
- azure上传代码_深入了解Azure Data Studio:更多代码和更少GUI
azure上传代码 In the previous two articles, Starting your journey with Azure Data Studio and Developing ...
最新文章
- Linux内核编译和测试
- Guava包学习---Maps
- C#三层ATM-11.查看交易信息
- Windows下使用MinGw和gcc构建第一个C程序、g++构建第一个C++程序
- Too many files with unapproved license: 2 See RAT report
- java工作中mq应用多吗_RabbitMQ消息中间件在工作中的应用场景
- java基础自学教程_Java基础自学教程(全套)
- 0x07 MySQL 多表查询
- idea Terminal配置cmder(增加nodejs,git配置,jdk本地环境)
- Java实现第九届蓝桥杯分数
- 【从Northwind学习数据库】汇总查询
- 计算机Auto服务错误1053,Win7电脑宽带连接错误1053的原因和解决方案
- PyTorch常用5个抽样函数
- Android Jetpack架构组件之Room
- K-th Largest Value
- JS学习之BOM | 常见网页特效 | 轮播图 | 返回顶部 | 筋斗云案例
- 「镁客·请讲」第六镜叶雨桐:进一步细化产品应用,做大规模场景的动态识别...
- 14个程序员常去的外国网站
- 使用功耗分析仪,对一款LORA低功耗温度传感器进行功耗评测,评估温度传感器的待机时长,供参考。
- 电压放大器的作用原理是什么
热门文章
- keil debug如何在watch直接修改变量值_零基础学VBA:什么是VBA?如何编写和运行VBA代码?...
- 写java线程导致电脑内存不足_如何写出让java虚拟机发生内存溢出异常OutOfMemoryError的代码...
- 服务器日志显示意外关闭,服务器事件日志
- android studio crashlytics,完美解决Android Studio集成crashlytics后无法编译的问题
- mysql 魔术设置_PHP之十六个魔术方法详细介绍
- 远程电脑桌面控制怎么看计算机,计算机如何通过远程控制,可以查看他人电脑屏幕...
- mysql denide_MYSQL 出现Error1045 access denied 的解决方法
- 计算机C语言常用语句,计算机二级C语言考试常见知识积累
- linux发挥显卡性能,Linux Kernel 2.6.30下Intel显卡性能有大幅提升!
- dataframe 删除首尾空格_你敲空格的速度很快,但女人的手不是用来敲空格的!...