Search code examples
hadoopmapreduceworkflowoozie

How to get oozie jobId in oozie workflow?


I have a oozie workflow that will invoke a shell file, Shell file will further invoke a driver class of mapreduce job. Now i want to map my oozie jobId to Mapreduce jobId for later process. Is there any way to get oozie jobId in workflow file so that i can pass the same as argument to my driver class for mapping.

Following is my sample workflow.xml file

<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" />

Following is my shell script.

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

Solution

  • Try to use ${wf:id()}:

    String wf:id()

    It returns the workflow job ID for the current workflow job.

    More info here.