Browse Source

HUE-2729 [oozie] Add XSLT2 to generate workflow graph data from XML

krish 10 years ago
parent
commit
837abe5
37 changed files with 564 additions and 2 deletions
  1. 7 0
      apps/oozie/src/oozie/conf.py
  2. 40 1
      apps/oozie/src/oozie/importlib/workflows.py
  3. 35 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/action.xslt
  4. 17 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/control.xslt
  5. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/distcp.0.1.xslt
  6. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/email.0.1.xslt
  7. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/hive.0.1.xslt
  8. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/hive.0.2.xslt
  9. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/shell.0.1.xslt
  10. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/sqoop.0.1.xslt
  11. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/sqoop.0.2.xslt
  12. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/ssh.0.1.xslt
  13. 9 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/command.xslt
  14. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/jar_path.xslt
  15. 21 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/job_properties.xslt
  16. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/job_xml.xslt
  17. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/mapper.xslt
  18. 24 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/prepares.xslt
  19. 10 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/reducer.xslt
  20. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/script_path.xslt
  21. 20 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/touchzs.xslt
  22. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/user.xslt
  23. 26 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/xml.xslt
  24. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fork.xslt
  25. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fs.xslt
  26. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/generic.xslt
  27. 14 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/java.xslt
  28. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/mapreduce.xslt
  29. 13 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/pig.xslt
  30. 16 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/streaming.xslt
  31. 11 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/subworkflow.xslt
  32. 16 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/workflow.xslt
  33. 14 0
      apps/oozie/src/oozie/importlib/xslt2/workflows/workflow.xslt
  34. 14 0
      apps/oozie/src/oozie/models2.py
  35. 36 0
      apps/oozie/src/oozie/test_data/xslt2/test-workflow.xml
  36. 12 0
      apps/oozie/src/oozie/tests2.py
  37. 4 1
      apps/oozie/src/oozie/views/dashboard.py

+ 7 - 0
apps/oozie/src/oozie/conf.py

@@ -33,6 +33,13 @@ DEFINITION_XSLT_DIR = Config(
   private=True
 )
 
