aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [27/50] [abbrv] git commit: code cleanup.
Date Sat, 05 Apr 2014 00:05:13 GMT
code cleanup.


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

Branch: refs/heads/mansu/job_page
Commit: 96ab5016449a3616ac695252e99081a1041ae73d
Parents: d1d65e2
Author: Suman Karumuri <skarumuri@twitter.com>
Authored: Sun Mar 30 00:13:34 2014 -0700
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Sun Mar 30 00:17:28 2014 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/http/ui/js/controllers.js  | 64 ++++++++++----------
 1 file changed, 32 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/96ab5016/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 3cda549..506375c 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
@@ -341,35 +341,9 @@ auroraUIControllers.controller('JobController',
       $scope.taskSummary = summarizeActiveTaskConfigs(response.tasks);
       console.log($scope.taskSummary);
 
-      var tasks = _.chain(response.tasks)
-        .map(function (task) {
-          var isActive = isActiveTask(task);
-
-          // TODO: Clean this logic.
-
-          var sortedTaskEvents = _.sortBy(task.taskEvents, function (taskEvent) {
-            return taskEvent.timestamp;
-          });
-
-          var lastTransition = _.isEmpty(sortedTaskEvents) ? _.last(sortedTaskEvents).timestamp
: 0;
-
-          var runningTaskEvent = sortedTaskEvents.length === 0 ? undefined : getRunningTaskEvent(task);
-
-          return {
-            instanceId: task.assignedTask.instanceId,
-            status: _.invert(ScheduleStatus)[task.status],
-            host: task.assignedTask.slaveHost || '',
-            latestActivity: lastTransition,
-            duration: isActive || _.isUndefined(runningTaskEvent)
-              ? 0
-              : lastTransition - runningTaskEvent.timestamp,
-            isActive: isActive,
-            taskId: task.assignedTask.taskId,
-            taskEvents: toTaskEvents(sortedTaskEvents),
-            showDetails: false
-          };
-        })
-        .value();
+      var tasks = _.map(response.tasks, function (task) {
+        return summarizeTask(task);
+      });
 
       var activeTaskPredicate = function (task) {
         return task.isActive;
@@ -390,21 +364,47 @@ auroraUIControllers.controller('JobController',
         .value();
     }
 
+    function summarizeTask(task) {
+      var isActive = isActiveTask(task);
+      var sortedTaskEvents = _.sortBy(task.taskEvents, function (taskEvent) {
+        return taskEvent.timestamp;
+      });
+      var lastTransitionAt = _.isEmpty(sortedTaskEvents) ? 0 : _.last(sortedTaskEvents).timestamp;
+
+      return {
+        instanceId: task.assignedTask.instanceId,
+        status: _.invert(ScheduleStatus)[task.status],
+        host: task.assignedTask.slaveHost || '',
+        latestActivity: lastTransitionAt,
+        duration: getDuration(sortedTaskEvents, isActive),
+        isActive: isActive,
+        taskId: task.assignedTask.taskId,
+        taskEvents: summarizeTaskEvents(sortedTaskEvents),
+        showDetails: false
+      };
+    }
+
     function isActiveTask(task) {
       return _.contains(ACTIVE_STATES, task.status);
     }
 
-    function getRunningTaskEvent(task) {
-      return _.find(task.taskEvents, function (taskEvent) {
+    function getDuration(sortedTaskEvents, isActive) {
+      if (!isActive || _.isEmpty(sortedTaskEvents)) {
+        return 0;
+      }
+
+      var runningTaskEvent = _.find(sortedTaskEvents, function (taskEvent) {
         return taskEvent.status === ScheduleStatus['RUNNING'];
       });
+
+      return runningTaskEvent ? _.last(sortedTaskEvents).timestamp - runningTaskEvent.timestamp
: 0;
     }
 
     function fromNow(date, dropSuffix) {
       return moment(date).fromNow(dropSuffix);
     }
 
-    function toTaskEvents(taskEvents) {
+    function summarizeTaskEvents(taskEvents) {
       return _.map(taskEvents, function (taskEvent) {
         return {
           date: moment(taskEvent.timestamp).format('MM DD h:mm:ss z'),


Mime
View raw message