oozie JAVA Client 编程提交作业
1,eclipse环境搭建
在eclipse中新建一个JAVA工程,导入必要的依赖包,目前用到的有:

其次编写JAVA 程序提交Oozie作业,这里可参考:oozie官方参考文档
在运行提交程序前,首先需要把相应的程序打成jar包,定义好workflow.xml,再把它们上传到HDFS中。然后在程序中指定作业的属性,这里我是直接用的oozie-examples.tar.gz中的示例。
部分代码参考如下:
OozieClient wc = new OozieClient("http://192.168.121.35:11000/oozie");
//create workflow job configuration
Properties conf = wc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, "hdfs://datanode1:8020/user/cdhfive/examples/apps/map-reduce");
//set a workflow parameters
conf.setProperty("nameNode", "hdfs://datanode1:8020");
conf.setProperty("jobTracker", "datanode1:8032");
conf.setProperty("inputDir", "/user/cdhfive/examples/input-data");
// conf.setProperty("outputDir", "hdfs://192.168.121.35:8020/user/cdhfive/examples/output-data");
conf.setProperty("outputDir", "/user/cdhfive/examples/output-data");
conf.setProperty("queueName", "default");
conf.setProperty("examplesRoot", "examples");
conf.setProperty("user.name", "cdhfive");
在代码中workflow的参数时需要注意以下几点:
①在workflow.xml中定义的变量需要在程序中进行设置。如workflow.xml中的 ${jobTracker},则在JAVA程序中需要用语句:
conf.setProperty("jobTracker", "datanode1:8032");设置好。并且value 值要符合相应的格式。
2,作业提交过程中碰到的一些问题及解决:
由于我在本地windows系统上的用户hapjin运行的eclipse应用程序进行的提交,而集群则是远程的虚拟机。因此作业执行时报权限错误。
这里可以在作业提交过程中指定作业的用户名:conf.setProperty("user.name", "cdhfive")
ⓑ变量不能解析的错误:这是因为在workflow.xml中定义了一些变量,如${examplesRoot},而在JAVA代码中没有给这些变量赋值(conf.setProperty(key,value))。
javax.servlet.jsp.el.ELException: variable [examplesRoot] cannot be resolved
解决:workflow.xml中定义的变量需要在Java代码中使用 conf.setProerty方法指定值。
整个完整的程序代码参考如下:
package test; import java.util.Properties; import org.apache.oozie.client.OozieClient;
import org.apache.oozie.client.OozieClientException;
import org.apache.oozie.client.WorkflowJob.Status; public class CommitJob {
public static void main(String[] args) {
//get a OozieClient for local Oozie
OozieClient wc = new OozieClient("http://192.168.121.35:11000/oozie"); //create workflow job configuration
Properties conf = wc.createConfiguration();
conf.setProperty(OozieClient.APP_PATH, "hdfs://datanode1:8020/user/cdhfive/examples/apps/map-reduce"); //set a workflow parameters
conf.setProperty("nameNode", "hdfs://datanode1:8020"); conf.setProperty("inputDir", "/user/cdhfive/examples/input-data");
// conf.setProperty("outputDir", "hdfs://192.168.121.35:8020/user/cdhfive/examples/output-data");
conf.setProperty("outputDir", "/user/cdhfive/examples/output-data");
conf.setProperty("queueName", "default");
conf.setProperty("examplesRoot", "examples");
conf.setProperty("user.name", "cdhfive"); //submit and start the workflow job
try{
String jobId = wc.run(conf);
System.out.println("Workflow job submitted"); //wait until the workflow job finishes
while(wc.getJobInfo(jobId).getStatus() == Status.RUNNING){
System.out.println("Workflow job running...");
try{
Thread.sleep(10*1000);
}catch(InterruptedException e){e.printStackTrace();}
}
System.out.println("Workflow job completed!");
System.out.println(wc.getJobId(jobId));
}catch(OozieClientException e){e.printStackTrace();} }
}
运行结果截图:


