This is an automated email from the ASF dual-hosted git repository. mzhu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit f4db86c525affd8b875b6ddb8f1a608eee830ce6 Author: Meng Zhu <[email protected]> AuthorDate: Mon Aug 19 13:57:07 2019 -0700 Made RoleTree class default constructable. This makes the metric handler optional. This is mainly for unit testing purpose. Review: https://reviews.apache.org/r/71312 --- src/master/allocator/mesos/hierarchical.cpp | 14 ++++++++++++-- src/master/allocator/mesos/hierarchical.hpp | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp index 852d426..b8b9241 100644 --- a/src/master/allocator/mesos/hierarchical.cpp +++ b/src/master/allocator/mesos/hierarchical.cpp @@ -224,6 +224,9 @@ void Role::removeChild(Role* child) } +RoleTree::RoleTree() : root_(new Role("", nullptr)) {} + + RoleTree::RoleTree(Metrics* metrics_) : root_(new Role("", nullptr)), metrics(metrics_) {} @@ -268,7 +271,10 @@ Role& RoleTree::operator[](const std::string& rolePath) current == root_ ? token : strings::join("/", current->role, token); CHECK_NOT_CONTAINS(roles_, newRolePath); roles_.put(newRolePath, Role(newRolePath, current)); - metrics->addRole(newRolePath); + + if (metrics.isSome()) { + (*metrics)->addRole(newRolePath); + } Role& role = roles_.at(newRolePath); current->addChild(&role); @@ -300,7 +306,11 @@ bool RoleTree::tryRemove(const std::string& role) Role* parent = CHECK_NOTNULL(current->parent); parent->removeChild(current); - metrics->removeRole(current->role); + + if (metrics.isSome()) { + (*metrics)->removeRole(current->role); + } + roles_.erase(current->role); current = parent; diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index db26a2a..035fd3d 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -188,6 +188,8 @@ private: class RoleTree { public: + RoleTree(); // Only used in tests. + RoleTree(Metrics* metrics); ~RoleTree(); @@ -234,7 +236,7 @@ private: Role* root_; // Allocator's metrics handle for publishing role related metrics. - Metrics* metrics; + Option<Metrics*> metrics; // A map of role and `Role` pairs for quick lookup. hashmap<std::string, Role> roles_;
