Search in sources :

Example 21 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordRerunXCommand method testCoordRerunActions2.

/**
 * Test : rerun <jobId> -action 1-2 -nocleanup
 *
 * @throws Exception
 */
public void testCoordRerunActions2() throws Exception {
    final String jobId = "0000000-" + new Date().getTime() + "-testCoordRerun-C";
    final int actionNum1 = 1;
    final int actionNum2 = 2;
    final String actionId1 = jobId + "@" + actionNum1;
    final String actionId2 = jobId + "@" + actionNum2;
    try {
        addRecordToJobTable(jobId, CoordinatorJob.Status.SUCCEEDED);
        addRecordToActionTable(jobId, actionNum1, actionId1, CoordinatorAction.Status.SUCCEEDED, "coord-rerun-action1.xml");
        addRecordToActionTable(jobId, actionNum2, actionId2, CoordinatorAction.Status.SUCCEEDED, "coord-rerun-action2.xml");
    } catch (Exception e) {
        e.printStackTrace();
        fail("Could not update db.");
    }
    String rerunScope = Integer.toString(actionNum1) + "-" + Integer.toString(actionNum2);
    final OozieClient coordClient = LocalOozie.getCoordClient();
    coordClient.reRunCoord(jobId, RestConstants.JOB_COORD_SCOPE_ACTION, rerunScope, false, true);
    CoordinatorActionBean action1 = getCoordinatorAction(actionId1);
    assertNotSame(action1.getStatus(), CoordinatorAction.Status.SUCCEEDED);
    CoordinatorActionBean action2 = getCoordinatorAction(actionId2);
    assertNotSame(action2.getStatus(), CoordinatorAction.Status.SUCCEEDED);
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) StoreException(org.apache.oozie.store.StoreException) IOException(java.io.IOException)

Example 22 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordRerunXCommand method testCoordRerunForBackwardSupport3.

/**
 * Tests functionality of the coord rerun for backward support is true. </p> Insert a coordinator job with SUCCEEDED
 * and coordinator actions with pending false. However, job's doneMaterialization is false to imitate update from
 * 2.x to 3.0.1.
 * Set oozie.service.StatusTransitService.backward.support.for.coord.status=true
 * and use uri:oozie:coordinator:0.1 namespace, then, rerun the coord job for action 1 and action 2.
 *
 * @throws Exception
 */
public void testCoordRerunForBackwardSupport3() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_COORD_STATUS, "true");
    services = new Services();
    services.init();
    Date start = DateUtils.parseDateOozieTZ("2009-02-01T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-02-02T23:59Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, false, false, 3);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    coordJob.setAppNamespace(SchemaService.COORDINATOR_NAMESPACE_URI_1);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_APPNAMESPACE, coordJob);
    CoordinatorActionBean action1 = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-rerun-action1.xml", 0);
    CoordinatorActionBean action2 = addRecordToCoordActionTable(coordJob.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-rerun-action1.xml", 0);
    CoordinatorActionBean action3 = addRecordToCoordActionTable(coordJob.getId(), 3, CoordinatorAction.Status.SUCCEEDED, "coord-rerun-action1.xml", 0);
    String rerunScope = Integer.toString(1) + "-" + Integer.toString(2);
    final OozieClient coordClient = LocalOozie.getCoordClient();
    coordClient.reRunCoord(coordJob.getId(), RestConstants.JOB_COORD_SCOPE_ACTION, rerunScope, false, true);
    coordJob = getCoordinatorJob(coordJob.getId());
    assertEquals(CoordinatorJob.Status.SUCCEEDED, coordJob.getStatus());
    action1 = getCoordinatorAction(action1.getId());
    assertNotSame(action1.getStatus(), CoordinatorAction.Status.SUCCEEDED);
    action2 = getCoordinatorAction(action2.getId());
    assertNotSame(action2.getStatus(), CoordinatorAction.Status.SUCCEEDED);
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 23 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordWfActionInfoXCommand method createTestData.

/**
 * init the test case.
 * 1 coordJob
 * 5 coordAction created by the coordJob, while the 5th coordAction's workflow instance is null
 * 4 wfJob match the 1st ~ 4th coordAction
 * the 1st - 3rd wfAction has a wfAction named 'aa' each, but the 4th desn't.
 */
private void createTestData() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull("Missing jpa service", jpaService);
    coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, false, false);
    wfJobs = new ArrayList<WorkflowJobBean>();
    coordActions = new ArrayList<CoordinatorActionBean>();
    for (int i = 0; i < 4; i++) {
        WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
        wfJobs.add(wfJob);
    }
    for (int i = 0; i < 4; i++) {
        CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), (i + 1), CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", wfJobs.get(i).getId(), "SUCCEEDED", 0);
        coordActions.add(coordAction);
    }
    // add a coordAction that doesnt create workflow instance yet
    CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 5, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", null, null, 0);
    coordActions.add(coordAction);
    // set the NominalTime,in order to keep the order of the coordAction.
    for (int i = 0; i < 5; i++) {
        setCoordActionNominalTime(coordActions.get(i).getId(), (i + 1) * 1000);
    }
    // create the case that the 4th wfJob doesnt have a action named "aa"
    for (int i = 0; i < 4; i++) {
        String name = (i == 3) ? "bb" : "aa";
        addRecordToWfActionTable(wfJobs.get(i).getId(), name, WorkflowAction.Status.DONE);
    }
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 24 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordActionReadyXCommand method _testActionsInREADY.

