Author: tucu
Date: Mon Apr 30 21:37:01 2012
New Revision: 1332414
URL: http://svn.apache.org/viewvc?rev=1332414&view=rev
Log:
OOZIE-241 EL function(s) to expose action output data as a (XML/JSON/PROP) blob
(tucu)
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/TestDagELFunctions.java
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
incubator/oozie/trunk/release-log.txt
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
---
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
(original)
+++
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
Mon Apr 30 21:37:01 2012
@@ -17,7 +17,13 @@
*/
package org.apache.oozie.util;
+import org.apache.hadoop.conf.Configuration;
+import org.jdom.Element;
+import org.json.JSONObject;
+
import java.text.SimpleDateFormat;
+import java.util.Map;
+import java.util.Properties;
import java.util.TimeZone;
import java.util.Date;
import java.net.URLEncoder;
@@ -126,4 +132,25 @@ public class ELConstantsFunctions {
}
}
+ public static String toJsonStr(Map<String, String> map) {
+ JSONObject json = new JSONObject(map);
+ return XmlUtils.escapeCharsForXML(json.toString());
+ }
+
+ public static String toPropertiesStr(Map<String, String> map) {
+ Properties props = new Properties();
+ for (Map.Entry<String, String> entry: map.entrySet()) {
+ props.setProperty(entry.getKey(), entry.getValue());
+ }
+ return
XmlUtils.escapeCharsForXML(PropertiesUtils.propertiesToString(props));
+ }
+
+ public static String toConfigurationStr(Map<String, String> map) {
+ Configuration conf = new Configuration(false);
+ for (Map.Entry<String, String> entry: map.entrySet()) {
+ conf.set(entry.getKey(), entry.getValue());
+ }
+ return
XmlUtils.escapeCharsForXML(XmlUtils.prettyPrint(conf).toString());
+ }
+
}
Modified: incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/resources/oozie-default.xml?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/resources/oozie-default.xml (original)
+++ incubator/oozie/trunk/core/src/main/resources/oozie-default.xml Mon Apr 30
21:37:01 2012
@@ -438,6 +438,9 @@
trim=org.apache.oozie.util.ELConstantsFunctions#trim,
timestamp=org.apache.oozie.util.ELConstantsFunctions#timestamp,
urlEncode=org.apache.oozie.util.ELConstantsFunctions#urlEncode,
+ toJsonStr=org.apache.oozie.util.ELConstantsFunctions#toJsonStr,
+
toPropertiesStr=org.apache.oozie.util.ELConstantsFunctions#toPropertiesStr,
+
toConfigurationStr=org.apache.oozie.util.ELConstantsFunctions#toConfigurationStr,
wf:id=org.apache.oozie.DagELFunctions#wf_id,
wf:name=org.apache.oozie.DagELFunctions#wf_name,
wf:appPath=org.apache.oozie.DagELFunctions#wf_appPath,
Modified:
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/TestDagELFunctions.java
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/TestDagELFunctions.java?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
---
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/TestDagELFunctions.java
(original)
+++
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/TestDagELFunctions.java
Mon Apr 30 21:37:01 2012
@@ -19,6 +19,7 @@ package org.apache.oozie;
import org.apache.oozie.client.OozieClient;
import org.apache.oozie.client.WorkflowAction;
+import org.apache.oozie.util.XmlUtils;
import org.apache.oozie.workflow.lite.EndNodeDef;
import org.apache.oozie.workflow.lite.LiteWorkflowApp;
import org.apache.oozie.workflow.WorkflowInstance;
@@ -101,6 +102,15 @@ public class TestDagELFunctions extends
assertEquals("B", eval.evaluate("${wf:actionData('actionName')['b']}",
String.class));
+ String expected = XmlUtils.escapeCharsForXML("{\"b\":\"B\"}");
+ assertEquals(expected,
eval.evaluate("${toJsonStr(wf:actionData('actionName'))}", String.class));
+ expected = XmlUtils.escapeCharsForXML("b=B");
+
assertTrue(eval.evaluate("${toPropertiesStr(wf:actionData('actionName'))}",
String.class).contains(expected));
+ conf = new XConfiguration();
+ conf.set("b", "B");
+ expected =
XmlUtils.escapeCharsForXML(XmlUtils.prettyPrint(conf).toString());
+
assertTrue(eval.evaluate("${toConfigurationStr(wf:actionData('actionName'))}",
String.class).contains(expected));
+
assertEquals("ext",
eval.evaluate("${wf:actionExternalId('actionName')}", String.class));
assertEquals("tracker",
eval.evaluate("${wf:actionTrackerUri('actionName')}", String.class));
assertEquals("externalStatus",
eval.evaluate("${wf:actionExternalStatus('actionName')}", String.class));
Modified:
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
---
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
(original)
+++
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
Mon Apr 30 21:37:01 2012
@@ -18,8 +18,15 @@
package org.apache.oozie.util;
import org.apache.oozie.test.XTestCase;
+import org.jdom.Element;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import java.io.StringReader;
import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
import java.util.TimeZone;
public class TestELConstantsFunctions extends XTestCase {
@@ -47,4 +54,40 @@ public class TestELConstantsFunctions ex
assertEquals("+", ELConstantsFunctions.urlEncode(" "));
assertEquals("%25", ELConstantsFunctions.urlEncode("%"));
}
+
+ public void testToJsonStr() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "A");
+ map.put("b", "&");
+ String str = ELConstantsFunctions.toJsonStr(map);
+ Element e = XmlUtils.parseXml("<x>" + str + "</x>");
+ JSONObject json = (JSONObject) new JSONParser().parse(e.getText());
+ Map<String, String> map2 = new HashMap<String, String>(json);
+ assertEquals(map, map2);
+ }
+
+ public void testToPropertiesStr() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "A");
+ map.put("b", "&");
+ String str = ELConstantsFunctions.toPropertiesStr(map);
+ Element e = XmlUtils.parseXml("<x>" + str + "</x>");
+ Properties map2 = PropertiesUtils.stringToProperties(e.getText());
+ assertEquals(map, map2);
+ }
+
+ public void testToConfigurationStr() throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "A");
+ map.put("b", "&");
+ String str = ELConstantsFunctions.toConfigurationStr(map);
+ Element e = XmlUtils.parseXml("<x>" + str + "</x>");
+ XConfiguration conf = new XConfiguration(new
StringReader(e.getText()));
+ Map<String, String> map2 = new HashMap<String, String>();
+ for (Map.Entry entry : conf) {
+ map2.put((String) entry.getKey(), (String) entry.getValue());
+ }
+ assertEquals(map, map2);
+ }
+
}
Modified: incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
(original)
+++ incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki Mon
Apr 30 21:37:01 2012
@@ -1460,6 +1460,24 @@ It returns the URL UTF-8 encoded value o
It returns the UTC current date and time in W3C format down to the second
(YYYY-MM-DDThh:mm:ss.sZ). I.e.:
1997-07-16T19:20:30.45Z
+*String toJsonStr(Map<String, String>)* (since Oozie 3.3)
+
+It returns an XML encoded JSON representation of a Map<String, String>. This
function is useful to encode as
+a single property the complete action-data of an action, *wf:actionData(String
actionName)*, in order to pass
+it in full to another action.
+
+*String toPropertiesStr(Map<String, String>)* (since Oozie 3.3)
+
+It returns an XML encoded Properties representation of a Map<String, String>.
This function is useful to encode as
+a single property the complete action-data of an action, *wf:actionData(String
actionName)*, in order to pass
+it in full to another action.
+
+*String toConfigurationStr(Map<String, String>)* (since Oozie 3.3)
+
+It returns an XML encoded Configuration representation of a Map<String,
String>. This function is useful to encode as
+a single property the complete action-data of an action, *wf:actionData(String
actionName)*, in order to pass
+it in full to another action.
+
---++++ 4.2.3 Workflow EL Functions
*String wf:id()*
Modified: incubator/oozie/trunk/release-log.txt
URL:
http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1332414&r1=1332413&r2=1332414&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Mon Apr 30 21:37:01 2012
@@ -1,5 +1,6 @@
-- Oozie 3.2.0 release
+OOZIE-241 EL function(s) to expose action output data as a (XML/JSON/PROP)
blob (tucu)
OOZIE-825 Update oozie-sharelib-hive to use Hive 0.9.0 (virag via tucu)
OOZIE-812 ooziedb tool does not create VALIDATE_CONN table (tucu)
OOZIE-824 ooziedb tool creates derby.log in current directory (tucu)