Search in sources :

Example 36 with XException

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

the class XCommand method call.

/**
 * Implements the XCommand life-cycle.
 *
 * @return the {link #execute} return value.
 * @throws CommandException thrown if the command could not be executed.
 */
@Override
public final T call() throws CommandException {
    setLogInfo();
    CallableQueueService callableQueueService = Services.get().get(CallableQueueService.class);
    Set<String> interruptTypes = callableQueueService.getInterruptTypes();
    if (interruptTypes.contains(this.getType()) && used.get()) {
        LOG.debug("Command [{0}] key [{1}]  already used for [{2}]", getName(), getEntityKey(), this.toString());
        return null;
    }
    commandQueue = null;
    instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".executions", 1);
    Instrumentation.Cron callCron = new Instrumentation.Cron();
    try {
        callCron.start();
        eagerLoadState();
        eagerVerifyPrecondition();
        try {
            T ret = null;
            if (isLockRequired() && !this.inInterruptMode()) {
                Instrumentation.Cron acquireLockCron = new Instrumentation.Cron();
                acquireLockCron.start();
                acquireLock();
                acquireLockCron.stop();
                instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".acquireLock", acquireLockCron);
            }
            // executing interrupts only in case of the lock required commands
            if (lock != null) {
                this.executeInterrupts();
            }
            if (!isLockRequired() || (lock != null) || this.inInterruptMode()) {
                if (interruptTypes.contains(this.getType()) && !used.compareAndSet(false, true)) {
                    LOG.debug("Command [{0}] key [{1}]  already executed for [{2}]", getName(), getEntityKey(), this.toString());
                    return null;
                }
                LOG.trace("Load state for [{0}]", getEntityKey());
                loadState();
                LOG.trace("Precondition check for command [{0}] key [{1}]", getName(), getEntityKey());
                verifyPrecondition();
                LOG.debug("Execute command [{0}] key [{1}]", getName(), getEntityKey());
                Instrumentation.Cron executeCron = new Instrumentation.Cron();
                executeCron.start();
                ret = execute();
                executeCron.stop();
                instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".execute", executeCron);
            }
            if (commandQueue != null) {
                for (Map.Entry<Long, List<XCommand<?>>> entry : commandQueue.entrySet()) {
                    LOG.debug("Queuing [{0}] commands with delay [{1}]ms", entry.getValue().size(), entry.getKey());
                    if (!callableQueueService.queueSerial(entry.getValue(), entry.getKey())) {
                        LOG.warn("Could not queue [{0}] commands with delay [{1}]ms, queue full", entry.getValue().size(), entry.getKey());
                    }
                }
            }
            return ret;
        } finally {
            if (isLockRequired() && !this.inInterruptMode()) {
                releaseLock();
            }
        }
    } catch (PreconditionException pex) {
        LOG.warn(pex.getMessage().toString() + ", Error Code: " + pex.getErrorCode().toString());
        instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".preconditionfailed", 1);
        return null;
    } catch (XException ex) {
        LOG.error("XException, ", ex);
        instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".xexceptions", 1);
        if (ex instanceof CommandException) {
            throw (CommandException) ex;
        } else {
            throw new CommandException(ex);
        }
    } catch (Exception ex) {
        LOG.error("Exception, ", ex);
        instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".exceptions", 1);
        throw new CommandException(ErrorCode.E0607, getName(), ex.getMessage(), ex);
    } catch (Error er) {
        LOG.error("Error, ", er);
        instrumentation.incr(INSTRUMENTATION_GROUP, getName() + ".errors", 1);
        throw er;
    } finally {
        FaultInjection.deactivate("org.apache.oozie.command.SkipCommitFaultInjection");
        callCron.stop();
        instrumentation.addCron(INSTRUMENTATION_GROUP, getName() + ".call", callCron);
    }
}
Also used : CallableQueueService(org.apache.oozie.service.CallableQueueService) Instrumentation(org.apache.oozie.util.Instrumentation) XException(org.apache.oozie.XException) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with XException

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

the class CoordUtils method getCoordActionsFromDates.

/**
 * Get the list of actions for given date ranges
 *
 * @param jobId coordinator job id
 * @param scope a comma-separated list of date ranges. Each date range element is specified with two dates separated by '::'
 * @return the list of Coordinator actions for the date range
 * @throws CommandException thrown if failed to get coordinator actions by given date range
 */
