Updated allocator.hpp to idiomatically use the "Process wrapper" pattern.
Review: https://reviews.apache.org/r/28666 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/219fa4bc Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/219fa4bc Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/219fa4bc Branch: refs/heads/master Commit: 219fa4bc2ae96d6e90cffdbacde782db6987271d Parents: 31317b3 Author: Benjamin Mahler <[email protected]> Authored: Tue Dec 2 18:17:28 2014 -0800 Committer: Benjamin Mahler <[email protected]> Committed: Wed Dec 3 15:02:04 2014 -0800 ---------------------------------------------------------------------- src/master/allocator.hpp | 146 +++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 73 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/219fa4bc/src/master/allocator.hpp ---------------------------------------------------------------------- diff --git a/src/master/allocator.hpp b/src/master/allocator.hpp index 04eb2a3..b8c5286 100644 --- a/src/master/allocator.hpp +++ b/src/master/allocator.hpp @@ -44,154 +44,154 @@ class Master; // Forward declaration. namespace allocator { +class AllocatorProcess; // Forward declaration. + // Basic model of an allocator: resources are allocated to a framework // in the form of offers. A framework can refuse some resources in // offers and run tasks in others. Resources can be recovered from a // framework when tasks finish/fail (or are lost due to a slave // failure) or when an offer is rescinded. -// NOTE: New Allocators should implement this interface. -class AllocatorProcess : public process::Process<AllocatorProcess> +// +// NOTE: DO NOT subclass this class when implementing a new allocator. +// Implement AllocatorProcess (above) instead! +class Allocator { public: - AllocatorProcess() {} + // The AllocatorProcess object passed to the constructor is spawned + // and terminated by the allocator. But it is the responsibility + // of the caller to de-allocate the object, if necessary. + explicit Allocator(AllocatorProcess* _process); - virtual ~AllocatorProcess() {} + virtual ~Allocator(); - virtual void initialize( + void initialize( const Flags& flags, const process::PID<Master>& master, - const hashmap<std::string, RoleInfo>& roles) = 0; + const hashmap<std::string, RoleInfo>& roles); - virtual void frameworkAdded( + void frameworkAdded( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used) = 0; + const Resources& used); - virtual void frameworkRemoved( - const FrameworkID& frameworkId) = 0; + void frameworkRemoved( + const FrameworkID& frameworkId); - virtual void frameworkActivated( + void frameworkActivated( const FrameworkID& frameworkId, - const FrameworkInfo& frameworkInfo) = 0; + const FrameworkInfo& frameworkInfo); - virtual void frameworkDeactivated( - const FrameworkID& frameworkId) = 0; + void frameworkDeactivated( + const FrameworkID& frameworkId); // Note that the 'total' resources are passed explicitly because it // includes resources that are dynamically "persisted" on the slave // (e.g. persistent volumes, dynamic reservations, etc). // The slaveInfo resources, on the other hand, correspond directly // to the static --resources flag value on the slave. - virtual void slaveAdded( + void slaveAdded( const SlaveID& slaveId, const SlaveInfo& slaveInfo, const Resources& total, - const hashmap<FrameworkID, Resources>& used) = 0; + const hashmap<FrameworkID, Resources>& used); - virtual void slaveRemoved( - const SlaveID& slaveId) = 0; + void slaveRemoved( + const SlaveID& slaveId); // No longer offers resources for the deactivated slave. - virtual void slaveDeactivated( - const SlaveID& slaveId) = 0; + void slaveDeactivated( + const SlaveID& slaveId); // Offers resources for the activated slave. - virtual void slaveActivated( - const SlaveID& slaveId) = 0; + void slaveActivated( + const SlaveID& slaveId); - virtual void updateWhitelist( - const Option<hashset<std::string> >& whitelist) = 0; + void updateWhitelist( + const Option<hashset<std::string> >& whitelist); - virtual void resourcesRequested( + void resourcesRequested( const FrameworkID& frameworkId, - const std::vector<Request>& requests) = 0; + const std::vector<Request>& requests); // Whenever resources are "recovered" in the cluster (e.g., a task // finishes, an offer is removed because a framework has failed or - // is failing over), or a framework refuses them, the master - // invokes this callback. - virtual void resourcesRecovered( + // is failing over), or a framework refuses them. + void resourcesRecovered( const FrameworkID& frameworkId, const SlaveID& slaveId, const Resources& resources, - const Option<Filters>& filters) = 0; + const Option<Filters>& filters); // Whenever a framework that has filtered resources wants to revive // offers for those resources the master invokes this callback. - virtual void offersRevived( - const FrameworkID& frameworkId) = 0; + void offersRevived( + const FrameworkID& frameworkId); + +private: + Allocator(const Allocator&); // Not copyable. + Allocator& operator=(const Allocator&); // Not assignable. + + AllocatorProcess* process; }; -// This is a wrapper around the AllocatorProcess interface. -// NOTE: DO NOT subclass this class when implementing a new allocator. -// Implement AllocatorProcess (above) instead! -class Allocator +class AllocatorProcess : public process::Process<AllocatorProcess> { public: - // The AllocatorProcess object passed to the constructor is - // spawned and terminated by the allocator. But it is the responsibility - // of the caller to de-allocate the object, if necessary. - explicit Allocator(AllocatorProcess* _process); + AllocatorProcess() {} - virtual ~Allocator(); + virtual ~AllocatorProcess() {} - void initialize( + virtual void initialize( const Flags& flags, const process::PID<Master>& master, - const hashmap<std::string, RoleInfo>& roles); + const hashmap<std::string, RoleInfo>& roles) = 0; - void frameworkAdded( + virtual void frameworkAdded( const FrameworkID& frameworkId, const FrameworkInfo& frameworkInfo, - const Resources& used); + const Resources& used) = 0; - void frameworkRemoved( - const FrameworkID& frameworkId); + virtual void frameworkRemoved( + const FrameworkID& frameworkId) = 0; - void frameworkActivated( + virtual void frameworkActivated( const FrameworkID& frameworkId, - const FrameworkInfo& frameworkInfo); + const FrameworkInfo& frameworkInfo) = 0; - void frameworkDeactivated( - const FrameworkID& frameworkId); + virtual void frameworkDeactivated( + const FrameworkID& frameworkId) = 0; - void slaveAdded( + virtual void slaveAdded( const SlaveID& slaveId, const SlaveInfo& slaveInfo, const Resources& total, - const hashmap<FrameworkID, Resources>& used); + const hashmap<FrameworkID, Resources>& used) = 0; - void slaveRemoved( - const SlaveID& slaveId); + virtual void slaveRemoved( + const SlaveID& slaveId) = 0; - void slaveDeactivated( - const SlaveID& slaveId); + virtual void slaveDeactivated( + const SlaveID& slaveId) = 0; - void slaveActivated( - const SlaveID& slaveId); + virtual void slaveActivated( + const SlaveID& slaveId) = 0; - void updateWhitelist( - const Option<hashset<std::string> >& whitelist); + virtual void updateWhitelist( + const Option<hashset<std::string> >& whitelist) = 0; - void resourcesRequested( + virtual void resourcesRequested( const FrameworkID& frameworkId, - const std::vector<Request>& requests); + const std::vector<Request>& requests) = 0; - void resourcesRecovered( + virtual void resourcesRecovered( const FrameworkID& frameworkId, const SlaveID& slaveId, const Resources& resources, - const Option<Filters>& filters); - - void offersRevived( - const FrameworkID& frameworkId); - -private: - Allocator(const Allocator&); // Not copyable. - Allocator& operator=(const Allocator&); // Not assignable. + const Option<Filters>& filters) = 0; - AllocatorProcess* process; + virtual void offersRevived( + const FrameworkID& frameworkId) = 0; };
