aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject git commit: Add pagination to getTasksStatus
Date Mon, 16 Jun 2014 17:59:34 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 2982077c0 -> 419cb3d97


Add pagination to getTasksStatus

Testing Done:
./gradlew build

Bugs closed: AURORA-521

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


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

Branch: refs/heads/master
Commit: 419cb3d9745383c12c07396b08972cce5dcc5230
Parents: 2982077
Author: David McLaughlin <david@dmclaughlin.com>
Authored: Mon Jun 16 10:59:21 2014 -0700
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Mon Jun 16 10:59:21 2014 -0700

----------------------------------------------------------------------
 .../thrift/SchedulerThriftInterface.java        |  9 ++-
 .../thrift/org/apache/aurora/gen/api.thrift     |  2 +
 .../thrift/SchedulerThriftInterfaceTest.java    | 77 ++++++++++++++++++++
 3 files changed, 87 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/419cb3d9/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 d9c3a1e..485b5e6 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -410,9 +410,16 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
   public Response getTasksStatus(TaskQuery query) {
     checkNotNull(query);
 
-    Set<IScheduledTask> tasks =
+    Iterable<IScheduledTask> tasks =
         Storage.Util.weaklyConsistentFetchTasks(storage, Query.arbitrary(query));
 
+    if (query.isSetOffset()) {
+      tasks = Iterables.skip(tasks, query.getOffset());
+    }
+    if (query.isSetLimit()) {
+      tasks = Iterables.limit(tasks, query.getLimit());
+    }
+
     return okResponse(Result.scheduleStatusResult(
             new ScheduleStatusResult().setTasks(IScheduledTask.toBuildersList(tasks))));
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/419cb3d9/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 505ca33..8865d8f 100644
--- a/src/main/thrift/org/apache/aurora/gen/api.thrift
+++ b/src/main/thrift/org/apache/aurora/gen/api.thrift
@@ -381,6 +381,8 @@ struct TaskQuery {
   7: set<i32> instanceIds
   10: set<string> slaveHosts
   11: set<JobKey> jobKeys
+  12: i32 offset
+  13: i32 limit
 }
 
 struct HostStatus {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/419cb3d9/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 2996796..1742171 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -17,14 +17,19 @@ import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Date;
+import java.util.List;
 import java.util.Set;
 
+import javax.annotation.Nullable;
+
+import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 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.Lists;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -76,6 +81,7 @@ import org.apache.aurora.gen.TaskQuery;
 import org.apache.aurora.gen.ValueConstraint;
 import org.apache.aurora.scheduler.base.JobKeys;
 import org.apache.aurora.scheduler.base.Query;
+import org.apache.aurora.scheduler.base.Query.Builder;
 import org.apache.aurora.scheduler.base.ScheduleException;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
@@ -1237,6 +1243,65 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     assertEquals(allJobs, thrift.getJobs(null).getResult().getGetJobsResult().getConfigs());
   }
 
+  private TaskQuery setupPaginatedQuery(Iterable<IScheduledTask> tasks, int offset,
int limit) {
+    TaskQuery query = new TaskQuery().setOffset(offset).setLimit(limit);
+    Builder builder = Query.arbitrary(query);
+    storageUtil.expectTaskFetch(builder, ImmutableSet.copyOf(tasks));
+    return query;
+  }
+
+  private static final Function<ScheduledTask, Integer> TO_INSTANCE_ID =
+      new Function<ScheduledTask, Integer>() {
+        @Nullable
+        @Override
+        public Integer apply(@Nullable ScheduledTask input) {
+          return input.getAssignedTask().getInstanceId();
+        }
+      };
+
+  @Test
+  public void testGetTasksStatusPagination() throws Exception {
+    Iterable<IScheduledTask> tasks = makeDefaultScheduledTasks(10);
+
+    TaskQuery page1Query = setupPaginatedQuery(tasks, 0, 4);
+    TaskQuery page2Query = setupPaginatedQuery(tasks, 4, 4);
+    TaskQuery page3Query = setupPaginatedQuery(tasks, 8, 4);
+
+    control.replay();
+
+    Response page1Response = assertOkResponse(thrift.getTasksStatus(page1Query));
+    Response page2Response = assertOkResponse(thrift.getTasksStatus(page2Query));
+    Response page3Response = assertOkResponse(thrift.getTasksStatus(page3Query));
+
+    Iterable<Integer> page1Ids = Lists.newArrayList(Iterables.transform(
+        page1Response.getResult().getScheduleStatusResult().getTasks(), TO_INSTANCE_ID));
+    Iterable<Integer> page2Ids = Lists.newArrayList(Iterables.transform(
+        page2Response.getResult().getScheduleStatusResult().getTasks(), TO_INSTANCE_ID));
+    Iterable<Integer> page3Ids = Lists.newArrayList(Iterables.transform(
+        page3Response.getResult().getScheduleStatusResult().getTasks(), TO_INSTANCE_ID));
+
+    assertEquals(Lists.newArrayList(0, 1, 2, 3), page1Ids);
+    assertEquals(Lists.newArrayList(4, 5, 6, 7), page2Ids);
+    assertEquals(Lists.newArrayList(8, 9), page3Ids);
+  }
+
+  @Test
+  public void testGetTasksStatus() throws Exception {
+    Builder query = Query.unscoped();
+
+    Iterable<IScheduledTask> tasks = makeDefaultScheduledTasks(10);
+
+    storageUtil.expectTaskFetch(query, ImmutableSet.copyOf(tasks));
+
+    control.replay();
+
+    ImmutableList<ScheduledTask> expected = IScheduledTask.toBuildersList(tasks);
+
+    Response response = assertOkResponse(thrift.getTasksStatus(new TaskQuery()));
+
+    assertEquals(expected, response.getResult().getScheduleStatusResult().getTasks());
+  }
+
   @Test
   public void testGetRoleSummary() throws Exception {
     final String BAZ_ROLE = "baz_role";
@@ -1541,6 +1606,18 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     return makeJob(task, 1);
   }
 
+  private static Iterable<IScheduledTask> makeDefaultScheduledTasks(int n) {
+    TaskConfig config = defaultTask(true);
+
+    List<IScheduledTask> tasks = Lists.newArrayList();
+    for (int i = 0; i < n; i++) {
+      tasks.add(IScheduledTask.build(new ScheduledTask()
+          .setAssignedTask(new AssignedTask().setTask(config).setInstanceId(i))));
+    }
+
+    return tasks;
+  }
+
   private static JobConfiguration makeJob(TaskConfig task, int shardCount) {
     return new JobConfiguration()
         .setOwner(ROLE_IDENTITY)


Mime
View raw message