简体   繁体   中英

Passing values from Java action to next Java action in Oozie workflow

I have two java actions written in Oozie workflow.xml. I want to pass output of my first java action to next java action for re-use.

I know this needs to be done using "oozie.action.output.properties". In the first action i am setting the output parameter "buildFileName" as shown below:

File file = new File(System.getProperty("oozie.action.output.properties"));
LOGGER.info("SystemGetProperty:" + System.getProperty("oozie.action.output.properties").toString());
Properties props = new Properties();
props.setProperty("buildFileName", buildFileName);
OutputStream os= new FileOutputStream(file);
props.store(os, "");
os.close();

But unfortunately, in the second action, i am not able to use the parameter value. The application job is getting successful, but the parameter value is coming null.

My first java action looks like :

<action name="java-action1">
    <java>
        <main-class>XYZ.MyJavaAction</main-class>
        <arg>Args</arg>
        <capture-output />
    </java>
<ok to="java-action2"/> 
<error to="fail"/> 

My second java action looks like :

<action name="java-action2">
    <java>
        <main-class>XYZ.MyJavaAction</main-class>
        <arg>{"outputFileName":"${wf:actionData('java-action1')['buildFileName']}"}</arg>
    </java>
<ok to="End"/> 
<error to="fail"/> 

Could anyone please help what i am missing here ?

A Google search on oozie capture_output java points straight to the Java Cookbook section "Capture-output element" , quoting:

  • In this example, we pass a the PASS_ME variable between the JAVA action and the PIG action.
  • The PASS_ME variable is given the value 123456 in the JAVA action ...
    The main() method writes a Property file to the path specified in the oozie.action.output.properties ENVIRONMENT variable ...
 Properties props = new Properties();
 props.setProperty("PASS_ME", "123456");
 File file = new File(System.getProperty("oozie.action.output.properties"));
 OutputStream os = new FileOutputStream(file);
 props.store(os, "");
 os.close();
  • The PIG action subsequently reads the value of the PASS_ME variable and passes it to the PIG script ...
    <param>MY_VAR=${wf:actionData('java1')['PASS_ME']}</param>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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