Search in sources :

Example 1 with CoordJobGetActionForNominalTimeJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetActionForNominalTimeJPAExecutor 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)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 XException (org.apache.oozie.XException)1 CommandException (org.apache.oozie.command.CommandException)1 CoordJobGetActionForNominalTimeJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetActionForNominalTimeJPAExecutor)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 JPAService (org.apache.oozie.service.JPAService)1