Author: tucu
Date: Wed May  2 23:46:08 2012
New Revision: 1333258

URL: http://svn.apache.org/viewvc?rev=1333258&view=rev
Log:
OOZIE-827 StatusTransitService fails to run if a stale reference to coord job 
is present (virag via tucu)

Modified:
    
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
    
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
    incubator/oozie/trunk/release-log.txt

Modified: 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java?rev=1333258&r1=1333257&r2=1333258&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
 (original)
+++ 
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
 Wed May  2 23:46:08 2012
@@ -29,6 +29,7 @@ import org.apache.oozie.BundleActionBean
 import org.apache.oozie.BundleJobBean;
 import org.apache.oozie.CoordinatorActionBean;
 import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.ErrorCode;
 import org.apache.oozie.client.CoordinatorAction;
 import org.apache.oozie.client.Job;
 import org.apache.oozie.command.CommandException;
@@ -624,7 +625,18 @@ public class StatusTransitService implem
                 }
                 pendingJobCheckList = new ArrayList<CoordinatorJobBean>();
                 for (String coordId : coordIds.toArray(new 
String[coordIds.size()])) {
-                    CoordinatorJobBean coordJob = jpaService.execute(new 
CoordJobGetJPAExecutor(coordId));
+                    CoordinatorJobBean coordJob;
+                    try{
+                        coordJob = jpaService.execute(new 
CoordJobGetJPAExecutor(coordId));
+                    }
+                    catch (JPAExecutorException jpaee) {
+                        if (jpaee.getErrorCode().equals(ErrorCode.E0604)) {
+                            LOG.warn("Exception happened during 
StatusTransitRunnable; Coordinator Job doesn't exist", jpaee);
+                            continue;
+                        } else {
+                            throw jpaee;
+                        }
+                    }
                     // Running coord job might have pending false
                     if (coordJob.isPending() || 
coordJob.getStatus().equals(Job.Status.RUNNING)) {
                         pendingJobCheckList.add(coordJob);

Modified: 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java?rev=1333258&r1=1333257&r2=1333258&view=diff
==============================================================================
--- 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
 (original)
+++ 
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/service/TestStatusTransitService.java
 Wed May  2 23:46:08 2012
@@ -6,9 +6,9 @@
  * 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.
@@ -770,4 +770,38 @@ public class TestStatusTransitService ex
         return wfBean;
     }
 
+    /**
+     * Tests functionality of the StatusTransitService Runnable command. </p> 
Insert a coordinator job with RUNNING and
+     * pending true and coordinator actions for that job with pending false. 
Insert a coordinator action with a stale coord job id. Then, runs the 
StatusTransitService runnable and ensures
+     * the job status of the good job changes to SUCCEEDED.
+     *
+     * @throws Exception
+     */
+    public void testCoordStatusTransitServiceStaleCoordActions() throws 
Exception {
+
+        // this block will initialize the lastinstancetime for status transit 
service
+        Runnable runnable = new StatusTransitRunnable();
+        runnable.run();
+
+        Date start = DateUtils.parseDateUTC("2009-02-01T01:00Z");
+        Date end = DateUtils.parseDateUTC("2009-02-02T23:59Z");
+
+        CoordinatorJobBean job = 
addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, true, true, 
3);
+        // add a record with stale reference to coord job id
+        addRecordToCoordActionTable("ABCD", 3, 
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
+        // add records with reference to correct job ids
+        addRecordToCoordActionTable(job.getId(), 1, 
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
+        addRecordToCoordActionTable(job.getId(), 2, 
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
+        addRecordToCoordActionTable(job.getId(), 3, 
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
+
+        runnable = new StatusTransitRunnable();
+        runnable.run();
+        Thread.sleep(1000);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        CoordJobGetJPAExecutor coordGetCmd = new 
CoordJobGetJPAExecutor(job.getId());
+        CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
+        assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
+    }
+
 }

Modified: incubator/oozie/trunk/release-log.txt
URL: 
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1333258&r1=1333257&r2=1333258&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Wed May  2 23:46:08 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-827 StatusTransitService fails to run if a stale reference to coord job 
is present (virag via tucu)
 OOZIE-783 Upgrade to Junit4 (virag via tucu)
 OOZIE-815 Remove select * from queries related to coord action (Virag via 
Mohammad)
 OOZIE-826 TestCoordKillXCommand's testCoordKillXCommandUniqueness testcase is 
failing after interrupt changes(virag via Mohammad)


Reply via email to