Search in sources :

Example 6 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project rubia-forums by flashboss.

the class ForumsACLResource method evaluate.

public boolean evaluate() {
    boolean isCriteriaMet = true;
    if (criteria != null) {
        try {
            JexlEngine jexl = new JexlEngine();
            JexlContext context2 = new MapContext();
            if (criteria != null) {
                Expression expression = jexl.createExpression(criteria);
                context2.set("param", map.get("runtimeInfo"));
                context2.set("identity", map.get("identity"));
                Object value = expression.evaluate(context2);
                isCriteriaMet = ((Boolean) value).booleanValue();
            }
        } catch (Exception e) {
            log.error(e);
            isCriteriaMet = false;
        }
    }
    return isCriteriaMet;
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 7 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkPullMissingDependencies.

/**
 * Check pull missing dependencies.
 *
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkPullMissingDependencies() throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseOne(coordAction, coordAction.getPullInputDependencies())));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 8 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkPushDependencies.

/**
 * Check push dependencies.
 *
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkPushDependencies() throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseOne(coordAction, coordAction.getPushInputDependencies())));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 9 with JexlContext

use of org.apache.commons.jexl2.JexlContext in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkUnResolved.

/**
 * Check unresolved.
 *
 * @param actualTime the actual time
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkUnResolved(Date actualTime) throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseTwo(coordAction, actualTime)));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 10 with JexlContext

use of org.apache.commons.jexl2.JexlContext 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)

Aggregations

JexlContext (org.apache.commons.jexl2.JexlContext)31 Expression (org.apache.commons.jexl2.Expression)25 MapContext (org.apache.commons.jexl2.MapContext)23 JexlContext (org.apache.commons.jexl3.JexlContext)21 JexlEngine (org.apache.commons.jexl2.JexlEngine)20 MapContext (org.apache.commons.jexl3.MapContext)17 Test (org.testng.annotations.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 JexlException (org.apache.commons.jexl2.JexlException)3 ObjectContext (org.apache.commons.jexl2.ObjectContext)3 IOException (java.io.IOException)2 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)2 JexlScript (org.apache.commons.jexl3.JexlScript)2 NumberUtils (org.apache.commons.lang.math.NumberUtils)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2 IntWritable (org.apache.hadoop.io.IntWritable)2 Text (org.apache.hadoop.io.Text)2 VersionMismatchException (org.apache.hadoop.io.VersionMismatchException)2