Search in sources :

Example 11 with ELEvaluator

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

the class CoordELEvaluator method createSLAEvaluator.

/**
 * Create a SLA evaluator to be used during Materialization
 * @param eAction the action
 * @param coordAction the coordinator action
 * @param conf the configuration
 * @return eval returns SLA evaluator to be used during Materialization
 * @throws Exception in case of error
 */
public static ELEvaluator createSLAEvaluator(Element eAction, CoordinatorActionBean coordAction, Configuration conf) throws Exception {
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("coord-sla-create");
    setConfigToEval(eval, conf);
    // TODO:
    SyncCoordAction appInst = new SyncCoordAction();
    appInst.setNominalTime(coordAction.getNominalTime());
    appInst.setActualTime(coordAction.getCreatedTime());
    appInst.setActionId(coordAction.getId());
    appInst.setName(eAction.getAttributeValue("name"));
    CoordELFunctions.configureEvaluator(eval, null, appInst);
    Element events = eAction.getChild("output-events", eAction.getNamespace());
    if (events != null) {
        for (Object obj : events.getChildren("data-out", eAction.getNamespace())) {
            Element data = (Element) obj;
            if (data.getChild("uris", data.getNamespace()) != null) {
                String uris = data.getChild("uris", data.getNamespace()).getTextTrim();
                uris = uris.replaceAll(CoordELFunctions.INSTANCE_SEPARATOR, CoordELFunctions.DIR_SEPARATOR);
                eval.setVariable(".dataout." + data.getAttributeValue("name"), uris);
            }
            if (data.getChild(CoordCommandUtils.UNRESOLVED_INSTANCES_TAG, data.getNamespace()) != null) {
                eval.setVariable(".dataout." + data.getAttributeValue("name") + ".unresolved", "true");
            }
        }
    }
    return eval;
}
Also used : Element(org.jdom.Element) ELService(org.apache.oozie.service.ELService) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 12 with ELEvaluator

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

the class CoordELEvaluator method createELEvaluatorForDataAndConf.

/**
 * Create an Evaluator using conf and input/output-data (used for sla)
 * @param conf the configuration
 * @param group the group for the EL expression
 * @param dataNameList the name list for the data
 * @return eval returns an Evaluator using conf and input/output-data (used for sla)
 * @throws Exception in case of error
 */
