Răsfoiți Sursa

HUE-2879 [oozie] Adding a dryrun before submitting workflow or coordinator

krish 10 ani în urmă
părinte
comite
2fcbafab4a

+ 6 - 0
apps/oozie/src/oozie/templates/editor/submit_job_popup.mako

@@ -54,6 +54,12 @@
          % endfor
       </div>
     </fieldset>
+
+    % if show_dryrun:
+      <label class="checkbox" style="display: inline-block; margin-top: 5px">
+        <input type="checkbox" name="dryrun_checkbox" /> ${ _('Do a dryrun before submitting the job?') }
+      </label>
+    % endif
   </div>
   <div class="modal-footer">
     <a href="#" class="btn" data-dismiss="modal">${ _('Cancel') }</a>

+ 6 - 0
apps/oozie/src/oozie/templates/editor2/submit_job_popup.mako

@@ -69,6 +69,12 @@
          % endfor
       </div>
       <div class="clearfix"></div>
+
+      % if show_dryrun:
+         <label class="checkbox" style="display: inline-block; margin-top: 5px">
+           <input type="checkbox" name="dryrun_checkbox" /> ${ _('Do a dryrun before submitting the job?') }
+         </label>
+      % endif
   </div>
   <div class="modal-footer">
     <a href="#" class="btn" data-dismiss="modal">${ _('Cancel') }</a>

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

@@ -805,6 +805,7 @@ def submit_external_job(request, application_path):
 
     if params_form.is_valid():
       mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
+      mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
       application_name = os.path.basename(application_path)
       application_class = Bundle if application_name == 'bundle.xml' else Coordinator if application_name == 'coordinator.xml' else get_workflow()
       mapping[application_class.get_application_path_key()] = application_path
@@ -834,7 +835,8 @@ def submit_external_job(request, application_path):
   popup = render('editor/submit_job_popup.mako', request, {
                    'params_form': params_form,
                    'name': _('Job'),
-                   'action': reverse('oozie:submit_external_job', kwargs={'application_path': application_path})
+                   'action': reverse('oozie:submit_external_job', kwargs={'application_path': application_path}),
+                   'show_dryrun': os.path.basename(application_path) != 'bundle.xml'
                  }, force_template=True).content
   return JsonResponse(popup, safe=False)
 

+ 8 - 3
apps/oozie/src/oozie/views/editor2.py

@@ -340,6 +340,7 @@ def submit_workflow(request, doc_id):
 
     if params_form.is_valid():
       mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
+      mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
 
       try:
         job_id = _submit_workflow(request.user, request.fs, request.jt, workflow, mapping)
@@ -357,7 +358,8 @@ def submit_workflow(request, doc_id):
     popup = render('editor2/submit_job_popup.mako', request, {
                      'params_form': params_form,
                      'name': workflow.name,
-                     'action': reverse('oozie:editor_submit_workflow', kwargs={'doc_id': workflow.id})
+                     'action': reverse('oozie:editor_submit_workflow', kwargs={'doc_id': workflow.id}),
+                     'show_dryrun': True
                    }, force_template=True).content
     return JsonResponse(popup, safe=False)
 
@@ -542,6 +544,7 @@ def submit_coordinator(request, doc_id):
 
     if params_form.is_valid():
       mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
+      mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
       job_id = _submit_coordinator(request, coordinator, mapping)
 
       request.info(_('Coordinator submitted.'))
@@ -556,7 +559,8 @@ def submit_coordinator(request, doc_id):
   popup = render('editor2/submit_job_popup.mako', request, {
                  'params_form': params_form,
                  'name': coordinator.name,
-                 'action': reverse('oozie:editor_submit_coordinator',  kwargs={'doc_id': coordinator.id})
+                 'action': reverse('oozie:editor_submit_coordinator',  kwargs={'doc_id': coordinator.id}),
+                 'show_dryrun': True
                 }, force_template=True).content
   return JsonResponse(popup, safe=False)
 
@@ -709,7 +713,8 @@ def submit_bundle(request, doc_id):
   popup = render('editor2/submit_job_popup.mako', request, {
                  'params_form': params_form,
                  'name': bundle.name,
-                 'action': reverse('oozie:editor_submit_bundle',  kwargs={'doc_id': bundle.id})
+                 'action': reverse('oozie:editor_submit_bundle',  kwargs={'doc_id': bundle.id}),
+                 'show_dryrun': False
                 }, force_template=True).content
   return JsonResponse(popup, safe=False)
 

+ 14 - 0
desktop/libs/liboozie/src/liboozie/oozie_api.py

@@ -250,6 +250,20 @@ class OozieApi(object):
     resp = self._root.post('jobs', params, data=config_gen(properties), contenttype=_XML_CONTENT_TYPE)
     return resp['id']
 
