This is an automated email from the ASF dual-hosted git repository. bmahler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit d6738bcc86525e1ac661d2027a1934134426255f Author: Benjamin Mahler <[email protected]> AuthorDate: Wed Jul 10 19:36:54 2019 -0400 Added Role::reserved, Role::allocated, Role::offered to master. This provides a breakdown of resource quantities on a per-role basis, that would aid debugging if shown in the endpoints and roles table in the ui. Review: https://reviews.apache.org/r/71050 --- src/master/master.hpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/master/master.hpp b/src/master/master.hpp index a44caa4..e8def83 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -2779,6 +2779,72 @@ struct Role return resources; } + ResourceQuantities reserved() const + { + const std::string& role = this->role; // For cleaner captures. + + ResourceQuantities total; + + auto reservedToRoleSubtree = [&role](const Resource& r) { + return Resources::isReserved(r) && + (Resources::reservationRole(r) == role || + roles::isStrictSubroleOf(Resources::reservationRole(r), role)); + }; + + foreachvalue (Slave* slave, master->slaves.registered) { + total += ResourceQuantities::fromResources( + slave->totalResources.filter(reservedToRoleSubtree)); + } + + return total; + } + + ResourceQuantities allocated() const + { + const std::string& role = this->role; // For cleaner captures. + + ResourceQuantities total; + + auto allocatedToRoleSubtree = [&role](const Resource& r) { + CHECK(r.has_allocation_info()); + return r.allocation_info().role() == role || + roles::isStrictSubroleOf(r.allocation_info().role(), role); + }; + + // Loop over all frameworks since `frameworks` only tracks + // those that are directly subscribed to this role, and we + // need to sum all descendant role allocations. + foreachvalue (Framework* framework, master->frameworks.registered) { + total += ResourceQuantities::fromResources( + framework->totalUsedResources.filter(allocatedToRoleSubtree)); + } + + return total; + } + + ResourceQuantities offered() const + { + const std::string& role = this->role; // For cleaner captures. + + ResourceQuantities total; + + auto allocatedToRoleSubtree = [&role](const Resource& r) { + CHECK(r.has_allocation_info()); + return r.allocation_info().role() == role || + roles::isStrictSubroleOf(r.allocation_info().role(), role); + }; + + // Loop over all frameworks since `frameworks` only tracks + // those that are directly subscribed to this role, and we + // need to sum all descendant role allocations. + foreachvalue (Framework* framework, master->frameworks.registered) { + total += ResourceQuantities::fromResources( + framework->totalOfferedResources.filter(allocatedToRoleSubtree)); + } + + return total; + } + const Master* master; const std::string role;