3,Oozie处理错误的方式
If the failure is of transient nature, Oozie will perform retries after a pre-defined time interval. The number of retries and timer interval for a type of action must be pre-configured at Oozie level. Workflow jobs can override such configuration.
Examples of a transient failures are network problems or a remote system temporary unavailable.
If the failure is of non-transient nature, Oozie will suspend the workflow job until an manual or programmatic intervention resumes the workflow job and the action start or end is retried.
如果作业是临时失败的,如因为网络原因或远程系统临时不可用,此时OOzie将会以预定的时间间隔重启作业。若作业不是临时失败的,Oozie将会挂起作业,此时需要手工或程序的干预才能恢复作业的运行。
oozie JAVA Client 编程提交作业的更多相关文章
- oozie java api提交作业
今晚试验用java的api来提交代码,由于代码是在我机器上写的,然后提交到我的虚拟机集群当中去,所以中间产生了一个错误..要想在任意一台机器上向oozie提交作业的话,需要对hadoop的core-s ...
- 利用SparkLauncher 类以JAVA API 编程的方式提交Spark job
一.环境说明和使用软件的版本说明: hadoop-version:hadoop-2.9.0.tar.gz spark-version:spark-2.2.0-bin-hadoop2.7.tgz jav ...
- oozie 重新提交作业
在oozie的运行过程当中可能会出现错误,比如数据库连接不上,或者作业执行报错导致流程进入suspend或者killed状态,这个时候我们就要分析了,如果确实是数据或者是网络有问题,我们比如把问题解决 ...
- Java第八次作业--数据库编程
Deadline: 2017-5-18 23:00 一.学习要点 认真看书并查阅相关资料,掌握以下内容: 掌握应用JDBC访问数据库的基本步骤 掌握DriverManager类.Connection接 ...
- java网络编程serversocket
转载:http://www.blogjava.net/landon/archive/2013/07/24/401911.html Java网络编程精解笔记3:ServerSocket详解ServerS ...
- java网络编程socket解析
转载:http://www.blogjava.net/landon/archive/2013/07/02/401137.html Java网络编程精解笔记2:Socket详解 Socket用法详解 在 ...
- Java 网络编程---分布式文件协同编辑器设计与实现
目录: 第一部分:Java网络编程知识 (一)简单的Http请求 一般浏览网页时,使用的时Ip地址,而IP(Internet Protocol,互联网协议)目前主要是IPv4和IPv6. IP地址是一 ...
- Java多线程编程中Future模式的详解
Java多线程编程中,常用的多线程设计模式包括:Future模式.Master-Worker模式.Guarded Suspeionsion模式.不变模式和生产者-消费者模式等.这篇文章主要讲述Futu ...
- Java并发编程面试题 Top 50 整理版
本文在 Java线程面试题 Top 50的基础上,对部分答案进行进行了整理和补充,问题答案主要来自<Java编程思想(第四版)>,<Java并发编程实战>和一些优秀的博客,当然 ...
随机推荐
- HTTP协议整理
一.概念 1.HTTP协议:即超文本传输协议(Hypertext transfer protocol).是一种详细规定了浏览器和Web服务器之间互相通信的规则,它允许将超文本标记语言(HTML)文档从 ...
- yum install 报错[Errno 14] curl#37 - Couldn't open file /mnt/repodata/repomd.xml
1.然后按照网上的一些修改,先是执行: yum cleam all 然后 yum makecache,问题还是没解决,继续报错. 其实这两条命令就是清空缓存,然后再重新缓存的意思,有时候可能有效. 2 ...
- python拉格朗日插值
#拉格朗日插值代码 import pandas as pd #导入数据分析库Pandas from scipy.interpolate import lagrange #导入拉格朗日插值函数 inpu ...
- shell 学习笔记二
一.break命令 break命令允许跳出所有循环(终止执行后面的所有循环). 下面的例子中,脚本进入死循环直至用户输入数字大于5.要跳出这个循环,返回到shell提示符下,就要使用break命令. ...
- 【转载】JAVA消息服务JMS规范及原理详解
转载:https://www.cnblogs.com/molao-doing/articles/6557305.html 作者: moyun- 一.简介 JMS即Java消息服务(Java Messa ...
- BZOJ3590 SNOI2013Quare(状压dp)
可能作为最优解的边双都可以这样生成:初始时边双内只有一个点,每次选取边双内部两点(可以相同)和一个当前不在边双内的点集,以该两点为起止点找一条链(当然如果两点相同就是个环)将点集串起来,加入边双.状压 ...
- 查看本地Git仓库历史修改内容
查看历史内容 在.git文件 同级目录下,右键 选择 git history 但是红框中的路径无法拷贝.右键红框中的任一文件,有 HighLight this only, Highlight this ...
- MessageBox函数第一个参数hwnd的作用
MessageBox 函数用于创建.显示并操作一个消息对话框.该对话框包含由调用程序定义的信息和标题,以及预先定义的图标和按钮. 这个方法的第一个参数hWnd,代表消息框拥有的窗口.这个参数到底有什么 ...
- mybatis There is no getter for property named '*' in 'class java.lang.String
1.原因 server层 xxxx.get("1234") map <if test="aaa != null and aaa.id != null and ...
- 自学Linux Shell12.7-控制循环break、continue命令
点击返回 自学Linux命令行与Shell脚本之路 12.7-控制循环break.continue命令 break命令.break命令用于跳出循环,使用break可以跳出任何类型的循环:for.whi ...