You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/07/11 17:32:05 UTC

[1/4] mesos git commit: Added test case for quota allocation with reserved resources.

Repository: mesos
Updated Branches:
  refs/heads/master 6af359ca1 -> b41963396


Added test case for quota allocation with reserved resources.

This test checks that when setting aside unallocated resources to ensure
that a quota guarantee can be met, we don't use resources that have been
reserved for a different role.

Review: https://reviews.apache.org/r/49610/


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

Branch: refs/heads/master
Commit: f51417cfa3bff018673b53a777bbf003b18680ff
Parents: 6af359c
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Jul 11 19:00:23 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Jul 11 19:00:23 2016 +0200

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 102 ++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f51417cf/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 0498cd5..32fc66f 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -2389,6 +2389,108 @@ TEST_F(HierarchicalAllocatorTest, ReservationWithinQuota)
 }
 
 
+// This test checks that when setting aside unallocated resources to
+// ensure that a quota guarantee can be met, we don't use resources
+// that have been reserved for a different role.
+//
+// We setup a scenario with 8 CPUs, where role X has quota for 4 CPUs
+// and role Y has 4 CPUs reserved. All offers are declined; the 4
+// unreserved CPUs should not be offered to role Y.
+TEST_F(HierarchicalAllocatorTest, QuotaSetAsideReservedResources)
+{
+  Clock::pause();
+
+  const string QUOTA_ROLE{"quota-role"};
+  const string NO_QUOTA_ROLE{"no-quota-role"};
+
+  initialize();
+
+  // Create two agents.
+  SlaveInfo agent1 = createSlaveInfo("cpus:4;mem:512;disk:0");
+  allocator->addSlave(agent1.id(), agent1, None(), agent1.resources(), {});
+
+  SlaveInfo agent2 = createSlaveInfo("cpus:4;mem:512;disk:0");
+  allocator->addSlave(agent2.id(), agent2, None(), agent2.resources(), {});
+
+  // Reserve 4 CPUs and 512MB of memory on `agent2` for non-quota'ed role.
+  Resources unreserved = Resources::parse("cpus:4;mem:512").get();
+  Resources dynamicallyReserved =
+    unreserved.flatten(NO_QUOTA_ROLE, createReservationInfo("ops"));
+
+  Offer::Operation reserve = RESERVE(dynamicallyReserved);
+
+  Future<Nothing> updateAgent2 =
+    allocator->updateAvailable(agent2.id(), {reserve});
+
+  AWAIT_EXPECT_READY(updateAgent2);
+
+  // Create `framework1` and set quota for its role.
+  FrameworkInfo framework1 = createFrameworkInfo(QUOTA_ROLE);
+  allocator->addFramework(framework1.id(), framework1, {});
+
+  const Quota quota = createQuota(QUOTA_ROLE, "cpus:4");
+  allocator->setQuota(QUOTA_ROLE, quota);
+
+  // `framework1` will be offered resources at `agent1` because the
+  // resources at `agent2` are reserved for a different role.
+  Future<Allocation> allocation = allocations.get();
+  AWAIT_READY(allocation);
+  EXPECT_EQ(framework1.id(), allocation.get().frameworkId);
+  EXPECT_EQ(agent1.resources(), Resources::sum(allocation.get().resources));
+
+  // `framework1` declines the resources on `agent1` for the duration
+  // of the test.
+  Filters longFilter;
+  longFilter.set_refuse_seconds(flags.allocation_interval.secs() * 10);
+
+  allocator->recoverResources(
+      framework1.id(),
+      agent1.id(),
+      agent1.resources(),
+      longFilter);
+
+  // Trigger a batch allocation for good measure, but don't expect any
+  // allocations.
+  Clock::advance(flags.allocation_interval);
+  Clock::settle();
+
+  allocation = allocations.get();
+  EXPECT_TRUE(allocation.isPending());
+
+  // Create `framework2` in a non-quota'ed role.
+  FrameworkInfo framework2 = createFrameworkInfo(NO_QUOTA_ROLE);
+  allocator->addFramework(framework2.id(), framework2, {});
+
+  // `framework2` will be offered the reserved resources at `agent2`
+  // because those resources are reserved for its role.
+  AWAIT_READY(allocation);
+  EXPECT_EQ(framework2.id(), allocation.get().frameworkId);
+  EXPECT_EQ(dynamicallyReserved, Resources::sum(allocation.get().resources));
+
+  // `framework2` declines the resources on `agent2` for the duration
+  // of the test.
+  allocator->recoverResources(
+      framework2.id(),
+      agent2.id(),
+      dynamicallyReserved,
+      longFilter);
+
+  // No more resource offers should be made until the filters expire:
+  // `framework1` should not be offered the resources at `agent2`
+  // (because they are reserved for a different role), and
+  // `framework2` should not be offered the resources at `agent1`
+  // (because this would risk violating quota guarantees).
+
+  // Trigger a batch allocation for good measure, but don't expect any
+  // allocations.
+  Clock::advance(flags.allocation_interval);
+  Clock::settle();
+
+  allocation = allocations.get();
+  EXPECT_TRUE(allocation.isPending());
+}
+
+
 // This test checks that if a framework suppresses offers, disconnects and
 // reconnects again, it will start receiving resource offers again.
 TEST_F(HierarchicalAllocatorTest, DeactivateAndReactivateFramework)


