Search in sources :

Example 56 with WorkflowJobGetJPAExecutor

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

the class TestStatusTransitService method testCoordStatusTransitServiceKilledByUser1.

/**
 * Tests functionality of the StatusTransitService Runnable command. </p> Insert a coordinator job with RUNNING and
 * pending false and coordinator actions with pending false. Then, runs the CoordKillXCommand and
 * StatusTransitService runnable and ensures the job pending changes to false.
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceKilledByUser1() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final String wfJobId = wfJob.getId();
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJobId, "RUNNING", 0);
    new CoordKillXCommand(coordJob.getId()).call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
            WorkflowJobBean wfBean = jpaService.execute(wfGetCmd);
            return wfBean.getStatusStr().equals("KILLED");
        }
    });
    assertNotNull(jpaService);
    final CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    CoordActionGetJPAExecutor coordActionGetCmd = new CoordActionGetJPAExecutor(coordAction.getId());
    WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(wfJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    coordAction = jpaService.execute(coordActionGetCmd);
    wfJob = jpaService.execute(wfGetCmd);
    assertEquals(CoordinatorJob.Status.KILLED, coordJob.getStatus());
    assertEquals(CoordinatorAction.Status.KILLED, coordAction.getStatus());
    assertEquals(WorkflowJob.Status.KILLED, wfJob.getStatus());
    assertEquals(false, coordAction.isPending());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    // Status of coordJobBean is being updated asynchronously.
    // Increasing wait time to atmost 10s to make sure there is
    // sufficient time for the status to get updated. Thus, resulting
    // in following assertion not failing.
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean coordJobBean = jpaService.execute(coordJobGetCmd);
            return !coordJobBean.isPending();
        }
    });
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(false, coordJob.isPending());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)

Example 57 with WorkflowJobGetJPAExecutor

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

the class TestStatusTransitService method testBundleStatusTransitServiceKilled.

/**
 * Test : kill a bundle job - bundle job's pending will be updated to false.
 * <p/>
 * The pending is updated bottom-up. workflow job -> coordinator action -> coordinator job -> bundle action ->
 * bundle job
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceKilled() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.KILLED, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.KILLED);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.KILLED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    WorkflowJobBean wfJob1_1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable("action1-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_1.getId(), wfJob1_1.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable("action1-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_2.getId(), wfJob1_2.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_3 = addRecordToCoordActionTable("action2-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_3.getId(), wfJob1_3.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_4 = addRecordToCoordActionTable("action2-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_4.getId(), wfJob1_4.getStatusStr(), 0);
    new CoordKillXCommand("action1-C").call();
    new CoordKillXCommand("action2-C").call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(coordAction1_4.getExternalId()));
            return wfJob.getStatus().equals(Job.Status.KILLED);
        }
    });
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.isPending() == false;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertFalse(bundleJob.isPending());
    assertEquals(Job.Status.KILLED, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.KILLED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.KILLED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertFalse(bundleAction2.isPending());
    assertEquals(Job.Status.KILLED, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertFalse(coordJob2.isPending());
    assertEquals(Job.Status.KILLED, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 58 with WorkflowJobGetJPAExecutor

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

the class TestStatusTransitService method testBundleStatusTransitServiceSuspended.

/**
 * Test : Suspend a bundle job - bundle job's pending will be updated to false.
 * <p/>
 * The pending is updated bottom-up. workflow job -> coordinator action -> coordinator job -> bundle action ->
 * bundle job
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceSuspended() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.SUSPENDED, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.SUSPENDED);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.SUSPENDED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1-C", CoordinatorJob.Status.RUNNING, start, end, false, false, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, false, false, 2);
    WorkflowJobBean wfJob1_1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable("action1-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_1.getId(), wfJob1_1.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable("action1-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_2.getId(), wfJob1_2.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_3 = addRecordToCoordActionTable("action2-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_3.getId(), wfJob1_3.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_4 = addRecordToCoordActionTable("action2-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_4.getId(), wfJob1_4.getStatusStr(), 0);
    new CoordSuspendXCommand("action1-C").call();
    new CoordSuspendXCommand("action2-C").call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(coordAction1_4.getExternalId()));
            return wfJob.getStatus().equals(Job.Status.SUSPENDED);
        }
    });
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.isPending() == false;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertFalse(bundleJob.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.SUSPENDED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertFalse(bundleAction2.isPending());
    assertEquals(Job.Status.SUSPENDED, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertFalse(coordJob2.isPending());
    assertEquals(Job.Status.SUSPENDED, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 59 with WorkflowJobGetJPAExecutor

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

the class XDataTestCase method addRecordToCoordActionTable.

protected CoordinatorActionBean addRecordToCoordActionTable(CoordinatorActionBean action, String wfId) throws Exception {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordActionInsertJPAExecutor coordActionInsertExecutor = new CoordActionInsertJPAExecutor(action);
        jpaService.execute(coordActionInsertExecutor);
        if (wfId != null) {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(wfId));
            wfJob.setParentId(action.getId());
            WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_PARENT_MODIFIED, wfJob);
        }
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord action record to table");
        throw je;
    }
    return action;
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 60 with WorkflowJobGetJPAExecutor

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

the class XDataTestCase method addRecordToCoordActionTable.

/**
 * Insert coord action and workflow id as external id for testing.
 *
 * @param jobId coord job id
 * @param actionNum action number
 * @param status coord action status
 * @param resourceXmlName xml file name
 * @param wfId wf id
 * @param wfStatus wf status
 * @param pending pending counter
 * @return coord action bean
 * @throws Exception thrown if unable to create coord action bean
 */
protected CoordinatorActionBean addRecordToCoordActionTable(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName, String wfId, String wfStatus, int pending) throws Exception {
    CoordinatorActionBean action = createCoordAction(jobId, actionNum, status, resourceXmlName, pending);
    action.setExternalId(wfId);
    action.setExternalStatus(wfStatus);
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordActionInsertJPAExecutor coordActionInsertExecutor = new CoordActionInsertJPAExecutor(action);
        jpaService.execute(coordActionInsertExecutor);
        if (wfId != null) {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(wfId));
            wfJob.setParentId(action.getId());
            WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_PARENT_MODIFIED, wfJob);
        }
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test coord action record to table");
        throw je;
    }
    return action;
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordActionInsertJPAExecutor(org.apache.oozie.executor.jpa.CoordActionInsertJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Aggregations

WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)60 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)58 JPAService (org.apache.oozie.service.JPAService)49 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)45 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)42 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)38 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)30 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)29 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)25 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)23 BundleActionBean (org.apache.oozie.BundleActionBean)13 BundleJobBean (org.apache.oozie.BundleJobBean)13 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)13 Date (java.util.Date)12 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)12 Configuration (org.apache.hadoop.conf.Configuration)10 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)10 XConfiguration (org.apache.oozie.util.XConfiguration)8 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)6 FileWriter (java.io.FileWriter)5