public static ELEvaluator createELEvaluatorForDataAndConf(Configuration conf, String group, HashMap<String, String> dataNameList) throws Exception {
    ELEvaluator eval = createELEvaluatorForDataEcho(conf, group, dataNameList);
    setConfigToEval(eval, conf);
    return eval;
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 13 with ELEvaluator

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

the class CoordELFunctions method coord_latestRange_sync.

private static String coord_latestRange_sync(int startOffset, int endOffset) throws Exception {
    final XLog LOG = XLog.getLog(CoordELFunctions.class);
    final Thread currentThread = Thread.currentThread();
    ELEvaluator eval = ELEvaluator.getCurrent();
    String retVal = "";
    // in minutes
    int datasetFrequency = (int) getDSFrequency();
    TimeUnit dsTimeUnit = getDSTimeUnit();
    int[] instCount = new int[1];
    boolean useCurrentTime = Services.get().getConf().getBoolean(LATEST_EL_USE_CURRENT_TIME, false);
    Calendar nominalInstanceCal;
    if (useCurrentTime) {
        nominalInstanceCal = getCurrentInstance(new Date(), instCount);
    } else {
        nominalInstanceCal = getCurrentInstance(getActualTime(), instCount);
    }
    StringBuilder resolvedInstances = new StringBuilder();
    StringBuilder resolvedURIPaths = new StringBuilder();
    if (nominalInstanceCal != null) {
        Calendar initInstance = getInitialInstanceCal();
        SyncCoordDataset ds = (SyncCoordDataset) eval.getVariable(DATASET);
        if (ds == null) {
            throw new RuntimeException("Associated Dataset should be defined with key " + DATASET);
        }
        String uriTemplate = ds.getUriTemplate();
        Configuration conf = (Configuration) eval.getVariable(CONFIGURATION);
        if (conf == null) {
            throw new RuntimeException("Associated Configuration should be defined with key " + CONFIGURATION);
        }
        int available = 0;
        boolean resolved = false;
        String user = ParamChecker.notEmpty((String) eval.getVariable(OozieClient.USER_NAME), OozieClient.USER_NAME);
        String doneFlag = ds.getDoneFlag();
        URIHandlerService uriService = Services.get().get(URIHandlerService.class);
        URIHandler uriHandler = null;
        Context uriContext = null;
        try {
            while (nominalInstanceCal.compareTo(initInstance) >= 0 && !currentThread.isInterrupted()) {
                ELEvaluator uriEval = getUriEvaluator(nominalInstanceCal);
                String uriPath = uriEval.evaluate(uriTemplate, String.class);
                if (uriHandler == null) {
                    URI uri = new URI(uriPath);
                    uriHandler = uriService.getURIHandler(uri);
                    uriContext = uriHandler.getContext(uri, conf, user, true);
                }
                String uriWithDoneFlag = uriHandler.getURIWithDoneFlag(uriPath, doneFlag);
                if (uriHandler.exists(new URI(uriWithDoneFlag), uriContext)) {
                    XLog.getLog(CoordELFunctions.class).debug("Found latest(" + available + "): " + uriWithDoneFlag);
                    if (available == startOffset) {
                        LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag);
                        resolved = true;
                        resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal));
                        resolvedURIPaths.append(uriPath);
                        retVal = resolvedInstances.toString();
                        eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString());
                        break;
                    } else if (available <= endOffset) {
                        LOG.debug("Matched latest(" + available + "): " + uriWithDoneFlag);
                        resolvedInstances.append(DateUtils.formatDateOozieTZ(nominalInstanceCal)).append(INSTANCE_SEPARATOR);
                        resolvedURIPaths.append(uriPath).append(INSTANCE_SEPARATOR);
                    }
                    available--;
                }
                // nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), -datasetFrequency);
                nominalInstanceCal = (Calendar) initInstance.clone();
                instCount[0]--;
                nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), instCount[0] * datasetFrequency);
            // DateUtils.moveToEnd(nominalInstanceCal, getDSEndOfFlag());
            }
            if (!StringUtils.isEmpty(resolvedURIPaths.toString()) && eval.getVariable(CoordELConstants.RESOLVED_PATH) == null) {
                eval.setVariable(CoordELConstants.RESOLVED_PATH, resolvedURIPaths.toString());
            }
        } finally {
            if (uriContext != null) {
                uriContext.destroy();
            }
        }
        if (!resolved) {
            // return unchanged latest function with variable 'is_resolved'
            // to 'false'
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE);
            if (startOffset == endOffset) {
                retVal = "${coord:latest(" + startOffset + ")}";
            } else {
                retVal = "${coord:latestRange(" + startOffset + "," + endOffset + ")}";
            }
        } else {
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.TRUE);
        }
    } else {
        // No feasible nominal time
        eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE);
    }
    return retVal;
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) Configuration(org.apache.hadoop.conf.Configuration) XLog(org.apache.oozie.util.XLog) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) URI(java.net.URI) Date(java.util.Date) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 14 with ELEvaluator

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

the class CoordELFunctions method ph1_coord_hours.

/**
 * Used in defining the frequency in 'hour' unit. <p> parameter value domain: <code> val &gt; 0</code> and should
 * be integer.
 *
 * @param val frequency in number of hours.
 * @return number of minutes and also set the frequency timeunit to "minute"
 */
public static int ph1_coord_hours(int val) {
    val = ParamChecker.checkGTZero(val, "n");
    ELEvaluator eval = ELEvaluator.getCurrent();
    eval.setVariable("timeunit", TimeUnit.MINUTE);
    eval.setVariable("endOfDuration", TimeUnit.NONE);
    return val * 60;
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 15 with ELEvaluator

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

the class CoordELFunctions method ph1_coord_endOfMonths.

/**
 * Used in defining the frequency in 'month' unit and specify the "end of month" property. <p> Every instance will
 * start at first day of each month at 00:00 hour. <p> domain: <code> val &gt; 0</code> and should be integer.
 *
 * @param val frequency in number of months.
 * @return number of months and also set the frequency timeunit to "month" and end_of_duration flag to "month"
 */
public static int ph1_coord_endOfMonths(int val) {
    val = ParamChecker.checkGTZero(val, "n");
    ELEvaluator eval = ELEvaluator.getCurrent();
    eval.setVariable("timeunit", TimeUnit.MONTH);
    eval.setVariable("endOfDuration", TimeUnit.END_OF_MONTH);
    return val;
}
Also used : 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