oozie——多指令碼邏輯順序執行
阿新 • • 發佈:2018-12-17
楔子
oozie順序執行sh指令碼。
1 描述
依次執行
p1.sh
和p2.sh
。每個裡面都是簡單的列印資訊。如下
p1.sh
[[email protected] shell]$ more p1.sh
#!/bin/bash
echo ''>/tmp/p1.log
/sbin/ifconfig>>/tmp/p1.log
echo `date`>>/tmp/p1.log
p2.sh
[[email protected] shell]$ more p2.sh #!/bin/bash /bin/date>>/tmp/p2.log echo '-----------------'>>/tmp/p2.log
2 配置
配置檔案如下
[[email protected] shell]$ ls
job.properties p1.sh p2.sh workflow.xml
2.1 配置job.properties
nameNode=hdfs://hadoop102:9000 jobTracker=hadoop103:8032 # 佇列名稱 queueName=default examplesRoot=oozie-apps oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell EXEC1=p1.sh EXEC2=p2.sh
2.1 配置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/grq/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/grq/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>