Search in sources :

Example 1 with CoordResumeXCommand

use of org.apache.oozie.command.coord.CoordResumeXCommand in project oozie by apache.

the class TestEventGeneration method testCoordinatorActionEvent.

@Test
public void testCoordinatorActionEvent() throws Exception {
    // avoid noise from other apptype events by setting it to only
    // coord action
    ehs.setAppTypes(new HashSet<String>(Arrays.asList("coordinator_action")));
    assertEquals(queue.size(), 0);
    Date startTime = DateUtils.parseDateOozieTZ("2013-01-01T10:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-01-01T10:01Z");
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, false, 0);
    modifyCoordForRunning(coord);
    // Action WAITING on materialization
    new CoordMaterializeTransitionXCommand(coord.getId(), 3600).call();
    final CoordActionGetJPAExecutor coordGetCmd = new CoordActionGetJPAExecutor(coord.getId() + "@1");
    CoordinatorActionBean action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.WAITING, action.getStatus());
    assertEquals(1, queue.size());
    JobEvent event = (JobEvent) queue.poll();
    assertNotNull(event);
    assertEquals(EventStatus.WAITING, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertNull(event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    assertEquals(0, queue.size());
    // Make Action ready
    // In this case it will proceed to Running since n(ready_actions) < concurrency
    new CoordActionInputCheckXCommand(action.getId(), coord.getId()).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.RUNNING, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.STARTED, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(action.getExternalId()));
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    sleep(2000);
    // Action Success
    wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.SUCCEEDED, action.getStatus());
    List<Event> list = queue.pollBatch();
    event = (JobEvent) list.get(list.size() - 1);
    assertEquals(EventStatus.SUCCESS, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action Failure
    wfJob.setStatus(WorkflowJob.Status.FAILED);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.FAILED, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.FAILURE, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action Suspended
    wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
    action.setStatus(CoordinatorAction.Status.RUNNING);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wfJob);
    new CoordActionCheckXCommand(action.getId(), 0).call();
    action = jpaService.execute(coordGetCmd);
    assertEquals(CoordinatorAction.Status.SUSPENDED, action.getStatus());
    event = (JobEvent) queue.poll();
    assertEquals(EventStatus.SUSPEND, event.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, event.getAppType());
    assertEquals(action.getId(), event.getId());
    assertEquals(action.getJobId(), event.getParentId());
    assertEquals(action.getNominalTime(), ((CoordinatorActionEvent) event).getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertEquals(coord.getUser(), event.getUser());
    assertEquals(coord.getAppName(), event.getAppName());
    // Action start on Coord Resume
    coord.setStatus(CoordinatorJobBean.Status.SUSPENDED);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB_STATUS, coord);
    action.setStatus(CoordinatorAction.Status.SUSPENDED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    wfJob.setStatus(WorkflowJob.Status.SUSPENDED);
    WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
    ((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.SUSPENDED);
    wfJob.setWorkflowInstance(wfInstance);
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, wfJob);
    queue.clear();
    new CoordResumeXCommand(coord.getId()).call();
    waitForEventGeneration(1000);
    CoordinatorActionEvent cevent = (CoordinatorActionEvent) queue.poll();
    assertEquals(EventStatus.STARTED, cevent.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
    assertEquals(action.getId(), cevent.getId());
    assertEquals(action.getJobId(), cevent.getParentId());
    assertEquals(action.getNominalTime(), cevent.getNominalTime());
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(coord.getLastModifiedTime(), cevent.getStartTime());
    // Action going to WAITING on Coord Rerun
    action.setStatus(CoordinatorAction.Status.KILLED);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, action);
    queue.clear();
    new CoordRerunXCommand(coord.getId(), RestConstants.JOB_COORD_SCOPE_ACTION, "1", false, true, false, null).call();
    waitFor(3 * 100, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return jpaService.execute(coordGetCmd).getStatus() == CoordinatorAction.Status.WAITING;
        }
    });
    cevent = (CoordinatorActionEvent) queue.poll();
    assertEquals(EventStatus.WAITING, cevent.getEventStatus());
    assertEquals(AppType.COORDINATOR_ACTION, cevent.getAppType());
    assertEquals(action.getId(), cevent.getId());
    assertEquals(action.getJobId(), cevent.getParentId());
    assertEquals(action.getNominalTime(), cevent.getNominalTime());
    assertEquals(wfJob.getStartTime(), event.getStartTime());
    assertNotNull(cevent.getMissingDeps());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordRerunXCommand(org.apache.oozie.command.coord.CoordRerunXCommand) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) CoordMaterializeTransitionXCommand(org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand) CoordActionCheckXCommand(org.apache.oozie.command.coord.CoordActionCheckXCommand) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) JobEvent(org.apache.oozie.client.event.JobEvent) JobEvent(org.apache.oozie.client.event.JobEvent) Event(org.apache.oozie.client.event.Event) CoordActionInputCheckXCommand(org.apache.oozie.command.coord.CoordActionInputCheckXCommand) Test(org.junit.Test)

Example 2 with CoordResumeXCommand

use of org.apache.oozie.command.coord.CoordResumeXCommand in project oozie by apache.

the class BundleJobResumeXCommand method resumeChildren.

/* (non-Javadoc)
     * @see org.apache.oozie.command.ResumeTransitionXCommand#resumeChildren()
     */
