Search in sources :

Example 36 with ELEvaluator

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

the class CoordCommandUtils method materializeInputDataEvents.

public static void materializeInputDataEvents(List<Element> events, SyncCoordAction appInst, Configuration conf, CoordinatorActionBean actionBean, boolean isInputLogicSpecified) throws Exception {
    if (events == null) {
        return;
    }
    CoordInputDependency coordPullInputDependency = CoordInputDependencyFactory.createPullInputDependencies(isInputLogicSpecified);
    CoordInputDependency coordPushInputDependency = CoordInputDependencyFactory.createPushInputDependencies(isInputLogicSpecified);
    List<Pair<String, String>> unresolvedList = new ArrayList<Pair<String, String>>();
    URIHandlerService uriService = Services.get().get(URIHandlerService.class);
    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
        String resolvedList = separateResolvedAndUnresolved(event, instances);
        String name = event.getAttribute("name").getValue();
        if (!resolvedList.isEmpty()) {
            Element uri = event.getChild("dataset", event.getNamespace()).getChild("uri-template", event.getNamespace());
            String uriTemplate = uri.getText();
            URI baseURI = uriService.getAuthorityWithScheme(uriTemplate);
            URIHandler handler = uriService.getURIHandler(baseURI);
            List<CoordInputInstance> inputInstanceList = new ArrayList<CoordInputInstance>();
            for (String inputInstance : resolvedList.split("#")) {
                inputInstanceList.add(new CoordInputInstance(inputInstance, false));
            }
            if (handler.getDependencyType(baseURI).equals(DependencyType.PULL)) {
                coordPullInputDependency.addInputInstanceList(name, inputInstanceList);
            } else {
                coordPushInputDependency.addInputInstanceList(name, inputInstanceList);
            }
        }
        String tmpUnresolved = event.getChildTextTrim(UNRESOLVED_INSTANCES_TAG, event.getNamespace());
        if (tmpUnresolved != null) {
            unresolvedList.add(new Pair<String, String>(name, tmpUnresolved));
        }
    }
    for (Pair<String, String> unresolvedDataset : unresolvedList) {
        coordPullInputDependency.addUnResolvedList(unresolvedDataset.getFirst(), unresolvedDataset.getSecond());
    }
    actionBean.setPullInputDependencies(coordPullInputDependency);
    actionBean.setPushInputDependencies(coordPushInputDependency);
    actionBean.setMissingDependencies(coordPullInputDependency.serialize());
    actionBean.setPushMissingDependencies(coordPushInputDependency.serialize());
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) URI(java.net.URI) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) CoordInputInstance(org.apache.oozie.coord.input.dependency.CoordInputInstance) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordInputDependency(org.apache.oozie.coord.input.dependency.CoordInputDependency) Pair(org.apache.oozie.util.Pair)

Example 37 with ELEvaluator

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

the class CoordELEvaluator method createELEvaluatorForDataEcho.

