Repository: oozie Updated Branches: refs/heads/master 37e9d7cf9 -> cab20408e
OOZIE-1401 PurgeCommand should purge the workflow jobs w/o end_time (asasvari) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/cab20408 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/cab20408 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/cab20408 Branch: refs/heads/master Commit: cab20408e54b10c8a4c90a4e0ba6df2e99db45f9 Parents: 37e9d7c Author: Attila Sasvari <asasv...@cloudera.com> Authored: Sat Nov 4 22:21:36 2017 +0100 Committer: Attila Sasvari <asasv...@cloudera.com> Committed: Mon Nov 6 10:34:36 2017 +0100 ---------------------------------------------------------------------- .../org/apache/oozie/command/PurgeXCommand.java | 14 +++++++++-- .../apache/oozie/command/TestPurgeXCommand.java | 26 +++++++++++++++++++- release-log.txt | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/cab20408/core/src/main/java/org/apache/oozie/command/PurgeXCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/command/PurgeXCommand.java b/core/src/main/java/org/apache/oozie/command/PurgeXCommand.java index 2ba1999..166c236 100644 --- a/core/src/main/java/org/apache/oozie/command/PurgeXCommand.java +++ b/core/src/main/java/org/apache/oozie/command/PurgeXCommand.java @@ -43,8 +43,10 @@ import org.eclipse.jgit.util.StringUtils; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.List; + /** * This class is used to purge workflows, coordinators, and bundles. It takes into account the relationships between workflows and * coordinators, and coordinators and bundles. It also only acts on 'limit' number of items at a time to not overtax the DB and in @@ -246,8 +248,16 @@ public class PurgeXCommand extends XCommand<Void> { List<String> children = new ArrayList<String>(); long wfOlderThanMS = System.currentTimeMillis() - (wfOlderThan * DAY_IN_MS); for (WorkflowJobBean wfjBean : wfBeanList) { - if (wfjBean.inTerminalState() && wfjBean.getEndTime().getTime() < wfOlderThanMS) { - children.add(wfjBean.getId()); + final Date wfEndTime = wfjBean.getEndTime(); + final boolean isFinished = wfjBean.inTerminalState(); + if (isFinished && wfEndTime != null && wfEndTime.getTime() < wfOlderThanMS) { + children.add(wfjBean.getId()); + } + else { + final Date lastModificationTime = wfjBean.getLastModifiedTime(); + if (isFinished && lastModificationTime != null && lastModificationTime.getTime() < wfOlderThanMS) { + children.add(wfjBean.getId()); + } } } return children; http://git-wip-us.apache.org/repos/asf/oozie/blob/cab20408/core/src/test/java/org/apache/oozie/command/TestPurgeXCommand.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/command/TestPurgeXCommand.java b/core/src/test/java/org/apache/oozie/command/TestPurgeXCommand.java index 20a59c0..af9591b 100644 --- a/core/src/test/java/org/apache/oozie/command/TestPurgeXCommand.java +++ b/core/src/test/java/org/apache/oozie/command/TestPurgeXCommand.java @@ -174,10 +174,34 @@ public class TestPurgeXCommand extends XDataTestCase { } /** - * Test : purge killed wf job and action successfully + * Test : purge failed wf job with null end_time successfully * * @throws Exception */ + public void testFailedJobNullEndTimePurgeXCommand() throws Exception { + final WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.FAILED, WorkflowInstance.Status.FAILED); + final Date endTime = job.getEndTime(); + job.setLastModifiedTime(endTime); + job.setEndTime(null); + + final JPAService jpaService = Services.get().get(JPAService.class); + final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(job.getId()); + + new PurgeXCommand(7, 1, 1, 10).call(); + + try { + jpaService.execute(wfJobGetCmd); + fail("Workflow Job should have been purged"); + } catch (JPAExecutorException je) { + assertEquals(ErrorCode.E0604, je.getErrorCode()); + } + } + + /** + * Test : purge killed wf job and action successfully + * + * @throws Exception + */ public void testKillJobPurgeXCommand() throws Exception { WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED); WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.KILLED); http://git-wip-us.apache.org/repos/asf/oozie/blob/cab20408/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index caf6fa0..76185fe 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ -- Oozie 5.0.0 release (trunk - unreleased) +OOZIE-1401 PurgeCommand should purge the workflow jobs w/o end_time (asasvari) OOZIE-3084 Add missing JVM properties to Jetty startup script (andras.piros) OOZIE-3097 Change version in pom in master to 5.0.0-beta1 (dbist13 via gezapeti) OOZIE-3098 Allow to use the rest api to get the creation time of the Coordinator (chiwen via andras.piros)