You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gy...@apache.org on 2017/02/09 06:51:44 UTC

mesos git commit: Enabled revive offer per role.

Repository: mesos
Updated Branches:
  refs/heads/master 54e65143c -> c2388a511


Enabled revive offer per role.

Enabled revive offer per role.

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


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

Branch: refs/heads/master
Commit: c2388a511c775dd6f392961b06fd7738bf051dbc
Parents: 54e6514
Author: Guangya Liu <gy...@apache.org>
Authored: Thu Feb 9 14:51:27 2017 +0800
Committer: Guangya Liu <gy...@gmail.com>
Committed: Thu Feb 9 14:51:27 2017 +0800

----------------------------------------------------------------------
 include/mesos/allocator/allocator.hpp       | 12 +++++----
 src/master/allocator/mesos/allocator.hpp    | 12 ++++++---
 src/master/allocator/mesos/hierarchical.cpp | 10 +++++---
 src/master/allocator/mesos/hierarchical.hpp |  4 +--
 src/master/master.cpp                       | 31 +++++++++++++++++++++++-
 src/tests/allocator.hpp                     | 11 +++++----
 src/tests/hierarchical_allocator_tests.cpp  |  8 +++---
 7 files changed, 64 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/include/mesos/allocator/allocator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/allocator/allocator.hpp b/include/mesos/allocator/allocator.hpp
