Преглед изворни кода

HUE-1086 [oozie] Coordinator submission should prefil variables from workflow properties

Add tests
Fix 2.4 compatibility problem
Fix multi-statement exception in Beeswax
Romain Rigaux пре 12 година
родитељ
комит
000d97f113

+ 5 - 1
apps/beeswax/src/beeswax/views.py

@@ -600,10 +600,14 @@ def watch_query_refresh_json(request, id):
     if not query_history.is_finished() and query_history.is_success() and not query_history.has_results:
       db.execute_next_statement(query_history)
       handle, state = _get_query_handle_and_state(query_history)
+  except BeeswaxException, ex:
+    LOG.exception(ex)
+    handle, state = _get_query_handle_and_state(query_history)
 
+  try:
     log = db.get_log(handle)
   except BeeswaxException, ex:
-    handle, state = _get_query_handle_and_state(query_history)
+    log = str(ex)
 
   jobs = _parse_out_hadoop_jobs(log)
   job_urls = dict([(job, reverse('jobbrowser.views.single_job', kwargs=dict(job=job))) for job in jobs])

+ 3 - 0
apps/oozie/src/oozie/models.py

@@ -1324,6 +1324,9 @@ class Coordinator(Job):
     for ds in self.dataoutput_set.all():
       params.pop(ds.name, None)
 
+    for wf_param in json.loads(self.job_properties):
+      params.pop(wf_param['name'], None)
+
     return params
 
 

+ 30 - 2
apps/oozie/src/oozie/tests.py

@@ -1078,6 +1078,10 @@ class TestEditor(OozieMockBase):
         '          <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'
@@ -1157,6 +1161,10 @@ class TestEditor(OozieMockBase):
           <name>username</name>
           <value>${coord:user()}</value>
         </property>
+        <property>
+          <name>SLEEP</name>
+          <value>1000</value>
+        </property>
       </configuration>
    </workflow>
   </action>
@@ -1225,7 +1233,7 @@ class TestEditor(OozieMockBase):
     create_dataset(coord, self.c)
     create_coordinator_data(coord, self.c)
 
-    assert_equal([{'name': u'output', 'value': ''}, {'name': u'SLEEP', 'value': ''}, {'name': u'market', 'value': u'US'}],
+    assert_equal([{'name': u'output', 'value': ''}, {'name': u'market', 'value': u'US'}],
                  coord.find_all_parameters())
 
 
@@ -1258,6 +1266,26 @@ class TestEditor(OozieMockBase):
     assert_true('&quot;&gt;&lt;script&gt;alert(1);&lt;/script&gt;' in resp.content, resp.content)
 
 
+  def test_submit_workflow(self):
+    # Check param popup
+    response = self.c.get(reverse('oozie:submit_workflow', args=[self.wf.id]))
+    assert_equal([{'name': u'output', 'value': ''},
+                  {'name': u'SLEEP', 'value': ''},
+                  {'name': u'market', 'value': u'US'}
+                  ],
+                  response.context['params_form'].initial)
+
+  def test_submit_coordinator(self):
+    coord = create_coordinator(self.wf, self.c)
+
+    # Check param popup, SLEEP is set by coordinator so not shown in the popup
+    response = self.c.get(reverse('oozie:submit_coordinator', args=[coord.id]))
+    assert_equal([{'name': u'output', 'value': ''},
+                  {'name': u'market', 'value': u'US'}
+                  ],
+                  response.context['params_form'].initial)
+
+
 class TestEditorBundle(OozieMockBase):
 
   def setUp(self):
@@ -2581,7 +2609,7 @@ COORDINATOR_DICT = {
     u'end_0': [u'07/04/2012'], u'end_1': [u'12:00 AM'],
     u'timezone': [u'America/Los_Angeles'],
     u'parameters': [u'[{"name":"market","value":"US"}]'],
-    u'job_properties': [u'[{"name":"username","value":"${coord:user()}"}]'],
+    u'job_properties': [u'[{"name":"username","value":"${coord:user()}"},{"name":"SLEEP","value":"1000"}]'],
     u'timeout': [u'100'],
     u'concurrency': [u'3'],
     u'execution': [u'FIFO'],

+ 2 - 2
desktop/core/src/desktop/lib/json_utils.py

@@ -36,14 +36,14 @@ class JSONEncoderForHTML(json.JSONEncoder):
     def encode(self, o):
         # Override JSONEncoder.encode because it has hacks for
         # performance that make things more complicated.
-        chunks = self.iterencode(o, True)
+        chunks = self.iterencode(o) # .iterencode(o, True) because of 2.4
         if self.ensure_ascii:
             return ''.join(chunks)
         else:
             return u''.join(chunks)
 
     def iterencode(self, o, _one_shot=False):
-        chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot)
+        chunks = super(JSONEncoderForHTML, self).iterencode(o) # .iterencode(o, _one_shot) because of 2.4
         for chunk in chunks:
             chunk = chunk.replace('&', '\\u0026')
             chunk = chunk.replace('<', '\\u003c')