Updated resource model reporting to sum across multiple roles.

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


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

Branch: refs/heads/master
Commit: c1cb7d39e2f1e48738b669f266c09a14738ae82b
Parents: ae5a6d5
Author: Dominic Hamon <dha...@twopensource.com>
Authored: Fri Feb 21 16:41:28 2014 -0800
Committer: Benjamin Mahler <bmah...@twitter.com>
Committed: Fri Feb 21 16:41:28 2014 -0800

----------------------------------------------------------------------
 src/Makefile.am     |   2 +
 src/common/http.cpp | 119 +++++++++++++++++++++++++++++++++++++++++++++++
 src/common/http.hpp |  39 ++++++++++++++++
 src/master/http.cpp |  99 +++------------------------------------
 src/slave/http.cpp  |  76 +++---------------------------
 5 files changed, 173 insertions(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index f1ceab3..61d832b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,6 +186,7 @@ libmesos_no_3rdparty_la_SOURCES =                           
        \
        slave/status_update_manager.cpp                                 \
        exec/exec.cpp                                                   \
        common/lock.cpp                                                 \
+       common/http.cpp                                                 \
        common/date_utils.cpp                                           \
        common/resources.cpp                                            \
        common/attributes.cpp                                           \
@@ -221,6 +222,7 @@ endif
 libmesos_no_3rdparty_la_SOURCES += common/attributes.hpp               \
        common/build.hpp common/date_utils.hpp common/factory.hpp       \
        common/protobuf_utils.hpp                                       \
+       common/http.hpp                                                 \
        common/lock.hpp                                                 \
        common/type_utils.hpp common/thread.hpp                         \
        examples/utils.hpp files/files.hpp                              \

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
new file mode 100644
index 0000000..e81a7ad
--- /dev/null
+++ b/src/common/http.cpp
@@ -0,0 +1,119 @@
+#include "common/http.hpp"
+
+#include <map>
+#include <string>
+
+#include <glog/logging.h>
+
+#include <stout/foreach.hpp>
+#include <stout/stringify.hpp>
+
+#include "common/attributes.hpp"
+
+#include "messages/messages.hpp"
+
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
+using std::map;
+using std::string;
+
+namespace mesos {
+namespace internal {
+
+// TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
+// it becomes available).
+
+JSON::Object model(const Resources& resources)
+{
+  JSON::Object object;
+  object.values["cpus"] = 0;
+  object.values["mem"] = 0;
+  object.values["disk"] = 0;
+
+  const Option<double>& cpus = resources.cpus();
+  if (cpus.isSome()) {
+    object.values["cpus"] = cpus.get();
+  }
+
+  const Option<Bytes>& mem = resources.mem();
+  if (mem.isSome()) {
+    object.values["mem"] = mem.get().megabytes();
+  }
+
+  const Option<Bytes>& disk = resources.disk();
+  if (disk.isSome()) {
+    object.values["disk"] = disk.get().megabytes();
+  }
+
+  const Option<Value::Ranges>& ports = resources.ports();
+  if (ports.isSome()) {
+    object.values["ports"] = stringify(ports.get());
+  }
+
+  return object;
+}
+
+
+JSON::Object model(const Attributes& attributes)
+{
+  JSON::Object object;
+
+  foreach (const Attribute& attribute, attributes) {
+    switch (attribute.type()) {
+      case Value::SCALAR:
+        object.values[attribute.name()] = attribute.scalar().value();
+        break;
+      case Value::RANGES:
+        object.values[attribute.name()] = stringify(attribute.ranges());
+        break;
+      case Value::SET:
+        object.values[attribute.name()] = stringify(attribute.set());
+        break;
+      case Value::TEXT:
+        object.values[attribute.name()] = attribute.text().value();
+        break;
+      default:
+        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
+        break;
+    }
+  }
+
+  return object;
+}
+
+
+// Returns a JSON object modeled on a TaskStatus.
+JSON::Object model(const TaskStatus& status)
+{
+  JSON::Object object;
+  object.values["state"] = TaskState_Name(status.state());
+  object.values["timestamp"] = status.timestamp();
+
+  return object;
+}
+
+
+// TODO(bmahler): Expose the executor name / source.
+JSON::Object model(const Task& task)
+{
+  JSON::Object object;
+  object.values["id"] = task.task_id().value();
+  object.values["name"] = task.name();
+  object.values["framework_id"] = task.framework_id().value();
+  object.values["executor_id"] = task.executor_id().value();
+  object.values["slave_id"] = task.slave_id().value();
+  object.values["state"] = TaskState_Name(task.state());
+  object.values["resources"] = model(task.resources());
+
+  JSON::Array array;
+  foreach (const TaskStatus& status, task.statuses()) {
+    array.values.push_back(model(status));
+  }
+  object.values["statuses"] = array;
+
+  return object;
+}
+
+}  // namespace internal {
+}  // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
new file mode 100644
index 0000000..717bbe9
--- /dev/null
+++ b/src/common/http.hpp
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __COMMON_HTTP_HPP__
+#define __COMMON_HTTP_HPP__
+
+#include <stout/json.hpp>
+
+namespace mesos {
+class Resources;
+
+namespace internal {
+class Attributes;
+class Task;
+
+JSON::Object model(const Resources& resources);
+JSON::Object model(const Attributes& attributes);
+JSON::Object model(const Task& task);
+
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __COMMON_HTTP_HPP__
+

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index c941274..6654cac 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -24,9 +24,6 @@
 
 #include <boost/array.hpp>
 
-#include <mesos/mesos.hpp>
-#include <mesos/resources.hpp>
-
 #include <process/help.hpp>
 
 #include <stout/foreach.hpp>
@@ -40,17 +37,23 @@
 
 #include "common/attributes.hpp"
 #include "common/build.hpp"
-#include "common/type_utils.hpp"
+#include "common/http.hpp"
 #include "common/protobuf_utils.hpp"
+#include "common/type_utils.hpp"
 
 #include "logging/logging.hpp"
 
 #include "master/master.hpp"
 
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
 namespace mesos {
 namespace internal {
 namespace master {
 
+using mesos::internal::model;
+
 using process::Future;
 using process::HELP;
 using process::TLDR;
@@ -71,93 +74,6 @@ using std::vector;
 // TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
 // it becomes available).
 
-// Returns a JSON object modeled on a Resources.
-JSON::Object model(const Resources& resources)
-{
-  JSON::Object object;
-
-  foreach (const Resource& resource, resources) {
-    switch (resource.type()) {
-      case Value::SCALAR:
-        object.values[resource.name()] = resource.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[resource.name()] = stringify(resource.ranges());
-        break;
-      case Value::SET:
-        object.values[resource.name()] = stringify(resource.set());
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << resource.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-JSON::Object model(const Attributes& attributes)
-{
-  JSON::Object object;
-
-  foreach (const Attribute& attribute, attributes) {
-    switch (attribute.type()) {
-      case Value::SCALAR:
-        object.values[attribute.name()] = attribute.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[attribute.name()] = stringify(attribute.ranges());
-        break;
-      case Value::SET:
-        object.values[attribute.name()] = stringify(attribute.set());
-        break;
-      case Value::TEXT:
-        object.values[attribute.name()] = attribute.text().value();
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-// Returns a JSON object modeled on a TaskStatus.
-JSON::Object model(const TaskStatus& status)
-{
-  JSON::Object object;
-  object.values["state"] = TaskState_Name(status.state());
-  object.values["timestamp"] = status.timestamp();
-
-  return object;
-}
-
-
-// Returns a JSON object modeled on a Task.
-// TODO(bmahler): Expose the executor name / source.
-JSON::Object model(const Task& task)
-{
-  JSON::Object object;
-  object.values["id"] = task.task_id().value();
-  object.values["name"] = task.name();
-  object.values["framework_id"] = task.framework_id().value();
-  object.values["executor_id"] = task.executor_id().value();
-  object.values["slave_id"] = task.slave_id().value();
-  object.values["state"] = TaskState_Name(task.state());
-  object.values["resources"] = model(task.resources());
-
-  JSON::Array array;
-  foreach (const TaskStatus& status, task.statuses()) {
-    array.values.push_back(model(status));
-  }
-  object.values["statuses"] = array;
-
-  return object;
-}
-
 
 // Returns a JSON object modeled on an Offer.
 JSON::Object model(const Offer& offer)
@@ -395,7 +311,6 @@ const string Master::Http::REDIRECT_HELP = HELP(
         "this will attempt to redirect to the private IP address."));
 
 
-
 Future<Response> Master::Http::redirect(const Request& request)
 {
   LOG(INFO) << "HTTP request for '" << request.path << "'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 7c4cfba..7ed9abe 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -21,9 +21,6 @@
 #include <string>
 #include <vector>
 
-#include <mesos/mesos.hpp>
-#include <mesos/resources.hpp>
-
 #include <process/help.hpp>
 #include <process/owned.hpp>
 
@@ -36,14 +33,20 @@
 
 #include "common/attributes.hpp"
 #include "common/build.hpp"
+#include "common/http.hpp"
 #include "common/type_utils.hpp"
 
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
 #include "slave/slave.hpp"
 
 namespace mesos {
 namespace internal {
 namespace slave {
 
+using mesos::internal::model;
+
 using process::Future;
 using process::HELP;
 using process::Owned;
@@ -61,59 +64,6 @@ using std::vector;
 // TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
 // in becomes available).
 
-// Returns a JSON object modeled on a Resources.
-JSON::Object model(const Resources& resources)
-{
-  JSON::Object object;
-
-  foreach (const Resource& resource, resources) {
-    switch (resource.type()) {
-      case Value::SCALAR:
-        object.values[resource.name()] = resource.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[resource.name()] = stringify(resource.ranges());
-        break;
-      case Value::SET:
-        object.values[resource.name()] = stringify(resource.set());
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << resource.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-JSON::Object model(const Attributes& attributes)
-{
-  JSON::Object object;
-
-  foreach (const Attribute& attribute, attributes) {
-    switch (attribute.type()) {
-      case Value::SCALAR:
-        object.values[attribute.name()] = attribute.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[attribute.name()] = stringify(attribute.ranges());
-        break;
-      case Value::SET:
-        object.values[attribute.name()] = stringify(attribute.set());
-        break;
-      case Value::TEXT:
-        object.values[attribute.name()] = attribute.text().value();
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
 
 JSON::Object model(const CommandInfo& command)
 {
@@ -161,20 +111,6 @@ JSON::Object model(const ExecutorInfo& executorInfo)
 }
 
 
-JSON::Object model(const Task& task)
-{
-  JSON::Object object;
-  object.values["id"] = task.task_id().value();
-  object.values["name"] = task.name();
-  object.values["executor_id"] = task.executor_id().value();
-  object.values["framework_id"] = task.framework_id().value();
-  object.values["slave_id"] = task.slave_id().value();
-  object.values["state"] = TaskState_Name(task.state());
-  object.values["resources"] = model(task.resources());
-  return object;
-}
-
-
 JSON::Object model(const TaskInfo& task)
 {
   JSON::Object object;

Reply via email to