2015-10-13 109 views
1

我有一個將調用shell文件的oozie工作流,Shell文件將進一步調用mapreduce作業的驅動類。現在我想將我的oozie jobId映射到Mapreduce jobId以供以後使用。有沒有辦法在工作流文件中獲取oozie jobId,以便我可以將相同的參數傳遞給我的驅動程序類進行映射。如何在oozie工作流程中獲得oozie jobId?

以下是我的樣本workflow.xml文件

<workflow-app xmlns="uri:oozie:workflow:0.4" name="test"> 
<start to="start-test" /> 
<action name='start-test'> 
    <shell xmlns="uri:oozie:shell-action:0.2"> 
     <job-tracker>${jobTracker}</job-tracker> 
     <name-node>${nameNode}</name-node> 
     <configuration> 
      <property> 
       <name>mapred.job.queue.name</name> 
       <value>${queueName}</value> 
      </property> 
     </configuration> 
     <exec>${jobScript}</exec> 
     <argument>${fileLocation}</argument> 
     <argument>${nameNode}</argument> 
     <argument>${jobId}</argument> <!-- this is how i wanted to pass oozie jobId --> 
     <file>${jobScriptWithPath}#${jobScript}</file> 
    </shell> 
    <ok to="end" /> 
    <error to="kill" /> 
</action> 
<kill name="kill"> 
    <message>test job failed 
     failed:[${wf:errorMessage(wf:lastErrorNode())}]</message> 
</kill> 
<end name="end" /> 

以下是我的shell腳本。

hadoop jar testProject.jar testProject.MrDriver $1 $2 $3 

回答

4

嘗試使用${wf:id()}

字符串WF:ID()

它返回當前工作流任務工作流任務ID。

More info here.

+0

謝謝隊友。有用。 – Vijayakumar

1

Oozie的滴在運行shell(以下簡稱「發射器」容器)紗線容器的CWD一個XML文件,並設置一個環境變量指向的是XML (不記得名字雖然)

該XML包含很多內容,如工作流程名稱,操作名稱,兩者ID,運行嘗試編號等。 因此,您可以在shell腳本本身中將sed這些信息返回。

當然通過ID(如Alexei所建議的)會更清潔,但有時「乾淨」不是最好的方法。特別是如果你擔心它是否是第一次運行...