步驟描述
- workflow xml 配置
- java 代碼輸出
workflow xml 配置
備註: 必須添加 <capture-output/>
<workflow-app xmlns='uri:oozie:workflow:0.1' name='java-wf'>
<start to='java1' />
<action name='java1'>
<java>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<main-class>org.apache.oozie.test.MyTest</main-class>
<arg>${outputFileName}</arg>
<capture-output/>
</java>
<ok to="hive2" />
<error to="fail" />
</action>
<action name="hive2" cred="hive2">
<hive2 xmlns="uri:oozie:hive2-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<jdbc-url>${hiveServer2Uri}/${db}</jdbc-url>
<password>${password}</password>
<script>rinse.sql</script>
<param>rinse=${wf:actionData("java-1")["PASS_ME"]}</param>
</hive2>
<ok to="End"/>
<error to="Kill"/>
</action>
<kill name="fail">
<message>Hive2 failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name='end' />
</workflow-app>
Java 代碼輸出
備註: The main() method writes a Property file to the path specified in the 'oozie.action.output.properties' ENVIRONMENT variable.
package org.apache.oozie.test;
import java.io.*;
import java.util.Properties;
public class MyTest {
////////////////////////////////
// Do whatever you want in here
////////////////////////////////
public static void main (String[] args)
{
String fileName = args[0];
try{
File file = new File(System.getProperty("oozie.action.output.properties"));
Properties props = new Properties();
props.setProperty("PASS_ME", "123456");
OutputStream os = new FileOutputStream(file);
props.store(os, "");
os.close();
System.out.println(file.getAbsolutePath());
}
catch (Exception e) {
e.printStackTrace();
}
}
}