You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2013/04/11 17:40:48 UTC

svn commit: r1466926 [1/3] - in /oozie/trunk: ./ core/ core/src/main/java/org/apache/oozie/action/hadoop/ core/src/test/java/org/apache/oozie/action/hadoop/ sharelib/distcp/ sharelib/distcp/src/ sharelib/distcp/src/test/ sharelib/distcp/src/test/java/ ...

Author: rkanter
Date: Thu Apr 11 15:40:45 2013
New Revision: 1466926

URL: http://svn.apache.org/r1466926
Log:
OOZIE-1311 Refactor action Main classes into sharelibs (rkanter)

Added:
    oozie/trunk/sharelib/distcp/src/
    oozie/trunk/sharelib/distcp/src/test/
    oozie/trunk/sharelib/distcp/src/test/java/
    oozie/trunk/sharelib/distcp/src/test/java/org/
    oozie/trunk/sharelib/distcp/src/test/java/org/apache/
    oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/
    oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/
    oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java
    oozie/trunk/sharelib/hive/src/
    oozie/trunk/sharelib/hive/src/main/
    oozie/trunk/sharelib/hive/src/main/java/
    oozie/trunk/sharelib/hive/src/main/java/org/
    oozie/trunk/sharelib/hive/src/main/java/org/apache/
    oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/
    oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/
    oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java
    oozie/trunk/sharelib/hive/src/test/
    oozie/trunk/sharelib/hive/src/test/java/
    oozie/trunk/sharelib/hive/src/test/java/org/
    oozie/trunk/sharelib/hive/src/test/java/org/apache/
    oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/
    oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/
    oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java
    oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java
    oozie/trunk/sharelib/pig/src/
    oozie/trunk/sharelib/pig/src/main/
    oozie/trunk/sharelib/pig/src/main/java/
    oozie/trunk/sharelib/pig/src/main/java/org/
    oozie/trunk/sharelib/pig/src/main/java/org/apache/
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/PigMain.java
    oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/PigMainWithOldAPI.java
    oozie/trunk/sharelib/pig/src/test/
    oozie/trunk/sharelib/pig/src/test/java/
    oozie/trunk/sharelib/pig/src/test/java/org/
    oozie/trunk/sharelib/pig/src/test/java/org/apache/
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java
    oozie/trunk/sharelib/pig/src/test/java/org/apache/oozie/action/hadoop/UDFTester.java
    oozie/trunk/sharelib/sqoop/src/
    oozie/trunk/sharelib/sqoop/src/main/
    oozie/trunk/sharelib/sqoop/src/main/java/
    oozie/trunk/sharelib/sqoop/src/main/java/org/
    oozie/trunk/sharelib/sqoop/src/main/java/org/apache/
    oozie/trunk/sharelib/sqoop/src/main/java/org/apache/oozie/
    oozie/trunk/sharelib/sqoop/src/main/java/org/apache/oozie/action/
    oozie/trunk/sharelib/sqoop/src/main/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/sqoop/src/main/java/org/apache/oozie/action/hadoop/SqoopMain.java
    oozie/trunk/sharelib/sqoop/src/test/
    oozie/trunk/sharelib/sqoop/src/test/java/
    oozie/trunk/sharelib/sqoop/src/test/java/org/
    oozie/trunk/sharelib/sqoop/src/test/java/org/apache/
    oozie/trunk/sharelib/sqoop/src/test/java/org/apache/oozie/
    oozie/trunk/sharelib/sqoop/src/test/java/org/apache/oozie/action/
    oozie/trunk/sharelib/sqoop/src/test/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/sqoop/src/test/java/org/apache/oozie/action/hadoop/TestSqoopActionExecutor.java
    oozie/trunk/sharelib/streaming/src/
    oozie/trunk/sharelib/streaming/src/main/
    oozie/trunk/sharelib/streaming/src/main/java/
    oozie/trunk/sharelib/streaming/src/main/java/org/
    oozie/trunk/sharelib/streaming/src/main/java/org/apache/
    oozie/trunk/sharelib/streaming/src/main/java/org/apache/oozie/
    oozie/trunk/sharelib/streaming/src/main/java/org/apache/oozie/action/
    oozie/trunk/sharelib/streaming/src/main/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/streaming/src/main/java/org/apache/oozie/action/hadoop/StreamingMain.java
    oozie/trunk/sharelib/streaming/src/test/
    oozie/trunk/sharelib/streaming/src/test/java/
    oozie/trunk/sharelib/streaming/src/test/java/org/
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/oozie/
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/oozie/action/
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/oozie/action/hadoop/
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorStreaming.java
    oozie/trunk/sharelib/streaming/src/test/java/org/apache/oozie/action/hadoop/TestStreamingMain.java
Removed:
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMain.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigMainWithOldAPI.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopMain.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/StreamingMain.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/PigTestCase.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestSqoopActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestStreamingMain.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/UDFTester.java
    oozie/trunk/tests/pig/pom.xml
    oozie/trunk/tests/pig/src/test/java/org/apache/oozie/action/hadoop/TestPigActionExecutor.java
    oozie/trunk/tests/pig/src/test/java/org/apache/oozie/action/hadoop/TestPigMain.java
    oozie/trunk/tests/pom.xml
Modified:
    oozie/trunk/core/pom.xml
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveActionExecutor.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/MapReduceActionExecutor.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java
    oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionError.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorUberJar.java
    oozie/trunk/pom.xml
    oozie/trunk/release-log.txt
    oozie/trunk/sharelib/distcp/pom.xml
    oozie/trunk/sharelib/hive/pom.xml
    oozie/trunk/sharelib/pig/pom.xml
    oozie/trunk/sharelib/sqoop/pom.xml
    oozie/trunk/sharelib/streaming/pom.xml
    oozie/trunk/src/main/assemblies/partial-sharelib.xml

Modified: oozie/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/core/pom.xml?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/pom.xml (original)
+++ oozie/trunk/core/pom.xml Thu Apr 11 15:40:45 2013
@@ -236,71 +236,6 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.pig</groupId>
-            <artifactId>pig</artifactId>
-            <version>0.8.0</version>
-            <scope>provided</scope>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.apache.hadoop</groupId>
-                    <artifactId>hadoop-core</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>commons-httpclient</groupId>
-                    <artifactId>commons-httpclient</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.mortbay.jetty</groupId>
-                    <artifactId>jetty</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.mortbay.jetty</groupId>
-                    <artifactId>jetty-util</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.mortbay.jetty</groupId>
-                    <artifactId>servlet-api-2.5</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.mortbay.jetty</groupId>
-                    <artifactId>jsp-api-2.1</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.mortbay.jetty</groupId>
-                    <artifactId>jsp-2.1</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>commons-el</groupId>
-                    <artifactId>commons-el</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>tomcat</groupId>
-                    <artifactId>jasper-compiler</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>tomcat</groupId>
-                    <artifactId>jasper-runtime</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>junit</groupId>
-                    <artifactId>junit</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>net.sf.kosmosfs</groupId>
-                    <artifactId>kfs</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>net.java.dev.jets3t</groupId>
-                    <artifactId>jets3t</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>oro</groupId>
-                    <artifactId>oro</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-
-        <dependency>
             <groupId>org.antlr</groupId>
             <artifactId>antlr-runtime</artifactId>
             <version>3.0.1</version>
@@ -309,46 +244,6 @@
 
         <dependency>
             <groupId>org.apache.oozie</groupId>
