Author: virag
Date: Thu Jul 25 16:13:55 2013
New Revision: 1507047
URL: http://svn.apache.org/r1507047
Log:
OOZIE-1467 Bundle not killed if coordinator fails due to db exception
(rohini,virag via virag)
Modified:
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/JPAService.java
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/bundle/TestBundleStartXCommand.java
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
oozie/branches/branch-4.0/release-log.txt
Modified:
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
---
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
(original)
+++
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/command/coord/CoordSubmitXCommand.java
Thu Jul 25 16:13:55 2013
@@ -1095,8 +1095,10 @@ public class CoordSubmitXCommand extends
try {
jpaService.execute(new CoordJobInsertJPAExecutor(coordJob));
}
- catch (JPAExecutorException je) {
- throw new CommandException(je);
+ catch (JPAExecutorException jpaee) {
+ coordJob.setId(null);
+ coordJob.setStatus(CoordinatorJob.Status.FAILED);
+ throw new CommandException(jpaee);
}
}
return jobId;
Modified:
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/JPAService.java
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/JPAService.java?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
---
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/JPAService.java
(original)
+++
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/JPAService.java
Thu Jul 25 16:13:55 2013
@@ -24,6 +24,7 @@ import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.BundleActionBean;
@@ -223,6 +224,9 @@ public class JPAService implements Servi
}
return t;
}
+ catch (PersistenceException e) {
+ throw new JPAExecutorException(ErrorCode.E0603, e);
+ }
finally {
cron.stop();
if (instr != null) {
Modified:
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/StatusTransitService.java?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
---
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
(original)
+++
oozie/branches/branch-4.0/core/src/main/java/org/apache/oozie/service/StatusTransitService.java
Thu Jul 25 16:13:55 2013
@@ -18,7 +18,6 @@
package org.apache.oozie.service;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -30,7 +29,6 @@ import java.util.Comparator;
import org.apache.hadoop.conf.Configuration;
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;
@@ -39,7 +37,6 @@ import org.apache.oozie.command.CommandE
import org.apache.oozie.command.bundle.BundleKillXCommand;
import org.apache.oozie.command.bundle.BundleStatusUpdateXCommand;
import
org.apache.oozie.executor.jpa.BundleActionsGetByLastModifiedTimeJPAExecutor;
-import org.apache.oozie.executor.jpa.BundleActionsGetJPAExecutor;
import org.apache.oozie.executor.jpa.BundleActionsGetStatusPendingJPAExecutor;
import org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor;
import org.apache.oozie.executor.jpa.BundleJobUpdateJPAExecutor;
@@ -79,7 +76,7 @@ public class StatusTransitService implem
* (job done), we reset the job's pending flag to 0. If all child actions
are succeeded, we set the job's status to
* SUCCEEDED.
*/
- static class StatusTransitRunnable implements Runnable {
+ public static class StatusTransitRunnable implements Runnable {
private JPAService jpaService = null;
private MemoryLocks.LockToken lock;
Modified:
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/bundle/TestBundleStartXCommand.java
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/bundle/TestBundleStartXCommand.java?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
---
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/bundle/TestBundleStartXCommand.java
(original)
+++
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/bundle/TestBundleStartXCommand.java
Thu Jul 25 16:13:55 2013
@@ -25,14 +25,18 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.fs.Path;
import org.apache.oozie.BundleActionBean;
import org.apache.oozie.BundleJobBean;
+import org.apache.oozie.CoordinatorJobBean;
import org.apache.oozie.ErrorCode;
import org.apache.oozie.client.Job;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.command.CommandException;
import org.apache.oozie.executor.jpa.BundleActionsGetJPAExecutor;
import org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor;
+import org.apache.oozie.executor.jpa.CoordJobInsertJPAExecutor;
import org.apache.oozie.service.JPAService;
import org.apache.oozie.service.Services;
+import org.apache.oozie.service.UUIDService;
+import org.apache.oozie.service.StatusTransitService.StatusTransitRunnable;
import org.apache.oozie.test.XDataTestCase;
import org.apache.oozie.util.XConfiguration;
@@ -219,4 +223,53 @@ public class TestBundleStartXCommand ext
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(Job.Status.FAILED, job.getStatus());
}
+
+ public static class DummyUUIDService extends UUIDService {
+ boolean firstTime = true;
+ @Override
+ public String generateId(ApplicationType type) {
+ if (type.equals(ApplicationType.COORDINATOR) && firstTime) {
+ firstTime = false;
+ return "dummy-coord-id";
+ }
+ else {
+ return super.generateId(type);
+ }
+ }
+ }
+
+ public void testBundleStartWithFailedCoordinator() throws Exception {
+ services.destroy();
+ services = new Services();
+ String excludeServices[] = { "org.apache.oozie.service.UUIDService",
+ "org.apache.oozie.service.StatusTransitService" };
+ Configuration conf = services.getConf();
+ setClassesToBeExcluded(conf, excludeServices);
+ conf.set(Services.CONF_SERVICE_CLASSES,
+ conf.get(Services.CONF_SERVICE_CLASSES) + "," +
DummyUUIDService.class.getName());
+ services.init();
+ CoordinatorJobBean coordJob = new CoordinatorJobBean();
+ coordJob.setId("dummy-coord-id");
+ JPAService jpaService = Services.get().get(JPAService.class);
+ CoordJobInsertJPAExecutor coordInsertCmd = new
CoordJobInsertJPAExecutor(coordJob);
+ jpaService.execute(coordInsertCmd);
+ BundleJobBean job = addRecordToBundleJobTable(Job.Status.PREP, false);
+ BundleJobGetJPAExecutor bundleJobGetExecutor = new
BundleJobGetJPAExecutor(job.getId());
+ job = jpaService.execute(bundleJobGetExecutor);
+ assertEquals(job.getStatus(), Job.Status.PREP);
+ new BundleStartXCommand(job.getId()).call();
+ job = jpaService.execute(bundleJobGetExecutor);
+ assertEquals(job.getStatus(), Job.Status.RUNNING);
+ sleep(2000);
+ BundleActionsGetJPAExecutor bundleActionsGetExecutor = new
BundleActionsGetJPAExecutor(job.getId());
+ List<BundleActionBean> actions =
jpaService.execute(bundleActionsGetExecutor);
+ assertNull(actions.get(0).getCoordId());
+ assertEquals(Job.Status.FAILED, actions.get(0).getStatus());
+ Runnable runnable = new StatusTransitRunnable();
+ runnable.run();
+ job = jpaService.execute(bundleJobGetExecutor);
+ assertEquals(job.getStatus(), Job.Status.KILLED);
+ }
+
+
}
Modified:
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
---
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
(original)
+++
oozie/branches/branch-4.0/core/src/test/java/org/apache/oozie/command/coord/TestCoordKillXCommand.java
Thu Jul 25 16:13:55 2013
@@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.CoordinatorActionBean;
import org.apache.oozie.CoordinatorJobBean;
import org.apache.oozie.WorkflowJobBean;
@@ -29,9 +28,8 @@ import org.apache.oozie.client.Coordinat
import org.apache.oozie.client.CoordinatorJob;
import org.apache.oozie.client.WorkflowJob;
import org.apache.oozie.command.CommandException;
+import org.apache.oozie.command.PreconditionException;
import org.apache.oozie.coord.CoordELFunctions;
-import org.apache.oozie.dependency.FSURIHandler;
-import org.apache.oozie.dependency.HCatURIHandler;
import org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor;
import org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor;
import org.apache.oozie.executor.jpa.CoordJobUpdateJPAExecutor;
@@ -41,7 +39,6 @@ import org.apache.oozie.service.Partitio
import org.apache.oozie.service.SchemaService;
import org.apache.oozie.service.Services;
import org.apache.oozie.service.StatusTransitService;
-import org.apache.oozie.service.URIHandlerService;
import org.apache.oozie.test.XDataTestCase;
import org.apache.oozie.util.DateUtils;
import org.apache.oozie.util.HCatURI;
@@ -99,6 +96,29 @@ public class TestCoordKillXCommand exten
assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
assertTrue(job.isDoneMaterialization());
assertEquals(action.getStatus(), CoordinatorAction.Status.KILLED);
+
+ // Change job status to RUNNINGWITHERROR to simulate
StatusTransitService changing it to
+ // RUNNINGWITHERROR if it had loaded status and had it as RUNNING in
memory when CoordKill
+ // executes and updates status to KILLED in database.
+ job.setStatus(CoordinatorJob.Status.RUNNINGWITHERROR);
+ jpaService.execute(new CoordJobUpdateJPAExecutor(job));
+ job = jpaService.execute(coordJobGetCmd);
+ assertEquals(job.getStatus(), CoordinatorJob.Status.RUNNINGWITHERROR);
+ final CoordMaterializeTransitionXCommand transitionCmd = new
CoordMaterializeTransitionXCommand(job.getId(), 3600);
+ try {
+ transitionCmd.loadState();
+ transitionCmd.verifyPrecondition();
+ fail();
+ }
+ catch (PreconditionException e) {
+ // Materialization should not happen as done materialization is
set to true by coord kill
+ }
+ StatusTransitService.StatusTransitRunnable statusTransit = new
StatusTransitService.StatusTransitRunnable();
+ statusTransit.run();
+ // StatusTransitService should change the job back to KILLED
+ job = jpaService.execute(coordJobGetCmd);
+ assertEquals(job.getStatus(), CoordinatorJob.Status.KILLED);
+ assertTrue(job.isDoneMaterialization());
}
/**
Modified: oozie/branches/branch-4.0/release-log.txt
URL:
http://svn.apache.org/viewvc/oozie/branches/branch-4.0/release-log.txt?rev=1507047&r1=1507046&r2=1507047&view=diff
==============================================================================
--- oozie/branches/branch-4.0/release-log.txt (original)
+++ oozie/branches/branch-4.0/release-log.txt Thu Jul 25 16:13:55 2013
@@ -1,5 +1,6 @@
-- Oozie 4.0.0 release
+OOZIE-1467 Bundle not killed if coordinator fails due to db exception
(rohini,virag via virag)
OOZIE-1466 current EL should not check for less than or equal to zero (rohini)
OOZIE-1465 Making constants in CoordELFunctions public for el extensions
(shwethags via rohini)
OOZIE-1450 Duplicate Coord_Action events on Waiting -> Timeout, and Coord
Materialize not removing actions on Failure (mona)