You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mz...@apache.org on 2019/08/20 00:10:20 UTC

[mesos] 02/04: Added method to dump role tree state for debugging.

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 734523178f2e8e722fb4d15d00194e3e019ef722
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Mon Aug 19 13:55:25 2019 -0700

    Added method to dump role tree state for debugging.
    
    It dumps the role tree state in JSON format. This can potentially
    be added to an allocator debug endpoint.
    
    Review: https://reviews.apache.org/r/71311
---
 src/master/allocator/mesos/hierarchical.cpp | 33 +++++++++++++++++++++++++++++
 src/master/allocator/mesos/hierarchical.hpp |  3 +++
 2 files changed, 36 insertions(+)

diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 5127dfb..852d426 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -42,6 +42,7 @@
 #include <stout/stopwatch.hpp>
 #include <stout/stringify.hpp>
 
+#include "common/http.hpp"
 #include "common/protobuf_utils.hpp"
 #include "common/resources_utils.hpp"
 
@@ -390,6 +391,38 @@ void RoleTree::updateWeight(const string& role, double weight)
 }
 
 
+std::string RoleTree::toJSON() const
+{
+  std::function<void(JSON::ObjectWriter*, const Role*)> json =
+    [&](JSON::ObjectWriter* writer, const Role* role) {
+      writer->field("basename", role->basename);
+      writer->field("role", role->role);
+      writer->field("weight", role->weight_);
+      writer->field("guarantees", role->quota_.guarantees);
+      writer->field("limits", role->quota_.limits);
+      writer->field(
+          "reservation_quantities", role->reservationScalarQuantities_);
+
+      writer->field("frameworks", [&](JSON::ArrayWriter* writer) {
+        foreach (const FrameworkID& id, role->frameworks_) {
+          writer->element(id.value());
+        }
+      });
+
+      writer->field("children", [&](JSON::ArrayWriter* writer) {
+        foreachvalue (const Role* child, role->children_) {
+          writer->element(
+              [&](JSON::ObjectWriter* writer) { json(writer, child); });
+        }
+      });
+    };
+
+  auto tree = [&](JSON::ObjectWriter* writer) { json(writer, root_); };
+
+  return jsonify(tree);
+}
+
+
 Framework::Framework(
     const FrameworkInfo& frameworkInfo,
     const set<string>& _suppressedRoles,
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 46ce5fc..db26a2a 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -213,6 +213,9 @@ public:
 
   void updateWeight(const std::string& role, double weight);
 
+  // Dump the role tree state in JSON format for debugging.
+  std::string toJSON() const;
+
 private:
   // Lookup or add the role struct associated with the role. Ancestor roles
   // along the tree path will be created if necessary.