Search in sources :

Example 1 with CoordJobQuery

use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.

the class CoordChangeXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    LOG.info("STARTED CoordChangeXCommand for jobId=" + jobId);
    try {
        oldConcurrency = this.coordJob.getConcurrency();
        if (newEndTime != null) {
            // during coord materialization, nextMaterializedTime is set to
            // startTime + n(actions materialized) * frequency and this can be AFTER endTime,
            // while doneMaterialization is true. Hence the following checks
            // for newEndTime being in the middle of endTime and nextMatdTime.
            // Since job is already done materialization so no need to change
            boolean dontChange = coordJob.getEndTime().before(newEndTime) && coordJob.getNextMaterializedTime() != null && coordJob.getNextMaterializedTime().after(newEndTime);
            if (!dontChange) {
                coordJob.setEndTime(newEndTime);
                // OOZIE-1703, we should SUCCEEDED the coord, if it's in PREP and new endtime is before start time
                if (coordJob.getStartTime().compareTo(newEndTime) >= 0) {
                    if (coordJob.getStatus() != CoordinatorJob.Status.PREP) {
                        processLookaheadActions(coordJob, newEndTime);
                    }
                    if (coordJob.getStatus() == CoordinatorJob.Status.PREP || coordJob.getStatus() == CoordinatorJob.Status.RUNNING) {
                        LOG.info("Changing coord status to SUCCEEDED, because it's in " + coordJob.getStatus() + " and new end time is before start time. Startime is " + coordJob.getStartTime() + " and new end time is " + newEndTime);
                        coordJob.setStatus(CoordinatorJob.Status.SUCCEEDED);
                        coordJob.resetPending();
                    }
                    coordJob.setDoneMaterialization();
                } else {
                    // move it to running iff new end time is after starttime.
                    if (coordJob.getStatus() == CoordinatorJob.Status.SUCCEEDED) {
                        coordJob.setStatus(CoordinatorJob.Status.RUNNING);
                    }
                    if (coordJob.getStatus() == CoordinatorJob.Status.DONEWITHERROR || coordJob.getStatus() == CoordinatorJob.Status.FAILED) {
                        // Check for backward compatibility for Oozie versions (3.2 and before)
                        // when RUNNINGWITHERROR, SUSPENDEDWITHERROR and
                        // PAUSEDWITHERROR is not supported
                        coordJob.setStatus(StatusUtils.getStatusIfBackwardSupportTrue(CoordinatorJob.Status.RUNNINGWITHERROR));
                    }
                    coordJob.setPending();
                    coordJob.resetDoneMaterialization();
                    processLookaheadActions(coordJob, newEndTime);
                }
            } else {
                LOG.info("Didn't change endtime. Endtime is in between coord end time and next materialization time." + "Coord endTime = " + DateUtils.formatDateOozieTZ(newEndTime) + " next materialization time =" + DateUtils.formatDateOozieTZ(coordJob.getNextMaterializedTime()));
            }
        }
        if (newConcurrency != null) {
            this.coordJob.setConcurrency(newConcurrency);
        }
        if (newPauseTime != null || resetPauseTime == true) {
            this.coordJob.setPauseTime(newPauseTime);
            if (oldPauseTime != null && newPauseTime != null) {
                if (oldPauseTime.before(newPauseTime)) {
                    if (this.coordJob.getStatus() == Job.Status.PAUSED) {
                        this.coordJob.setStatus(Job.Status.RUNNING);
                    } else if (this.coordJob.getStatus() == Job.Status.PAUSEDWITHERROR) {
                        this.coordJob.setStatus(Job.Status.RUNNINGWITHERROR);
                    }
                }
            } else if (oldPauseTime != null && newPauseTime == null) {
                if (this.coordJob.getStatus() == Job.Status.PAUSED) {
                    this.coordJob.setStatus(Job.Status.RUNNING);
                } else if (this.coordJob.getStatus() == Job.Status.PAUSEDWITHERROR) {
                    this.coordJob.setStatus(Job.Status.RUNNINGWITHERROR);
                }
            }
            if (!resetPauseTime) {
                processLookaheadActions(coordJob, newPauseTime);
            }
        }
        if (jobStatus != null) {
            coordJob.setStatus(jobStatus);
            LOG.info("Coord status is changed to " + jobStatus + " from " + prevStatus);
            if (jobStatus.equals(CoordinatorJob.Status.RUNNING)) {
                coordJob.setPending();
                if (coordJob.getNextMaterializedTime() == null || coordJob.getEndTime().after(coordJob.getNextMaterializedTime())) {
                    coordJob.resetDoneMaterialization();
                }
            } else if (jobStatus.equals(CoordinatorJob.Status.IGNORED)) {
                coordJob.resetPending();
                coordJob.setDoneMaterialization();
            }
        }
        if (coordJob.getNextMaterializedTime() != null && coordJob.getEndTime().compareTo(coordJob.getNextMaterializedTime()) <= 0) {
            LOG.info("[" + coordJob.getId() + "]: all actions have been materialized, job status = " + coordJob.getStatus() + ", set pending to true");
            // set doneMaterialization to true when materialization is done
            coordJob.setDoneMaterialization();
        }
        coordJob.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_CHANGE, coordJob));
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, deleteList);
        if (newConcurrency != null && newConcurrency > oldConcurrency) {
            queue(new CoordActionReadyXCommand(jobId));
        }
        return null;
    } catch (XException ex) {
        throw new CommandException(ex);
    } finally {
        LOG.info("ENDED CoordChangeXCommand for jobId=" + jobId);
        // update bundle action
        if (coordJob.getBundleId() != null) {
            // ignore pending as it'sync command
            BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus, true);
            bundleStatusUpdate.call();
        }
    }
}
Also used : BundleStatusUpdateXCommand(org.apache.oozie.command.bundle.BundleStatusUpdateXCommand) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) Date(java.util.Date)

