Search in sources :

Example 1 with XException

use of org.apache.oozie.XException 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 XException

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

the class BundleJobChangeXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    StringBuffer changeReport = new StringBuffer();
    try {
        if (isChangePauseTime || isChangeEndTime) {
            if (isChangePauseTime) {
                bundleJob.setPauseTime(newPauseTime);
            } else if (isChangeEndTime) {
                bundleJob.setEndTime(newEndTime);
                if (bundleJob.getStatus() == Job.Status.SUCCEEDED) {
                    bundleJob.setStatus(Job.Status.RUNNING);
                }
                if (bundleJob.getStatus() == Job.Status.DONEWITHERROR || bundleJob.getStatus() == Job.Status.FAILED) {
                    bundleJob.setStatus(StatusUtils.getStatusIfBackwardSupportTrue(Job.Status.RUNNINGWITHERROR));
                }
            }
            for (BundleActionBean action : this.bundleActions) {
                // queue coord change commands;
                if (action.getStatus() != Job.Status.KILLED && action.getCoordId() != null) {
                    try {
                        new CoordChangeXCommand(action.getCoordId(), changeValue).call();
                    } catch (Exception e) {
                        String errorMsg = action.getCoordId() + " : " + e.getMessage();
                        LOG.info("Change command failed " + errorMsg);
                        changeReport.append("[ ").append(errorMsg).append(" ]");
                    }
                } else {
                    String errorMsg = action.getCoordId() + " : Coord is in killed state";
                    LOG.info("Change command failed " + errorMsg);
                    changeReport.append("[ ").append(errorMsg).append(" ]");
                }
            }
            updateList.add(new UpdateEntry<BundleJobQuery>(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PAUSE_ENDTIME, bundleJob));
            BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
        }
        if (!changeReport.toString().isEmpty()) {
            throw new CommandException(ErrorCode.E1320, changeReport.toString());
        }
        return null;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : BundleJobQuery(org.apache.oozie.executor.jpa.BundleJobQueryExecutor.BundleJobQuery) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) BundleActionBean(org.apache.oozie.BundleActionBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) CoordChangeXCommand(org.apache.oozie.command.coord.CoordChangeXCommand)

Example 3 with XException

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

the class BundleRerunXCommand method loadState.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#loadState()
     */
@Override
protected void loadState() throws CommandException {
    try {
        this.bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, jobId);
        this.bundleActions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, jobId);
        LogUtils.setLogInfo(bundleJob);
        super.setJob(bundleJob);
        prevPending = bundleJob.isPending();
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException)

Example 4 with XException

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

the class PurgeXCommand method loadState.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#loadState()
     */
@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            // Get the lists of workflows, coordinators, and bundles that can be purged (and have no parents)
            int size;
            do {
                size = wfList.size();
                wfList.addAll(jpaService.execute(new WorkflowJobsGetForPurgeJPAExecutor(wfOlderThan, wfList.size(), limit)));
            } while (size != wfList.size());
            if (purgeOldCoordAction) {
                LOG.debug("Purging workflows of long running coordinators is turned on");
                do {
                    size = coordActionList.size();
                    long olderThan = wfOlderThan;
                    List<WorkflowJobBean> jobBeans = WorkflowJobQueryExecutor.getInstance().getList(WorkflowJobQuery.GET_COMPLETED_COORD_WORKFLOWS_OLDER_THAN, olderThan, coordActionList.size(), limit);
                    for (WorkflowJobBean bean : jobBeans) {
                        coordActionList.add(bean.getParentId());
                        wfList.add(bean.getId());
                    }
                } while (size != coordActionList.size());
            }
            do {
                size = coordList.size();
                coordList.addAll(jpaService.execute(new CoordJobsGetForPurgeJPAExecutor(coordOlderThan, coordList.size(), limit)));
            } while (size != coordList.size());
            do {
                size = bundleList.size();
                bundleList.addAll(jpaService.execute(new BundleJobsGetForPurgeJPAExecutor(bundleOlderThan, bundleList.size(), limit)));
            } while (size != bundleList.size());
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : CoordJobsGetForPurgeJPAExecutor(org.apache.oozie.executor.jpa.CoordJobsGetForPurgeJPAExecutor) BundleJobsGetForPurgeJPAExecutor(org.apache.oozie.executor.jpa.BundleJobsGetForPurgeJPAExecutor) XException(org.apache.oozie.XException) WorkflowJobsGetForPurgeJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobsGetForPurgeJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 5 with XException

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

the class TestBundleChangeXCommand method testBundleChangeNegative2.

/**
 * Negative Test : pause time is a past time
 *
 * @throws Exception
 */
public void testBundleChangeNegative2() throws Exception {
    BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
    String dateStr = "2009-01-01T01:00Z";
    JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(job.getId());
    job = jpaService.execute(bundleJobGetCmd);
    assertEquals(job.getPauseTime(), null);
    try {
        new BundleJobChangeXCommand(job.getId(), "pausetime=" + dateStr).call();
        fail("Should not reach here");
    } catch (XException e) {
        assertEquals(ErrorCode.E1317, e.getErrorCode());
    }
}
Also used : BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) XException(org.apache.oozie.XException) JPAService(org.apache.oozie.service.JPAService)

Aggregations

XException (org.apache.oozie.XException)45 CommandException (org.apache.oozie.command.CommandException)32 JPAService (org.apache.oozie.service.JPAService)25 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)8 HashMap (java.util.HashMap)7 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)7 List (java.util.List)6 ParseException (java.text.ParseException)4 BundleJobBean (org.apache.oozie.BundleJobBean)4 SLAEventBean (org.apache.oozie.SLAEventBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Configuration (org.apache.hadoop.conf.Configuration)3 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 PreconditionException (org.apache.oozie.command.PreconditionException)3 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)3 Map (java.util.Map)2 BundleJobInfo (org.apache.oozie.BundleJobInfo)2 CoordinatorJobInfo (org.apache.oozie.CoordinatorJobInfo)2