aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Removed cron jobs table from role and env page. Added cron job summary to job page.
Date Thu, 15 May 2014 21:12:56 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master e50ba7df1 -> 301617852


Removed cron jobs table from role and env page. Added cron job summary to job page.

Updated getTasksQuery to not throw an exception when requesting a cron job with no tasks.

Testing Done:
Tested on local laptop.
./gradlew clean build.
./pants src/test/python:all -vxs

Bugs closed: AURORA-384

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


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

Branch: refs/heads/master
Commit: 301617852e0fffbad5bdd2b9c3a3a00314779cd0
Parents: e50ba7d
Author: Suman Karumuri <mansu@apache.org>
Authored: Thu May 15 14:11:58 2014 -0700
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Thu May 15 14:11:58 2014 -0700

----------------------------------------------------------------------
 .../thrift/SchedulerThriftInterface.java        |  19 +--
 .../apache/aurora/scheduler/http/ui/job.html    |  22 ++++
 .../aurora/scheduler/http/ui/js/controllers.js  | 122 ++++++-------------
 .../aurora/scheduler/http/ui/js/filters.js      |  16 ++-
 .../aurora/scheduler/http/ui/js/services.js     |  49 ++++++++
 .../apache/aurora/scheduler/http/ui/role.html   |  11 +-
 6 files changed, 125 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
index f101143..4386a86 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -337,18 +337,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     Set<IScheduledTask> tasks =
         Storage.Util.weaklyConsistentFetchTasks(storage, Query.arbitrary(query));
 
-    Response response = new Response();
-
-    if (tasks.isEmpty()) {
-      response.setResponseCode(INVALID_REQUEST)
-          .setMessage("No tasks found for query: " + query);
-    } else {
-      response.setResponseCode(OK)
-          .setResult(Result.scheduleStatusResult(
-              new ScheduleStatusResult().setTasks(IScheduledTask.toBuildersList(tasks))));
-    }
-
-    return response;
+    return new Response().setResponseCode(OK)
+        .setResult(Result.scheduleStatusResult(
+            new ScheduleStatusResult().setTasks(IScheduledTask.toBuildersList(tasks))));
   }
 
   @Override
