Author: kamrul
Date: Tue Apr 10 23:32:49 2012
New Revision: 1312042

URL: http://svn.apache.org/viewvc?rev=1312042&view=rev
Log:
OOZIE-791: coord job status not updated to done_with_error after kill(Virag via 
Mohammad)

Modified:
    
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/command/coord/CoordKillXCommand.java
    
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
    incubator/oozie/branches/branch-3.2/release-log.txt

Modified: 
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/command/coord/CoordKillXCommand.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/command/coord/CoordKillXCommand.java?rev=1312042&r1=1312041&r2=1312042&view=diff
==============================================================================
--- 
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/command/coord/CoordKillXCommand.java
 (original)
+++ 
incubator/oozie/branches/branch-3.2/core/src/main/java/org/apache/oozie/command/coord/CoordKillXCommand.java
 Tue Apr 10 23:32:49 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.
@@ -101,14 +101,18 @@ public class CoordKillXCommand extends K
         }
     }
 
-    private void updateCoordAction(CoordinatorActionBean action) throws 
CommandException {
+    private void updateCoordAction(CoordinatorActionBean action, boolean 
makePending) throws CommandException {
         action.setStatus(CoordinatorActionBean.Status.KILLED);
-        action.incrementAndGetPending();
+        if (makePending) {
+            action.incrementAndGetPending();
+        } else {
+            // set pending to false
+            action.setPending(0);
+        }
         action.setLastModifiedTime(new Date());
         try {
             jpaService.execute(new CoordActionUpdateStatusJPAExecutor(action));
-        }
-        catch (JPAExecutorException e) {
+        } catch (JPAExecutorException e) {
             throw new CommandException(e);
         }
     }
@@ -121,13 +125,15 @@ public class CoordKillXCommand extends K
                     // queue a WorkflowKillXCommand to delete the workflow job 
and actions
                     if (action.getExternalId() != null) {
                         queue(new KillXCommand(action.getExternalId()));
-                        updateCoordAction(action);
+                        // As the kill command for children is queued, set 
pending flag for coord action to be true
+                        updateCoordAction(action, true);
                         LOG.debug(
                                 "Killed coord action = [{0}], new status = 
[{1}], pending = [{2}] and queue KillXCommand for [{3}]",
                                 action.getId(), action.getStatus(), 
action.getPending(), action.getExternalId());
                     }
                     else {
-                        updateCoordAction(action);
+                        // As killing children is not required, set pending 
flag for coord action to be false
+                        updateCoordAction(action, false);
                         LOG.debug("Killed coord action = [{0}], current status 
= [{1}], pending = [{2}]",
                                 action.getId(), action.getStatus(), 
action.getPending());
                     }

Modified: 
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
URL: 
http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java?rev=1312042&r1=1312041&r2=1312042&view=diff
==============================================================================
--- 
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
 (original)
+++ 
incubator/oozie/branches/branch-3.2/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
 Tue Apr 10 23:32:49 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.
@@ -23,8 +23,10 @@ import java.util.List;
 
 import org.apache.oozie.CoordinatorActionBean;
 import org.apache.oozie.CoordinatorJobBean;
+import org.apache.oozie.WorkflowJobBean;
 import org.apache.oozie.client.CoordinatorAction;
 import org.apache.oozie.client.CoordinatorJob;
+import org.apache.oozie.client.WorkflowJob;
 import org.apache.oozie.command.CommandException;
 import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor;
 import org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor;
@@ -35,6 +37,7 @@ import org.apache.oozie.service.SchemaSe
 import org.apache.oozie.service.Services;
 import org.apache.oozie.service.StatusTransitService;
 import org.apache.oozie.test.XDataTestCase;
+import org.apache.oozie.workflow.WorkflowInstance;
 
 public class TestCoordKillXCommand extends XDataTestCase {
     private Services services;
@@ -200,6 +203,57 @@ public class TestCoordKillXCommand exten
         }
     }
 
