瀏覽代碼

[oozie] Import workflow with Generic action

Generic action will be called if we cannot infer node type of the action.
Test ensuring XML is generated.
abec 13 年之前
父節點
當前提交
fd3a4ef

+ 14 - 0
apps/oozie/src/oozie/test_data/0.4/test-generic.xml

@@ -0,0 +1,14 @@
+<workflow-app name="fs-test" xmlns="uri:oozie:workflow:0.4">
+    <start to="Fs"/>
+    <action name="Fs">
+        <bleh test="test">
+              <test>test</test>
+        </bleh>
+        <ok to="end"/>
+        <error to="kill"/>
+    </action>
+    <kill name="kill">
+        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
+    </kill>
+    <end name="end"/>
+</workflow-app>

+ 17 - 0
apps/oozie/src/oozie/tests.py

@@ -1325,6 +1325,23 @@ class TestEditor(OozieMockBase):
     workflow.delete()
 
 
+  def test_import_workflow_generic(self):
+    """
+    Validates import for generic node: xml.
+    """
+    workflow = Workflow.objects.new_workflow(self.user)
+    workflow.save()
+    f = open('apps/oozie/src/oozie/test_data/0.4/test-generic.xml')
+    import_workflow(workflow, f.read())
+    f.close()
+    workflow.save()
+    assert_equal(4, len(Node.objects.filter(workflow=workflow)))
+    assert_equal(3, len(Link.objects.filter(parent__workflow=workflow)))
+    node = Node.objects.get(workflow=workflow, node_type='generic').get_full_node()
+    assert_equal("<bleh test=\"test\">\n              <test>test</test>\n        </bleh>", node.xml)
+    workflow.delete()
+
+
   def test_xss_escape_js(self):
     escaped = '[{"name": "oozie.use.system.libpath", "value": "true"}, {"name": "123\\\\u0022\\\\u003E\\\\u003Cscript\\\\u003Ealert(1)\\\\u003C/script\\\\u003E", "value": "hacked"}]'
     hacked = '[{"name":"oozie.use.system.libpath","value":"true"}, {"name": "123\\"><script>alert(1)</script>", "value": "hacked"}]'

+ 1 - 0
apps/oozie/src/oozie/xslt/0.4/action.xslt

@@ -15,6 +15,7 @@
 <xsl:import href="nodes/mapreduce.xslt"/>
 <xsl:import href="nodes/pig.xslt"/>
 <xsl:import href="nodes/streaming.xslt"/>
+<xsl:import href="nodes/generic.xslt"/>
 
 <xsl:template match="workflow:action" xmlns:workflow="uri:oozie:workflow:0.4">
 

+ 28 - 0
apps/oozie/src/oozie/xslt/0.4/nodes/fields/xml.xslt

@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.4" exclude-result-prefixes="workflow">
+
+
+<xsl:template match="*" mode="copy-no-namespaces">
+    <xsl:element name="{local-name()}">
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates select="node()" mode="copy-no-namespaces"/>
+    </xsl:element>
+</xsl:template>
+
+<xsl:template match="comment()| processing-instruction()" mode="copy-no-namespaces">
+    <xsl:copy/>
+</xsl:template>
+
+<xsl:template name="xml">
+
+  <field name="xml" type="TextField">
+    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
+    <xsl:apply-templates  select="current()" mode="copy-no-namespaces"/>
+    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
+  </field>
+
+</xsl:template>
+
+<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
+</xsl:stylesheet>

+ 18 - 0
apps/oozie/src/oozie/xslt/0.4/nodes/generic.xslt

@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.4" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/xml.xslt"/>
+
+<xsl:template match="workflow:*[local-name()!='decision' and local-name()!='end' and local-name()!='fork' and local-name()!='fs' and local-name()!='java' and local-name()!='join' and local-name()!='kill' and local-name()!='mapreduce' and local-name()!='pig' and local-name()!='start' and local-name()!='streaming' and local-name()!='distcp' and local-name()!='email' and local-name()!='hive' and local-name()!='shell' and local-name()!='sqoop' and local-name()!='ssh' and local-name()!='ok' and local-name()!='error']" xmlns:workflow="uri:oozie:workflow:0.4">
+
+  <object model="oozie.generic" pk="0">
+
+    <xsl:call-template name="xml"/>
+
+  </object>
+
+</xsl:template>
+
+<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
+</xsl:stylesheet>