Apache Oozie like bunch of other first generation Hadoop component uses ungodly amount of XML for configuration. There is a project from Cloudera called Hue to ease some of the pain in creating Oozie workflows but if you cannot use a UI for creating workflows for version control and various other reasons you may need a different solution to avoid XML hell. In this blog post we will create a simple Oozie workflow without using a single line of XML and compare it to traditional approach of creating flows in Oozie.
The example below is taken from 'Introduction to Oozie' by Boris Lublinsky, Michael Segel. Lets say that you have two Map/Reduce jobs - one that is doing initial ingestion of the data and the second one merging data of the given type. The actual ingestion needs to execute initial ingestion and then merge data for two of the types - Lidar and Multicam. To automate this process we have created a simple Oozie Workflow (See the article by Boris Lublinsky, Michael Segel for the workflow in all its XML glory). Lets take a stab at creating the same workflow without using any XML. We will be using Gradle and gradle-oozie-plugin to create our workflow. This is how our flow will look like using Groovy dsl
oozie { def common_props = [ jobTracker: '${jobTracker}', namenode: '${nameNode}', configuration: ["mapred.job.queue.name": "default"] ] def ingestor = [ name: "ingestor", type: "java", mainClass: "com.navteq.assetmgmt.MapReduce.ips.IPSLoader", ok: "merging", error: "fail", args: ['${driveID}'], ] def merging = [ name: "merging", type: "fork", paths: [ "mergeLidar", "mergeSignage" ] ] def mergeLidar = [ name: "mergeLidar", type: "java", mainClass: "com.navteq.assetmgmt.hdfs.merge.MergerLoader", ok: "completed", error: "fail", args: ['-drive', '${driveID}', '-type', 'Lidar', '-chunk', '${lidarChunk}' ], javaOpts: "-Xmx2048m" ] def mergeSignage = [ name: "mergeSignage", type: "java", mainClass: "com.navteq.assetmgmt.hdfs.merge.MergerLoader", ok: "completed", error: "fail", args: ['-drive', '${driveID}', '-type', 'Lidar', '-chunk', '${signageChunk}' ], javaOpts: "-Xmx2048m" ] def completed = [ name: "completed", type: "join", to: "end" ] def fail = [ name: "fail", type: "kill", message: "Java failed, error message[\${wf:errorMessage(wf:lastErrorNode())}]" ] actions = [ ingestor, merging, mergeLidar, mergeSignage, completed, fail] common = common_props start = "ingestor" end = "end" name = 'oozie_flow' namespace = 'uri:oozie:workflow:0.1' outputDir = file("$projectDir/workflow2") }
once we have the flow created, we can generated the XML flow by running 'gradle oozieWorkflow'. This approach is a lot cleaner as Groovy not only removes a lot of boilerplate XML but also because we can define all the common properties in one location instead of repeating them in all nodes. Here is the the complete build.gradle file and generated workflow. Hopefully this approach will reduce some pain in working with Apache Oozie.
No comments:
Post a Comment