17 #ifndef __MASTER_ALLOCATOR_MESOS_HIERARCHICAL_HPP__ 18 #define __MASTER_ALLOCATOR_MESOS_HIERARCHICAL_HPP__ 59 typename FrameworkSorter>
79 class InverseOfferFilter;
86 const FrameworkInfo& frameworkInfo,
134 void add(
const SlaveID& slaveID,
const Resources& resources);
135 void subtract(
const SlaveID& slaveID,
const Resources& resources);
137 bool empty()
const {
return scalars.empty(); }
153 return reservationScalarQuantities_;
158 return offeredOrAllocatedReserved.quantities();
167 return offeredOrAllocatedUnreservedNonRevocable.quantities() +
168 reservationScalarQuantities_;
173 return allocatedUnreservedNonRevocable.quantities() +
174 reservationScalarQuantities_;
177 double weight()
const {
return weight_; }
181 return children_.empty() &&
182 frameworks_.empty() &&
183 reservationScalarQuantities_.empty() &&
188 std::vector<Role*>
children()
const {
return children_.values(); }
199 void addChild(
Role* child);
202 void removeChild(
Role* child);
277 void trackReservations(
const Resources& resources);
278 void untrackReservations(
const Resources& resources);
281 void trackAllocated(
const SlaveID& slaveId,
const Resources& resources);
282 void untrackAllocated(
const SlaveID& slaveId,
const Resources& resources);
285 const FrameworkID&
frameworkId,
const std::string& role);
286 void untrackFramework(
287 const FrameworkID& frameworkId,
const std::string& role);
289 void updateQuota(
const std::string& role,
const Quota& quota);
291 void updateWeight(
const std::string& role,
double weight);
293 void trackOfferedOrAllocated(
294 const SlaveID& slaveId,
297 void untrackOfferedOrAllocated(
298 const SlaveID& slaveId,
302 std::string toJSON()
const;
310 Role& operator[](
const std::string& role);
313 template<
class UnaryFunction>
314 static void applyToRoleAndAncestors(
Role* role, UnaryFunction
f) {
315 for (; role !=
nullptr; role = role->parent) {
327 bool tryRemove(
const std::string& role);
329 void updateQuotaConsumedMetric(
const Role* role);
346 const SlaveInfo& _info,
354 activated(_activated),
355 totalAllocated(
Resources::sum(_allocated)),
357 offeredOrAllocated(_allocated),
358 totalOfferedOrAllocated(
Resources::sum(_allocated)),
359 shared(_total.shared()),
360 hasGpu_(_total.gpus().getOrElse(0) > 0)
362 CHECK(_info.has_id());
370 return offeredOrAllocated;
375 return totalOfferedOrAllocated;
394 if (offeredOrAllocated_.
empty()) {
401 totalOfferedOrAllocated -= offeredOrAllocated_;
403 Resources& resources = offeredOrAllocated.at(frameworkId);
405 resources -= offeredOrAllocated_;
406 if (resources.
empty()) {
407 offeredOrAllocated.erase(frameworkId);
416 if (offeredOrAllocated_.
empty()) {
422 offeredOrAllocated[
frameworkId] += offeredOrAllocated_;
424 totalOfferedOrAllocated += offeredOrAllocated_;
485 void updateAvailable()
489 Resources totalOfferedOrAllocated_ = totalOfferedOrAllocated;
494 if (shared.empty()) {
495 available = total - totalOfferedOrAllocated_;
500 (total.nonShared() - totalOfferedOrAllocated_.
nonShared()) + shared;
550 const std::function<
Sorter*()>& roleSorterFactory,
551 const std::function<
Sorter*()>& _frameworkSorterFactory)
552 : initialized(false),
555 completedFrameworkMetrics(0),
557 roleSorter(roleSorterFactory()),
558 frameworkSorterFactory(_frameworkSorterFactory) {}
569 const lambda::function<
570 void(
const FrameworkID&,
573 const lambda::function<
574 void(
const FrameworkID&,
576 inverseOfferCallback)
override;
579 const int _expectedAgentCount,
584 const FrameworkInfo& frameworkInfo,
589 void removeFramework(
590 const FrameworkID& frameworkId)
override;
592 void activateFramework(
593 const FrameworkID& frameworkId)
override;
595 void deactivateFramework(
596 const FrameworkID& frameworkId)
override;
598 void updateFramework(
599 const FrameworkID& frameworkId,
600 const FrameworkInfo& frameworkInfo,
604 const SlaveID& slaveId,
605 const SlaveInfo& slaveInfo,
612 const SlaveID& slaveId)
override;
615 const SlaveID& slave,
616 const SlaveInfo& slaveInfo,
618 const Option<std::vector<SlaveInfo::Capability>>& capabilities =
None())
621 void addResourceProvider(
622 const SlaveID& slave,
626 void deactivateSlave(
627 const SlaveID& slaveId)
override;
630 const SlaveID& slaveId)
override;
632 void updateWhitelist(
635 void requestResources(
636 const FrameworkID& frameworkId,
637 const std::vector<Request>& requests)
override;
639 void updateAllocation(
640 const FrameworkID& frameworkId,
641 const SlaveID& slaveId,
643 const std::vector<ResourceConversion>& conversions)
override;
646 const SlaveID& slaveId,
647 const std::vector<Offer::Operation>& operations)
override;
649 void updateUnavailability(
650 const SlaveID& slaveId,
653 void updateInverseOffer(
654 const SlaveID& slaveId,
655 const FrameworkID& frameworkId,
663 getInverseOfferStatuses()
override;
665 void transitionOfferedToAllocated(
666 const SlaveID& slaveId,
const Resources& resources)
override;
668 void recoverResources(
669 const FrameworkID& frameworkId,
670 const SlaveID& slaveId,
673 bool isAllocated)
override;
676 const FrameworkID& frameworkId,
677 const std::set<std::string>&
roles)
override;
680 const FrameworkID& frameworkId,
681 const std::set<std::string>& roles)
override;
684 const std::string& role,
685 const Quota& quota)
override;
688 const std::vector<WeightInfo>& weightInfos)
override;
690 void pause()
override;
692 void resume()
override;
711 void __generateOffers();
713 void generateInverseOffers();
717 const FrameworkID& frameworkId,
718 const std::string& role,
719 const SlaveID& slaveId,
720 const std::weak_ptr<OfferFilter>& offerFilter);
723 const FrameworkID& frameworkId,
724 const std::string& role,
725 const SlaveID& slaveId,
726 const std::weak_ptr<OfferFilter>& offerFilter);
730 const FrameworkID& frameworkId,
731 const SlaveID& slaveId,
732 const std::weak_ptr<InverseOfferFilter>& inverseOfferFilter);
735 bool isWhitelisted(
const SlaveID& slaveId)
const;
741 const std::string& role,
749 const Slave& slave)
const;
753 const std::string& role,
765 void(
const FrameworkID&,
770 void(
const FrameworkID&,
779 return static_cast<double>(eventCount<process::DispatchEvent>());
782 double _resources_total(
783 const std::string& resource);
785 double _resources_offered_or_allocated(
786 const std::string& resource);
788 double _quota_offered_or_allocated(
789 const std::string& role,
790 const std::string& resource);
792 double _offer_filters_active(
793 const std::string& role);
876 std::shared_ptr<const ObjectApprover> frameworksApprover);
878 bool isFrameworkTrackedUnderRole(
879 const FrameworkID& frameworkId,
880 const std::string& role)
const;
887 const Quota& getQuota(
const std::string& role)
const;
896 void trackFrameworkUnderRole(
897 const Framework& framework,
const std::string& role);
898 bool tryUntrackFrameworkUnderRole(
899 const Framework& framework,
const std::string& role);
901 void suppressRoles(
Framework& framework,
const std::set<std::string>& roles);
902 void reviveRoles(
Framework& framework,
const std::set<std::string>& roles);
907 bool updateSlaveTotal(
const SlaveID& slaveId,
const Resources& total);
912 bool isRemoteSlave(
const Slave& slave)
const;
919 bool isCapableOfReceivingAgent(
921 const Slave& slave)
const;
938 void trackAllocatedResources(
939 const SlaveID& slaveId,
940 const FrameworkID& frameworkId,
947 void untrackAllocatedResources(
948 const SlaveID& slaveId,
949 const FrameworkID& frameworkId,
954 void removeFilters(
const SlaveID& slaveId);
966 typename FrameworkSorter>
976 return new RoleSorter(this->
self(),
"allocator/mesos/roles/");
978 []() ->
Sorter* {
return new FrameworkSorter(); }) {}
986 #endif // __MASTER_ALLOCATOR_MESOS_HIERARCHICAL_HPP__ Protocol< RecoverRequest, RecoverResponse > recover
std::string generate(const std::string &prefix="")
Returns 'prefix(N)' where N represents the number of instances where the same prefix (wrt...
std::set< std::string > roles
Definition: hierarchical.hpp:95
#define CHECK_CONTAINS(container, key)
Definition: check.hpp:298
HierarchicalAllocatorProcess(const std::function< Sorter *()> &roleSorterFactory, const std::function< Sorter *()> &_frameworkSorterFactory)
Definition: hierarchical.hpp:549
Per-framework allocator-specific options that are not part of FrameworkInfo.
Definition: allocator.hpp:147
mesos::allocator::Options options
Definition: hierarchical.hpp:759
Definition: nothing.hpp:16
Definition: option.hpp:29
T getOrElse(U &&u) const &
Definition: option.hpp:133
const hashmap< FrameworkID, Resources > & getOfferedOrAllocated() const
Definition: hierarchical.hpp:368
const Resources & getTotal() const
Definition: hierarchical.hpp:366
Maintenance(const Unavailability &_unavailability)
Definition: hierarchical.hpp:449
F && f
Definition: defer.hpp:270
protobuf::framework::Capabilities capabilities
Definition: hierarchical.hpp:99
Definition: hierarchical.hpp:447
hashmap< std::string, hashmap< SlaveID, hashset< std::shared_ptr< OfferFilter > > > > offerFilters
Definition: hierarchical.hpp:104
Metrics metrics
Definition: hierarchical.hpp:775
Definition: master.hpp:27
HierarchicalAllocatorProcess< RandomSorter, RandomSorter > HierarchicalRandomAllocatorProcess
Definition: hierarchical.hpp:69
Definition: hierarchical.hpp:342
hashmap< std::string, process::Owned< Sorter > > frameworkSorters
Definition: hierarchical.hpp:865
Definition: resource_quantities.hpp:63
BoundedHashMap< FrameworkID, process::Owned< FrameworkMetrics > > completedFrameworkMetrics
Definition: hierarchical.hpp:798
Definition: protobuf_utils.hpp:332
Definition: format.hpp:45
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Option< int > expectedAgentCount
Definition: hierarchical.hpp:762
Definition: resources.hpp:83
Slave * getSlave(Master *master, const SlaveID &slaveId)
Slave(const SlaveInfo &_info, const protobuf::slave::Capabilities &_capabilities, bool _activated, const Resources &_total, const hashmap< FrameworkID, Resources > &_allocated)
Definition: hierarchical.hpp:345
Option< double > gpus() const
~HierarchicalAllocatorProcess() override
Definition: hierarchical.hpp:560
Pass in configuration to the allocator.
Definition: allocator.hpp:53
ResourceQuantities quantities() const
Definition: hierarchical.hpp:138
const hashmap< std::string, Role > & roles() const
Definition: hierarchical.hpp:271
hashmap< SlaveID, Slave > slaves
Definition: hierarchical.hpp:800
constexpr double DEFAULT_WEIGHT
Definition: constants.hpp:180
MesosAllocator< HierarchicalRandomAllocatorProcess > HierarchicalRandomAllocator
Definition: hierarchical.hpp:72
Future< Nothing > add(const T &metric)
Definition: metrics.hpp:95
Definition: allocator.hpp:41
Mode
Definition: paths.hpp:90
const std::string basename
Definition: hierarchical.hpp:191
SlaveInfo info
Definition: hierarchical.hpp:435
bool hasGpu() const
Definition: hierarchical.hpp:380
::mesos::allocator::OfferConstraintsFilter offerConstraintsFilter
Definition: hierarchical.hpp:120
ResourceQuantities quotaOfferedOrConsumed() const
Definition: hierarchical.hpp:165
MesosAllocator< HierarchicalDRFAllocatorProcess > HierarchicalDRFAllocator
Definition: hierarchical.hpp:66
std::vector< Role * > children() const
Definition: hierarchical.hpp:188
const std::function< Sorter *()> frameworkSorterFactory
Definition: hierarchical.hpp:868
bool activated
Definition: hierarchical.hpp:439
Definition: hashmap.hpp:38
RoleTree roleTree
Definition: hierarchical.hpp:805
const SlaveID id
Definition: hierarchical.hpp:429
lambda::function< void(const FrameworkID &, const hashmap< std::string, hashmap< SlaveID, Resources >> &)> offerCallback
Definition: hierarchical.hpp:767
bool active
Definition: hierarchical.hpp:109
Try< Nothing > unavailability(const Unavailability &unavailability)
Definition: hierarchical.hpp:546
process::Owned< Sorter > roleSorter
Definition: hierarchical.hpp:857
std::set< std::string > suppressedRoles
Definition: hierarchical.hpp:97
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.
hashmap< FrameworkID, mesos::allocator::InverseOfferStatus > statuses
Definition: hierarchical.hpp:463
Result< std::vector< Filter< Classifier > > > filters(const std::string &_link, const Handle &parent)
Definition: internal.hpp:769
ResourceQuantities totalScalarQuantities
Definition: hierarchical.hpp:803
const FrameworkID frameworkId
Definition: hierarchical.hpp:91
Definition: hierarchical.hpp:146
double weight() const
Definition: hierarchical.hpp:177
Definition: hierarchical.hpp:83
Definition: allocator.hpp:186
Definition: protobuf_utils.hpp:631
hashmap< FrameworkID, Framework > frameworks
Definition: hierarchical.hpp:795
HierarchicalAllocatorProcess< DRFSorter, DRFSorter > HierarchicalDRFAllocatorProcess
Definition: hierarchical.hpp:60
bool publishPerFrameworkMetrics
Definition: hierarchical.hpp:111
const Quota & quota() const
Definition: hierarchical.hpp:163
Definition: allocator.hpp:91
ResourceQuantities offeredOrAllocatedReservedScalarQuantities() const
Definition: hierarchical.hpp:156
const ResourceQuantities & reservationScalarQuantities() const
Definition: hierarchical.hpp:151
hashmap< SlaveID, hashset< std::shared_ptr< InverseOfferFilter > > > inverseOfferFilters
Definition: hierarchical.hpp:107
const Role * root() const
Definition: hierarchical.hpp:273
process::Owned< FrameworkMetrics > metrics
Definition: hierarchical.hpp:113
Framework(const FrameworkInfo &frameworkInfo,::mesos::allocator::FrameworkOptions &&options, bool active, bool publishPerFrameworkMetrics)
Option< hashset< std::string > > whitelist
Definition: hierarchical.hpp:817
double _event_queue_dispatches()
Definition: hierarchical.hpp:777
hashset< SlaveID > allocationCandidates
Definition: hierarchical.hpp:810
Definition: boundedhashmap.hpp:27
Try< bool > remove(const std::string &link, const Handle &parent, uint16_t protocol)
FrameworkInfo info
Definition: hierarchical.hpp:93
const Resources & getAvailable() const
Definition: hierarchical.hpp:378
Definition: hierarchical.hpp:129
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
bool empty() const
Definition: resources.hpp:451
Definition: attributes.hpp:24
Definition: hierarchical.hpp:259
bool isEmpty() const
Definition: hierarchical.hpp:179
hashset< FrameworkID > offersOutstanding
Definition: hierarchical.hpp:469
Resources nonShared() const
Option< process::Future< Nothing > > offerGeneration
Definition: hierarchical.hpp:814
Definition: executor.hpp:48
Unavailability unavailability
Definition: hierarchical.hpp:453
HierarchicalAllocatorProcess This
Definition: hierarchical.hpp:697
hashmap< std::string, std::vector< ResourceQuantities > > minAllocatableResources
Definition: hierarchical.hpp:118
Definition: sorter.hpp:42
ResourceQuantities quotaConsumed() const
Definition: hierarchical.hpp:171
friend Metrics
Definition: hierarchical.hpp:774
bool empty() const
Definition: hierarchical.hpp:137
const std::string role
Definition: hierarchical.hpp:190
bool initialized
Definition: hierarchical.hpp:756
void increaseAvailable(const FrameworkID &frameworkId, const Resources &offeredOrAllocated_)
Definition: hierarchical.hpp:390
Definition: hierarchical.hpp:60
HierarchicalAllocatorProcess Self
Definition: hierarchical.hpp:696
Option< Maintenance > maintenance
Definition: hierarchical.hpp:475
const Resources & getTotalOfferedOrAllocated() const
Definition: hierarchical.hpp:373
void decreaseAvailable(const FrameworkID &frameworkId, const Resources &offeredOrAllocated_)
Definition: hierarchical.hpp:413
const Quota DEFAULT_QUOTA
Definition: constants.hpp:177
Resources totalAllocated
Definition: hierarchical.hpp:482
const hashset< FrameworkID > & frameworks() const
Definition: hierarchical.hpp:161
Definition: metrics.hpp:64
HierarchicalAllocatorProcess()
Definition: hierarchical.hpp:971
constexpr const char * name
Definition: shell.hpp:41
bool paused
Definition: hierarchical.hpp:757
protobuf::slave::Capabilities capabilities
Definition: hierarchical.hpp:437
void updateTotal(const Resources &newTotal)
Definition: hierarchical.hpp:382
lambda::function< void(const FrameworkID &, const hashmap< SlaveID, UnavailableResources > &)> inverseOfferCallback
Definition: hierarchical.hpp:772