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:
68  static Try<Allocator*> create(
69  const std::string& name,
70  const std::string& roleSorter,
71  const std::string& frameworkSorter);
72 
73  Allocator() {}
74 
75  virtual ~Allocator() {}
76 
91  virtual void initialize(
92  const Duration& allocationInterval,
93  const lambda::function<
94  void(const FrameworkID&,
95  const hashmap<std::string, hashmap<SlaveID, Resources>>&)>&
96  offerCallback,
97  const lambda::function<
98  void(const FrameworkID&,
100  inverseOfferCallback,
101  const Option<std::set<std::string>>&
102  fairnessExcludeResourceNames = None(),
103  bool filterGpuResources = true,
104  const Option<DomainInfo>& domain = None(),
105  const Option<std::vector<Resources>>&
106  minAllocatableResources = None()) = 0;
107 
121  virtual void recover(
122  const int expectedAgentCount,
123  const hashmap<std::string, Quota>& quotas) = 0;
124 
139  virtual void addFramework(
140  const FrameworkID& frameworkId,
141  const FrameworkInfo& frameworkInfo,
142  const hashmap<SlaveID, Resources>& used,
143  bool active,
144  const std::set<std::string>& suppressedRoles) = 0;
145 
151  virtual void removeFramework(
152  const FrameworkID& frameworkId) = 0;
153 
158  virtual void activateFramework(
159  const FrameworkID& frameworkId) = 0;
160 
165  virtual void deactivateFramework(
166  const FrameworkID& frameworkId) = 0;
167 
178  virtual void updateFramework(
179  const FrameworkID& frameworkId,
180  const FrameworkInfo& frameworkInfo,
181  const std::set<std::string>& suppressedRoles) = 0;
182 
198  virtual void addSlave(
199  const SlaveID& slaveId,
200  const SlaveInfo& slaveInfo,
201  const std::vector<SlaveInfo::Capability>& capabilities,
203  const Resources& total,
204  const hashmap<FrameworkID, Resources>& used) = 0;
205 
210  virtual void removeSlave(
211  const SlaveID& slaveId) = 0;
212 
222  virtual void updateSlave(
223  const SlaveID& slave,
224  const SlaveInfo& slaveInfo,
225  const Option<Resources>& total = None(),
226  const Option<std::vector<SlaveInfo::Capability>>&
227  capabilities = None()) = 0;
228 
237  virtual void addResourceProvider(
238  const SlaveID& slave,
239  const Resources& total,
240  const hashmap<FrameworkID, Resources>& used) = 0;
241 
246  virtual void activateSlave(
247  const SlaveID& slaveId) = 0;
248 
257  virtual void deactivateSlave(
258  const SlaveID& slaveId) = 0;
259 
268  virtual void updateWhitelist(
269  const Option<hashset<std::string>>& whitelist) = 0;
270 
278  virtual void requestResources(
279  const FrameworkID& frameworkId,
280  const std::vector<Request>& requests) = 0;
281 
292  virtual void updateAllocation(
293  const FrameworkID& frameworkId,
294  const SlaveID& slaveId,
295  const Resources& offeredResources,
296  const std::vector<ResourceConversion>& conversions) = 0;
297 
306  const SlaveID& slaveId,
307  const std::vector<Offer::Operation>& operations) = 0;
308 
317  virtual void updateUnavailability(
318  const SlaveID& slaveId,
319  const Option<Unavailability>& unavailability) = 0;
320 
339  virtual void updateInverseOffer(
340  const SlaveID& slaveId,
341  const FrameworkID& frameworkId,
342  const Option<UnavailableResources>& unavailableResources,
344  const Option<Filters>& filters = None()) = 0;
345 
349  virtual process::Future<
350  hashmap<SlaveID,
353 
367  virtual void recoverResources(
368  const FrameworkID& frameworkId,
369  const SlaveID& slaveId,
370  const Resources& resources,
371  const Option<Filters>& filters) = 0;
372 
380  virtual void suppressOffers(
381  const FrameworkID& frameworkId,
382  const std::set<std::string>& roles) = 0;
383 
391  virtual void reviveOffers(
392  const FrameworkID& frameworkId,
393  const std::set<std::string>& roles) = 0;
394 
413  virtual void setQuota(
414  const std::string& role,
415  const Quota& quota) = 0;
416 
431  virtual void removeQuota(
432  const std::string& role) = 0;
433 
439  virtual void updateWeights(
440  const std::vector<WeightInfo>& weightInfos) = 0;
441 };
442 
443 } // namespace allocator {
444 } // namespace mesos {
445 
446 #endif // __MESOS_MASTER_ALLOCATOR_HPP__
Allocator()
Definition: allocator.hpp:73
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:75
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
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 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(), const Option< std::vector< Resources >> &minAllocatableResources=None())=0
Initializes the allocator when the master starts up.
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.
Definition: none.hpp:27
virtual void updateWhitelist(const Option< hashset< std::string >> &whitelist)=0
Updates the list of trusted agents.
static Try< Allocator * > create(const std::string &name, const std::string &roleSorter, const std::string &frameworkSorter)
Attempts either to create a built-in DRF allocator or to load an allocator instance from a module usi...
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.