|
|
@@ -31,6 +31,7 @@ Action extensions are also versioned.
|
|
|
Every action extension will have its own version via /xslt/<workflow version>/extensions/<name of extensions>.<version>.xslt
|
|
|
"""
|
|
|
|
|
|
+import json
|
|
|
import logging
|
|
|
from lxml import etree
|
|
|
import os
|
|
|
@@ -53,6 +54,50 @@ OOZIE_NAMESPACES = ['uri:oozie:workflow:0.1', 'uri:oozie:workflow:0.2', 'uri:ooz
|
|
|
LINKS = ('ok', 'error', 'path')
|
|
|
|
|
|
|
|
|
+def _set_properties(workflow, root, namespace):
|
|
|
+ # root should be config element.
|
|
|
+ properties = []
|
|
|
+ seen = {}
|
|
|
+ namespaces = {
|
|
|
+ 'n': namespace
|
|
|
+ }
|
|
|
+
|
|
|
+ for prop in root.xpath('n:property', namespaces=namespaces):
|
|
|
+ name = prop.xpath('n:name', namespaces=namespaces)[0].text
|
|
|
+ value = prop.xpath('n:value', namespaces=namespaces)[0].text
|
|
|
+ if name not in seen:
|
|
|
+ properties.append({'name': name, 'value': value})
|
|
|
+ seen[name] = True
|
|
|
+
|
|
|
+ workflow.job_properties = json.dumps(properties)
|
|
|
+
|
|
|
+
|
|
|
+def _global_configuration(workflow, root, namespace):
|
|
|
+ # root should be global config element.
|
|
|
+ namespaces = {
|
|
|
+ 'n': namespace
|
|
|
+ }
|
|
|
+
|
|
|
+ job_xml = root.xpath('n:job-xml', namespaces=namespaces)
|
|
|
+ configuration = root.xpath('n:configuration', namespaces=namespaces)
|
|
|
+ if job_xml:
|
|
|
+ workflow.job_xml = job_xml[0].text
|
|
|
+ if configuration:
|
|
|
+ _set_properties(workflow, configuration[0], namespace)
|
|
|
+
|
|
|
+
|
|
|
+def _assign_workflow_properties(workflow, root, namespace):
|
|
|
+ namespaces = {
|
|
|
+ 'n': namespace
|
|
|
+ }
|
|
|
+
|
|
|
+ global_config = root.xpath('n:global', namespaces=namespaces)
|
|
|
+ if global_config:
|
|
|
+ _global_configuration(workflow, global_config[0], namespace)
|
|
|
+
|
|
|
+ LOG.debug("Finished assigning properties to workflow %s" % smart_str(workflow.name))
|
|
|
+
|
|
|
+
|
|
|
def _save_links(workflow, root):
|
|
|
"""
|
|
|
Iterates over all links in the passed XML doc and creates links.
|
|
|
@@ -77,7 +122,7 @@ def _save_links(workflow, root):
|
|
|
|
|
|
Note: The nodes that these links point to should exist already.
|
|
|
Note: Nodes are looked up by workflow and name.
|
|
|
- Note: Skip global configuration explicitly. Unknown knows should throw an error.
|
|
|
+ Note: Unknown elements should throw an error.
|
|
|
"""
|
|
|
# Iterate over nodes
|
|
|
for child_el in root:
|
|
|
@@ -608,6 +653,7 @@ def import_workflow_root(workflow, workflow_definition_root, metadata=None, fs=N
|
|
|
_preprocess_nodes(workflow, transformed_root, workflow_definition_root, nodes, fs)
|
|
|
_save_nodes(workflow, nodes)
|
|
|
_save_links(workflow, workflow_definition_root)
|
|
|
+ _assign_workflow_properties(workflow, workflow_definition_root, schema_version)
|
|
|
if metadata:
|
|
|
_process_metadata(workflow, metadata)
|
|
|
|