Search in sources :

Example 81 with CommandException

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

the class CoordRerunXCommand method rerunChildren.

@Override
public void rerunChildren() throws CommandException {
    boolean isError = false;
    try {
        CoordinatorActionInfo coordInfo = null;
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        if (checkAllActionsRunnable(coordActions)) {
            Map<String, Context> uriHandlerContextMap = new HashMap<String, Context>();
            Configuration coordJobConf = null;
            try {
                coordJobConf = new XConfiguration(new StringReader(coordJob.getConf()));
            } catch (IOException e) {
                throw new CommandException(ErrorCode.E0907, "failed to read coord job conf to clean up output data");
            }
            try {
                for (CoordinatorActionBean coordAction : coordActions) {
                    String actionXml = coordAction.getActionXml();
                    // Cleanup activity should not run when failed option has been provided
                    if (!noCleanup && !failed) {
                        Element eAction = XmlUtils.parseXml(actionXml);
                        cleanupOutputEvents(eAction, coordJobConf, uriHandlerContextMap);
                    }
                    if (refresh) {
                        refreshAction(coordJob, coordAction);
                    }
                    updateAction(coordJob, coordAction);
                    if (SLAService.isEnabled()) {
                        SLAOperations.updateRegistrationEvent(coordAction.getId());
                    }
                    queue(new CoordActionNotificationXCommand(coordAction), 100);
                    queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100);
                    if (coordAction.getPushMissingDependencies() != null) {
                        queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100);
                    }
                }
            } finally {
                Iterator<Entry<String, Context>> itr = uriHandlerContextMap.entrySet().iterator();
                while (itr.hasNext()) {
                    Entry<String, Context> entry = itr.next();
                    entry.getValue().destroy();
                    itr.remove();
                }
            }
        } else {
            isError = true;
            throw new CommandException(ErrorCode.E1018, "part or all actions are not eligible to rerun!");
        }
        coordInfo = new CoordinatorActionInfo(coordActions);
        ret = coordInfo;
    } catch (XException xex) {
        isError = true;
        throw new CommandException(xex);
    } catch (JDOMException jex) {
        isError = true;
        throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
    } catch (Exception ex) {
        isError = true;
        throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex);
    } finally {
        if (isError) {
            transitToPrevious();
        }
    }
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) IOException(java.io.IOException) XException(org.apache.oozie.XException) XConfiguration(org.apache.oozie.util.XConfiguration) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) Entry(java.util.Map.Entry) XException(org.apache.oozie.XException) StringReader(java.io.StringReader)

Example 82 with CommandException

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

the class CoordSLAAlertsXCommand method updateJobSLA.

/**
 * Update job sla.
 *
 * @param newParams the new params
 * @throws CommandException the command exception
 */
protected void updateJobSLA(Map<String, String> newParams) throws CommandException {
    try {
        CoordinatorJobBean job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB_XML, getJobId());
        Element eAction;
        try {
            eAction = XmlUtils.parseXml(job.getJobXml());
        } catch (JDOMException e) {
            throw new CommandException(ErrorCode.E1005, e.getMessage(), e);
        }
        Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
        if (newParams != null) {
            if (newParams.get(RestConstants.SLA_NOMINAL_TIME) != null) {
                updateSlaTagElement(eSla, SLAOperations.NOMINAL_TIME, newParams.get(RestConstants.SLA_NOMINAL_TIME));
            }
            if (newParams.get(RestConstants.SLA_SHOULD_START) != null) {
                updateSlaTagElement(eSla, SLAOperations.SHOULD_START, newParams.get(RestConstants.SLA_SHOULD_START));
            }
            if (newParams.get(RestConstants.SLA_SHOULD_END) != null) {
                updateSlaTagElement(eSla, SLAOperations.SHOULD_END, newParams.get(RestConstants.SLA_SHOULD_END));
            }
            if (newParams.get(RestConstants.SLA_MAX_DURATION) != null) {
                updateSlaTagElement(eSla, SLAOperations.MAX_DURATION, newParams.get(RestConstants.SLA_MAX_DURATION));
            }
        }
        String actualXml = XmlUtils.prettyPrint(eAction).toString();
        job.setJobXml(actualXml);
        job.setId(getJobId());
        CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB_XML, job);
    } catch (XException e) {
        throw new CommandException(e);
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) Element(org.jdom.Element) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException)

Example 83 with CommandException

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

the class ActionCheckXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_ACTION_OP, jobId);
        this.wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_CHECK, actionId);
    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    }
    LogUtils.setLogInfo(wfJob);
    LogUtils.setLogInfo(wfAction);
}
Also used : JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException)

Example 84 with CommandException

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

the class ActionCheckXCommand method eagerVerifyPrecondition.

@Override
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException {
    if (wfJob == null) {
        throw new PreconditionException(ErrorCode.E0604, jobId);
    }
    if (wfAction == null) {
        throw new PreconditionException(ErrorCode.E0605, actionId);
    }
    // if the action has been updated, quit this command
    if (actionCheckDelay > 0) {
        Timestamp actionCheckTs = new Timestamp(System.currentTimeMillis() - actionCheckDelay * 1000);
        Timestamp actionLmt = wfAction.getLastCheckTimestamp();
        if (actionLmt.after(actionCheckTs)) {
            throw new PreconditionException(ErrorCode.E0817, actionId);
        }
    }
    executor = Services.get().get(ActionService.class).getExecutor(wfAction.getType());
    if (executor == null) {
        throw new CommandException(ErrorCode.E0802, wfAction.getType());
    }
}
Also used : CommandException(org.apache.oozie.command.CommandException) Timestamp(java.sql.Timestamp) PreconditionException(org.apache.oozie.command.PreconditionException)

Example 85 with CommandException

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

the class ActionEndXCommand method loadState.

@Override
protected void loadState() throws CommandException {
    try {
        jpaService = Services.get().get(JPAService.class);
        if (jpaService != null) {
            this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_ACTION_OP, jobId);
            this.wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_END, actionId);
            LogUtils.setLogInfo(wfJob);
            LogUtils.setLogInfo(wfAction);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

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