@VisibleForTesting
public static List<CoordinatorActionBean> getCoordActionsFromDates(String jobId, String scope, boolean active) throws CommandException {
    JPAService jpaService = Services.get().get(JPAService.class);
    ParamChecker.notEmpty(jobId, "jobId");
    ParamChecker.notEmpty(scope, "scope");
    Set<CoordinatorActionBean> actionSet = new LinkedHashSet<CoordinatorActionBean>();
    String[] list = scope.split(",");
    for (String s : list) {
        s = s.trim();
        // A date range is specified with two dates separated by '::'
        if (s.contains("::")) {
            List<CoordinatorActionBean> listOfActions;
            try {
                // Get list of actions within the range of date
                listOfActions = CoordActionsInDateRange.getCoordActionsFromDateRange(jobId, s, active);
            } catch (XException e) {
                throw new CommandException(e);
            }
            actionSet.addAll(listOfActions);
        } else {
            try {
                // Get action for the nominal time
                Date date = DateUtils.parseDateOozieTZ(s.trim());
                CoordinatorActionBean coordAction = jpaService.execute(new CoordJobGetActionForNominalTimeJPAExecutor(jobId, date));
                if (coordAction != null) {
                    actionSet.add(coordAction);
                } else {
                    throw new RuntimeException("This should never happen, Coordinator Action shouldn't be null");
                }
            } catch (ParseException e) {
                throw new CommandException(ErrorCode.E0302, s.trim(), e);
            } catch (JPAExecutorException e) {
                if (e.getErrorCode() == ErrorCode.E0605) {
                    XLog.getLog(CoordUtils.class).info("No action for nominal time:" + s + ". Skipping over");
                }
                throw new CommandException(e);
            }
        }
    }
    List<CoordinatorActionBean> coordActions = new ArrayList<CoordinatorActionBean>();
    for (CoordinatorActionBean coordAction : actionSet) {
        coordActions.add(coordAction);
    }
    return coordActions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) XException(org.apache.oozie.XException) ParseException(java.text.ParseException) JPAService(org.apache.oozie.service.JPAService) CoordJobGetActionForNominalTimeJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionForNominalTimeJPAExecutor) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 38 with XException

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

the class KillXCommand 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_KILL, wfId);
            this.actionList = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
            LogUtils.setLogInfo(wfJob);
        } else {
            throw new CommandException(ErrorCode.E0610);
        }
        actionService = Services.get().get(ActionService.class);
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) ActionService(org.apache.oozie.service.ActionService)

Example 39 with XException

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

the class SignalXCommand 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, jobId);
            LogUtils.setLogInfo(wfJob);
            if (actionId != null) {
                this.wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_SIGNAL, actionId);
                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)

Example 40 with XException

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

the class CoordActionsInDateRange method getCoordActionIdsFromDateRange.

/**
 * Get the coordinator actions for a given date range
 * @param jobId the coordinator job id
 * @param range the date range separated by '::'
 * @return the list of Coordinator actions for the date range
 * @throws XException if range is not well formatted or invalid
 */
public static List<String> getCoordActionIdsFromDateRange(String jobId, String range) throws XException {
    String[] dateRange = range.split("::");
    // This block checks for errors in the format of specifying date range
    if (dateRange.length != 2) {
        throw new XException(ErrorCode.E0308, "'" + range + "'. Date value expected on both sides of the scope resolution operator '::' to signify start and end of range");
    }
    Date start;
    Date end;
    try {
        // Get the start and end dates for the range
        start = DateUtils.parseDateOozieTZ(dateRange[0].trim());
        end = DateUtils.parseDateOozieTZ(dateRange[1].trim());
    } catch (ParseException dx) {
        throw new XException(ErrorCode.E0308, "Error in parsing start or end date. " + dx);
    }
    if (start.after(end)) {
        throw new XException(ErrorCode.E0308, "'" + range + "'. Start date '" + start + "' is older than end date: '" + end + "'");
    }
    List<CoordinatorActionBean> listOfActions = CoordActionQueryExecutor.getInstance().getList(CoordActionQuery.GET_TERMINATED_ACTIONS_FOR_DATES, jobId, start, end);
    List<String> idsList = new ArrayList<String>();
    for (CoordinatorActionBean bean : listOfActions) {
        idsList.add(bean.getId());
    }
    return idsList;
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) Date(java.util.Date)

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