Search in sources :

Example 1 with BundleStatusUpdateXCommand

use of org.apache.oozie.command.bundle.BundleStatusUpdateXCommand 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 BundleStatusUpdateXCommand

use of org.apache.oozie.command.bundle.BundleStatusUpdateXCommand in project oozie by apache.

the class CoordPauseXCommand method notifyParent.

/* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#notifyParent()
     */
@Override
public void notifyParent() throws CommandException {
    // update bundle action
    if (coordJob.getBundleId() != null) {
        BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus);
        bundleStatusUpdate.call();
    }
}
Also used : BundleStatusUpdateXCommand(org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)

Example 3 with BundleStatusUpdateXCommand

use of org.apache.oozie.command.bundle.BundleStatusUpdateXCommand in project oozie by apache.

the class CoordMaterializeTransitionXCommand method notifyParent.

/* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#notifyParent()
     */
@Override
public void notifyParent() throws CommandException {
    // update bundle action only when status changes in coord job
    if (this.coordJob.getBundleId() != null) {
        if (!prevStatus.equals(coordJob.getStatus())) {
            BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus);
            bundleStatusUpdate.call();
        }
    }
}
Also used : BundleStatusUpdateXCommand(org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)

Example 4 with BundleStatusUpdateXCommand

use of org.apache.oozie.command.bundle.BundleStatusUpdateXCommand in project oozie by apache.

the class CoordSubmitXCommand method notifyParent.

/* (non-Javadoc)
     * @see org.apache.oozie.command.TransitionXCommand#notifyParent()
     */
@Override
public void notifyParent() throws CommandException {
    // update bundle action
    if (coordJob.getBundleId() != null) {
        LOG.debug("Updating bundle record: " + coordJob.getBundleId() + " for coord id: " + coordJob.getId());
        BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus);
        bundleStatusUpdate.call();
    }
}
Also used : BundleStatusUpdateXCommand(org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)

Example 5 with BundleStatusUpdateXCommand

use of org.apache.oozie.command.bundle.BundleStatusUpdateXCommand in project oozie by apache.

the class CoordSuspendXCommand method notifyParent.

@Override
public void notifyParent() throws CommandException {
    // update bundle action
    if (this.coordJob.getBundleId() != null) {
        BundleStatusUpdateXCommand bundleStatusUpdate = new BundleStatusUpdateXCommand(coordJob, prevStatus);
        bundleStatusUpdate.call();
    }
}
Also used : BundleStatusUpdateXCommand(org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)

Aggregations

BundleStatusUpdateXCommand (org.apache.oozie.command.bundle.BundleStatusUpdateXCommand)10 Date (java.util.Date)2 XException (org.apache.oozie.XException)1 Job (org.apache.oozie.client.Job)1 Status (org.apache.oozie.client.Job.Status)1 CommandException (org.apache.oozie.command.CommandException)1 CoordJobQuery (org.apache.oozie.executor.jpa.CoordJobQueryExecutor.CoordJobQuery)1