aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmclaugh...@apache.org
Subject git commit: Asynchronous JS for Scheduler UI
Date Thu, 18 Sep 2014 21:30:44 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 860dc4e98 -> 99ad092df


Asynchronous JS for  Scheduler UI

Bugs closed: AURORA-700

Reviewed at https://reviews.apache.org/r/25721/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/99ad092d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/99ad092d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/99ad092d

Branch: refs/heads/master
Commit: 99ad092dfe6d1691df11b180ebaba960c8e5ce12
Parents: 860dc4e
Author: David McLaughlin <david@dmclaughlin.com>
Authored: Thu Sep 18 14:30:09 2014 -0700
Committer: David McLaughlin <dmclaughlin@twitter.com>
Committed: Thu Sep 18 14:30:09 2014 -0700

----------------------------------------------------------------------
 .../apache/aurora/scheduler/http/ui/job.html    |   9 +-
 .../aurora/scheduler/http/ui/js/controllers.js  | 273 ++++++++++---------
 .../aurora/scheduler/http/ui/js/services.js     | 252 ++++++++++-------
 3 files changed, 299 insertions(+), 235 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/99ad092d/src/main/resources/org/apache/aurora/scheduler/http/ui/job.html
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/ui/job.html b/src/main/resources/org/apache/aurora/scheduler/http/ui/job.html
index 14dce65..ca1a0f6 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/ui/job.html
+++ b/src/main/resources/org/apache/aurora/scheduler/http/ui/job.html
@@ -72,8 +72,15 @@
         </div>
       </div>
 
+      <div ng-if="!tasksReady">
+        <div class="row">
+          <div class="col-md-12">
+            Loading job information.
+          </div>
+        </div>
+      </div>
 
-      <tabset justified='true'>
+      <tabset ng-if="tasksReady" justified='true'>
         <tab heading='Active tasks ({{activeTasks.length}})' title='All Active tasks for
this job.'>
           <div class='task-tab'>
             <div class='group-summary'>

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/99ad092d/src/main/resources/org/apache/aurora/scheduler/http/ui/js/controllers.js
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/controllers.js b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/controllers.js
index a454b26..bcb094a 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/controllers.js
+++ b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/controllers.js
@@ -41,36 +41,38 @@
 
       $scope.error = '';
 