+  def dryrun(self, properties=None):
+    defaults = {
+      'user.name': self.user,
+    }
+
+    if properties is not None:
+      defaults.update(properties)
+
+    properties = defaults
+
+    params = self._get_params()
+    params['action'] = 'dryrun'
+    return self._root.post('jobs', params, data=config_gen(properties), contenttype=_XML_CONTENT_TYPE)
+
   def rerun(self, jobid, properties=None, params=None):
     properties = self._get_oozie_properties(properties)
     if params is None:

+ 19 - 10
desktop/libs/liboozie/src/liboozie/submission2.py

@@ -20,6 +20,7 @@ import logging
 import os
 import time
 
+from django.utils.functional import wraps
 from django.utils.translation import ugettext as _
 
 from desktop.lib.exceptions_renderable import PopupException
@@ -39,6 +40,23 @@ from liboozie.credentials import Credentials
 
 LOG = logging.getLogger(__name__)
 
+def submit_dryrun(run_func):
+  def decorate(self, deployment_dir=None):
+    if self.oozie_id is not None:
+      raise Exception(_("Submission already submitted (Oozie job id %s)") % (self.oozie_id,))
+
+    jt_address = cluster.get_cluster_addr_for_job_submission()
+
+    if deployment_dir is None:
+      self._update_properties(jt_address) # Needed as we need to set some properties like Credentials before
+      deployment_dir = self.deploy()
+
+    self._update_properties(jt_address, deployment_dir)
+    if self.properties.get('dryrun'):
+      self.api.dryrun(self.properties)
+    return run_func(self, deployment_dir)
+  return wraps(run_func)(decorate)
+
 
 class Submission(object):
   """
@@ -72,21 +90,12 @@ class Submission(object):
       res += " -- " + self.oozie_id
     return res
 
+  @submit_dryrun
   def run(self, deployment_dir=None):
     """
     Take care of all the actions of submitting a Oozie workflow.
     Returns the oozie job id if all goes well.
     """
-    if self.oozie_id is not None:
-      raise Exception(_("Submission already submitted (Oozie job id %s)") % (self.oozie_id,))
-
-    jt_address = cluster.get_cluster_addr_for_job_submission()
-
-    if deployment_dir is None:
-      self._update_properties(jt_address) # Needed as we need to set some properties like Credentials before
-      deployment_dir = self.deploy()
-
-    self._update_properties(jt_address, deployment_dir)
 
     self.oozie_id = self.api.submit_job(self.properties)
     LOG.info("Submitted: %s" % (self,))

+ 20 - 10
desktop/libs/liboozie/src/liboozie/submittion.py

@@ -21,6 +21,7 @@ import os
 import re
 import time
 
+from django.utils.functional import wraps
 from django.utils.translation import ugettext as _
 
 from desktop.lib.exceptions_renderable import PopupException
@@ -36,6 +37,24 @@ from liboozie.credentials import Credentials
 LOG = logging.getLogger(__name__)
 
 
+def submit_dryrun(run_func):
+  def decorate(self, deployment_dir=None):
+    if self.oozie_id is not None:
+      raise Exception(_("Submission already submitted (Oozie job id %s)") % (self.oozie_id,))
+
+    jt_address = cluster.get_cluster_addr_for_job_submission()
+
+    if deployment_dir is None:
+      self._update_properties(jt_address) # Needed as we need to set some properties like Credentials before
+      deployment_dir = self.deploy()
+
+    self._update_properties(jt_address, deployment_dir)
+    if self.properties.get('dryrun'):
+      self.api.dryrun(self.properties)
+    return run_func(self, deployment_dir)
+  return wraps(run_func)(decorate)
+
+
 class Submission(object):
   """
   Represents one unique Oozie submission.
@@ -66,21 +85,12 @@ class Submission(object):
       res += " -- " + self.oozie_id
     return res
 
+  @submit_dryrun
   def run(self, deployment_dir=None):
     """
     Take care of all the actions of submitting a Oozie workflow.
     Returns the oozie job id if all goes well.
     """
-    if self.oozie_id is not None:
-      raise Exception(_("Submission already submitted (Oozie job id %s)") % (self.oozie_id,))
-
-    jt_address = cluster.get_cluster_addr_for_job_submission()
-
-    if deployment_dir is None:
-      self._update_properties(jt_address) # Needed as we need to set some properties like Credentials before
-      deployment_dir = self.deploy()
-
-    self._update_properties(jt_address, deployment_dir)
 
     self.oozie_id = self.api.submit_job(self.properties)
     LOG.info("Submitted: %s" % (self,))