@@ -403,8 +394,8 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
 
   private Query.Builder maybeRoleScoped(Optional<String> ownerRole) {
     return ownerRole.isPresent()
-          ? Query.roleScoped(ownerRole.get())
-          : Query.unscoped();
+        ? Query.roleScoped(ownerRole.get())
+        : Query.unscoped();
   }
 
   private Map<IJobKey, IJobConfiguration> getJobs(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/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 cd78c20..284c2bc 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
@@ -22,6 +22,28 @@
         </div>
       </div>
 
+      <div ng-controller="CronJobSummaryController">
+        <div ng-show='error'>
+          <error/>
+        </div>
+
+        <div ng-hide='error'>
+          <div class='container-fluid'>
+            <div ng-if='cronJobSummary'>
+              <h3>Cron Job Summary</h3>
+
+              <div>
+                <smart-table config='cronJobSummaryTableConfig'
+                             columns='cronJobSummaryTableColumns'
+                             rows='cronJobSummary'
+                             class='table table-striped table-hover table-bordered table-condensed'>
+                </smart-table>
+              </div>
+            </div>
+          </div>
+        </div>
+      </div>
+
       <div class='container-fluid'>
         <button class="btn summaryButton" ng-click='toggleSummaryVisibility()'>
           {{summaryButtonText}}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/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 4a83e1d..c13a88f 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
@@ -88,27 +88,8 @@ auroraUIControllers.controller('JobSummaryController',
       {label: 'Failed Tasks', map: 'failedTasks'}
     ];
 
-    $scope.cronJobsTableColumns = [
-      {label: 'Environment', map: 'environment', cellTemplateUrl: '/roleEnvLink.html'},
-      {label: 'Job Name', map: 'jobName'},
-      {label: 'Tasks', map: 'tasks'},
-      {label: 'Schedule', map: 'schedule'},
-      {label: 'Next Run',
-        map: 'nextCronRun',
-        formatFunction: function (value, format) {
-          return printDate(value);
-        }
-      },
-      {label: 'Collision Policy', map: 'collisionPolicy'},
-      {label: 'Metadata', map: 'metadata'}
-    ];
-
     $scope.jobsTableConfig = infoTableConfig;
 
-    $scope.cronJobsTableConfig = infoTableConfig;
-
-    $scope.cronJobs = [];
-
     $scope.jobs = getJobs();
 
     function getJobs() {
@@ -131,27 +112,7 @@ auroraUIControllers.controller('JobSummaryController',
         return summary.jobName;
       };
 
-      $scope.cronJobs = _.chain(jobSummaries)
-        .filter(function (summary) {
-          return isCronJob(summary.job);
-        })
-        .map(function (summary) {
-          return {
-            role: $scope.role, // required for roleEnvLink directive
-            environment: summary.job.key.environment,
-            jobName: summary.job.taskConfig.jobName,
-            tasks: summary.job.instanceCount,
-            schedule: summary.job.cronSchedule,
-            nextCronRun: summary.nextCronRunMs,
-            collisionPolicy: getCronCollisionPolicy(summary.job.cronCollisionPolicy),
-            metadata: getMetadata(summary.job.taskConfig.metadata)
-          };
-        })
-        .sortBy(byJobName)
-        .value();
-
       return _.chain(jobSummaries)
-        .reject(isCronJobWithNoTasks)
         .map(function (summary) {
           return {
             role: $scope.role, // required for roleEnvLink directive
@@ -174,60 +135,12 @@ auroraUIControllers.controller('JobSummaryController',
         return 'service';
       }
 
-      if (isCronJob(job)) {
+      if (job.cronSchedule !== null) {
         return 'cron';
       }
 
       return 'adhoc';
     }
-
-    function isCronJob(job) {
-      return job.cronSchedule !== null;
-    }
-
-    function isCronJobWithNoTasks(summary) {
-      var stats = summary.stats;
-      var taskCount = stats.pendingTaskCount
-        + stats.activeTaskCount
-        + stats.finishedTaskCount
-        + stats.failedTaskCount;
-      return isCronJob(summary.job) && taskCount === 0;
-    }
-
-    function getMetadata(attributes) {
-      return _.map(attributes,function (attribute) {
-        return attribute.key + ': ' + attribute.value;
-      }).join(', ');
-    }
-
-    function getCronCollisionPolicy(cronCollisionPolicy) {
-      return _.keys(CronCollisionPolicy)[cronCollisionPolicy ? cronCollisionPolicy : 0];
-    }
-
-    // TODO(Suman Karumuri): Replace printDate with a more user friendly directive.
-    function printDate(timestamp) {
-      function pad(number) {
-        number = '' + number;
-        if (number.length < 2) {
-          return '0' + number;
-        }
-        return number;
-      }
-
-      var d = new Date(timestamp);
-      return pad(d.getUTCMonth() + 1) + '/'
-        + pad(d.getUTCDate()) + ' '
-        + pad(d.getUTCHours()) + ':'
-        + pad(d.getUTCMinutes()) + ':'
-        + pad(d.getUTCSeconds())
-        + ' UTC ('
-        + pad(d.getMonth() + 1) + '/'
-        + pad(d.getDate()) + ' '
-        + pad(d.getHours()) + ':'
-        + pad(d.getMinutes()) + ':'
-        + pad(d.getSeconds())
-        + ' local)';
-    }
   });
 
 auroraUIControllers.controller('QuotaController',
@@ -278,6 +191,39 @@ auroraUIControllers.controller('QuotaController',
   }
 );
 
+auroraUIControllers.controller('CronJobSummaryController',
+  function ($scope, $filter, cronJobSummaryService) {
+    $scope.cronJobSummaryTableConfig = summaryTableConfig;
+
+    $scope.cronJobSummaryTableColumns = [
+      {label: 'Number of tasks', map: 'tasks', isSortable: false},
+      {label: 'Cron Schedule', map: 'schedule', isSortable: false},
+      {label: 'Next Cron Run', map: 'nextCronRun', isSortable: false},
+      {label: 'Collision Policy', map: 'collisionPolicy', isSortable: false},
+      {label: 'Metadata', map: 'metadata', isSortable: false}
+    ];
+
+    $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 [];
+    }
+
+    if (cronJobSummary.cronJobSummary) {
+      var nextCronRunTs = cronJobSummary.cronJobSummary.nextCronRun;
+      cronJobSummary.cronJobSummary.nextCronRun =
+        $filter('toLocalTime')(nextCronRunTs) + ', ' + $filter('toUtcTime')(nextCronRunTs);
+
+      $scope.cronJobSummary = [cronJobSummary.cronJobSummary];
+    }
+  }
+);
+
 auroraUIControllers.controller('JobController',
   function ($scope, $routeParams, auroraClient, taskUtil) {
     $scope.error = '';

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/src/main/resources/org/apache/aurora/scheduler/http/ui/js/filters.js
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/filters.js b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/filters.js
index 2e8b73b..a2aea4d 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/ui/js/filters.js
+++ b/src/main/resources/org/apache/aurora/scheduler/http/ui/js/filters.js
@@ -61,11 +61,23 @@ auroraUI.filter('scaleMb', function () {
 auroraUI.filter('toCores', function () {
   return  function (count) {
     return count + ' cores';
-  }
+  };
 });
 
 auroraUI.filter('toElapsedTime', function () {
   return function (timestamp) {
     return moment.duration(moment().valueOf() - timestamp).humanize();
-  }
+  };
 });
+
+auroraUI.filter('toUtcTime', function () {
+  return function (timestamp, timezone) {
+    return moment(timestamp).utc().format('MM/DD h:mm:ss') + ' UTC';
+  };
+});
+
+auroraUI.filter('toLocalTime', function () {
+  return function (timestamp, timezone) {
+    return moment(timestamp).format('MM/DD h:mm:ss') + ' LOCAL';
+  };
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/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 7722900..f984956 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
@@ -213,3 +213,52 @@ auroraUI.factory(
     };
     return taskUtil;
   });
+
+auroraUI.factory(
+  'cronJobSummaryService',
+  [ 'auroraClient',
+    function (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) {
+              // summarize the cron job.
+              return {
+                tasks: summary.job.instanceCount,
+                schedule: summary.job.cronSchedule,
+                nextCronRun: summary.nextCronRunMs,
+                collisionPolicy: cronJobSmrySvc.getCronCollisionPolicy(summary.job.cronCollisionPolicy),
+                metadata: cronJobSmrySvc.getMetadata(summary.job.taskConfig.metadata)
+              };
+            })
+            .last() // there will always be 1 job in this list.
+            .value();
+
+          return {error: '', cronJobSummary: cronJobSummary}
+        },
+
+        getMetadata: function (attributes) {
+          return _.map(attributes,function (attribute) {
+            return attribute.key + ': ' + attribute.value;
+          }).join(', ');
+        },
+
+        getCronCollisionPolicy: function (cronCollisionPolicy) {
+          return _.keys(CronCollisionPolicy)[cronCollisionPolicy ? cronCollisionPolicy :
0];
+        }
+      };
+      return cronJobSmrySvc;
+    }]);

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/30161785/src/main/resources/org/apache/aurora/scheduler/http/ui/role.html
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/ui/role.html b/src/main/resources/org/apache/aurora/scheduler/http/ui/role.html
index 94fda63..8b829bb 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/ui/role.html
+++ b/src/main/resources/org/apache/aurora/scheduler/http/ui/role.html
@@ -18,7 +18,7 @@
         </div>
 
         <div class='container-fluid'>
-          <div ng-show='!environment'>
+         <div ng-show='!environment'>
             <div class='row'>
               <div class='span8'>
                 <div ng-controller="QuotaController">
@@ -47,15 +47,6 @@
                        class='table table-striped table-hover table-bordered table-condensed'>
           </smart-table>
         </div>
-
-        <div class='container-fluid'>
-          <h2 class='text-center'>Cron jobs for role <em>{{role}}</em></h2>
-          <smart-table config='cronJobsTableConfig'
-                       columns='cronJobsTableColumns'
-                       rows='cronJobs'
-                       class='table table-striped table-hover table-bordered table-condensed'>
-          </smart-table>
-        </div>
       </div>
     </div>
   </div>


Mime
View raw message