17 #ifndef __MASTER_ALLOCATOR_MESOS_SORTER_RANDOM_SORTER_HPP__ 18 #define __MASTER_ALLOCATOR_MESOS_SORTER_RANDOM_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;
99 const SlaveID& slaveId,
109 std::vector<std::string>
sort()
override;
111 bool contains(
const std::string& clientPath)
const override;
113 size_t count()
const override;
122 double getWeight(
const Node* node)
const;
131 Node*
find(
const std::string& clientPath)
const;
137 SortInfo(
const RandomSorter* sorter_) : dirty(
true), sorter(sorter_) {}
141 std::pair<std::vector<std::string>, std::vector<double>>
142 getClientsAndWeights();
149 void updateRelativeWeights();
151 std::vector<std::string> clients;
159 std::vector<double> weights;
165 std::mt19937 generator;
208 :
name(_name),
kind(_kind), parent(_parent)
215 if (parent ==
nullptr) {
217 }
else if (parent->parent ==
nullptr) {
274 CHECK(kind == ACTIVE_LEAF || kind == INACTIVE_LEAF);
275 return CHECK_NOTNULL(parent)->path;
283 if (kind == ACTIVE_LEAF || kind == INACTIVE_LEAF) {
284 CHECK(children.empty());
294 auto it =
std::find(children.begin(), children.end(), child);
295 CHECK(it != children.end());
303 auto it =
std::find(children.begin(), children.end(), child);
304 CHECK(it == children.end());
309 if (child->
kind == INACTIVE_LEAF) {
310 children.push_back(child);
312 children.insert(children.begin(), child);
326 .
filter([
this, slaveId](
const Resource& resource) {
327 return !resources[slaveId].contains(resource);
332 (toAdd.
nonShared() + sharedToAdd).scalars());
334 resources[slaveId] += toAdd;
335 totals += quantitiesToAdd;
340 CHECK(resources.contains(slaveId))
341 <<
"Resources " << resources <<
" does not contain " << slaveId;
342 CHECK(resources.at(slaveId).contains(toRemove))
343 <<
"Resources " << resources.at(slaveId) <<
" at agent " << slaveId
344 <<
" does not contain " << toRemove;
346 resources[slaveId] -= toRemove;
351 .
filter([
this, slaveId](
const Resource& resource) {
352 return !resources[slaveId].contains(resource);
357 (toRemove.nonShared() + sharedToRemove).scalars());
359 CHECK(totals.contains(quantitiesToRemove))
360 << totals <<
" does not contain " << quantitiesToRemove;
362 totals -= quantitiesToRemove;
364 if (resources.at(slaveId).empty()) {
365 resources.erase(slaveId);
370 const SlaveID& slaveId,
379 CHECK(resources.contains(slaveId))
380 <<
"Resources " << resources <<
" does not contain " << slaveId;
381 CHECK(resources[slaveId].
contains(oldAllocation))
382 <<
"Resources " << resources[slaveId] <<
" at agent " << slaveId
383 <<
" does not contain " << oldAllocation;
385 CHECK(totals.contains(oldAllocationQuantities))
386 << totals <<
" does not contain " << oldAllocationQuantities;
388 resources[slaveId] -= oldAllocation;
389 resources[slaveId] += newAllocation;
393 if (resources.at(slaveId).empty()) {
394 resources.erase(slaveId);
397 totals -= oldAllocationQuantities;
398 totals += newAllocationQuantities;
420 #endif // __MASTER_ALLOCATOR_MESOS_SORTER_RANDOM_SORTER_HPP__ const hashmap< SlaveID, Resources > & allocation(const std::string &clientPath) const override
Definition: sorter.hpp:194
Node * parent
Definition: sorter.hpp:250
Definition: sorter.hpp:202
Definition: option.hpp:29
void updateWeight(const std::string &path, double weight) override
Definition: master.hpp:27
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:307
Definition: hashset.hpp:53
Definition: resource_quantities.hpp:63
void removeSlave(const SlaveID &slaveId) override
Definition: sorter.hpp:102
bool isLeaf() const
Definition: sorter.hpp:281
Resources filter(const lambda::function< bool(const Resource &)> &predicate) const
Definition: sorter.hpp:203
Definition: resources.hpp:83
Definition: sorter.hpp:44
void initialize(const Option< std::set< std::string >> &fairnessExcludeResourceNames) override
const std::string & clientPath() const
Definition: sorter.hpp:271
Definition: hashmap.hpp:38
void unallocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources) override
Definition: sorter.hpp:317
~Node()
Definition: sorter.hpp:224
void activate(const std::string &clientPath) override
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
static ResourceQuantities fromScalarResources(const Resources &resources)
void allocated(const std::string &clientPath, const SlaveID &slaveId, const Resources &resources) override
void removeChild(const Node *child)
Definition: sorter.hpp:291
bool contains(const std::string &clientPath) const override
void addChild(Node *child)
Definition: sorter.hpp:300
Option< double > weight
Definition: sorter.hpp:246
void update(const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation)
Definition: sorter.hpp:369
std::vector< Node * > children
Definition: sorter.hpp:260
void deactivate(const std::string &clientPath) override
size_t count() const override
std::vector< std::string > sort() override
std::string name
Definition: sorter.hpp:236
Allocation()
Definition: sorter.hpp:319
Resources scalars() const
const ResourceQuantities & allocationScalarQuantities() const override
void add(const std::string &clientPath) override
Definition: attributes.hpp:24
Node(const std::string &_name, Kind _kind, Node *_parent)
Definition: sorter.hpp:207
void subtract(const SlaveID &slaveId, const Resources &toRemove)
Definition: sorter.hpp:338
Resources nonShared() const
std::set< pid_t > children(pid_t, const std::list< Process > &, bool)
Definition: os.hpp:217
Kind kind
Definition: sorter.hpp:248
Definition: sorter.hpp:42
hashmap< SlaveID, Resources > resources
Definition: sorter.hpp:405
std::string path
Definition: sorter.hpp:240
ResourceQuantities totals
Definition: sorter.hpp:411
constexpr const char * name
Definition: shell.hpp:41
Kind
Definition: sorter.hpp:200
Try< std::list< std::string > > find(const std::string &directory, const std::string &pattern)
Definition: find.hpp:37
void addSlave(const SlaveID &slaveId, const ResourceQuantities &scalarQuantities) override
Definition: sorter.hpp:98
void add(const SlaveID &slaveId, const Resources &toAdd)
Definition: sorter.hpp:321
void update(const std::string &clientPath, const SlaveID &slaveId, const Resources &oldAllocation, const Resources &newAllocation) override