aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Added nextCronRunMs field to JobSummary.
Date Fri, 21 Mar 2014 02:44:12 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 5fcf3a3b2 -> 930553ad3


Added nextCronRunMs field to JobSummary.

Testing Done:
./gradlew clean build run on laptop.

Bugs closed: AURORA-277

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


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

Branch: refs/heads/master
Commit: 930553ad3fc296df2186e05880dee5474b53f980
Parents: 5fcf3a3
Author: Suman Karumuri <mansu@apache.org>
Authored: Thu Mar 20 19:42:19 2014 -0700
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Thu Mar 20 19:42:19 2014 -0700

----------------------------------------------------------------------
 .../thrift/SchedulerThriftInterface.java        | 20 +++++++++---
 .../thrift/org/apache/aurora/gen/api.thrift     |  1 +
 .../thrift/SchedulerThriftInterfaceTest.java    | 32 +++++++++++++++-----
 .../aurora/scheduler/thrift/ThriftIT.java       |  2 ++
 .../org/apache/aurora/gen/api.thrift.md5        |  2 +-
 5 files changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/930553ad/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 0d1e214..12d33ff 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -32,6 +32,7 @@ import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
+import com.google.common.base.Strings;
 import com.google.common.base.Throwables;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.HashMultimap;
@@ -99,6 +100,7 @@ import org.apache.aurora.scheduler.base.Tasks;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager.TaskDescriptionException;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
+import org.apache.aurora.scheduler.cron.CronPredictor;
 import org.apache.aurora.scheduler.quota.QuotaInfo;
 import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.quota.QuotaManager.QuotaException;
@@ -175,6 +177,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
   private final Recovery recovery;
   private final MaintenanceController maintenance;
   private final CronJobManager cronJobManager;
+  private final CronPredictor cronPredictor;
   private final QuotaManager quotaManager;
   private final Amount<Long, Time> killTaskInitialBackoff;
   private final Amount<Long, Time> killTaskMaxBackoff;
@@ -188,6 +191,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       StorageBackup backup,
       Recovery recovery,
       CronJobManager cronJobManager,
+      CronPredictor cronPredictor,
       MaintenanceController maintenance,
       QuotaManager quotaManager) {
 
@@ -199,6 +203,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
         recovery,
         maintenance,
         cronJobManager,
+        cronPredictor,
         quotaManager,
         KILL_TASK_INITIAL_BACKOFF.get(),
         KILL_TASK_MAX_BACKOFF.get());
@@ -214,6 +219,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       Recovery recovery,
       MaintenanceController maintenance,
       CronJobManager cronJobManager,
