Maintenance Primitives: Added updateInverseOffer to Allocator. Review: https://reviews.apache.org/r/37280
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/42f9ce5d Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/42f9ce5d Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/42f9ce5d Branch: refs/heads/master Commit: 42f9ce5d61bf3e2c48d6a3de86d2e3e5cd3f6b57 Parents: 6c568ba Author: Joris Van Remoortere <[email protected]> Authored: Sun Aug 30 14:23:51 2015 -0400 Committer: Joris Van Remoortere <[email protected]> Committed: Mon Sep 14 13:58:37 2015 -0400 ---------------------------------------------------------------------- include/mesos/master/allocator.hpp | 10 +++++ src/master/allocator/mesos/allocator.hpp | 25 ++++++++++++ src/master/allocator/mesos/hierarchical.hpp | 50 ++++++++++++++++++++++++ src/tests/mesos.hpp | 16 ++++++++ 4 files changed, 101 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/42f9ce5d/include/mesos/master/allocator.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp index 18d31ef..fb09e2a 100644 --- a/include/mesos/master/allocator.hpp +++ b/include/mesos/master/allocator.hpp @@ -149,6 +149,16 @@ public: const SlaveID& slaveId, const Option<Unavailability>& unavailability) = 0; + // Informs the allocator that the inverse offer has been responded to or + // revoked. If `status` is not set then the inverse offer was not responded + // to, possibly because the offer timed out or was rescinded. This might + // require the implementation of the function to remove any inverse offers + // that are outstanding. + virtual void updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<InverseOfferStatus>& status) = 0; + // Informs the Allocator to recover resources that are considered // used by the framework. virtual void recoverResources( http://git-wip-us.apache.org/repos/asf/mesos/blob/42f9ce5d/src/master/allocator/mesos/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp index 124dd3d..171548b 100644 --- a/src/master/allocator/mesos/allocator.hpp +++ b/src/master/allocator/mesos/allocator.hpp @@ -116,6 +116,11 @@ public: const SlaveID& slaveId, const Option<Unavailability>& unavailability); + void updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<mesos::master::InverseOfferStatus>& status); + void recoverResources( const FrameworkID& frameworkId, const SlaveID& slaveId, @@ -215,6 +220,11 @@ public: const SlaveID& slaveId, const Option<Unavailability>& unavailability) = 0; + virtual void updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<mesos::master::InverseOfferStatus>& status) = 0; + virtual void recoverResources( const FrameworkID& frameworkId, const SlaveID& slaveId, @@ -467,6 +477,21 @@ inline void MesosAllocator<AllocatorProcess>::updateUnavailability( template <typename AllocatorProcess> +inline void MesosAllocator<AllocatorProcess>::updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<mesos::master::InverseOfferStatus>& status) +{ + return process::dispatch( + process, + &MesosAllocatorProcess::updateInverseOffer, + slaveId, + frameworkId, + status); +} + + +template <typename AllocatorProcess> inline void MesosAllocator<AllocatorProcess>::recoverResources( const FrameworkID& frameworkId, const SlaveID& slaveId, http://git-wip-us.apache.org/repos/asf/mesos/blob/42f9ce5d/src/master/allocator/mesos/hierarchical.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index 8ae7475..8e3ec9c 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -154,6 +154,11 @@ public: const SlaveID& slaveId, const Option<Unavailability>& unavailability); + void updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<mesos::master::InverseOfferStatus>& status); + void recoverResources( const FrameworkID& frameworkId, const SlaveID& slaveId, @@ -861,6 +866,51 @@ HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::updateUnavailability( template <class RoleSorter, class FrameworkSorter> void +HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::updateInverseOffer( + const SlaveID& slaveId, + const FrameworkID& frameworkId, + const Option<mesos::master::InverseOfferStatus>& status) +{ + CHECK(initialized); + CHECK(frameworks.contains(frameworkId)); + CHECK(slaves.contains(slaveId)); + CHECK(slaves[slaveId].maintenance.isSome()); + + // NOTE: We currently implement maintenance in the allocator to be able to + // leverage state and features such as the FrameworkSorter and Filters. + + // We use a reference by alias because we intend to modify the + // `maintenance` and to improve readability. + typename Slave::Maintenance& maintenance = slaves[slaveId].maintenance.get(); + + // Only handle inverse offers that we currently have outstanding. If it is not + // currently outstanding this means it is old and can be safely ignored. + if (maintenance.offersOutstanding.contains(frameworkId)) { + + // We always remove the outstanding offer so that we will send a new offer + // out the next time we schedule inverse offers. + maintenance.offersOutstanding.erase(frameworkId); + + // If the response is `Some`, this means the framework responded. Otherwise + // if it is `None` the inverse offer timed out or was rescinded. + if (status.isSome()) { + // For now we don't allow frameworks to respond with `UNKNOWN`. The caller + // should guard against this. This goes against the pattern of not + // checking external invariants; however, the allocator and master are + // currently so tightly coupled that this check is valuable. + CHECK_NE( + status.get().status(), + mesos::master::InverseOfferStatus::UNKNOWN); + + // If the framework responded, we update our state to match. + maintenance.statuses[frameworkId].CopyFrom(status.get()); + } + } +} + + +template <class RoleSorter, class FrameworkSorter> +void HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::recoverResources( const FrameworkID& frameworkId, const SlaveID& slaveId, http://git-wip-us.apache.org/repos/asf/mesos/blob/42f9ce5d/src/tests/mesos.hpp ---------------------------------------------------------------------- diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp index 858618f..3db97ac 100644 --- a/src/tests/mesos.hpp +++ b/src/tests/mesos.hpp @@ -1359,6 +1359,12 @@ ACTION_P(InvokeUpdateUnavailability, allocator) } +ACTION_P(InvokeUpdateInverseOffer, allocator) +{ + return allocator->real->updateInverseOffer(arg0, arg1, arg2); +} + + ACTION_P(InvokeRecoverResources, allocator) { allocator->real->recoverResources(arg0, arg1, arg2, arg3); @@ -1487,6 +1493,11 @@ public: EXPECT_CALL(*this, updateUnavailability(_, _)) .WillRepeatedly(DoDefault()); + ON_CALL(*this, updateInverseOffer(_, _, _)) + .WillByDefault(InvokeUpdateInverseOffer(this)); + EXPECT_CALL(*this, updateInverseOffer(_, _, _)) + .WillRepeatedly(DoDefault()); + ON_CALL(*this, recoverResources(_, _, _, _)) .WillByDefault(InvokeRecoverResources(this)); EXPECT_CALL(*this, recoverResources(_, _, _, _)) @@ -1568,6 +1579,11 @@ public: const SlaveID&, const Option<Unavailability>&)); + MOCK_METHOD3(updateInverseOffer, void( + const SlaveID&, + const FrameworkID&, + const Option<mesos::master::InverseOfferStatus>&)); + MOCK_METHOD4(recoverResources, void( const FrameworkID&, const SlaveID&,