[3/4] mesos git commit: Fixed typos in comments in allocator-related tests.

Posted by al...@apache.org.
Fixed typos in comments in allocator-related tests.

Review: https://reviews.apache.org/r/49880/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0434858c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0434858c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0434858c

Branch: refs/heads/master
Commit: 0434858c88cfe7b4f71b763f8ab456188c857293
Parents: cf6d64a
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Jul 11 19:02:53 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Jul 11 19:02:53 2016 +0200

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 2 +-
 src/tests/master_allocator_tests.cpp       | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0434858c/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index aa1e45b..472c82f 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -2570,7 +2570,7 @@ TEST_F(HierarchicalAllocatorTest, SuppressAndReviveOffers)
   // framework's redundant REVIVE calls.
   allocator->reviveOffers(framework.id());
 
-  // Nothing is allocated because of no additinal resources.
+  // Nothing is allocated because of no additional resources.
   allocation = allocations.get();
   EXPECT_TRUE(allocation.isPending());
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/0434858c/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index 4beebff..32e3a46 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -427,7 +427,7 @@ TYPED_TEST(MasterAllocatorTest, SchedulerFailover)
   EXPECT_CALL(sched1, resourceOffers(_, _))
     .WillRepeatedly(DeclineOffers()); // For subsequent offers.
 
-  // Initially, all of slave1's resources are avaliable.
+  // Initially, all of slave1's resources are available.
   EXPECT_CALL(sched1, resourceOffers(_, OfferEq(3, 1024)))
     .WillOnce(LaunchTasks(DEFAULT_EXECUTOR_INFO, 1, 1, 256, "*"));
 
@@ -556,7 +556,7 @@ TYPED_TEST(MasterAllocatorTest, FrameworkExited)
     .WillRepeatedly(DeclineOffers());
 
   // The first time the framework is offered resources, all of the
-  // cluster's resources should be avaliable.
+  // cluster's resources should be available.
   EXPECT_CALL(sched1, resourceOffers(_, OfferEq(3, 1024)))
     .WillOnce(LaunchTasks(executor1, 1, 2, 512, "*"));
 
@@ -815,7 +815,7 @@ TYPED_TEST(MasterAllocatorTest, SlaveAdded)
   EXPECT_CALL(sched, resourceOffers(_, _))
     .WillRepeatedly(DeclineOffers());
 
-  // Initially, all of slave1's resources are avaliable.
+  // Initially, all of slave1's resources are available.
   EXPECT_CALL(sched, resourceOffers(_, OfferEq(3, 1024)))
     .WillOnce(LaunchTasks(DEFAULT_EXECUTOR_INFO, 1, 2, 512, "*"));
 


[4/4] mesos git commit: Renamed and lambda-ified a function in allocator tests.

Posted by al...@apache.org.
Renamed and lambda-ified a function in allocator tests.

Review: https://reviews.apache.org/r/49883/


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

Branch: refs/heads/master
Commit: b419633967308e0b6b615818a430aa5781e10842
Parents: 0434858
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Jul 11 19:03:32 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Jul 11 19:03:32 2016 +0200

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 63 ++++++++++++-------------
 1 file changed, 31 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b4196339/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 472c82f..153c9b4 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -243,35 +243,6 @@ protected:
     return weightInfo;
   }
 
