Repository: mesos
Updated Branches:
  refs/heads/master 68505cd0a -> c08055396


Include ExecutorInfos in master/state.json

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


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

Branch: refs/heads/master
Commit: c08055396b021def72213e316cba10d58d0daa98
Parents: 68505cd
Author: haosdent huang <[email protected]>
Authored: Sat Jun 20 09:47:43 2015 +0000
Committer: Adam B <[email protected]>
Committed: Sat Jun 20 09:47:43 2015 +0000

----------------------------------------------------------------------
 src/common/http.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++
 src/common/http.hpp |  2 ++
 src/master/http.cpp | 22 +++++++++++++++++
 src/slave/http.cpp  | 63 ------------------------------------------------
 4 files changed, 83 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c0805539/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index c9a441f..4c8102e 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -168,6 +168,65 @@ JSON::Object model(const Task& task)
 }
 
 
+JSON::Object model(const CommandInfo& command)
+{
+  JSON::Object object;
+
+  if (command.has_shell()) {
+    object.values["shell"] = command.shell();
+  }
+
+  if (command.has_value()) {
+    object.values["value"] = command.value();
+  }
+
+  JSON::Array argv;
+  foreach (const string& arg, command.arguments()) {
+    argv.values.push_back(arg);
+  }
+  object.values["argv"] = argv;
+
+  if (command.has_environment()) {
+    JSON::Object environment;
+    JSON::Array variables;
+    foreach(const Environment_Variable& variable,
+            command.environment().variables()) {
+      JSON::Object variableObject;
+      variableObject.values["name"] = variable.name();
+      variableObject.values["value"] = variable.value();
+      variables.values.push_back(variableObject);
+    }
+    environment.values["variables"] = variables;
+    object.values["environment"] = environment;
+  }
+
+  JSON::Array uris;
+  foreach(const CommandInfo_URI& uri, command.uris()) {
+    JSON::Object uriObject;
+    uriObject.values["value"] = uri.value();
+    uriObject.values["executable"] = uri.executable();
+
+    uris.values.push_back(uriObject);
+  }
+  object.values["uris"] = uris;
+
+  return object;
+}
+
+
+JSON::Object model(const ExecutorInfo& executorInfo)
+{
+  JSON::Object object;
+  object.values["executor_id"] = executorInfo.executor_id().value();
+  object.values["name"] = executorInfo.name();
+  object.values["data"] = executorInfo.data();
+  object.values["framework_id"] = executorInfo.framework_id().value();
+  object.values["command"] = model(executorInfo.command());
+  object.values["resources"] = model(executorInfo.resources());
+  return object;
+}
+
+
 // TODO(bmahler): Expose the executor name / source.
 JSON::Object model(
     const TaskInfo& task,

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0805539/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index afce7fe..6f100f7 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -37,6 +37,8 @@ class Task;
 
 JSON::Object model(const Resources& resources);
 JSON::Object model(const Attributes& attributes);
+JSON::Object model(const CommandInfo& command);
+JSON::Object model(const ExecutorInfo& executorInfo);
 
 // These are the two identical ways to model a task, depending on
 // whether you have a 'Task' or a 'TaskInfo' available.

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0805539/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 8b69413..b893013 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -192,6 +192,28 @@ JSON::Object model(const Framework& framework)
     object.values["offers"] = std::move(array);
   }
 
+  // Model all of the executors of a framework.
+  {
+    JSON::Array executors;
+    int executorSize = 0;
+    foreachvalue (const auto& executorsMap,
+                  framework.executors) {
+      executorSize += executorsMap.size();
+    }
+    executors.values.reserve(executorSize); // MESOS-2353
+    foreachpair (const SlaveID& slaveId,
+                 const auto& executorsMap,
+                 framework.executors) {
+      foreachvalue (const ExecutorInfo& executor, executorsMap) {
+        JSON::Object executorJson = model(executor);
+        executorJson.values["slave_id"] = slaveId.value();
+        executors.values.push_back(executorJson);
+      }
+    }
+
+    object.values["executors"] = std::move(executors);
+  }
+
   return object;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c0805539/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index bc25bdd..6245710 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -78,69 +78,6 @@ using process::http::Response;
 using process::http::Request;
 
 
-// TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
-// in becomes available).
-
-
-JSON::Object model(const CommandInfo& command)
-{
-  JSON::Object object;
-
-  if (command.has_shell()) {
-    object.values["shell"] = command.shell();
-  }
-
-  if (command.has_value()) {
-    object.values["value"] = command.value();
-  }
-
-  JSON::Array argv;
-  foreach (const string& arg, command.arguments()) {
-    argv.values.push_back(arg);
-  }
-  object.values["argv"] = argv;
-
-  if (command.has_environment()) {
-    JSON::Object environment;
-    JSON::Array variables;
-    foreach(const Environment_Variable& variable,
-            command.environment().variables()) {
-      JSON::Object variableObject;
-      variableObject.values["name"] = variable.name();
-      variableObject.values["value"] = variable.value();
-      variables.values.push_back(variableObject);
-    }
-    environment.values["variables"] = variables;
-    object.values["environment"] = environment;
-  }
-
-  JSON::Array uris;
-  foreach(const CommandInfo_URI& uri, command.uris()) {
-    JSON::Object uriObject;
-    uriObject.values["value"] = uri.value();
-    uriObject.values["executable"] = uri.executable();
-
-    uris.values.push_back(uriObject);
-  }
-  object.values["uris"] = uris;
-
-  return object;
-}
-
-
-JSON::Object model(const ExecutorInfo& executorInfo)
-{
-  JSON::Object object;
-  object.values["executor_id"] = executorInfo.executor_id().value();
-  object.values["name"] = executorInfo.name();
-  object.values["data"] = executorInfo.data();
-  object.values["framework_id"] = executorInfo.framework_id().value();
-  object.values["command"] = model(executorInfo.command());
-  object.values["resources"] = model(executorInfo.resources());
-  return object;
-}
-
-
 JSON::Object model(const TaskInfo& task)
 {
   JSON::Object object;

Reply via email to