JAVA端通过Oozie Client 启动Oozie任务

来源:互联网 发布:淘宝外卖要实体店吗 编辑:程序博客网 时间:2024/06/03 01:02

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 infoDRBServiceConfigHandler mic = new DRBServiceConfigHandler();OozieClient wc = new OozieClient(DRBServiceConfigHandler.getOozieService()); // create a workflow job configuration and set the workflow// application pathProperties 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, errormessage[${wf:errorMessage(wf:lastErrorNode())}]</message></kill><end name='end' /></workflow-app>


3adhoc.txt文件

${SCRIPT}

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


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


0 0
原创粉丝点击