You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by tm...@apache.org on 2013/07/02 05:38:35 UTC

[2/5] git commit: Added a json http endpoint for getting information about roles.

Added a json http endpoint for getting information about roles.

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


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

Branch: refs/heads/master
Commit: 91df0822517996ea86b6556329cffdc7d0d9c233
Parents: 1a153b3
Author: Thomas Marshall <tw...@gmail.com>
Authored: Mon Jul 1 23:29:05 2013 -0400
Committer: Thomas Marshall <tw...@gmail.com>
Committed: Mon Jul 1 23:34:09 2013 -0400

----------------------------------------------------------------------
 src/master/http.cpp   | 41 +++++++++++++++++++++++++++++++++++++++++
 src/master/master.cpp |  1 +
 src/master/master.hpp | 14 ++++++++++++++
 3 files changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/91df0822/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 4317bfc..b5c8db9 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -208,6 +208,27 @@ JSON::Object model(const Slave& slave)
   return object;
 }
 
+// Returns a JSON object modeled after a Role.
+JSON::Object model(const Role& role)
+{
+  JSON::Object object;
+  object.values["name"] = role.info.name();
+  object.values["weight"] = role.info.weight();
+  object.values["resources"] = model(role.resources());
+
+  {
+    JSON::Array array;
+
+    foreachkey (const FrameworkID& frameworkId, role.frameworks) {
+      array.values.push_back(frameworkId.value());
+    }
+
+    object.values["frameworks"] = array;
+  }
+
+  return object;
+}
+
 
 Future<Response> Master::Http::vars(const Request& request)
 {
@@ -364,6 +385,26 @@ Future<Response> Master::Http::state(const Request& request)
   return OK(object, request.query.get("jsonp"));
 }
 
+
+Future<Response> Master::Http::roles(const Request& request)
+{
+  VLOG(1) << "HTTP request for '" << request.path << "'";
+
+  JSON::Object object;
+
+  // Model all of the roles.
+  {
+    JSON::Array array;
+    foreachvalue (Role* role, master.roles) {
+      array.values.push_back(model(*role));
+    }
+
+    object.values["roles"] = array;
+  }
+
+  return OK(object, request.query.get("jsonp"));
+}
+
 } // namespace master {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/91df0822/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 37fb884..f39aa94 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -409,6 +409,7 @@ void Master::initialize()
   route("/vars", None(), bind(&Http::vars, http, params::_1));
   route("/stats.json", None(), bind(&Http::stats, http, params::_1));
   route("/state.json", None(), bind(&Http::state, http, params::_1));
+  route("/roles.json", None(), bind(&Http::roles, http, params::_1));
 
   // Provide HTTP assets from a "webui" directory. This is either
   // specified via flags (which is necessary for running out of the

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/91df0822/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 3d9422f..a076658 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -214,6 +214,10 @@ private:
     process::Future<process::http::Response> state(
         const process::http::Request& request);
 
+    // /master/roles.json
+    process::Future<process::http::Response> roles(
+        const process::http::Request& request);
+
   private:
     const Master& master;
   } http;
@@ -528,6 +532,16 @@ struct Role
     frameworks.erase(framework->id);
   }
 
+  Resources resources() const
+  {
+    Resources resources;
+    foreachvalue (Framework* framework, frameworks) {
+      resources += framework->resources;
+    }
+
+    return resources;
+  }
+
   RoleInfo info;
 
   hashmap<FrameworkID, Framework*> frameworks;