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;
}
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;
}
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 + "'");
}
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;
}
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();
}
Aggregations