+      CronPredictor cronPredictor,
       QuotaManager quotaManager,
       Amount<Long, Time> initialBackoff,
       Amount<Long, Time> maxBackoff) {
@@ -226,6 +232,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     this.recovery = checkNotNull(recovery);
     this.maintenance = checkNotNull(maintenance);
     this.cronJobManager = checkNotNull(cronJobManager);
+    this.cronPredictor = checkNotNull(cronPredictor);
     this.quotaManager = checkNotNull(quotaManager);
     this.killTaskInitialBackoff = checkNotNull(initialBackoff);
     this.killTaskMaxBackoff = checkNotNull(maxBackoff);
@@ -409,9 +416,14 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     Function<IJobKey, JobSummary> makeJobSummary = new Function<IJobKey, JobSummary>()
{
       @Override
       public JobSummary apply(IJobKey jobKey) {
-        return new JobSummary()
-            .setJob(jobs.get(jobKey).newBuilder())
+        IJobConfiguration job = jobs.get(jobKey);
+        JobSummary smry = new JobSummary()
+            .setJob(job.newBuilder())
             .setStats(Jobs.getJobStats(tasks.get(jobKey)).newBuilder());
+
+        return Strings.isNullOrEmpty(job.getCronSchedule())
+            ? smry
+            : smry.setNextCronRunMs(cronPredictor.predictNextRun(job.getCronSchedule()).getTime());
       }
     };
 
@@ -457,8 +469,8 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
         ? Predicates.compose(Predicates.equalTo(ownerRole.get()), JobKeys.CONFIG_TO_ROLE)
         : Predicates.<IJobConfiguration>alwaysTrue();
     jobs.putAll(Maps.uniqueIndex(
-            FluentIterable.from(cronJobManager.getJobs()).filter(configFilter),
-            JobKeys.FROM_CONFIG));
+        FluentIterable.from(cronJobManager.getJobs()).filter(configFilter),
+        JobKeys.FROM_CONFIG));
 
     return jobs;
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/930553ad/src/main/thrift/org/apache/aurora/gen/api.thrift
----------------------------------------------------------------------
diff --git a/src/main/thrift/org/apache/aurora/gen/api.thrift b/src/main/thrift/org/apache/aurora/gen/api.thrift
index e64f844..c0618e4 100644
--- a/src/main/thrift/org/apache/aurora/gen/api.thrift
+++ b/src/main/thrift/org/apache/aurora/gen/api.thrift
@@ -219,6 +219,7 @@ struct JobStats {
 struct JobSummary {
   1: JobConfiguration job
   2: JobStats stats
+  3: optional i64 nextCronRunMs  // Timestamp of next cron run in ms since epoch, for a cron
job
 }
 
 // A request to add the following instances to an existing job. Used by addInstances.

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/930553ad/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index 60df209..c89965c 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -15,6 +15,7 @@
  */
 package org.apache.aurora.scheduler.thrift;
 
+import java.util.Date;
 import java.util.Set;
 
 import com.google.common.base.Optional;
@@ -22,7 +23,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -76,6 +76,7 @@ import org.apache.aurora.scheduler.base.Query;
 import org.apache.aurora.scheduler.base.ScheduleException;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
+import org.apache.aurora.scheduler.cron.CronPredictor;
 import org.apache.aurora.scheduler.quota.QuotaInfo;
 import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.state.CronJobManager;
@@ -145,6 +146,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   private static final ServerInfo SERVER_INFO =
       new ServerInfo().setClusterName("test").setThriftAPIVersion(THRIFT_API_VERSION);
   private static final APIVersion API_VERSION = new APIVersion().setMajor(THRIFT_API_VERSION);
+  private static final String CRON_SCHEDULE = "0 * * * *";
 
   private StorageTestUtil storageUtil;
   private SchedulerCore scheduler;
@@ -156,6 +158,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   private MaintenanceController maintenance;
   private AuroraAdmin.Iface thrift;
   private CronJobManager cronJobManager;
+  private CronPredictor cronPredictor;
   private QuotaManager quotaManager;
 
   @Before
@@ -171,6 +174,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     recovery = createMock(Recovery.class);
     maintenance = createMock(MaintenanceController.class);
     cronJobManager = createMock(CronJobManager.class);
+    cronPredictor = createMock(CronPredictor.class);
     quotaManager = createMock(QuotaManager.class);
 
     // Use guice and install AuthModule to apply AOP-style auth layer.
@@ -189,6 +193,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         bind(QuotaManager.class).toInstance(quotaManager);
         bind(AuroraAdmin.Iface.class).to(SchedulerThriftInterface.class);
         bind(IServerInfo.class).toInstance(IServerInfo.build(SERVER_INFO));
+        bind(CronPredictor.class).toInstance(cronPredictor);
       }
     };
     Injector injector = Guice.createInjector(testModule, new AopModule());
@@ -952,12 +957,13 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
 
   @Test
   public void testGetJobSummary() throws Exception {
+    int nextCronRunMs = 100;
     TaskConfig ownedCronJobTask = nonProductionTask()
         .setJobName(JobKeys.TO_JOB_NAME.apply(JOB_KEY))
         .setOwner(ROLE_IDENTITY)
         .setEnvironment(JobKeys.TO_ENVIRONMENT.apply(JOB_KEY));
     JobConfiguration ownedCronJob = makeJob()
-        .setCronSchedule("0 * * * *")
+        .setCronSchedule(CRON_SCHEDULE)
         .setTaskConfig(ownedCronJobTask);
     IScheduledTask ownedCronJobScheduledTask = IScheduledTask.build(new ScheduledTask()
         .setAssignedTask(new AssignedTask().setTask(ownedCronJobTask))
@@ -965,7 +971,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     Identity otherOwner = new Identity("other", "other");
     JobConfiguration unownedCronJob = makeJob()
         .setOwner(otherOwner)
-        .setCronSchedule("0 * * * *")
+        .setCronSchedule(CRON_SCHEDULE)
         .setKey(JOB_KEY.newBuilder().setRole("other"))
         .setTaskConfig(ownedCronJobTask.deepCopy().setOwner(otherOwner));
     TaskConfig ownedImmediateTaskInfo = defaultTask(false)
@@ -973,9 +979,15 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         .setOwner(ROLE_IDENTITY);
     Set<JobConfiguration> ownedCronJobOnly = ImmutableSet.of(ownedCronJob);
     Set<JobSummary> ownedCronJobSummaryOnly = ImmutableSet.of(
-        new JobSummary().setJob(ownedCronJob).setStats(new JobStats()));
+        new JobSummary()
+            .setJob(ownedCronJob)
+            .setStats(new JobStats())
+            .setNextCronRunMs(nextCronRunMs));
     Set<JobSummary> ownedCronJobSummaryWithRunningTask = ImmutableSet.of(
-        new JobSummary().setJob(ownedCronJob).setStats(new JobStats().setActiveTaskCount(1)));
+        new JobSummary()
+            .setJob(ownedCronJob)
+            .setStats(new JobStats().setActiveTaskCount(1))
+            .setNextCronRunMs(nextCronRunMs));
     Set<JobConfiguration> unownedCronJobOnly = ImmutableSet.of(unownedCronJob);
     Set<JobConfiguration> bothCronJobs = ImmutableSet.of(ownedCronJob, unownedCronJob);
 
