Executing Sqoops using Oozie

Rio picture Rio · Apr 1, 2014 · Viewed 11.9k times · Source

I have 2 Sqoops that loads data from HDFS to MySQL. I want to execute them using Oozie. I have seen that Oozie is an XML file. How can I configure it so I can execute those Sqoop? Demonstration with steps will be appreciated?

Two Sqoops are:

1.

sqoop export --connect jdbc:mysql://localhost/hduser --table foo1 -m 1 --export-dir /user/cloudera/bar1

2.

sqoop export --connect jdbc:mysql://localhost/hduser --table foo2 -m 1 --export-dir /user/cloudera/bar2

Thanks.

Answer

DMA picture DMA · Apr 2, 2014

You don't have to execute it via a shell action. There is a separate sqoop action in oozie. Here is what you have to put in your workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.4" name="oozie-wf">
    <start to="sqoop-wf1"/>
    <action name="sqoop-wf1">
        <sqoop xmlns="uri:oozie:sqoop-action:0.2">
                <job-tracker>${jobTracker}</job-tracker>
                <name-node>${nameNode}</name-node>
                <command>export --connect jdbc:mysql://localhost/hduser --table foo1 -m 1 --export-dir /user/cloudera/bar1</command>
        </sqoop>
        <ok to="sqoop-wf2"/>
        <error to="fail"/>
    </action> 
    <action name="sqoop-wf2">
        <sqoop xmlns="uri:oozie:sqoop-action:0.2">
                <job-tracker>${jobTracker}</job-tracker>
                <name-node>${nameNode}</name-node>
                <command>export --connect jdbc:mysql://localhost/hduser --table foo1 -m 1 --export-dir /user/cloudera/bar2</command>
        </sqoop>
        <ok to="end"/>
        <error to="fail"/>
    </action> 
    <kill name="fail">
        <message>Failed, Error Message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

Hope this helps..