Apache Mesos
allocator.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MESOS_ALLOCATOR_ALLOCATOR_HPP__
18 #define __MESOS_ALLOCATOR_ALLOCATOR_HPP__
19 
20 #include <string>
21 #include <vector>
22 
23 // ONLY USEFUL AFTER RUNNING PROTOC.
24 #include <mesos/allocator/allocator.pb.h>
25 
27 
28 #include <mesos/quota/quota.hpp>
29 
30 #include <mesos/resources.hpp>
31 
32 #include <process/future.hpp>
33 
34 #include <stout/duration.hpp>
35 #include <stout/hashmap.hpp>
36 #include <stout/hashset.hpp>
37 #include <stout/lambda.hpp>
38 #include <stout/option.hpp>
39 #include <stout/try.hpp>
40 
41 namespace mesos {
42 namespace allocator {
43 
55 class Allocator
56 {
57 public:
65  static Try<Allocator*> create(const std::string& name);
66 
67  Allocator() {}
68 
69  virtual ~Allocator() {}
70 
85  virtual void initialize(
86  const Duration& allocationInterval,
87  const lambda::function<
88  void(const FrameworkID&,
89  const hashmap<std::string, hashmap<SlaveID, Resources>>&)>&
90  offerCallback,
91  const lambda::function<
92  void(const FrameworkID&,
94  inverseOfferCallback,
95  const Option<std::set<std::string>>&
96  fairnessExcludeResourceNames = None(),
97  bool filterGpuResources = true,
98  const Option<DomainInfo>& domain = None()) = 0;
99 
113  virtual void recover(
114  const int expectedAgentCount,
115  const hashmap<std::string, Quota>& quotas) = 0;
116 
131  virtual void addFramework(
132  const FrameworkID& frameworkId,
133  const FrameworkInfo& frameworkInfo,
134  const hashmap<SlaveID, Resources>& used,
135  bool active,
136  const std::set<std::string>& suppressedRoles) = 0;
137 
143  virtual void removeFramework(
144  const FrameworkID& frameworkId) = 0;
145 
150  virtual void activateFramework(
151  const FrameworkID& frameworkId) = 0;
152 
157  virtual void deactivateFramework(
158  const FrameworkID& frameworkId) = 0;
159 
170  virtual void updateFramework(
171  const FrameworkID& frameworkId,
172  const FrameworkInfo& frameworkInfo,
173  const std::set<std::string>& suppressedRoles) = 0;
174 
190  virtual void addSlave(
191  const SlaveID& slaveId,
192  const SlaveInfo& slaveInfo,
193  const std::vector<SlaveInfo::Capability>& capabilities,
195  const Resources& total,
196  const hashmap<FrameworkID, Resources>& used) = 0;
197 
202  virtual void removeSlave(
203  const SlaveID& slaveId) = 0;
204 
214  virtual void updateSlave(
215  const SlaveID& slave,
216  const SlaveInfo& slaveInfo,
217  const Option<Resources>& total = None(),
218  const Option<std::vector<SlaveInfo::Capability>>&
219  capabilities = None()) = 0;
220 
229  virtual void addResourceProvider(
230  const SlaveID& slave,
231  const Resources& total,
232  const hashmap<FrameworkID, Resources>& used) = 0;
233 
238  virtual void activateSlave(
239  const SlaveID& slaveId) = 0;
240 
249  virtual void deactivateSlave(
250  const SlaveID& slaveId) = 0;
251 
260  virtual void updateWhitelist(
261  const Option<hashset<std::string>>& whitelist) = 0;
262 
270  virtual void requestResources(
271  const FrameworkID& frameworkId,
272  const std::vector<Request>& requests) = 0;
273 
284  virtual void updateAllocation(
285  const FrameworkID& frameworkId,
286  const SlaveID& slaveId,
287  const Resources& offeredResources,
288  const std::vector<ResourceConversion>& conversions) = 0;
289 
298  const SlaveID& slaveId,
299  const std::vector<Offer::Operation>& operations) = 0;
300 
309  virtual void updateUnavailability(
310  const SlaveID& slaveId,
311  const Option<Unavailability>& unavailability) = 0;
312 
331  virtual void updateInverseOffer(
332  const SlaveID& slaveId,
333  const FrameworkID& frameworkId,
334  const Option<UnavailableResources>& unavailableResources,
336  const Option<Filters>& filters = None()) = 0;
337 
341  virtual process::Future<
342  hashmap<SlaveID,
345 
359  virtual void recoverResources(
360  const FrameworkID& frameworkId,
361  const SlaveID& slaveId,
362  const Resources& resources,
363  const Option<Filters>& filters) = 0;
364 
372  virtual void suppressOffers(
373  const FrameworkID& frameworkId,
374  const std::set<std::string>& roles) = 0;
375 
383  virtual void reviveOffers(
384  const FrameworkID& frameworkId,
385  const std::set<std::string>& roles) = 0;
386 
405  virtual void setQuota(
406  const std::string& role,
407  const Quota& quota) = 0;
408 
423  virtual void removeQuota(
424  const std::string& role) = 0;
425 
431  virtual void updateWeights(
432  const std::vector<WeightInfo>& weightInfos) = 0;
433 };
434 
435 } // namespace allocator {
436 } // namespace mesos {
437 
438 #endif // __MESOS_MASTER_ALLOCATOR_HPP__
Allocator()
Definition: allocator.hpp:67
virtual void recoverResources(const FrameworkID &frameworkId, const SlaveID &slaveId, const Resources &resources, const Option< Filters > &filters)=0
Recovers resources.
virtual void removeQuota(const std::string &role)=0
Informs the allocator to remove quota for the given role.
virtual void addResourceProvider(const SlaveID &slave, const Resources &total, const hashmap< FrameworkID, Resources > &used)=0
Add resources from a local resource provider to an agent.
Definition: option.hpp:28
Definition: check.hpp:33
virtual ~Allocator()
Definition: allocator.hpp:69
virtual void activateSlave(const SlaveID &slaveId)=0
Activates an agent.
virtual void updateAllocation(const FrameworkID &frameworkId, const SlaveID &slaveId, const Resources &offeredResources, const std::vector< ResourceConversion > &conversions)=0
Updates allocation by applying offer operations.
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
virtual void initialize(const Duration &allocationInterval, const lambda::function< void(const FrameworkID &, const hashmap< std::string, hashmap< SlaveID, Resources >> &)> &offerCallback, const lambda::function< void(const FrameworkID &, const hashmap< SlaveID, UnavailableResources > &)> &inverseOfferCallback, const Option< std::set< std::string >> &fairnessExcludeResourceNames=None(), bool filterGpuResources=true, const Option< DomainInfo > &domain=None())=0
Initializes the allocator when the master starts up.
Definition: resources.hpp:79
virtual void reviveOffers(const FrameworkID &frameworkId, const std::set< std::string > &roles)=0
Revives offers to this framework for the specified roles.
virtual process::Future< hashmap< SlaveID, hashmap< FrameworkID, mesos::allocator::InverseOfferStatus > > > getInverseOfferStatuses()=0
Retrieves the status of all inverse offers maintained by the allocator.
Definition: duration.hpp:32
virtual void deactivateFramework(const FrameworkID &frameworkId)=0
Deactivates a framework in the Mesos cluster.
virtual void addFramework(const FrameworkID &frameworkId, const FrameworkInfo &frameworkInfo, const hashmap< SlaveID, Resources > &used, bool active, const std::set< std::string > &suppressedRoles)=0
Adds a framework to the Mesos cluster.
Definition: hashmap.hpp:38
virtual void updateWeights(const std::vector< WeightInfo > &weightInfos)=0
Updates the weight associated with one or more roles.
virtual void removeSlave(const SlaveID &slaveId)=0
Removes an agent from the Mesos cluster.
Definition: quota.hpp:25
Try< Nothing > unavailability(const Unavailability &unavailability)
virtual void activateFramework(const FrameworkID &frameworkId)=0
Activates a framework in the Mesos cluster.
Result< std::vector< Filter< Classifier > > > filters(const std::string &_link, const Handle &parent)
Definition: internal.hpp:776
virtual void updateFramework(const FrameworkID &frameworkId, const FrameworkInfo &frameworkInfo, const std::set< std::string > &suppressedRoles)=0
Updates capabilities of a framework in the Mesos cluster.
virtual void setQuota(const std::string &role, const Quota &quota)=0
Informs the allocator to set quota for the given role.
Definition: spec.hpp:30
virtual void removeFramework(const FrameworkID &frameworkId)=0
Removes a framework from the Mesos cluster.
virtual void updateUnavailability(const SlaveID &slaveId, const Option< Unavailability > &unavailability)=0
Updates unavailability for an agent.
virtual void addSlave(const SlaveID &slaveId, const SlaveInfo &slaveInfo, const std::vector< SlaveInfo::Capability > &capabilities, const Option< Unavailability > &unavailability, const Resources &total, const hashmap< FrameworkID, Resources > &used)=0
Adds or re-adds an agent to the Mesos cluster.
Basic model of an allocator: resources are allocated to a framework in the form of offers...
Definition: allocator.hpp:55
virtual void deactivateSlave(const SlaveID &slaveId)=0
Deactivates an agent.
static Try< Allocator * > create(const std::string &name)
Attempts either to create a built-in DRF allocator or to load an allocator instance from a module usi...
Definition: none.hpp:27
virtual void updateWhitelist(const Option< hashset< std::string >> &whitelist)=0
Updates the list of trusted agents.
virtual void requestResources(const FrameworkID &frameworkId, const std::vector< Request > &requests)=0
Requests resources for a framework.
virtual void recover(const int expectedAgentCount, const hashmap< std::string, Quota > &quotas)=0
Informs the allocator of the recovered state from the master.
virtual void suppressOffers(const FrameworkID &frameworkId, const std::set< std::string > &roles)=0
Suppresses offers.
virtual process::Future< Nothing > updateAvailable(const SlaveID &slaveId, const std::vector< Offer::Operation > &operations)=0
Updates available resources on an agent based on a sequence of offer operations.
constexpr const char * name
Definition: shell.hpp:43
virtual void updateInverseOffer(const SlaveID &slaveId, const FrameworkID &frameworkId, const Option< UnavailableResources > &unavailableResources, const Option< InverseOfferStatus > &status, const Option< Filters > &filters=None())=0
Updates inverse offer.
virtual void updateSlave(const SlaveID &slave, const SlaveInfo &slaveInfo, const Option< Resources > &total=None(), const Option< std::vector< SlaveInfo::Capability >> &capabilities=None())=0
Updates an agent.