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 
31 #include <mesos/resources.hpp>
32 
33 #include <process/future.hpp>
34 
35 #include <stout/duration.hpp>
36 #include <stout/hashmap.hpp>
37 #include <stout/hashset.hpp>
38 #include <stout/lambda.hpp>
39 #include <stout/option.hpp>
40 #include <stout/try.hpp>
41 
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.
64 
66 
68 };
69 
70 
82 class Allocator
83 {
84 public:
95  static Try<Allocator*> create(
96  const std::string& name,
97  const std::string& roleSorter,
98  const std::string& frameworkSorter);
99 
101 
102  virtual ~Allocator() {}
103 
118  virtual void initialize(
119  const Options& options,
120  const lambda::function<
121  void(const FrameworkID&,
122  const hashmap<std::string, hashmap<SlaveID, Resources>>&)>&
123  offerCallback,
124  const lambda::function<
125  void(const FrameworkID&,
127  inverseOfferCallback) = 0;
128 
142  virtual void recover(
143  const int expectedAgentCount,
144  const hashmap<std::string, Quota>& quotas) = 0;
145 
160  virtual void addFramework(
161  const FrameworkID& frameworkId,
162  const FrameworkInfo& frameworkInfo,
164  bool active,
165  const std::set<std::string>& suppressedRoles) = 0;
166 
172  virtual void removeFramework(
173  const FrameworkID& frameworkId) = 0;
174 
179  virtual void activateFramework(
180  const FrameworkID& frameworkId) = 0;
181 
186  virtual void deactivateFramework(
187  const FrameworkID& frameworkId) = 0;
188 
199  virtual void updateFramework(
200  const FrameworkID& frameworkId,
201  const FrameworkInfo& frameworkInfo,
202  const std::set<std::string>& suppressedRoles) = 0;
203 
219  virtual void addSlave(
220  const SlaveID& slaveId,
221  const SlaveInfo& slaveInfo,
222  const std::vector<SlaveInfo::Capability>& capabilities,
224  const Resources& total,
225  const hashmap<FrameworkID, Resources>& used) = 0;
226 
231  virtual void removeSlave(
232  const SlaveID& slaveId) = 0;
233 
243  virtual void updateSlave(
244  const SlaveID& slave,
245  const SlaveInfo& slaveInfo,
246  const Option<Resources>& total = None(),
247  const Option<std::vector<SlaveInfo::Capability>>&
248  capabilities = None()) = 0;
249 
258  virtual void addResourceProvider(
259  const SlaveID& slave,
260  const Resources& total,
261  const hashmap<FrameworkID, Resources>& used) = 0;
262 
267  virtual void activateSlave(
268  const SlaveID& slaveId) = 0;
269 
278  virtual void deactivateSlave(
279  const SlaveID& slaveId) = 0;
280 
289  virtual void updateWhitelist(
290  const Option<hashset<std::string>>& whitelist) = 0;
291 
299  virtual void requestResources(
300  const FrameworkID& frameworkId,
301  const std::vector<Request>& requests) = 0;
302 
313  virtual void updateAllocation(
314  const FrameworkID& frameworkId,
315  const SlaveID& slaveId,
316  const Resources& offeredResources,
317  const std::vector<ResourceConversion>& conversions) = 0;
318 
326  virtual process::Future<Nothing> updateAvailable(
327  const SlaveID& slaveId,
328  const std::vector<Offer::Operation>& operations) = 0;
329 
338  virtual void updateUnavailability(
339  const SlaveID& slaveId,
340  const Option<Unavailability>& unavailability) = 0;
341 
360  virtual void updateInverseOffer(
361  const SlaveID& slaveId,
362  const FrameworkID& frameworkId,
363  const Option<UnavailableResources>& unavailableResources,
365  const Option<Filters>& filters = None()) = 0;
366 
370  virtual process::Future<
371  hashmap<SlaveID,
373  getInverseOfferStatuses() = 0;
374 
379  virtual void transitionOfferedToAllocated(
380  const SlaveID& slaveId, const Resources& resources) = 0;
381 
397  virtual void recoverResources(
398  const FrameworkID& frameworkId,
399  const SlaveID& slaveId,
400  const Resources& resources,
401  const Option<Filters>& filters,
402  bool isAllocated) = 0;
403 
411  virtual void suppressOffers(
412  const FrameworkID& frameworkId,
413  const std::set<std::string>& roles) = 0;
414 
422  virtual void reviveOffers(
423  const FrameworkID& frameworkId,
424  const std::set<std::string>& roles) = 0;
425 
435  virtual void updateQuota(
436  const std::string& role,
437  const Quota& quota) = 0;
438 
444  virtual void updateWeights(
445  const std::vector<WeightInfo>& weightInfos) = 0;
446 
450  virtual void pause() = 0;
451 
455  virtual void resume() = 0;
456 };
457 
458 } // namespace allocator {
459 } // namespace mesos {
460 
461 #endif // __MESOS_MASTER_ALLOCATOR_HPP__
Allocator()
Definition: allocator.hpp:100
Protocol< RecoverRequest, RecoverResponse > recover
Definition: option.hpp:29
Option< std::vector< ResourceQuantities > > minAllocatableResources
Definition: allocator.hpp:63
Definition: check.hpp:33
virtual ~Allocator()
Definition: allocator.hpp:102
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
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: agent.hpp:25
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:82
Definition: none.hpp:27
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
size_t maxCompletedFrameworks
Definition: allocator.hpp:65
Option< std::set< std::string > > fairnessExcludeResourceNames
Definition: allocator.hpp:54
bool publishPerFrameworkMetrics
Definition: allocator.hpp:67
Definition: quota.hpp:27
constexpr const char * name
Definition: shell.hpp:43
Duration allocationInterval
Definition: allocator.hpp:51