-  void handleAllocationsAndRecoverResources(
-      Resources& totalAllocatedResources,
-      hashmap<FrameworkID, Allocation>& frameworkAllocations,
-      int allocationsCount,
-      bool recoverResources)
-  {
-    for (int i = 0; i < allocationsCount; i++) {
-      Future<Allocation> allocation = allocations.get();
-      AWAIT_READY(allocation);
-
-      frameworkAllocations[allocation.get().frameworkId] = allocation.get();
-      totalAllocatedResources += Resources::sum(allocation.get().resources);
-
-      if (recoverResources) {
-        // Recover the allocated resources so they can be offered again
-        // next time.
-        foreachpair (const SlaveID& slaveId,
-                     const Resources& resources,
-                     allocation.get().resources) {
-          allocator->recoverResources(
-              allocation.get().frameworkId,
-              slaveId,
-              resources,
-              None());
-        }
-      }
-    }
-  }
-
 protected:
   master::Flags flags;
 
@@ -3045,6 +3016,34 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
   const string FOURFOLD_RESOURCES = "cpus:8;mem:4096";
   const string TOTAL_RESOURCES = "cpus:12;mem:6144";
 
+  auto awaitAllocationsAndRecoverResources = [this](
+      Resources& totalAllocatedResources,
+      hashmap<FrameworkID, Allocation>& frameworkAllocations,
+      int allocationsCount,
+      bool recoverResources) {
+    for (int i = 0; i < allocationsCount; i++) {
+      Future<Allocation> allocation = allocations.get();
+      AWAIT_READY(allocation);
+
+      frameworkAllocations[allocation.get().frameworkId] = allocation.get();
+      totalAllocatedResources += Resources::sum(allocation.get().resources);
+
+      if (recoverResources) {
+        // Recover the allocated resources so they can be offered
+        // again next time.
+        foreachpair (const SlaveID& slaveId,
+                     const Resources& resources,
+                     allocation.get().resources) {
+          allocator->recoverResources(
+              allocation.get().frameworkId,
+              slaveId,
+              resources,
+              None());
+        }
+      }
+    }
+  };
+
   // Register six agents with the same resources (cpus:2;mem:1024).
   vector<SlaveInfo> agents;
   for (unsigned i = 0; i < 6; i++) {
@@ -3106,7 +3105,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
     // since each framework's role has a weight of 1.0 by default.
     hashmap<FrameworkID, Allocation> frameworkAllocations;
     Resources totalAllocatedResources;
-    handleAllocationsAndRecoverResources(totalAllocatedResources,
+    awaitAllocationsAndRecoverResources(totalAllocatedResources,
         frameworkAllocations, 2, true);
 
     // Framework1 should get one allocation with three agents.
@@ -3144,7 +3143,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
     // resources are offered with a ratio of 1:2 between both frameworks.
     hashmap<FrameworkID, Allocation> frameworkAllocations;
     Resources totalAllocatedResources;
-    handleAllocationsAndRecoverResources(totalAllocatedResources,
+    awaitAllocationsAndRecoverResources(totalAllocatedResources,
         frameworkAllocations, 2, true);
 
     // Framework1 should get one allocation with two agents.
@@ -3193,7 +3192,7 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
     // will get the proper resource ratio of 1:2:3.
     hashmap<FrameworkID, Allocation> frameworkAllocations;
     Resources totalAllocatedResources;
-    handleAllocationsAndRecoverResources(totalAllocatedResources,
+    awaitAllocationsAndRecoverResources(totalAllocatedResources,
         frameworkAllocations, 3, false);
 
     // Framework1 should get one allocation with one agent.


[2/4] mesos git commit: Removed unnecessary `Clock::settle` calls from test cases.

Posted by al...@apache.org.
Removed unnecessary `Clock::settle` calls from test cases.

If a test case calls `Clock::settle` and then immediately waits for a
future to be completed, settling the clock is usually unnecessary.

Review: https://reviews.apache.org/r/49612/


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

Branch: refs/heads/master
Commit: cf6d64a629a4aba4c2cb5a936e2a1a15576e7aac
Parents: f51417c
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Jul 11 19:02:39 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Mon Jul 11 19:02:39 2016 +0200

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 14 --------------
 1 file changed, 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cf6d64a6/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 32fc66f..aa1e45b 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -815,7 +815,6 @@ TEST_F(HierarchicalAllocatorTest, SmallOfferFilterTimeout)
 
   // Trigger a batch allocation.
   Clock::advance(flags.allocation_interval);
-  Clock::settle();
 
   // Since the filter is removed, resources are offered to `framework2`.
   allocation = allocations.get();
@@ -1616,7 +1615,6 @@ TEST_F(HierarchicalAllocatorTest, QuotaProvidesGuarantee)
   // Ensure the offer filter times out (2x the allocation interval)
   // and the next batch allocation occurs.
   Clock::advance(flags.allocation_interval);
-  Clock::settle();
 
   // Previously declined resources should be offered to the quota'ed role.
   AWAIT_READY(allocation);
@@ -1696,7 +1694,6 @@ TEST_F(HierarchicalAllocatorTest, RemoveQuota)
 
   // Trigger the next batch allocation.
   Clock::advance(flags.allocation_interval);
-  Clock::settle();
 
   Future<Allocation> allocation = allocations.get();
   AWAIT_READY(allocation);
@@ -1827,7 +1824,6 @@ TEST_F(HierarchicalAllocatorTest, MultipleFrameworksInRoleWithQuota)
 
   // Trigger the next batch allocation.
   Clock::advance(flags.allocation_interval);
-  Clock::settle();
 
   allocation = allocations.get();
   AWAIT_READY(allocation);
@@ -2093,7 +2089,6 @@ TEST_F(HierarchicalAllocatorTest, QuotaAgainstStarvation)
 
   // Trigger the next batch allocation.
   Clock::advance(flags.allocation_interval);
-  Clock::settle();
 
   allocation = allocations.get();
   AWAIT_READY(allocation);
@@ -2541,7 +2536,6 @@ TEST_F(HierarchicalAllocatorTest, DeactivateAndReactivateFramework)
 
   // Framework will be offered all of agent's resources again
   // after getting activated.
-  Clock::settle();
   AWAIT_READY(allocation);
   EXPECT_EQ(framework.id(), allocation.get().frameworkId);
   EXPECT_EQ(agent.resources(), Resources::sum(allocation.get().resources));
@@ -2590,7 +2584,6 @@ TEST_F(HierarchicalAllocatorTest, SuppressAndReviveOffers)
 
   // Advance the clock and trigger a background allocation cycle.
   Clock::advance(flags.allocation_interval);
-
   Clock::settle();
 
   // Still pending because the framework has suppressed offers.
@@ -2601,7 +2594,6 @@ TEST_F(HierarchicalAllocatorTest, SuppressAndReviveOffers)
 
   // Framework will be offered all of agent's resources again after
   // reviving offers.
-  Clock::settle();
   AWAIT_READY(allocation);
   EXPECT_EQ(framework.id(), allocation.get().frameworkId);
   EXPECT_EQ(agent.resources(), Resources::sum(allocation.get().resources));
@@ -3104,7 +3096,6 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
   {
     // Advance the clock and trigger a batch allocation.
     Clock::advance(flags.allocation_interval);
-    Clock::settle();
 
     // role1 share = 0.5 (cpus=6, mem=3072)
     //   framework1 share = 1
@@ -3143,7 +3134,6 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
 
     // 'updateWeights' will trigger the allocation immediately, so it does not
     // need to manually advance the clock here.
-    Clock::settle();
 
     // role1 share = 0.33 (cpus=4, mem=2048)
     //   framework1 share = 1
@@ -3190,7 +3180,6 @@ TEST_F(HierarchicalAllocatorTest, UpdateWeight)
 
     // 'addFramework' will trigger the allocation immediately, so it does not
     // need to manually advance the clock here.
-    Clock::settle();
 
     // role1 share = 0.166 (cpus=2, mem=1024)
     //   framework1 share = 1
@@ -3272,9 +3261,6 @@ TEST_F(HierarchicalAllocatorTest, ReviveOffers)
 
   allocator->reviveOffers(framework.id());
 
-  // Wait for the `reviveOffers` operation to be processed.
-  Clock::settle();
-
   // Framework will be offered all of agent's resources again
   // after reviving offers.
   AWAIT_READY(allocation);