You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by vi...@apache.org on 2012/08/22 21:32:05 UTC

svn commit: r1376204 [3/4] - in /incubator/oozie/trunk: ./ core/src/main/java/org/apache/oozie/ core/src/main/java/org/apache/oozie/command/ core/src/main/java/org/apache/oozie/command/bundle/ core/src/main/java/org/apache/oozie/command/coord/ core/src...

Added: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStartJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStartJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStartJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,127 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Collection;
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Class for inserting and updating beans in bulk
+ *
+ */
+public class BulkUpdateInsertForCoordActionStartJPAExecutor implements JPAExecutor<Void> {
+
+    private Collection<JsonBean> updateList;
+    private Collection<JsonBean> insertList;
+
+    /**
+     * Initialize the JPAExecutor using the update and insert list of JSON beans
+     *
+     * @param updateList
+     * @param insertList
+     */
+    public BulkUpdateInsertForCoordActionStartJPAExecutor(Collection<JsonBean> updateList,
+            Collection<JsonBean> insertList) {
+        this.updateList = updateList;
+        this.insertList = insertList;
+    }
+
+    public BulkUpdateInsertForCoordActionStartJPAExecutor() {
+    }
+
+    /**
+     * Sets the update list for JSON bean
+     *
+     * @param updateList
+     */
+    public void setUpdateList(Collection<JsonBean> updateList) {
+        this.updateList = updateList;
+    }
+
+    /**
+     * Sets the insert list for JSON bean
+     *
+     * @param insertList
+     */
+    public void setInsertList(Collection<JsonBean> insertList) {
+        this.insertList = insertList;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+     */
+    @Override
+    public String getName() {
+        return "BulkUpdateInsertForCoordActionStartJPAExecutor";
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
+     * EntityManager)
+     */
+    @Override
+    public Void execute(EntityManager em) throws JPAExecutorException {
+        try {
+            if (insertList != null) {
+                for (JsonBean entity : insertList) {
+                    ParamChecker.notNull(entity, "JsonBean");
+                    em.persist(entity);
+                }
+            }
+            // Only used by test cases to check for rollback of transaction
+            FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
+            if (updateList != null) {
+                for (JsonBean entity : updateList) {
+                    ParamChecker.notNull(entity, "JsonBean");
+                    if (entity instanceof CoordinatorActionBean) {
+                        CoordinatorActionBean action = (CoordinatorActionBean) entity;
+                        Query q = em.createNamedQuery("UPDATE_COORD_ACTION_FOR_START");
+                        q.setParameter("id", action.getId());
+                        q.setParameter("status", action.getStatus().toString());
+                        q.setParameter("lastModifiedTime", new Date());
+                        q.setParameter("runConf", action.getRunConf());
+                        q.setParameter("externalId", action.getExternalId());
+                        q.setParameter("pending", action.getPending());
+                        q.executeUpdate();
+                    }
+                    else {
+                        em.merge(entity);
+                    }
+                }
+            }
+            // Since the return type is Void, we have to return null
+            return null;
+        }
+        catch (Exception e) {
+            throw new JPAExecutorException(ErrorCode.E0603, e);
+        }
+    }
+}

Added: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStatusJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStatusJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStatusJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertForCoordActionStatusJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,124 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.Collection;
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.util.ParamChecker;
+
+/**
+ * Class for inserting and updating beans in bulk
+ *
+ */
+public class BulkUpdateInsertForCoordActionStatusJPAExecutor implements JPAExecutor<Void> {
+
+    private Collection<JsonBean> updateList;
+    private Collection<JsonBean> insertList;
+
+    /**
+     * Initialize the JPAExecutor using the update and insert list of JSON beans
+     *
+     * @param updateList
+     */
+    public BulkUpdateInsertForCoordActionStatusJPAExecutor(Collection<JsonBean> updateList,
+            Collection<JsonBean> insertList) {
+        this.updateList = updateList;
+        this.insertList = insertList;
+    }
+
+    public BulkUpdateInsertForCoordActionStatusJPAExecutor() {
+    }
+
+    /**
+     * Sets the update list for JSON bean
+     *
+     * @param updateList
+     */
+    public void setUpdateList(Collection<JsonBean> updateList) {
+        this.updateList = updateList;
+    }
+
+    /**
+     * Sets the insert list for JSON bean
+     *
+     * @param insertList
+     */
+    public void setInsertList(Collection<JsonBean> insertList) {
+        this.insertList = insertList;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
+     */
+    @Override
+    public String getName() {
+        return "BulkUpdateInsertForCoordActionStatusJPAExecutor";
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
+     * EntityManager)
+     */
+    @Override
+    public Void execute(EntityManager em) throws JPAExecutorException {
+        try {
+            if (insertList != null) {
+                for (JsonBean entity : insertList) {
+                    ParamChecker.notNull(entity, "JsonBean");
+                    em.persist(entity);
+                }
+            }
+            // Only used by test cases to check for rollback of transaction
+            FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
+            if (updateList != null) {
+                for (JsonBean entity : updateList) {
+                    ParamChecker.notNull(entity, "JsonBean");
+                    if (entity instanceof CoordinatorActionBean) {
+                        CoordinatorActionBean action = (CoordinatorActionBean) entity;
+                        Query q = em.createNamedQuery("UPDATE_COORD_ACTION_STATUS_PENDING_TIME");
+                        q.setParameter("id", action.getId());
+                        q.setParameter("status", action.getStatus().toString());
+                        q.setParameter("pending", action.getPending());
+                        q.setParameter("lastModifiedTime", new Date());
+                        q.executeUpdate();
+                    }
+                    else {
+                        em.merge(entity);
+                    }
+                }
+            }
+            // Since the return type is Void, we have to return null
+            return null;
+        }
+        catch (Exception e) {
+            throw new JPAExecutorException(ErrorCode.E0603, e);
+        }
+    }
+}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BulkUpdateInsertJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -78,18 +78,18 @@ public class BulkUpdateInsertJPAExecutor
     @Override
     public Void execute(EntityManager em) throws JPAExecutorException {
         try {
-            if (updateList!= null){
-                for (JsonBean entity: updateList){
+            if (insertList!= null){
+                for (JsonBean entity: insertList){
                     ParamChecker.notNull(entity, "JsonBean");
-                    em.merge(entity);
+                    em.persist(entity);
                 }
             }
             // Only used by test cases to check for rollback of transaction
             FaultInjection.activate("org.apache.oozie.command.SkipCommitFaultInjection");
-            if (insertList!= null){
-                for (JsonBean entity: insertList){
+            if (updateList!= null){
+                for (JsonBean entity: updateList){
                     ParamChecker.notNull(entity, "JsonBean");
-                    em.persist(entity);
+                    em.merge(entity);
                 }
             }
             return null;

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleActionsDeleteForPurgeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleActionsDeleteForPurgeJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleActionsDeleteForPurgeJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleActionsDeleteForPurgeJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,62 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.oozie.ErrorCode;
-import org.apache.oozie.util.ParamChecker;
-
-/**
- * Delete the list of BundleAction for a BundleJob and return the number of actions been deleted.
- */
-public class BundleActionsDeleteForPurgeJPAExecutor implements JPAExecutor<Integer> {
-
-    private String bundleId = null;
-
-    public BundleActionsDeleteForPurgeJPAExecutor(String bundleId) {
-        ParamChecker.notNull(bundleId, "bundleId");
-        this.bundleId = bundleId;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
-     */
-    @Override
-    public String getName() {
-        return "BundleActionsDeleteForPurgeJPAExecutor";
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
-     */
-    @Override
-    public Integer execute(EntityManager em) throws JPAExecutorException {
-        int actionsDeleted = 0;
-        try {
-            Query g = em.createNamedQuery("DELETE_COMPLETED_ACTIONS_FOR_BUNDLE");
-            g.setParameter("bundleId", bundleId);
-            actionsDeleted = g.executeUpdate();
-        }
-        catch (Exception e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
-        return actionsDeleted;
-    }
-}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleJobDeleteJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleJobDeleteJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleJobDeleteJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/BundleJobDeleteJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,56 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import javax.persistence.EntityManager;
-
-import org.apache.oozie.BundleJobBean;
-import org.apache.oozie.util.ParamChecker;
-
-/**
- * Delete bundle job
- */
-public class BundleJobDeleteJPAExecutor implements JPAExecutor<Void> {
-
-    private String bundleJobId = null;
-
-    public BundleJobDeleteJPAExecutor(String bundleJobId) {
-        ParamChecker.notEmpty(bundleJobId, "bundleJobId");
-        this.bundleJobId = bundleJobId;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
-     */
-    @Override
-    public Void execute(EntityManager em) throws JPAExecutorException {
-        BundleJobBean job = em.find(BundleJobBean.class, this.bundleJobId);
-        if (job != null) {
-            em.remove(job);
-        }
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
-     */
-    @Override
-    public String getName() {
-        return "BundleJobDeleteJPAExecutor";
-    }
-}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionUpdateForStartJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,76 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import java.util.Date;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.oozie.CoordinatorActionBean;
-import org.apache.oozie.ErrorCode;
-import org.apache.oozie.util.ParamChecker;
-
-/**
- * Updates the action status, last modified time, runConf, externalId and pending of CoordinatorAction and persists it.
- * It executes SQL update query and return type is Void.
- */
-public class CoordActionUpdateForStartJPAExecutor implements JPAExecutor<Void> {
-
-    private CoordinatorActionBean coordAction = null;
-
-    public CoordActionUpdateForStartJPAExecutor(CoordinatorActionBean coordAction) {
-        ParamChecker.notNull(coordAction, "coordAction");
-        this.coordAction = coordAction;
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.
-     * EntityManager)
-     */
-    @Override
-    public Void execute(EntityManager em) throws JPAExecutorException {
-        try {
-            Query q = em.createNamedQuery("UPDATE_COORD_ACTION_FOR_START");
-            q.setParameter("id", coordAction.getId());
-            q.setParameter("status", coordAction.getStatus().toString());
-            q.setParameter("lastModifiedTime", new Date());
-            q.setParameter("runConf", coordAction.getRunConf());
-            q.setParameter("externalId", coordAction.getExternalId());
-            q.setParameter("pending", coordAction.getPending());
-            q.executeUpdate();
-            // Since the return type is Void, we have to return null
-            return null;
-        }
-        catch (Exception e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
-     */
-    @Override
-    public String getName() {
-        return "CoordActionUpdateForStartJPAExecutor";
-    }
-}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionsDeleteForPurgeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionsDeleteForPurgeJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionsDeleteForPurgeJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordActionsDeleteForPurgeJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,62 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.oozie.ErrorCode;
-import org.apache.oozie.util.ParamChecker;
-
-/**
- * Delete the list of CoordinatorAction for a CoordJob and return the number of actions been deleted.
- */
-public class CoordActionsDeleteForPurgeJPAExecutor implements JPAExecutor<Integer> {
-
-    private String coordJobId = null;
-
-    public CoordActionsDeleteForPurgeJPAExecutor(String coordJobId) {
-        ParamChecker.notNull(coordJobId, "coordJobId");
-        this.coordJobId = coordJobId;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
-     */
-    @Override
-    public String getName() {
-        return "CoordActionsDeleteForPurgeJPAExecutor";
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
-     */
-    @Override
-    public Integer execute(EntityManager em) throws JPAExecutorException {
-        int actionsDeleted = 0;
-        try {
-            Query g = em.createNamedQuery("DELETE_COMPLETED_ACTIONS_FOR_COORDINATOR");
-            g.setParameter("jobId", coordJobId);
-            actionsDeleted = g.executeUpdate();
-        }
-        catch (Exception e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
-        return actionsDeleted;
-    }
-}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionByActionNumberJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionByActionNumberJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionByActionNumberJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/CoordJobGetActionByActionNumberJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -17,12 +17,9 @@
  */
 package org.apache.oozie.executor.jpa;
 
-import java.util.List;
-
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
-import org.apache.oozie.CoordinatorActionBean;
 import org.apache.oozie.ErrorCode;
 import org.apache.oozie.util.ParamChecker;
 

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowActionsDeleteForPurgeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowActionsDeleteForPurgeJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowActionsDeleteForPurgeJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/executor/jpa/WorkflowActionsDeleteForPurgeJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,63 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.oozie.ErrorCode;
-import org.apache.oozie.util.ParamChecker;
-
-/**
- * Delete the list of WorkflowAction for a WorkflowJob and return the number of actions been deleted.
- */
-public class WorkflowActionsDeleteForPurgeJPAExecutor implements JPAExecutor<Integer> {
-
-    private String wfId = null;
-
-    public WorkflowActionsDeleteForPurgeJPAExecutor(String wfId) {
-        ParamChecker.notNull(wfId, "wfId");
-        this.wfId = wfId;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#getName()
-     */
-    @Override
-    public String getName() {
-        return "WorkflowActionsDeleteForPurgeJPAExecutor";
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.oozie.executor.jpa.JPAExecutor#execute(javax.persistence.EntityManager)
-     */
-    @Override
-    public Integer execute(EntityManager em) throws JPAExecutorException {
-        int actionsDeleted = 0;
-        try {
-            Query g = em.createNamedQuery("DELETE_ACTIONS_FOR_WORKFLOW");
-            g.setParameter("wfId", wfId);
-            actionsDeleted = g.executeUpdate();
-        }
-        catch (Exception e) {
-            throw new JPAExecutorException(ErrorCode.E0603, e);
-        }
-        return actionsDeleted;
-    }
-
-}

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/store/SLAStore.java Wed Aug 22 19:32:02 2012
@@ -18,9 +18,7 @@
 package org.apache.oozie.store;
 
 import java.sql.SQLException;
-import java.sql.Timestamp;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.concurrent.Callable;
 
@@ -29,7 +27,6 @@ import javax.persistence.Query;
 
 import org.apache.oozie.ErrorCode;
 import org.apache.oozie.SLAEventBean;
-import org.apache.oozie.XException;
 import org.apache.oozie.service.InstrumentationService;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.util.Instrumentation;

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbOperations.java Wed Aug 22 19:32:02 2012
@@ -24,11 +24,7 @@ import org.apache.oozie.SLAEventBean;
 import org.apache.oozie.client.SLAEvent.SlaAppType;
 import org.apache.oozie.client.SLAEvent.Status;
 import org.apache.oozie.command.CommandException;
-import org.apache.oozie.executor.jpa.SLAEventInsertJPAExecutor;
-import org.apache.oozie.service.JPAService;
 import org.apache.oozie.service.Services;
-import org.apache.oozie.service.StoreService;
-import org.apache.oozie.store.SLAStore;
 import org.apache.oozie.store.Store;
 import org.apache.oozie.util.DateUtils;
 import org.apache.oozie.util.XLog;
@@ -37,11 +33,11 @@ import org.jdom.Element;
 public class SLADbOperations {
     public static final String CLIENT_ID_TAG = "oozie:sla:client-id";
 
-    public static void writeSlaRegistrationEvent(Element eSla, Store store, String slaId, SlaAppType appType, String user,
+    public static SLAEventBean createSlaRegistrationEvent(Element eSla, Store store, String slaId, SlaAppType appType, String user,
             String groupName) throws Exception {
         // System.out.println("BBBBB SLA added");
         if (eSla == null) {
-            return;
+            return null;
         }
         // System.out.println("Writing REG AAAAA " + slaId);
         SLAEventBean sla = new SLAEventBean();
@@ -106,16 +102,15 @@ public class SLADbOperations {
         sla.setJobStatus(Status.CREATED);
         sla.setStatusTimestamp(new Date());
 
-        SLAStore slaStore = (SLAStore) Services.get().get(StoreService.class).getStore(SLAStore.class, store);
-        slaStore.insertSLAEvent(sla);
+        return sla;
     }
 
-    public static void writeSlaRegistrationEvent(Element eSla,
+    public static SLAEventBean createSlaRegistrationEvent(Element eSla,
                                                  String slaId, SlaAppType appType, String user, String groupName, XLog log)
             throws Exception {
         // System.out.println("BBBBB SLA added");
         if (eSla == null) {
-            return;
+            return null;
         }
         //System.out.println("Writing REG AAAAA " + slaId);
         SLAEventBean sla = new SLAEventBean();
@@ -186,16 +181,10 @@ public class SLADbOperations {
         //        .getStore(SLAStore.class, store);
         //slaStore.insertSLAEvent(sla);
 
-        JPAService jpaService = Services.get().get(JPAService.class);
-        if (jpaService != null) {
-            jpaService.execute(new SLAEventInsertJPAExecutor(sla));
-        }
-        else {
-            log.error(ErrorCode.E0610);
-        }
+        return sla;
     }
 
-    public static void writeSlaStatusEvent(String id,
+    public static SLAEventBean createSlaStatusEvent(String id,
                                            Status status, Store store, SlaAppType appType) throws Exception {
         SLAEventBean sla = new SLAEventBean();
         sla.setSlaId(id);
@@ -203,12 +192,13 @@ public class SLADbOperations {
         sla.setAppType(appType);
         sla.setStatusTimestamp(new Date());
         //System.out.println("Writing STATUS AAAAA " + id);
-        SLAStore slaStore = (SLAStore) Services.get().get(StoreService.class)
-                .getStore(SLAStore.class, store);
-        slaStore.insertSLAEvent(sla);
+        //SLAStore slaStore = (SLAStore) Services.get().get(StoreService.class)
+                //.getStore(SLAStore.class, store);
+        //slaStore.insertSLAEvent(sla);
+        return sla;
     }
 
-    public static void writeSlaStatusEvent(String id, Status status, SlaAppType appType, XLog log) throws Exception {
+    public static SLAEventBean createSlaStatusEvent(String id, Status status, SlaAppType appType, XLog log) throws Exception {
         SLAEventBean sla = new SLAEventBean();
         sla.setSlaId(id);
         sla.setJobStatus(status);
@@ -218,35 +208,29 @@ public class SLADbOperations {
         //SLAStore slaStore = (SLAStore) Services.get().get(StoreService.class).getStore(SLAStore.class, store);
         //slaStore.insertSLAEvent(sla);
 
-        JPAService jpaService = Services.get().get(JPAService.class);
-        if (jpaService != null) {
-            jpaService.execute(new SLAEventInsertJPAExecutor(sla));
-        }
-        else {
-            log.error(ErrorCode.E0610);
-        }
+        return sla;
     }
 
-    public static void writeStausEvent(String slaXml, String id, Store store,
+    public static SLAEventBean createStatusEvent(String slaXml, String id, Store store,
                                        Status stat, SlaAppType appType) throws CommandException {
         if (slaXml == null || slaXml.length() == 0) {
-            return;
+            return null;
         }
         try {
-            writeSlaStatusEvent(id, stat, store, appType);
+            return createSlaStatusEvent(id, stat, store, appType);
         }
         catch (Exception e) {
             throw new CommandException(ErrorCode.E1007, " id " + id, e);
         }
     }
 
-    public static void writeStausEvent(String slaXml, String id, Status stat, SlaAppType appType, XLog log)
+    public static SLAEventBean createStatusEvent(String slaXml, String id, Status stat, SlaAppType appType, XLog log)
             throws CommandException {
         if (slaXml == null || slaXml.length() == 0) {
-            return;
+            return null;
         }
         try {
-            writeSlaStatusEvent(id, stat, appType, log);
+            return createSlaStatusEvent(id, stat, appType, log);
         }
         catch (Exception e) {
             throw new CommandException(ErrorCode.E1007, " id " + id, e);

Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/db/SLADbXOperations.java Wed Aug 22 19:32:02 2012
@@ -24,8 +24,6 @@ import org.apache.oozie.SLAEventBean;
 import org.apache.oozie.client.SLAEvent.SlaAppType;
 import org.apache.oozie.client.SLAEvent.Status;
 import org.apache.oozie.command.CommandException;
-import org.apache.oozie.executor.jpa.SLAEventInsertJPAExecutor;
-import org.apache.oozie.service.JPAService;
 import org.apache.oozie.service.Services;
 import org.apache.oozie.util.DateUtils;
 import org.jdom.Element;
@@ -43,11 +41,11 @@ public class SLADbXOperations {
      * @param groupName group name
      * @throws Exception
      */
-    public static void writeSlaRegistrationEvent(Element eSla, String slaId,
+    public static SLAEventBean createSlaRegistrationEvent(Element eSla, String slaId,
                                                  SlaAppType appType, String user, String groupName)
             throws Exception {
         if (eSla == null) {
-            return;
+            return null;
         }
         SLAEventBean sla = new SLAEventBean();
         // sla.setClientId(getTagElement( eSla, "client-id"));
@@ -107,14 +105,7 @@ public class SLADbXOperations {
         sla.setJobStatus(Status.CREATED);
         sla.setStatusTimestamp(new Date());
 
-        JPAService jpaService = Services.get().get(JPAService.class);
-
-        if (jpaService != null) {
-            jpaService.execute(new SLAEventInsertJPAExecutor(sla));
-        }
-        else {
-            throw new CommandException(ErrorCode.E0610, "unable to write sla event.");
-        }
+        return sla;
 
     }
 
@@ -126,7 +117,7 @@ public class SLADbXOperations {
      * @param appType SLA app type
      * @throws Exception
      */
-    public static void writeSlaStatusEvent(String id,
+    public static SLAEventBean createSlaStatusEvent(String id,
                                            Status status, SlaAppType appType) throws Exception {
         SLAEventBean sla = new SLAEventBean();
         sla.setSlaId(id);
@@ -134,14 +125,7 @@ public class SLADbXOperations {
         sla.setAppType(appType);
         sla.setStatusTimestamp(new Date());
 
-        JPAService jpaService = Services.get().get(JPAService.class);
-
-        if (jpaService != null) {
-            jpaService.execute(new SLAEventInsertJPAExecutor(sla));
-        }
-        else {
-            throw new CommandException(ErrorCode.E0610, "unable to write sla event.");
-        }
+        return sla;
     }
 
     /**
@@ -153,13 +137,13 @@ public class SLADbXOperations {
      * @param appType SLA app type
      * @throws CommandException
      */
-    public static void writeStausEvent(String slaXml, String id, Status stat,
+    public static SLAEventBean createStatusEvent(String slaXml, String id, Status stat,
                                        SlaAppType appType) throws CommandException {
         if (slaXml == null || slaXml.length() == 0) {
-            return;
+            return null;
         }
         try {
-            writeSlaStatusEvent(id, stat, appType);
+            return createSlaStatusEvent(id, stat, appType);
         }
         catch (Exception e) {
             throw new CommandException(ErrorCode.E1007, " id " + id, e);

Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/wf/TestActionErrors.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/wf/TestActionErrors.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/wf/TestActionErrors.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/command/wf/TestActionErrors.java Wed Aug 22 19:32:02 2012
@@ -30,7 +30,6 @@ import org.apache.oozie.DagEngine;
 import org.apache.oozie.ForTestingActionExecutor;
 import org.apache.oozie.WorkflowActionBean;
 import org.apache.oozie.WorkflowJobBean;
-import org.apache.oozie.action.control.KillActionExecutor;
 import org.apache.oozie.client.CoordinatorJob;
 import org.apache.oozie.client.CoordinatorAction;
 import org.apache.oozie.client.OozieClient;

Added: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkDeleteForPurgeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkDeleteForPurgeJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkDeleteForPurgeJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkDeleteForPurgeJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,216 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.oozie.BundleJobBean;
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.BundleJob;
+import org.apache.oozie.client.Job;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.command.SkipCommitFaultInjection;
+import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.workflow.WorkflowInstance;
+
+/**
+ * Testcases for bulk JPA writes - delete operations for Purge commands
+ */
+public class TestBulkDeleteForPurgeJPAExecutor extends XDataTestCase {
+    Services services;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        services = new Services();
+        services.init();
+        cleanUpDBTables();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        services.destroy();
+        super.tearDown();
+    }
+
+    /**
+     * Test bulk deletes with bundle job and its 1 bundle action
+     * @throws Exception
+     */
+    public void testDeleteBundle() throws Exception {
+        BundleJobBean bundleJob = addRecordToBundleJobTable(BundleJob.Status.PREP, true);
+        addRecordToBundleActionTable(bundleJob.getId(), "COORD_NAME", 1, Job.Status.SUCCEEDED);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        // add to list for doing bulk delete by bundle job
+        deleteList.add(bundleJob);
+        BulkDeleteForPurgeJPAExecutor bulkPurgeDelCmd = new BulkDeleteForPurgeJPAExecutor();
+        bulkPurgeDelCmd.setDeleteList(deleteList);
+        jpaService.execute(bulkPurgeDelCmd);
+
+        // check for non existence after running bulkDeleteJPA
+        try {
+            jpaService.execute(new BundleJobGetJPAExecutor(bundleJob.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0604, jex.getErrorCode());
+        }
+        try {
+            jpaService.execute(new BundleActionGetJPAExecutor(bundleJob.getId(), "COORD_NAME"));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+    }
+
+    /**
+     * Test bulk deletes with coord job with its 2 coord actions - only 1 in terminal state
+     * @throws Exception
+     */
+    public void testDeleteCoord() throws Exception {
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        CoordinatorActionBean action1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
+        addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.SUSPENDED, "coord-action-get.xml", 0);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        // add to list for doing bulk delete by bundle job
+        deleteList.add(coordJob);
+        BulkDeleteForPurgeJPAExecutor bulkPurgeDelCmd = new BulkDeleteForPurgeJPAExecutor();
+        bulkPurgeDelCmd.setDeleteList(deleteList);
+        assertEquals(1, jpaService.execute(bulkPurgeDelCmd).intValue());
+
+        // check for non existence after running bulkDeleteJPA
+        try {
+            jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0604, jex.getErrorCode());
+        }
+        try {
+            jpaService.execute(new CoordActionGetJPAExecutor(action1.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+    }
+
+    /**
+     * Test bulk deletes with workflow job and its 2 actions
+     * @throws Exception
+     */
+    public void testDeleteWorkflow() throws Exception {
+        WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.RUNNING);
+        WorkflowActionBean action1 = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.KILLED);
+        WorkflowActionBean action2 = addRecordToWfActionTable(wfJob.getId(), "2", WorkflowAction.Status.START_RETRY);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        // add to list for doing bulk delete by bundle job
+        deleteList.add(wfJob);
+        BulkDeleteForPurgeJPAExecutor bulkPurgeDelCmd = new BulkDeleteForPurgeJPAExecutor();
+        bulkPurgeDelCmd.setDeleteList(deleteList);
+        jpaService.execute(bulkPurgeDelCmd);
+
+        // check for non existence after running bulkDeleteJPA
+        try {
+            jpaService.execute(new WorkflowJobGetJPAExecutor(wfJob.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0604, jex.getErrorCode());
+        }
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action1.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action2.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+    }
+
+    /**
+     * Test bulk deletes rollback
+     *
+     * @throws Exception
+     */
+    public void testBulkDeletesRollback() throws Exception{
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.RUNNING);
+        WorkflowActionBean action1 = addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.KILLED);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        deleteList.add(job);
+        BulkDeleteForPurgeJPAExecutor bulkPurgeDelCmd = new BulkDeleteForPurgeJPAExecutor(deleteList);
+
+        // set fault injection to true, so transaction is roll backed
+        setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
+        setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
+        try {
+            jpaService.execute(bulkPurgeDelCmd);
+            fail("Expected exception due to commit failure but didn't get any");
+        }
+        catch (Exception e) {
+        }
+        FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
+
+        // Check whether transactions are rolled back or not
+        try {
+            jpaService.execute(new WorkflowJobGetJPAExecutor(job.getId()));
+        }
+        catch (JPAExecutorException je) {
+            fail("WF job should not be removed due to transaction rollback but was not found");
+        }
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action1.getId()));
+        }
+        catch (JPAExecutorException je) {
+            fail("WF action should not be removed due to transaction rollback but was not found");
+        }
+    }
+
+}

Added: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateDeleteJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateDeleteJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateDeleteJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateDeleteJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,231 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.oozie.CoordinatorActionBean;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.CoordinatorAction;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.command.SkipCommitFaultInjection;
+import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.workflow.WorkflowInstance;
+
+/**
+ * Testcases for bulk JPA writes - update and delete operations
+ */
+public class TestBulkUpdateDeleteJPAExecutor extends XDataTestCase {
+    Services services;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        services = new Services();
+        services.init();
+        cleanUpDBTables();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        services.destroy();
+        super.tearDown();
+    }
+
+    /**
+     * Test bulk updates by updating coordinator job, workflow job and workflow action
+     * @throws Exception
+     */
+    public void testUpdates() throws Exception {
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        // update the status
+        coordJob.setStatus(CoordinatorJob.Status.RUNNING);
+        wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
+        action.setStatus(WorkflowAction.Status.RUNNING);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // update the list for doing bulk writes
+        updateList.add(coordJob);
+        updateList.add(wfJob);
+        updateList.add(action);
+        BulkUpdateDeleteJPAExecutor bulkUpdateCmd = new BulkUpdateDeleteJPAExecutor();
+        bulkUpdateCmd.setUpdateList(updateList);
+        jpaService.execute(bulkUpdateCmd);
+
+        // check for expected status after running bulkUpdateJPA
+        coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+        assertEquals("RUNNING", coordJob.getStatusStr());
+
+        wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(wfJob.getId()));
+        assertEquals("SUCCEEDED", wfJob.getStatusStr());
+
+        WorkflowActionBean action2 = jpaService.execute(new WorkflowActionGetJPAExecutor(action.getId()));
+        assertEquals(WorkflowAction.Status.RUNNING, action2.getStatus());
+
+    }
+
+    /**
+     * Test bulk deletes by deleting a coord action and a wf action
+     * @throws Exception
+     */
+    public void testDeletes() throws Exception{
+        CoordinatorActionBean action1 = addRecordToCoordActionTable("000-123-C", 1, CoordinatorAction.Status.KILLED, "coord-action-get.xml", 0);
+        WorkflowActionBean action2 = addRecordToWfActionTable("000-123-W", "2", WorkflowAction.Status.PREP);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        // insert one workflow job and two actions
+        deleteList.add(action1);
+        deleteList.add(action2);
+
+        BulkUpdateDeleteJPAExecutor bulkDelRerunCmd = new BulkUpdateDeleteJPAExecutor();
+        bulkDelRerunCmd.setDeleteList(deleteList);
+        jpaService.execute(bulkDelRerunCmd);
+
+        // check for non existence after running bulkDeleteJPA
+        try {
+            jpaService.execute(new CoordActionGetJPAExecutor(action1.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action2.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+    }
+
+    /**
+     * Test bulk updates and deletes
+     * workflow job and action
+     *
+     * @throws Exception
+     */
+    public void testBulkUpdatesDeletes() throws Exception{
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
+        WorkflowActionBean action = addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // Add job to update
+        updateList.add(job);
+
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        //Add action to delete
+        deleteList.add(action);
+
+        BulkUpdateDeleteJPAExecutor bulkDelRerunCmd = new BulkUpdateDeleteJPAExecutor();
+        bulkDelRerunCmd.setUpdateList(updateList);
+        bulkDelRerunCmd.setDeleteList(deleteList);
+        jpaService.execute(bulkDelRerunCmd);
+
+        // check for update after running bulkJPA. job should be updated from KILLED -> RUNING
+        job = jpaService.execute(new WorkflowJobGetJPAExecutor(job.getId()));
+        assertEquals("RUNNING", job.getStatusStr());
+
+        // check for non existence after running bulkJPA
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action.getId()));
+            fail(); //should not be found
+        }
+        catch(JPAExecutorException jex) {
+            assertEquals(ErrorCode.E0605, jex.getErrorCode());
+        }
+    }
+
+    /**
+     * Test bulk updates and deletes rollback
+     *
+     * @throws Exception
+     */
+    public void testBulkUpdatesDeletesRollback() throws Exception{
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = addRecordToWfActionTable(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        List<JsonBean> deleteList = new ArrayList<JsonBean>();
+        // Add two actions to delete list
+        deleteList.add(action1);
+        deleteList.add(action2);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // Add to update list
+        updateList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        BulkUpdateDeleteJPAExecutor wfUpdateCmd1 = new BulkUpdateDeleteJPAExecutor(updateList, deleteList, true);
+
+        // set fault injection to true, so transaction is roll backed
+        setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
+        setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
+        try {
+            jpaService.execute(wfUpdateCmd1);
+            fail("Expected exception due to commit failure but didn't get any");
+        }
+        catch (Exception e) {
+        }
+        FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
+
+        // Check whether transactions are rolled back or not
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
+        // status should NOT be RUNNING
+        assertEquals("PREP", wfBean.getStatusStr());
+
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action1.getId()));
+        }
+        catch (JPAExecutorException je) {
+            fail("WF action should not be removed due to rollback but was not found");
+        }
+
+        try {
+            jpaService.execute(new WorkflowActionGetJPAExecutor(action2.getId()));
+        }
+        catch (JPAExecutorException je) {
+            fail("WF action should not be removed due to rollback but was not found");
+        }
+    }
+
+}

Added: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStartJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStartJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStartJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStartJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,260 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.Job;
+import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.command.SkipCommitFaultInjection;
+import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.LiteWorkflowStoreService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.workflow.WorkflowApp;
+import org.apache.oozie.workflow.WorkflowInstance;
+import org.apache.oozie.workflow.lite.EndNodeDef;
+import org.apache.oozie.workflow.lite.LiteWorkflowApp;
+import org.apache.oozie.workflow.lite.StartNodeDef;
+
+/**
+ * Testcases for bulk JPA writes - insert and update operations for Coord Action
+ * Start command
+ */
+public class TestBulkUpdateInsertForCoordActionStartJPAExecutor extends XDataTestCase {
+    Services services;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        services = new Services();
+        services.init();
+        cleanUpDBTables();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        services.destroy();
+        super.tearDown();
+    }
+
+    /**
+     * Test bulk updates by updating coordinator job, workflow job and workflow action
+     * @throws Exception
+     */
+    public void testUpdates() throws Exception {
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        // update the status
+        coordJob.setStatus(CoordinatorJob.Status.RUNNING);
+        wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
+        action.setStatus(WorkflowAction.Status.RUNNING);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // update the list for doing bulk writes
+        updateList.add(coordJob);
+        updateList.add(wfJob);
+        updateList.add(action);
+        BulkUpdateInsertForCoordActionStartJPAExecutor bulkUpdateCmd = new BulkUpdateInsertForCoordActionStartJPAExecutor();
+        bulkUpdateCmd.setUpdateList(updateList);
+        jpaService.execute(bulkUpdateCmd);
+
+        // check for expected status after running bulkUpdateJPA
+        coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+        assertEquals("RUNNING", coordJob.getStatusStr());
+
+        wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(wfJob.getId()));
+        assertEquals("SUCCEEDED", wfJob.getStatusStr());
+
+        WorkflowActionBean action2 = jpaService.execute(new WorkflowActionGetJPAExecutor(action.getId()));
+        assertEquals(WorkflowAction.Status.RUNNING, action2.getStatus());
+
+    }
+
+    /**
+     * Test bulk inserts by inserting a workflow job and two workflow actions
+     * @throws Exception
+     */
+    public void testInserts() throws Exception{
+        WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>",
+            new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end"))
+                .addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
+        Configuration conf = new Configuration();
+        Path appUri = new Path(getAppPath(), "workflow.xml");
+        conf.set(OozieClient.APP_PATH, appUri.toString());
+        conf.set(OozieClient.LOG_TOKEN, "testToken");
+        conf.set(OozieClient.USER_NAME, getTestUser());
+
+        WorkflowJobBean job = createWorkflow(app, conf, "auth", WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // insert one workflow job and two actions
+        insertList.add(action1);
+        insertList.add(action2);
+        insertList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        BulkUpdateInsertForCoordActionStartJPAExecutor bulkInsertCmd = new BulkUpdateInsertForCoordActionStartJPAExecutor();
+        bulkInsertCmd.setInsertList(insertList);
+        jpaService.execute(bulkInsertCmd);
+
+        // check for expected status after running bulkUpdateJPA
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        action1 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action1.getStatusStr());
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        action2 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action2.getStatusStr());
+
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        job = jpaService.execute(wfGetCmd);
+        assertEquals("PREP", job.getStatusStr());
+
+    }
+
+    /**
+     * Test bulk inserts and updates by inserting wf actions and updating
+     * coordinator and workflow jobs
+     *
+     * @throws Exception
+     */
+    public void testBulkInsertUpdates() throws Exception{
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        coordJob.setStatus(Job.Status.SUCCEEDED);
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // Add two actions to insert list
+        insertList.add(action1);
+        insertList.add(action2);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        //Add two jobs to update list
+        updateList.add(coordJob);
+        updateList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        BulkUpdateInsertForCoordActionStartJPAExecutor bulkUpdateCmd = new BulkUpdateInsertForCoordActionStartJPAExecutor(updateList, insertList);
+        jpaService.execute(bulkUpdateCmd);
+
+        coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+        assertEquals("SUCCEEDED", coordJob.getStatusStr());
+
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
+        assertEquals("RUNNING", wfBean.getStatusStr());
+
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        action1 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action1.getStatusStr());
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        action2 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action2.getStatusStr());
+    }
+
+    /**
+     * Test bulk inserts and updates rollback
+     *
+     * @throws Exception
+     */
+    public void testBulkInsertUpdatesRollback() throws Exception{
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // Add two actions to insert list
+        insertList.add(action1);
+        insertList.add(action2);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // Add to update list
+        updateList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        BulkUpdateInsertForCoordActionStartJPAExecutor wfUpdateCmd1 = new BulkUpdateInsertForCoordActionStartJPAExecutor(updateList, insertList);
+
+        // set fault injection to true, so transaction is roll backed
+        setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
+        setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
+        try {
+            jpaService.execute(wfUpdateCmd1);
+            fail("Expected exception due to commit failure but didn't get any");
+        }
+        catch (Exception e) {
+        }
+        FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
+
+        // Check whether transactions are rolled back or not
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
+        // status should not be RUNNING
+        assertEquals("PREP", wfBean.getStatusStr());
+
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        try {
+            action1 = jpaService.execute(actionGetCmd);
+            fail("Expected exception but didnt get any");
+        }
+        catch (JPAExecutorException jpaee) {
+            assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
+        }
+
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        try {
+            action2 = jpaService.execute(actionGetCmd);
+            fail("Expected exception but didnt get any");
+        }
+        catch (JPAExecutorException jpaee) {
+            assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
+        }
+
+    }
+
+}

Added: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStatusJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStatusJPAExecutor.java?rev=1376204&view=auto
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStatusJPAExecutor.java (added)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertForCoordActionStatusJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -0,0 +1,260 @@
+/**
+ * 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.executor.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.ErrorCode;
+import org.apache.oozie.FaultInjection;
+import org.apache.oozie.WorkflowActionBean;
+import org.apache.oozie.WorkflowJobBean;
+import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.Job;
+import org.apache.oozie.client.OozieClient;
+import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.client.WorkflowJob;
+import org.apache.oozie.client.rest.JsonBean;
+import org.apache.oozie.command.SkipCommitFaultInjection;
+import org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor;
+import org.apache.oozie.service.JPAService;
+import org.apache.oozie.service.LiteWorkflowStoreService;
+import org.apache.oozie.service.Services;
+import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.workflow.WorkflowApp;
+import org.apache.oozie.workflow.WorkflowInstance;
+import org.apache.oozie.workflow.lite.EndNodeDef;
+import org.apache.oozie.workflow.lite.LiteWorkflowApp;
+import org.apache.oozie.workflow.lite.StartNodeDef;
+
+/**
+ * Testcases for bulk JPA writes - insert and update operations for Coord Action
+ * Status commands
+ */
+public class TestBulkUpdateInsertForCoordActionStatusJPAExecutor extends XDataTestCase {
+    Services services;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        services = new Services();
+        services.init();
+        cleanUpDBTables();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        services.destroy();
+        super.tearDown();
+    }
+
+    /**
+     * Test bulk updates by updating coordinator job, workflow job and workflow action
+     * @throws Exception
+     */
+    public void testUpdates() throws Exception {
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        // update the status
+        coordJob.setStatus(CoordinatorJob.Status.RUNNING);
+        wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
+        action.setStatus(WorkflowAction.Status.RUNNING);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // update the list for doing bulk writes
+        updateList.add(coordJob);
+        updateList.add(wfJob);
+        updateList.add(action);
+        BulkUpdateInsertForCoordActionStatusJPAExecutor bulkUpdateCmd = new BulkUpdateInsertForCoordActionStatusJPAExecutor();
+        bulkUpdateCmd.setUpdateList(updateList);
+        jpaService.execute(bulkUpdateCmd);
+
+        // check for expected status after running bulkUpdateJPA
+        coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+        assertEquals("RUNNING", coordJob.getStatusStr());
+
+        wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(wfJob.getId()));
+        assertEquals("SUCCEEDED", wfJob.getStatusStr());
+
+        WorkflowActionBean action2 = jpaService.execute(new WorkflowActionGetJPAExecutor(action.getId()));
+        assertEquals(WorkflowAction.Status.RUNNING, action2.getStatus());
+
+    }
+
+    /**
+     * Test bulk inserts by inserting a workflow job and two workflow actions
+     * @throws Exception
+     */
+    public void testInserts() throws Exception{
+        WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>",
+            new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end"))
+                .addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
+        Configuration conf = new Configuration();
+        Path appUri = new Path(getAppPath(), "workflow.xml");
+        conf.set(OozieClient.APP_PATH, appUri.toString());
+        conf.set(OozieClient.LOG_TOKEN, "testToken");
+        conf.set(OozieClient.USER_NAME, getTestUser());
+
+        WorkflowJobBean job = createWorkflow(app, conf, "auth", WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // insert one workflow job and two actions
+        insertList.add(action1);
+        insertList.add(action2);
+        insertList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        BulkUpdateInsertForCoordActionStatusJPAExecutor bulkInsertCmd = new BulkUpdateInsertForCoordActionStatusJPAExecutor();
+        bulkInsertCmd.setInsertList(insertList);
+        jpaService.execute(bulkInsertCmd);
+
+        // check for expected status after running bulkUpdateJPA
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        action1 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action1.getStatusStr());
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        action2 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action2.getStatusStr());
+
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        job = jpaService.execute(wfGetCmd);
+        assertEquals("PREP", job.getStatusStr());
+
+    }
+
+    /**
+     * Test bulk inserts and updates by inserting wf actions and updating
+     * coordinator and workflow jobs
+     *
+     * @throws Exception
+     */
+    public void testBulkInsertUpdates() throws Exception{
+        CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        coordJob.setStatus(Job.Status.SUCCEEDED);
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // Add two actions to insert list
+        insertList.add(action1);
+        insertList.add(action2);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        //Add two jobs to update list
+        updateList.add(coordJob);
+        updateList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        BulkUpdateInsertForCoordActionStatusJPAExecutor bulkUpdateCmd = new BulkUpdateInsertForCoordActionStatusJPAExecutor(updateList, insertList);
+        jpaService.execute(bulkUpdateCmd);
+
+        coordJob = jpaService.execute(new CoordJobGetJPAExecutor(coordJob.getId()));
+        assertEquals("SUCCEEDED", coordJob.getStatusStr());
+
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
+        assertEquals("RUNNING", wfBean.getStatusStr());
+
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        action1 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action1.getStatusStr());
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        action2 = jpaService.execute(actionGetCmd);
+        assertEquals("PREP", action2.getStatusStr());
+    }
+
+    /**
+     * Test bulk inserts and updates rollback
+     *
+     * @throws Exception
+     */
+    public void testBulkInsertUpdatesRollback() throws Exception{
+        WorkflowJobBean job = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
+        WorkflowActionBean action1 = createWorkflowAction(job.getId(), "1", WorkflowAction.Status.PREP);
+        WorkflowActionBean action2 = createWorkflowAction(job.getId(), "2", WorkflowAction.Status.PREP);
+
+        job.setStatus(WorkflowJob.Status.RUNNING);
+        List<JsonBean> insertList = new ArrayList<JsonBean>();
+        // Add two actions to insert list
+        insertList.add(action1);
+        insertList.add(action2);
+
+        List<JsonBean> updateList = new ArrayList<JsonBean>();
+        // Add to update list
+        updateList.add(job);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+
+        BulkUpdateInsertForCoordActionStatusJPAExecutor wfUpdateCmd1 = new BulkUpdateInsertForCoordActionStatusJPAExecutor(updateList, insertList);
+
+        // set fault injection to true, so transaction is roll backed
+        setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
+        setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
+        try {
+            jpaService.execute(wfUpdateCmd1);
+            fail("Expected exception due to commit failure but didn't get any");
+        }
+        catch (Exception e) {
+        }
+        FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
+
+        // Check whether transactions are rolled back or not
+        WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(job.getId());
+        WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
+        // status should not be RUNNING
+        assertEquals("PREP", wfBean.getStatusStr());
+
+        WorkflowActionGetJPAExecutor actionGetCmd = new WorkflowActionGetJPAExecutor(action1.getId());
+        try {
+            action1 = jpaService.execute(actionGetCmd);
+            fail("Expected exception but didnt get any");
+        }
+        catch (JPAExecutorException jpaee) {
+            assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
+        }
+
+
+        actionGetCmd = new WorkflowActionGetJPAExecutor(action2.getId());
+        try {
+            action2 = jpaService.execute(actionGetCmd);
+            fail("Expected exception but didnt get any");
+        }
+        catch (JPAExecutorException jpaee) {
+            assertEquals(ErrorCode.E0605, jpaee.getErrorCode());
+        }
+
+    }
+
+}

Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBulkUpdateInsertJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -45,6 +45,9 @@ import org.apache.oozie.workflow.lite.En
 import org.apache.oozie.workflow.lite.LiteWorkflowApp;
 import org.apache.oozie.workflow.lite.StartNodeDef;
 
+/**
+ * Testcases for bulk JPA writes - inserts and updates
+ */
 public class TestBulkUpdateInsertJPAExecutor extends XDataTestCase {
     Services services;
 

Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleActionsDeleteForPurgeJPAExecutor.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleActionsDeleteForPurgeJPAExecutor.java?rev=1376204&r1=1376203&r2=1376204&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleActionsDeleteForPurgeJPAExecutor.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/executor/jpa/TestBundleActionsDeleteForPurgeJPAExecutor.java Wed Aug 22 19:32:02 2012
@@ -1,88 +0,0 @@
-/**
- * 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.executor.jpa;
-
-import java.util.Date;
-import java.util.List;
-
-import org.apache.oozie.BundleActionBean;
-import org.apache.oozie.BundleJobBean;
-import org.apache.oozie.client.Job;
-import org.apache.oozie.service.JPAService;
-import org.apache.oozie.service.Services;
-import org.apache.oozie.test.XDataTestCase;
-import org.apache.oozie.util.DateUtils;
-
-public class TestBundleActionsDeleteForPurgeJPAExecutor extends XDataTestCase {
-    Services services;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        services = new Services();
-        services.init();
-        cleanUpDBTables();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        services.destroy();
-        super.tearDown();
-    }
-
-    public void testBundleActionsDeleteForPurgeJPAExecutor() throws Exception {
-        BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ(
-            "2011-01-01T01:00Z"));
-        this.addRecordToBundleActionTable(job.getId(), "action1", 0, Job.Status.SUCCEEDED);
-        this.addRecordToBundleActionTable(job.getId(), "action2", 0, Job.Status.SUCCEEDED);
-        _testBundleActionsDelete(job.getId());
-    }
-
-    private void _testBundleActionsDelete(String jobId) throws Exception {
-        JPAService jpaService = Services.get().get(JPAService.class);
-        assertNotNull(jpaService);
-
-        BundleActionsGetJPAExecutor bundleActionsGetCmd = new BundleActionsGetJPAExecutor(jobId);
-        List<BundleActionBean> ret = jpaService.execute(bundleActionsGetCmd);
-        assertEquals(2, ret.size());
-
-        BundleActionsDeleteForPurgeJPAExecutor bundleActionsDelCmd = new BundleActionsDeleteForPurgeJPAExecutor(jobId);
-        jpaService.execute(bundleActionsDelCmd);
-
-        ret = jpaService.execute(bundleActionsGetCmd);
-        assertEquals(0, ret.size());
-    }
-
-    protected BundleJobBean addRecordToBundleJobTable(Job.Status jobStatus, Date lastModifiedTime) throws Exception {
-        BundleJobBean bundle = createBundleJob(jobStatus, false);
-        bundle.setLastModifiedTime(lastModifiedTime);
-        try {
-            JPAService jpaService = Services.get().get(JPAService.class);
-            assertNotNull(jpaService);
-            BundleJobInsertJPAExecutor bundleInsertjpa = new BundleJobInsertJPAExecutor(bundle);
-            jpaService.execute(bundleInsertjpa);
-        }
-        catch (JPAExecutorException je) {
-            je.printStackTrace();
-            fail("Unable to insert the test bundle job record to table");
-            throw je;
-        }
-        return bundle;
-    }
-
-}