17 #ifndef __MASTER_ALLOCATOR_SORTER_DRF_SORTER_HPP__ 18 #define __MASTER_ALLOCATOR_SORTER_DRF_SORTER_HPP__ 50 const std::string& metricsPrefix);
55 const Option<std::set<std::string>>& fairnessExcludeResourceNames);
57 virtual void add(
const std::string& clientPath);
59 virtual void remove(
const std::string& clientPath);
61 virtual void activate(
const std::string& clientPath);
63 virtual void deactivate(
const std::string& clientPath);
68 const std::string& clientPath,
69 const SlaveID& slaveId,
73 const std::string& clientPath,
74 const SlaveID& slaveId,
79 const std::string& clientPath,
80 const SlaveID& slaveId,
84 const std::string& clientPath)
const;
87 const std::string& clientPath)
const;
90 const SlaveID& slaveId)
const;
93 const std::string& clientPath,
94 const SlaveID& slaveId)
const;
98 virtual void add(
const SlaveID& slaveId,
const Resources& resources);
100 virtual void remove(
const SlaveID& slaveId,
const Resources& resources);
102 virtual std::vector<std::string>
sort();
104 virtual bool contains(
const std::string& clientPath)
const;
106 virtual size_t count()
const;
113 double calculateShare(
const Node* node)
const;
118 double findWeight(
const Node* node)
const;
123 Node*
find(
const std::string& clientPath)
const;
210 :
name(_name), share(0),
kind(_kind), parent(_parent)
217 if (parent ==
nullptr) {
219 }
else if (parent->parent ==
nullptr) {
276 CHECK(kind == ACTIVE_LEAF || kind == INACTIVE_LEAF);
277 return CHECK_NOTNULL(parent)->path;
285 if (kind == ACTIVE_LEAF || kind == INACTIVE_LEAF) {
286 CHECK(children.empty());
296 auto it =
std::find(children.begin(), children.end(), child);
297 CHECK(it != children.end());
305 auto it =
std::find(children.begin(), children.end(), child);
306 CHECK(it == children.end());
312 if (child->
kind == INACTIVE_LEAF) {
313 children.push_back(child);
315 children.insert(children.begin(), child);
329 .
filter([
this, slaveId](
const Resource& resource) {
330 return !resources[slaveId].contains(resource);
334 (toAdd.
nonShared() + sharedToAdd).createStrippedScalarQuantity();
336 resources[slaveId] += toAdd;
337 scalarQuantities += quantitiesToAdd;
339 foreach (
const Resource& resource, quantitiesToAdd) {
340 totals[resource.name()] += resource.scalar();
348 CHECK(resources.contains(slaveId));
349 CHECK(resources.at(slaveId).contains(toRemove))
350 <<
"Resources " << resources.at(slaveId) <<
" at agent " << slaveId
351 <<
" does not contain " << toRemove;
353 resources[slaveId] -= toRemove;
358 .
filter([
this, slaveId](
const Resource& resource) {
359 return !resources[slaveId].contains(resource);
363 (toRemove.nonShared() + sharedToRemove).createStrippedScalarQuantity();
365 foreach (
const Resource& resource, quantitiesToRemove) {
366 totals[resource.name()] -= resource.scalar();
369 CHECK(scalarQuantities.contains(quantitiesToRemove))
370 << scalarQuantities <<
" does not contain " << quantitiesToRemove;
372 scalarQuantities -= quantitiesToRemove;
374 if (resources[slaveId].empty()) {
375 resources.erase(slaveId);
380 const SlaveID& slaveId,
389 CHECK(resources.contains(slaveId));
390 CHECK(resources[slaveId].
contains(oldAllocation))
391 <<
"Resources " << resources[slaveId] <<
" at agent " << slaveId
392 <<
" does not contain " << oldAllocation;
394 CHECK(scalarQuantities.contains(oldAllocationQuantity))
395 << scalarQuantities <<
" does not contain " << oldAllocationQuantity;
397 resources[slaveId] -= oldAllocation;
398 resources[slaveId] += newAllocation;
400 scalarQuantities -= oldAllocationQuantity;
401 scalarQuantities += newAllocationQuantity;
403 foreach (
const Resource& resource, oldAllocationQuantity) {
404 totals[resource.name()] -= resource.scalar();
407 foreach (
const Resource& resource, newAllocationQuantity) {
408 totals[resource.name()] += resource.scalar();
462 #endif // __MASTER_ALLOCATOR_SORTER_DRF_SORTER_HPP__
Node(const std::string &_name, Kind _kind, Node *_parent)
Definition: sorter.hpp:209
Definition: option.hpp:28
bool isLeaf() const
Definition: sorter.hpp:283
Definition: master.hpp:27
double share
Definition: sorter.hpp:244
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:306
std::string clientPath() const
Definition: sorter.hpp:273
std::vector< Node * > children
Definition: sorter.hpp:262
void add(const SlaveID &slaveId, const Resources &toAdd)
Definition: sorter.hpp:324
std::string path
Definition: sorter.hpp:242
Resources scalarQuantities
Definition: sorter.hpp:430
Resources filter(const lambda::function< bool(const Resource &)> &predicate) const
Definition: resources.hpp:79
virtual std::vector< std::string > sort()
uint64_t count
Definition: sorter.hpp:419
Allocation()
Definition: sorter.hpp:322
Definition: sorter.hpp:320
std::string name
Definition: sorter.hpp:238
virtual void update(const std::string &clientPath, const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation)
virtual void deactivate(const std::string &clientPath)
Definition: hashmap.hpp:38
Kind
Definition: sorter.hpp:202
Definition: metrics.hpp:35
hashmap< SlaveID, Resources > resources
Definition: sorter.hpp:425
struct mesos::internal::master::allocator::DRFSorter::Node::Allocation allocation
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
void subtract(const SlaveID &slaveId, const Resources &toRemove)
Definition: sorter.hpp:346
void removeChild(const Node *child)
Definition: sorter.hpp:293
virtual const Resources & totalScalarQuantities() const
Resources createStrippedScalarQuantity() const
Node * parent
Definition: sorter.hpp:248
Definition: sorter.hpp:204
virtual const Resources & allocationScalarQuantities(const std::string &clientPath) const
Definition: sorter.hpp:196
virtual void unallocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources)
hashmap< std::string, Value::Scalar > totals
Definition: sorter.hpp:439
static bool compareDRF(const Node *left, const Node *right)
Definition: sorter.hpp:443
Definition: sorter.hpp:43
virtual void allocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources)
virtual void add(const std::string &clientPath)
Definition: sorter.hpp:205
Definition: attributes.hpp:24
Resources nonShared() const
std::set< pid_t > children(pid_t, const std::list< Process > &, bool)
Definition: os.hpp:215
Definition: sorter.hpp:41
virtual size_t count() const
virtual bool contains(const std::string &clientPath) const
Kind kind
Definition: sorter.hpp:246
virtual void initialize(const Option< std::set< std::string >> &fairnessExcludeResourceNames)
virtual const hashmap< SlaveID, Resources > & allocation(const std::string &clientPath) const
void addChild(Node *child)
Definition: sorter.hpp:302
void update(const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation)
Definition: sorter.hpp:379
constexpr const char * name
Definition: shell.hpp:43
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37
virtual void activate(const std::string &clientPath)
~Node()
Definition: sorter.hpp:226
virtual void updateWeight(const std::string &path, double weight)