index 449a1ca..23413d1 100644
--- a/include/mesos/allocator/allocator.hpp
+++ b/include/mesos/allocator/allocator.hpp
@@ -359,14 +359,16 @@ public:
       const Option<std::string>& role) = 0;
 
   /**
-   * Revives offers for a framework. This is invoked by a framework when
-   * it wishes to receive filtered resources or offers immediately.
+   * Revives offers to this framework for the specified role. This is
+   * invoked by a framework when it wishes to receive filtered resources
+   * immediately or get itself out of a suppressed state.
    *
-   * TODO(bmahler): Take an optional role to allow frameworks with
-   * multiple roles to do fine-grained revival.
+   * @param role The optional role parameter allows frameworks with multiple
+   *     roles to do fine-grained revival.
    */
   virtual void reviveOffers(
-      const FrameworkID& frameworkId) = 0;
+      const FrameworkID& frameworkId,
+      const Option<std::string>& role) = 0;
 
   /**
    * Informs the allocator to set quota for the given role.

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/master/allocator/mesos/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp
index fd36b39..38fbf16 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -147,7 +147,8 @@ public:
       const Option<std::string>& role);
 
   void reviveOffers(
-      const FrameworkID& frameworkId);
+      const FrameworkID& frameworkId,
+      const Option<std::string>& role);
 
   void setQuota(
       const std::string& role,
@@ -281,7 +282,8 @@ public:
       const Option<std::string>& role) = 0;
 
   virtual void reviveOffers(
-      const FrameworkID& frameworkId) = 0;
+      const FrameworkID& frameworkId,
+      const Option<std::string>& role) = 0;
 
   virtual void setQuota(
       const std::string& role,
@@ -618,12 +620,14 @@ inline void MesosAllocator<AllocatorProcess>::suppressOffers(
 
 template <typename AllocatorProcess>
 inline void MesosAllocator<AllocatorProcess>::reviveOffers(
-    const FrameworkID& frameworkId)
+    const FrameworkID& frameworkId,
+    const Option<std::string>& role)
 {
   process::dispatch(
       process,
       &MesosAllocatorProcess::reviveOffers,
-      frameworkId);
+      frameworkId,
+      role);
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 63f4c6b..eeb44fe 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1170,7 +1170,8 @@ void HierarchicalAllocatorProcess::suppressOffers(
 
 
 void HierarchicalAllocatorProcess::reviveOffers(
-    const FrameworkID& frameworkId)
+    const FrameworkID& frameworkId,
+    const Option<string>& role)
 {
   CHECK(initialized);
   CHECK(frameworks.contains(frameworkId));
@@ -1179,13 +1180,16 @@ void HierarchicalAllocatorProcess::reviveOffers(
   framework.offerFilters.clear();
   framework.inverseOfferFilters.clear();
 
+  const set<string>& roles =
+    role.isSome() ? set<string>{role.get()} : framework.roles;
+
   if (framework.suppressed) {
     framework.suppressed = false;
 
     // Activating the framework in the sorter on REVIVE is fine as long as
     // SUPPRESS is not parameterized. When parameterization is added,
     // we may need to differentiate between the cases here.
-    foreach (const string& role, framework.roles) {
+    foreach (const string& role, roles) {
       CHECK(frameworkSorters.contains(role));
       frameworkSorters.at(role)->activate(frameworkId.value());
     }
@@ -1198,7 +1202,7 @@ void HierarchicalAllocatorProcess::reviveOffers(
   // would expire that filter too soon. Note that this only works
   // right now because ALL Filter types "expire".
 
-  LOG(INFO) << "Revived offers for roles " << stringify(framework.roles)
+  LOG(INFO) << "Revived offers for roles " << stringify(roles)
             << " of framework " << frameworkId;
 
   allocate();

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 6658d39..d333067 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -191,9 +191,9 @@ public:
       const FrameworkID& frameworkId,
       const Option<std::string>& role);
 
-  // TODO(bmahler): Update to take optional Revive.role.
   void reviveOffers(
-      const FrameworkID& frameworkId);
+      const FrameworkID& frameworkId,
+      const Option<std::string>& role);
 
   void setQuota(
       const std::string& role,

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 5ba9433..620919e 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -4847,7 +4847,36 @@ void Master::revive(
 
   ++metrics->messages_revive_offers;
 
-  allocator->reviveOffers(framework->id());
+  const Option<string> role =
+    revive.has_role() ? Option<string>(revive.role()) : None();
+
+  // Validate role if it is set. We need to make sure the role is valid
+  // and also one of the framework roles.
+  if (role.isSome()) {
+    Option<Error> roleError = roles::validate(role.get());
+    if (roleError.isSome()) {
+      LOG(WARNING) << "REVIVE call message with invalid role: "
+                   <<  roleError.get().message;
+
+      return;
+    }
+
+    // TODO(gyliu513): Store the roles set within the Framework struct, so
+    // that we don't have to keep re-computing it.
+    const set<string> roles = protobuf::framework::getRoles(framework->info);
+    if (roles.count(role.get()) == 0) {
+      // TODO(gyliu513): Consider adding a `drop` overload to avoid
+      // custom logging here.
+      LOG(WARNING)
+        << "Ignoring REVIVE call message for framework " << *framework
+        << " with role " << role.get() << " because it does not exist in"
+        << " framework roles";
+
+      return;
+    }
+  }
+
+  allocator->reviveOffers(framework->id(), role);
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/tests/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp
index 64311c2..c741a98 100644
--- a/src/tests/allocator.hpp
+++ b/src/tests/allocator.hpp
@@ -180,7 +180,7 @@ ACTION_P(InvokeSuppressOffers, allocator)
 
 ACTION_P(InvokeReviveOffers, allocator)
 {
-  allocator->real->reviveOffers(arg0);
+  allocator->real->reviveOffers(arg0, arg1);
 }
 
 
@@ -334,9 +334,9 @@ public:
     EXPECT_CALL(*this, suppressOffers(_, _))
       .WillRepeatedly(DoDefault());
 
-    ON_CALL(*this, reviveOffers(_))
+    ON_CALL(*this, reviveOffers(_, _))
       .WillByDefault(InvokeReviveOffers(this));
-    EXPECT_CALL(*this, reviveOffers(_))
+    EXPECT_CALL(*this, reviveOffers(_, _))
       .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, setQuota(_, _))
@@ -454,8 +454,9 @@ public:
       const FrameworkID&,
       const Option<std::string>&));
 
-  MOCK_METHOD1(reviveOffers, void(
-      const FrameworkID&));
+  MOCK_METHOD2(reviveOffers, void(
+      const FrameworkID&,
+      const Option<std::string>&));
 
   MOCK_METHOD2(setQuota, void(
       const std::string&,

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2388a51/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 44685b8..a866d03 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -2866,7 +2866,7 @@ TEST_F(HierarchicalAllocatorTest, SuppressAndReviveOffers)
 
   // Here the revival is totally unnecessary but we should tolerate the
   // framework's redundant REVIVE calls.
-  allocator->reviveOffers(framework.id());
+  allocator->reviveOffers(framework.id(), None());
 
   // Settle to ensure that the dispatched allocation is executed.
   Clock::settle();
@@ -2891,7 +2891,7 @@ TEST_F(HierarchicalAllocatorTest, SuppressAndReviveOffers)
   EXPECT_TRUE(allocation.isPending());
 
   // Revive again and this time it should work.
-  allocator->reviveOffers(framework.id());
+  allocator->reviveOffers(framework.id(), None());
 
   // Framework will be offered all of agent's resources again after
   // reviving offers.
@@ -3641,7 +3641,7 @@ TEST_F(HierarchicalAllocatorTest, ReviveOffers)
   Future<Allocation> allocation = allocations.get();
   EXPECT_TRUE(allocation.isPending());
 
-  allocator->reviveOffers(framework.id());
+  allocator->reviveOffers(framework.id(), None());
 
   // Framework will be offered all of agent's resources again
   // after reviving offers.
@@ -4585,7 +4585,7 @@ TEST_P(HierarchicalAllocator_BENCHMARK_Test, AllocatorBacklog)
   // events. The allocator doesn't have more resources to allocate
   // but still incurs the overhead of additional allocation runs.
   for (size_t i = 0; i < frameworkCount; i++) {
-    allocator->reviveOffers(frameworks.at(i).id());
+    allocator->reviveOffers(frameworks.at(i).id(), None());
   }
 
   // Wait for all the `reviveOffers` operations to be processed.