Search code examples
shellhadoopapache-pigooziehue

Run script in response to error occurrence


Is there any way to run script (Pig, shell) in response to error occurrence? I mean: I create workflow in Oozie (Workflow Manager) and one of task fail and call error, and if this error occur i want to run specific script or another task. I want provide some kind of error handling:

  • When error1 occur - do something
  • When error2 occur - do somthing else

I will be gratefull for your help.


Solution

  • For Error handling you can use Decision nodes. For example:

    <action name="Action1">
        <map-reduce>
            <job-tracker>foo:9001</job-tracker>
            <name-node>bar:9000</name-node>
            <job-xml>job1.xml</job-xml>
        </map-reduce>
        <ok to="NextAction"/>
        <error to="ErrorhandlingDecision"/>
    </action>
    <decision name="ErrorhandlingDecision">
        <switch>
            <case to="CorrectError1Node">
              ${wf:errorCode("SourceActionNodeName") eq "JA018"}
            </case>
            <case to="CorrectError2Node">
              ${errorMessage(wf:lastErrorNode()) eq "Error Msg Received"}
            </case>
            <default to="NextAction"/>
        </switch>
    </decision>
    

    All you need to catch the Error code or error message.

    Note: Expression Lang (EL) support following operation

    one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||", "?"]

    Hope this help.