简体   繁体   English

在Oozie中将参数从一个动作传递到另一个动作

[英]Passing parameters from one action to another in Oozie

I have a following shell script: 我有以下shell脚本:

DATE= date +"%d%b%y" -d "-1 days"

How can I pass DATE to a Java action? 如何将DATE传递给Java操作?

You can capture output from shell script and pass it to java action.In the shell script , echo the property like 'dateVariable=${DATE}' and add the capture-output element int the shell action. 您可以捕获shell脚本的输出并将其传递给java动作。在shell脚本中,回显诸如'dateVariable = $ {DATE}'之类的属性,然后将capture-output元素添加到shell动作中。 This will let you capture dateVariable from shell script.In the java action, You can pass the captured variable as parameter as ${wf:actionData('shellAction')['dateVariable']} where shellAction is the shell action name. 这将使您能够从shell脚本捕获dateVariable。在java动作中,您可以将捕获的变量作为参数传递为$ {wf:actionData('shellAction')['dateVariable']},其中shellAction是Shell动作名称。

Sample workflow :- 示例工作流程:-

<?xml version="1.0" encoding="UTF-8"?>
<workflow-app xmlns="uri:oozie:workflow:0.4"
    name="Test workflow">
    <start to="shellAction" />
    <action name="shellAction">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>test_script.sh</exec> <file>${nameNode}/${workFlowLocation}/Scripts/test_script.sh#test_script.sh</file>          
            <capture-output />
        </shell>
        <ok to="JavaAction" />
        <error to="fail" />
    </action>

    <action name="JavaAction">
        <java>
            <main-class>com.test.TestDriver</main-class>
            <arg>${wf:actionData('shellAction')['dateVariable']}</arg>
            <capture-output />
        </java>
        <ok to="end" />
        <error to="fail" />
    </action>

    <kill name="fail">
        <message>Job failed, error
            message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end" />
</workflow-app>

In the shell script ,echo the value as below 在shell脚本中,回显以下值

 echo "dateVariable=${dateValue}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM