You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/12/11 23:55:46 UTC

[09/11] mesos git commit: Updated the allocator interface to enable unit testing.

Updated the allocator interface to enable unit testing.

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


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

Branch: refs/heads/master
Commit: e72037f3459d40412a5f677f7c3d5edc2bb7a033
Parents: 300327f
Author: Benjamin Mahler <be...@gmail.com>
Authored: Fri Dec 5 12:38:15 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Dec 11 14:40:30 2014 -0800

----------------------------------------------------------------------
 src/master/allocator.hpp                      | 15 +++++++++++----
 src/master/hierarchical_allocator_process.hpp | 22 ++++++++++++++--------
 src/master/master.cpp                         |  5 ++++-
 src/tests/mesos.hpp                           |  4 +++-
 4 files changed, 32 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e72037f3/src/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator.hpp b/src/master/allocator.hpp
index 0849ac8..f4068aa 100644
--- a/src/master/allocator.hpp
+++ b/src/master/allocator.hpp
@@ -30,6 +30,7 @@
 
 #include <stout/hashmap.hpp>
 #include <stout/hashset.hpp>
+#include <stout/lambda.hpp>
 #include <stout/option.hpp>
 
 #include "master/flags.hpp"
@@ -66,7 +67,9 @@ public:
 
   void initialize(
       const Flags& flags,
-      const process::PID<Master>& master,
+      const lambda::function<
+          void(const FrameworkID&,
+               const hashmap<SlaveID, Resources>&)>& offerCallback,
       const hashmap<std::string, RoleInfo>& roles);
 
   void addFramework(
@@ -146,7 +149,9 @@ public:
 
   virtual void initialize(
       const Flags& flags,
-      const process::PID<Master>& master,
+      const lambda::function<
+          void(const FrameworkID&,
+               const hashmap<SlaveID, Resources>&)>& offerCallback,
       const hashmap<std::string, RoleInfo>& roles) = 0;
 
   virtual void addFramework(
@@ -212,14 +217,16 @@ inline Allocator::~Allocator()
 
 inline void Allocator::initialize(
     const Flags& flags,
-    const process::PID<Master>& master,
+    const lambda::function<
+        void(const FrameworkID&,
+             const hashmap<SlaveID, Resources>&)>& offerCallback,
     const hashmap<std::string, RoleInfo>& roles)
 {
   process::dispatch(
       process,
       &AllocatorProcess::initialize,
       flags,
-      master,
+      offerCallback,
       roles);
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/e72037f3/src/master/hierarchical_allocator_process.hpp
----------------------------------------------------------------------
diff --git a/src/master/hierarchical_allocator_process.hpp b/src/master/hierarchical_allocator_process.hpp
index f18346f..70970be 100644
--- a/src/master/hierarchical_allocator_process.hpp
+++ b/src/master/hierarchical_allocator_process.hpp
@@ -71,8 +71,10 @@ public:
 
   void initialize(
       const Flags& flags,
-      const process::PID<Master>& _master,
-      const hashmap<std::string, RoleInfo>& _roles);
+      const lambda::function<
+          void(const FrameworkID&,
+               const hashmap<SlaveID, Resources>&)>& offerCallback,
+      const hashmap<std::string, RoleInfo>& roles);
 
   void addFramework(
       const FrameworkID& frameworkId,
@@ -154,7 +156,10 @@ protected:
   bool initialized;
 
   Flags flags;
-  process::PID<Master> master;
+
+  lambda::function<
+      void(const FrameworkID&,
+           const hashmap<SlaveID, Resources>&)> offerCallback;
 
   struct Framework
   {
@@ -248,11 +253,13 @@ template <class RoleSorter, class FrameworkSorter>
 void
 HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::initialize(
     const Flags& _flags,
-    const process::PID<Master>& _master,
+    const lambda::function<
+        void(const FrameworkID&,
+             const hashmap<SlaveID, Resources>&)>& _offerCallback,
     const hashmap<std::string, RoleInfo>& _roles)
 {
   flags = _flags;
-  master = _master;
+  offerCallback = _offerCallback;
   roles = _roles;
   initialized = true;
 
@@ -262,8 +269,7 @@ HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::initialize(
     sorters[name] = new FrameworkSorter();
   }
 
-  VLOG(1) << "Initializing hierarchical allocator process "
-          << "with master : " << master;
+  VLOG(1) << "Initializing hierarchical allocator process";
 
   delay(flags.allocation_interval, self(), &Self::batch);
 }
@@ -734,7 +740,7 @@ HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::allocate(
 
   // Now offer the resources to each framework.
   foreachkey (const FrameworkID& frameworkId, offerable) {
-    dispatch(master, &Master::offer, frameworkId, offerable[frameworkId]);
+    offerCallback(frameworkId, offerable[frameworkId]);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/e72037f3/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 9936980..0f55a5c 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -456,7 +456,10 @@ void Master::initialize()
   }
 
   // Initialize the allocator.
-  allocator->initialize(flags, self(), roleInfos);
+  allocator->initialize(
+      flags,
+      defer(self(), &Master::offer, lambda::_1, lambda::_2),
+      roleInfos);
 
   // Parse the whitelist. Passing allocator::updateWhitelist()
   // callback is safe because we shut down the whitelistWatcher in

http://git-wip-us.apache.org/repos/asf/mesos/blob/e72037f3/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 90c575e..bb24222 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -734,7 +734,9 @@ public:
 
   MOCK_METHOD3(initialize, void(
       const master::Flags&,
-      const process::PID<master::Master>&,
+      const lambda::function<
+          void(const FrameworkID&,
+               const hashmap<SlaveID, Resources>&)>&,
       const hashmap<std::string, RoleInfo>&));
 
   MOCK_METHOD3(addFramework, void(