Prechádzať zdrojové kódy

HUE-8732 [jb] Rerun button for scheduler tasks is not working

Ivan Dzikovsky 6 rokov pred
rodič
commit
ec488cc

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

@@ -77,7 +77,7 @@ class Api(object):
 
   def apps(self, filters): return {'apps': [], 'total': 0}
 
-  def app(self, appid): return {} # Also contains progress (0-100) and status [RUNNING, FINISHED, PAUSED]
+  def app(self, appid): return {} # Also contains progress (0-100) and status [RUNNING, FINISHED, PAUSED, FAILED]
 
   def action(self, app_ids, operation): return {}
 

+ 36 - 8
apps/jobbrowser/src/jobbrowser/apis/schedule_api.py

@@ -86,6 +86,8 @@ class ScheduleApi(Api):
         'canWrite': has_job_edition_permission(coordinator, self.user),
     }
     common['properties'] = json.loads(response.content)
+    for action in common['properties']['actions']:
+      action['apiStatus'] = self._task_api_status(action['status'])
     common['properties']['tasks'] = common['properties']['actions']
     common['properties']['xml'] = ''
     common['properties']['properties'] = ''
@@ -123,15 +125,41 @@ class ScheduleApi(Api):
       coordinator = self.app(appid)
       return coordinator['properties']['tasks']
 
+  _API_STATUSES = {
+    'PREP':               'RUNNING',
+    'RUNNING':            'RUNNING',
+    'RUNNINGWITHERROR':   'RUNNING',
+    'PREPSUSPENDED':      'PAUSED',
+    'SUSPENDED':          'PAUSED',
+    'SUSPENDEDWITHERROR': 'PAUSED',
+    'PREPPAUSED':         'PAUSED',
+    'PAUSED':             'PAUSED',
+    'PAUSEDWITHERROR':    'PAUSED',
+    'SUCCEEDED':          'SUCCEEDED',
+    'DONEWITHERROR':      'FAILED',
+    'KILLED':             'FAILED',
+    'FAILED':             'FAILED',
+  }
+
   def _api_status(self, status):
-    if status in ['PREP', 'RUNNING', 'RUNNINGWITHERROR']:
-      return 'RUNNING'
-    elif status in ['PREPSUSPENDED', 'SUSPENDED', 'SUSPENDEDWITHERROR', 'PREPPAUSED', 'PAUSED', 'PAUSEDWITHERROR']:
-      return 'PAUSED'
-    elif status == 'SUCCEEDED':
-      return 'SUCCEEDED'
-    else:
-      return 'FAILED' # DONEWITHERROR, KILLED, FAILED
+    return self._API_STATUSES.get(status, 'FAILED')
+
+  _TASK_API_STATUSES = {
+    'WAITING':   'RUNNING',
+    'READY':     'RUNNING',
+    'SUBMITTED': 'RUNNING',
+    'RUNNING':   'RUNNING',
+    'SUSPENDED': 'PAUSED',
+    'SUCCEEDED': 'SUCCEEDED',
+    'TIMEDOUT':  'FAILED',
+    'KILLED':    'FAILED',
+    'FAILED':    'FAILED',
+    'IGNORED':   'FAILED',
+    'SKIPPED':   'FAILED',
+  }
+
+  def _task_api_status(self, status):
+    return self._TASK_API_STATUSES.get(status, 'FAILED')
 
 
 class MockGet():

+ 21 - 9
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -2348,7 +2348,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       self.apiStatus = ko.observableDefault(job.apiStatus);
       self.progress = ko.observableDefault(job.progress);
       self.isRunning = ko.computed(function() {
-        return self.apiStatus() == 'RUNNING' || self.apiStatus() == 'PAUSED' || job.isRunning;
+        return ['RUNNING', 'PAUSED'].indexOf(self.apiStatus()) != -1 || job.isRunning;
       });
 
       self.user = ko.observableDefault(job.user);
@@ -2371,15 +2371,13 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 
       self.coordinatorActions = ko.pureComputed(function() {
         if (self.mainType() == 'schedules' && self.properties['tasks']) {
-          var apps = [];
-          self.properties['tasks']().forEach(function (instance) {
-            var job = new Job(vm, ko.mapping.toJS(instance));
-            job.resumeEnabled = function() { return false };
+          var apps = self.properties['tasks']().map(function (instance) {
+            var job = new CoordinatorAction(vm, ko.mapping.toJS(instance), self);
             job.properties = instance;
-            apps.push(job);
+            return job;
           });
           var instances = new Jobs(vm);
-          instances.apps(apps)
+          instances.apps(apps);
           instances.isCoordinator(true);
           return instances;
         }
@@ -2860,6 +2858,20 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       };
     };
 
+    var CoordinatorAction = function (vm, job, coordinator) {
+      var self = this;
+      Job.apply(self, [vm, job]);
+      self.coordinator = coordinator;
+
+      self.canWrite = ko.computed(function () {
+        return self.coordinator.canWrite();
+      });
+
+      self.resumeEnabled = function () {
+        return false;
+      };
+    };
+
     var Jobs = function (vm) {
       var self = this;
 
@@ -3470,7 +3482,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
 
     $(document).ready(function () {
       var jobBrowserViewModel = new JobBrowserViewModel();
-      function openJob(id) {
+      var openJob = function(id) {
         if (jobBrowserViewModel.job() == null) {
           jobBrowserViewModel.job(new Job(jobBrowserViewModel, {}));
         }
@@ -3533,7 +3545,7 @@ ${ 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.')}');
+        $.jHueNotify.info('${_("Rerun submitted.")}');
         $('#rerun-modal${ SUFFIX }').modal('hide');
 
         jobBrowserViewModel.job().apiStatus('RUNNING');