Browse Source

HUE-2777 [oozie] Move Coordinator action filter buttons to backend

krish 10 years ago
parent
commit
a3f4969491

+ 58 - 28
apps/oozie/src/oozie/templates/dashboard/list_oozie_coordinator.mako

@@ -183,9 +183,9 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
                   % endif
                 </div>
                 <span class="btn-group pull-right" style="margin-right: 20px">
-                  <a class="btn btn-status btn-success" data-value="success" data-bind="click: function () { setFilter('succeeded'); }">${ _('Succeeded') }</a>
-                  <a class="btn btn-status btn-warning" data-value="warning" data-bind="click: function () { setFilter('running'); }">${ _('Running') }</a>
-                  <a class="btn btn-status btn-danger disable-feedback" data-value="important" data-bind="click: function () { setFilter('failed'); }">${ _('Failed') }</a>
+                  <a class="btn btn-status btn-success" data-table="calendar" data-value="SUCCEEDED">${ _('Succeeded') }</a>
+                  <a class="btn btn-status btn-warning" data-table="calendar" data-value="RUNNING">${ _('Running') }</a>
+                  <a class="btn btn-status btn-danger disable-feedback" data-table="calendar" data-value="ERROR">${ _('Error') }</a>
                 </span>
               </div>
 
@@ -237,6 +237,11 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
 
 
             <div class="tab-pane" id="actions">
+              <span class="btn-group pull-right" style="margin-right: 20px;margin-bottom:20px">
+                <a class="btn btn-status btn-success" data-table="actions" data-value="SUCCEEDED">${ _('Succeeded') }</a>
+                <a class="btn btn-status btn-warning" data-table="actions" data-value="RUNNING">${ _('Running') }</a>
+                <a class="btn btn-status btn-danger disable-feedback" data-table="actions" data-value="ERROR">${ _('Error') }</a>
+              </span>
               <table class="table table-striped table-condensed" cellpadding="0" cellspacing="0">
                 <thead>
                 <tr>
@@ -531,27 +536,6 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
       }
     });
 
-    this.setFilter = function (filter) {
-      if (! Array.isArray(self.filter())) {
-        self.filter([]);
-      }
-
-      // checks to see if a button is toggled
-      if ($.inArray(filter, self.filter()) !== -1) {
-        // remove if already in array due to toggling of filter
-        self.filter.splice(self.filter.indexOf(filter), 1);
-        self.clearSelections(filter);
-        self.allSelected(false);
-      } else {
-        self.filter.push(filter)
-        self.select(filter);
-      }
-
-      if (self.selectedActions().length === self.actions().length) {
-        self.allSelected(true);
-      }
-    };
-
     this.filteredActions = ko.computed(function () {
       var filter = self.filter(),
         actions = [],
@@ -649,6 +633,17 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
       % endif
     });
 
+    $("a.btn-status").click(function () {
+      var val = $(this).data("value")
+      var btnCalendar = $("a.btn-status[data-table='calendar'][data-value='"+ val + "']");
+      var btnAction = $("a.btn-status[data-table='actions'][data-value='"+ val + "']");
+
+      refreshActionsPagination();
+      btnCalendar.toggleClass("active");
+      btnAction.toggleClass("active");
+      refreshView();
+    });
+
     $("a.btn-actions-pagination").on("click", function () {
       if (!$(this).parent().hasClass("disabled")) {
         var _additionalOffset = 0;
@@ -729,6 +724,30 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
       });
     });
 
+    function refreshActionsPagination() {
+      actionTableOffset = 1;
+    }
+
+    function getFilteredStatuses(type) {
+      var selectedStatuses = '';
+      var btnStatuses = [];
+      $.each($("a.btn-status.active[data-table='calendar']"), function () {
+        val = $(this).data('value');
+        if (val == 'SUCCEEDED') {
+          btnStatuses = btnStatuses.concat(['SUCCEEDED']);
+        } else if (val == 'RUNNING') {
+          btnStatuses = btnStatuses.concat(['RUNNING', 'READY', 'SUBMITTED', 'SUSPENDED', 'WAITING']);
+        } else if (val == 'ERROR') {
+          btnStatuses = btnStatuses.concat(['KILLED', 'FAILED', 'TIMEDOUT', 'IGNORED', 'SKIPPED']);
+        }
+      });
+
+      $.each(btnStatuses, function (iStatus, status) {
+        selectedStatuses += '&status=' + status;
+      });
+      return selectedStatuses;
+    }
+
     resizeLogs();
     refreshView();
     refreshLogs();
