You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/06/26 03:29:44 UTC
mesos git commit: Added reservations support to master's state.json.
Repository: mesos
Updated Branches:
refs/heads/master f62530487 -> bdf2ea144
Added reservations support to master's state.json.
Review: https://reviews.apache.org/r/35717
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bdf2ea14
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bdf2ea14
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bdf2ea14
Branch: refs/heads/master
Commit: bdf2ea1448990f0717f43c27d5b0d0348f15332d
Parents: f625304
Author: haosdent huang <ha...@gmail.com>
Authored: Thu Jun 25 18:05:53 2015 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Thu Jun 25 18:05:53 2015 -0700
----------------------------------------------------------------------
src/common/http.cpp | 12 ++++++++++++
src/common/http.hpp | 2 ++
src/master/http.cpp | 5 ++++-
src/tests/common/http_tests.cpp | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/bdf2ea14/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index d667cc1..1585999 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -80,6 +80,18 @@ JSON::Object model(const Resources& resources)
}
+JSON::Object model(const hashmap<string, Resources>& resourcesMap)
+{
+ JSON::Object object;
+
+ foreachpair (const string& key, const Resources& resources, resourcesMap) {
+ object.values[key] = model(resources);
+ }
+
+ return object;
+}
+
+
JSON::Object model(const Attributes& attributes)
{
JSON::Object object;
http://git-wip-us.apache.org/repos/asf/mesos/blob/bdf2ea14/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 6f100f7..c400848 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -23,6 +23,7 @@
#include <mesos/mesos.hpp>
+#include <stout/hashmap.hpp>
#include <stout/json.hpp>
namespace mesos {
@@ -36,6 +37,7 @@ class Task;
JSON::Object model(const Resources& resources);
+JSON::Object model(const hashmap<std::string, Resources>& resourcesMap);
JSON::Object model(const Attributes& attributes);
JSON::Object model(const CommandInfo& command);
JSON::Object model(const ExecutorInfo& executorInfo);
http://git-wip-us.apache.org/repos/asf/mesos/blob/bdf2ea14/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index b893013..3503833 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -231,9 +231,12 @@ JSON::Object summarize(const Slave& slave)
object.values["reregistered_time"] = slave.reregisteredTime.get().secs();
}
- object.values["resources"] = model(slave.info.resources());
+ const Resources& totalResources = slave.totalResources;
+ object.values["resources"] = model(totalResources);
object.values["used_resources"] = model(Resources::sum(slave.usedResources));
object.values["offered_resources"] = model(slave.offeredResources);
+ object.values["reserved_resources"] = model(totalResources.reserved());
+ object.values["unreserved_resources"] = model(totalResources.unreserved());
object.values["attributes"] = model(slave.info.attributes());
object.values["active"] = slave.active;
http://git-wip-us.apache.org/repos/asf/mesos/blob/bdf2ea14/src/tests/common/http_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/common/http_tests.cpp b/src/tests/common/http_tests.cpp
index 97a0eba..40872eb 100644
--- a/src/tests/common/http_tests.cpp
+++ b/src/tests/common/http_tests.cpp
@@ -148,3 +148,39 @@ TEST(HTTP, ModelResources)
ASSERT_SOME(expected);
EXPECT_EQ(expected.get(), object);
}
+
+
+// This test verifies that ResourcesMap model are divided by keys.
+TEST(HTTP, ModelResourcesMap)
+{
+ Resources fooResources = Resources::parse(
+ "cpus(foo):1;ports(foo):[1-10]").get();
+ Resources barResources = Resources::parse(
+ "mem(bar):512;disk(bar):1024").get();
+
+ hashmap<std::string, Resources> resourcesMap;
+ resourcesMap["foo"] = fooResources;
+ resourcesMap["bar"] = barResources;
+
+ JSON::Value object = model(resourcesMap);
+
+ Try<JSON::Value> expected = JSON::parse(
+ "{"
+ " \"foo\":"
+ " {"
+ " \"cpus\":1,"
+ " \"disk\":0,"
+ " \"mem\":0,"
+ " \"ports\":\"[1-10]\""
+ " },"
+ " \"bar\":"
+ " {"
+ " \"cpus\":0,"
+ " \"mem\":512,"
+ " \"disk\":1024"
+ " }"
+ "}");
+
+ ASSERT_SOME(expected);
+ EXPECT_EQ(expected.get(), object);
+}