继前一篇大致上翻译了Email的Action配置,本篇继续看一下Shell的相关配置。java
Shell Action能够执行Shell脚本命令,工做流会等到shell彻底执行完毕后退出,再执行下一个节点。为了运行shell,必须配置job-tracker
以及name-node
,而且设置exec
来执行shell.node
Shell既可使用job-xml引用一个配置文件,也能够在shell action内直接配置。shell action中的配置会覆盖job-xml中的配置。web
EL表达式一样适用于shell action。shell
注意,mapred.job.tracker
以及fs.default.name
属性不能再shell action中直接配置。c#
在mapreduce任务中能够处理一些资源,这样shell就可使用了。更多的内容参考[WorkflowFunctionalSpec#FilesAchives]``[Adding Files and Archives for the Job]
章节。缓存
shell的输出能够被后面的工做流任务使用,这些信息能够用来配置一些关键的信息。若是shell的输出想要对整个工做流任务可用,那么必须知足app
<workflow-app name="[WF-DEF-NAME]" xmlns="uri:oozie:workflow:0.3"> ... <action name="[NODE-NAME]"> <shell xmlns="uri:oozie:shell-action:0.1"> <job-tracker>[JOB-TRACKER]</job-tracker> <name-node>[NAME-NODE]</name-node> <prepare> <delete path="[PATH]"/> ... <mkdir path="[PATH]"/> ... </prepare> <job-xml>[SHELL SETTINGS FILE]</job-xml> <configuration> <property> <name>[PROPERTY-NAME]</name> <value>[PROPERTY-VALUE]</value> </property> ... </configuration> <exec>[SHELL-COMMAND]</exec> <argument>[ARG-VALUE]</argument> ... <argument>[ARG-VALUE]</argument> <env-var>[VAR1=VALUE1]</env-var> ... <env-var>[VARN=VALUEN]</env-var> <file>[FILE-PATH]</file> ... <archive>[FILE-PATH]</archive> ... <capture-output/> </shell> <ok to="[NODE-NAME]"/> <error to="[NODE-NAME]"/> </action> ... </workflow-app>
prepare元素
,常常用于建立一系列的目录或者删除目录。注意目录必须是hdfs://host:port
这种格式的。job-xml元素
,指定shell任务的配置。在0.2的schema中,job-xml元素容许指定多个job-xml文件。configuration元素
,包含了shell任务的配置信息。exec元素
,这个是必填项。包含了shell脚本的路径,并执行它。参数能够设置0个或者多个argument元素。argument元素
,用于传递给shell脚本。env-var元素
,能够设置环境变量,传递给shell脚本。env-var须要包含键值对这种的信息。好比包含$PATH
这种信息,那么须要设置PATH=$PATH:mypath
这种格式。不要使用${}这种语法,由于它会被认为是Oozie的EL表达式。capture-output元素
,用来指定输出端。shell命令输出必须是java属性这种格式,而且小于2kb.经过工做流的定义,输出也能够经过string action实现。上面这些元素都支持EL表达式。分布式
如何运行shell或者perl脚本。oop
<workflow-app xmlns='uri:oozie:workflow:0.3' name='shell-wf'> <start to='shell1' /> <action name='shell1'> <shell xmlns="uri:oozie:shell-action:0.1"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>${EXEC}</exec> <argument>A</argument> <argument>B</argument> <file>${EXEC}#${EXEC}</file> <!--Copy the executable to compute node's current working directory --> </shell> <ok to="end" /> <error to="fail" /> </action> <kill name="fail"> <message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name='end' /> </workflow-app>
用于提交oozie工做的参数有spa
oozie.wf.application.path=hdfs://localhost:8020/user/kamrul/workflows/script#Execute is expected to be in the Workflow directory. #Shell Script to run EXEC=script.sh #CPP executable. Executable should be binary compatible to the compute node OS. #EXEC=hello #Perl script #EXEC=script.pl jobTracker=localhost:8021 nameNode=hdfs://localhost:8020 queueName=default
如何运行java程序并添加jar包
<workflow-app xmlns='uri:oozie:workflow:0.3' name='shell-wf'> <start to='shell1' /> <action name='shell1'> <shell xmlns="uri:oozie:shell-action:0.1"> <job-tracker>${jobTracker}</job-tracker> <name-node>${nameNode}</name-node> <configuration> <property> <name>mapred.job.queue.name</name> <value>${queueName}</value> </property> </configuration> <exec>java</exec> <argument>-classpath</argument> <argument>./${EXEC}:$CLASSPATH</argument> <argument>Hello</argument> <file>${EXEC}#${EXEC}</file> <!--Copy the jar to compute node current working directory --> </shell> <ok to="end" /> <error to="fail" /> </action> <kill name="fail"> <message>Script failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message> </kill> <end name='end' /> </workflow-app>
提交的相关参数
oozie.wf.application.path=hdfs://localhost:8020/user/kamrul/workflows/script#Hello.jar file is expected to be in the Workflow directory. EXEC=Hello.jar jobTracker=localhost:8021 nameNode=hdfs://localhost:8020 queueName=default
shell action标准输出和错误输出均可以直接输出到oozie的mapreduce任务控制台上。
经过oozie web控制台,也能够看到它的执行日志。
尽管shell能够执行任何的脚本命令,可是仍是有一些限制的。
shell能够输出java properties格式的数据,而且能够配合EL表达式,在其余的action中使用。所以它能够做为工做流的初始化任务,以及配置服务。
好比,在脚本中:
#!/bin/sh a=1 b=2 echo "a=$a" echo "b=$b"
在其余的节点中就能够经过EL表达式来使用了。