Search in sources :

Example 1 with CoordPullInputDependency

use of org.apache.oozie.coord.input.dependency.CoordPullInputDependency in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method getInputDependencies.

/**
 * Get input dependencies.
 *
 * @param name the name
 * @param syncCoordAction the sync coord action
 * @return the string
 * @throws JDOMException the JDOM exception
 */
public String getInputDependencies(String name, SyncCoordAction syncCoordAction) throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    ELEvaluator eval = ELEvaluator.getCurrent();
    coordAction.setId(syncCoordAction.getActionId());
    Element eJob = XmlUtils.parseXml(eval.getVariable(".actionInputLogic").toString());
    String expression = new InputLogicParser().parseWithName(eJob, name);
    Expression e = jexl.createExpression(expression);
    CoordPullInputDependency pull = (CoordPullInputDependency) syncCoordAction.getPullDependencies();
    CoordPushInputDependency push = (CoordPushInputDependency) syncCoordAction.getPushDependencies();
    coordAction.setPushInputDependencies(push);
    coordAction.setPullInputDependencies(pull);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseThree(coordAction, eval)));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    if (result == null || !result.isTrue()) {
        log.debug("Input logic expression for [{0}] is [{1}] and it is not resolved", name, expression);
        return "${coord:dataIn('" + name + "')}";
    } else {
        log.debug("Input logic expression for [{0}] is [{1}] and evaluate result is [{2}]", name, expression, result.getStatus());
        return result.getDataSets();
    }
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Element(org.jdom.Element) CoordPullInputDependency(org.apache.oozie.coord.input.dependency.CoordPullInputDependency) JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordPushInputDependency(org.apache.oozie.coord.input.dependency.CoordPushInputDependency)

Example 2 with CoordPullInputDependency

use of org.apache.oozie.coord.input.dependency.CoordPullInputDependency in project oozie by apache.

the class CoordInputLogicEvaluatorPhaseTwo method evalInput.

@Override
public CoordInputLogicEvaluatorResult evalInput(String dataSet, int min, int wait) {
    try {
        CoordPullInputDependency coordPullInputDependency = (CoordPullInputDependency) coordInputDependency;
        ELEvaluator eval = CoordELEvaluator.createLazyEvaluator(actualTime, coordAction.getNominalTime(), getInputSetEvent(dataSet), getConf());
        if (coordPullInputDependency.getUnResolvedDependency(dataSet) == null) {
            return super.evalInput(dataSet, min, wait);
        } else {
            cleanPreviousCheckData(coordPullInputDependency, dataSet);
            List<String> unresolvedList = coordPullInputDependency.getUnResolvedDependency(dataSet).getDependencies();
            for (String unresolved : unresolvedList) {
                String resolvedPath = "";
                CoordELFunctions.evalAndWrap(eval, unresolved);
                boolean isResolved = (Boolean) eval.getVariable(CoordELConstants.IS_RESOLVED);
                coordPullInputDependency.setDependencyMap(dependencyMap);
                if (eval.getVariable(CoordELConstants.RESOLVED_PATH) != null) {
                    resolvedPath = eval.getVariable(CoordELConstants.RESOLVED_PATH).toString();
                }
                if (resolvedPath != null) {
                    resolvedPath = getEvalResult(isResolved, min, wait, Arrays.asList(DependencyChecker.dependenciesAsArray(resolvedPath.toString()))).getDataSets();
                }
                log.trace(MessageFormat.format("Return data is {0}", resolvedPath));
                log.debug(MessageFormat.format("Resolved status of Data set {0} with min {1} and wait {2}  =  {3}", dataSet, min, wait, !StringUtils.isEmpty(resolvedPath)));
                if ((isInputWaitElapsed(wait) || isResolved) && !StringUtils.isEmpty(resolvedPath)) {
                    coordPullInputDependency.addResolvedList(dataSet, resolvedPath.toString());
                } else {
                    cleanPreviousCheckData(coordPullInputDependency, dataSet);
                    if (!isInputWaitElapsed(wait)) {
                        return new CoordInputLogicEvaluatorResult(CoordInputLogicEvaluatorResult.STATUS.TIMED_WAITING);
                    } else {
                        return new CoordInputLogicEvaluatorResult(CoordInputLogicEvaluatorResult.STATUS.FALSE);
                    }
                }
            }
            coordPullInputDependency.getUnResolvedDependency(dataSet).setResolved(true);
            return new CoordInputLogicEvaluatorResult(STATUS.TRUE, getListAsString(coordPullInputDependency.getUnResolvedDependency(dataSet).getResolvedList(), dataSet));
        }
    } catch (Exception e) {
        throw new RuntimeException(" event not found" + e, e);
    }
}
Also used : CoordPullInputDependency(org.apache.oozie.coord.input.dependency.CoordPullInputDependency) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) JDOMException(org.jdom.JDOMException)

Aggregations

CoordPullInputDependency (org.apache.oozie.coord.input.dependency.CoordPullInputDependency)2 ELEvaluator (org.apache.oozie.util.ELEvaluator)2 Expression (org.apache.commons.jexl2.Expression)1 JexlContext (org.apache.commons.jexl2.JexlContext)1 JexlEngine (org.apache.commons.jexl2.JexlEngine)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordELEvaluator (org.apache.oozie.coord.CoordELEvaluator)1 CoordPushInputDependency (org.apache.oozie.coord.input.dependency.CoordPushInputDependency)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1