@@ -774,13 +793,24 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
     }
 
     function refreshView() {
-      $.getJSON("${ oozie_coordinator.get_absolute_url(oozie_bundle=oozie_bundle, format='json') }" + "&offset=" + actionTableOffset, function (data) {
+      $.getJSON("${ oozie_coordinator.get_absolute_url(oozie_bundle=oozie_bundle, format='json') }" + "&offset=" + actionTableOffset + getFilteredStatuses(), function (data) {
         viewModel.isLoading(false);
+
+        // Getting selected status from previous action list
+        updatedActionList = [];
         if (data != null && data.actions){
-          viewModel.actions(ko.utils.arrayMap(data.actions, function (action) {
-            return new Action(action);
-          }));
+          var prevActions = viewModel.actions();
+          $(data.actions).each(function (iAction, action) {
+            var actionItem = new Action(action);
+            $(prevActions).each(function (iPrev, prev) {
+              if (prev.id == actionItem.id) {
+                actionItem.selected(prev.selected());
+              }
+            });
+            updatedActionList.push(actionItem);
+          });
         }
+        viewModel.actions(updatedActionList);
 
         // Refresh actions pagination
         totalActions = data.total_actions;

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

@@ -148,7 +148,7 @@ class MockOozieApi:
     else:
       return OozieWorkflow(self, {'id': job_id, 'actions': []})
 
-  def get_coordinator(self, job_id, action_offset=1):
+  def get_coordinator(self, job_id, **kwargs):
     if job_id in MockOozieApi.COORDINATOR_DICT:
       return OozieCoordinator(self, MockOozieApi.COORDINATOR_DICT[job_id])
     else:

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

@@ -383,8 +383,12 @@ def list_oozie_workflow(request, job_id):
 
 @show_oozie_error
 def list_oozie_coordinator(request, job_id):
-  actions_offset = request.GET.get('offset', 1)
-  oozie_coordinator = check_job_access_permission(request, job_id, actions_offset)
+  kwargs = {'cnt': 50, 'filters': []}
+  kwargs['offset'] = request.GET.get('offset', 1)
+  if request.GET.getlist('status'):
+      kwargs['filters'].extend([('status', status) for status in request.GET.getlist('status')])
+
+  oozie_coordinator = check_job_access_permission(request, job_id, **kwargs)
 
   # Cross reference the submission history (if any)
   coordinator = get_history().get_coordinator_from_config(oozie_coordinator.conf_dict)
@@ -979,7 +983,7 @@ def massaged_oozie_jobs_for_json(oozie_jobs, user, just_sla=False):
   return { 'jobs': jobs }
 
 
-def check_job_access_permission(request, job_id, actions_offset=1):
+def check_job_access_permission(request, job_id, **kwargs):
   """
   Decorator ensuring that the user has access to the job submitted to Oozie.
 
@@ -999,7 +1003,7 @@ def check_job_access_permission(request, job_id, actions_offset=1):
 
     try:
       if job_id.endswith('C'):
-        oozie_job = get_job(job_id, actions_offset)
+        oozie_job = get_job(job_id, **kwargs)
       else:
         oozie_job = get_job(job_id)
     except RestException, ex:

+ 15 - 4
desktop/libs/liboozie/src/liboozie/oozie_api.py

@@ -34,7 +34,6 @@ DEFAULT_USER = DEFAULT_USER.get()
 API_VERSION = 'v1' # Overridden to v2 for SLA
 
 _XML_CONTENT_TYPE = 'application/xml;charset=UTF-8'
-ACTIONS_PER_PAGE = 50
 
 
 def get_oozie(user, api_version=API_VERSION):
@@ -143,11 +142,23 @@ class OozieApi(object):
     wf = Workflow(self, resp)
     return wf
 
-  def get_coordinator(self, jobid, actions_offset=1):
+  def get_coordinator(self, jobid, offset=None, cnt=None, filters=None):
     params = self._get_params()
-    params.update({'offset': actions_offset})
-    params.update({'len': ACTIONS_PER_PAGE})
+    if offset is not None:
+      params['offset'] = str(offset)
+    if cnt is not None:
+      params['len'] = str(cnt)
+    if filters is None:
+      filters = {}
     params.update({'order': 'desc'})
+
+    filter_list = []
+    for key, val in filters:
+      if key not in OozieApi.VALID_JOB_FILTERS:
+        raise ValueError('"%s" is not a valid filter for selecting jobs' % (key,))
+      filter_list.append('%s=%s' % (key, val))
+    params['filter'] = ';'.join(filter_list)
+
     resp = self._root.get('job/%s' % (jobid,), params)
     return Coordinator(self, resp)