浏览代码

HUE-1488 [oozie] Coordinator should reuse workflow properties

Workflow properties do not need to be all redefined in tje coordinator
workflow properties. They are picked up from the workflow and can be
overriden in Step 5 of the coordinator.
Romain Rigaux 12 年之前
父节点
当前提交
d817bdc
共有 2 个文件被更改,包括 46 次插入31 次删除
  1. 9 2
      apps/oozie/src/oozie/models.py
  2. 37 29
      apps/oozie/src/oozie/tests.py

+ 9 - 2
apps/oozie/src/oozie/models.py

@@ -1268,7 +1268,7 @@ class Coordinator(Job):
                                  help_text=_t('The materialization or creation throttle value for its coordinator actions. '
                                               'Number of maximum coordinator actions that are allowed to be in WAITING state concurrently.'))
   job_properties = models.TextField(default='[]', verbose_name=_t('Workflow properties'),
-                                    help_text=_t('Configuration properties to transmit to the workflow, e.g. limit=100, and EL functions, e.g. username=${coord:user()}'))
+                                    help_text=_t('Additional properties to transmit to the workflow, e.g. limit=100, and EL functions, e.g. username=${coord:user()}'))
 
   objects = TrashManager()
 
@@ -1332,7 +1332,14 @@ class Coordinator(Job):
     return 'coordinator.xml'
 
   def get_properties(self):
-    return json.loads(self.job_properties)
+    props = json.loads(self.job_properties)
+    index = [prop['name'] for prop in props]
+
+    for prop in self.workflow.get_parameters():
+      if not prop['name'] in index:
+        props.append(prop)
+
+    return props
 
   @property
   def job_properties_escapejs(self):

+ 37 - 29
apps/oozie/src/oozie/tests.py

@@ -37,7 +37,7 @@ from liboozie.oozie_api_test import OozieServerProvider
 from liboozie.types import WorkflowList, Workflow as OozieWorkflow, Coordinator as OozieCoordinator,\
   Bundle as OozieBundle, CoordinatorList, WorkflowAction, BundleList
 
-from oozie.models import Workflow, Node, Kill, Streaming, Link, Job, Coordinator, History,\
+from oozie.models import Workflow, Node, Kill, Link, Job, Coordinator, History,\
   find_parameters, NODE_TYPES, Bundle
 from oozie.conf import SHARE_JOBS
 from oozie.utils import workflow_to_dict, model_to_dict, smart_path
@@ -1178,33 +1178,37 @@ class TestEditor(OozieMockBase):
   def test_coordinator_gen_xml(self):
     coord = create_coordinator(self.wf, self.c)
 
-    assert_equal(
-        '<coordinator-app name="MyCoord"\n'
-        '  frequency="${coord:days(1)}"\n'
-        '  start="2012-07-01T00:00Z" end="2012-07-04T00:00Z" timezone="America/Los_Angeles"\n'
-        '  xmlns="uri:oozie:coordinator:0.2">\n'
-        '  <controls>\n'
-        '    <timeout>100</timeout>\n'
-        '    <concurrency>3</concurrency>\n'
-        '    <execution>FIFO</execution>\n'
-        '    <throttle>10</throttle>\n'
-        '  </controls>\n'
-        '  <action>\n'
-        '    <workflow>\n'
-        '      <app-path>${wf_application_path}</app-path>\n'
-        '      <configuration>\n'
-        '        <property>\n'
-        '          <name>username</name>\n'
-        '          <value>${coord:user()}</value>\n'
-        '        </property>\n'
-        '        <property>\n'
-        '          <name>SLEEP</name>\n'
-        '          <value>1000</value>\n'
-        '        </property>\n'
-        '      </configuration>\n'
-        '   </workflow>\n'
-        '  </action>\n'
-        '</coordinator-app>\n'.split(), coord.to_xml().split())
+    assert_true(
+"""<coordinator-app name="MyCoord"
+  frequency="${coord:days(1)}"
+  start="2012-07-01T00:00Z" end="2012-07-04T00:00Z" timezone="America/Los_Angeles"
+  xmlns="uri:oozie:coordinator:0.2">
+  <controls>
+    <timeout>100</timeout>
+    <concurrency>3</concurrency>
+    <execution>FIFO</execution>
+    <throttle>10</throttle>
+  </controls>
+  <action>
+    <workflow>
+      <app-path>${wf_application_path}</app-path>
+      <configuration>
+        <property>
+          <name>username</name>
+          <value>${coord:user()}</value>
+        </property>
+        <property>
+          <name>SLEEP</name>
+          <value>1000</value>
+        </property>
+        <property>
+          <name>market</name>
+          <value>US</value>
+        </property>
+      </configuration>
+   </workflow>
+  </action>
+</coordinator-app>""" in coord.to_xml(), coord.to_xml())
 
 
   def test_coordinator_with_data_input_gen_xml(self):
@@ -1221,7 +1225,7 @@ class TestEditor(OozieMockBase):
                           u'create-advanced_end_instance': [u'0'],
                           u'create-start_0': [u'07/01/2012'], u'create-start_1': [u'12:00 AM'],
                           u'create-timezone': [u'America/Los_Angeles'], u'create-done_flag': [u''],
-                        u'create-description': [u'']})
+                          u'create-description': [u'']})
 
     self.c.post(reverse('oozie:create_coordinator_data', args=[coord.id, 'output']),
                          {u'output-name': [u'output_dir'], u'output-dataset': [u'2']})
@@ -1284,6 +1288,10 @@ class TestEditor(OozieMockBase):
           <name>SLEEP</name>
           <value>1000</value>
         </property>
+        <property>
+          <name>market</name>
+          <value>US</value>
+        </property>
       </configuration>
    </workflow>
   </action>