Repository: mesos Updated Branches: refs/heads/master c0bf80e2b -> 11105f7c0
Updated the allocator to take framework's resources by SlaveID. Review: https://reviews.apache.org/r/31666 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/11105f7c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/11105f7c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/11105f7c Branch: refs/heads/master Commit: 11105f7c009e186ae3e47ff8987671ab5078de7b Parents: c0bf80e Author: Michael Park <[email protected]> Authored: Fri Apr 17 16:34:50 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Fri Apr 17 16:34:52 2015 -0700 ---------------------------------------------------------------------- src/master/allocator/allocator.hpp | 2 +- src/master/allocator/mesos/allocator.hpp | 6 +-- src/master/allocator/mesos/hierarchical.hpp | 8 +++- src/master/master.cpp | 5 +-- src/tests/hierarchical_allocator_tests.cpp | 51 ++++++++++++++++-------- src/tests/mesos.hpp | 2 +- 6 files changed, 46 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/master/allocator/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/allocator.hpp b/src/master/allocator/allocator.hpp index 91f8050..5e3e613 100644 --- a/src/master/allocator/allocator.hpp +++ b/src/master/allocator/allocator.hpp @@ -65,7 +65,7 @@ public: virtual void addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used) = 0; + const hashmap<SlaveID, Resources>& used) = 0; virtual void removeFramework( const FrameworkID& frameworkId) = 0; http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/master/allocator/mesos/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp index fb898f1..af27a9b 100644 --- a/src/master/allocator/mesos/allocator.hpp +++ b/src/master/allocator/mesos/allocator.hpp @@ -53,7 +53,7 @@ public: void addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used); + const hashmap<SlaveID, Resources>& used); void removeFramework( const FrameworkID& frameworkId); @@ -130,7 +130,7 @@ public: virtual void addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used) = 0; + const hashmap<SlaveID, Resources>& used) = 0; virtual void removeFramework( const FrameworkID& frameworkId) = 0; @@ -217,7 +217,7 @@ template <typename AllocatorProcess> inline void MesosAllocator<AllocatorProcess>::addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used) + const hashmap<SlaveID, Resources>& used) { process::dispatch( process, http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/master/allocator/mesos/hierarchical.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index 9f9a631..90ac197 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -81,7 +81,7 @@ public: void addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used); + const hashmap<SlaveID, Resources>& used); void removeFramework( const FrameworkID& frameworkId); @@ -295,7 +295,7 @@ void HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::addFramework( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used) + const hashmap<SlaveID, Resources>& used_) { CHECK(initialized); @@ -310,6 +310,10 @@ HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::addFramework( // framework's role. // Update the allocation to this framework. + // TODO(mpark): Once the sorter API is updated to operate on + // 'hashmap<SlaveID, Resources>' rather than 'Resources', update + // the sorters for each slave instead. + Resources used = Resources::sum(used_); roleSorter->allocated(role, used.unreserved()); frameworkSorters[role]->add(used); frameworkSorters[role]->allocated(frameworkId.value(), used); http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index 944a943..e30b951 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -4131,13 +4131,10 @@ void Master::addFramework(Framework* framework) // There should be no offered resources yet! CHECK_EQ(Resources(), framework->totalOfferedResources); - // TODO(mpark): Once the allocator API is updated to operate on - // 'hashmap<SlaveID, Resources>' rather than 'Resources', pass - // 'framework->usedResources' instead. allocator->addFramework( framework->id(), framework->info, - framework->totalUsedResources); + framework->usedResources); // Export framework metrics. http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/tests/hierarchical_allocator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp index 8861bf3..0b564a7 100644 --- a/src/tests/hierarchical_allocator_tests.cpp +++ b/src/tests/hierarchical_allocator_tests.cpp @@ -184,7 +184,8 @@ TEST_F(HierarchicalAllocatorTest, UnreservedDRF) // framework1 will be offered all of slave1's resources since it is // the only framework running so far. FrameworkInfo framework1 = createFrameworkInfo("role1"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -195,7 +196,8 @@ TEST_F(HierarchicalAllocatorTest, UnreservedDRF) // framework1 share = 1 FrameworkInfo framework2 = createFrameworkInfo("role2"); - allocator->addFramework(framework2.id(), framework2, Resources()); + allocator->addFramework( + framework2.id(), framework2, hashmap<SlaveID, Resources>()); // Total cluster resources will become cpus=3, mem=1536: // role1 share = 0.66 (cpus=2, mem=1024) @@ -238,7 +240,8 @@ TEST_F(HierarchicalAllocatorTest, UnreservedDRF) // framework2 share = 1 FrameworkInfo framework3 = createFrameworkInfo("role1"); - allocator->addFramework(framework3.id(), framework3, Resources()); + allocator->addFramework( + framework3.id(), framework3, hashmap<SlaveID, Resources>()); // Total cluster resources will become cpus=10, mem=7680: // role1 share = 0.2 (cpus=2, mem=1024) @@ -264,7 +267,8 @@ TEST_F(HierarchicalAllocatorTest, UnreservedDRF) // framework2 share = 1 FrameworkInfo framework4 = createFrameworkInfo("role1"); - allocator->addFramework(framework4.id(), framework4, Resources()); + allocator->addFramework( + framework4.id(), framework4, hashmap<SlaveID, Resources>()); // Total cluster resources will become cpus=11, mem=8192 // role1 share = 0.63 (cpus=6, mem=5120) @@ -306,7 +310,8 @@ TEST_F(HierarchicalAllocatorTest, ReservedDRF) // framework1 will be offered all of the resources. FrameworkInfo framework1 = createFrameworkInfo("role1"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -314,7 +319,8 @@ TEST_F(HierarchicalAllocatorTest, ReservedDRF) EXPECT_EQ(slave1.resources(), Resources::sum(allocation.get().resources)); FrameworkInfo framework2 = createFrameworkInfo("role2"); - allocator->addFramework(framework2.id(), framework2, Resources()); + allocator->addFramework( + framework2.id(), framework2, hashmap<SlaveID, Resources>()); // framework2 will be allocated the new resoures. SlaveInfo slave2 = createSlaveInfo("cpus:2;mem:512;disk:0"); @@ -342,7 +348,8 @@ TEST_F(HierarchicalAllocatorTest, ReservedDRF) // expect framework3 to receive the next allocation of role1 // resources. FrameworkInfo framework3 = createFrameworkInfo("role1"); - allocator->addFramework(framework3.id(), framework3, Resources()); + allocator->addFramework( + framework3.id(), framework3, hashmap<SlaveID, Resources>()); SlaveInfo slave4 = createSlaveInfo( "cpus(role1):2;mem(role1):1024;disk(role1):0"); @@ -378,7 +385,8 @@ TEST_F(HierarchicalAllocatorTest, CoarseGrained) // resources so that we can test what happens when there are 2 // frameworks and 2 slaves to consider during allocation. FrameworkInfo framework1 = createFrameworkInfo("role1"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -400,7 +408,8 @@ TEST_F(HierarchicalAllocatorTest, CoarseGrained) // Now add the second framework, we expect there to be 2 subsequent // allocations, each framework being allocated a full slave. FrameworkInfo framework2 = createFrameworkInfo("role2"); - allocator->addFramework(framework2.id(), framework2, Resources()); + allocator->addFramework( + framework2.id(), framework2, hashmap<SlaveID, Resources>()); hashmap<FrameworkID, Allocation> allocations; @@ -440,10 +449,12 @@ TEST_F(HierarchicalAllocatorTest, SameShareFairness) hashmap<FrameworkID, Resources> EMPTY; FrameworkInfo framework1 = createFrameworkInfo("*"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); FrameworkInfo framework2 = createFrameworkInfo("*"); - allocator->addFramework(framework2.id(), framework2, Resources()); + allocator->addFramework( + framework2.id(), framework2, hashmap<SlaveID, Resources>()); SlaveInfo slave = createSlaveInfo("cpus:2;mem:1024;disk:0"); allocator->addSlave(slave.id(), slave, slave.resources(), EMPTY); @@ -501,7 +512,8 @@ TEST_F(HierarchicalAllocatorTest, Reservations) // framework1 should get all the resources from slave1, and the // unreserved resources from slave2. FrameworkInfo framework1 = createFrameworkInfo("role1"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -514,7 +526,8 @@ TEST_F(HierarchicalAllocatorTest, Reservations) // framework2 should get all of its reserved resources on slave2. FrameworkInfo framework2 = createFrameworkInfo("role2"); - allocator->addFramework(framework2.id(), framework2, Resources()); + allocator->addFramework( + framework2.id(), framework2, hashmap<SlaveID, Resources>()); allocation = queue.get(); AWAIT_READY(allocation); @@ -542,7 +555,8 @@ TEST_F(HierarchicalAllocatorTest, RecoverResources) // Initially, all the resources are allocated. FrameworkInfo framework1 = createFrameworkInfo("role1"); - allocator->addFramework(framework1.id(), framework1, Resources()); + allocator->addFramework( + framework1.id(), framework1, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -599,7 +613,8 @@ TEST_F(HierarchicalAllocatorTest, Allocatable) initialize(vector<string>{"role1"}); FrameworkInfo framework = createFrameworkInfo("role1"); - allocator->addFramework(framework.id(), framework, Resources()); + allocator->addFramework( + framework.id(), framework, hashmap<SlaveID, Resources>()); hashmap<FrameworkID, Resources> EMPTY; @@ -671,7 +686,8 @@ TEST_F(HierarchicalAllocatorTest, UpdateAllocation) // Initially, all the resources are allocated. FrameworkInfo framework = createFrameworkInfo("role1"); - allocator->addFramework(framework.id(), framework, Resources()); + allocator->addFramework( + framework.id(), framework, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); AWAIT_READY(allocation); @@ -749,7 +765,8 @@ TEST_F(HierarchicalAllocatorTest, Whitelist) allocator->addSlave(slave.id(), slave, slave.resources(), EMPTY); FrameworkInfo framework = createFrameworkInfo("*"); - allocator->addFramework(framework.id(), framework, Resources()); + allocator->addFramework( + framework.id(), framework, hashmap<SlaveID, Resources>()); Future<Allocation> allocation = queue.get(); http://git-wip-us.apache.org/repos/asf/mesos/blob/11105f7c/src/tests/mesos.hpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp index 42e42ac..7744df5 100644 --- a/src/tests/mesos.hpp +++ b/src/tests/mesos.hpp @@ -855,7 +855,7 @@ public: MOCK_METHOD3(addFramework, void( const FrameworkID&, const FrameworkInfo&, - const Resources&)); + const hashmap<SlaveID, Resources>&)); MOCK_METHOD1(removeFramework, void( const FrameworkID&));
