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 
42 
43 namespace mesos {
44 namespace allocator {
45 
49 struct Options
50 {
52 
53  // Resources (by name) that will be excluded from a role's fair share.
55 
56  // Filter GPU resources based on the `GPU_RESOURCES` framework capability.
57  bool filterGpuResources = true;
58 
59  // The master's domain, if any.
61 
62  // The minimum allocatable resource quantities, if any.
65 
67 
69 };
70 
71 
83 class Allocator
84 {
85 public:
96  static Try<Allocator*> create(
97  const std::string& name,
98  const std::string& roleSorter,
99  const std::string& frameworkSorter);
100 
102 
103  virtual ~Allocator() {}
104 
119  virtual void initialize(
120  const Options& options,
121  const lambda::function<
122  void(const FrameworkID&,
123  const hashmap<std::string, hashmap<SlaveID, Resources>>&)>&
124  offerCallback,
125  const lambda::function<
126  void(const FrameworkID&,
128  inverseOfferCallback) = 0;
129 
143  virtual void recover(
144  const int expectedAgentCount,
145  const hashmap<std::string, Quota>& quotas) = 0;
146 
161  virtual void addFramework(
162  const FrameworkID& frameworkId,
163  const FrameworkInfo& frameworkInfo,
165  bool active,
166  const std::set<std::string>& suppressedRoles) = 0;
167 
173  virtual void removeFramework(
174  const FrameworkID& frameworkId) = 0;
175 
180  virtual void activateFramework(
181  const FrameworkID& frameworkId) = 0;
182 
187  virtual void deactivateFramework(
188  const FrameworkID& frameworkId) = 0;
189 
200  virtual void updateFramework(
201  const FrameworkID& frameworkId,
202  const FrameworkInfo& frameworkInfo,
203  const std::set<std::string>& suppressedRoles) = 0;
204 
220  virtual void addSlave(
221  const SlaveID& slaveId,
222  const SlaveInfo& slaveInfo,
223  const std::vector<SlaveInfo::Capability>& capabilities,
225  const Resources& total,
226  const hashmap<FrameworkID, Resources>& used) = 0;
227 
232  virtual void removeSlave(
233  const SlaveID& slaveId) = 0;
234 
244  virtual void updateSlave(
245  const SlaveID& slave,
246  const SlaveInfo& slaveInfo,
247  const Option<Resources>& total = None(),
248  const Option<std::vector<SlaveInfo::Capability>>&
249  capabilities = None()) = 0;
250 
259  virtual void addResourceProvider(
260  const SlaveID& slave,
261  const Resources& total,
262  const hashmap<FrameworkID, Resources>& used) = 0;
263 
268  virtual void activateSlave(
269  const SlaveID& slaveId) = 0;
270 
279  virtual void deactivateSlave(
280  const SlaveID& slaveId) = 0;
281 
290  virtual void updateWhitelist(
291  const Option<hashset<std::string>>& whitelist) = 0;
292 
300  virtual void requestResources(
301  const FrameworkID& frameworkId,
302  const std::vector<Request>& requests) = 0;
303 
314  virtual void updateAllocation(
315  const FrameworkID& frameworkId,
316  const SlaveID& slaveId,
317  const Resources& offeredResources,
318  const std::vector<ResourceConversion>& conversions) = 0;
319 
327  virtual process::Future<Nothing> updateAvailable(
328  const SlaveID& slaveId,
329  const std::vector<Offer::Operation>& operations) = 0;
330 
339  virtual void updateUnavailability(
340  const SlaveID& slaveId,
341  const Option<Unavailability>& unavailability) = 0;
342 
361  virtual void updateInverseOffer(
362  const SlaveID& slaveId,
363  const FrameworkID& frameworkId,
364  const Option<UnavailableResources>& unavailableResources,
366  const Option<Filters>& filters = None()) = 0;
367 
371  virtual process::Future<
372  hashmap<SlaveID,
374  getInverseOfferStatuses() = 0;
375 
389  virtual void recoverResources(
390  const FrameworkID& frameworkId,
391  const SlaveID& slaveId,
392  const Resources& resources,
393  const Option<Filters>& filters) = 0;
394 
402  virtual void suppressOffers(
403  const FrameworkID& frameworkId,
404  const std::set<std::string>& roles) = 0;
405 
413  virtual void reviveOffers(
414  const FrameworkID& frameworkId,
415  const std::set<std::string>& roles) = 0;
416 
435  virtual void setQuota(
436  const std::string& role,
437  const Quota& quota) = 0;
438 
453  virtual void removeQuota(
454  const std::string& role) = 0;
455 
461  virtual void updateWeights(
462  const std::vector<WeightInfo>& weightInfos) = 0;
463 
467  virtual void pause() = 0;
468 
472  virtual void resume() = 0;
473 };
474 
475 } // namespace allocator {
476 } // namespace mesos {
477 
478 #endif // __MESOS_MASTER_ALLOCATOR_HPP__
Allocator()
Definition: allocator.hpp:101
Protocol< RecoverRequest, RecoverResponse > recover
Definition: option.hpp:28
Definition: check.hpp:33
virtual ~Allocator()
Definition: allocator.hpp:103
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: resources.hpp:83
Pass in configuration to the allocator.
Definition: allocator.hpp:49
Definition: duration.hpp:32
Definition: hashmap.hpp:38
Option< DomainInfo > domain
Definition: allocator.hpp:60
Definition: quota.hpp:25
Try< Nothing > unavailability(const Unavailability &unavailability)
Try< Bytes > used(const std::string &path="/")
Definition: fs.hpp:43
Try< Nothing > initialize(const Flags &flags)
Initialized state for support of systemd functions in this file.
Result< std::vector< Filter< Classifier > > > filters(const std::string &_link, const Handle &parent)
Definition: internal.hpp:769
Definition: duration.hpp:207
Definition: spec.hpp:26
bool filterGpuResources
Definition: allocator.hpp:57
Basic model of an allocator: resources are allocated to a framework in the form of offers...
Definition: allocator.hpp:83
Definition: none.hpp:27
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Option< std::vector< mesos::internal::ResourceQuantities > > minAllocatableResources
Definition: allocator.hpp:64
size_t maxCompletedFrameworks
Definition: allocator.hpp:66
Option< std::set< std::string > > fairnessExcludeResourceNames
Definition: allocator.hpp:54
bool publishPerFrameworkMetrics
Definition: allocator.hpp:68
constexpr const char * name
Definition: shell.hpp:43
Duration allocationInterval
Definition: allocator.hpp:51