Sunday, March 3, 2013

Oozie Example: Java Action / MapReduce Jobs

Running a Java action through Oozie is very easy. But there are some things you need to consider before you run your Java action. In this tutorial, I'm going to execute a very simple Java action. I have a JAR file TestMR.jar which is a MapReduce application. So this application will be executed on the Hadoop cluster as a Map-Reduce job. 

TestMR.jar file has a class TestMR.java which has a public static void main method(String args[]) that initiates the whole application. To run a Java action, you need to pass the main Java class name through the tag <main-class>.

This is the workflow.xml file for a Java action with minimum number of parameters:

Your Java action has to be configured with <job-tracker> and <name-node>. And as you know, Hadoop will throw exceptions if the output folder is already exists. That's why I'm using <prepare> tag which will delete the output folder before execution. My jar also takes command line arguments. One of the argument is "-r 6" which means how many reducers I want to use for the MR job. So I'm using "<arg>" tag to pass command line arguments. You can have multiple <arg> for a single Java action. As like other actions, to indicate a "ok" transition, the main Java application needs to be completed without any error. If it throws any exception, the workflow will indicate a "error" transition.

Now comes to the folder structure inside HDFS. When Oozie executes any action, it automatically adds all JAR files and native libraries from the "/lib" folder to its classpath. Here, "/lib" folder is a sub-folder inside Oozie workflow application path. So, if "java-action" is the workflow application path then the structure would be:
- java-action
- java-action/workflow.xml
- java-action/lib

In my HDFS, I have:
And here is my job.properties file:
That's pretty much it! Now you can execute your workflow by:
Remember, this is a very basic and simple workflow to run a Java action through Oozie. You can do a lot more than these by using several other options provided by Oozie. Once you are able to run a simple workflow, I would recommend you to go through Oozie documentation and try some workflows with different settings.

Consideration: Be careful about what you have inside your "/lib" folder. If the version of the library which you are using for your application conflicts with Hadoop's library file's version, it will throw errors and those type of errors are hard to find. To avoid those kind of errors, better to match your library files with the versions you have inside "/usr/lib/[hadoop/hive/hbase/oozie]/lib" folder on your client node.


Note: For privacy purpose, I had to modify several lines on this post from my original post. So if you find something is not working or facing any issues, please do not hesitate to contact me.

40 comments:

  1. As a beginner, i really find your blog very useful thanks for sharing.

    Hadoop training velachery

    ReplyDelete
    Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. i got EJ001 error code with "could not locate sharelib. It is compulsory to use sharelib to run mapreduce job with oozie.

    ReplyDelete
    Replies
    1. Yes, you can install sharelib if you haven't yet. If you don't have sharelib, Oozie will not find all required libraries. Follow this link to know more about sharelib: http://blog.cloudera.com/blog/2012/12/how-to-use-the-sharelib-in-apache-oozie/

      Delete



  3. In the site was very excellent,i think this is very best one compare others and then the more information to get after read this post.


    HADOOP Training in Chennai

    ReplyDelete
  4. Hi,

    did you created the .jar file and uploaded to HDFS.? If so please let me know how did you created a jar file.

    ReplyDelete
  5. The information shared was very much useful my sincere thanks for sharing this post Please continue to share this post
    Hadoop Training in Chennai

    ReplyDelete
  6. This is really an amazing blog with smart and cute content..Thanks for sharing an informative article..
    BE Project Center in Chennai | ME Project Center in Chennai | MBA Project Center in Chennai | BBA Project Center in Chennai

    ReplyDelete
  7. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me…
    Java Training Center in Chennai | Best J2EE Training Center in Chennai | No.1 Java Training Institution in Velachery | Core Java Training in Chennai

    ReplyDelete
  8. Good one. The post is very simple and easily understood. Helpful for java beginners. Thanks for sharing and keep updating.
    Really awesome blog on iOS. Very interesting to read. Thanks for sharing.
    Final Year Project Center in Chennai | IEEE Project Center in Chennai |  Diploma Project Center in Chennai

    ReplyDelete
  9. Nice post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog updated.Thanks
    Best Photoshop Training Institute in Chennai | No.1 Adobe Photoshop Training Institute in Velachery

    ReplyDelete
  10. Nice post..Thanks for sharing your wonderful information. keep updating..
    mobile website builder

    ReplyDelete
  11. This is really an amazing blog with smart and cute content..Thanks for sharing an informative article..
    white label website builder

    mobile website builder

    ReplyDelete
  12. Thankfulness for truly being mindful and furthermore to decide on certain superb aides a great many people truly need to know about.Authorized Dot Net training in chennai

    ReplyDelete
  13. Great article,
    thank you very much for sharing this awesome post with us.
    Excellent Summer Courses in Guindy | Best Summer Classes in Chennai

    ReplyDelete
  14. In a recent test, of 126 jobs advertised as available in a large city, an employment organisation found that the actual number of jobs fulfilling the search criteria was 10! Online Jobs

    ReplyDelete
  15. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    datascience training in chennai

    ReplyDelete
  16. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..
    InDesign Certification Center in Chennai | No.1 InDesign Training in Keelkattalai

    ReplyDelete
  17. Nice and good blog to read.... really i gathered some information thanks for sharing.
    Python Certification Center in Chennai | No.1 Python Exams in Nanganallur

    ReplyDelete
  18. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me…

    AWS training in Chennai

    AWS Online Training in Chennai

    AWS training in Bangalore

    AWS training in Hyderabad

    AWS training in Coimbatore

    AWS training


    ReplyDelete
  19. Good Post! it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
    AngularJS Training in Pune

    ReplyDelete
  20. Достойный и проверенный поставщик всегда может показать невероятный сортамент кафельного покрытия для кухни. Фирма Сотни.ру реализует absolut keramika sajalin на протяжении пятнадцати лет.

    ReplyDelete
  21. It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .
    Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.
    Amazon Web Services Training in Chennai |
    AWS Training in Chennai |
    AWS certification course in Chennai |
    AWS course in Chennai


    ReplyDelete
  22. Looking a more unique post from your article.Great Article, very useful information, thank you !!
    Reactjs Training in Chennai |
    Best Reactjs Training Institute in Chennai |
    Reactjs course in Chennai |

    ReplyDelete