Search in sources :

Example 61 with CommandException

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

the class CoordUpdateXCommand method storeToDB.

@Override
protected String storeToDB(String xmlElement, Element eJob, CoordinatorJobBean coordJob) throws CommandException {
    check(oldCoordJob, coordJob);
    computeDiff(eJob);
    oldCoordJob.setAppPath(conf.get(OozieClient.COORDINATOR_APP_PATH));
    if (isConfChange) {
        oldCoordJob.setConf(XmlUtils.prettyPrint(conf).toString());
    }
    oldCoordJob.setMatThrottling(coordJob.getMatThrottling());
    oldCoordJob.setOrigJobXml(xmlElement);
    oldCoordJob.setConcurrency(coordJob.getConcurrency());
    oldCoordJob.setExecution(coordJob.getExecution());
    oldCoordJob.setTimeout(coordJob.getTimeout());
    oldCoordJob.setJobXml(XmlUtils.prettyPrint(eJob).toString());
    if (!dryrun) {
        oldCoordJob.setLastModifiedTime(new Date());
        // Should log the changes, this should be useful for debugging.
        LOG.info("Coord update changes : " + diff.toString());
        try {
            CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, oldCoordJob);
        } catch (JPAExecutorException jpaee) {
            throw new CommandException(jpaee);
        }
    }
    return jobId;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

Example 62 with CommandException

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

the class CoordActionCheckXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected Void execute() throws CommandException {
    try {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        Status slaStatus = null;
        CoordinatorAction.Status initialStatus = coordAction.getStatus();
        if (workflowJob.getStatus() == WorkflowJob.Status.SUCCEEDED) {
            coordAction.setStatus(CoordinatorAction.Status.SUCCEEDED);
            // set pending to false as the status is SUCCEEDED
            coordAction.setPending(0);
            slaStatus = Status.SUCCEEDED;
        } else {
            if (workflowJob.getStatus() == WorkflowJob.Status.FAILED) {
                coordAction.setStatus(CoordinatorAction.Status.FAILED);
                slaStatus = Status.FAILED;
                // set pending to false as the status is FAILED
                coordAction.setPending(0);
            } else {
                if (workflowJob.getStatus() == WorkflowJob.Status.KILLED) {
                    coordAction.setStatus(CoordinatorAction.Status.KILLED);
                    slaStatus = Status.KILLED;
                    // set pending to false as the status is KILLED
                    coordAction.setPending(0);
                } else if (workflowJob.getStatus() == WorkflowJob.Status.SUSPENDED) {
                    coordAction.setStatus(CoordinatorAction.Status.SUSPENDED);
                    slaStatus = Status.FAILED;
                    // set pending to false as the status is SUSPENDED
                    coordAction.setPending(0);
                } else {
                    LOG.warn("Unexpected workflow " + workflowJob.getId() + " STATUS " + workflowJob.getStatus());
                    coordAction.setLastModifiedTime(new Date());
                    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQueryExecutor.CoordActionQuery.UPDATE_COORD_ACTION_FOR_MODIFIED_DATE, coordAction);
                    return null;
                }
            }
        }
        LOG.debug("Updating Coordinator actionId :" + coordAction.getId() + "status to =" + coordAction.getStatus());
        coordAction.setLastModifiedTime(new Date());
        updateList.add(new UpdateEntry<CoordActionQuery>(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction));
        if (slaStatus != null) {
            SLAEventBean slaEvent = SLADbOperations.createStatusEvent(coordAction.getSlaXml(), coordAction.getId(), slaStatus, SlaAppType.COORDINATOR_ACTION, LOG);
            if (slaEvent != null) {
                insertList.add(slaEvent);
            }
        }
        BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
        CoordinatorAction.Status endStatus = coordAction.getStatus();
        if (endStatus != initialStatus && EventHandlerService.isEnabled()) {
            generateEvent(coordAction, coordJob.getUser(), coordJob.getAppName(), workflowJob.getStartTime());
        }
    } catch (XException ex) {
        LOG.warn("CoordActionCheckCommand Failed ", ex);
        throw new CommandException(ex);
    }
    return null;
}
Also used : Status(org.apache.oozie.client.SLAEvent.Status) XException(org.apache.oozie.XException) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) SLAEventBean(org.apache.oozie.SLAEventBean) CoordActionQuery(org.apache.oozie.executor.jpa.CoordActionQueryExecutor.CoordActionQuery)

Example 63 with CommandException

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

the class CoordActionInputCheckXCommand method checkUnresolvedInstances.

/**
 * Check if any unsolved paths under data output. Resolve the unresolved data input paths.
 *
 * @param eAction action element
 * @param actionConf action configuration
 * @return true if successful to resolve input and output paths
 * @throws Exception thrown if failed to resolve data input and output paths
 */
@SuppressWarnings("unchecked")
private boolean checkUnresolvedInstances(CoordinatorActionBean coordAction, Element eAction, Configuration actionConf) throws Exception {
    boolean ret = coordAction.getPullInputDependencies().checkUnresolved(coordAction, eAction);
    // Using latest() or future() in output-event is not intuitive.
    // We need to make sure, this assumption is correct.
    Element outputList = eAction.getChild("output-events", eAction.getNamespace());
    if (outputList != null) {
        for (Element dEvent : (List<Element>) outputList.getChildren("data-out", eAction.getNamespace())) {
            if (dEvent.getChild(CoordCommandUtils.UNRESOLVED_INSTANCES_TAG, dEvent.getNamespace()) != null) {
                throw new CommandException(ErrorCode.E1006, "coord:latest()/future()", " not permitted in output-event ");
            }
        }
    }
    return ret;
}
Also used : Element(org.jdom.Element) List(java.util.List) CommandException(org.apache.oozie.command.CommandException)

Example 64 with CommandException

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

the class CoordActionNotificationXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    Configuration conf;
    try {
        conf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    } catch (IOException e1) {
        LOG.warn("Configuration parse error. read from DB :" + actionBean.getRunConf());
        throw new CommandException(ErrorCode.E1005, e1.getMessage(), e1);
    }
    url = conf.get(OozieClient.COORD_ACTION_NOTIFICATION_URL);
    if (url != null) {
        url = url.replaceAll(ACTION_ID_PATTERN, actionBean.getId());
        url = url.replaceAll(STATUS_PATTERN, actionBean.getStatus().toString());
        proxyConf = conf.get(OozieClient.COORD_ACTION_NOTIFICATION_PROXY, Services.get().getConf().get(NOTIFICATION_PROXY_KEY));
        LOG.debug("Proxy :" + proxyConf);
    }
    LOG.debug("Notification URL :" + url);
    LogUtils.setLogInfo(actionBean);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 65 with CommandException

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

the class CoordActionSkipXCommand method execute.

@Override
protected Void execute() throws CommandException {
    if (actionBean.getStatus() == CoordinatorAction.Status.WAITING || actionBean.getStatus() == CoordinatorAction.Status.READY) {
        LOG.info("Setting action [{0}] status to SKIPPED", actionBean.getId());
        actionBean.setStatus(CoordinatorAction.Status.SKIPPED);
        try {
            queue(new CoordActionNotificationXCommand(actionBean), 100);
            actionBean.setLastModifiedTime(new Date());
            CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, actionBean);
            if (EventHandlerService.isEnabled()) {
                generateEvent(actionBean, user, appName, null);
            }
        } catch (JPAExecutorException e) {
            throw new CommandException(e);
        }
    }
    return null;
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

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