命令行方式
最常用的就是通過命令行方式提交,見YARN和HDFS的調用方式彙總中的“使用oozie提交yarn作業環節。
REST方式
使用REST的方式顯然更通用,當然原理與上述完全一致。
步驟1–創建工作空間目錄
首先在HDFS上創建相應工作空間目錄–/user/${user.name}/workspaces
,放置oozie要用到的workflow.xml,並創建lib文件夾,裏面放置打好的jar包,如下圖。注:我這裏的user.name變量的值是“hdfs”。
完整的workflow文件如下,裏面變量${inputDir}
、${outputDir}
等的值需要從下一步驟產生的config.xml文件中獲取。
特別注意:此處應該把原MR程序中所有的作業設置參數都拿過來,否則即使作業提交成功,結果也不正確!!!
<workflow-app name="test-wordcount" xmlns="uri:oozie:workflow:0.4">
<start to="test-wordcount"/>
<action name="test-wordcount">
<map-reduce>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapreduce.input.fileinputformat.inputdir</name>
<value>${inputDir}</value>
</property>
<property>
<name>mapreduce.output.fileoutputformat.outputdir</name>
<value>${outputDir}</value>
</property>
<property>
<name>mapreduce.job.map.class</name>
<value>wordcount.WordCount$TokenizerMapper</value>
</property>
<property>
<name>mapreduce.job.reduce.class</name>
<value>wordcount.WordCount$IntSumReducer</value>
</property>
<property>
<name>mapreduce.job.combine.class</name>
<value>wordcount.WordCount$IntSumReducer</value>
</property>
<property>
<name>mapreduce.job.output.key.class</name>
<value>org.apache.hadoop.io.Text</value>
</property>
<property>
<name>mapreduce.job.output.value.class</name>
<value>org.apache.hadoop.io.IntWritable</value>
</property>
<property>
<name>mapred.mapper.new-api</name>
<value>true</value>
</property>
<property>
<name>mapred.reducer.new-api</name>
<value>true</value>
</property>
<property>
<name>mapreduce.job.reduces</name>
<value>1</value>
</property>
</configuration>
</map-reduce>
<ok to="end"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
步驟2—新建配置文件
在本地新建配置文件config.xml,定義變量的值,內容如下,
<configuration>
<property>
<name>oozie.use.system.libpath</name>
<value>True</value>
</property>
<property>
<name>security_enabled</name>
<value>False</value>
</property>
<property>
<name>user.name</name>
<value>hdfs</value>
</property>
<property>
<name>oozie.wf.application.path</name>
<value>${nameNode}/user/${user.name}/workspaces</value>
</property>
<property>
<name>nameNode</name>
<value>hdfs://your-namenode:8020</value>
</property>
<property>
<name>jobTracker</name>
<value>your-jobtracker-server:8032</value>
</property>
<property>
<name>inputDir</name>
<value>${nameNode}/user/${user.name}/reviews_data.csv</value>
</property>
<property>
<name>outputDir</name>
<value>${nameNode}/user/${user.name}/output2</value>
</property>
</configuration>
步驟3—提交workflow
curl -X POST -H "Content-Type: application/xml" -d @config.xml "http://oozie-server:11000/oozie/v2/jobs?action=start"
在HUE中查看,