Search in sources :

Example 31 with ELEvaluator

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

the class BundleSubmitXCommand method createEvaluator.

/**
 * Create ELEvaluator
 *
 * @param conf job configuration
 * @return ELEvaluator the evaluator for el function
 * @throws BundleJobException thrown if failed to create evaluator
 */
public ELEvaluator createEvaluator(Configuration conf) throws BundleJobException {
    ELEvaluator eval;
    ELEvaluator.Context context;
    try {
        context = new ELEvaluator.Context();
        eval = new ELEvaluator(context);
        for (Map.Entry<String, String> entry : conf) {
            eval.setVariable(entry.getKey(), entry.getValue());
        }
    } catch (Exception e) {
        throw new BundleJobException(ErrorCode.E1004, e.getMessage(), e);
    }
    return eval;
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator) Map(java.util.Map) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException)

Example 32 with ELEvaluator

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

the class BundleSubmitXCommand method createELEvaluatorForGroup.

public static ELEvaluator createELEvaluatorForGroup(Configuration conf, String group) {
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator(group);
    setConfigToEval(eval, conf);
    return eval;
}
Also used : ELService(org.apache.oozie.service.ELService) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 33 with ELEvaluator

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

the class CoordSLAChangeXCommand method executeSlaCommand.

@Override
protected boolean executeSlaCommand() throws ServiceException, CommandException {
    try {
        List<Pair<String, Map<String, String>>> idSlaDefinitionList = new ArrayList<Pair<String, Map<String, String>>>();
        List<CoordinatorActionBean> coordinatorActionBeanList = getNotTerminatedActions();
        Configuration conf = getJobConf();
        for (CoordinatorActionBean coordAction : coordinatorActionBeanList) {
            Map<String, String> slaDefinitionMap = new HashMap<String, String>(newParams);
            for (String key : slaDefinitionMap.keySet()) {
                Element eAction = XmlUtils.parseXml(coordAction.getActionXml().toString());
                ELEvaluator evalSla = CoordELEvaluator.createSLAEvaluator(eAction, coordAction, conf);
                String updateValue = CoordELFunctions.evalAndWrap(evalSla, slaDefinitionMap.get(key));
                slaDefinitionMap.put(key, updateValue);
            }
            idSlaDefinitionList.add(new Pair<String, Map<String, String>>(coordAction.getId(), slaDefinitionMap));
        }
        return Services.get().get(SLAService.class).changeDefinition(idSlaDefinitionList);
    } catch (Exception e) {
        throw new CommandException(ErrorCode.E1027, e.getMessage(), e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) ArrayList(java.util.ArrayList) CommandException(org.apache.oozie.command.CommandException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.oozie.util.Pair)

Example 34 with ELEvaluator

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

the class CoordCommandUtils method createEarlyURIs.

/**
 * The function create a list of URIs separated by "," using the instances
 * time stamp and URI-template
 *
 * @param event : &lt;data-in&gt; event
 * @param instances : List of time stamp separated by ","
 * @param unresolvedInstances : list of instance with latest function
 * @param urisWithDoneFlag : list of URIs with the done flag appended
 * @return : list of URIs separated by ";" as a string.
 * @throws Exception
 */
public static String createEarlyURIs(Element event, String instances, StringBuilder unresolvedInstances, StringBuilder urisWithDoneFlag) throws Exception {
    if (instances == null || instances.length() == 0) {
        return "";
    }
    String[] instanceList = instances.split(CoordELFunctions.INSTANCE_SEPARATOR);
    StringBuilder uris = new StringBuilder();
    Element doneFlagElement = event.getChild("dataset", event.getNamespace()).getChild("done-flag", event.getNamespace());
    URIHandlerService uriService = Services.get().get(URIHandlerService.class);
    for (int i = 0; i < instanceList.length; i++) {
        if (instanceList[i].trim().length() == 0) {
            continue;
        }
        int funcType = getFuncType(instanceList[i]);
        if (funcType == LATEST || funcType == FUTURE) {
            if (unresolvedInstances.length() > 0) {
                unresolvedInstances.append(CoordELFunctions.INSTANCE_SEPARATOR);
            }
            unresolvedInstances.append(instanceList[i]);
            continue;
        }
        ELEvaluator eval = CoordELEvaluator.createURIELEvaluator(instanceList[i]);
        if (uris.length() > 0) {
            uris.append(CoordELFunctions.INSTANCE_SEPARATOR);
            urisWithDoneFlag.append(CoordELFunctions.INSTANCE_SEPARATOR);
        }
        String uriPath = CoordELFunctions.evalAndWrap(eval, event.getChild("dataset", event.getNamespace()).getChild("uri-template", event.getNamespace()).getTextTrim());
        URIHandler uriHandler = uriService.getURIHandler(uriPath);
        uriHandler.validate(uriPath);
        uris.append(uriPath);
        urisWithDoneFlag.append(uriHandler.getURIWithDoneFlag(uriPath, CoordUtils.getDoneFlag(doneFlagElement)));
    }
    return uris.toString();
}
Also used : Element(org.jdom.Element) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 35 with ELEvaluator

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

the class CoordCommandUtils method materializeSLA.

/**
 * @param eAction
 * @param coordAction
 * @param conf
 * @return boolean to determine whether the SLA element is present or not
 * @throws CoordinatorJobException
 */
public static boolean materializeSLA(Element eAction, CoordinatorActionBean coordAction, Configuration conf) throws CoordinatorJobException {
    Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
    if (eSla == null) {
        // eAppXml.getNamespace("sla"));
        return false;
    }
    try {
        ELEvaluator evalSla = CoordELEvaluator.createSLAEvaluator(eAction, coordAction, conf);
        List<Element> elemList = eSla.getChildren();
        for (Element elem : elemList) {
            String updated;
            try {
                updated = CoordELFunctions.evalAndWrap(evalSla, elem.getText().trim());
            } catch (Exception e) {
                throw new CoordinatorJobException(ErrorCode.E1004, e.getMessage(), e);
            }
            elem.removeContent();
            elem.addContent(updated);
        }
    } catch (Exception e) {
        throw new CoordinatorJobException(ErrorCode.E1004, e.getMessage(), e);
    }
    return true;
}
Also used : CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) Element(org.jdom.Element) CoordELEvaluator(org.apache.oozie.coord.CoordELEvaluator) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordinatorJobException(org.apache.oozie.coord.CoordinatorJobException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) ParseException(java.text.ParseException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

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