You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/02/05 06:18:42 UTC

[2/8] mesos git commit: Added json() function for jsonification of the global help process.

Added json() function for jsonification of the global help process.

This will be used to dump the help strings into a JSON object when
hitting the /help endpoint with a specific request for JSON data.

Review: https://reviews.apache.org/r/43216/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/24fff875
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/24fff875
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/24fff875

Branch: refs/heads/master
Commit: 24fff8758ff4aef93822eeb79f966f764ff306d8
Parents: 0f53c9a
Author: Kevin Klues <kl...@gmail.com>
Authored: Thu Feb 4 19:24:32 2016 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Feb 4 21:18:17 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/help.hpp |  4 +++
 3rdparty/libprocess/src/help.cpp             | 39 +++++++++++++++++++++++
 2 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/24fff875/3rdparty/libprocess/include/process/help.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/help.hpp b/3rdparty/libprocess/include/process/help.hpp
index 414d14e..93306ad 100644
--- a/3rdparty/libprocess/include/process/help.hpp
+++ b/3rdparty/libprocess/include/process/help.hpp
@@ -103,6 +103,10 @@ public:
   // Remove all previously installed 'help' strings for '/id/*'.
   bool remove(const std::string& id);
 
+  // Allow the global json function to dump this object to its
+  // canonical JSON representation.
+  friend void json(JSON::ObjectWriter* writer, const Help& help);
+
 protected:
   virtual void initialize();
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/24fff875/3rdparty/libprocess/src/help.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/help.cpp b/3rdparty/libprocess/src/help.cpp
index ec1c2d4..85d6bcb 100644
--- a/3rdparty/libprocess/src/help.cpp
+++ b/3rdparty/libprocess/src/help.cpp
@@ -16,6 +16,7 @@
 
 #include <process/help.hpp>
 
+#include <map>
 #include <string>
 #include <vector>
 
@@ -30,6 +31,7 @@
 #include <stout/stringify.hpp>
 #include <stout/strings.hpp>
 
+using std::map;
 using std::string;
 using std::vector;
 
@@ -128,6 +130,43 @@ void Help::initialize()
 }
 
 
+// Write the help strings contained in the help process to JSON.
+// The schema looks as follows:
+// {
+//   "processes":
+//   [
+//     {
+//       "id": id,
+//       "endpoints": [ { "name" : name, "text" : text }, ... ]
+//     },
+//     ...
+//   ]
+// }
+void json(JSON::ObjectWriter* writer, const Help& help)
+{
+  // We must declare this temporary typedef in order to make the
+  // foreachpair macro happy. Otherwise it interprets the ',' in the
+  // map definition to denote a new parameter in the macro invocation.
+  typedef map<string, string> StringStringMap;
+
+  writer->field("processes", [&help](JSON::ArrayWriter* writer) {
+    foreachpair (const string& id, const StringStringMap& names, help.helps) {
+      writer->element([&id, &names](JSON::ObjectWriter* writer) {
+        writer->field("id", id);
+        writer->field("endpoints", [&names](JSON::ArrayWriter* writer) {
+          foreachpair (const string& name, const string& text, names) {
+            writer->element([&name, &text](JSON::ObjectWriter* writer) {
+              writer->field("name", name);
+              writer->field("text", text);
+            });
+          }
+        });
+      });
+    }
+  });
+}
+
+
 Future<http::Response> Help::help(const http::Request& request)
 {
   // Split the path by '/'.