-            <artifactId>oozie-sharelib-pig</artifactId>
-            <scope>provided</scope>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.apache.pig</groupId>
-                    <artifactId>pig</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.antlr</groupId>
-                    <artifactId>antlr-runtime</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.oozie</groupId>
-            <artifactId>oozie-sharelib-streaming</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.oozie</groupId>
-            <artifactId>oozie-sharelib-distcp</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.oozie</groupId>
-            <artifactId>oozie-sharelib-hive</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.oozie</groupId>
-            <artifactId>oozie-sharelib-sqoop</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.oozie</groupId>
             <artifactId>oozie-sharelib-oozie</artifactId>
             <scope>provided</scope>
         </dependency>

Modified: oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveActionExecutor.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveActionExecutor.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/HiveActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -32,20 +32,17 @@ import org.jdom.Namespace;
 
 public class HiveActionExecutor extends ScriptLanguageActionExecutor {
 
+    private static final String HIVE_MAIN_CLASS_NAME = "org.apache.oozie.action.hadoop.HiveMain";
+    static final String HIVE_SCRIPT = "oozie.hive.script";
+    static final String HIVE_PARAMS = "oozie.hive.params";
+
     public HiveActionExecutor() {
         super("hive");
     }
 
     @Override
-    protected List<Class> getLauncherClasses() {
-        List<Class> classes = super.getLauncherClasses();
-        classes.add(HiveMain.class);
-        return classes;
-    }
-
-    @Override
     protected String getLauncherMain(Configuration launcherConf, Element actionXml) {
-        return launcherConf.get(CONF_OOZIE_ACTION_MAIN_CLASS, HiveMain.class.getName());
+        return launcherConf.get(CONF_OOZIE_ACTION_MAIN_CLASS, HIVE_MAIN_CLASS_NAME);
     }
 
     @Override
@@ -69,10 +66,15 @@ public class HiveActionExecutor extends 
             strParams[i] = params.get(i).getTextTrim();
         }
 
-        HiveMain.setHiveScript(conf, scriptName, strParams);
+        setHiveScript(conf, scriptName, strParams);
         return conf;
     }
 
+    public static void setHiveScript(Configuration conf, String script, String[] params) {
+        conf.set(HIVE_SCRIPT, script);
+        MapReduceMain.setStrings(conf, HIVE_PARAMS, params);
+    }
+
     @Override
     protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException {
         return true;

Modified: oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/MapReduceActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/MapReduceActionExecutor.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/MapReduceActionExecutor.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/MapReduceActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -45,6 +45,7 @@ public class MapReduceActionExecutor ext
     public static final String HADOOP_COUNTERS = "hadoop.counters";
     public static final String OOZIE_MAPREDUCE_UBER_JAR = "oozie.mapreduce.uber.jar";
     public static final String OOZIE_MAPREDUCE_UBER_JAR_ENABLE = "oozie.action.mapreduce.uber.jar.enable";
+    private static final String STREAMING_MAIN_CLASS_NAME = "org.apache.oozie.action.hadoop.StreamingMain";
     private XLog log = XLog.getLog(getClass());
 
     public MapReduceActionExecutor() {
@@ -56,7 +57,6 @@ public class MapReduceActionExecutor ext
         List<Class> classes = super.getLauncherClasses();
         classes.add(LauncherMain.class);
         classes.add(MapReduceMain.class);
-        classes.add(StreamingMain.class);
         classes.add(PipesMain.class);
         return classes;
     }
@@ -66,7 +66,7 @@ public class MapReduceActionExecutor ext
         String mainClass;
         Namespace ns = actionXml.getNamespace();
         if (actionXml.getChild("streaming", ns) != null) {
-            mainClass = launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, StreamingMain.class.getName());
+            mainClass = launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, STREAMING_MAIN_CLASS_NAME);
         }
         else {
             if (actionXml.getChild("pipes", ns) != null) {
@@ -107,7 +107,7 @@ public class MapReduceActionExecutor ext
             for (int i = 0; i < list.size(); i++) {
                 env[i] = list.get(i).getTextTrim();
             }
-            StreamingMain.setStreaming(actionConf, mapper, reducer, recordReader, recordReaderMapping, env);
+            setStreaming(actionConf, mapper, reducer, recordReader, recordReaderMapping, env);
         }
         else {
             if (actionXml.getChild("pipes", ns) != null) {
@@ -292,4 +292,20 @@ public class MapReduceActionExecutor ext
         }
         return launcherJobConf;
     }
+
+    public static void setStreaming(Configuration conf, String mapper, String reducer, String recordReader,
+                                    String[] recordReaderMapping, String[] env) {
+        if (mapper != null) {
+            conf.set("oozie.streaming.mapper", mapper);
+        }
+        if (reducer != null) {
+            conf.set("oozie.streaming.reducer", reducer);
+        }
+        if (recordReader != null) {
+            conf.set("oozie.streaming.record-reader", recordReader);
+        }
+        MapReduceMain.setStrings(conf, "oozie.streaming.record-reader-mapping", recordReaderMapping);
+        MapReduceMain.setStrings(conf, "oozie.streaming.env", env);
+    }
+
 }

Modified: oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/PigActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -40,22 +40,18 @@ import java.util.List;
 
 public class PigActionExecutor extends ScriptLanguageActionExecutor {
 
+    private static final String PIG_MAIN_CLASS_NAME = "org.apache.oozie.action.hadoop.PigMain";
+    static final String PIG_SCRIPT = "oozie.pig.script";
+    static final String PIG_PARAMS = "oozie.pig.params";
+    static final String PIG_ARGS = "oozie.pig.args";
+
     public PigActionExecutor() {
         super("pig");
     }
 
     @Override
-    protected List<Class> getLauncherClasses() {
-        List<Class> classes = super.getLauncherClasses();
-        classes.add(PigMain.class);
-        classes.add(OoziePigStats.class);
-        return classes;
-    }
-
-
-    @Override
     protected String getLauncherMain(Configuration launcherConf, Element actionXml) {
-        return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, PigMain.class.getName());
+        return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, PIG_MAIN_CLASS_NAME);
     }
 
     @Override
@@ -85,10 +81,17 @@ public class PigActionExecutor extends S
                 strArgs[i] = eArgs.get(i).getTextTrim();
             }
         }
-        PigMain.setPigScript(actionConf, pigName, strParams, strArgs);
+        setPigScript(actionConf, pigName, strParams, strArgs);
         return actionConf;
     }
 
+    public static void setPigScript(Configuration conf, String script, String[] params, String[] args) {
+        conf.set(PIG_SCRIPT, script);
+        MapReduceMain.setStrings(conf, PIG_PARAMS, params);
+        MapReduceMain.setStrings(conf, PIG_ARGS, args);
+    }
+
+
     @Override
     protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException {
         return false;

Modified: oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopActionExecutor.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopActionExecutor.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/action/hadoop/SqoopActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -46,6 +46,8 @@ import org.jdom.Namespace;
 public class SqoopActionExecutor extends JavaActionExecutor {
 
   public static final String OOZIE_ACTION_EXTERNAL_STATS_WRITE = "oozie.action.external.stats.write";
+  private static final String SQOOP_MAIN_CLASS_NAME = "org.apache.oozie.action.hadoop.SqoopMain";
+  static final String SQOOP_ARGS = "oozie.sqoop.args";
 
     public SqoopActionExecutor() {
         super("sqoop");
@@ -56,14 +58,12 @@ public class SqoopActionExecutor extends
         List<Class> classes = super.getLauncherClasses();
         classes.add(LauncherMain.class);
         classes.add(MapReduceMain.class);
-        classes.add(HiveMain.class);
-        classes.add(SqoopMain.class);
         return classes;
     }
 
     @Override
     protected String getLauncherMain(Configuration launcherConf, Element actionXml) {
-        return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, SqoopMain.class.getName());
+        return launcherConf.get(LauncherMapper.CONF_OOZIE_ACTION_MAIN_CLASS, SQOOP_MAIN_CLASS_NAME);
     }
 
     @Override
@@ -103,10 +103,14 @@ public class SqoopActionExecutor extends
             }
         }
 