private void _testActionsInREADY(Execution execPolicy) throws Exception {
    Date now = new Date();
    Date start = new Date(now.getTime() - 16 * 60 * 1000);
    Date end = new Date(now.getTime() + 20 * 60 * 1000);
    CoordinatorJobBean job = createCoordJob(Job.Status.RUNNING, start, end, true, true, 5);
    job.setStartTime(start);
    job.setEndTime(end);
    job.setExecutionOrder(execPolicy);
    job.setFrequency("5");
    job.setTimeUnit(Timeunit.MINUTE);
    // Concurrency=1 ensures that with the 1 RUNNING action, CoordActionReadyXCommand won't actually start another action
    // (CoordActionStartXCommand), which would throw an Exception because the DB only has partial info
    job.setConcurrency(1);
    addRecordToCoordJobTable(job);
    final CoordinatorActionBean action1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "wf-no-op.xml", 1, start);
    final CoordinatorActionBean action2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 5 * 60 * 1000));
    final CoordinatorActionBean action3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 10 * 60 * 1000));
    final CoordinatorActionBean action4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 15 * 60 * 1000));
    final CoordinatorActionBean action5 = addRecordToCoordActionTable(job.getId(), 5, CoordinatorAction.Status.WAITING, "wf-no-op.xml", 1, new Date(start.getTime() + 20 * 60 * 1000));
    checkCoordActionStatus(action1.getId(), CoordinatorAction.Status.RUNNING);
    checkCoordActionStatus(action2.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action3.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action4.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action5.getId(), CoordinatorAction.Status.WAITING);
    new CoordActionReadyXCommand(job.getId()).call();
    checkCoordActionStatus(action1.getId(), CoordinatorAction.Status.RUNNING);
    checkCoordActionStatus(action2.getId(), CoordinatorAction.Status.SKIPPED);
    checkCoordActionStatus(action3.getId(), CoordinatorAction.Status.SKIPPED);
    checkCoordActionStatus(action4.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action5.getId(), CoordinatorAction.Status.WAITING);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date)

Example 25 with CoordinatorActionBean

use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.

the class TestCoordActionSkipXCommand method testVerifyPrecondition.

public void testVerifyPrecondition() throws Exception {
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + 1 * 60 * 1000);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    int actionNum = 1;
    for (CoordinatorAction.Status actionStatus : CoordinatorAction.Status.values()) {
        CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum, actionStatus, "coord-action-get.xml", 0);
        try {
            new CoordActionSkipXCommand(action, getTestUser(), "my-app-name").verifyPrecondition();
            if (!(actionStatus.equals(CoordinatorAction.Status.WAITING) || actionStatus.equals(CoordinatorAction.Status.READY))) {
                fail();
            }
        } catch (PreconditionException pe) {
            assertEquals(ErrorCode.E1100, pe.getErrorCode());
            assertTrue(pe.getMessage().endsWith("[" + actionStatus + "]]"));
        }
        actionNum++;
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) Date(java.util.Date) PreconditionException(org.apache.oozie.command.PreconditionException)

Aggregations

CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)307 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)148 Date (java.util.Date)117 JPAService (org.apache.oozie.service.JPAService)113 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)102 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)60 CommandException (org.apache.oozie.command.CommandException)55 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 IOException (java.io.IOException)49 XConfiguration (org.apache.oozie.util.XConfiguration)44 Configuration (org.apache.hadoop.conf.Configuration)43 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)42 ArrayList (java.util.ArrayList)40 JDOMException (org.jdom.JDOMException)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 StringReader (java.io.StringReader)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)29 StoreException (org.apache.oozie.store.StoreException)24 Test (org.junit.Test)24 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)22