+DEFINITION_XSLT2_DIR = Config(
+  key="definition_xslt2_dir",
+  default=os.path.join(os.path.dirname(__file__), "importlib", "xslt2"),
+  help=_t("Location on local FS where the xslt files are stored for workflow import."),
+  private=True
+)
+
 LOCAL_SAMPLE_DIR = Config(
   key="local_data_dir",
   default=os.path.join(os.path.dirname(__file__), "..", "..", "examples"),

+ 40 - 1
apps/oozie/src/oozie/importlib/workflows.py

@@ -42,7 +42,7 @@ from django.utils.translation import ugettext as _
 
 from desktop.models import Document
 
-from oozie.conf import DEFINITION_XSLT_DIR
+from oozie.conf import DEFINITION_XSLT_DIR, DEFINITION_XSLT2_DIR
 from oozie.models import Workflow, Node, Link, Start, End,\
                          Decision, DecisionEnd, Fork, Join,\
                          Kill
@@ -685,3 +685,42 @@ def import_workflow(workflow, workflow_definition, metadata=None, fs=None):
     raise RuntimeError(_("Could not find any nodes in Workflow definition. Maybe it's malformed?"))
 
   return import_workflow_root(workflow, workflow_definition_root, metadata, fs)
+
+def generate_v2_graph_nodes(workflow_definition):
+  # Parse Workflow Definition
+  workflow_definition_root = etree.fromstring(workflow_definition)
+  if workflow_definition_root is None:
+    raise MalformedWfDefException()
+
+  xslt_definition_fh = open("%(xslt_dir)s/workflow.xslt" % {
+      'xslt_dir': os.path.join(DEFINITION_XSLT2_DIR.get(), 'workflows')
+    })
+
+  tag = etree.QName(workflow_definition_root.tag)
+  schema_version = tag.namespace
+
+  # Ensure namespace exists
+  if schema_version not in OOZIE_NAMESPACES:
+    raise InvalidTagWithNamespaceException(workflow_definition_root.tag)
+
+  # Get XSLT
+  xslt = etree.parse(xslt_definition_fh)
+  xslt_definition_fh.close()
+  transform = etree.XSLT(xslt)
+
+  # Transform XML using XSLT
+  transformed_root = transform(workflow_definition_root)
+  node_list = str(transformed_root).replace('\n', '').replace(' ', '')
+  node_list = json.loads(node_list)
+
+  return node_list
+
+
+class MalformedWfDefException(Exception):
+  pass
+
+
+class InvalidTagWithNamespaceException(Exception):
+  def __init__(self, namespace):
+    self.namespace = namespace
+    self.namespaces = ', '.join(OOZIE_NAMESPACES)

+ 35 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/action.xslt

@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="extensions/distcp.0.1.xslt"/>
+<xsl:import href="extensions/email.0.1.xslt"/>
+<xsl:import href="extensions/hive.0.1.xslt"/>
+<xsl:import href="extensions/hive.0.2.xslt"/>
+<xsl:import href="extensions/shell.0.1.xslt"/>
+<xsl:import href="extensions/sqoop.0.1.xslt"/>
+<xsl:import href="extensions/sqoop.0.2.xslt"/>
+<xsl:import href="extensions/ssh.0.1.xslt"/>
+<xsl:import href="nodes/fs.xslt"/>
+<xsl:import href="nodes/java.xslt"/>
+<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:import href="nodes/subworkflow.xslt"/>
+
+<xsl:template match="workflow:action" xmlns:workflow="uri:oozie:workflow:0.5">
+  {
+    "name": "<xsl:value-of select="@name"/>",
+    "node_type": "<xsl:value-of select="name(*)"/>",
+
+    <xsl:variable name="ok" select="'ok'"/>
+    <xsl:variable name="error" select="'error'"/>
+    "ok_to": "<xsl:value-of select="*[name()=$ok]/@to"/>",
+    "error_to": "<xsl:value-of select="*[name()=$error]/@to"/>"
+
+    <xsl:apply-templates select="*"/>
+  },
+</xsl:template>
+
+</xsl:stylesheet>

+ 17 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/control.xslt

@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="nodes/fork.xslt"/>
+
+<xsl:template match="workflow:start | workflow:end | workflow:decision | workflow:fork | workflow:join | workflow:kill">
+  {
+    "name": "<xsl:value-of select="@name"/>",
+    "node_type": "<xsl:value-of select="name(.)"/>",
+    "ok_to": "<xsl:value-of select="@to"/>"
+
+    <xsl:apply-imports/>
+  },
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/distcp.0.1.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:distcp="uri:oozie:distcp-action:0.1" exclude-result-prefixes="workflow distcp">
+
+<xsl:import href="../nodes/fields/job_xml.xslt"/>
+
+<xsl:template match="distcp:distcp">
+
+  ,"distcp": <xsl:call-template name="job_xml"/>
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/email.0.1.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:email="uri:oozie:email-action:0.1" exclude-result-prefixes="workflow email">
+
+<xsl:template match="email:email">
+
+  ,"email": {"subject": "<xsl:value-of select="*[local-name()='subject']"/>"}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/hive.0.1.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:hive="uri:oozie:hive-action:0.1" exclude-result-prefixes="workflow hive">
+
+<xsl:import href="../nodes/fields/script_path.xslt"/>
+
+<xsl:template match="hive:hive">
+
+  ,"hive": {<xsl:call-template name="script_path"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/hive.0.2.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:hive="uri:oozie:hive-action:0.2" exclude-result-prefixes="workflow hive">
+
+<xsl:import href="../nodes/fields/script_path.xslt"/>
+
+<xsl:template match="hive:hive">
+
+  ,"hive": {<xsl:call-template name="script_path"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/shell.0.1.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:shell="uri:oozie:shell-action:0.1" exclude-result-prefixes="workflow shell">
+
+<xsl:import href="../nodes/fields/command.xslt"/>
+
+<xsl:template match="shell:shell">
+
+  ,"shell": {<xsl:call-template name="command"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/sqoop.0.1.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:sqoop="uri:oozie:sqoop-action:0.1" exclude-result-prefixes="workflow sqoop">
+
+<xsl:import href="../nodes/fields/script_path.xslt"/>
+
+<xsl:template match="sqoop:sqoop">
+
+  ,"sqoop": {<xsl:call-template name="script_path"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/sqoop.0.2.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:sqoop="uri:oozie:sqoop-action:0.2" exclude-result-prefixes="workflow sqoop">
+
+<xsl:template match="sqoop:sqoop">
+
+  ,"sqoop": {"script_path": "<xsl:value-of select="*[local-name()='command']"/>"}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/extensions/ssh.0.1.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:ssh="uri:oozie:ssh-action:0.1" exclude-result-prefixes="workflow ssh">
+
+<xsl:import href="../nodes/fields/command.xslt"/>
+
+<xsl:template match="ssh:ssh">
+
+  ,"ssh": "<xsl:call-template name="command"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 9 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/command.xslt

@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="command">
+  "command":"<xsl:value-of select="*[local-name()='exec']"/>"
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/jar_path.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="jar_path">
+
+  "jar_path": "<xsl:value-of select="*[local-name()='jar-path']"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 21 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/job_properties.xslt

@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="job_properties">
+  "job_properties":
+    <xsl:text>[</xsl:text>
+    <xsl:for-each select="*[local-name()='configuration']/*[local-name()='property']">
+      <xsl:choose>
+        <xsl:when test="position() &lt; last()">
+          <xsl:text><![CDATA[{"name":"]]></xsl:text><xsl:value-of select="*[local-name()='name']" /><xsl:text><![CDATA[","value":"]]></xsl:text><xsl:value-of select="*[local-name()='value']" /><xsl:text><![CDATA["},]]></xsl:text>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:text><![CDATA[{"name":"]]></xsl:text><xsl:value-of select="*[local-name()='name']" /><xsl:text><![CDATA[","value":"]]></xsl:text><xsl:value-of select="*[local-name() ='value']" /><xsl:text><![CDATA["}]]></xsl:text>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+    <xsl:text>]</xsl:text>
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/job_xml.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="job_xml">
+
+  "job_xml": "<xsl:value-of select="*[local-name()='job-xml']"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/mapper.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="mapper">
+
+  "mapper": "<xsl:value-of select="*[local-name()='streaming']/*[local-name()='mapper']"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 24 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/prepares.xslt

@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="prepares">
+
+  "prepares":
+
+    <xsl:text>[</xsl:text>
+    <xsl:for-each select="*[local-name()='prepare']/*">
+      <xsl:choose>
+        <xsl:when test="position() &lt; last()">
+          <xsl:text><![CDATA[{"type":"]]></xsl:text><xsl:value-of select="local-name()" /><xsl:text><![CDATA[","value":"]]></xsl:text><xsl:value-of select="@path" /><xsl:text><![CDATA["},]]></xsl:text>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:text><![CDATA[{"type":"]]></xsl:text><xsl:value-of select="local-name()" /><xsl:text><![CDATA[","value":"]]></xsl:text><xsl:value-of select="@path" /><xsl:text><![CDATA["}]]></xsl:text>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+    <xsl:text>]</xsl:text>
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 10 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/reducer.xslt

@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="reducer">
+
+  "reducer": "<xsl:value-of select="*[local-name()='streaming']/*[local-name()='reducer']"/>"
+
+</xsl:template>
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/script_path.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="script_path">
+
+  "script_path": "<xsl:value-of select="*[local-name()='script']"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

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

@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="touchzs">
+
+  "touchzs":
+
+    <xsl:text>[</xsl:text>
+    <xsl:for-each select="*[local-name()='touchz']">
+      <xsl:text><![CDATA[{"name":"]]></xsl:text><xsl:value-of select="@path" /><xsl:text><![CDATA["}]]></xsl:text>
+      <xsl:if  test="position() &lt; last()">
+        "<xsl:text>,</xsl:text>"
+      </xsl:if>
+    </xsl:for-each>
+    <xsl:text>]</xsl:text>
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/user.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template name="user">
+
+  "user": "<xsl:value-of select="*[local-name()='user']"/>"
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 26 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fields/xml.xslt

@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" 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">
+
+  "xml":
+    <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>,
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fork.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:template match="workflow:fork" xmlns:workflow="uri:oozie:workflow:0.5">
+  <xsl:for-each select="*">
+    ,"path<xsl:value-of select='position()'/>": "<xsl:value-of select="@start"/>"
+  </xsl:for-each>
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/fs.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/touchzs.xslt"/>
+
+<xsl:template match="workflow:fs" xmlns:workflow="uri:oozie:workflow:0.5">
+
+  ,"fs": { <xsl:call-template name="touchzs"/> }
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/generic.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" 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()!='map-reduce' and local-name()!='pig' and local-name()!='start' and local-name()!='streaming' and local-name()!='subworkflow' 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.5">
+
+  ,"generic": {<xsl:call-template name="xml"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 14 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/java.xslt

@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/jar_path.xslt"/>
+
+<xsl:template match="workflow:java" xmlns:workflow="uri:oozie:workflow:0.5">
+
+  ,"java": {<xsl:call-template name="jar_path"/>}
+
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/mapreduce.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/jar_path.xslt"/>
+
+<xsl:template match="workflow:map-reduce" xmlns:workflow="uri:oozie:workflow:0.5">
+
+  ,"mapreduce": {<xsl:call-template name="jar_path"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 13 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/pig.xslt

@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/script_path.xslt"/>
+
+<xsl:template match="workflow:pig" xmlns:workflow="uri:oozie:workflow:0.5">
+
+  ,"pig": {<xsl:call-template name="script_path"/>}
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 16 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/streaming.xslt

@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/mapper.xslt"/>
+<xsl:import href="fields/reducer.xslt"/>
+
+<xsl:template match="workflow:streaming" xmlns:workflow="uri:oozie:workflow:0.5">
+
+  ,"streaming": {
+        <xsl:call-template name="mapper"/>,
+        <xsl:call-template name="reducer"/> }
+
+</xsl:template>
+
+</xsl:stylesheet>

+ 11 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/nodes/subworkflow.xslt

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:import href="fields/job_properties.xslt"/>
+
+<xsl:template match="workflow:sub-workflow" xmlns:workflow="uri:oozie:workflow:0.5">
+  , <xsl:call-template name="job_properties"/>
+</xsl:template>
+
+</xsl:stylesheet>

+ 16 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/0.5/workflow.xslt

@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" xmlns:sla="uri:oozie:sla:0.2" exclude-result-prefixes="workflow">
+
+<xsl:include href="action.xslt"/>
+<xsl:include href="control.xslt"/>
+
+<xsl:template match="/workflow:workflow-app">
+
+   [ <xsl:apply-templates select="workflow:start | workflow:end | workflow:decision | workflow:fork | workflow:join | workflow:kill"/>
+    <xsl:apply-templates select="workflow:action"/> {}]
+
+</xsl:template>
+
+<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
+</xsl:stylesheet>

+ 14 - 0
apps/oozie/src/oozie/importlib/xslt2/workflows/workflow.xslt

@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:workflow="uri:oozie:workflow:0.5" exclude-result-prefixes="workflow">
+
+<xsl:include href="0.5/workflow.xslt"/>
+
+<xsl:template match="/">
+
+    <xsl:apply-templates select="*"/>
+
+</xsl:template>
+
+<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
+</xsl:stylesheet>

+ 14 - 0
apps/oozie/src/oozie/models2.py

@@ -40,6 +40,7 @@ from liboozie.submission2 import Submission
 from liboozie.submission2 import create_directories
 
 from oozie.conf import REMOTE_SAMPLE_DIR
+from oozie.importlib.workflows import generate_v2_graph_nodes, MalformedWfDefException, InvalidTagWithNamespaceException
 from oozie.utils import utc_datetime_format
 from hadoop.fs.exceptions import WebHdfsException
 
@@ -289,6 +290,19 @@ class Workflow(Job):
   def get_application_path_key(cls):
     return 'oozie.wf.application.path'
 
+  @classmethod
+  def gen_workflow_data_from_xml(cls, user, oozie_workflow):
+    try:
+      return generate_v2_graph_nodes(oozie_workflow.definition)
+    except MalformedWfDefException, e:
+      LOG.exception(_("Could not find any nodes in Workflow definition. Maybe it's malformed?"))
+    except InvalidTagWithNamespaceException, e:
+      LOG.exception(_("Tag with namespace %(namespace)s is not valid. Please use one of the following namespaces: %(namespaces)s") % {
+      'namespace': e.namespace,
+      'namespaces': e.namespaces
+    })
+    return []
+
 
 class Node():
   def __init__(self, data):

+ 36 - 0
apps/oozie/src/oozie/test_data/xslt2/test-workflow.xml

@@ -0,0 +1,36 @@
+<workflow-app name="Sub" xmlns="uri:oozie:workflow:0.5">
+    <start to="fork-68d4"/>
+    <kill name="Kill">
+        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
+    </kill>
+    <action name="subworkflow-a13f">
+        <sub-workflow>
+            <app-path>${nameNode}/user/hue/oozie/deployments/_admin_-oozie-50001-1427488969.48</app-path>
+              <propagate-configuration/>
+            <configuration>
+                <property>
+                    <name>hue-id-w</name>
+                    <value>50001</value>
+                </property>
+            </configuration>
+        </sub-workflow>
+        <ok to="join-775e"/>
+        <error to="Kill"/>
+    </action>
+    <action name="shell-0f44">
+        <shell xmlns="uri:oozie:shell-action:0.1">
+            <job-tracker>${jobTracker}</job-tracker>
+            <name-node>${nameNode}</name-node>
+            <exec>ls</exec>
+              <capture-output/>
+        </shell>
+        <ok to="join-775e"/>
+        <error to="Kill"/>
+    </action>
+    <fork name="fork-68d4">
+        <path start="subworkflow-a13f" />
+        <path start="shell-0f44" />
+    </fork>
+    <join name="join-775e" to="End"/>
+    <end name="End"/>
+</workflow-app>

+ 12 - 0
apps/oozie/src/oozie/tests2.py

@@ -117,6 +117,18 @@ LIMIT $limit"""))
     assert_equal('My_______1st_W$rkflow__With___Bad__lette', job.validated_name)
 
 
+class TestUtils():
+
+  def setUp(self):
+    self.wf = Workflow()
+
+  def test_gen_workflow_data_from_xml(self):
+    f = open('apps/oozie/src/oozie/test_data/xslt2/test-workflow.xml')
+    self.wf.definition = f.read()
+    node_list = "[{u'node_type': u'start', u'ok_to': u'fork-68d4', u'name': u''}, {u'node_type': u'kill', u'ok_to': u'', u'name': u'Kill'}, {u'path2': u'shell-0f44', u'node_type': u'fork', u'ok_to': u'', u'name': u'fork-68d4', u'path1': u'subworkflow-a13f'}, {u'node_type': u'join', u'ok_to': u'End', u'name': u'join-775e'}, {u'node_type': u'end', u'ok_to': u'', u'name': u'End'}, {u'node_type': u'sub-workflow', u'ok_to': u'join-775e', u'name': u'subworkflow-a13f', u'job_properties': [{u'name': u'hue-id-w', u'value': u'50001'}], u'error_to': u'Kill'}, {u'shell': {u'command': u'ls'}, u'node_type': u'shell', u'ok_to': u'join-775e', u'name': u'shell-0f44', u'error_to': u'Kill'}, {}]"
+    assert_equal(node_list, str(Workflow.gen_workflow_data_from_xml('admin', self.wf)))
+
+
 #  def test_workflow_name(self):
 #    try:
 #      workflow_dict = WORKFLOW_DICT.copy()

+ 4 - 1
apps/oozie/src/oozie/views/dashboard.py

@@ -288,7 +288,10 @@ def list_oozie_workflow(request, job_id):
         workflow_data = new_workflow.get_data()
         credentials = Credentials()
       else:
-        workflow_graph, full_node_list = OldWorkflow.gen_status_graph_from_xml(request.user, oozie_workflow)
+        try:
+          Workflow.gen_workflow_data_from_xml(request.user, oozie_workflow)
+        except Exception, e:
+          LOG.exception(_('Graph data could not be generated from Workflow %s: %s' % (oozie_workflow.id, e)))
     except:
       LOG.exception("Ignoring error updating Document2 record for job_id=%s", job_id)
   else: