aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Added getJobSummary call to thrift API
Date Thu, 26 Dec 2013 22:24:28 GMT
Updated Branches:
  refs/heads/master 468247981 -> 868d46bb1


Added getJobSummary call to thrift API

Added a new Thrift service to host all read only api's. Added a getJobSummary
call to the read only service end point. The output of the call will be used to
render the home page.

Implemented the getJobSummary API in SchedulerThriftInterface and added a
corresponding unit test. To keep it simple, the implementation of getJobSummary
is a clone of SchedulerzHome.get().

Testing Done:
gradle clean build

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


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

Branch: refs/heads/master
Commit: 868d46bb15eb3ce030c3140a9c86c73aaba07c7c
Parents: 4682479
Author: Suman Karumuri <mansu@apache.org>
Authored: Thu Dec 26 14:22:34 2013 -0800
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Thu Dec 26 14:22:34 2013 -0800

----------------------------------------------------------------------
 .../thrift/SchedulerThriftInterface.java        | 29 +++++++++++
 .../thrift/com/twitter/aurora/gen/api.thrift    | 23 ++++++++-
 .../thrift/SchedulerThriftInterfaceTest.java    | 52 ++++++++++++++++++++
 .../scheduler/thrift/aop/ForwardingThrift.java  |  5 ++
 4 files changed, 108 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/868d46bb/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
b/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
index 503ac44..3ff0f1c 100644
--- a/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -40,6 +40,8 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.Sets;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -62,6 +64,8 @@ import com.twitter.aurora.gen.JobConfigRewrite;
 import com.twitter.aurora.gen.JobConfigValidation;
 import com.twitter.aurora.gen.JobConfiguration;
 import com.twitter.aurora.gen.JobKey;
+import com.twitter.aurora.gen.JobSummary;
+import com.twitter.aurora.gen.JobSummaryResult;
 import com.twitter.aurora.gen.ListBackupsResult;
 import com.twitter.aurora.gen.Lock;
 import com.twitter.aurora.gen.LockKey;
@@ -371,6 +375,31 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
   }
 
   @Override
