17 #ifndef __MASTER_ALLOCATOR_MESOS_SORTER_DRF_SORTER_HPP__ 18 #define __MASTER_ALLOCATOR_MESOS_SORTER_DRF_SORTER_HPP__ 51 const std::string& metricsPrefix);
56 const Option<std::set<std::string>>& fairnessExcludeResourceNames)
59 void add(
const std::string& clientPath)
override;
61 void remove(
const std::string& clientPath)
override;
63 void activate(
const std::string& clientPath)
override;
65 void deactivate(
const std::string& clientPath)
override;
70 const std::string& clientPath,
71 const SlaveID& slaveId,
75 const std::string& clientPath,
76 const SlaveID& slaveId,
81 const std::string& clientPath,
82 const SlaveID& slaveId,
86 const std::string& clientPath)
const override;
89 const std::string& clientPath)
const override;
94 const std::string& clientPath,
95 const SlaveID& slaveId)
const override;
98 const SlaveID& slaveId,
103 std::vector<std::string>
sort()
override;
105 bool contains(
const std::string& clientPath)
const override;
107 size_t count()
const override;
114 double calculateShare(
const Node* node)
const;
119 double getWeight(
const Node* node)
const;
124 Node*
find(
const std::string& clientPath)
const;
195 :
name(_name), share(0),
kind(_kind), parent(_parent)
202 if (parent ==
nullptr) {
204 }
else if (parent->parent ==
nullptr) {
268 CHECK(kind == ACTIVE_LEAF || kind == INACTIVE_LEAF);
269 return CHECK_NOTNULL(parent)->path;
277 if (kind == ACTIVE_LEAF || kind == INACTIVE_LEAF) {
278 CHECK(children.empty());
288 auto it =
std::find(children.begin(), children.end(), child);
289 CHECK(it != children.end());
297 auto it =
std::find(children.begin(), children.end(), child);
298 CHECK(it == children.end());
304 if (child->
kind == INACTIVE_LEAF) {
305 children.push_back(child);
307 children.insert(children.begin(), child);
321 .
filter([
this, slaveId](
const Resource& resource) {
322 return !resources[slaveId].contains(resource);
327 (toAdd.
nonShared() + sharedToAdd).scalars());
329 resources[slaveId] += toAdd;
330 totals += quantitiesToAdd;
337 CHECK(resources.contains(slaveId))
338 <<
"Resources " << resources <<
" does not contain " << slaveId;
339 CHECK(resources.at(slaveId).contains(toRemove))
340 <<
"Resources " << resources.at(slaveId) <<
" at agent " << slaveId
341 <<
" does not contain " << toRemove;
343 resources[slaveId] -= toRemove;
348 .
filter([
this, slaveId](
const Resource& resource) {
349 return !resources[slaveId].contains(resource);
354 (toRemove.nonShared() + sharedToRemove).scalars());
356 CHECK(totals.contains(quantitiesToRemove))
357 << totals <<
" does not contain " << quantitiesToRemove;
359 totals -= quantitiesToRemove;
361 if (resources.at(slaveId).empty()) {
362 resources.erase(slaveId);
367 const SlaveID& slaveId,
376 CHECK(resources.contains(slaveId))
377 <<
"Resources " << resources <<
" does not contain " << slaveId;
378 CHECK(resources[slaveId].
contains(oldAllocation))
379 <<
"Resources " << resources[slaveId] <<
" at agent " << slaveId
380 <<
" does not contain " << oldAllocation;
382 CHECK(totals.contains(oldAllocationQuantities))
383 << totals <<
" does not contain " << oldAllocationQuantities;
385 resources[slaveId] -= oldAllocation;
386 resources[slaveId] += newAllocation;
390 if (resources.at(slaveId).empty()) {
391 resources.erase(slaveId);
394 totals -= oldAllocationQuantities;
395 totals += newAllocationQuantities;
440 #endif // __MASTER_ALLOCATOR_MESOS_SORTER_DRF_SORTER_HPP__
bool contains(const std::string &clientPath) const override
Node(const std::string &_name, Kind _kind, Node *_parent)
Definition: sorter.hpp:194
Definition: option.hpp:29
void deactivate(const std::string &clientPath) override
bool isLeaf() const
Definition: sorter.hpp:275
Definition: master.hpp:27
double share
Definition: sorter.hpp:230
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:307
std::vector< Node * > children
Definition: sorter.hpp:254
Definition: resource_quantities.hpp:63
void add(const SlaveID &slaveId, const Resources &toAdd)
Definition: sorter.hpp:316
std::string path
Definition: sorter.hpp:227
Resources filter(const lambda::function< bool(const Resource &)> &predicate) const
Definition: resources.hpp:83
void unallocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources) override
void update(const std::string &clientPath, const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation) override
Option< double > weight
Definition: sorter.hpp:236
uint64_t count
Definition: sorter.hpp:405
Allocation()
Definition: sorter.hpp:314
Definition: sorter.hpp:312
std::string name
Definition: sorter.hpp:223
Definition: hashmap.hpp:38
Kind
Definition: sorter.hpp:187
Definition: metrics.hpp:35
hashmap< SlaveID, Resources > resources
Definition: sorter.hpp:411
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:335
static ResourceQuantities fromScalarResources(const Resources &resources)
void removeChild(const Node *child)
Definition: sorter.hpp:285
void updateWeight(const std::string &path, double weight) override
Node * parent
Definition: sorter.hpp:240
Definition: sorter.hpp:189
void initialize(const Option< std::set< std::string >> &fairnessExcludeResourceNames) override
Definition: sorter.hpp:181
const ResourceQuantities & allocationScalarQuantities() const override
std::vector< std::string > sort() override
static bool compareDRF(const Node *left, const Node *right)
Definition: sorter.hpp:421
Definition: sorter.hpp:44
ResourceQuantities totals
Definition: sorter.hpp:417
void allocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources) override
Resources scalars() const
void removeSlave(const SlaveID &slaveId) override
const hashmap< SlaveID, Resources > & allocation(const std::string &clientPath) const override
Definition: sorter.hpp:190
Definition: attributes.hpp:24
Resources nonShared() const
std::set< pid_t > children(pid_t, const std::list< Process > &, bool)
Definition: os.hpp:217
Definition: sorter.hpp:42
void activate(const std::string &clientPath) override
const std::string & clientPath() const
Definition: sorter.hpp:265
Kind kind
Definition: sorter.hpp:238
void addChild(Node *child)
Definition: sorter.hpp:294
void update(const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation)
Definition: sorter.hpp:366
void addSlave(const SlaveID &slaveId, const ResourceQuantities &scalarQuantities) override
size_t count() const override
constexpr const char * name
Definition: shell.hpp:41
void add(const std::string &clientPath) override
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37
~Node()
Definition: sorter.hpp:211