-      $scope.roleSummaryColumns = [
-        {label: 'Role', map: 'role', cellTemplateUrl: 'roleLink.html'},
-        {label: 'Jobs', map: 'jobCount'},
-        {label: 'Cron Jobs', map: 'cronJobCount'}
-      ];
-
-      $scope.roleSummaries = parseResponse(auroraClient.getRoleSummary());
+      auroraClient.getRoleSummary().then(function (roleSummaries) {
+        $scope.roleSummaries = parseResponse(roleSummaries);
 
-      function parseResponse(response) {
-        $scope.error = response.error ? 'Error requesting role summary: ' + response.error
: '';
+        $scope.roleSummaryColumns = [
+          {label: 'Role', map: 'role', cellTemplateUrl: 'roleLink.html'},
+          {label: 'Jobs', map: 'jobCount'},
+          {label: 'Cron Jobs', map: 'cronJobCount'}
+        ];
 
-        if ($scope.error) {
-          return [];
-        }
+        function parseResponse(response) {
+          $scope.error = response.error ? 'Error requesting role summary: ' + response.error
: '';
 
-        // TODO(Suman Karumuri): Replace sort with defaultSortColumn once it lands
-        // https://github.com/lorenzofox3/Smart-Table/pull/61
-        return response.summaries.sort(function (a, b) {
-          if (a.role.toLowerCase() > b.role.toLowerCase()) {
-            return 1;
-          }
-          if (a.role.toLowerCase() < b.role.toLowerCase()) {
-            return -1;
+          if ($scope.error) {
+            return [];
           }
-          return 0;
-        });
-      }
 
-      $scope.roleSummaryTableConfig = infoTableConfig;
-      $scope.roleSummaryTableConfig.columnSpan = $scope.roleSummaryColumns.length;
+          // TODO(Suman Karumuri): Replace sort with defaultSortColumn once it lands
+          // https://github.com/lorenzofox3/Smart-Table/pull/61
+          return response.summaries.sort(function (a, b) {
+            if (a.role.toLowerCase() > b.role.toLowerCase()) {
+              return 1;
+            }
+            if (a.role.toLowerCase() < b.role.toLowerCase()) {
+              return -1;
+            }
+            return 0;
+          });
+        }
+
+        $scope.roleSummaryTableConfig = infoTableConfig;
+        $scope.roleSummaryTableConfig.columnSpan = $scope.roleSummaryColumns.length;
+      });
     });
 
   auroraUIControllers.controller('JobSummaryController',
@@ -94,10 +96,19 @@
       $scope.jobsTableConfig = infoTableConfig;
       $scope.jobsTableConfig.columnSpan = $scope.jobsTableColumns.length;
 
-      $scope.jobs = getJobs();
+      function getJobType(job) {
+        if (job.taskConfig.isService) {
+          return 'service';
+        }
 
-      function getJobs() {
-        var summaries = auroraClient.getJobSummary($scope.role);
+        if (job.cronSchedule !== null) {
+          return 'cron';
+        }
+
+        return 'adhoc';
+      }
+
+      function getJobs(summaries) {
         $scope.error = summaries.error ? 'Error fetching job summaries: ' + summaries.error
: '';
 
         if ($scope.error) {
@@ -134,17 +145,10 @@
           .value();
       }
 
-      function getJobType(job) {
-        if (job.taskConfig.isService) {
-          return 'service';
-        }
-
-        if (job.cronSchedule !== null) {
-          return 'cron';
-        }
+      auroraClient.getJobSummary($scope.role).then(function (summaries) {
+        $scope.jobs = getJobs(summaries);
+      });
 
-        return 'adhoc';
-      }
     });
 
   auroraUIControllers.controller('QuotaController',
@@ -160,10 +164,12 @@
 
       $scope.resourcesTableConfig = summaryTableConfig;
 
-      $scope.resources = getQuota();
 
-      function getQuota() {
-        var quotaResponse = auroraClient.getQuota($scope.role);
+      auroraClient.getQuota($scope.role).then(function (quotaResponse) {
+        $scope.resources = getQuota(quotaResponse);
+      });
+
+      function getQuota(quotaResponse) {
         $scope.error = quotaResponse.error ? 'Error fetching quota: ' + quotaResponse.error
: '';
 
         if ($scope.error) {
@@ -210,21 +216,21 @@
       $scope.error = '';
       $scope.cronJobSummary = [];
 
-      var cronJobSummary = cronJobSummaryService.getCronJobSummary($scope.role, $scope.environment,
-        $scope.job);
-
-      if (cronJobSummary.error) {
-        $scope.error = 'Error fetching cron job summary: ' + cronJobSummary.error;
-        return [];
-      }
+      cronJobSummaryService.getCronJobSummary($scope.role, $scope.environment,
+       $scope.job).then(function (cronJobSummary) {
+        if (cronJobSummary.error) {
+          $scope.error = 'Error fetching cron job summary: ' + cronJobSummary.error;
+          return [];
+        }
 
-      if (cronJobSummary.cronJobSummary) {
-        var nextCronRunTs = cronJobSummary.cronJobSummary.nextCronRun;
-        cronJobSummary.cronJobSummary.nextCronRun =
-          $filter('toLocalTime')(nextCronRunTs) + ', ' + $filter('toUtcTime')(nextCronRunTs);
+        if (cronJobSummary.cronJobSummary) {
+          var nextCronRunTs = cronJobSummary.cronJobSummary.nextCronRun;
+          cronJobSummary.cronJobSummary.nextCronRun =
+            $filter('toLocalTime')(nextCronRunTs) + ', ' + $filter('toUtcTime')(nextCronRunTs);
 
-        $scope.cronJobSummary = [cronJobSummary.cronJobSummary];
-      }
+          $scope.cronJobSummary = [cronJobSummary.cronJobSummary];
+        }
+      });
     }
   );
 
@@ -237,47 +243,49 @@
       $scope.job = $routeParams.job;
 
       var getUpdateProgress = function () {
-        $scope.update = auroraClient.getJobUpdateDetails(updateId).details;
-        $scope.inProgress = updateUtil.isInProgress($scope.update.update.summary.state.status);
-
-        var duration = $scope.update.update.summary.state.lastModifiedTimestampMs -
-          $scope.update.update.summary.state.createdTimestampMs;
-
-        $scope.duration = moment.duration(duration).humanize();
-
-        $scope.stats = updateUtil.getUpdateStats($scope.update);
-        $scope.configJson = JSON
-          .stringify($scope.update.update.instructions.desiredState.task, undefined, 2);
-
-        // pagination for instance events
-        var instanceEvents = $scope.instanceEvents = $scope.update.instanceEvents;
-        $scope.eventsPerPage = 10;
-        $scope.changeInstancePage = function () {
-          var start = ($scope.currentPage - 1) * $scope.eventsPerPage;
-          var end   = start + $scope.eventsPerPage;
-          $scope.instanceEvents = instanceEvents.slice(start, end);
-        };
-        $scope.totalEvents = instanceEvents.length;
-        $scope.currentPage = 1;
-        $scope.changeInstancePage();
-
-        // Instance summary display.
-        $scope.instanceSummary = updateUtil.fillInstanceSummary($scope.update, $scope.stats);
-
-        if ($scope.instanceSummary.length <= 20) {
-          $scope.instanceGridSize = 'big';
-        } else if ($scope.instanceSummary.length <= 1000) {
-          $scope.instanceGridSize = 'medium';
-        } else {
-          $scope.instanceGridSize = 'small';
-        }
+        auroraClient.getJobUpdateDetails(updateId).then(function (response) {
+          $scope.update = response.details;
+          $scope.inProgress = updateUtil.isInProgress($scope.update.update.summary.state.status);
+
+          var duration = $scope.update.update.summary.state.lastModifiedTimestampMs -
+            $scope.update.update.summary.state.createdTimestampMs;
+
+          $scope.duration = moment.duration(duration).humanize();
+
+          $scope.stats = updateUtil.getUpdateStats($scope.update);
+          $scope.configJson = JSON
+            .stringify($scope.update.update.instructions.desiredState.task, undefined, 2);
+
+          // pagination for instance events
+          var instanceEvents = $scope.instanceEvents = $scope.update.instanceEvents;
+          $scope.eventsPerPage = 10;
+          $scope.changeInstancePage = function () {
+            var start = ($scope.currentPage - 1) * $scope.eventsPerPage;
+            var end   = start + $scope.eventsPerPage;
+            $scope.instanceEvents = instanceEvents.slice(start, end);
+          };
+          $scope.totalEvents = instanceEvents.length;
+          $scope.currentPage = 1;
+          $scope.changeInstancePage();
+
+          // Instance summary display.
+          $scope.instanceSummary = updateUtil.fillInstanceSummary($scope.update, $scope.stats);
+
+          if ($scope.instanceSummary.length <= 20) {
+            $scope.instanceGridSize = 'big';
+          } else if ($scope.instanceSummary.length <= 1000) {
+            $scope.instanceGridSize = 'medium';
+          } else {
+            $scope.instanceGridSize = 'small';
+          }
 
-        // Poll for updates while this update is in progress.
-        if ($scope.inProgress) {
-          $timeout(function () {
-            getUpdateProgress();
-          }, AURORA_UPDATE_POLL_MS);
-        }
+          // Poll for updates while this update is in progress.
+          if ($scope.inProgress) {
+            $timeout(function () {
+              getUpdateProgress();
+            }, AURORA_UPDATE_POLL_MS);
+          }
+        });
       };
 
       getUpdateProgress();
@@ -285,7 +293,7 @@
   );
 
   auroraUIControllers.controller('JobController',
-    function ($scope, $routeParams, $timeout, auroraClient, taskUtil, updateUtil) {
+    function ($scope, $routeParams, $timeout, $q, auroraClient, taskUtil, updateUtil) {
       $scope.error = '';
 
       $scope.role = $routeParams.role;
@@ -346,13 +354,13 @@
       };
 
       $scope.jobDashboardUrl = '';
-
+      // These two task arrays need to be initialized due to a quirk in SmartTable's behavior.
+      $scope.activeTasks = [];
       $scope.completedTasks = [];
+      $scope.tasksReady = false;
 
-      $scope.activeTasks = getTasksForJob($scope.role, $scope.environment, $scope.job);
+      function buildGroupSummary(response) {
 
-      function buildGroupSummary($scope) {
-        var response = auroraClient.getConfigSummary($scope.role, $scope.environment, $scope.job);
         if (response.error) {
           $scope.error = 'Error fetching configuration summary: ' + response.error;
           return [];
@@ -388,38 +396,46 @@
         });
       }
 
-      function getUpdatesForJob($scope) {
-        var query = new JobUpdateQuery();
-        var jobKey = new JobKey();
-        jobKey.role = $scope.role;
-        jobKey.environment = $scope.environment;
-        jobKey.name = $scope.job;
-        query.jobKey = jobKey;
+      auroraClient.getTasksWithoutConfigs($scope.role, $scope.environment, $scope.job)
+        .then(getTasksForJob);
 
-        $scope.updates = auroraClient.getJobUpdateSummaries(query).summaries;
+      auroraClient.getConfigSummary($scope.role, $scope.environment, $scope.job)
+        .then(buildGroupSummary);
 
-        function getUpdateInProgress() {
-          if ($scope.updates.length > 0 &&
-             updateUtil.isInProgress($scope.updates[0].status)) {
+      var query = new JobUpdateQuery();
+      var jobKey = new JobKey();
+      jobKey.role = $scope.role;
+      jobKey.environment = $scope.environment;
+      jobKey.name = $scope.job;
+      query.jobKey = jobKey;
 
-            $scope.updateInProgress =
-              auroraClient.getJobUpdateDetails($scope.updates[0].updateId).details;
+      auroraClient.getJobUpdateSummaries(query).then(getUpdatesForJob);
+
+
+      function getUpdatesForJob(response) {
+        $scope.updates = response.summaries;
+
+        function getUpdateInProgress() {
+          auroraClient.getJobUpdateDetails($scope.updates[0].updateId).then(function (response)
{
+            $scope.updateInProgress = response.details;
 
             $scope.updateStats = updateUtil.getUpdateStats($scope.updateInProgress);
 
-            // Poll for updates as long as this update is in progress.
-            $timeout(function () {
-              getUpdateInProgress();
-            }, AURORA_UPDATE_POLL_MS);
-          }
+            if (updateUtil.isInProgress($scope.updateInProgress.state.status)) {
+              // Poll for updates as long as this update is in progress.
+              $timeout(function () {
+                getUpdateInProgress();
+              }, AURORA_UPDATE_POLL_MS);
+            }
+          });
         }
 
-        getUpdateInProgress();
+        if ($scope.updates.length > 0 && updateUtil.isInProgress($scope.updates[0].state.status))
{
+          getUpdateInProgress();
+        }
       }
 
-      function getTasksForJob(role, environment, job) {
-        var response = auroraClient.getTasksWithoutConfigs(role, environment, job);
-
+      function getTasksForJob(response) {
         if (response.error) {
           $scope.error = 'Error fetching tasks: ' + response.error;
           return [];
@@ -427,9 +443,6 @@
 
         $scope.jobDashboardUrl = getJobDashboardUrl(response.statsUrlPrefix);
 
-        buildGroupSummary($scope);
-        getUpdatesForJob($scope);
-
         var tasks = _.map(response.tasks, function (task) {
           return summarizeTask(task);
         });
@@ -438,6 +451,11 @@
           return task.isActive;
         };
 
+        $scope.activeTasks = _.chain(tasks)
+          .filter(activeTaskPredicate)
+          .sortBy('instanceId')
+          .value();
+
         $scope.completedTasks = _.chain(tasks)
           .reject(activeTaskPredicate)
           .sortBy(function (task) {
@@ -445,12 +463,7 @@
           })
           .value();
 
-        return _.chain(tasks)
-          .filter(activeTaskPredicate)
-          .sortBy(function (task) {
-            return task.instanceId;
-          })
-          .value();
+        $scope.tasksReady = true;
       }
 
       function summarizeTask(task) {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/99ad092d/src/main/resources/org/apache/aurora/scheduler/http/ui/js/services.js
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/services.js b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/services.js
index 7d9c646..8a719f8 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/services.js
+++ b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/services.js
@@ -30,31 +30,46 @@
 
   auroraUI.factory(
     'auroraClient',
-    ['$window',
-      function ($window) {
+    ['$window', '$q',
+      function ($window, $q) {
+        function async(fn) {
+          var deferred = $q.defer();
+          fn(deferred);
+          return deferred.promise;
+        }
+
         var auroraClient = {
           // Each of the functions below wrap an API call on the scheduler.
           getRoleSummary: function () {
-            var response = auroraClient.getSchedulerClient().getRoleSummary();
-            var result = auroraClient.processResponse(response);
-            result.summaries = response.result !== null ?
-              response.result.roleSummaryResult.summaries : [];
-            return result;
+            return async(function (deferred) {
+              auroraClient.getSchedulerClient().getRoleSummary(function (response) {
+                var result = auroraClient.processResponse(response);
+                result.summaries = response.result !== null ?
+                  response.result.roleSummaryResult.summaries : [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getJobSummary: function (role) {
-            var response = auroraClient.getSchedulerClient().getJobSummary(role);
-            var result = auroraClient.processResponse(response);
-            result.jobs = response.result !== null ?
-              response.result.jobSummaryResult.summaries : [];
-            return result;
+            return async(function (deferred) {
+              auroraClient.getSchedulerClient().getJobSummary(role, function (response) {
+                var result = auroraClient.processResponse(response);
+                result.jobs = response.result !== null ?
+                  response.result.jobSummaryResult.summaries : [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getQuota: function (role) {
-            var response = auroraClient.getSchedulerClient().getQuota(role);
-            var result = auroraClient.processResponse(response);
-            result.quota = response.result !== null ? response.result.getQuotaResult : [];
-            return result;
+            return async(function (deferred) {
+              auroraClient.getSchedulerClient().getQuota(role, function (response) {
+                var result = auroraClient.processResponse(response);
+                result.quota = response.result !== null ? response.result.getQuotaResult
: [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getTasks: function (role, environment, jobName) {
@@ -64,79 +79,105 @@
             taskQuery.owner = id;
             taskQuery.environment = environment;
             taskQuery.jobName = jobName;
-            var response = auroraClient.getSchedulerClient().getTasksStatus(taskQuery);
-            var result = auroraClient.processResponse(response);
-            result.tasks = response.result !== null ?
-              response.result.scheduleStatusResult.tasks : [];
-            return result;
+            return async(function (deferred) {
+              auroraClient.getSchedulerClient().getTasksStatus(taskQuery, function (response)
{
+                var result = auroraClient.processResponse(response);
+                result.tasks = response.result !== null ?
+                  response.result.scheduleStatusResult.tasks : [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getTasksWithoutConfigs: function (role, environment, jobName) {
             var query = makeJobTaskQuery(role, environment, jobName);
-            var response = auroraClient.getSchedulerClient().getTasksWithoutConfigs(query);
-            var result = auroraClient.processResponse(response);
-            result.tasks = response.result !== null ?
-              response.result.scheduleStatusResult.tasks : [];
-
-            // Attach current pending reasons to any pending tasks we might have
-            var pendingTasks = _.filter(result.tasks, function (t) {
-              return t.status === ScheduleStatus.PENDING;
-            });
 
-            if (pendingTasks.length > 0) {
-              var pendingResponse = auroraClient.getSchedulerClient().getPendingReason(query);
-              var reasons = pendingResponse.result !== null ?
-                pendingResponse.result.getPendingReasonResult.reasons : [];
-
-              reasons = _.indexBy(reasons, 'taskId');
-              pendingTasks.forEach(function (t) {
-                if (reasons.hasOwnProperty(t.assignedTask.taskId)) {
-                  // find the latest task event (that is pending)
-                  // and set the message to be this reason
-                  var latestPending = _.chain(t.taskEvents)
-                    .filter(function (e) {
-                      return e.status === ScheduleStatus.PENDING;
-                    })
-                    .sortBy(function (e) {
-                      return e.timestamp;
-                    })
-                    .last().value();
-
-                  latestPending.message = reasons[t.assignedTask.taskId].reason;
-                }
+            return async(function (deferred) {
+              var tasksPromise = async(function (d1) {
+                auroraClient.getSchedulerClient().getTasksWithoutConfigs(query, function
(rsp) {
+                  var result = auroraClient.processResponse(rsp);
+                  result.tasks = rsp.result !== null ?
+                    rsp.result.scheduleStatusResult.tasks : [];
+                  d1.resolve(result);
+                });
               });
-            }
 
-            return result;
+              var pendingPromise = async(function (d2) {
+                auroraClient.getSchedulerClient().getPendingReason(query, function (response)
{
+                  var reasons = response.result !== null ?
+                    response.result.getPendingReasonResult.reasons : [];
+                  d2.resolve(reasons);
+                });
+              });
+
+              $q.all([tasksPromise, pendingPromise]).then(function (responses) {
+                var result = responses[0], reasons = responses[1];
+                // Attach current pending reasons to any pending tasks we might have
+                var pendingTasks = _.filter(result.tasks, function (t) {
+                  return t.status === ScheduleStatus.PENDING;
+                });
+
+                if (pendingTasks.length > 0) {
+                  reasons = _.indexBy(reasons, 'taskId');
+                  pendingTasks.forEach(function (t) {
+                    if (reasons.hasOwnProperty(t.assignedTask.taskId)) {
+                      // find the latest task event (that is pending)
+                      // and set the message to be this reason
+                      var latestPending = _.chain(t.taskEvents)
+                        .filter(function (e) {
+                          return e.status === ScheduleStatus.PENDING;
+                        })
+                        .sortBy(function (e) {
+                          return e.timestamp;
+                        })
+                        .last().value();
+
+                      latestPending.message = reasons[t.assignedTask.taskId].reason;
+                    }
+                  });
+                }
+
+                deferred.resolve(result);
+              });
+            });
           },
 
           getConfigSummary: function (role, environment, jobName) {
-            var key = new JobKey();
-            key.role = role;
-            key.environment = environment;
-            key.name = jobName;
-            var response = auroraClient.getSchedulerClient().getConfigSummary(key);
-            var result = auroraClient.processResponse(response);
-            result.groups = response.result !== null ?
-              response.result.configSummaryResult.summary.groups : [];
-            return result;
+            return async(function (deferred) {
+              var key = new JobKey();
+              key.role = role;
+              key.environment = environment;
+              key.name = jobName;
+              auroraClient.getSchedulerClient().getConfigSummary(key, function (response)
{
+                var result = auroraClient.processResponse(response);
+                result.groups = response.result !== null ?
+                  response.result.configSummaryResult.summary.groups : [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getJobUpdateSummaries: function (query) {
-            query = query || new JobUpdateQuery();
-            var response = auroraClient.getSchedulerClient().getJobUpdateSummaries(query);
-            var result = auroraClient.processResponse(response);
-            result.summaries = response.result !== null ?
-              response.result.getJobUpdateSummariesResult.updateSummaries : [];
-            return result;
+            return async(function (deferred) {
+              query = query || new JobUpdateQuery();
+              auroraClient.getSchedulerClient().getJobUpdateSummaries(query, function (response)
{
+                var result = auroraClient.processResponse(response);
+                result.summaries = response.result !== null ?
+                  response.result.getJobUpdateSummariesResult.updateSummaries : [];
+                deferred.resolve(result);
+              });
+            });
           },
 
           getJobUpdateDetails: function (id) {
-            var response = auroraClient.getSchedulerClient().getJobUpdateDetails(id);
-            var result = auroraClient.processResponse(response);
-            result.details = response.result !== null ?
-              response.result.getJobUpdateDetailsResult.details : {};
-            return result;
+            return async(function (deferred) {
+              auroraClient.getSchedulerClient().getJobUpdateDetails(id, function (response)
{
+                var result = auroraClient.processResponse(response);
+                result.details = response.result !== null ?
+                  response.result.getJobUpdateDetailsResult.details : {};
+                deferred.resolve(result);
+              });
+            });
           },
 
           // Utility functions
@@ -180,6 +221,7 @@
             $window.document.title = auroraClient.getPageTitle(serverInfo);
           }
         };
+
         return auroraClient;
       }
     ]);
@@ -496,40 +538,42 @@
 
   auroraUI.factory(
     'cronJobSummaryService',
-    [ 'auroraClient',
-      function (auroraClient) {
+    [ '$q', 'auroraClient',
+      function ($q, auroraClient) {
         var cronJobSmrySvc = {
           getCronJobSummary: function (role, env, jobName) {
-            var summaries = auroraClient.getJobSummary(role);
-
-            if (summaries.error) {
-              return {error: 'Failed to fetch cron schedule from scheduler.'};
-            }
-
-            var cronJobSummary = _.chain(summaries.jobs)
-              .filter(function (summary) {
-                // fetch the cron job with a matching name and env.
-                var job = summary.job;
-                return job.cronSchedule !== null &&
-                  job.key.environment === env &&
-                  job.taskConfig.jobName === jobName;
-              })
-              .map(function (summary) {
-                var collisionPolicy =
-                  cronJobSmrySvc.getCronCollisionPolicy(summary.job.cronCollisionPolicy);
-                // summarize the cron job.
-                return {
-                  tasks: summary.job.instanceCount,
-                  schedule: summary.job.cronSchedule,
-                  nextCronRun: summary.nextCronRunMs,
-                  collisionPolicy: collisionPolicy,
-                  metadata: cronJobSmrySvc.getMetadata(summary.job.taskConfig.metadata)
-                };
-              })
-              .last() // there will always be 1 job in this list.
-              .value();
+            var deferred = $q.defer();
+            auroraClient.getJobSummary(role).then(function (summaries) {
+              if (summaries.error) {
+                deferred.resolve({error: 'Failed to fetch cron schedule from scheduler.'});
+              }
 
-            return {error: '', cronJobSummary: cronJobSummary};
+              var cronJobSummary = _.chain(summaries.jobs)
+                .filter(function (summary) {
+                  // fetch the cron job with a matching name and env.
+                  var job = summary.job;
+                  return job.cronSchedule !== null &&
+                    job.key.environment === env &&
+                    job.taskConfig.jobName === jobName;
+                })
+                .map(function (summary) {
+                  var collisionPolicy =
+                    cronJobSmrySvc.getCronCollisionPolicy(summary.job.cronCollisionPolicy);
+                  // summarize the cron job.
+                  return {
+                    tasks: summary.job.instanceCount,
+                    schedule: summary.job.cronSchedule,
+                    nextCronRun: summary.nextCronRunMs,
+                    collisionPolicy: collisionPolicy,
+                    metadata: cronJobSmrySvc.getMetadata(summary.job.taskConfig.metadata)
+                  };
+                })
+                .last() // there will always be 1 job in this list.
+                .value();
+
+              deferred.resolve({error: '', cronJobSummary: cronJobSummary});
+            });
+            return deferred.promise;
           },
 
           getMetadata: function (attributes) {


Mime
View raw message