Pārlūkot izejas kodu

HUE-3831 [oozie] Show operations inside the HDFS fs graph node for external workflows

krish 9 gadi atpakaļ
vecāks
revīzija
ed3bb9a

+ 18 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/deletes.xslt

@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template name="deletes">
+
+  "deletes": [
+
+    <xsl:for-each select="*[local-name()='delete']">
+      {"value": "<xsl:value-of select="@path"/>"}
+      <xsl:if  test="position() &lt; last()">
+        ,
+      </xsl:if>
+    </xsl:for-each>
+  ]
+</xsl:template>
+
+</xsl:stylesheet>

+ 18 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/mkdirs.xslt

@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template name="mkdirs">
+
+  "mkdirs": [
+
+    <xsl:for-each select="*[local-name()='mkdir']">
+      {"value": "<xsl:value-of select="@path"/>"}
+      <xsl:if  test="position() &lt; last()">
+        ,
+      </xsl:if>
+    </xsl:for-each>
+  ]
+</xsl:template>
+
+</xsl:stylesheet>

+ 19 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/moves.xslt

@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template name="moves">
+
+  "moves": [
+
+    <xsl:for-each select="*[local-name()='move']">
+      {"source": "<xsl:value-of select="@source"/>",
+      "destination": "<xsl:value-of select="@target"/>"}
+      <xsl:if  test="position() &lt; last()">
+        ,
+      </xsl:if>
+    </xsl:for-each>
+  ]
+</xsl:template>
+
+</xsl:stylesheet>

+ 3 - 3
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/touchzs.xslt

@@ -4,15 +4,15 @@
 
 <xsl:template name="touchzs">
 
-  "touchzs": {
+  "touchzs": [
 
     <xsl:for-each select="*[local-name()='touchz']">
-      "path<xsl:value-of select='position()'/>": "<xsl:value-of select="@path"/>"
+      {"value": "<xsl:value-of select="@path"/>"}
       <xsl:if  test="position() &lt; last()">
         ,
       </xsl:if>
     </xsl:for-each>
-  }
+  ]
 </xsl:template>
 
 </xsl:stylesheet>

+ 7 - 1
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fs.xslt

@@ -3,10 +3,16 @@
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow5="uri:oozie:workflow:0.5" xmlns:workflow4="uri:oozie:workflow:0.4">
 
 <xsl:import href="fields/touchzs.xslt"/>
+<xsl:import href="fields/deletes.xslt"/>
+<xsl:import href="fields/mkdirs.xslt"/>
+<xsl:import href="fields/moves.xslt"/>
 
 <xsl:template match="workflow5:fs | workflow4:fs" xmlns:workflow5="uri:oozie:workflow:0.5" xmlns:workflow4="uri:oozie:workflow:0.4">
 
-  ,"fs": { <xsl:call-template name="touchzs"/> }
+  ,"fs": { <xsl:call-template name="touchzs"/>,
+           <xsl:call-template name="deletes"/>,
+           <xsl:call-template name="mkdirs"/>,
+           <xsl:call-template name="moves"/> }
 
 </xsl:template>
 

+ 4 - 2
apps/oozie/src/oozie/models2.py

@@ -590,8 +590,10 @@ def _dig_nodes(nodes, adj_list, user, wf_nodes):
         properties['user'] = '%s@%s' % (node.get('ssh').get('user'), node.get('ssh').get('host'))
         properties['ssh_command'] = node.get('ssh').get('command')
       elif node['node_type'] == 'fs':
-        fs_props = node.get('fs')
-        # TBD: gather props for different fs operations
+        properties['touchzs'] = node.get('fs').get('touchzs')
+        properties['mkdirs'] = node.get('fs').get('mkdirs')
+        properties['moves'] = node.get('fs').get('moves')
+        properties['deletes'] = node.get('fs').get('deletes')
       elif node['node_type'] == 'email':
         properties['to'] = node.get('email').get('to')
         properties['subject'] = node.get('email').get('subject')

+ 31 - 0
apps/oozie/src/oozie/models2_tests.py

@@ -741,6 +741,37 @@ class TestExternalWorkflowGraph(object):
     assert_equal(workflow_data['layout'][0]['rows'][1]['widgets'][0]['widgetType'], 'email-widget')
     assert_equal(workflow_data['workflow']['nodes'][0]['name'], 'start-3f10')
 
+  def test_gen_workflow_data_from_xml_for_fs(self):
+    self.wf.definition = """<workflow-app name="My_Workflow" xmlns="uri:oozie:workflow:0.5">
+        <start to="fs-d2ff"/>
+        <kill name="Kill">
+            <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
+        </kill>
+        <action name="fs-d2ff">
+            <fs>
+                  <delete path='${nameNode}/user/admin/y'/>
+                  <delete path='${nameNode}/user/admin/a'/>
+                  <mkdir path='${nameNode}/user/admin/sai'/>
+                  <mkdir path='${nameNode}/user/admin/sai1'/>
+                  <move source='${nameNode}/user/admin/sai/test' target='${nameNode}/user/admin/sai/test1'/>
+                  <move source='${nameNode}/user/admin/b' target='${nameNode}/user/admin/c'/>
+                  <touchz path='${nameNode}/user/admin/sai/test'/>
+                  <touchz path='${nameNode}/user/admin/temp1'/>
+            </fs>
+            <ok to="End"/>
+            <error to="Kill"/>
+        </action>
+        <end name="End"/>
+    </workflow-app>"""
+
+    workflow_data = Workflow.gen_workflow_data_from_xml(self.user, self.wf)
+
+    assert_true(len(workflow_data['layout'][0]['rows']) == 4)
+    assert_true(len(workflow_data['workflow']['nodes']) == 4)
+    assert_equal(workflow_data['layout'][0]['rows'][1]['widgets'][0]['widgetType'], 'fs-widget')
+    assert_true(len(workflow_data['workflow']['nodes'][1]['properties']['deletes']), 2)
+    assert_equal(workflow_data['workflow']['nodes'][1]['properties']['deletes'][0]['value'], u'${nameNode}/user/admin/y')
+
   def test_gen_workflow_data_from_xml_for_decision_node(self):
     self.wf.definition = """<workflow-app xmlns="uri:oozie:workflow:0.5" name="capture-output-wf">
       <credentials>