Search in sources :

Example 26 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestPurgeXCommand method testPurgeCoordWithWFChildWithSubWF3.

/**
 * Test : The subworkflow and workflow should get purged, and the coordinator parent should get purged --> all will get
 * purged
 *
 * @throws Exception
 */
public void testPurgeCoordWithWFChildWithSubWF3() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowJobBean subwfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowActionBean subwfAction = addRecordToWfActionTable(subwfJob.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob.getId(), "SUCCEEDED", 0);
    final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    final WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(wfAction.getId());
    final WorkflowJobGetJPAExecutor subwfJobGetCmd = new WorkflowJobGetJPAExecutor(subwfJob.getId());
    final WorkflowActionGetJPAExecutor subwfActionGetCmd = new WorkflowActionGetJPAExecutor(subwfAction.getId());
    final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    final CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction = jpaService.execute(wfActionGetCmd);
    subwfJob = jpaService.execute(subwfJobGetCmd);
    subwfAction = jpaService.execute(subwfActionGetCmd);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, subwfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, subwfAction.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction.getStatus());
    new PurgeXCommand(7, 7, 1, 10).call();
    try {
        jpaService.execute(coordJobGetCmd);
        fail("Coordinator Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(coordActionGetCmd);
        fail("Coordinator Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(wfJobGetCmd);
        fail("Workflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(wfActionGetCmd);
        fail("Workflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfJobGetCmd);
        fail("SubWorkflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfActionGetCmd);
        fail("SubWorkflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 27 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestPurgeXCommand method testPurgeWFWithSubWF2MoreThanLimit.

/**
 * Test : The subworkflows shouldn't get purged, but the workflow parent should get purged --> none will get purged
 * There are more subworkflow children than the limit
 *
 * @throws Exception
 */
public void testPurgeWFWithSubWF2MoreThanLimit() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobBean wfJob = addRecordToWfJobTableForNegCase(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction1 = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction2 = addRecordToWfActionTable(wfJob.getId(), "2", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction3 = addRecordToWfActionTable(wfJob.getId(), "3", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction4 = addRecordToWfActionTable(wfJob.getId(), "4", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction5 = addRecordToWfActionTable(wfJob.getId(), "5", WorkflowAction.Status.OK);
    WorkflowJobBean subwfJob1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, wfJob.getId());
    WorkflowJobBean subwfJob2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, wfJob.getId());
    WorkflowJobBean subwfJob3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, wfJob.getId());
    WorkflowJobBean subwfJob4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, wfJob.getId());
    WorkflowJobBean subwfJob5 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING, wfJob.getId());
    WorkflowActionBean subwfAction1 = addRecordToWfActionTable(subwfJob1.getId(), "1", WorkflowAction.Status.RUNNING);
    WorkflowActionBean subwfAction2 = addRecordToWfActionTable(subwfJob2.getId(), "1", WorkflowAction.Status.RUNNING);
    WorkflowActionBean subwfAction3 = addRecordToWfActionTable(subwfJob3.getId(), "1", WorkflowAction.Status.RUNNING);
    WorkflowActionBean subwfAction4 = addRecordToWfActionTable(subwfJob4.getId(), "1", WorkflowAction.Status.RUNNING);
    WorkflowActionBean subwfAction5 = addRecordToWfActionTable(subwfJob5.getId(), "1", WorkflowAction.Status.RUNNING);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    WorkflowActionGetJPAExecutor wfAction1GetCmd = new WorkflowActionGetJPAExecutor(wfAction1.getId());
    WorkflowActionGetJPAExecutor wfAction2GetCmd = new WorkflowActionGetJPAExecutor(wfAction2.getId());
    WorkflowActionGetJPAExecutor wfAction3GetCmd = new WorkflowActionGetJPAExecutor(wfAction3.getId());
    WorkflowActionGetJPAExecutor wfAction4GetCmd = new WorkflowActionGetJPAExecutor(wfAction4.getId());
    WorkflowActionGetJPAExecutor wfAction5GetCmd = new WorkflowActionGetJPAExecutor(wfAction5.getId());
    WorkflowJobGetJPAExecutor subwfJob1GetCmd = new WorkflowJobGetJPAExecutor(subwfJob1.getId());
    WorkflowJobGetJPAExecutor subwfJob2GetCmd = new WorkflowJobGetJPAExecutor(subwfJob2.getId());
    WorkflowJobGetJPAExecutor subwfJob3GetCmd = new WorkflowJobGetJPAExecutor(subwfJob3.getId());
    WorkflowJobGetJPAExecutor subwfJob4GetCmd = new WorkflowJobGetJPAExecutor(subwfJob4.getId());
    WorkflowJobGetJPAExecutor subwfJob5GetCmd = new WorkflowJobGetJPAExecutor(subwfJob5.getId());
    WorkflowActionGetJPAExecutor subwfAction1GetCmd = new WorkflowActionGetJPAExecutor(subwfAction1.getId());
    WorkflowActionGetJPAExecutor subwfAction2GetCmd = new WorkflowActionGetJPAExecutor(subwfAction2.getId());
    WorkflowActionGetJPAExecutor subwfAction3GetCmd = new WorkflowActionGetJPAExecutor(subwfAction3.getId());
    WorkflowActionGetJPAExecutor subwfAction4GetCmd = new WorkflowActionGetJPAExecutor(subwfAction4.getId());
    WorkflowActionGetJPAExecutor subwfAction5GetCmd = new WorkflowActionGetJPAExecutor(subwfAction5.getId());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction1 = jpaService.execute(wfAction1GetCmd);
    wfAction2 = jpaService.execute(wfAction2GetCmd);
    wfAction3 = jpaService.execute(wfAction3GetCmd);
    wfAction4 = jpaService.execute(wfAction4GetCmd);
    wfAction5 = jpaService.execute(wfAction5GetCmd);
    subwfJob1 = jpaService.execute(subwfJob1GetCmd);
    subwfJob2 = jpaService.execute(subwfJob2GetCmd);
    subwfJob3 = jpaService.execute(subwfJob3GetCmd);
    subwfJob4 = jpaService.execute(subwfJob4GetCmd);
    subwfJob5 = jpaService.execute(subwfJob5GetCmd);
    subwfAction1 = jpaService.execute(subwfAction1GetCmd);
    subwfAction2 = jpaService.execute(subwfAction2GetCmd);
    subwfAction3 = jpaService.execute(subwfAction3GetCmd);
    subwfAction4 = jpaService.execute(subwfAction4GetCmd);
    subwfAction5 = jpaService.execute(subwfAction5GetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction1.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction2.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction3.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction4.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction5.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, subwfJob1.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, subwfJob2.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, subwfJob3.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, subwfJob4.getStatus());
    assertEquals(WorkflowJob.Status.RUNNING, subwfJob5.getStatus());
    assertEquals(WorkflowAction.Status.RUNNING, subwfAction1.getStatus());
    assertEquals(WorkflowAction.Status.RUNNING, subwfAction2.getStatus());
    assertEquals(WorkflowAction.Status.RUNNING, subwfAction3.getStatus());
    assertEquals(WorkflowAction.Status.RUNNING, subwfAction4.getStatus());
    assertEquals(WorkflowAction.Status.RUNNING, subwfAction5.getStatus());
    new PurgeXCommand(7, 1, 1, 10).call();
    try {
        jpaService.execute(wfJobGetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job should not have been purged");
    }
    try {
        jpaService.execute(wfAction1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 1 should not have been purged");
    }
    try {
        jpaService.execute(wfAction2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 2 should not have been purged");
    }
    try {
        jpaService.execute(wfAction3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 3 should not have been purged");
    }
    try {
        jpaService.execute(wfAction4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 4 should not have been purged");
    }
    try {
        jpaService.execute(wfAction5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 5 should not have been purged");
    }
    try {
        jpaService.execute(subwfJob1GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Job 1 should not have been purged");
    }
    try {
        jpaService.execute(subwfJob2GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Job 2 should not have been purged");
    }
    try {
        jpaService.execute(subwfJob3GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Job 3 should not have been purged");
    }
    try {
        jpaService.execute(subwfJob4GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Job 4 should not have been purged");
    }
    try {
        jpaService.execute(subwfJob5GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Job 5 should not have been purged");
    }
    try {
        jpaService.execute(subwfAction1GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Action 1 should not have been purged");
    }
    try {
        jpaService.execute(subwfAction2GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Action 2 should not have been purged");
    }
    try {
        jpaService.execute(subwfAction3GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Action 3 should not have been purged");
    }
    try {
        jpaService.execute(subwfAction4GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Action 4 should not have been purged");
    }
    try {
        jpaService.execute(subwfAction5GetCmd);
    } catch (JPAExecutorException je) {
        fail("SubWorkflow Action 5 should not have been purged");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 28 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestPurgeXCommand method testPurgeCoordWithWFChildWithSubWFNullEndTimeValidLastModifiedTime.

/**
 * Test : The subworkflow and workflow should get purged, and the coordinator parent should get purged --> all will get
 * purged
 *
 * Coordinator parent finished Workflow and its subworkflow have terminated, last modified time is known, but end time is null
 * for workflow and subworkflow
 *
 * @throws Exception
 */
public void testPurgeCoordWithWFChildWithSubWFNullEndTimeValidLastModifiedTime() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    final QueryExecutor<WorkflowJobBean, WorkflowJobQueryExecutor.WorkflowJobQuery> workflowJobQueryExecutor = WorkflowJobQueryExecutor.getInstance();
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    wfJob.setLastModifiedTime(wfJob.getEndTime());
    wfJob.setEndTime(null);
    workflowJobQueryExecutor.executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowJobBean subwfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    subwfJob.setLastModifiedTime(subwfJob.getEndTime());
    subwfJob.setEndTime(null);
    workflowJobQueryExecutor.executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW, subwfJob);
    WorkflowActionBean subwfAction = addRecordToWfActionTable(subwfJob.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob.getId(), "SUCCEEDED", 0);
    final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    final WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(wfAction.getId());
    final WorkflowJobGetJPAExecutor subwfJobGetCmd = new WorkflowJobGetJPAExecutor(subwfJob.getId());
    final WorkflowActionGetJPAExecutor subwfActionGetCmd = new WorkflowActionGetJPAExecutor(subwfAction.getId());
    final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    final CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction = jpaService.execute(wfActionGetCmd);
    subwfJob = jpaService.execute(subwfJobGetCmd);
    subwfAction = jpaService.execute(subwfActionGetCmd);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, subwfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, subwfAction.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction.getStatus());
    final int wfOlderThanDays = 7;
    final int coordOlderThanDays = 7;
    final int bundleOlderThanDays = 1;
    final int limit = 10;
    new PurgeXCommand(wfOlderThanDays, coordOlderThanDays, bundleOlderThanDays, limit).call();
    try {
        jpaService.execute(coordJobGetCmd);
        fail("Coordinator Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(coordActionGetCmd);
        fail("Coordinator Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(wfJobGetCmd);
        fail("Workflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(wfActionGetCmd);
        fail("Workflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfJobGetCmd);
        fail("SubWorkflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfActionGetCmd);
        fail("SubWorkflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService)

Example 29 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestPurgeXCommand method testPurgeWFWithSubWF3.

/**
 * Test : The subworkflow should get purged, and the workflow parent should get purged --> both will get purged
 *
 * @throws Exception
 */
public void testPurgeWFWithSubWF3() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowJobBean subwfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED, wfJob.getId());
    WorkflowActionBean subwfAction = addRecordToWfActionTable(subwfJob.getId(), "1", WorkflowAction.Status.OK);
    WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(wfJob.getId());
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(wfAction.getId());
    WorkflowJobGetJPAExecutor subwfJobGetCmd = new WorkflowJobGetJPAExecutor(subwfJob.getId());
    WorkflowActionGetJPAExecutor subwfActionGetCmd = new WorkflowActionGetJPAExecutor(subwfAction.getId());
    wfJob = jpaService.execute(wfJobGetCmd);
    wfAction = jpaService.execute(wfActionGetCmd);
    subwfJob = jpaService.execute(subwfJobGetCmd);
    subwfAction = jpaService.execute(subwfActionGetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, subwfJob.getStatus());
    assertEquals(WorkflowAction.Status.OK, subwfAction.getStatus());
    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());
    }
    try {
        jpaService.execute(wfActionGetCmd);
        fail("Workflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfJobGetCmd);
        fail("SubWorkflow Job should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0604, je.getErrorCode());
    }
    try {
        jpaService.execute(subwfActionGetCmd);
        fail("SubWorkflow Action should have been purged");
    } catch (JPAExecutorException je) {
        assertEquals(ErrorCode.E0605, je.getErrorCode());
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 30 with WorkflowActionGetJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor in project oozie by apache.

the class TestPurgeXCommand method testPurgeBundleWithCoordChildWithWFChild2MoreThanLimit.

/**
 * Test : The workflow and coordinator should not get purged, but the bundle parent should get purged --> none will get purged
 * There are more coordinator children than the limit
 *
 * @throws Exception
 */
public void testPurgeBundleWithCoordChildWithWFChild2MoreThanLimit() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobBean bundleJob = addRecordToBundleJobTable(Job.Status.SUCCEEDED, DateUtils.parseDateOozieTZ("2011-01-01T01:00Z"));
    CoordinatorJobBean coordJob1 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    CoordinatorJobBean coordJob2 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob2.setAppName("coord2");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob2);
    CoordinatorJobBean coordJob3 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob3.setAppName("coord3");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob3);
    CoordinatorJobBean coordJob4 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob4.setAppName("coord4");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob4);
    CoordinatorJobBean coordJob5 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    coordJob5.setAppName("coord5");
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob5);
    WorkflowJobBean wfJob1 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJob2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJob3 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJob4 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowJobBean wfJob5 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    WorkflowActionBean wfAction1 = addRecordToWfActionTable(wfJob1.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction2 = addRecordToWfActionTable(wfJob2.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction3 = addRecordToWfActionTable(wfJob3.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction4 = addRecordToWfActionTable(wfJob4.getId(), "1", WorkflowAction.Status.OK);
    WorkflowActionBean wfAction5 = addRecordToWfActionTable(wfJob5.getId(), "1", WorkflowAction.Status.OK);
    CoordinatorActionBean coordAction1 = addRecordToCoordActionTable(coordJob1.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob1.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction2 = addRecordToCoordActionTable(coordJob2.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob2.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction3 = addRecordToCoordActionTable(coordJob3.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob3.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction4 = addRecordToCoordActionTable(coordJob4.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob4.getId(), "SUCCEEDED", 0);
    CoordinatorActionBean coordAction5 = addRecordToCoordActionTable(coordJob5.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJob5.getId(), "SUCCEEDED", 0);
    BundleActionBean bundleAction1 = addRecordToBundleActionTable(bundleJob.getId(), coordJob1.getId(), coordJob1.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction2 = addRecordToBundleActionTable(bundleJob.getId(), coordJob2.getId(), coordJob2.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction3 = addRecordToBundleActionTable(bundleJob.getId(), coordJob3.getId(), coordJob3.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction4 = addRecordToBundleActionTable(bundleJob.getId(), coordJob4.getId(), coordJob4.getAppName(), 0, Job.Status.SUCCEEDED);
    BundleActionBean bundleAction5 = addRecordToBundleActionTable(bundleJob.getId(), coordJob5.getId(), coordJob5.getAppName(), 0, Job.Status.SUCCEEDED);
    WorkflowJobGetJPAExecutor wfJob1GetCmd = new WorkflowJobGetJPAExecutor(wfJob1.getId());
    WorkflowJobGetJPAExecutor wfJob2GetCmd = new WorkflowJobGetJPAExecutor(wfJob2.getId());
    WorkflowJobGetJPAExecutor wfJob3GetCmd = new WorkflowJobGetJPAExecutor(wfJob3.getId());
    WorkflowJobGetJPAExecutor wfJob4GetCmd = new WorkflowJobGetJPAExecutor(wfJob4.getId());
    WorkflowJobGetJPAExecutor wfJob5GetCmd = new WorkflowJobGetJPAExecutor(wfJob5.getId());
    WorkflowActionGetJPAExecutor wfAction1GetCmd = new WorkflowActionGetJPAExecutor(wfAction1.getId());
    WorkflowActionGetJPAExecutor wfAction2GetCmd = new WorkflowActionGetJPAExecutor(wfAction2.getId());
    WorkflowActionGetJPAExecutor wfAction3GetCmd = new WorkflowActionGetJPAExecutor(wfAction3.getId());
    WorkflowActionGetJPAExecutor wfAction4GetCmd = new WorkflowActionGetJPAExecutor(wfAction4.getId());
    WorkflowActionGetJPAExecutor wfAction5GetCmd = new WorkflowActionGetJPAExecutor(wfAction5.getId());
    CoordJobGetJPAExecutor coordJob1GetCmd = new CoordJobGetJPAExecutor(coordJob1.getId());
    CoordJobGetJPAExecutor coordJob2GetCmd = new CoordJobGetJPAExecutor(coordJob2.getId());
    CoordJobGetJPAExecutor coordJob3GetCmd = new CoordJobGetJPAExecutor(coordJob3.getId());
    CoordJobGetJPAExecutor coordJob4GetCmd = new CoordJobGetJPAExecutor(coordJob4.getId());
    CoordJobGetJPAExecutor coordJob5GetCmd = new CoordJobGetJPAExecutor(coordJob5.getId());
    CoordActionGetJPAExecutor coordAction1GetCmd = new CoordActionGetJPAExecutor(coordAction1.getId());
    CoordActionGetJPAExecutor coordAction2GetCmd = new CoordActionGetJPAExecutor(coordAction2.getId());
    CoordActionGetJPAExecutor coordAction3GetCmd = new CoordActionGetJPAExecutor(coordAction3.getId());
    CoordActionGetJPAExecutor coordAction4GetCmd = new CoordActionGetJPAExecutor(coordAction4.getId());
    CoordActionGetJPAExecutor coordAction5GetCmd = new CoordActionGetJPAExecutor(coordAction5.getId());
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(bundleJob.getId());
    BundleActionGetJPAExecutor bundleAction1GetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob1.getAppName());
    BundleActionGetJPAExecutor bundleAction2GetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob2.getAppName());
    BundleActionGetJPAExecutor bundleAction3GetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob3.getAppName());
    BundleActionGetJPAExecutor bundleAction4GetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob4.getAppName());
    BundleActionGetJPAExecutor bundleAction5GetCmd = new BundleActionGetJPAExecutor(bundleJob.getId(), coordJob5.getAppName());
    wfJob1 = jpaService.execute(wfJob1GetCmd);
    wfJob2 = jpaService.execute(wfJob2GetCmd);
    wfJob3 = jpaService.execute(wfJob3GetCmd);
    wfJob4 = jpaService.execute(wfJob4GetCmd);
    wfJob5 = jpaService.execute(wfJob5GetCmd);
    wfAction1 = jpaService.execute(wfAction1GetCmd);
    wfAction2 = jpaService.execute(wfAction2GetCmd);
    wfAction3 = jpaService.execute(wfAction3GetCmd);
    wfAction4 = jpaService.execute(wfAction4GetCmd);
    wfAction5 = jpaService.execute(wfAction5GetCmd);
    coordJob1 = jpaService.execute(coordJob1GetCmd);
    coordJob2 = jpaService.execute(coordJob2GetCmd);
    coordJob3 = jpaService.execute(coordJob3GetCmd);
    coordJob4 = jpaService.execute(coordJob4GetCmd);
    coordJob5 = jpaService.execute(coordJob5GetCmd);
    coordAction1 = jpaService.execute(coordAction1GetCmd);
    coordAction2 = jpaService.execute(coordAction2GetCmd);
    coordAction3 = jpaService.execute(coordAction3GetCmd);
    coordAction4 = jpaService.execute(coordAction4GetCmd);
    coordAction5 = jpaService.execute(coordAction5GetCmd);
    bundleJob = jpaService.execute(bundleJobGetCmd);
    bundleAction1 = jpaService.execute(bundleAction1GetCmd);
    bundleAction2 = jpaService.execute(bundleAction2GetCmd);
    bundleAction3 = jpaService.execute(bundleAction3GetCmd);
    bundleAction4 = jpaService.execute(bundleAction4GetCmd);
    bundleAction5 = jpaService.execute(bundleAction5GetCmd);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob1.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob2.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob3.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob4.getStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfJob5.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction1.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction2.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction3.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction4.getStatus());
    assertEquals(WorkflowAction.Status.OK, wfAction5.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob1.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob2.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob3.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob4.getStatus());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob5.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction1.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction2.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction3.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction4.getStatus());
    assertEquals(CoordinatorAction.Status.SUCCEEDED, coordAction5.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleJob.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction1.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction2.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction3.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction4.getStatus());
    assertEquals(BundleJobBean.Status.SUCCEEDED, bundleAction5.getStatus());
    new PurgeXCommand(getNumDaysToNotBePurged(wfJob1.getEndTime()), getNumDaysToNotBePurged(coordJob1.getLastModifiedTime()), 7, 3).call();
    try {
        jpaService.execute(bundleJobGetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Job should not have been purged");
    }
    try {
        jpaService.execute(bundleAction1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action 1 should not have been purged");
    }
    try {
        jpaService.execute(bundleAction2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action 2 should not have been purged");
    }
    try {
        jpaService.execute(bundleAction3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action 3 should not have been purged");
    }
    try {
        jpaService.execute(bundleAction4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action 4 should not have been purged");
    }
    try {
        jpaService.execute(bundleAction5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Bundle Action 5 should not have been purged");
    }
    try {
        jpaService.execute(coordJob1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job 1 should not have been purged");
    }
    try {
        jpaService.execute(coordJob2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job 2 should not have been purged");
    }
    try {
        jpaService.execute(coordJob3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job 3 should not have been purged");
    }
    try {
        jpaService.execute(coordJob4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job 4 should not have been purged");
    }
    try {
        jpaService.execute(coordJob5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Job 5 should not have been purged");
    }
    try {
        jpaService.execute(coordAction1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action 1 should not have been purged");
    }
    try {
        jpaService.execute(coordAction2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action 2 should not have been purged");
    }
    try {
        jpaService.execute(coordAction3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action 3 should not have been purged");
    }
    try {
        jpaService.execute(coordAction4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action 4 should not have been purged");
    }
    try {
        jpaService.execute(coordAction5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Coordinator Action 5 should not have been purged");
    }
    try {
        jpaService.execute(wfJob1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job 1 should not have been purged");
    }
    try {
        jpaService.execute(wfJob2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job 2 should not have been purged");
    }
    try {
        jpaService.execute(wfJob3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job 3 should not have been purged");
    }
    try {
        jpaService.execute(wfJob4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job 4 should not have been purged");
    }
    try {
        jpaService.execute(wfJob5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Job 5 should not have been purged");
    }
    try {
        jpaService.execute(wfAction1GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 1 should not have been purged");
    }
    try {
        jpaService.execute(wfAction2GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 2 should not have been purged");
    }
    try {
        jpaService.execute(wfAction3GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 3 should not have been purged");
    }
    try {
        jpaService.execute(wfAction4GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 4 should not have been purged");
    }
    try {
        jpaService.execute(wfAction5GetCmd);
    } catch (JPAExecutorException je) {
        fail("Workflow Action 5 should not have been purged");
    }
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) BundleActionBean(org.apache.oozie.BundleActionBean)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)47 JPAService (org.apache.oozie.service.JPAService)47 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)38 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)35 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)22 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)21 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)20 BundleActionBean (org.apache.oozie.BundleActionBean)9 BundleJobBean (org.apache.oozie.BundleJobBean)9 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)9 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)9 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)9 Configuration (org.apache.hadoop.conf.Configuration)6 MapReduceActionExecutor (org.apache.oozie.action.hadoop.MapReduceActionExecutor)6 ActionExecutorContext (org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)6 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)5 Date (java.util.Date)3