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/10/15 09:13:00 UTC
mesos git commit: Hierarchical Allocator: Replaced Polymorphic
factory with functions.
Repository: mesos
Updated Branches:
refs/heads/master 2391f84fb -> 8b87d4772
Hierarchical Allocator: Replaced Polymorphic factory with functions.
Review: https://reviews.apache.org/r/39312
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8b87d477
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8b87d477
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8b87d477
Branch: refs/heads/master
Commit: 8b87d4772c8653574b4892b8a28b8de1a3575fd3
Parents: 2391f84
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Thu Oct 15 08:56:48 2015 +0200
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Oct 15 09:12:39 2015 +0200
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 4 +--
src/master/allocator/mesos/hierarchical.hpp | 44 ++++++------------------
2 files changed, 12 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/8b87d477/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 0a6f8a6..f4e4a12 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -126,11 +126,11 @@ void HierarchicalAllocatorProcess::initialize(
roles = _roles;
initialized = true;
- roleSorter = sorterFactory->createRoleSorter();
+ roleSorter = roleSorterFactory();
foreachpair (
const std::string& name, const mesos::master::RoleInfo& roleInfo, roles) {
roleSorter->add(name, roleInfo.weight());
- frameworkSorters[name] = sorterFactory->createFrameworkSorter();
+ frameworkSorters[name] = frameworkSorterFactory();
}
if (roleSorter->count() == 0) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/8b87d477/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index e468b5a..cfd937b 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -62,45 +62,19 @@ class OfferFilter;
class InverseOfferFilter;
-// A level of indirection that allows us to keep the allocator implementation
-// in an implementation file: `hierarchical.cpp`. This maps the static
-// templatization of `HierarchicalAllocatorProcess` to a polymorphic
-// implementation in the internal namespace.
-struct SorterFactoryBase
-{
- virtual ~SorterFactoryBase() {}
-
- virtual Sorter* createRoleSorter() const = 0;
-
- virtual Sorter* createFrameworkSorter() const = 0;
-};
-
-
-template <typename RoleSorter, typename FrameworkSorter>
-struct SorterFactory : public SorterFactoryBase
-{
- virtual Sorter* createRoleSorter() const
- {
- return new RoleSorter();
- }
-
- virtual Sorter* createFrameworkSorter() const
- {
- return new FrameworkSorter();
- }
-};
-
-
// Implements the basic allocator algorithm - first pick a role by
// some criteria, then pick one of their frameworks to allocate to.
class HierarchicalAllocatorProcess : public MesosAllocatorProcess
{
public:
- HierarchicalAllocatorProcess(SorterFactoryBase* _sorterFactory)
+ HierarchicalAllocatorProcess(
+ const std::function<Sorter*()>& _roleSorterFactory,
+ const std::function<Sorter*()>& _frameworkSorterFactory)
: ProcessBase(process::ID::generate("hierarchical-allocator")),
initialized(false),
metrics(*this),
- sorterFactory(_sorterFactory),
+ roleSorterFactory(_roleSorterFactory),
+ frameworkSorterFactory(_frameworkSorterFactory),
roleSorter(NULL) {}
virtual ~HierarchicalAllocatorProcess() {}
@@ -386,7 +360,8 @@ protected:
// resources as regular resources when doing fairness calculations.
// TODO(vinod): Consider using a different fairness algorithm for
// oversubscribed resources.
- SorterFactoryBase* sorterFactory;
+ const std::function<Sorter*()> roleSorterFactory;
+ const std::function<Sorter*()> frameworkSorterFactory;
Sorter* roleSorter;
hashmap<std::string, Sorter*> frameworkSorters;
};
@@ -396,7 +371,7 @@ protected:
// We map the templatized version of the `HierarchicalAllocatorProcess` to one
-// that relies on polymorphic sorters in the internal namespace. This allows us
+// that relies on sorter factories in the internal namespace. This allows us
// to keep the implemention of the allocator in the implementation file.
template <typename RoleSorter, typename FrameworkSorter>
class HierarchicalAllocatorProcess
@@ -405,7 +380,8 @@ class HierarchicalAllocatorProcess
public:
HierarchicalAllocatorProcess()
: internal::HierarchicalAllocatorProcess(
- new internal::SorterFactory<RoleSorter, FrameworkSorter>()) {}
+ []() -> Sorter* { return new RoleSorter(); },
+ []() -> Sorter* { return new FrameworkSorter(); }) {}
};