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 #include <mesos/scheduler/scheduler.pb.h>
26 
29 #include <mesos/quota/quota.hpp>
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 
48 
49 
53 struct Options
54 {
56 
57  // Resources (by name) that will be excluded from a role's fair share.
59 
60  // Filter GPU resources based on the `GPU_RESOURCES` framework capability.
61  bool filterGpuResources = true;
62 
63  // The master's domain, if any.
65 
66  // The minimum allocatable resource quantities, if any.
68 
70 
72 
73  // Authentication realm for HTTP debug endpoints exposed by the allocator.
75 
76  // Mesos master's authorizer.
78 
79  // Recovery options
82 };
83 
84 
85 namespace internal {
86 class OfferConstraintsFilterImpl;
87 
88 } // namespace internal {
89 
90 
92 {
93 public:
94  // TODO(asekretenko): Given that most dependants of the public allocator
95  // interface do not care about filter creation, we should consider decoupling
96  // the filter construction interface (which at this point consists of the
97  // `struct Options` and the `create()` method) from the allocator interface.
98  struct Options
99  {
100  struct RE2Limits
101  {
104  };
105 
107  };
108 
110  const Options& options,
111  scheduler::OfferConstraints&& constraints);
112 
113  /*
114  * Constructs a no-op filter that does not exclude any agents/resources from
115  * being offered. This is equivalent to passing default-constructed
116  * `OfferConstraints` to the factory method `create()`.
117  */
119 
120  // Definitions of these need `OfferConstraintsFilterImpl` to be a complete
121  // type.
125 
130  bool isAgentExcluded(
131  const std::string& role,
132  const SlaveInfo& agentInfo) const;
133 
134  // TODO(asekretenko): Add a method for filtering `Resources` on an agent.
135 
136 private:
137  std::unique_ptr<internal::OfferConstraintsFilterImpl> impl;
138 
139  OfferConstraintsFilter(internal::OfferConstraintsFilterImpl&& impl_);
140 };
141 
142 
148 {
152  std::set<std::string> suppressedRoles;
153 
158 };
159 
160 
173 {
174 public:
185  static Try<Allocator*> create(
186  const std::string& name,
187  const std::string& roleSorter,
188  const std::string& frameworkSorter);
189 
191 
192  virtual ~Allocator() {}
193 
208  virtual void initialize(
209  const Options& options,
210  const lambda::function<
211  void(const FrameworkID&,
212  const hashmap<std::string, hashmap<SlaveID, Resources>>&)>&
213  offerCallback,
214  const lambda::function<
215  void(const FrameworkID&,
217  inverseOfferCallback) = 0;
218 
232  virtual void recover(
233  const int expectedAgentCount,
234  const hashmap<std::string, Quota>& quotas) = 0;
235 
250  virtual void addFramework(
251  const FrameworkID& frameworkId,
252  const FrameworkInfo& frameworkInfo,
254  bool active,
255  FrameworkOptions&& options) = 0;
256 
262  virtual void removeFramework(
263  const FrameworkID& frameworkId) = 0;
264 
269  virtual void activateFramework(
270  const FrameworkID& frameworkId) = 0;
271 
276  virtual void deactivateFramework(
277  const FrameworkID& frameworkId) = 0;
278 
286  virtual void updateFramework(
287  const FrameworkID& frameworkId,
288  const FrameworkInfo& frameworkInfo,
289  FrameworkOptions&& options) = 0;
290 
311  virtual void addSlave(
312  const SlaveID& slaveId,
313  const SlaveInfo& slaveInfo,
314  const std::vector<SlaveInfo::Capability>& capabilities,
316  const Resources& total,
317  const hashmap<FrameworkID, Resources>& used) = 0;
318 
323  virtual void removeSlave(
324  const SlaveID& slaveId) = 0;
325 
335  virtual void updateSlave(
336  const SlaveID& slave,
337  const SlaveInfo& slaveInfo,
338  const Option<Resources>& total = None(),
339  const Option<std::vector<SlaveInfo::Capability>>&
340  capabilities = None()) = 0;
341 
350  virtual void addResourceProvider(
351  const SlaveID& slave,
352  const Resources& total,
353  const hashmap<FrameworkID, Resources>& used) = 0;
354 
359  virtual void activateSlave(
360  const SlaveID& slaveId) = 0;
361 
370  virtual void deactivateSlave(
371  const SlaveID& slaveId) = 0;
372 
381  virtual void updateWhitelist(
382  const Option<hashset<std::string>>& whitelist) = 0;
383 
391  virtual void requestResources(
392  const FrameworkID& frameworkId,
393  const std::vector<Request>& requests) = 0;
394 
405  virtual void updateAllocation(
406  const FrameworkID& frameworkId,
407  const SlaveID& slaveId,
408  const Resources& offeredResources,
409  const std::vector<ResourceConversion>& conversions) = 0;
410 
418  virtual process::Future<Nothing> updateAvailable(
419  const SlaveID& slaveId,
420  const std::vector<Offer::Operation>& operations) = 0;
421 
430  virtual void updateUnavailability(
431  const SlaveID& slaveId,
432  const Option<Unavailability>& unavailability) = 0;
433 
452  virtual void updateInverseOffer(
453  const SlaveID& slaveId,
454  const FrameworkID& frameworkId,
455  const Option<UnavailableResources>& unavailableResources,
457  const Option<Filters>& filters = None()) = 0;
458 
462  virtual process::Future<
463  hashmap<SlaveID,
465  getInverseOfferStatuses() = 0;
466 
471  virtual void transitionOfferedToAllocated(
472  const SlaveID& slaveId, const Resources& resources) = 0;
473 
489  virtual void recoverResources(
490  const FrameworkID& frameworkId,
491  const SlaveID& slaveId,
492  const Resources& resources,
493  const Option<Filters>& filters,
494  bool isAllocated) = 0;
495 
503  virtual void suppressOffers(
504  const FrameworkID& frameworkId,
505  const std::set<std::string>& roles) = 0;
506 
514  virtual void reviveOffers(
515  const FrameworkID& frameworkId,
516  const std::set<std::string>& roles) = 0;
517 
527  virtual void updateQuota(
528  const std::string& role,
529  const Quota& quota) = 0;
530 
536  virtual void updateWeights(
537  const std::vector<WeightInfo>& weightInfos) = 0;
538 
542  virtual void pause() = 0;
543 
547  virtual void resume() = 0;
548 };
549 
550 } // namespace allocator {
551 } // namespace mesos {
552 
553 #endif // __MESOS_MASTER_ALLOCATOR_HPP__
Allocator()
Definition: allocator.hpp:190
Protocol< RecoverRequest, RecoverResponse > recover
Option<::mesos::Authorizer * > authorizer
Definition: allocator.hpp:77
Per-framework allocator-specific options that are not part of FrameworkInfo.
Definition: allocator.hpp:147
Definition: option.hpp:29
Option< std::vector< ResourceQuantities > > minAllocatableResources
Definition: allocator.hpp:67
double agentRecoveryFactor
Definition: allocator.hpp:81
Definition: check.hpp:33
OfferConstraintsFilter offerConstraintsFilter
The internal representation of framework&#39;s offer constraints.
Definition: allocator.hpp:157
virtual ~Allocator()
Definition: allocator.hpp:192
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: resources.hpp:83
constexpr double DEFAULT_ALLOCATOR_AGENT_RECOVERY_FACTOR
Definition: allocator.hpp:47
Pass in configuration to the allocator.
Definition: allocator.hpp:53
Definition: duration.hpp:32
Definition: hashmap.hpp:38
Option< DomainInfo > domain
Definition: allocator.hpp:64
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:221
Definition: duration.hpp:207
Definition: agent.hpp:25
bool filterGpuResources
Definition: allocator.hpp:61
Definition: allocator.hpp:91
Basic model of an allocator: resources are allocated to a framework in the form of offers...
Definition: allocator.hpp:172
constexpr Duration DEFAULT_ALLOCATOR_RECOVERY_TIMEOUT
Definition: allocator.hpp:46
std::set< std::string > suppressedRoles
The set of roles for which the allocator should not generate offers.
Definition: allocator.hpp:152
Definition: none.hpp:27
Definition: attributes.hpp:24
Option< std::string > readonlyHttpAuthenticationRealm
Definition: allocator.hpp:74
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Definition: bytes.hpp:30
size_t maxCompletedFrameworks
Definition: allocator.hpp:69
Option< std::set< std::string > > fairnessExcludeResourceNames
Definition: allocator.hpp:58
bool publishPerFrameworkMetrics
Definition: allocator.hpp:71
Definition: quota.hpp:27
constexpr const char * name
Definition: shell.hpp:41
Duration allocationInterval
Definition: allocator.hpp:55
Duration recoveryTimeout
Definition: allocator.hpp:80
RE2Limits re2Limits
Definition: allocator.hpp:106