Search code examples
hadoopoozieoozie-coordinatorsqoop

global variable HADOOP_USER_NAME oozie?


is there any way that I can declare the HADOOP_USER_NAME as a global variable in a oozie workflow? actually I'm creating several shell actions for my project but it's not efficient to declare a HADOOP_USER_NAME for each shell action that's why I'm wondering if a global variable can take place in this scenario, if so, how can I proceed with it...

Your help is really appreciated.

This is the code I'm using

<workflow-app name="My_Workflow" xmlns="uri:oozie:workflow:0.5">
  <global>
        <configuration>
            <property>
                <name>HADOOP_USER_NAME</name>
                <value>*****</value>
            </property>
        </configuration>
  </global>
<start to="shell-a0a5"/>
<kill name="Kill">
    <message>Error [${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<action name="shell-a0a5">
    <shell xmlns="uri:oozie:shell-action:0.1">
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <exec>script1.sh</exec>
        <file>script1.sh#script1.sh</file>
    </shell>
    <ok to="End"/>
    <error to="Kill"/>
</action>
<end name="End"/>

for some reason I'm not getting the value from HADOOP_USER_NAME perhaps I'm doing it wrong, I had to write it down into the shell file as export HADOOP_USER_NAME=****;


Solution

  • You can pass a <property> to any kind of Oozie action that is running a Java utility -- but not to a shell action.

    In your specific case, you can declare an <env-var> locally in each shell action, and you can define the actual value of that variable globally...

    • in the <parameter> section of the workflow
    • or in the configuration file at submit time

      <workflow-app name='hello-wf' xmlns="uri:oozie:workflow:0.4">
        <parameters>
          <property>
            <name>hadoopUser</name>
            <value>biloute</value>
          </property>
        </parameters>
      ...
        <action name='some-shell'>
          <shell xmlns="uri:oozie:shell-action:0.1">>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>script1.sh</exec>
            <env-var>HADOOP_USER=NAME=${hadoopUser}</env-var>
            <file>script1.sh#script1.sh</file>
          </shell>
          <ok to="End"/>
          <error to="Kill"/>
        </action>
      ...