Browse Source

HUE-1834 [oozie] Filter dasboard jobs in the backend

krish 10 years ago
parent
commit
9198879633

+ 1 - 29
apps/oozie/src/oozie/static/oozie/js/dashboard-utils.js

@@ -48,34 +48,6 @@ function emptyStringIfNull(obj) {
 var PersistedButtonsFilters = function (oSettings, aData, iDataIndex) {
   var urlHashes = "";
 
-  var statusBtn = $("a.btn-status.active");
-  var statusFilter = true;
-  if (statusBtn.length > 0) {
-    var statuses = [];
-    $.each(statusBtn, function () {
-      statuses.push($(this).attr("data-value"));
-    });
-    var _statusColumn = aData[2];
-    if (typeof $(_statusColumn).attr("data-type") == "undefined") {
-      _statusColumn = aData[1];
-    }
-    statusFilter = _statusColumn.match(RegExp(statuses.join('|'), "i")) != null;
-  }
-
-  var dateBtn = $("a.btn-date.active");
-  var dateFilter = true;
-  if (dateBtn.length > 0) {
-    var minAge = new Date() - parseInt(dateBtn.attr("data-value")) * 1000 * 60 * 60 * 24;
-    var _dateColumn = aData[1];
-    if (typeof $(_dateColumn).attr("data-type") == "undefined" || $(_dateColumn).attr("data-type") == "status") {
-      _dateColumn = aData[0];
-    }
-    if (typeof _dateColumn == "string") {
-      _dateColumn = $(_dateColumn).attr("data-sort-value");
-    }
-    dateFilter = _dateColumn * 1000 >= minAge;
-  }
-
   var submittedBtn = $("a.btn-submitted.active");
   var submittedByFilter = true;
   if (submittedBtn.length > 0) {
@@ -94,5 +66,5 @@ var PersistedButtonsFilters = function (oSettings, aData, iDataIndex) {
     }
   }
 
-  return statusFilter && dateFilter && submittedByFilter;
+  return submittedByFilter;
 }

+ 40 - 5
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflows.mako

@@ -288,7 +288,8 @@ ${ layout.menubar(section='workflows', dashboard=True) }
 
     $("a.btn-status").click(function () {
       $(this).toggleClass("active");
-      drawTable();
+      refreshRunning();
+      refreshCompleted();
     });
 
     $("a.btn-submitted").click(function () {
@@ -300,7 +301,8 @@ ${ layout.menubar(section='workflows', dashboard=True) }
     $("a.btn-date").click(function () {
       $("a.btn-date").not(this).removeClass("active");
       $(this).toggleClass("active");
-      drawTable();
+      refreshRunning();
+      refreshCompleted();
     });
 
     var hash = window.location.hash.replace(/(<([^>]+)>)/ig, "");
@@ -319,6 +321,38 @@ ${ layout.menubar(section='workflows', dashboard=True) }
       window.location.hash = hash;
     }
 
+    function getStatuses(type) {
+      var selectedStatuses = (type == 'running') ? ['RUNNING', 'PREP', 'SUSPENDED'] : ['SUCCEEDED', 'KILLED', 'FAILED'];
+      var btnStatuses = [];
+
+      var statusBtns = $("a.btn-status.active");
+      $.each(statusBtns, function () {
+        val = $(this).data('value');
+        if (val == 'SUCCEEDED') {
+          btnStatuses = btnStatuses.concat(['SUCCEEDED']);
+        } else if (val == 'RUNNING') {
+          btnStatuses = btnStatuses.concat(['RUNNING', 'PREP', 'SUSPENDED']);
+        } else if (val == 'KILLED') {
+          btnStatuses = btnStatuses.concat(['KILLED', 'FAILED']);
+        }
+      });
+
+      if (btnStatuses.length > 0) {
+        selectedStatuses = $.makeArray($(selectedStatuses).filter(btnStatuses));
+      }
+
+      return selectedStatuses.length > 0 ? ('&status=' + selectedStatuses.join('&status=')) : '';
+    }
+
+    function getDaysFilter() {
+      var dateBtn = $("a.btn-date.active");
+      var daysFilter = ''
+      if (dateBtn.length > 0) {
+        daysFilter = '&startcreatedtime=-' + dateBtn.attr("data-value") + 'd';
+      }
+      return daysFilter;
+    }
+
     $.fn.dataTableExt.sErrMode = "throw";
 
     $.fn.dataTableExt.afnFiltering.push(PersistedButtonsFilters); // from dashboard-utils.js
@@ -352,7 +386,7 @@ ${ layout.menubar(section='workflows', dashboard=True) }
     var numRunning = 0;
 
     refreshRunning = function () {
-      $.getJSON(window.location.pathname + "?format=json&type=running", function (data) {
+      $.getJSON(window.location.pathname + "?format=json" + getStatuses('running') + getDaysFilter(), function (data) {
         if (data.jobs) {
           var nNodes = runningTable.fnGetNodes();
 
@@ -412,6 +446,7 @@ ${ layout.menubar(section='workflows', dashboard=True) }
         }
         numRunning = data.jobs.length;
 
+        runningTable.fnDraw();
         window.setTimeout(refreshRunning, 5000);
       });
     }
@@ -435,7 +470,7 @@ ${ layout.menubar(section='workflows', dashboard=True) }
     }
 
     function refreshCompleted() {
-      $.getJSON(window.location.pathname + "?format=json&type=completed", function (data) {
+      $.getJSON(window.location.pathname + "?format=json" + getStatuses('completed') + getDaysFilter(), function (data) {
         completedTable.fnClearTable();
         $(data.jobs).each(function (iWf, item) {
           var wf = new Workflow(item);
@@ -459,7 +494,7 @@ ${ layout.menubar(section='workflows', dashboard=True) }
     }
 
     function refreshProgress() {
-      $.getJSON(window.location.pathname + "?format=json&type=progress", function (data) {
+      $.getJSON(window.location.pathname + "?format=json&type=progress" + getStatuses('running') + getDaysFilter(), function (data) {
         var nNodes = runningTable.fnGetNodes();
         $(data.jobs).each(function (iWf, item) {
             var wf = new Workflow(item);

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

@@ -168,12 +168,15 @@ def list_oozie_workflows(request):
 
   if request.GET.get('format') == 'json':
     just_sla = request.GET.get('justsla') == 'true'
-    if request.GET.get('type') in ('running', 'progress'):
-      kwargs['filters'].extend([('status', status) for status in OozieWorkflow.RUNNING_STATUSES])
-    elif request.GET.get('type') == 'completed':
-      kwargs['filters'].extend([('status', status) for status in OozieWorkflow.FINISHED_STATUSES])
 
-    json_jobs = oozie_api.get_workflows(**kwargs).jobs
+    if request.GET.get('startcreatedtime'):
+      kwargs['filters'].extend([('startcreatedtime', request.GET.get('startcreatedtime'))])
+
+    json_jobs = []
+    if request.GET.getlist('status'):
+      kwargs['filters'].extend([('status', status) for status in request.GET.getlist('status')])
+      json_jobs = oozie_api.get_workflows(**kwargs).jobs
+
     if request.GET.get('type') == 'progress':
       json_jobs = [oozie_api.get_job(job.id) for job in json_jobs]
 

+ 1 - 1
desktop/libs/liboozie/src/liboozie/oozie_api.py

@@ -88,7 +88,7 @@ class OozieApi(object):
 
     return defaults
 
-  VALID_JOB_FILTERS = ('name', 'user', 'group', 'status')
+  VALID_JOB_FILTERS = ('name', 'user', 'group', 'status', 'startcreatedtime')
 
   def get_jobs(self, jobtype, offset=None, cnt=None, filters=None):
     """