尚硅谷大数据技术之Oozie(新)第4章 Oozie的使用
4.2 案例二:Oozie逻辑调度执行多个Job
目标:使用Oozie执行多个Job调度
分步执行:
- 解压官方案例模板
[atguigu@hadoop102 oozie-4.0.0-cdh5.3.6]$ tar -zxf oozie-examples.tar.gz
- 编写脚本
[atguigu@hadoop102 oozie-4.0.0-cdh5.3.6]$ vi oozie-apps/shell/p2.sh
内容如下:
#!/bin/bash /bin/date > /tmp/p2.log |
3)修改job.properties和workflow.xml文件
job.properties
nameNode=hdfs://hadoop102:8020 jobTracker=hadoop103:8032 queueName=default examplesRoot=oozie-apps
oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell EXEC1=p1.sh EXEC2=p2.sh |
workflow.xml
<workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf"> <start to="p1-shell-node"/> <action name="p1-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>${EXEC1}</exec> <file>/user/atguigu/oozie-apps/shell/${EXEC1}#${EXEC1}</file> <!-- <argument>my_output=Hello Oozie</argument>--> <capture-output/> </shell> <ok to="p2-shell-node"/> <error to="fail"/> </action>
<action name="p2-shell-node"> <shell xmlns="uri:oozie:shell-action:0.2"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>${EXEC2}</exec> <file>/user/admin/oozie-apps/shell/${EXEC2}#${EXEC2}</file> <!-- <argument>my_output=Hello Oozie</argument>--> <capture-output/> </shell> <ok to="end"/> <error to="fail"/> </action> <decision name="check-output"> <switch> <case to="end"> ${wf:actionData('shell-node')['my_output'] eq 'Hello Oozie'} </case> <default to="fail-output"/> </switch> </decision> <kill name="fail"> <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <kill name="fail-output"> <message>Incorrect output, expected [Hello Oozie] but was [${wf:actionData('shell-node')['my_output']}]</message> </kill> <end name="end"/> </workflow-app> |
- 上传任务配置
$ bin/hadoop fs -rmr /user/atguigu/oozie-apps/
$ bin/hadoop fs -put oozie-apps/map-reduce /user/atguigu/oozie-apps
- 执行任务
[atguigu@hadoop102 oozie-4.0.0-cdh5.3.6]$ bin/oozie job -oozie http://hadoop102:11000/oozie -config oozie-apps/shell/job.properties -run