Added quiesce logic in allocator.

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


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

Branch: refs/heads/master
Commit: 3de5bf088b595b8c0f38cb24743465f586e0d81d
Parents: 3a1f2d3
Author: Guangya Liu <[email protected]>
Authored: Fri Sep 18 16:13:44 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Fri Sep 18 16:13:44 2015 -0700

----------------------------------------------------------------------
 include/mesos/master/allocator.hpp          |  4 ++++
 src/master/allocator/mesos/allocator.hpp    | 17 +++++++++++++++++
 src/master/allocator/mesos/hierarchical.hpp | 24 ++++++++++++++++++++++++
 src/master/master.cpp                       |  3 +--
 src/tests/mesos.hpp                         | 13 +++++++++++++
 5 files changed, 59 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3de5bf08/include/mesos/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/allocator.hpp 
b/include/mesos/master/allocator.hpp
index fb09e2a..2dc6312 100644
--- a/include/mesos/master/allocator.hpp
+++ b/include/mesos/master/allocator.hpp
@@ -171,6 +171,10 @@ public:
   // offers for those resources the master invokes this callback.
   virtual void reviveOffers(
       const FrameworkID& frameworkId) = 0;
+
+  // Informs the allocator to stop sending resources for the framework
+  virtual void quiesceOffers(
+      const FrameworkID& frameworkId) = 0;
 };
 
 } // namespace allocator {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3de5bf08/src/master/allocator/mesos/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/allocator.hpp 
b/src/master/allocator/mesos/allocator.hpp
index 171548b..86f6c55 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -127,6 +127,9 @@ public:
       const Resources& resources,
       const Option<Filters>& filters);
 
+  void quiesceOffers(
+      const FrameworkID& frameworkId);
+
   void reviveOffers(
       const FrameworkID& frameworkId);
 
@@ -231,6 +234,9 @@ public:
       const Resources& resources,
       const Option<Filters>& filters) = 0;
 
+  virtual void quiesceOffers(
+      const FrameworkID& frameworkId) = 0;
+
   virtual void reviveOffers(
       const FrameworkID& frameworkId) = 0;
 };
@@ -509,6 +515,17 @@ inline void 
MesosAllocator<AllocatorProcess>::recoverResources(
 
 
 template <typename AllocatorProcess>
+inline void MesosAllocator<AllocatorProcess>::quiesceOffers(
+    const FrameworkID& frameworkId)
+{
+  process::dispatch(
+      process,
+      &MesosAllocatorProcess::quiesceOffers,
+      frameworkId);
+}
+
+
+template <typename AllocatorProcess>
 inline void MesosAllocator<AllocatorProcess>::reviveOffers(
     const FrameworkID& frameworkId)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3de5bf08/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp 
b/src/master/allocator/mesos/hierarchical.hpp
index 3374d63..8f2232a 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -165,6 +165,9 @@ public:
       const Resources& resources,
       const Option<Filters>& filters);
 
+  void quiesceOffers(
+      const FrameworkID& frameworkId);
+
   void reviveOffers(
       const FrameworkID& frameworkId);
 
@@ -241,6 +244,9 @@ protected:
     std::string role;
     bool checkpoint;  // Whether the framework desires checkpointing.
 
+    // Whether the framework quiesces resources.
+    bool quiesced;
+
     // Whether the framework desires revocable resources.
     bool revocable;
 
@@ -450,6 +456,8 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::addFramework(
     }
   }
 
+  frameworks[frameworkId].quiesced = false;
+
   LOG(INFO) << "Added framework " << frameworkId;
 
   allocate();
@@ -1006,12 +1014,23 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::recoverResources(
 
 template <class RoleSorter, class FrameworkSorter>
 void
+HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::quiesceOffers(
+    const FrameworkID& frameworkId)
+{
+  CHECK(initialized);
+  frameworks[frameworkId].quiesced = true;
+}
+
+
+template <class RoleSorter, class FrameworkSorter>
+void
 HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::reviveOffers(
     const FrameworkID& frameworkId)
 {
   CHECK(initialized);
 
   frameworks[frameworkId].filters.clear();
+  frameworks[frameworkId].quiesced = false;
 
   // We delete each actual Filter when
   // HierarchicalAllocatorProcess::expire gets invoked. If we delete the
@@ -1101,6 +1120,11 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::allocate(
         FrameworkID frameworkId;
         frameworkId.set_value(frameworkId_);
 
+        // If the framework has quiesced, ignore.
+        if (frameworks[frameworkId].quiesced) {
+          continue;
+        }
+
         // Calculate the currently available resources on the slave.
         Resources available = slaves[slaveId].total - 
slaves[slaveId].allocated;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3de5bf08/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 7ae4ef8..151ce71 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -2607,8 +2607,7 @@ void Master::quiesce(Framework* framework)
 
   LOG(INFO) << "Processing QUIESCE call for framework " << *framework;
 
-  //TODO(gyliu513): Add quiesce logic here.
-  LOG(WARNING) << "Not implemented yet, ignoring the QUIESCE call.";
+  allocator->quiesceOffers(framework->id());
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3de5bf08/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 3db97ac..760dcb7 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -1380,6 +1380,12 @@ ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, 
timeout)
 }
 
 
+ACTION_P(InvokeQuiesceOffers, allocator)
+{
+  allocator->real->quiesceOffers(arg0);
+}
+
+
 ACTION_P(InvokeReviveOffers, allocator)
 {
   allocator->real->reviveOffers(arg0);
@@ -1507,6 +1513,11 @@ public:
       .WillByDefault(InvokeReviveOffers(this));
     EXPECT_CALL(*this, reviveOffers(_))
       .WillRepeatedly(DoDefault());
+
+    ON_CALL(*this, quiesceOffers(_))
+      .WillByDefault(InvokeQuiesceOffers(this));
+    EXPECT_CALL(*this, quiesceOffers(_))
+      .WillRepeatedly(DoDefault());
   }
 
   virtual ~TestAllocator() {}
@@ -1592,6 +1603,8 @@ public:
 
   MOCK_METHOD1(reviveOffers, void(const FrameworkID&));
 
+  MOCK_METHOD1(quiesceOffers, void(const FrameworkID&));
+
   process::Owned<mesos::master::allocator::Allocator> real;
 };
 

Reply via email to