Pārlūkot izejas kodu

HUE-1176 [jb] Add rerun action of coordinator actions

Romain Rigaux 8 gadi atpakaļ
vecāks
revīzija
bf3e3f0

+ 39 - 16
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -237,7 +237,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 </div>
 
 <!-- ko if: $root.job() -->
-  <div id="rerun-modal" class="modal hide" data-bind="html: $root.job().rerunModalContent"></div>
+  <div id="rerun-modal" class="modal" data-bind="html: $root.job().rerunModalContent"></div>
 <!-- /ko -->
 
 </div>
@@ -989,7 +989,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       self.properties = ko.mapping.fromJS(job.properties || {});
       self.mainType = ko.observable(vm.interface());
 
-      self.coordinatorActions = ko.computed(function() {
+      self.coordinatorActions = ko.pureComputed(function() {
         if (self.mainType() == 'schedules' && self.properties['tasks']) {
           var apps = [];
           self.properties['tasks']().forEach(function (instance) {
@@ -1168,9 +1168,12 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 
         if (vm.job() == self && self.apiStatus() == 'RUNNING') {
           lastFetchJobRequest = self._fetchJob(function (data) {
-            // vm.job(new Job(vm, data.app)); // Updates everything but redraw the page
-            vm.job().fetchStatus();
-            vm.job().fetchLogs();
+            if (vm.job().type() == 'schedule') {
+              vm.job(new Job(vm, data.app)); // Updates everything but redraw the page
+            } else {
+              vm.job().fetchStatus();
+              vm.job().fetchLogs();
+            }
             // vm.job().fetchProfile(); // Get name of active tab?
             // updateWorkflowGraph() // If workflow
           });
@@ -1316,7 +1319,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
         return self.isCoordinator();
       });
       self.rerunEnabled = ko.pureComputed(function() {
-        return self.hasRerun() && self.selectedJobs().length > 0 && $.grep(self.selectedJobs(), function(job) {
+        return self.hasRerun() && self.selectedJobs().length == 1 && $.grep(self.selectedJobs(), function(job) {
           return job.rerunEnabled();
         }).length == self.selectedJobs().length;
       });
@@ -1481,16 +1484,34 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       };
 
       self.control = function (action) {
-        self._control(
-          $.map(self.selectedJobs(), function(job) {
-            return job.id();
-          }),
-          action,
-          function(data) {
-            $(document).trigger("info", data.message);
-            self.updateJobs();
-          }
-        )
+        if (action == 'rerun') {
+          $.get('/oozie/rerun_oozie_coord/' + vm.job().id() + '/?format=json', function(response) {
+            $('#rerun-modal').modal('show');
+            vm.job().rerunModalContent(response);
+
+            var frag = document.createDocumentFragment();
+            vm.job().coordinatorActions().selectedJobs().forEach(function (item) {
+              var option = $('<option>', {
+                value: item.properties.number(),
+                selected: true
+              });
+              option.appendTo($(frag));
+            });
+            $('#id_actions').find('option').remove();
+            $(frag).appendTo('#id_actions');
+          });
+        } else {
+          self._control(
+            $.map(self.selectedJobs(), function(job) {
+              return job.id();
+            }),
+            action,
+            function(data) {
+              $(document).trigger("info", data.message);
+              self.updateJobs();
+            }
+          )
+        }
       }
 
       self._control = function (app_ids, action, callback) {
@@ -1696,12 +1717,14 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 
       huePubSub.publish('cluster.config.get.config');
 
+      % if not is_mini:
       huePubSub.subscribe('submit.rerun.popup.return', function (data) {
         $.jHueNotify.info('${_('Rerun submitted.')}');
         $('#rerun-modal').modal('hide');
         viewModel.job().apiStatus('RUNNING');
         viewModel.job().updateJob();
       }, 'jobbrowser');
+      % endif
     });
   })();
 </script>

+ 5 - 0
apps/oozie/src/oozie/forms.py

@@ -479,14 +479,19 @@ class RerunCoordForm(forms.Form):
   refresh = forms.BooleanField(initial=True, required=False, help_text=_t("Used to indicate if user wants to refresh an action's input and output events"))
   nocleanup = forms.BooleanField(initial=True, required=False, help_text=_t('Used to indicate if user wants to cleanup output events for given rerun actions'))
   actions = forms.MultipleChoiceField(required=True)
+  return_json = forms.BooleanField(required=False, widget=forms.HiddenInput)
 
   def __init__(self, *args, **kwargs):
     oozie_coordinator = kwargs.pop('oozie_coordinator')
+    return_json = kwargs.pop('return_json', None)
 
     super(RerunCoordForm, self).__init__(*args, **kwargs)
 
     self.fields['actions'].choices = [(action.actionNumber, action.title) for action in reversed(oozie_coordinator.get_working_actions())]
 
+    if return_json is not None:
+      self.fields['return_json'].initial = return_json
+
 
 class RerunBundleForm(forms.Form):
   refresh = forms.BooleanField(initial=True, required=False, help_text=_t("Used to indicate if user wants to refresh an action's input and output events"))

+ 28 - 9
apps/oozie/src/oozie/templates/dashboard/rerun_coord_popup.mako

@@ -22,7 +22,7 @@
 <%namespace name="utils" file="../utils.inc.mako" />
 
 
-<form action="${ action }" method="POST">
+<form action="${ action }" method="POST" id="submit-rerun-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>
@@ -42,6 +42,7 @@
               ${ utils.render_field_no_popover(rerun_form['nocleanup'], show_label=True) }
             </div>
           </div>
+
           <div id="param-container">
             ${ params_form.management_form | n,unicode }
 
@@ -71,6 +72,10 @@
             % endif
           </div>
         </div>
+
+        % for hidden in rerun_form.hidden_fields():
+          ${ hidden | n,unicode }
+        % endfor
       </div>
     </fieldset>
   </div>
@@ -82,15 +87,29 @@
 </form>
 
 <script charset="utf-8">
-  var frag = document.createDocumentFragment();
-  viewModel.selectedActions().forEach(function (item) {
-    var option = $('<option>', {
-      value: item,
-      selected: true
+  % if return_json:
+    $('#submit-rerun-form').submit(function (e) {
+      $.ajax({
+        type: "POST",
+        url: '${ action }',
+        data: $('#submit-rerun-form').serialize(),
+        success: function (data) {
+          huePubSub.publish('submit.rerun.popup.return', data);
+        }
+      });
+      e.preventDefault();
     });
+  % else:
+    var frag = document.createDocumentFragment();
+    viewModel.selectedActions().forEach(function (item) {
+      var option = $('<option>', {
+        value: item,
+        selected: true
+      });
 
-    option.appendTo($(frag));
-  });
+      option.appendTo($(frag));
+    });
 
-  $(frag).appendTo('#id_actions');
+    $(frag).appendTo('#id_actions');
+  % endif
 </script>

+ 0 - 0
apps/oozie/src/oozie/templates/dashboard/rerun_job_popup.mako → apps/oozie/src/oozie/templates/dashboard/rerun_workflow_popup.mako


+ 1 - 1
apps/oozie/src/oozie/urls.py

@@ -132,7 +132,7 @@ urlpatterns += patterns(
   url(r'^list_oozie_bundle/(?P<job_id>[-\w]+)$', 'list_oozie_bundle', name='list_oozie_bundle'),
 
   url(r'^rerun_oozie_job/(?P<job_id>[-\w]+)/(?P<app_path>.+?)?$', 'rerun_oozie_job', name='rerun_oozie_job'),
-  url(r'^rerun_oozie_coord/(?P<job_id>[-\w]+)/(?P<app_path>.+?)$', 'rerun_oozie_coordinator', name='rerun_oozie_coord'),
+  url(r'^rerun_oozie_coord/(?P<job_id>[-\w]+)/(?P<app_path>.+?)?$', 'rerun_oozie_coordinator', name='rerun_oozie_coord'),
   url(r'^rerun_oozie_bundle/(?P<job_id>[-\w]+)/(?P<app_path>.+?)$', 'rerun_oozie_bundle', name='rerun_oozie_bundle'),
   url(r'^sync_coord_workflow/(?P<job_id>[-\w]+)$', 'sync_coord_workflow', name='sync_coord_workflow'),
   url(r'^manage_oozie_jobs/(?P<job_id>[-\w]+)/(?P<action>(start|suspend|resume|kill|rerun|change|ignore))$', 'manage_oozie_jobs', name='manage_oozie_jobs'),

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

@@ -744,7 +744,8 @@ def rerun_oozie_job(request, job_id, app_path=None):
   ParametersFormSet = formset_factory(ParameterForm, extra=0)
   oozie_workflow = check_job_access_permission(request, job_id)
   check_job_edition_permission(oozie_workflow, request.user)
-  app_path = oozie_workflow.appPath
+  if app_path is None:
+    app_path = oozie_workflow.appPath
   return_json = request.GET.get('format') == 'json'
 
   if request.method == 'POST':
@@ -776,7 +777,7 @@ def rerun_oozie_job(request, job_id, app_path=None):
     initial_params = ParameterForm.get_initial_params(oozie_workflow.conf_dict)
     params_form = ParametersFormSet(initial=initial_params)
 
-  popup = render('dashboard/rerun_job_popup.mako', request, {
+  popup = render('dashboard/rerun_workflow_popup.mako', request, {
                    'rerun_form': rerun_form,
                    'params_form': params_form,
                    'action': reverse('oozie:rerun_oozie_job', kwargs={'job_id': job_id, 'app_path': app_path}),
@@ -799,10 +800,13 @@ def _rerun_workflow(request, oozie_id, run_args, mapping):
 
 
 @show_oozie_error
-def rerun_oozie_coordinator(request, job_id, app_path):
+def rerun_oozie_coordinator(request, job_id, app_path=None):
   oozie_coordinator = check_job_access_permission(request, job_id)
   check_job_edition_permission(oozie_coordinator, request.user)
   ParametersFormSet = formset_factory(ParameterForm, extra=0)
+  if app_path is None:
+    app_path = oozie_coordinator.coordJobPath
+  return_json = request.GET.get('format') == 'json'
 
   if request.method == 'POST':
     params_form = ParametersFormSet(request.POST)
@@ -823,13 +827,16 @@ def rerun_oozie_coordinator(request, job_id, app_path):
 
       _rerun_coordinator(request, job_id, args, params, properties)
 
-      request.info(_('Coordinator re-running.'))
-      return redirect(reverse('oozie:list_oozie_coordinator', kwargs={'job_id': job_id}))
+      if rerun_form.cleaned_data['return_json']:
+        return JsonResponse({'status': 0, 'job_id': job_id}, safe=False)
+      else:
+        request.info(_('Coordinator re-running.'))
+        return redirect(reverse('oozie:list_oozie_coordinator', kwargs={'job_id': job_id}))
     else:
       request.error(_('Invalid submission form: %s') % smart_unicode(rerun_form.errors))
       return list_oozie_coordinator(request, job_id)
   else:
-    rerun_form = RerunCoordForm(oozie_coordinator=oozie_coordinator)
+    rerun_form = RerunCoordForm(oozie_coordinator=oozie_coordinator, return_json=return_json)
     initial_params = ParameterForm.get_initial_params(oozie_coordinator.conf_dict)
     params_form = ParametersFormSet(initial=initial_params)
 
@@ -837,6 +844,7 @@ def rerun_oozie_coordinator(request, job_id, app_path):
                    'rerun_form': rerun_form,
                    'params_form': params_form,
                    'action': reverse('oozie:rerun_oozie_coord', kwargs={'job_id': job_id, 'app_path': app_path}),
+                   'return_json': return_json,
                  }, force_template=True).content
 
   return JsonResponse(popup, safe=False)