public static ELEvaluator createELEvaluatorForDataEcho(Configuration conf, String group, HashMap<String, String> dataNameList) throws Exception {
    ELEvaluator eval = createELEvaluatorForGroup(conf, group);
    for (Iterator<String> it = dataNameList.keySet().iterator(); it.hasNext(); ) {
        String key = it.next();
        String value = dataNameList.get(key);
        eval.setVariable("oozie.dataname." + key, value);
    }
    return eval;
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 38 with ELEvaluator

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

the class CoordELEvaluator method createLazyEvaluator.

/**
 * Create a new evaluator for Lazy resolve (phase 3). For example, coord_latest(n) and coord_actualTime()function
 * should be resolved when all other data dependencies are met.
 *
 * @param actualTime : Action start time
 * @param nominalTime : Action creation time
 * @param dEvent :XML element for data-in element usually enclosed by &lt;data-in(out)&gt; tag
 * @param conf :Configuration to substitute any variables
 * @return configured ELEvaluator
 * @throws Exception : If there is any date-time string in wrong format, the exception is thrown
 */
public static ELEvaluator createLazyEvaluator(Date actualTime, Date nominalTime, Element dEvent, Configuration conf) throws Exception {
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("coord-action-start");
    setConfigToEval(eval, conf);
    SyncCoordDataset ds = getDSObject(dEvent);
    SyncCoordAction appInst = new SyncCoordAction();
    appInst.setNominalTime(nominalTime);
    appInst.setActualTime(actualTime);
    CoordELFunctions.configureEvaluator(eval, ds, appInst);
    eval.setVariable(CoordELFunctions.CONFIGURATION, conf);
    return eval;
}
Also used : ELService(org.apache.oozie.service.ELService) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 39 with ELEvaluator

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

the class CoordELEvaluator method createDataEvaluator.

public static ELEvaluator createDataEvaluator(Element eJob, Configuration conf, String actionId, CoordInputDependency pullDependencies, CoordInputDependency pushDependencies) throws Exception {
    ELEvaluator e = Services.get().get(ELService.class).createEvaluator("coord-action-start");
    setConfigToEval(e, conf);
    SyncCoordAction appInst = new SyncCoordAction();
    String strNominalTime = eJob.getAttributeValue("action-nominal-time");
    if (strNominalTime != null) {
        appInst.setNominalTime(DateUtils.parseDateOozieTZ(strNominalTime));
        appInst.setTimeZone(DateUtils.getTimeZone(eJob.getAttributeValue("timezone")));
        appInst.setFrequency(eJob.getAttributeValue("frequency"));
        appInst.setTimeUnit(TimeUnit.valueOf(eJob.getAttributeValue("freq_timeunit")));
        appInst.setActionId(actionId);
        appInst.setName(eJob.getAttributeValue("name"));
        appInst.setPullDependencies(pullDependencies);
        appInst.setPushDependencies(pushDependencies);
        if (CoordUtils.isInputLogicSpecified(eJob)) {
            e.setVariable(".actionInputLogic", XmlUtils.prettyPrint(eJob.getChild(CoordInputLogicEvaluator.INPUT_LOGIC, eJob.getNamespace())).toString());
        }
    }
    String strActualTime = eJob.getAttributeValue("action-actual-time");
    if (strActualTime != null) {
        appInst.setActualTime(DateUtils.parseDateOozieTZ(strActualTime));
    }
    CoordELFunctions.configureEvaluator(e, null, appInst);
    Element events = eJob.getChild("input-events", eJob.getNamespace());
    if (events != null) {
        for (Element data : (List<Element>) events.getChildren("data-in", eJob.getNamespace())) {
            if (data.getChild("uris", data.getNamespace()) != null) {
                String uris = data.getChild("uris", data.getNamespace()).getTextTrim();
                uris = uris.replaceAll(CoordELFunctions.INSTANCE_SEPARATOR, CoordELFunctions.DIR_SEPARATOR);
                e.setVariable(".datain." + data.getAttributeValue("name"), uris);
            } else {
            }
            if (data.getChild(CoordCommandUtils.UNRESOLVED_INSTANCES_TAG, data.getNamespace()) != null) {
                // TODO:
                e.setVariable(".datain." + data.getAttributeValue("name") + ".unresolved", "true");
            // check
            // null
            }
            Element doneFlagElement = data.getChild("dataset", data.getNamespace()).getChild("done-flag", data.getNamespace());
            String doneFlag = CoordUtils.getDoneFlag(doneFlagElement);
            e.setVariable(".datain." + data.getAttributeValue("name") + ".doneFlag", doneFlag);
        }
    }
    events = eJob.getChild("output-events", eJob.getNamespace());
    if (events != null) {
        for (Element data : (List<Element>) events.getChildren("data-out", eJob.getNamespace())) {
            if (data.getChild("uris", data.getNamespace()) != null) {
                String uris = data.getChild("uris", data.getNamespace()).getTextTrim();
                uris = uris.replaceAll(CoordELFunctions.INSTANCE_SEPARATOR, CoordELFunctions.DIR_SEPARATOR);
                e.setVariable(".dataout." + data.getAttributeValue("name"), uris);
            } else {
            }
            // TODO
            if (data.getChild(CoordCommandUtils.UNRESOLVED_INSTANCES_TAG, data.getNamespace()) != null) {
                // TODO:
                e.setVariable(".dataout." + data.getAttributeValue("name") + ".unresolved", "true");
            // check
            // null
            }
        }
    }
    return e;
}
Also used : Element(org.jdom.Element) ELService(org.apache.oozie.service.ELService) List(java.util.List) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 40 with ELEvaluator

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

the class CoordELEvaluator method createInstancesELEvaluator.

public static ELEvaluator createInstancesELEvaluator(String tag, Element event, SyncCoordAction appInst, Configuration conf) throws Exception {
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator(tag);
    setConfigToEval(eval, conf);
    SyncCoordDataset ds = getDSObject(event);
    CoordELFunctions.configureEvaluator(eval, ds, appInst);
    return eval;
}
Also used : ELService(org.apache.oozie.service.ELService) 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