You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/11/09 18:33:24 UTC
[2/2] mesos git commit: Quota: Extended the Allocator interface with
quota-related methods.
Quota: Extended the Allocator interface with quota-related methods.
Review: https://reviews.apache.org/r/38218
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6b66fb71
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6b66fb71
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6b66fb71
Branch: refs/heads/master
Commit: 6b66fb712224243100065b295efb18a1cb1f7181
Parents: 3cd887c
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Mon Nov 9 16:33:35 2015 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 9 16:38:12 2015 +0100
----------------------------------------------------------------------
include/mesos/master/allocator.hpp | 49 ++++++++++++++++++++++--
src/master/allocator/mesos/allocator.hpp | 38 ++++++++++++++++++
src/master/allocator/mesos/hierarchical.cpp | 19 +++++++++
src/master/allocator/mesos/hierarchical.hpp | 8 +++-
src/tests/allocator.hpp | 41 +++++++++++++++++---
5 files changed, 145 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66fb71/include/mesos/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp
index dbceb53..f76118b 100644
--- a/include/mesos/master/allocator.hpp
+++ b/include/mesos/master/allocator.hpp
@@ -27,6 +27,8 @@
#include <mesos/maintenance/maintenance.hpp>
+#include <mesos/quota/quota.hpp>
+
#include <mesos/resources.hpp>
#include <process/future.hpp>
@@ -328,6 +330,14 @@ public:
const Option<Filters>& filters) = 0;
/**
+ * Suppresses offers.
+ *
+ * Informs the allocator to stop sending offers to the framework.
+ */
+ virtual void suppressOffers(
+ const FrameworkID& frameworkId) = 0;
+
+ /**
* Revives offers.
*
* Revives offers for a framework. This is invoked by a framework when
@@ -337,12 +347,43 @@ public:
const FrameworkID& frameworkId) = 0;
/**
- * Suppresses offers.
+ * Informs the allocator to set quota for the given role.
*
- * Informs the allocator to stop sending offers to the framework.
+ * It is up to the allocator implementation how to satisfy quota. An
+ * implementation may employ different strategies for roles with or
+ * without quota. Hence an empty (or zero) quota is not necessarily the
+ * same as an absence of quota. Logically, this method implies that the
+ * given role should be transitioned to the group of roles with quota
+ * set. An allocator implementation may assert quota for the given role
+ * is not set prior to the call and react accordingly if this assumption
+ * is violated (i.e. fail).
+ *
+ * TODO(alexr): Consider returning a future which an allocator can fail
+ * in order to report failure.
+ *
+ * TODO(alexr): Consider adding an `updateQuota()` method which allows
+ * updating existing quota.
*/
- virtual void suppressOffers(
- const FrameworkID& frameworkId) = 0;
+ virtual void setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota) = 0;
+
+ /**
+ * Informs the allocator to remove quota for the given role.
+ *
+ * An allocator implementation may employ different strategies for roles
+ * with or without quota. Hence an empty (or zero) quota is not necessarily
+ * the same as an absence of quota. Logically, this method implies that the
+ * given role should be transitioned to the group of roles without quota
+ * set (absence of quota). An allocator implementation may assert quota
+ * for the given role is set prior to the call and react accordingly if
+ * this assumption is violated (i.e. fail).
+ *
+ * TODO(alexr): Consider returning a future which an allocator can fail in
+ * order to report failure.
+ */
+ virtual void removeQuota(
+ const std::string& role) = 0;
};
} // namespace allocator {
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66fb71/src/master/allocator/mesos/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp
index c5375aa..d2d32af 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -140,6 +140,13 @@ public:
void reviveOffers(
const FrameworkID& frameworkId);
+ void setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota);
+
+ void removeQuota(
+ const std::string& role);
+
private:
MesosAllocator();
MesosAllocator(const MesosAllocator&); // Not copyable.
@@ -252,6 +259,13 @@ public:
virtual void reviveOffers(
const FrameworkID& frameworkId) = 0;
+
+ virtual void setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota) = 0;
+
+ virtual void removeQuota(
+ const std::string& role) = 0;
};
@@ -563,6 +577,30 @@ inline void MesosAllocator<AllocatorProcess>::reviveOffers(
frameworkId);
}
+
+template <typename AllocatorProcess>
+inline void MesosAllocator<AllocatorProcess>::setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota)
+{
+ process::dispatch(
+ process,
+ &MesosAllocatorProcess::setQuota,
+ role,
+ quota);
+}
+
+
+template <typename AllocatorProcess>
+inline void MesosAllocator<AllocatorProcess>::removeQuota(
+ const std::string& role)
+{
+ process::dispatch(
+ process,
+ &MesosAllocatorProcess::removeQuota,
+ role);
+}
+
} // namespace allocator {
} // namespace master {
} // namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66fb71/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index f4e4a12..14fef63 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -834,6 +834,25 @@ void HierarchicalAllocatorProcess::reviveOffers(
}
+void HierarchicalAllocatorProcess::setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota)
+{
+ CHECK(initialized);
+
+ LOG(INFO) << "Received quota set request for role " << role;
+}
+
+
+void HierarchicalAllocatorProcess::removeQuota(
+ const std::string& role)
+{
+ CHECK(initialized);
+
+ LOG(INFO) << "Received quota remove request for role " << role;
+}
+
+
void HierarchicalAllocatorProcess::batch()
{
allocate();
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66fb71/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index cfd937b..cd0d3e0 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -176,6 +176,13 @@ public:
void reviveOffers(
const FrameworkID& frameworkId);
+ void setQuota(
+ const std::string& role,
+ const mesos::quota::QuotaInfo& quota);
+
+ void removeQuota(
+ const std::string& role);
+
protected:
// Useful typedefs for dispatch/delay/defer to self()/this.
typedef HierarchicalAllocatorProcess Self;
@@ -384,7 +391,6 @@ public:
[]() -> Sorter* { return new FrameworkSorter(); }) {}
};
-
} // namespace allocator {
} // namespace master {
} // namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/6b66fb71/src/tests/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp
index 4ab4766..e0cb2e7 100644
--- a/src/tests/allocator.hpp
+++ b/src/tests/allocator.hpp
@@ -180,6 +180,18 @@ ACTION_P(InvokeReviveOffers, allocator)
}
+ACTION_P(InvokeSetQuota, allocator)
+{
+ allocator->real->setQuota(arg0, arg1);
+}
+
+
+ACTION_P(InvokeRemoveQuota, allocator)
+{
+ allocator->real->removeQuota(arg0);
+}
+
+
template <typename T = master::allocator::HierarchicalDRFAllocator>
mesos::master::allocator::Allocator* createAllocator()
{
@@ -302,14 +314,24 @@ public:
EXPECT_CALL(*this, recoverResources(_, _, _, _))
.WillRepeatedly(DoDefault());
+ ON_CALL(*this, suppressOffers(_))
+ .WillByDefault(InvokeSuppressOffers(this));
+ EXPECT_CALL(*this, suppressOffers(_))
+ .WillRepeatedly(DoDefault());
+
ON_CALL(*this, reviveOffers(_))
.WillByDefault(InvokeReviveOffers(this));
EXPECT_CALL(*this, reviveOffers(_))
.WillRepeatedly(DoDefault());
- ON_CALL(*this, suppressOffers(_))
- .WillByDefault(InvokeSuppressOffers(this));
- EXPECT_CALL(*this, suppressOffers(_))
+ ON_CALL(*this, setQuota(_, _))
+ .WillByDefault(InvokeSetQuota(this));
+ EXPECT_CALL(*this, setQuota(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, removeQuota(_))
+ .WillByDefault(InvokeRemoveQuota(this));
+ EXPECT_CALL(*this, removeQuota(_))
.WillRepeatedly(DoDefault());
}
@@ -401,9 +423,18 @@ public:
const Resources&,
const Option<Filters>& filters));
- MOCK_METHOD1(reviveOffers, void(const FrameworkID&));
+ MOCK_METHOD1(suppressOffers, void(
+ const FrameworkID&));
+
+ MOCK_METHOD1(reviveOffers, void(
+ const FrameworkID&));
+
+ MOCK_METHOD2(setQuota, void(
+ const std::string&,
+ const mesos::quota::QuotaInfo&));
- MOCK_METHOD1(suppressOffers, void(const FrameworkID&));
+ MOCK_METHOD1(removeQuota, void(
+ const std::string&));
process::Owned<mesos::master::allocator::Allocator> real;
};