Permalink
Browse files

dataIn to construct paths even for non-input datasets - for optional …

…inputs
  • Loading branch information...
1 parent bb8fdd1 commit e9d3db95b3116dfae3da24309c41d030e97253d6 Shwetha GS committed Oct 29, 2012
@@ -21,14 +21,19 @@
import java.util.Calendar;
import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.conf.Configuration;
import org.apache.oozie.command.coord.CoordCommandUtils;
+import org.apache.oozie.coord.CoordELEvaluator;
import org.apache.oozie.coord.CoordELFunctions;
import org.apache.oozie.coord.SyncCoordAction;
import org.apache.oozie.coord.SyncCoordDataset;
import org.apache.oozie.util.DateUtils;
import org.apache.oozie.util.ELEvaluator;
import org.apache.oozie.util.ParamChecker;
import org.apache.oozie.util.XLog;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Text;
public class OozieELExtensions {
@@ -39,21 +44,30 @@
public static final String COORD_CURRENT = "coord:current";
public static String ph1_dataIn_echo(String dataInName, String part) {
- ELEvaluator eval = ELEvaluator.getCurrent();
- String val = (String) eval.getVariable("oozie.dataname." + dataInName);
- if (val == null || !val.equals("data-in")) {
- XLog.getLog(CoordELFunctions.class).error("data_in_name " + dataInName + " is not valid");
- throw new RuntimeException("data_in_name " + dataInName + " is not valid");
- }
return "dataIn('" + dataInName + "', '" + part + "')";
}
public static String ph3_dataIn(String dataInName, String part) {
ELEvaluator eval = ELEvaluator.getCurrent();
String uristr = (String) eval.getVariable(".datain." + dataInName);
- Boolean unresolved = (Boolean) eval.getVariable(".datain." + dataInName + ".unresolved");
- if (unresolved != null && unresolved) {
- throw new RuntimeException("There are unresolved instances in " + uristr);
+ if(uristr == null) { //optional input
+ Element dsEle = getDSElement(eval, dataInName);
+ Configuration conf = new Configuration();
+ SyncCoordAction appInst = (SyncCoordAction) eval.getVariable(CoordELFunctions.COORD_ACTION);
+ try {
+ ELEvaluator instEval = CoordELEvaluator.createInstancesELEvaluator(dsEle, appInst, conf);
+ StringBuilder instances = new StringBuilder();
+ CoordCommandUtils.resolveInstanceRange(dsEle, instances , appInst, conf, instEval);
+ uristr = CoordCommandUtils.createEarlyURIs(dsEle, instances.toString(), new StringBuilder(), new StringBuilder());
+ uristr = uristr.replace(CoordELFunctions.INSTANCE_SEPARATOR, ",");
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to resolve instance range for " + dataInName, e);
+ }
+ } else {
+ Boolean unresolved = (Boolean) eval.getVariable(".datain." + dataInName + ".unresolved");
+ if (unresolved != null && unresolved) {
+ throw new RuntimeException("There are unresolved instances in " + uristr);
+ }
}
if (StringUtils.isNotEmpty(uristr) && StringUtils.isNotEmpty(part) && !part.equals("null")) {
@@ -71,6 +85,32 @@ public static String ph3_dataIn(String dataInName, String part) {
return uristr;
}
+ private static Element getDSElement(ELEvaluator eval, String dataInName) {
+ Element ele = new Element("datain");
+ Element dsEle = new Element("dataset");
+ ele.getChildren().add(dsEle);
+
+ String[] attrs = {"initial-instance", "frequency", "freq_timeunit", "timezone", "end_of_duration"};
+ for(String attr:attrs)
+ dsEle.getAttributes().add(new Attribute(attr, (String) eval.getVariable(dataInName + "." + attr)));
+
+ String[] children = {"done-flag", "uri-template"};
+ for(String child:children) {
+ Element childEle = new Element(child);
+ childEle.setContent(new Text(((String) eval.getVariable(dataInName + "." + child)).replace('%', '$')));
+ dsEle.getChildren().add(childEle);
+ }
+
+ String[] eleChildren = {"start-instance", "end-instance"};
+ for(String child:eleChildren) {
+ Element childEle = new Element(child);
+ childEle.setContent(new Text("${" + ((String) eval.getVariable(dataInName + "." + child)) + "}"));
+ ele.getChildren().add(childEle);
+ }
+
+ return ele;
+ }
+
public static String ph1_now_echo(int hr, int min) {
ELEvaluator eval = ELEvaluator.getCurrent();
eval.setVariable(".wrap", "true");
Oops, something went wrong.

0 comments on commit e9d3db9

Please sign in to comment.