+  public Response getJobSummary() {
+    Set<IScheduledTask> tasks = Storage.Util.weaklyConsistentFetchTasks(storage, Query.unscoped());
+    Multimap<String, IJobKey> jobsByRole = Multimaps.index(
+        FluentIterable.from(tasks).transform(Tasks.SCHEDULED_TO_JOB_KEY),
+        JobKeys.TO_ROLE);
+
+    Multimap<String, IJobKey> cronJobsByRole = Multimaps.index(
+        FluentIterable.from(cronJobManager.getJobs()).transform(JobKeys.FROM_CONFIG),
+        JobKeys.TO_ROLE);
+
+    List<JobSummary> jobSummaries = Lists.newLinkedList();
+    for (String role : Sets.union(jobsByRole.keySet(), cronJobsByRole.keySet())) {
+      JobSummary summary = new JobSummary();
+      summary.setRole(role);
+      summary.setJobCount(jobsByRole.get(role).size());
+      summary.setCronJobCount(cronJobsByRole.get(role).size());
+      jobSummaries.add(summary);
+    }
+
+    return new Response()
+        .setResponseCode(OK)
+        .setResult(Result.jobSummaryResult(new JobSummaryResult(jobSummaries)));
+  }
+
+  @Override
   public Response getJobs(@Nullable String maybeNullRole) {
     Optional<String> ownerRole = Optional.fromNullable(maybeNullRole);
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/868d46bb/src/main/thrift/com/twitter/aurora/gen/api.thrift
----------------------------------------------------------------------
diff --git a/src/main/thrift/com/twitter/aurora/gen/api.thrift b/src/main/thrift/com/twitter/aurora/gen/api.thrift
index 9b3680b..ef96f36 100644
--- a/src/main/thrift/com/twitter/aurora/gen/api.thrift
+++ b/src/main/thrift/com/twitter/aurora/gen/api.thrift
@@ -351,6 +351,12 @@ struct HostStatus {
   2: MaintenanceMode mode
 }
 
+struct JobSummary {
+  1: string role
+  2: i32 jobCount
+  3: i32 cronJobCount
+}
+
 struct Hosts {
   1: set<string> hostNames
 }
@@ -379,6 +385,10 @@ struct EndMaintenanceResult {
   1: set<HostStatus> statuses
 }
 
+struct JobSummaryResult {
+  1: list<JobSummary> summaries
+}
+
 // Specifies validation level for the populateJobConfig.
 enum JobConfigValidation {
   NONE              = 0   // No additional job config validation would be performed (only
parsing).
@@ -398,6 +408,7 @@ union Result {
   11: EndMaintenanceResult endMaintenanceResult
   15: APIVersion getVersionResult
   16: AcquireLockResult acquireLockResult
+  17: JobSummaryResult jobSummaryResult
 }
 
 struct Response {
@@ -407,10 +418,16 @@ struct Response {
   3: optional Result result
 }
 
+// A service that provides all the read only calls to the Aurora scheduler.
+service ReadOnlyScheduler {
+  // Returns a summary of the jobs grouped by role.
+  Response getJobSummary()
+}
+
 // Due to assumptions in the client all authenticated RPCs must have a SessionKey as their
 // last argument. Note that the order in this file is what matters, and message numbers should
still
 // never be reused.
-service AuroraSchedulerManager {
+service AuroraSchedulerManager extends ReadOnlyScheduler {
   // Creates a new job.  The request will be denied if a job with the provided
   // name already exists in the cluster.
   Response createJob(1: JobConfiguration description, 3: Lock lock, 2: SessionKey session)
@@ -426,9 +443,11 @@ service AuroraSchedulerManager {
   // Restarts a batch of shards.
   Response restartShards(5: JobKey job, 3: set<i32> shardIds, 6: Lock lock 4: SessionKey
session)
 
+  // TODO(Suman Karumuri): Move this call into read only api
   // Fetches the status of tasks.
   Response getTasksStatus(1: TaskQuery query)
 
+  // TODO(Suman Karumuri): Move this call into the read only api
   // Fetches the status of jobs.
   // ownerRole is optional, in which case all jobs are returned.
   Response getJobs(1: string ownerRole)
@@ -436,9 +455,11 @@ service AuroraSchedulerManager {
   // Initiates a kill on tasks.
   Response killTasks(1: TaskQuery query, 3: Lock lock, 2: SessionKey session)
 
+  // TODO(Suman Karumuri): Move this call into the read only api
   // Fetches the quota allocated for a user.
   Response getQuota(1: string ownerRole)
 
+  // TODO(Suman Karumuri): Move this call into the read only api
   // Returns the current version of the API implementation
   Response getVersion()
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/868d46bb/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
b/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index 1e1e7b5..7e641b7 100644
--- a/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -50,6 +50,8 @@ import com.twitter.aurora.gen.JobConfigRewrite;
 import com.twitter.aurora.gen.JobConfigValidation;
 import com.twitter.aurora.gen.JobConfiguration;
 import com.twitter.aurora.gen.JobKey;
+import com.twitter.aurora.gen.JobSummary;
+import com.twitter.aurora.gen.JobSummaryResult;
 import com.twitter.aurora.gen.LimitConstraint;
 import com.twitter.aurora.gen.Lock;
 import com.twitter.aurora.gen.LockKey;
@@ -1035,6 +1037,56 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   }
 
   @Test
+  public void testGetRoleSummary() throws Exception {
+    final String BAZ_ROLE = "baz_role";
+    final Identity BAZ_ROLE_IDENTITY = new Identity(BAZ_ROLE, USER);
+
+    JobConfiguration cronJobOne = makeJob()
+        .setCronSchedule("1 * * * *")
+        .setKey(JOB_KEY.newBuilder())
+        .setTaskConfig(nonProductionTask());
+    JobConfiguration cronJobTwo = makeJob()
+        .setCronSchedule("2 * * * *")
+        .setKey(JOB_KEY.newBuilder())
+        .setTaskConfig(nonProductionTask());
+
+    JobConfiguration cronJobThree = makeJob()
+        .setCronSchedule("3 * * * *")
+        .setKey(JOB_KEY.newBuilder().setRole(BAZ_ROLE))
+        .setTaskConfig(nonProductionTask())
+        .setOwner(BAZ_ROLE_IDENTITY);
+
+    Set<JobConfiguration> crons = ImmutableSet.of(cronJobOne, cronJobTwo, cronJobThree);
+
+    TaskConfig immediateTaskConfig = defaultTask(false)
+        .setJobName("immediate")
+        .setOwner(ROLE_IDENTITY);
+    IScheduledTask immediateTask = IScheduledTask.build(new ScheduledTask()
+        .setAssignedTask(new AssignedTask().setTask(immediateTaskConfig)));
+
+    TaskConfig immediateTaskConfigTwo = defaultTask(false)
+        .setJobName("immediateTwo")
+        .setOwner(BAZ_ROLE_IDENTITY);
+    IScheduledTask immediateTaskTwo = IScheduledTask.build(new ScheduledTask()
+        .setAssignedTask(new AssignedTask().setTask(immediateTaskConfigTwo)));
+
+    storageUtil.expectTaskFetch(Query.unscoped(), immediateTask, immediateTaskTwo);
+    expect(cronJobManager.getJobs()).andReturn(IJobConfiguration.setFromBuilders(crons));
+
+    JobSummaryResult expectedResult = new JobSummaryResult();
+    expectedResult.addToSummaries(
+        new JobSummary().setRole(ROLE).setCronJobCount(2).setJobCount(1));
+    expectedResult.addToSummaries(
+        new JobSummary().setRole(BAZ_ROLE).setCronJobCount(1).setJobCount(1));
+
+    control.replay();
+
+    Response response = thrift.getJobSummary();
+    assertEquals(ResponseCode.OK, response.getResponseCode());
+    assertEquals(expectedResult, response.getResult().getJobSummaryResult());
+  }
+
+  @Test
   public void testSnapshot() throws Exception {
     expectAuth(ROOT, false);
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/868d46bb/src/test/java/com/twitter/aurora/scheduler/thrift/aop/ForwardingThrift.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/twitter/aurora/scheduler/thrift/aop/ForwardingThrift.java b/src/test/java/com/twitter/aurora/scheduler/thrift/aop/ForwardingThrift.java
index 7c5100b..37c0da2 100644
--- a/src/test/java/com/twitter/aurora/scheduler/thrift/aop/ForwardingThrift.java
+++ b/src/test/java/com/twitter/aurora/scheduler/thrift/aop/ForwardingThrift.java
@@ -107,6 +107,11 @@ abstract class ForwardingThrift implements AuroraAdmin.Iface {
   }
 
   @Override
+  public Response getJobSummary() throws TException {
+    return delegate.getJobSummary();
+  }
+
+  @Override
   public Response createJob(JobConfiguration description, Lock lock, SessionKey session)
       throws TException {
 


Mime
View raw message