소스 검색

[oozie] Importing workflow with credentials

https://github.com/cloudera/hue/pull/156
Mariusz Strzelecki 10 년 전
부모
커밋
36d7109646
3개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      apps/oozie/src/oozie/importlib/workflows.py
  2. 29 0
      apps/oozie/src/oozie/test_data/workflows/0.4/test-credentials.xml
  3. 15 0
      apps/oozie/src/oozie/tests.py

+ 12 - 0
apps/oozie/src/oozie/importlib/workflows.py

@@ -138,6 +138,10 @@ def _save_links(workflow, root):
     if child_el.tag.endswith('global'):
       continue
 
+    # Skip credentials configuration.
+    if child_el.tag.endswith('credentials'):
+      continue
+
     tag = etree.QName(child_el).localname
     name = child_el.attrib.get('name', tag)
     LOG.debug("Getting node with data - XML TAG: %(tag)s\tLINK NAME: %(node_name)s\tWORKFLOW NAME: %(workflow_name)s" % {
@@ -520,10 +524,18 @@ def _prepare_nodes(workflow, root):
 def _preprocess_nodes(workflow, transformed_root, workflow_definition_root, nodes, fs=None):
   """
   preprocess nodes
+  Sets credentials keys for actions.
   Resolve start name and subworkflow dependencies.
   Looks at path and interrogates all workflows until the proper deployment path is found.
   If the proper deployment path is never found, then
   """
+
+  for action_el in workflow_definition_root:
+    if 'cred' in action_el.attrib:
+      for full_node in nodes:
+        if full_node.name == action_el.attrib['name']:
+          full_node.credentials = [{"name": cred, "value": True} for cred in action_el.attrib['cred'].split(',')];
+
   for full_node in nodes:
     if full_node.node_type is 'start':
       full_node.name = 'start'

+ 29 - 0
apps/oozie/src/oozie/test_data/workflows/0.4/test-credentials.xml

@@ -0,0 +1,29 @@
+
+<workflow-app name="credentiale" xmlns="uri:oozie:workflow:0.4">
+  <credentials>
+    <credential name="hcat" type="hcat">
+      <property>
+        <name>hcat.metastore.uri</name>
+        <value>URI</value>
+      </property>
+      <property>
+        <name>hcat.metastore.principal</name>
+        <value>PRINCIPAL</value>
+      </property>
+    </credential>
+  </credentials>
+    <start to="hive"/>
+    <action name="hive" cred="hcat">
+        <hive xmlns="uri:oozie:hive-action:0.2">
+            <job-tracker>${jobTracker}</job-tracker>
+            <name-node>${nameNode}</name-node>
+            <script>hive.hql</script>
+        </hive>
+        <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>

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

@@ -2141,6 +2141,21 @@ class TestImportWorkflow04(OozieMockBase):
     assert_equal('uri:oozie:workflow:0.4', workflow.schema_version)
     workflow.delete(skip_trash=True)
 
+  def test_import_workflow_credentials(self):
+    """
+    Validates import for workflow with credentials.
+    """
+    workflow = Workflow.objects.new_workflow(self.user)
+    workflow.save()
+    f = open('apps/oozie/src/oozie/test_data/workflows/0.4/test-credentials.xml')
+    import_workflow(workflow, f.read())
+    f.close()
+    credentials = Node.objects.get(workflow=workflow, node_type='hive').credentials
+    assert_equal(1, len(credentials))
+    assert_equal('hcat', credentials[0]['name'])
+    assert_equal(True, credentials[0]['value'])
+    workflow.delete(skip_trash=True)
+
 
   def test_import_workflow_basic_global_config(self):
     """