Search in sources :

Example 56 with CommandException

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

the class CoordSubmitXCommand method submitJob.

protected String submitJob() throws CommandException {
    String jobId = null;
    InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
    boolean exceptionOccured = false;
    try {
        mergeDefaultConfig();
        String appXml = readAndValidateXml();
        coordJob.setOrigJobXml(appXml);
        LOG.debug("jobXml after initial validation " + XmlUtils.prettyPrint(appXml).toString());
        Element eXml = XmlUtils.parseXml(appXml);
        String appNamespace = readAppNamespace(eXml);
        coordJob.setAppNamespace(appNamespace);
        ParameterVerifier.verifyParameters(conf, eXml);
        appXml = XmlUtils.removeComments(appXml);
        initEvaluators();
        Element eJob = basicResolveAndIncludeDS(appXml, conf, coordJob);
        validateCoordinatorJob();
        // checking if the coordinator application data input/output events
        // specify multiple data instance values in erroneous manner
        checkMultipleTimeInstances(eJob, COORD_INPUT_EVENTS, COORD_INPUT_EVENTS_DATA_IN);
        checkMultipleTimeInstances(eJob, COORD_OUTPUT_EVENTS, COORD_OUTPUT_EVENTS_DATA_OUT);
        LOG.debug("jobXml after all validation " + XmlUtils.prettyPrint(eJob).toString());
        jobId = storeToDB(appXml, eJob, coordJob);
        // log job info for coordinator job
        LogUtils.setLogInfo(coordJob);
        if (!dryrun) {
            queueMaterializeTransitionXCommand(jobId);
        } else {
            return getDryRun(coordJob);
        }
    } catch (JDOMException jex) {
        exceptionOccured = true;
        LOG.warn("ERROR: ", jex);
        throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
    } catch (CoordinatorJobException cex) {
        exceptionOccured = true;
        LOG.warn("ERROR:  ", cex);
        throw new CommandException(cex);
    } catch (ParameterVerifierException pex) {
        exceptionOccured = true;
        LOG.warn("ERROR: ", pex);
        throw new CommandException(pex);
    } catch (IllegalArgumentException iex) {
        exceptionOccured = true;
        LOG.warn("ERROR:  ", iex);
        throw new CommandException(ErrorCode.E1003, iex.getMessage(), iex);
    } catch (Exception ex) {
        exceptionOccured = true;
        LOG.warn("ERROR:  ", ex);
        throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
    } finally {
        if (exceptionOccured) {
            if (coordJob.getId() == null || coordJob.getId().equalsIgnoreCase("")) {
                coordJob.setStatus(CoordinatorJob.Status.FAILED);
                coordJob.resetPending();
            }
        }
    }
    return jobId;
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom.Element) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) 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) IOException(java.io.IOException) ParameterVerifierException(org.apache.oozie.util.ParameterVerifierException)

Example 57 with CommandException

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

the class CoordSubmitXCommand method storeToDB.

/**
 * Write a coordinator job into database
 *
 *@param appXML : Coordinator definition xml
 * @param eJob : XML element of job
 * @param coordJob : Coordinator job bean
 * @return Job id
 * @throws CommandException thrown if unable to save coordinator job to db
 */
protected String storeToDB(String appXML, Element eJob, CoordinatorJobBean coordJob) throws CommandException {
    String jobId = Services.get().get(UUIDService.class).generateId(ApplicationType.COORDINATOR);
    coordJob.setId(jobId);
    coordJob.setAppPath(conf.get(OozieClient.COORDINATOR_APP_PATH));
    coordJob.setCreatedTime(new Date());
    coordJob.setUser(conf.get(OozieClient.USER_NAME));
    String group = ConfigUtils.getWithDeprecatedCheck(conf, OozieClient.JOB_ACL, OozieClient.GROUP_NAME, null);
    coordJob.setGroup(group);
    coordJob.setConf(XmlUtils.prettyPrint(conf).toString());
    coordJob.setJobXml(XmlUtils.prettyPrint(eJob).toString());
    coordJob.setLastActionNumber(0);
    coordJob.setLastModifiedTime(new Date());
    if (!dryrun) {
        coordJob.setLastModifiedTime(new Date());
        try {
            CoordJobQueryExecutor.getInstance().insert(coordJob);
        } catch (JPAExecutorException jpaee) {
            coordJob.setId(null);
            coordJob.setStatus(CoordinatorJob.Status.FAILED);
            throw new CommandException(jpaee);
        }
    }
    return jobId;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) UUIDService(org.apache.oozie.service.UUIDService) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

Example 58 with CommandException

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

the class CoordSuspendXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    super.eagerLoadState();
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            this.coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB_SUSPEND_KILL, this.jobId);
            prevStatus = coordJob.getStatus();
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (Exception ex) {
        throw new CommandException(ErrorCode.E0603, ex.getMessage(), ex);
    }
    LogUtils.setLogInfo(this.coordJob);
}
Also used : CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 59 with CommandException

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

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

the class CoordUpdateXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    super.loadState();
    jpaService = Services.get().get(JPAService.class);
    if (jpaService == null) {
        throw new CommandException(ErrorCode.E0610);
    }
    coordJob = new CoordinatorJobBean();
    try {
        oldCoordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, jobId);
    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    }
    LogUtils.setLogInfo(oldCoordJob);
    if (!isConfChange || StringUtils.isEmpty(conf.get(OozieClient.COORDINATOR_APP_PATH))) {
        try {
            XConfiguration jobConf = new XConfiguration(new StringReader(oldCoordJob.getConf()));
            if (!isConfChange) {
                conf = jobConf;
            } else {
                for (String bundleConfKey : bundleConfList) {
                    if (jobConf.get(bundleConfKey) != null) {
                        conf.set(bundleConfKey, jobConf.get(bundleConfKey));
                    }
                }
                if (StringUtils.isEmpty(conf.get(OozieClient.COORDINATOR_APP_PATH))) {
                    conf.set(OozieClient.COORDINATOR_APP_PATH, jobConf.get(OozieClient.COORDINATOR_APP_PATH));
                }
            }
        } catch (Exception e) {
            throw new CommandException(ErrorCode.E1023, e.getMessage(), e);
        }
    }
    coordJob.setConf(XmlUtils.prettyPrint(conf).toString());
    setJob(coordJob);
    LogUtils.setLogInfo(coordJob);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

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