Search in sources :

Example 41 with ELEvaluator

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

the class CoordELEvaluator method createURIELEvaluator.

/**
 * Create a new Evaluator to resolve URI temple with time specific constant
 *
 * @param strDate : Date-time
 * @return configured ELEvaluator
 * @throws Exception If there is any date-time string in wrong format, the exception is thrown
 */
public static ELEvaluator createURIELEvaluator(String strDate) throws Exception {
    ELEvaluator eval = new ELEvaluator();
    Calendar date = Calendar.getInstance(DateUtils.getOozieProcessingTimeZone());
    // always???
    date.setTime(DateUtils.parseDateOozieTZ(strDate));
    eval.setVariable("YEAR", date.get(Calendar.YEAR));
    eval.setVariable("MONTH", make2Digits(date.get(Calendar.MONTH) + 1));
    eval.setVariable("DAY", make2Digits(date.get(Calendar.DAY_OF_MONTH)));
    eval.setVariable("HOUR", make2Digits(date.get(Calendar.HOUR_OF_DAY)));
    eval.setVariable("MINUTE", make2Digits(date.get(Calendar.MINUTE)));
    return eval;
}
Also used : Calendar(java.util.Calendar) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 42 with ELEvaluator

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

the class CoordELEvaluator method createELEvaluatorForGroup.

/**
 * Create an evaluator to be used in resolving configuration vars and frequency constant/functions (used in Stage
 * 1)
 *
 * @param conf : Configuration containing property variables
 * @param group  Name of the group of required EL Evaluator.
 * @return configured ELEvaluator
 */
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 43 with ELEvaluator

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

the class CoordELFunctions method ph1_coord_dataIn_echo.

public static String ph1_coord_dataIn_echo(String n) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    String val = (String) eval.getVariable("oozie.dataname." + n);
    if ((val == null || val.equals("data-in") == false)) {
        XLog.getLog(CoordELFunctions.class).error("data_in_name " + n + " is not valid");
        throw new RuntimeException("data_in_name " + n + " is not valid");
    }
    return echoUnResolved("dataIn", "'" + n + "'");
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 44 with ELEvaluator

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

the class CoordELFunctions method coord_futureRange_sync.

private static String coord_futureRange_sync(int startOffset, int endOffset, int instance) 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];
    Calendar nominalInstanceCal = getCurrentInstance(getActionCreationtime(), instCount);
    StringBuilder resolvedInstances = new StringBuilder();
    StringBuilder resolvedURIPaths = new StringBuilder();
    if (nominalInstanceCal != null) {
        Calendar initInstance = getInitialInstanceCal();
        nominalInstanceCal = (Calendar) initInstance.clone();
        nominalInstanceCal.add(dsTimeUnit.getCalendarUnit(), instCount[0] * datasetFrequency);
        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, checkedInstance = 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 (instance >= checkedInstance && !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)) {
                    if (available == endOffset) {
                        LOG.debug("Matched future(" + 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 >= startOffset) {
                        LOG.debug("Matched future(" + 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);
                checkedInstance++;
            // 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 future function with variable 'is_resolved'
            // to 'false'
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.FALSE);
            if (startOffset == endOffset) {
                retVal = "${coord:future(" + startOffset + ", " + instance + ")}";
            } else {
                retVal = "${coord:futureRange(" + startOffset + ", " + endOffset + ", " + instance + ")}";
            }
        } else {
            eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.TRUE);
        }
    } else {
        // No feasible nominal time
        eval.setVariable(CoordELConstants.IS_RESOLVED, Boolean.TRUE);
        retVal = "";
    }
    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) URIHandlerService(org.apache.oozie.service.URIHandlerService) URIHandler(org.apache.oozie.dependency.URIHandler) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 45 with ELEvaluator

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

the class CoordELFunctions method getActualTime.

/**
 * @return Actual Time when all the dependencies of an application instance are met.
 */
private static Date getActualTime() {
    ELEvaluator eval = ELEvaluator.getCurrent();
    SyncCoordAction coordAction = (SyncCoordAction) eval.getVariable(COORD_ACTION);
    if (coordAction == null) {
        throw new RuntimeException("Associated Application instance should be defined with key " + COORD_ACTION);
    }
    return coordAction.getActualTime();
}
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