Răsfoiți Sursa

HUE-1176 [jb] Add rerun action of workflows

Romain Rigaux 8 ani în urmă
părinte
comite
27d6ba6

+ 2 - 2
apps/jobbrowser/src/jobbrowser/apis/base_api.py

@@ -66,13 +66,13 @@ class Api(object):
 
 class MockDjangoRequest():
 
-  def __init__(self, user, get=None, post=None):
+  def __init__(self, user, get=None, post=None, method='POST'):
     self.user = user
     self.jt = None
     self.GET = get if get is not None else {'format': 'json'}
     self.POST = post if post is not None else {}
     self.REQUEST = {}
-    self.method = "POST"
+    self.method = method
 
 
 def _extract_query_params(filters):

+ 30 - 5
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -235,6 +235,11 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
   </div>
 </div>
 </div>
+
+<!-- ko if: $root.job() -->
+  <div id="rerun-modal" class="modal hide" data-bind="html: $root.job().rerunModalContent"></div>
+<!-- /ko -->
+
 </div>
 
 
@@ -260,6 +265,10 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
   <h3>
     <ul class="inline hue-breadcrumbs-bar" data-bind="foreach: breadcrumbs">
       <li>
+      <!-- ko if: $index() > 1 -->
+        <span class="divider">&gt;</span>
+      <!-- /ko -->
+
       <!-- ko if: $index() != 0 -->
         <!-- ko if: $index() != $parent.breadcrumbs().length - 1 -->
           <a href="javascript:void(0)" data-bind="click: function() { $parent.breadcrumbs.splice($index()); $root.job().id(id); $root.job().fetchJob(); }">
@@ -1033,6 +1042,8 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
         self.fetchProfile('tasks');
       });
 
+      self.rerunModalContent = ko.observable('');
+
       self.hasKill = ko.pureComputed(function() {
         return ['MAPREDUCE', 'SPARK', 'workflow', 'schedule', 'bundle'].indexOf(self.type()) != -1;
       });
@@ -1213,10 +1224,17 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       };
 
       self.control = function (action) {
-        vm.jobs._control([self.id()], action, function(data) {
-            $(document).trigger("info", data.message);
-            self.fetchStatus();
-        });
+        if (action == 'rerun') {
+          $.get('/oozie/rerun_oozie_job/' + self.id() + '/?format=json', function(response) {
+            $('#rerun-modal').modal('show');
+            self.rerunModalContent(response);
+          });
+        } else {
+          vm.jobs._control([self.id()], action, function(data) {
+              $(document).trigger("info", data.message);
+              self.fetchStatus();
+          });
+        }
       }
 
       self.updateWorkflowGraph = function() {
@@ -1295,7 +1313,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       });
 
       self.hasRerun = ko.pureComputed(function() {
-        return ['workflows'].indexOf(vm.interface()) != -1 || self.isCoordinator();
+        return self.isCoordinator();
       });
       self.rerunEnabled = ko.pureComputed(function() {
         return self.hasRerun() && self.selectedJobs().length > 0 && $.grep(self.selectedJobs(), function(job) {
@@ -1677,6 +1695,13 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       });
 
       huePubSub.publish('cluster.config.get.config');
+
+      huePubSub.subscribe('submit.rerun.popup.return', function (data) {
+        $.jHueNotify.info('${_('Rerun submitted.')}');
+        $('#rerun-modal').modal('hide');
+        viewModel.job().apiStatus('RUNNING');
+        viewModel.job().updateJob();
+      }, 'jobbrowser');
     });
   })();
 </script>

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

@@ -450,9 +450,11 @@ _node_type_TO_FORM_CLS = {
 
 class RerunForm(forms.Form):
   skip_nodes = forms.MultipleChoiceField(required=False)
+  return_json = forms.BooleanField(required=False, widget=forms.HiddenInput)
 
   def __init__(self, *args, **kwargs):
     oozie_workflow = kwargs.pop('oozie_workflow')
+    return_json = kwargs.pop('return_json', None)
 
     # Build list of skip nodes
     decisions = filter(lambda node: node.type == 'switch', oozie_workflow.get_control_flow_actions())
@@ -469,6 +471,9 @@ class RerunForm(forms.Form):
     self.fields['skip_nodes'].choices = skip_nodes
     self.fields['skip_nodes'].initial = initial_skip_nodes
 
+    if return_json is not None:
+      self.fields['return_json'].initial = return_json
+
 
 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"))

+ 25 - 8
apps/oozie/src/oozie/templates/dashboard/rerun_job_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>
@@ -45,6 +45,9 @@
               </div>
             </div>
           </div>
+          % for hidden in rerun_form.hidden_fields():
+            ${ hidden | n,unicode }
+          % endfor
       </div>
 
       <div id="param-container">
@@ -85,13 +88,27 @@
 </form>
 
 <script type="text/javascript">
-    $(document).ready(function(){
-        $("#id_skip_nodes").jHueSelector({
-            selectAllLabel: "${_('Select all')}",
-            searchPlaceholder: "${_('Search')}",
-            noChoicesFound: "${_('No successful actions found.')}",
-            width:350,
-            height:150
+  $(document).ready(function(){
+      $("#id_skip_nodes").jHueSelector({
+          selectAllLabel: "${_('Select all')}",
+          searchPlaceholder: "${_('Search')}",
+          noChoicesFound: "${_('No successful actions found.')}",
+          width:350,
+          height:150
+      });
+
+      % 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();
         });
+      % endif
     });
 </script>

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

@@ -131,7 +131,7 @@ urlpatterns += patterns(
   url(r'^list_oozie_workflow_action/(?P<action>[-\w@]+)/$', 'list_oozie_workflow_action', name='list_oozie_workflow_action'),
   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_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_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'),

+ 10 - 4
apps/oozie/src/oozie/views/dashboard.py

@@ -740,10 +740,12 @@ def sync_coord_workflow(request, job_id):
   return JsonResponse(popup, safe=False)
 
 @show_oozie_error
-def rerun_oozie_job(request, job_id, app_path):
+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
+  return_json = request.GET.get('format') == 'json'
 
   if request.method == 'POST':
     rerun_form = RerunForm(request.POST, oozie_workflow=oozie_workflow)
@@ -762,12 +764,15 @@ def rerun_oozie_job(request, job_id, app_path):
 
       _rerun_workflow(request, job_id, args, mapping)
 
-      request.info(_('Workflow re-running.'))
-      return redirect(reverse('oozie:list_oozie_workflow', 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(_('Workflow re-running.'))
+        return redirect(reverse('oozie:list_oozie_workflow', kwargs={'job_id': job_id}))
     else:
       request.error(_('Invalid submission form: %s %s' % (rerun_form.errors, params_form.errors)))
   else:
-    rerun_form = RerunForm(oozie_workflow=oozie_workflow)
+    rerun_form = RerunForm(oozie_workflow=oozie_workflow, return_json=return_json)
     initial_params = ParameterForm.get_initial_params(oozie_workflow.conf_dict)
     params_form = ParametersFormSet(initial=initial_params)
 
@@ -775,6 +780,7 @@ def rerun_oozie_job(request, job_id, app_path):
                    'rerun_form': rerun_form,
                    'params_form': params_form,
                    'action': reverse('oozie:rerun_oozie_job', kwargs={'job_id': job_id, 'app_path': app_path}),
+                   'return_json': return_json
                  }, force_template=True).content
 
   return JsonResponse(popup, safe=False)