Search in sources :

Example 1 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class TestELService method testELForWorkflow.

public void testELForWorkflow() throws Exception {
    assertNotNull(Services.get().get(ELService.class));
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
    assertNotNull(eval.evaluate("${KB}", Long.class));
    assertNotNull(eval.evaluate("${MB}", Long.class));
    assertNotNull(eval.evaluate("${GB}", Long.class));
    assertNotNull(eval.evaluate("${TB}", Long.class));
    assertNotNull(eval.evaluate("${PB}", Long.class));
    assertNotNull(eval.evaluate("${trim(' ')}", String.class));
    assertNotNull(eval.evaluate("${concat('a', 'b')}", String.class));
    assertNotNull(eval.evaluate("${firstNotNull(null, 'b')}", String.class));
    assertNotNull(eval.evaluate("${timestamp()}", String.class));
    assertNotNull(eval.evaluate("${urlEncode('abc')}", String.class));
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 2 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class JavaActionExecutor method getCredProperties.

@SuppressWarnings("unchecked")
protected CredentialsProperties getCredProperties(Context context, String credName) throws Exception {
    CredentialsProperties credProp = null;
    String workflowXml = ((WorkflowJobBean) context.getWorkflow()).getWorkflowInstance().getApp().getDefinition();
    XConfiguration wfjobConf = getWorkflowConf(context);
    Element elementJob = XmlUtils.parseXml(workflowXml);
    Element credentials = elementJob.getChild("credentials", elementJob.getNamespace());
    if (credentials != null) {
        for (Element credential : (List<Element>) credentials.getChildren("credential", credentials.getNamespace())) {
            String name = credential.getAttributeValue("name");
            String type = credential.getAttributeValue("type");
            LOG.debug("getCredProperties: Name: " + name + ", Type: " + type);
            if (name.equalsIgnoreCase(credName)) {
                credProp = new CredentialsProperties(name, type);
                for (Element property : (List<Element>) credential.getChildren("property", credential.getNamespace())) {
                    String propertyName = property.getChildText("name", property.getNamespace());
                    String propertyValue = property.getChildText("value", property.getNamespace());
                    ELEvaluator eval = new ELEvaluator();
                    for (Map.Entry<String, String> entry : wfjobConf) {
                        eval.setVariable(entry.getKey(), entry.getValue().trim());
                    }
                    propertyName = eval.evaluate(propertyName, String.class);
                    propertyValue = eval.evaluate(propertyValue, String.class);
                    credProp.getProperties().put(propertyName, propertyValue);
                    LOG.debug("getCredProperties: Properties name :'" + propertyName + "', Value : '" + propertyValue + "'");
                }
            }
        }
        if (credProp == null && credName != null) {
            throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "JA021", "Could not load credentials with name [{0}]].", credName);
        }
    } else {
        LOG.debug("credentials is null for the action");
    }
    return credProp;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ELEvaluator(org.apache.oozie.util.ELEvaluator) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class DagELFunctions method wf_actionData.

/**
 * Return the action data for an action.
 *
 * @param actionName action name.
 * @return value of the property.
 */
@SuppressWarnings("unchecked")
public static Map<String, String> wf_actionData(String actionName) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    Properties props = (Properties) eval.getVariable(actionName + ACTION_ERROR_MESSAGE);
    if (props == null) {
        String data = getWorkflow().getWorkflowInstance().getVar(actionName + WorkflowInstance.NODE_VAR_SEPARATOR + ACTION_DATA);
        if (data != null) {
            props = PropertiesUtils.stringToProperties(data);
        } else {
            props = new Properties();
        }
        eval.setVariable(actionName + ACTION_ERROR_MESSAGE, props);
    }
    return (Map<String, String>) (Map) props;
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator) Properties(java.util.Properties) Map(java.util.Map)

Example 4 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class CoordActionInputCheckXCommand method resolveCoordConfiguration.

static String resolveCoordConfiguration(StringBuilder actionXml, Configuration actionConf, String actionId, CoordInputDependency pullDependencies, CoordInputDependency pushDependencies) throws Exception {
    Element eAction = XmlUtils.parseXml(actionXml.toString());
    ELEvaluator eval = CoordELEvaluator.createDataEvaluator(eAction, actionConf, actionId, pullDependencies, pushDependencies);
    materializeDataProperties(eAction, actionConf, eval);
    return XmlUtils.prettyPrint(eAction).toString();
}
Also used : Element(org.jdom.Element) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 5 with ELEvaluator

use of org.apache.oozie.util.ELEvaluator in project oozie by apache.

the class CoordCommandUtils method materializeOutputDataEvents.

/**
 * Materialize all &lt;input-events&gt;/&lt;data-in&gt; or &lt;output-events&gt;/&lt;data-out&gt;
 * tags Create uris for resolved instances. Create unresolved instance for
 * latest()/future().
 *
 * @param events
 * @param appInst
 * @param conf
 * @throws Exception
 */
private static void materializeOutputDataEvents(List<Element> events, SyncCoordAction appInst, Configuration conf) throws Exception {
    if (events == null) {
        return;
    }
    for (Element event : events) {
        StringBuilder instances = new StringBuilder();
        ELEvaluator eval = CoordELEvaluator.createInstancesELEvaluator(event, appInst, conf);
        // Handle list of instance tag
        resolveInstances(event, instances, appInst, conf, eval);
        // Handle start-instance and end-instance
        resolveInstanceRange(event, instances, appInst, conf, eval);
        // Separate out the unresolved instances
        separateResolvedAndUnresolved(event, instances);
    }
}
Also used : Element(org.jdom.Element) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Aggregations

ELEvaluator (org.apache.oozie.util.ELEvaluator)72 Element (org.jdom.Element)16 ELService (org.apache.oozie.service.ELService)15 XConfiguration (org.apache.oozie.util.XConfiguration)15 Configuration (org.apache.hadoop.conf.Configuration)13 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)11 URISyntaxException (java.net.URISyntaxException)9 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 CoordELEvaluator (org.apache.oozie.coord.CoordELEvaluator)8 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)7 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)7 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)7 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)7 CommandException (org.apache.oozie.command.CommandException)6 IOException (java.io.IOException)5 StringReader (java.io.StringReader)5 URI (java.net.URI)5 Date (java.util.Date)5 Map (java.util.Map)5 HCatURI (org.apache.oozie.util.HCatURI)5