Example 2 with CoordJobQuery

use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.

the class CoordResumeXCommand method updateJob.

@Override
public void updateJob() {
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    coordJob.setSuspendedTime(null);
    coordJob.setLastModifiedTime(new Date());
    LOG.debug("Resume coordinator job id = " + jobId + ", status = " + coordJob.getStatus() + ", pending = " + coordJob.isPending());
    updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
Also used : CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) Date(java.util.Date)

Example 3 with CoordJobQuery

use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.

the class CoordSuspendXCommand method updateJob.

@Override
public void updateJob() {
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    coordJob.setLastModifiedTime(new Date());
    coordJob.setSuspendedTime(new Date());
    LOG.debug("Suspend coordinator job id = " + jobId + ", status = " + coordJob.getStatus() + ", pending = " + coordJob.isPending());
    updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
}
Also used : CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery) Date(java.util.Date)

Example 4 with CoordJobQuery

use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.

the class CoordSuspendXCommand method suspendChildren.

@Override
public void suspendChildren() throws CommandException {
    try {
        // Get all running actions of a job to suspend them
        List<CoordinatorActionBean> actionList = jpaService.execute(new CoordJobGetActionsRunningJPAExecutor(jobId));
        for (CoordinatorActionBean action : actionList) {
            // queue a SuspendXCommand
            if (action.getExternalId() != null) {
                queue(new SuspendXCommand(action.getExternalId()));
                updateCoordAction(action);
                LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and queue SuspendXCommand for [{3}]", action.getId(), action.getStatus(), action.getPending(), action.getExternalId());
            } else {
                updateCoordAction(action);
                LOG.debug("Suspend coord action = [{0}], new status = [{1}], pending = [{2}] and external id is null", action.getId(), action.getStatus(), action.getPending());
            }
        }
        LOG.debug("Suspended coordinator actions for the coordinator=[{0}]", jobId);
    } catch (XException ex) {
        exceptionOccured = true;
        throw new CommandException(ex);
    } finally {
        if (exceptionOccured) {
            coordJob.setStatus(CoordinatorJob.Status.FAILED);
            coordJob.resetPending();
            LOG.debug("Exception happened, fail coordinator job id = " + jobId + ", status = " + coordJob.getStatus());
            updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_PENDING_TIME, coordJob));
        }
    }
}
Also used : SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) CoordJobGetActionsRunningJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionsRunningJPAExecutor) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

Example 5 with CoordJobQuery

use of org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery in project oozie by apache.

the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDelete.

public void testExecuteBatchUpdateInsertDelete() throws Exception {
    BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
    // for update
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
    WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
    // for insert
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    coordAction.setId("testCoordAction1");
    JPAService jpaService = Services.get().get(JPAService.class);
    // update the status
    coordJob.setStatus(CoordinatorJob.Status.RUNNING);
    wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
    // update the list for doing bulk writes
    List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
    updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_MODTIME, coordJob));
    updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob));
    // insert beans
    Collection<JsonBean> insertList = new ArrayList<JsonBean>();
    insertList.add(coordAction);
    // delete beans
    Collection<JsonBean> deleteList = new ArrayList<JsonBean>();
    deleteList.add(wfAction);
    BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, deleteList);
    // check update after running ExecuteBatchUpdateInsertDelete
    coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coordJob.getId());
    assertEquals("RUNNING", coordJob.getStatusStr());
    wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, wfJob.getId());
    assertEquals("SUCCEEDED", wfJob.getStatusStr());
    coordAction = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordAction.getId());
    assertEquals("testCoordAction1", coordAction.getId());
    try {
        wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfJob.getId());
        fail();
    } catch (JPAExecutorException ex) {
        assertEquals(ex.getErrorCode().toString(), "E0605");
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) JsonBean(org.apache.oozie.client.rest.JsonBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) JPAService(org.apache.oozie.service.JPAService) CoordJobQuery(org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)

Aggregations

CoordJobQuery (org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)7 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)4 Date (java.util.Date)3 XException (org.apache.oozie.XException)3 CommandException (org.apache.oozie.command.CommandException)3 ArrayList (java.util.ArrayList)2 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)2 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)2 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)2 JsonBean (org.apache.oozie.client.rest.JsonBean)2 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)2 JPAService (org.apache.oozie.service.JPAService)2 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 BundleActionBean (org.apache.oozie.BundleActionBean)1 BundleJobBean (org.apache.oozie.BundleJobBean)1 BundleStatusUpdateXCommand (org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)1 ResumeXCommand (org.apache.oozie.command.wf.ResumeXCommand)1 SuspendXCommand (org.apache.oozie.command.wf.SuspendXCommand)1 UpdateEntry (org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry)1