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(),
107  const size_t maxCompletedFrameworks = 0) = 0;
108 
122  virtual void recover(
123  const int expectedAgentCount,
124  const hashmap<std::string, Quota>& quotas) = 0;
125 
140  virtual void addFramework(
141  const FrameworkID& frameworkId,
142  const FrameworkInfo& frameworkInfo,
144  bool active,
145  const std::set<std::string>& suppressedRoles) = 0;
146 
152  virtual void removeFramework(
153  const FrameworkID& frameworkId) = 0;
154 
159  virtual void activateFramework(
160  const FrameworkID& frameworkId) = 0;
161 
166  virtual void deactivateFramework(
167  const FrameworkID& frameworkId) = 0;
168 
179  virtual void updateFramework(
180  const FrameworkID& frameworkId,
181  const FrameworkInfo& frameworkInfo,
182  const std::set<std::string>& suppressedRoles) = 0;
183 
199  virtual void addSlave(
200  const SlaveID& slaveId,
201  const SlaveInfo& slaveInfo,
202  const std::vector<SlaveInfo::Capability>& capabilities,
204  const Resources& total,
205  const hashmap<FrameworkID, Resources>& used) = 0;
206 
211  virtual void removeSlave(
212  const SlaveID& slaveId) = 0;
213 
223  virtual void updateSlave(
224  const SlaveID& slave,
225  const SlaveInfo& slaveInfo,
226  const Option<Resources>& total = None(),
227  const Option<std::vector<SlaveInfo::Capability>>&
228  capabilities = None()) = 0;
229 
238  virtual void addResourceProvider(
239  const SlaveID& slave,
240  const Resources& total,
241  const hashmap<FrameworkID, Resources>& used) = 0;
242 
247  virtual void activateSlave(
248  const SlaveID& slaveId) = 0;
249 
258  virtual void deactivateSlave(
259  const SlaveID& slaveId) = 0;
260 
269  virtual void updateWhitelist(
270  const Option<hashset<std::string>>& whitelist) = 0;
271 
279  virtual void requestResources(
280  const FrameworkID& frameworkId,
281  const std::vector<Request>& requests) = 0;
282 
293  virtual void updateAllocation(
294  const FrameworkID& frameworkId,
295  const SlaveID& slaveId,
296  const Resources& offeredResources,
297  const std::vector<ResourceConversion>& conversions) = 0;
298 
307  const SlaveID& slaveId,
308  const std::vector<Offer::Operation>& operations) = 0;
309 
318  virtual void updateUnavailability(
319  const SlaveID& slaveId,
320  const Option<Unavailability>& unavailability) = 0;
321 
340  virtual void updateInverseOffer(
341  const SlaveID& slaveId,
342  const FrameworkID& frameworkId,
343  const Option<UnavailableResources>& unavailableResources,
345  const Option<Filters>& filters = None()) = 0;
346 
350  virtual process::Future<
351  hashmap<SlaveID,
354 
368  virtual void recoverResources(
369  const FrameworkID& frameworkId,
370  const SlaveID& slaveId,
371  const Resources& resources,
372  const Option<Filters>& filters) = 0;
373 
381  virtual void suppressOffers(
382  const FrameworkID& frameworkId,
383  const std::set<std::string>& roles) = 0;
384 
392  virtual void reviveOffers(
393  const FrameworkID& frameworkId,
394  const std::set<std::string>& roles) = 0;
395 
414  virtual void setQuota(
415  const std::string& role,
416  const Quota& quota) = 0;
417 
432  virtual void removeQuota(
433  const std::string& role) = 0;
434 
440  virtual void updateWeights(
441  const std::vector<WeightInfo>& weightInfos) = 0;
442 
446  virtual void pause() = 0;
447 
451  virtual void resume() = 0;
452 };
453 
454 } // namespace allocator {
455 } // namespace mesos {
456 
457 #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 void pause()=0
Idempotent helper to pause allocations.
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:81
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 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(), const size_t maxCompletedFrameworks=0)=0
Initializes the allocator when the master starts up.
virtual void removeSlave(const SlaveID &slaveId)=0
Removes an agent from the Mesos cluster.
Definition: quota.hpp:25
Try< Nothing > unavailability(const Unavailability &unavailability)
Try< Bytes > used(const std::string &path="/")
Definition: fs.hpp:43
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:769
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.
virtual void resume()=0
Idempotent helper to resume allocations.
Definition: spec.hpp:26
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.