aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject git commit: Use JobKey when getting roles to authenticate against.
Date Wed, 15 Oct 2014 18:05:05 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 7d87801e1 -> 312d9def5


Use JobKey when getting roles to authenticate against.

Testing Done:
./gradlew clean test

Bugs closed: AURORA-837

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


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

Branch: refs/heads/master
Commit: 312d9def5c9b993b685e6989fd3f0ad187a8cbac
Parents: 7d87801
Author: Zameer Manji <zmanji@twopensource.com>
Authored: Wed Oct 15 10:55:28 2014 -0700
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Wed Oct 15 10:55:28 2014 -0700

----------------------------------------------------------------------
 .../org/apache/aurora/scheduler/base/Query.java     |  4 +---
 .../scheduler/thrift/SchedulerThriftInterface.java  |  3 +++
 .../scheduler/storage/mem/MemTaskStoreTest.java     | 15 +++++++--------
 .../thrift/SchedulerThriftInterfaceTest.java        | 16 ++++++++++++++++
 4 files changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/312d9def/src/main/java/org/apache/aurora/scheduler/base/Query.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/base/Query.java b/src/main/java/org/apache/aurora/scheduler/base/Query.java
index eded7a5..d518acb 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/Query.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/Query.java
@@ -260,9 +260,7 @@ public final class Query {
 
       return new Builder(
           query.deepCopy()
-              .setOwner(new Identity().setRole(jobKey.getRole()))
-              .setEnvironment(jobKey.getEnvironment())
-              .setJobName(jobKey.getName()));
+              .setJobKeys(ImmutableSet.of(jobKey.newBuilder())));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/312d9def/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 137f97d..e792d23 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -720,6 +720,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     // authenticated this way.
     ImmutableSet.Builder<String> targetRoles = ImmutableSet.<String>builder()
         .addAll(FluentIterable.from(tasks).transform(GET_ROLE));
+    Set<IJobKey> keys = JobKeys.from(taskQuery).or(ImmutableSet.<IJobKey>of());
+    targetRoles.addAll(FluentIterable.from(keys).transform(JobKeys.TO_ROLE));
+
     if (taskQuery.get().isSetOwner()) {
       targetRoles.add(taskQuery.get().getOwner().getRole());
     }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/312d9def/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
index 3b61ff3..581f639 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
@@ -136,20 +136,19 @@ public class MemTaskStoreTest {
             JobKeys.from("role-c", "env-c", "job-c"))),
         TASK_A, TASK_B, TASK_C);
 
-    // Conflicting jobs will produce empty result as TaskQuery fields are ANDed.
-    assertEquals(
-        0,
-        store.fetchTasks(
-            Query.jobScoped(JobKeys.from("role-a", "env-a", "job-a"))
-                .byJobKeys(ImmutableSet.of(JobKeys.from("role-b", "env-b", "job-b")))).size());
+    // Conflicting jobs will produce the result from the last added JobKey
+    assertQueryResults(
+          Query.jobScoped(JobKeys.from("role-a", "env-a", "job-a"))
+              .byJobKeys(ImmutableSet.of(JobKeys.from("role-b", "env-b", "job-b"))),
+        TASK_B);
 
-    // Matching jobs would return successfully.
+    // The .byJobKeys will override the previous scoping and OR all of the keys.
     assertQueryResults(
         Query.jobScoped(JobKeys.from("role-a", "env-a", "job-a"))
             .byJobKeys(ImmutableSet.of(
                 JobKeys.from("role-b", "env-b", "job-b"),
                 JobKeys.from("role-a", "env-a", "job-a"))),
-        TASK_A);
+        TASK_A, TASK_B);
 
     // Combination of individual field and jobKeys is allowed.
     assertQueryResults(

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/312d9def/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 c3f0bbe..ebe879c 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -855,6 +855,22 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
   }
 
   @Test
+  public void testKillCronAuthenticatesQueryJobKeyRole() throws Exception {
+    expectAuth(ROOT, false);
+    IJobKey key = JobKeys.from("role", "env", "job");
+
+    Query.Builder query = Query.arbitrary(new TaskQuery().setJobKeys(
+        ImmutableSet.of(key.newBuilder())));
+
+    storageUtil.expectTaskFetch(query.active());
+    expectAuth(ImmutableSet.of("role"), true);
+    expect(cronJobManager.deleteJob(key)).andReturn(true);
+
+    control.replay();
+    assertOkResponse(thrift.killTasks(query.get(), DEFAULT_LOCK, SESSION));
+  }
+
+  @Test
   public void testSetQuota() throws Exception {
     ResourceAggregate resourceAggregate = new ResourceAggregate()
         .setNumCpus(10)


Mime
View raw message