-        SqoopMain.setSqoopCommand(actionConf, args);
+        setSqoopCommand(actionConf, args);
         return actionConf;
     }
 
+    private void setSqoopCommand(Configuration conf, String[] args) {
+        MapReduceMain.setStrings(conf, SQOOP_ARGS, args);
+    }
+
     /**
      * We will gather counters from all executed action Hadoop jobs (e.g. jobs
      * that moved data, not the launcher itself) and merge them together. There

Modified: oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionError.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionError.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionError.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionError.java Thu Apr 11 15:40:45 2013
@@ -78,7 +78,6 @@ public class TestMapReduceActionError ex
         classes.add(ActionType.class);
         classes.add(LauncherMain.class);
         classes.add(MapReduceMain.class);
-        classes.add(StreamingMain.class);
         classes.add(PipesMain.class);
         assertEquals(classes, ae.getLauncherClasses());
 

Modified: oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutor.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutor.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -25,7 +25,6 @@ import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.RunningJob;
 import org.apache.hadoop.mapred.JobID;
-import org.apache.hadoop.streaming.StreamJob;
 import org.apache.oozie.WorkflowActionBean;
 import org.apache.oozie.WorkflowJobBean;
 import org.apache.oozie.client.WorkflowAction;
@@ -97,7 +96,6 @@ public class TestMapReduceActionExecutor
         classes.add(ActionType.class);
         classes.add(LauncherMain.class);
         classes.add(MapReduceMain.class);
-        classes.add(StreamingMain.class);
         classes.add(PipesMain.class);
         assertEquals(classes, ae.getLauncherClasses());
 
@@ -301,7 +299,7 @@ public class TestMapReduceActionExecutor
         return runningJob;
     }
 
-    private String _testSubmit(String name, String actionXml) throws Exception {
+    protected String _testSubmit(String name, String actionXml) throws Exception {
 
         Context context = createContext(name, actionXml);
         final RunningJob launcherJob = submitAction(context);
@@ -569,37 +567,6 @@ public class TestMapReduceActionExecutor
         }
     }
 
-    protected XConfiguration getStreamingConfig(String inputDir, String outputDir) {
-        XConfiguration conf = new XConfiguration();
-        conf.set("mapred.input.dir", inputDir);
-        conf.set("mapred.output.dir", outputDir);
-        return conf;
-    }
-
-    public void testStreaming() throws Exception {
-        FileSystem fs = getFileSystem();
-        Path streamingJar = new Path(getFsTestCaseDir(), "jar/hadoop-streaming.jar");
-
-        InputStream is = new FileInputStream(ClassUtils.findContainingJar(StreamJob.class));
-        OutputStream os = fs.create(new Path(getAppPath(), streamingJar));
-        IOUtils.copyStream(is, os);
-
-        Path inputDir = new Path(getFsTestCaseDir(), "input");
-        Path outputDir = new Path(getFsTestCaseDir(), "output");
-
-        Writer w = new OutputStreamWriter(fs.create(new Path(inputDir, "data.txt")));
-        w.write("dummy\n");
-        w.write("dummy\n");
-        w.close();
-
-        String actionXml = "<map-reduce>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>"
-                + getNameNodeUri() + "</name-node>" + "      <streaming>" + "        <mapper>cat</mapper>"
-                + "        <reducer>wc</reducer>" + "      </streaming>"
-                + getStreamingConfig(inputDir.toString(), outputDir.toString()).toXmlString(false) + "<file>"
-                + streamingJar + "</file>" + "</map-reduce>";
-        _testSubmit("streaming", actionXml);
-    }
-
     protected XConfiguration getPipesConfig(String inputDir, String outputDir) {
         XConfiguration conf = new XConfiguration();
         conf.setBoolean("hadoop.pipes.java.recordreader", true);

Modified: oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorUberJar.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorUberJar.java?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorUberJar.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/action/hadoop/TestMapReduceActionExecutorUberJar.java Thu Apr 11 15:40:45 2013
@@ -76,11 +76,6 @@ public class TestMapReduceActionExecutor
     }
 
     @Override
-    public void testStreaming() throws Exception {
-        // skip test
-    }
-
-    @Override
     public void testPipes() throws Exception {
         // skip test
     }

Modified: oozie/trunk/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/pom.xml?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/pom.xml (original)
+++ oozie/trunk/pom.xml Thu Apr 11 15:40:45 2013
@@ -98,7 +98,6 @@
         <module>hbaselibs</module>
         <module>hcataloglibs</module>
         <module>core</module>
-        <module>tests</module>
         <module>webapp</module>
         <module>examples</module>
         <module>docs</module>

Modified: oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Thu Apr 11 15:40:45 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1311 Refactor action Main classes into sharelibs (rkanter)
 OOZIE-897 remove special build handling for sqoop testcase (rkanter)
 OOZIE-1209 Event generation and handling for workflow and coordinator (mona)
 OOZIE-1118 improve logic of purge service (rkanter)

Modified: oozie/trunk/sharelib/distcp/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/distcp/pom.xml?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/sharelib/distcp/pom.xml (original)
+++ oozie/trunk/sharelib/distcp/pom.xml Thu Apr 11 15:40:45 2013
@@ -43,6 +43,37 @@
             <artifactId>oozie-hadoop-distcp</artifactId>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hcatalog</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Added: oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java?rev=1466926&view=auto
==============================================================================
--- oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java (added)
+++ oozie/trunk/sharelib/distcp/src/test/java/org/apache/oozie/action/hadoop/TestDistCpActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -0,0 +1,150 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.JobID;
+import org.apache.hadoop.mapred.RunningJob;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.service.HadoopAccessorService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.service.WorkflowAppService;
+import org.apache.oozie.util.IOUtils;
+import org.apache.oozie.util.XConfiguration;
+
+public class TestDistCpActionExecutor extends ActionExecutorTestCase{
+
+    @Override
+    protected void setSystemProps() throws Exception {
+        super.setSystemProps();
+        setSystemProperty("oozie.service.ActionService.executor.classes", DistcpActionExecutor.class.getName());
+    }
+
+    public void testDistCpFile() throws Exception {
+        Path inputPath = new Path(getFsTestCaseDir(), "input.txt");
+        final Path outputPath = new Path(getFsTestCaseDir(), "output.txt");
+        byte[] content = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes();
+
+        OutputStream os = getFileSystem().create(inputPath);
+        os.write(content);
+        os.close();
+
+        String actionXml = "<distcp>" +
+                "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" +
+                "<name-node>" + getNameNodeUri() + "</name-node>" +
+                "<arg>" + inputPath + "</arg>"+
+                "<arg>" + outputPath + "</arg>" +
+                "</distcp>";
+        Context context = createContext(actionXml);
+        final RunningJob runningJob = submitAction(context);
+        waitFor(60 * 1000, new Predicate() {
+            public boolean evaluate() throws Exception {
+                return runningJob.isComplete();
+            }
+        });
+        assertTrue(runningJob.isSuccessful());
+
+        waitFor(60 * 1000, new Predicate() {
+            public boolean evaluate() throws Exception {
+                return getFileSystem().exists(outputPath);
+            }
+        });
+        assertTrue(getFileSystem().exists(outputPath));
+
+        byte[] readContent = new byte[content.length];
+        InputStream is = getFileSystem().open(outputPath);
+        int offset = 0;
+        while (offset < readContent.length)
+        {
+            int numRead = is.read(readContent, offset, readContent.length);
+            if(numRead == -1) {
+                break;
+            }
+            offset += numRead;
+        }
+        assertEquals(is.read(), -1);
+        is.close();
+        offset = 0;
+        while (offset < readContent.length)
+        {
+            assertEquals(readContent[offset], content[offset]);
+            offset++;
+        }
+    }
+
+
+    protected Context createContext(String actionXml) throws Exception {
+        DistcpActionExecutor ae = new DistcpActionExecutor();
+
+        Path appJarPath = new Path("lib/test.jar");
+        File jarFile = IOUtils.createJar(new File(getTestCaseDir()), "test.jar", LauncherMainTester.class);
+        InputStream is = new FileInputStream(jarFile);
+        OutputStream os = getFileSystem().create(new Path(getAppPath(), "lib/test.jar"));
+        IOUtils.copyStream(is, os);
+
+        Path appSoPath = new Path("lib/test.so");
+        getFileSystem().create(new Path(getAppPath(), appSoPath)).close();
+
+        XConfiguration protoConf = new XConfiguration();
+        protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
+        protoConf.setStrings(WorkflowAppService.APP_LIB_PATH_LIST, appJarPath.toString(), appSoPath.toString());
+
+
+        WorkflowJobBean wf = createBaseWorkflow(protoConf, "action");
+        WorkflowActionBean action = (WorkflowActionBean) wf.getActions().get(0);
+        action.setType(ae.getType());
+        action.setConf(actionXml);
+
+        return new Context(wf, action);
+    }
+
+
+    protected RunningJob submitAction(Context context) throws Exception {
+        DistcpActionExecutor ae = new DistcpActionExecutor();
+
+        WorkflowAction action = context.getAction();
+
+        ae.prepareActionDir(getFileSystem(), context);
+        ae.submitLauncher(getFileSystem(), context, action);
+
+        String jobId = action.getExternalId();
+        String jobTracker = action.getTrackerUri();
+        String consoleUrl = action.getConsoleUrl();
+        assertNotNull(jobId);
+        assertNotNull(jobTracker);
+        assertNotNull(consoleUrl);
+
+        JobConf jobConf = Services.get().get(HadoopAccessorService.class).createJobConf(jobTracker);
+        jobConf.set("mapred.job.tracker", jobTracker);
+
+        JobClient jobClient =
+            Services.get().get(HadoopAccessorService.class).createJobClient(getTestUser(), jobConf);
+        final RunningJob runningJob = jobClient.getJob(JobID.forName(jobId));
+        assertNotNull(runningJob);
+        return runningJob;
+    }
+}

Modified: oozie/trunk/sharelib/hive/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/hive/pom.xml?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/sharelib/hive/pom.xml (original)
+++ oozie/trunk/sharelib/hive/pom.xml Thu Apr 11 15:40:45 2013
@@ -111,6 +111,42 @@
             <version>3.0.1</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hcatalog</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <build>

Added: oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java?rev=1466926&view=auto
==============================================================================
--- oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java (added)
+++ oozie/trunk/sharelib/hive/src/main/java/org/apache/oozie/action/hadoop/HiveMain.java Thu Apr 11 15:40:45 2013
@@ -0,0 +1,280 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.cli.CliDriver;
+
+public class HiveMain extends LauncherMain {
+    private static final Pattern[] HIVE_JOB_IDS_PATTERNS = {
+      Pattern.compile("Ended Job = (job_\\S*)")
+    };
+
+    public static final String HIVE_L4J_PROPS = "hive-log4j.properties";
+    public static final String HIVE_EXEC_L4J_PROPS = "hive-exec-log4j.properties";
+    public static final String HIVE_SITE_CONF = "hive-site.xml";
+
+    public static void main(String[] args) throws Exception {
+        run(HiveMain.class, args);
+    }
+
+    private static Configuration initActionConf() {
+        // Loading action conf prepared by Oozie
+        Configuration hiveConf = new Configuration(false);
+
+        String actionXml = System.getProperty("oozie.action.conf.xml");
+
+        if (actionXml == null) {
+            throw new RuntimeException("Missing Java System Property [oozie.action.conf.xml]");
+        }
+        if (!new File(actionXml).exists()) {
+            throw new RuntimeException("Action Configuration XML file [" + actionXml + "] does not exist");
+        } else {
+            System.out.println("Using action configuration file " + actionXml);
+        }
+
+        hiveConf.addResource(new Path("file:///", actionXml));
+
+        // Propagate delegation related props from launcher job to Hive job
+        String delegationToken = System.getenv("HADOOP_TOKEN_FILE_LOCATION");
+        if (delegationToken != null) {
+            hiveConf.set("mapreduce.job.credentials.binary", delegationToken);
+            System.out.println("------------------------");
+            System.out.println("Setting env property for mapreduce.job.credentials.binary to: " + delegationToken);
+            System.out.println("------------------------");
+            System.setProperty("mapreduce.job.credentials.binary", delegationToken);
+        } else {
+            System.out.println("Non-Kerberos execution");
+        }
+
+        // Have to explicitly unset this property or Hive will not set it.
+        hiveConf.set("mapred.job.name", "");
+
+        // See https://issues.apache.org/jira/browse/HIVE-1411
+        hiveConf.set("datanucleus.plugin.pluginRegistryBundleCheck", "LOG");
+
+        // to force hive to use the jobclient to submit the job, never using HADOOPBIN (to do localmode)
+        hiveConf.setBoolean("hive.exec.mode.local.auto", false);
+
+        return hiveConf;
+    }
+
+    public static String setUpHiveLog4J(Configuration hiveConf) throws IOException {
+        //Logfile to capture job IDs
+        String hadoopJobId = System.getProperty("oozie.launcher.job.id");
+        if (hadoopJobId == null) {
+            throw new RuntimeException("Launcher Hadoop Job ID system property not set");
+        }
+
+        String logFile = new File("hive-oozie-" + hadoopJobId + ".log").getAbsolutePath();
+
+        Properties hadoopProps = new Properties();
+
+        // Preparing log4j configuration
+        URL log4jFile = Thread.currentThread().getContextClassLoader().getResource("log4j.properties");
+        if (log4jFile != null) {
+            // getting hadoop log4j configuration
+            hadoopProps.load(log4jFile.openStream());
+        }
+
+        String logLevel = hiveConf.get("oozie.hive.log.level", "INFO");
+
+        hadoopProps.setProperty("log4j.logger.org.apache.hadoop.hive", logLevel + ", A");
+        hadoopProps.setProperty("log4j.logger.hive", logLevel + ", A");
+        hadoopProps.setProperty("log4j.logger.DataNucleus", logLevel + ", A");
+        hadoopProps.setProperty("log4j.logger.DataStore", logLevel + ", A");
+        hadoopProps.setProperty("log4j.logger.JPOX", logLevel + ", A");
+        hadoopProps.setProperty("log4j.appender.A", "org.apache.log4j.ConsoleAppender");
+        hadoopProps.setProperty("log4j.appender.A.layout", "org.apache.log4j.PatternLayout");
+        hadoopProps.setProperty("log4j.appender.A.layout.ConversionPattern", "%-4r [%t] %-5p %c %x - %m%n");
+
+        hadoopProps.setProperty("log4j.appender.jobid", "org.apache.log4j.FileAppender");
+        hadoopProps.setProperty("log4j.appender.jobid.file", logFile);
+        hadoopProps.setProperty("log4j.appender.jobid.layout", "org.apache.log4j.PatternLayout");
+        hadoopProps.setProperty("log4j.appender.jobid.layout.ConversionPattern", "%-4r [%t] %-5p %c %x - %m%n");
+        hadoopProps.setProperty("log4j.logger.org.apache.hadoop.hive.ql.exec", "INFO, jobid");
+
+        String localProps = new File(HIVE_L4J_PROPS).getAbsolutePath();
+        OutputStream os1 = new FileOutputStream(localProps);
+        hadoopProps.store(os1, "");
+        os1.close();
+
+        localProps = new File(HIVE_EXEC_L4J_PROPS).getAbsolutePath();
+        os1 = new FileOutputStream(localProps);
+        hadoopProps.store(os1, "");
+        os1.close();
+        return logFile;
+    }
+
+    public static Configuration setUpHiveSite() throws Exception {
+        Configuration hiveConf = initActionConf();
+
+        // Write the action configuration out to hive-site.xml
+        OutputStream os = new FileOutputStream(HIVE_SITE_CONF);
+        hiveConf.writeXml(os);
+        os.close();
+
+        System.out.println();
+        System.out.println("Hive Configuration Properties:");
+        System.out.println("------------------------");
+        for (Entry<String, String> entry : hiveConf) {
+            System.out.println(entry.getKey() + "=" + entry.getValue());
+        }
+        System.out.flush();
+        System.out.println("------------------------");
+        System.out.println();
+        return hiveConf;
+    }
+
+    protected void run(String[] args) throws Exception {
+        System.out.println();
+        System.out.println("Oozie Hive action configuration");
+        System.out.println("=================================================================");
+        System.out.println();
+
+        Configuration hiveConf = setUpHiveSite();
+
+        List<String> arguments = new ArrayList<String>();
+        String scriptPath = hiveConf.get(HiveActionExecutor.HIVE_SCRIPT);
+
+        if (scriptPath == null) {
+            throw new RuntimeException("Action Configuration does not have [" +  HiveActionExecutor.HIVE_SCRIPT + "] property");
+        }
+
+        if (!new File(scriptPath).exists()) {
+            throw new RuntimeException("Hive script file [" + scriptPath + "] does not exist");
+        }
+
+        String logFile = setUpHiveLog4J(hiveConf);
+
+        // print out current directory & its contents
+        File localDir = new File("dummy").getAbsoluteFile().getParentFile();
+        System.out.println("Current (local) dir = " + localDir.getAbsolutePath());
+        System.out.println("------------------------");
+        for (String file : localDir.list()) {
+            System.out.println("  " + file);
+        }
+        System.out.println("------------------------");
+        System.out.println();
+
+        // Prepare the Hive Script
+        String script = readStringFromFile(scriptPath);
+        System.out.println();
+        System.out.println("Script [" + scriptPath + "] content: ");
+        System.out.println("------------------------");
+        System.out.println(script);
+        System.out.println("------------------------");
+        System.out.println();
+
+        // Pass any parameters to Hive via arguments
+        String[] params = MapReduceMain.getStrings(hiveConf, HiveActionExecutor.HIVE_PARAMS);
+        if (params.length > 0) {
+            System.out.println("Parameters:");
+            System.out.println("------------------------");
+            for (String param : params) {
+                System.out.println("  " + param);
+
+                int idx = param.indexOf('=');
+                if (idx == -1) {
+                    throw new RuntimeException("Parameter expression must contain an assignment: " + param);
+                } else if (idx == 0) {
+                    throw new RuntimeException("Parameter value not specified: " + param);
+                }
+                arguments.add("--hivevar");
+                arguments.add(param);
+            }
+            System.out.println("------------------------");
+            System.out.println();
+        }
+
+        arguments.add("-f");
+        arguments.add(scriptPath);
+
+
+        System.out.println("Hive command arguments :");
+        for (String arg : arguments) {
+            System.out.println("             " + arg);
+        }
+        System.out.println();
+
+        System.out.println("=================================================================");
+        System.out.println();
+        System.out.println(">>> Invoking Hive command line now >>>");
+        System.out.println();
+        System.out.flush();
+
+        try {
+            runHive(arguments.toArray(new String[arguments.size()]));
+        }
+        catch (SecurityException ex) {
+            if (LauncherSecurityManager.getExitInvoked()) {
+                if (LauncherSecurityManager.getExitCode() != 0) {
+                    throw ex;
+                }
+            }
+        }
+
+        System.out.println("\n<<< Invocation of Hive command completed <<<\n");
+
+        // harvesting and recording Hadoop Job IDs
+        Properties jobIds = getHadoopJobIds(logFile, HIVE_JOB_IDS_PATTERNS);
+        File file = new File(System.getProperty("oozie.action.output.properties"));
+        OutputStream os = new FileOutputStream(file);
+        jobIds.store(os, "");
+        os.close();
+        System.out.println(" Hadoop Job IDs executed by Hive: " + jobIds.getProperty(HADOOP_JOBS));
+        System.out.println();
+    }
+
+    private void runHive(String[] args) throws Exception {
+        CliDriver.main(args);
+    }
+
+    private static String readStringFromFile(String filePath) throws IOException {
+        String line;
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new FileReader(filePath));
+            StringBuilder sb = new StringBuilder();
+            String sep = System.getProperty("line.separator");
+            while ((line = br.readLine()) != null) {
+                sb.append(line).append(sep);
+            }
+            return sb.toString();
+        }
+        finally {
+            if (br != null) {
+                br.close();
+            }
+        }
+     }
+}

Added: oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java?rev=1466926&view=auto
==============================================================================
--- oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java (added)
+++ oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveActionExecutor.java Thu Apr 11 15:40:45 2013
@@ -0,0 +1,230 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.io.Writer;
+import java.text.MessageFormat;
+import java.util.Properties;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.JobID;
+import org.apache.hadoop.mapred.RunningJob;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.service.HadoopAccessorService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.service.WorkflowAppService;
+import org.apache.oozie.util.ClassUtils;
+import org.apache.oozie.util.IOUtils;
+import org.apache.oozie.util.XConfiguration;
+import org.apache.oozie.util.XmlUtils;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+public class TestHiveActionExecutor extends ActionExecutorTestCase {
+
+    private static final String NEW_LINE =
+        System.getProperty("line.separator", "\n");
+
+    private static final String SAMPLE_DATA_TEXT =
+        "3\n4\n6\n1\n2\n7\n9\n0\n8\n";
+
+    private static final String HIVE_SCRIPT_FILENAME = "script.q";
+
+    private static final String INPUT_DIRNAME = "input";
+    private static final String OUTPUT_DIRNAME = "output";
+    private static final String DATA_FILENAME = "data.txt";
+
+    protected void setSystemProps() throws Exception {
+        super.setSystemProps();
+        setSystemProperty("oozie.service.ActionService.executor.classes",
+                HiveActionExecutor.class.getName());
+    }
+
+    public void testSetupMethods() throws Exception {
+        HiveActionExecutor ae = new HiveActionExecutor();
+        assertEquals("hive", ae.getType());
+    }
+
+    public void testLauncherJar() throws Exception {
+        HiveActionExecutor ae = new HiveActionExecutor();
+        Path jar = new Path(ae.getOozieRuntimeDir(), ae.getLauncherJarName());
+        assertTrue(new File(jar.toString()).exists());
+    }
+
+    private String getHiveScript(String inputPath, String outputPath) {
+        StringBuilder buffer = new StringBuilder(NEW_LINE);
+        buffer.append("set -v;").append(NEW_LINE);
+        buffer.append("CREATE EXTERNAL TABLE test (a INT) STORED AS");
+        buffer.append(NEW_LINE).append("TEXTFILE LOCATION '");
+        buffer.append(inputPath).append("';").append(NEW_LINE);
+        buffer.append("INSERT OVERWRITE DIRECTORY '");
+        buffer.append(outputPath).append("'").append(NEW_LINE);
+        buffer.append("SELECT (a-1) FROM test;").append(NEW_LINE);
+
+        return buffer.toString();
+    }
+
+    private String getActionXml() {
+        String script = "<hive xmlns=''uri:oozie:hive-action:0.2''>" +
+        "<job-tracker>{0}</job-tracker>" +
+        "<name-node>{1}</name-node>" +
+        "<configuration>" +
+        "<property>" +
+        "<name>javax.jdo.option.ConnectionURL</name>" +
+        "<value>jdbc:derby:" + getTestCaseDir() + "/db;create=true</value>" +
+        "</property>" +
+        "<property>" +
+        "<name>javax.jdo.option.ConnectionDriverName</name>" +
+        "<value>org.apache.derby.jdbc.EmbeddedDriver</value>" +
+        "</property>" +
+        "<property>" +
+        "<name>javax.jdo.option.ConnectionUserName</name>" +
+        "<value>sa</value>" +
+        "</property>" +
+        "<property>" +
+        "<name>javax.jdo.option.ConnectionPassword</name>" +
+        "<value> </value>" +
+        "</property>" +
+        "<property>" +
+        "<name>oozie.hive.log.level</name>" +
+        "<value>DEBUG</value>" +
+        "</property>" +
+        "</configuration>" +
+        "<script>" + HIVE_SCRIPT_FILENAME + "</script>" +
+        "</hive>";
+        return MessageFormat.format(script, getJobTrackerUri(), getNameNodeUri());
+    }
+
+    public void testHiveAction() throws Exception {
+        Path inputDir = new Path(getFsTestCaseDir(), INPUT_DIRNAME);
+        Path outputDir = new Path(getFsTestCaseDir(), OUTPUT_DIRNAME);
+
+        FileSystem fs = getFileSystem();
+        Path script = new Path(getAppPath(), HIVE_SCRIPT_FILENAME);
+        Writer scriptWriter = new OutputStreamWriter(fs.create(script));
+        scriptWriter.write(getHiveScript(inputDir.toString(), outputDir.toString()));
+        scriptWriter.close();
+
+        Writer dataWriter = new OutputStreamWriter(fs.create(new Path(inputDir, DATA_FILENAME)));
+        dataWriter.write(SAMPLE_DATA_TEXT);
+        dataWriter.close();
+
+        Context context = createContext(getActionXml());
+        final RunningJob launcherJob = submitAction(context);
+        String launcherId = context.getAction().getExternalId();
+        waitFor(200 * 1000, new Predicate() {
+            public boolean evaluate() throws Exception {
+                return launcherJob.isComplete();
+            }
+        });
+        assertTrue(launcherJob.isSuccessful());
+
+        assertFalse(LauncherMapper.hasIdSwap(launcherJob));
+
+        HiveActionExecutor ae = new HiveActionExecutor();
+        ae.check(context, context.getAction());
+        assertTrue(launcherId.equals(context.getAction().getExternalId()));
+        assertEquals("SUCCEEDED", context.getAction().getExternalStatus());
+        assertNotNull(context.getAction().getData());
+        ae.end(context, context.getAction());
+        assertEquals(WorkflowAction.Status.OK, context.getAction().getStatus());
+
+        assertNotNull(context.getAction().getData());
+        Properties outputData = new Properties();
+        outputData.load(new StringReader(context.getAction().getData()));
+        assertTrue(outputData.containsKey(LauncherMain.HADOOP_JOBS));
+        //while this works in a real cluster, it does not with miniMR
+        //assertTrue(outputData.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
+
+        assertTrue(fs.exists(outputDir));
+        assertTrue(fs.isDirectory(outputDir));
+    }
+
+    private RunningJob submitAction(Context context) throws Exception {
+        HiveActionExecutor ae = new HiveActionExecutor();
+
+        WorkflowAction action = context.getAction();
+
+        ae.prepareActionDir(getFileSystem(), context);
+        ae.submitLauncher(getFileSystem(), context, action);
+
+        String jobId = action.getExternalId();
+        String jobTracker = action.getTrackerUri();
+        String consoleUrl = action.getConsoleUrl();
+        assertNotNull(jobId);
+        assertNotNull(jobTracker);
+        assertNotNull(consoleUrl);
+        Element e = XmlUtils.parseXml(action.getConf());
+        Namespace ns = Namespace.getNamespace("uri:oozie:hive-action:0.2");
+        XConfiguration conf =
+                new XConfiguration(new StringReader(XmlUtils.prettyPrint(e.getChild("configuration", ns)).toString()));
+        conf.set("mapred.job.tracker", e.getChildTextTrim("job-tracker", ns));
+        conf.set("fs.default.name", e.getChildTextTrim("name-node", ns));
+        conf.set("user.name", context.getProtoActionConf().get("user.name"));
+        conf.set("group.name", getTestGroup());
+
+        JobConf jobConf = Services.get().get(HadoopAccessorService.class).createJobConf(jobTracker);
+        XConfiguration.copy(conf, jobConf);
+        String user = jobConf.get("user.name");
+        String group = jobConf.get("group.name");
+        JobClient jobClient = Services.get().get(HadoopAccessorService.class).createJobClient(user, jobConf);
+        final RunningJob runningJob = jobClient.getJob(JobID.forName(jobId));
+        assertNotNull(runningJob);
+        return runningJob;
+    }
+
+    private String copyJar(String targetFile, Class<?> anyContainedClass)
+            throws Exception {
+        String file = ClassUtils.findContainingJar(anyContainedClass);
+        System.out.println("[copy-jar] class: " + anyContainedClass
+                + ", local jar ==> " + file);
+        Path targetPath = new Path(getAppPath(), targetFile);
+        FileSystem fs = getFileSystem();
+        InputStream is = new FileInputStream(file);
+        OutputStream os = fs.create(new Path(getAppPath(), targetPath));
+        IOUtils.copyStream(is, os);
+        return targetPath.toString();
+    }
+
+    private Context createContext(String actionXml) throws Exception {
+        HiveActionExecutor ae = new HiveActionExecutor();
+
+        XConfiguration protoConf = new XConfiguration();
+        protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser());
+
+        SharelibUtils.addToDistributedCache("hive", getFileSystem(), getFsTestCaseDir(), protoConf);
+
+        WorkflowJobBean wf = createBaseWorkflow(protoConf, "hive-action");
+        WorkflowActionBean action = (WorkflowActionBean) wf.getActions().get(0);
+        action.setType(ae.getType());
+        action.setConf(actionXml);
+
+        return new Context(wf, action);
+    }
+
+}

Added: oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java?rev=1466926&view=auto
==============================================================================
--- oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java (added)
+++ oozie/trunk/sharelib/hive/src/test/java/org/apache/oozie/action/hadoop/TestHiveMain.java Thu Apr 11 15:40:45 2013
@@ -0,0 +1,157 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.test.MiniHCatServer;
+import org.apache.oozie.util.XConfiguration;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.net.URL;
+
+public class TestHiveMain extends MainTestCase {
+    private SecurityManager SECURITY_MANAGER;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        SECURITY_MANAGER = System.getSecurityManager();
+    }
+
+    protected void tearDown() throws Exception {
+        System.setSecurityManager(SECURITY_MANAGER);
+        super.tearDown();
+    }
+
+    private static final String NEW_LINE =
+        System.getProperty("line.separator", "\n");
+
+    private String getHiveScript(String inputPath, String outputPath) {
+        StringBuilder buffer = new StringBuilder(NEW_LINE);
+        buffer.append("set -v;").append(NEW_LINE);
+        buffer.append("CREATE EXTERNAL TABLE test (a INT) STORED AS");
+        buffer.append(NEW_LINE).append("TEXTFILE LOCATION '");
+        buffer.append(inputPath).append("';").append(NEW_LINE);
+        buffer.append("INSERT OVERWRITE DIRECTORY '");
+        buffer.append(outputPath).append("'").append(NEW_LINE);
+        buffer.append("SELECT (a-1) FROM test;").append(NEW_LINE);
+
+        return buffer.toString();
+    }
+
+    public Void call() throws Exception {
+        if (System.getenv("HADOOP_HOME") == null) {
+            System.out.println("WARNING: 'HADOOP_HOME' env var not defined, TestHiveMain test is not running");
+        }
+        else {
+            FileSystem fs = getFileSystem();
+
+            Path inputDir = new Path(getFsTestCaseDir(), "input");
+            fs.mkdirs(inputDir);
+            Writer writer = new OutputStreamWriter(fs.create(new Path(inputDir, "data.txt")));
+            writer.write("3\n4\n6\n1\n2\n7\n9\n0\n8\n");
+            writer.close();
+
+            Path outputDir = new Path(getFsTestCaseDir(), "output");
+
+            Path script = new Path(getTestCaseDir(), "script.q");
+            Writer w = new FileWriter(script.toString());
+            w.write(getHiveScript("${IN}", "${OUT}"));
+            w.close();
+
+            XConfiguration jobConf = new XConfiguration();
+            XConfiguration.copy(createJobConf(), jobConf);
+
+            jobConf.set("oozie.hive.log.level", "DEBUG");
+
+            jobConf.set("user.name", getTestUser());
+            jobConf.set("group.name", getTestGroup());
+            jobConf.setInt("mapred.map.tasks", 1);
+            jobConf.setInt("mapred.map.max.attempts", 1);
+            jobConf.setInt("mapred.reduce.max.attempts", 1);
+            jobConf.set("javax.jdo.option.ConnectionURL", "jdbc:derby:" + getTestCaseDir() + "/db;create=true");
+            jobConf.set("javax.jdo.option.ConnectionDriverName", "org.apache.derby.jdbc.EmbeddedDriver");
+            jobConf.set("javax.jdo.option.ConnectionUserName", "sa");
+            jobConf.set("javax.jdo.option.ConnectionPassword", " ");
+
+            SharelibUtils.addToDistributedCache("hive", fs, getFsTestCaseDir(), jobConf);
+
+            HiveActionExecutor.setHiveScript(jobConf, script.toString(), new String[]{"IN=" + inputDir.toUri().getPath(),
+                    "OUT=" + outputDir.toUri().getPath()});
+
+            File actionXml = new File(getTestCaseDir(), "action.xml");
+            OutputStream os = new FileOutputStream(actionXml);
+            jobConf.writeXml(os);
+            os.close();
+
+            //needed in the testcase classpath
+            URL url = Thread.currentThread().getContextClassLoader().getResource("PigMain.txt");
+            File classPathDir = new File(url.getPath()).getParentFile();
+            assertTrue(classPathDir.exists());
+            File hiveSite = new File(classPathDir, "hive-site.xml");
+
+            File outputDataFile = new File(getTestCaseDir(), "outputdata.properties");
+
+            setSystemProperty("oozie.launcher.job.id", "" + System.currentTimeMillis());
+            setSystemProperty("oozie.action.conf.xml", actionXml.getAbsolutePath());
+            setSystemProperty("oozie.action.output.properties", outputDataFile.getAbsolutePath());
+
+            new LauncherSecurityManager();
+            String user = System.getProperty("user.name");
+            try {
+                os = new FileOutputStream(hiveSite);
+                jobConf.writeXml(os);
+                os.close();
+                MiniHCatServer.resetDefaultDBCreation();
+                MiniHCatServer.resetHiveConfStaticVariables();
+                HiveMain.main(null);
+            }
+            catch (SecurityException ex) {
+                if (LauncherSecurityManager.getExitInvoked()) {
+                    System.out.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+                    System.err.println("Intercepting System.exit(" + LauncherSecurityManager.getExitCode() + ")");
+                    if (LauncherSecurityManager.getExitCode() != 0) {
+                        fail();
+                    }
+                }
+                else {
+                    throw ex;
+                }
+            }
+            finally {
+                System.setProperty("user.name", user);
+                hiveSite.delete();
+                MiniHCatServer.resetHiveConfStaticVariables();
+            }
+
+            assertTrue(outputDataFile.exists());
+
+//TODO: I cannot figure out why when log file is not created in this testcase, it works when running in Launcher
+//            Properties props = new Properties();
+//            props.load(new FileReader(outputDataFile));
+//            assertTrue(props.containsKey(LauncherMain.HADOOP_JOBS));
+//            assertTrue(props.getProperty(LauncherMain.HADOOP_JOBS).trim().length() > 0);
+        }
+        return null;
+    }
+
+}

Modified: oozie/trunk/sharelib/pig/pom.xml
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/pig/pom.xml?rev=1466926&r1=1466925&r2=1466926&view=diff
==============================================================================
--- oozie/trunk/sharelib/pig/pom.xml (original)
+++ oozie/trunk/sharelib/pig/pom.xml Thu Apr 11 15:40:45 2013
@@ -66,6 +66,38 @@
             <scope>compile</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-core</artifactId>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hadoop-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.oozie</groupId>
+            <artifactId>oozie-hcatalog</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>

Added: oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java
URL: http://svn.apache.org/viewvc/oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java?rev=1466926&view=auto
==============================================================================
--- oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java (added)
+++ oozie/trunk/sharelib/pig/src/main/java/org/apache/oozie/action/hadoop/OoziePigStats.java Thu Apr 11 15:40:45 2013
@@ -0,0 +1,156 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oozie.action.hadoop;
+
+import java.util.Map;
+
+import org.apache.hadoop.mapred.Counters;
+import org.apache.hadoop.mapred.Counters.Counter;
+import org.apache.pig.tools.pigstats.JobStats;
+import org.apache.pig.tools.pigstats.PigStats;
+import org.apache.pig.tools.pigstats.PigStatsUtil;
+import org.json.simple.JSONObject;
+
+/**
+ * Class to collect the Pig statistics for a Pig action
+ *
+ */
+public class OoziePigStats extends ActionStats {
+    PigStats pigStats = null;
+
+    public OoziePigStats(PigStats pigStats) {
+        this.currentActionType = ActionType.PIG;
+        this.pigStats = pigStats;
+    }
+
+    /**
+     * The PigStats API is used to collect the statistics and the result is returned as a JSON String.
+     *
+     * @return a JSON string
+     */
+    @SuppressWarnings("unchecked")
+    @Override
+    public String toJSON() {
+        JSONObject pigStatsGroup = new JSONObject();
+        pigStatsGroup.put("ACTION_TYPE", getCurrentActionType().toString());
+
+        // pig summary related counters
+        pigStatsGroup.put("BYTES_WRITTEN", Long.toString(pigStats.getBytesWritten()));
+        pigStatsGroup.put("DURATION", Long.toString(pigStats.getDuration()));
+        pigStatsGroup.put("ERROR_CODE", Long.toString(pigStats.getErrorCode()));
+        pigStatsGroup.put("ERROR_MESSAGE", pigStats.getErrorMessage());
+        pigStatsGroup.put("FEATURES", pigStats.getFeatures());
+        pigStatsGroup.put("HADOOP_VERSION", pigStats.getHadoopVersion());
+        pigStatsGroup.put("NUMBER_JOBS", Long.toString(pigStats.getNumberJobs()));
+        pigStatsGroup.put("PIG_VERSION", pigStats.getPigVersion());
+        pigStatsGroup.put("PROACTIVE_SPILL_COUNT_OBJECTS", Long.toString(pigStats.getProactiveSpillCountObjects()));
+        pigStatsGroup.put("PROACTIVE_SPILL_COUNT_RECORDS", Long.toString(pigStats.getProactiveSpillCountRecords()));
+        pigStatsGroup.put("RECORD_WRITTEN", Long.toString(pigStats.getRecordWritten()));
+        pigStatsGroup.put("RETURN_CODE", Long.toString(pigStats.getReturnCode()));
+        pigStatsGroup.put("SCRIPT_ID", pigStats.getScriptId());
+        pigStatsGroup.put("SMM_SPILL_COUNT", Long.toString(pigStats.getSMMSpillCount()));
+
+        PigStats.JobGraph jobGraph = pigStats.getJobGraph();
+        StringBuffer sb = new StringBuffer();
+        String separator = ",";
+
+        for (JobStats jobStats : jobGraph) {
+            // Get all the HadoopIds and put them as comma separated string for JOB_GRAPH
+            String hadoopId = jobStats.getJobId();
+            if (sb.length() > 0) {
+                sb.append(separator);
+            }
+            sb.append(hadoopId);
+            // Hadoop Counters for pig created MR job
+            pigStatsGroup.put(hadoopId, toJSONFromJobStats(jobStats));
+        }
+        pigStatsGroup.put("JOB_GRAPH", sb.toString());
+        return pigStatsGroup.toJSONString();
+    }
+
+    // MR job related counters
+    @SuppressWarnings("unchecked")
+    private static JSONObject toJSONFromJobStats(JobStats jobStats) {
+        JSONObject jobStatsGroup = new JSONObject();
+
+        // hadoop counters
+        jobStatsGroup.put(PigStatsUtil.HDFS_BYTES_WRITTEN, Long.toString(jobStats.getHdfsBytesWritten()));
+        jobStatsGroup.put(PigStatsUtil.MAP_INPUT_RECORDS, Long.toString(jobStats.getMapInputRecords()));
+        jobStatsGroup.put(PigStatsUtil.MAP_OUTPUT_RECORDS, Long.toString(jobStats.getMapOutputRecords()));
+        jobStatsGroup.put(PigStatsUtil.REDUCE_INPUT_RECORDS, Long.toString(jobStats.getReduceInputRecords()));
+        jobStatsGroup.put(PigStatsUtil.REDUCE_OUTPUT_RECORDS, Long.toString(jobStats.getReduceOutputRecords()));
+        // currently returns null; pig bug
+        jobStatsGroup.put("HADOOP_COUNTERS", toJSONFromCounters(jobStats.getHadoopCounters()));
+
+        // pig generated hadoop counters and other stats
+        jobStatsGroup.put("Alias", jobStats.getAlias());
+        jobStatsGroup.put("AVG_MAP_TIME", Long.toString(jobStats.getAvgMapTime()));
+        jobStatsGroup.put("AVG_REDUCE_TIME", Long.toString(jobStats.getAvgREduceTime()));
+        jobStatsGroup.put("BYTES_WRITTEN", Long.toString(jobStats.getBytesWritten()));
+        jobStatsGroup.put("ERROR_MESSAGE", jobStats.getErrorMessage());
+        jobStatsGroup.put("FEATURE", jobStats.getFeature());
+        jobStatsGroup.put("JOB_ID", jobStats.getJobId());
+        jobStatsGroup.put("MAX_MAP_TIME", Long.toString(jobStats.getMaxMapTime()));
+        jobStatsGroup.put("MIN_MAP_TIME", Long.toString(jobStats.getMinMapTime()));
+        jobStatsGroup.put("MAX_REDUCE_TIME", Long.toString(jobStats.getMaxReduceTime()));
+        jobStatsGroup.put("MIN_REDUCE_TIME", Long.toString(jobStats.getMinReduceTime()));
+        jobStatsGroup.put("NUMBER_MAPS", Long.toString(jobStats.getNumberMaps()));
+        jobStatsGroup.put("NUMBER_REDUCES", Long.toString(jobStats.getNumberReduces()));
+        jobStatsGroup.put("PROACTIVE_SPILL_COUNT_OBJECTS", Long.toString(jobStats.getProactiveSpillCountObjects()));
+        jobStatsGroup.put("PROACTIVE_SPILL_COUNT_RECS", Long.toString(jobStats.getProactiveSpillCountRecs()));
+        jobStatsGroup.put("RECORD_WRITTEN", Long.toString(jobStats.getRecordWrittern()));
+        jobStatsGroup.put("SMMS_SPILL_COUNT", Long.toString(jobStats.getSMMSpillCount()));
+        jobStatsGroup.put("MULTI_STORE_COUNTERS", toJSONFromMultiStoreCounters(jobStats.getMultiStoreCounters()));
+
+        return jobStatsGroup;
+
+    }
+
+    // multistorecounters to JSON
+    @SuppressWarnings("unchecked")
+    private static JSONObject toJSONFromMultiStoreCounters(Map<String, Long> map) {
+        JSONObject group = new JSONObject();
+        for (String cName : map.keySet()) {
+            group.put(cName, map.get(cName));
+        }
+        return group;
+
+    }
+
+    // hadoop counters to JSON
+    @SuppressWarnings("unchecked")
+    private static JSONObject toJSONFromCounters(Counters counters) {
+        if (counters == null) {
+            return null;
+        }
+
+        JSONObject groups = new JSONObject();
+        for (String gName : counters.getGroupNames()) {
+            JSONObject group = new JSONObject();
+            for (Counter counter : counters.getGroup(gName)) {
+                String cName = counter.getName();
+                Long cValue = counter.getValue();
+                group.put(cName, Long.toString(cValue));
+            }
+            groups.put(gName, group);
+        }
+        return groups;
+
+    }
+
+}