Jelajahi Sumber

HUE-6737 [fb] Submit workflow.xml sends to Hue 3

Romain Rigaux 8 tahun lalu
induk
melakukan
fa5f51d98d

+ 11 - 1
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -1705,7 +1705,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
 
       self.submitSelected = function() {
         % if 'oozie' in apps:
-          $.get("${ url('oozie:submit_external_job', application_path='/') }../" + self.selectedFile().path, function (response) {
+          $.get("${ url('oozie:submit_external_job', application_path='/') }../" + self.selectedFile().path, {'format': IS_HUE_4 ? 'json' : 'html'}, function (response) {
             $('#submit-wf-modal').html(response);
             $('#submit-wf-modal').modal('show');
           });
@@ -2427,6 +2427,16 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
         });
       });
 
+      huePubSub.subscribe('submit.popup.return', function (data) {
+        if (data.type == 'external_workflow') {
+          $.jHueNotify.info('${_('Workflow submitted.')}');
+          huePubSub.publish('open.link', '/jobbrowser/#!id=' + data.job_id);
+          huePubSub.publish('browser.job.open.link', data.job_id);
+          $('.submit-modal').modal('hide');
+          $('.modal-backdrop').hide();
+        }
+      }, 'filebrowser');
+
       huePubSub.subscribe('update.history', function(){
         if (getHistory().length == 0) {
           $('.history').addClass('no-history');

+ 30 - 1
apps/oozie/src/oozie/templates/editor/submit_job_popup.mako

@@ -21,7 +21,7 @@
 <%namespace name="utils" file="../utils.inc.mako" />
 
 
-<form action="${ action }" method="POST">
+<form action="${ action }" method="POST" class="form submit-external-workflow-form">
   ${ csrf_token(request) | n,unicode }
   <div class="modal-header">
     <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
@@ -52,6 +52,10 @@
             </div>
           </div>
          % endfor
+
+        % if return_json:
+          <input type="hidden" name="format" value="json">
+        % endif
       </div>
     </fieldset>
 
@@ -66,3 +70,28 @@
     <input id="submit-btn" type="submit" class="btn btn-primary" value="${ _('Submit') }"/>
   </div>
 </form>
+
+% if return_json:
+<script type="text/javascript">
+    $('.submit-external-workflow-form').submit(function (e) {
+      $.ajax({
+        type: "POST",
+        url: '${ action }',
+        data: $('.submit-external-workflow-form').serialize(),
+        dataType: "json",
+        success: function (data) {
+          if (data.status == 0) {
+            huePubSub.publish('submit.popup.return', data);
+          } else {
+            var message = "${ _('Submission was not successful') }";
+            if (data.message) {
+              message = data.message;
+            }
+            $.jHueNotify.error(data.message + (data.detail ? (': ' + data.detail) : ''));
+          }
+        }
+      });
+      e.preventDefault();
+    });
+</script>
+% endif

+ 9 - 6
apps/oozie/src/oozie/views/dashboard.py

@@ -953,14 +953,16 @@ def submit_external_job(request, application_path):
         detail = ex._headers.get('oozie-error-message', ex)
         if 'Max retries exceeded with url' in str(detail):
           detail = '%s: %s' % (_('The Oozie server is not running'), detail)
-
         LOG.exception(smart_str(detail))
-
         raise PopupException(_("Error submitting job %s") % (application_path,), detail=detail)
 
-      request.info(_('Oozie job submitted'))
-      view = 'list_oozie_bundle' if application_name == 'bundle.xml' else 'list_oozie_coordinator' if application_name == 'coordinator.xml' else 'list_oozie_workflow'
-      return redirect(reverse('oozie:%s' % view, kwargs={'job_id': job_id}))
+      jsonify = request.POST.get('format') == 'json'
+      if jsonify:
+        return JsonResponse({'status': 0, 'job_id': job_id, 'type': 'external_workflow'}, safe=False)
+      else:
+        request.info(_('Oozie job submitted'))
+        view = 'list_oozie_bundle' if application_name == 'bundle.xml' else 'list_oozie_coordinator' if application_name == 'coordinator.xml' else 'list_oozie_workflow'
+        return redirect(reverse('oozie:%s' % view, kwargs={'job_id': job_id}))
     else:
       request.error(_('Invalid submission form: %s' % params_form.errors))
   else:
@@ -972,7 +974,8 @@ def submit_external_job(request, application_path):
                    'params_form': params_form,
                    'name': _('Job'),
                    'action': reverse('oozie:submit_external_job', kwargs={'application_path': application_path}),
-                   'show_dryrun': os.path.basename(application_path) != 'bundle.xml'
+                   'show_dryrun': os.path.basename(application_path) != 'bundle.xml',
+                   'return_json': request.GET.get('format') == 'json'
                  }, force_template=True).content
   return JsonResponse(popup, safe=False)