@@ -992,6 +1004,10 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     Set<JobSummary> ownedImmedieteJobSummaryOnly = ImmutableSet.of(
         new JobSummary().setJob(ownedImmediateJob).setStats(new JobStats().setActiveTaskCount(1)));
 
+    expect(cronPredictor.predictNextRun(CRON_SCHEDULE))
+        .andReturn(new Date(nextCronRunMs))
+        .anyTimes();
+
     expect(cronJobManager.getJobs()).andReturn(IJobConfiguration.setFromBuilders(ownedCronJobOnly));
     storageUtil.expectTaskFetch(query);
 
@@ -1024,7 +1040,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
             .getJob()
             .getTaskConfig());
 
-    assertEquals(jobSummaryResponse(Sets.<JobSummary>newHashSet()), thrift.getJobSummary(ROLE));
+    assertEquals(jobSummaryResponse(ImmutableSet.<JobSummary>of()), thrift.getJobSummary(ROLE));
 
     assertEquals(jobSummaryResponse(ownedCronJobSummaryWithRunningTask),
         thrift.getJobSummary(ROLE));
@@ -1049,7 +1065,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         .setOwner(ROLE_IDENTITY)
         .setEnvironment(JobKeys.TO_ENVIRONMENT.apply(JOB_KEY));
     JobConfiguration ownedCronJob = makeJob()
-        .setCronSchedule("0 * * * *")
+        .setCronSchedule(CRON_SCHEDULE)
         .setTaskConfig(ownedCronJobTask);
     IScheduledTask ownedCronJobScheduledTask = IScheduledTask.build(new ScheduledTask()
         .setAssignedTask(new AssignedTask().setTask(ownedCronJobTask))
@@ -1057,7 +1073,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     Identity otherOwner = new Identity("other", "other");
     JobConfiguration unownedCronJob = makeJob()
         .setOwner(otherOwner)
-        .setCronSchedule("0 * * * *")
+        .setCronSchedule(CRON_SCHEDULE)
         .setKey(JOB_KEY.newBuilder().setRole("other"))
         .setTaskConfig(ownedCronJobTask.deepCopy().setOwner(otherOwner));
     TaskConfig ownedImmediateTaskInfo = defaultTask(false)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/930553ad/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
index e78ee7b..e212174 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
@@ -34,6 +34,7 @@ import org.apache.aurora.gen.AuroraAdmin;
 import org.apache.aurora.gen.ResourceAggregate;
 import org.apache.aurora.gen.ServerInfo;
 import org.apache.aurora.gen.SessionKey;
+import org.apache.aurora.scheduler.cron.CronPredictor;
 import org.apache.aurora.scheduler.cron.CronScheduler;
 import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.state.LockManager;
@@ -164,6 +165,7 @@ public class ThriftIT extends EasyMockTest {
             bind(SessionValidator.class).toInstance(validator);
             bind(CapabilityValidator.class).toInstance(new CapabilityValidatorFake(validator));
             bind(IServerInfo.class).toInstance(IServerInfo.build(new ServerInfo()));
+            bindMock(CronPredictor.class);
           }
         }
     );

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/930553ad/src/test/resources/org/apache/aurora/gen/api.thrift.md5
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/gen/api.thrift.md5 b/src/test/resources/org/apache/aurora/gen/api.thrift.md5
index 456634c..05c6e8a 100644
--- a/src/test/resources/org/apache/aurora/gen/api.thrift.md5
+++ b/src/test/resources/org/apache/aurora/gen/api.thrift.md5
@@ -1 +1 @@
-40e828a92f5193776f50e982b01a4663
+f91209ac428266e87dac5430bf46ed10


Mime
View raw message