JAVA端通过Oozie Client 启动Oozie任务

oozie虽然内置了条件触发,但有时当我们的触发条件比较复杂的时候,可以使用java程序来控制其运行,而oozie同样提供了client端供使用。


通过OozieClient 端设置conf

Workflow.xml指定任务内所需配置文件等信息,如hive的配置文件等。

需要注意必须指定user.name,否则将导致权限错误,使程序一直处于Hold状态。

1JAVA端调用

事例中参数内容为方便阅读,将真实内容写出,但程序内参数均可从外面配置文件读入。

OozieClient内提供了多种oozie任务可供选择,见如下代码标红处:

参见:Apache Oozie Client 3.3.2 API


//execute the oozie work flow
// get the config info
DRBServiceConfigHandler mic = new DRBServiceConfigHandler();
OozieClient wc = new OozieClient(DRBServiceConfigHandler.getOozieService());
 
// create a workflow job configuration and set the workflow
// application path
Properties conf = wc.createConfiguration();
 
conf.setProperty("JobId", RESTServiceJobId);
 
conf.setProperty(OozieClient.APP_PATH, "hdfs://moma03:9000/user/applications/ea5be0c6-6ed8-4b6e-b444-29f7ae1998fe/workflow/workflow.xml");
conf.setProperty("jobTracker", "moma03:9001");
conf.setProperty("queueName", "default");
conf.setProperty("nameNode", "hdfs://moma03:9000");
conf.setProperty("user.name", "biadmin");
conf.setProperty("oozie.libpath", "/biginsights/oozie/sharedLibraries/hive");
conf.setProperty("script", "alter table bb rename to cc");
 
// submit and start the workflow jobString jobId = wc.run(conf);

String jobId = wc.run(conf);


 

 

2Workflow.xml文件

<pre name="code" class="html"><workflow-app xmlns="uri:oozie:workflow:0.2" name="hive-adhoc">
<start to="hive1" />
<action name="hive1">
<hive xmlns="uri:oozie:hive-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<job-xml>/biginsights/oozie/sharedLibraries/hive/conf/hive-site.xml
</job-xml>
<configuration>
<property>
<name>mapred.compress.map.output</name>
<value>true</value>
</property>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
<property>
<name>oozie.hive.defaults</name>
<value>/biginsights/oozie/sharedLibraries/hive/hive-default.xml
</value>
</property>
</configuration>
<script>adhoc.txt</script>
<param>SCRIPT=${script}</param>
</hive>
<ok to="end" />
<error to="fail" />
</action>
<kill name="fail">
<message>hive failed, error
message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end' />
</workflow-app>


 

3adhoc.txt文件

${SCRIPT}

这个文件也可以直接写入hive命令,但考虑到扩展性,这个文件写成这样更方便修改。


本次只是通过java 调用一个包含hive语句的oozie,一般工作中,oozie内往往需要更多内容。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值