Search in sources :

Example 11 with CommandException

use of org.apache.oozie.command.CommandException 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 12 with CommandException

use of org.apache.oozie.command.CommandException 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 13 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class BundleJobResumeXCommand method loadState.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#loadState()
     */
@Override
protected void loadState() throws CommandException {
    jpaService = Services.get().get(JPAService.class);
    if (jpaService == null) {
        throw new CommandException(ErrorCode.E0610);
    }
    try {
        bundleJob = BundleJobQueryExecutor.getInstance().get(BundleJobQuery.GET_BUNDLE_JOB, bundleId);
        bundleActions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, bundleId);
    } catch (Exception Ex) {
        throw new CommandException(ErrorCode.E0604, bundleId);
    }
    LogUtils.setLogInfo(bundleJob);
}
Also used : CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 14 with CommandException

use of org.apache.oozie.command.CommandException 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 15 with CommandException

use of org.apache.oozie.command.CommandException in project oozie by apache.

the class BundleSubmitXCommand method submit.

/* (non-Javadoc)
     * @see org.apache.oozie.command.SubmitTransitionXCommand#submit()
     */
@Override
protected String submit() throws CommandException {
    LOG.info("STARTED Bundle Submit");
    try {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        ParameterVerifier.verifyParameters(conf, XmlUtils.parseXml(bundleBean.getOrigJobXml()));
        String jobXmlWithNoComment = XmlUtils.removeComments(this.bundleBean.getOrigJobXml().toString());
        // Resolving all variables in the job properties.
        // This ensures the Hadoop Configuration semantics is preserved.
        XConfiguration resolvedVarsConf = new XConfiguration();
        for (Map.Entry<String, String> entry : conf) {
            resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
        }
        conf = resolvedVarsConf;
        String resolvedJobXml = resolvedVarsandFunctions(jobXmlWithNoComment, conf);
        // verify the uniqueness of coord names
        verifyCoordNameUnique(resolvedJobXml);
        this.jobId = storeToDB(bundleBean, resolvedJobXml);
        LogUtils.setLogInfo(bundleBean);
        if (dryrun) {
            Date startTime = bundleBean.getStartTime();
            long startTimeMilli = startTime.getTime();
            long endTimeMilli = startTimeMilli + (3600 * 1000);
            Date jobEndTime = bundleBean.getEndTime();
            Date endTime = new Date(endTimeMilli);
            if (endTime.compareTo(jobEndTime) > 0) {
                endTime = jobEndTime;
            }
            jobId = bundleBean.getId();
            LOG.info("[" + jobId + "]: Update status to PREP");
            bundleBean.setStatus(Job.Status.PREP);
            try {
                new XConfiguration(new StringReader(bundleBean.getConf()));
            } catch (IOException e1) {
                LOG.warn("Configuration parse error. read from DB :" + bundleBean.getConf(), e1);
            }
            String output = bundleBean.getJobXml() + System.getProperty("line.separator");
            return output;
        } else {
            if (bundleBean.getKickoffTime() == null) {
                // If there is no KickOffTime, default kickoff is NOW.
                LOG.debug("Since kickoff time is not defined for job id " + jobId + ". Queuing and BundleStartXCommand immediately after submission");
                queue(new BundleStartXCommand(jobId));
            }
        }
    } catch (Exception ex) {
        throw new CommandException(ErrorCode.E1310, ex.getMessage(), ex);
    }
    LOG.info("ENDED Bundle Submit");
    return this.jobId;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) Map(java.util.Map) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException)

Aggregations

CommandException (org.apache.oozie.command.CommandException)225 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)85 XConfiguration (org.apache.oozie.util.XConfiguration)62 Date (java.util.Date)59 IOException (java.io.IOException)57 Configuration (org.apache.hadoop.conf.Configuration)56 JPAService (org.apache.oozie.service.JPAService)56 XException (org.apache.oozie.XException)42 PreconditionException (org.apache.oozie.command.PreconditionException)35 ArrayList (java.util.ArrayList)26 StringReader (java.io.StringReader)25 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)24 List (java.util.List)23 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)23 Element (org.jdom.Element)23 JDOMException (org.jdom.JDOMException)20 File (java.io.File)16 HadoopAccessorException (org.apache.oozie.service.HadoopAccessorException)16 WorkflowException (org.apache.oozie.workflow.WorkflowException)16 URISyntaxException (java.net.URISyntaxException)14