+
+    /**
+     * Test: Kill a waiting coord action
+     * @throws Exception
+     */
+    public void testCoordKillWaiting() throws Exception {
+        CoordinatorJobBean coordJob = 
addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
+        // Create a workflow job with RUNNING status
+        WorkflowJobBean wfJob1 = this
+                .addRecordToWfJobTable(WorkflowJob.Status.RUNNING, 
WorkflowInstance.Status.RUNNING);
+        // Create a coordinator job with RUNNING status
+        CoordinatorActionBean action1 = 
addRecordToCoordActionTable(coordJob.getId(), 1,
+                CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 
wfJob1.getId(), "RUNNING", 0);
+        // Create a coordinator job with WAITING status
+        CoordinatorActionBean action2 = 
addRecordToCoordActionTable(coordJob.getId(), 2,
+                CoordinatorAction.Status.WAITING, "coord-action-get.xml", 
null, null, 0);
+
+        JPAService jpaService = Services.get().get(JPAService.class);
+        assertNotNull(jpaService);
+        CoordJobGetJPAExecutor coordJobGetCmd = new 
CoordJobGetJPAExecutor(coordJob.getId());
+        CoordActionGetJPAExecutor coordActionGetCmd1 = new 
CoordActionGetJPAExecutor(action1.getId());
+        CoordActionGetJPAExecutor coordActionGetCmd2 = new 
CoordActionGetJPAExecutor(action2.getId());
+
+        coordJob = jpaService.execute(coordJobGetCmd);
+        action1 = jpaService.execute(coordActionGetCmd1);
+        action2 = jpaService.execute(coordActionGetCmd2);
+
+        // Make sure the status is updated
+        assertEquals(coordJob.getStatus(), CoordinatorJob.Status.RUNNING);
+        assertEquals(action1.getStatus(), CoordinatorAction.Status.RUNNING);
+        assertEquals(action2.getStatus(), CoordinatorAction.Status.WAITING);
+
+        // Issue the kill command
+        new CoordKillXCommand(coordJob.getId()).call();
+
+        coordJob = jpaService.execute(coordJobGetCmd);
+        action1 = jpaService.execute(coordActionGetCmd1);
+        action2 = jpaService.execute(coordActionGetCmd2);
+
+        // Check the status and pending flag after kill command is issued
+        assertEquals(coordJob.getStatus(), CoordinatorJob.Status.KILLED);
+        assertEquals(action1.getStatus(), CoordinatorAction.Status.KILLED);
+        // The wf job is running and can be killed, so pending for coord action
+        // kill should be true
+        assertEquals(action1.getPending(), 1);
+        assertEquals(action2.getStatus(), CoordinatorAction.Status.KILLED);
+        // The coord job is waiting and no wf created yet, so pending for coord
+        // action kill should be false
+        assertEquals(action2.getPending(), 0);
+    }
+
     public class MyCoordKillXCommand extends CoordKillXCommand {
         long executed = 0;
         int wait;

Modified: incubator/oozie/branches/branch-3.2/release-log.txt
URL: 
http://svn.apache.org/viewvc/incubator/oozie/branches/branch-3.2/release-log.txt?rev=1312042&r1=1312041&r2=1312042&view=diff
==============================================================================
--- incubator/oozie/branches/branch-3.2/release-log.txt (original)
+++ incubator/oozie/branches/branch-3.2/release-log.txt Tue Apr 10 23:32:49 2012
@@ -1,5 +1,6 @@
 -- Oozie 3.2.0 release
 
+OOZIE-791: coord job status not updated to done_with_error after kill(Virag 
via Mohammad)
 OOZIE-804 TestDecisionActionExecutor failing due to uninitialized conf.(virag 
via Mohammad)
 OOZIE-805 TestCoordSubmitX failing.(Virag via Mohammad)
 OOZIE-803 UP Remove HadoopAccessorService createFileSystem() method that takes 
config only (tucu)


Reply via email to