@Override
public void resumeChildren() {
    for (BundleActionBean action : bundleActions) {
        if (action.getStatus() == Job.Status.SUSPENDED || action.getStatus() == Job.Status.SUSPENDEDWITHERROR || action.getStatus() == Job.Status.PREPSUSPENDED) {
            // queue a CoordResumeXCommand
            if (action.getCoordId() != null) {
                queue(new CoordResumeXCommand(action.getCoordId()));
                updateBundleAction(action);
                LOG.debug("Resume bundle action = [{0}], new status = [{1}], " + "pending = [{2}] and queue CoordResumeXCommand for [{3}]", action.getBundleActionId(), action.getStatus(), action.getPending(), action.getCoordId());
            } else {
                updateBundleAction(action);
                LOG.debug("Resume bundle action = [{0}], new status = [{1}], " + "pending = [{2}] and coord id is null", action.getBundleActionId(), action.getStatus(), action.getPending());
            }
        }
    }
    LOG.debug("Resume bundle actions for the bundle=[{0}]", bundleId);
}
Also used : CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 3 with CoordResumeXCommand

use of org.apache.oozie.command.coord.CoordResumeXCommand in project oozie by apache.

the class TestStatusTransitService method testFoo.

/**
 * If you have a PREP coordinator job (with no actions) and you suspend it, it goes into PREPSUSPENDED.
 * The StatusTransitService should not transition it to RUNNING automatically.  This test verifies that the job remains in
 * PREPSUSPENDED; and transitions back to PREP after a resume command.
 *
 * @throws Exception
 */
public void testFoo() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, start, end, true, false, 0);
    final String coordJobId = coordJob.getId();
    new CoordSuspendXCommand(coordJobId).call();
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.PREPSUSPENDED, coordJob.getStatus());
    new StatusTransitRunnable().run();
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertEquals(Job.Status.PREPSUSPENDED, coordJob1.getStatus());
    new CoordResumeXCommand(coordJobId).call();
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.PREP, coordJob.getStatus());
    new StatusTransitRunnable().run();
    waitFor(20 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
            return job.getStatus().equals(Job.Status.PREP);
        }
    });
    coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertEquals(Job.Status.PREP, coordJob1.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Example 4 with CoordResumeXCommand

use of org.apache.oozie.command.coord.CoordResumeXCommand in project oozie by apache.

the class TestStatusTransitService method testBundleRunningAfterCoordResume.

public void testBundleRunningAfterCoordResume() throws Exception {
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    CoordinatorJobBean coord = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.RUNNING, true);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, coord.getId(), "COORD-TEST", 0, Job.Status.RUNNING);
    new CoordSuspendXCommand(coord.getId()).call();
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.SUSPENDED, coord.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.SUSPENDED, bundleJob.getStatus());
    new CoordResumeXCommand(coord.getId()).call();
    coord = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coord.getId());
    assertEquals(Job.Status.RUNNING, coord.getStatus());
    runnable = new StatusTransitRunnable();
    runnable.run();
    bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB_STATUS, bundleId);
    assertEquals(Job.Status.RUNNING, bundleJob.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) BundleJobBean(org.apache.oozie.BundleJobBean) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)

Example 5 with CoordResumeXCommand

use of org.apache.oozie.command.coord.CoordResumeXCommand in project oozie by apache.

the class TestStatusTransitService method testCoordStatusTransitServiceSuspendAndResume.

/**
 * Test : Suspend and resume a coordinator job which has finished materialization and all actions are succeeded.
 * </p>
 * Coordinator job changes to succeeded after resume
 *
 * @throws Exception
 */
public void testCoordStatusTransitServiceSuspendAndResume() throws Exception {
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    final String coordJobId = coordJob.getId();
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable(coordJobId, 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable(coordJobId, 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    this.addRecordToWfJobTable(coordAction1_1.getExternalId(), WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    this.addRecordToWfJobTable(coordAction1_2.getExternalId(), WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
    new CoordSuspendXCommand(coordJobId).call();
    CoordJobGetJPAExecutor coordJobGetCmd = new CoordJobGetJPAExecutor(coordJobId);
    coordJob = jpaService.execute(coordJobGetCmd);
    assertEquals(Job.Status.SUSPENDED, coordJob.getStatus());
    sleep(3000);
    new CoordResumeXCommand(coordJobId).call();
    coordJob = jpaService.execute(coordJobGetCmd);
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
            return job.getStatus().equals(Job.Status.SUCCEEDED);
        }
    });
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor(coordJobId));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.SUCCEEDED, coordJob1.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordSuspendXCommand(org.apache.oozie.command.coord.CoordSuspendXCommand) CoordResumeXCommand(org.apache.oozie.command.coord.CoordResumeXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException)

Aggregations

CoordResumeXCommand (org.apache.oozie.command.coord.CoordResumeXCommand)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 Date (java.util.Date)3 CoordSuspendXCommand (org.apache.oozie.command.coord.CoordSuspendXCommand)3 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)2 BundleActionBean (org.apache.oozie.BundleActionBean)1 BundleJobBean (org.apache.oozie.BundleJobBean)1 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 Event (org.apache.oozie.client.event.Event)1 JobEvent (org.apache.oozie.client.event.JobEvent)1 CommandException (org.apache.oozie.command.CommandException)1 CoordActionCheckXCommand (org.apache.oozie.command.coord.CoordActionCheckXCommand)1 CoordActionInputCheckXCommand (org.apache.oozie.command.coord.CoordActionInputCheckXCommand)1 CoordMaterializeTransitionXCommand (org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand)1 CoordRerunXCommand (org.apache.oozie.command.coord.CoordRerunXCommand)1 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)1 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)1