You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/02/10 17:15:54 UTC
mesos git commit: Added /master/slaves endpoint.
Repository: mesos
Updated Branches:
refs/heads/master a7b98e11e -> 4ed152304
Added /master/slaves endpoint.
Review: https://reviews.apache.org/r/29883
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4ed15230
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4ed15230
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4ed15230
Branch: refs/heads/master
Commit: 4ed152304ef97178599a99e5a56dfba333e27bf3
Parents: a7b98e1
Author: Alexander Rojas <al...@mesosphere.io>
Authored: Tue Feb 10 08:15:28 2015 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Tue Feb 10 08:15:31 2015 -0800
----------------------------------------------------------------------
src/master/http.cpp | 26 +++++++++++++
src/master/master.cpp | 3 ++
src/master/master.hpp | 5 +++
src/tests/master_tests.cpp | 82 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 116 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4ed15230/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 6d7b9f6..ff9f053 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -366,6 +366,32 @@ Future<Response> Master::Http::redirect(const Request& request)
}
+const string Master::Http::SLAVES_HELP = HELP(
+ TLDR(
+ "Information about registered slaves."),
+ USAGE(
+ "/master/slaves"),
+ DESCRIPTION(
+ "This endpoint shows information about the slaves registered in",
+ "this master formated as a json object."));
+
+
+Future<Response> Master::Http::slaves(const Request& request) {
+ LOG(INFO) << "HTTP request for '" << request.path << "'";
+
+ JSON::Array array;
+ foreachvalue (const Slave* slave, master->slaves.registered) {
+ JSON::Object object = model(*slave);
+ array.values.push_back(object);
+ }
+
+ JSON::Object object;
+ object.values["slaves"] = array;
+
+ return OK(object, request.query.get("jsonp"));
+}
+
+
// Declaration of 'stats' continuation.
static Future<Response> _stats(
const Request& request,
http://git-wip-us.apache.org/repos/asf/mesos/blob/4ed15230/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 7c3aa22..68bd6f5 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -727,6 +727,9 @@ void Master::initialize()
route("/shutdown",
Http::SHUTDOWN_HELP,
lambda::bind(&Http::shutdown, http, lambda::_1));
+ route("/slaves",
+ Http::SLAVES_HELP,
+ lambda::bind(&Http::slaves, http, lambda::_1));
route("/state.json",
None(),
lambda::bind(&Http::state, http, lambda::_1));
http://git-wip-us.apache.org/repos/asf/mesos/blob/4ed15230/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 6beeb1b..00b07d0 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -479,6 +479,10 @@ private:
process::Future<process::http::Response> shutdown(
const process::http::Request& request);
+ // /master/slaves
+ process::Future<process::http::Response> slaves(
+ const process::http::Request& request);
+
// /master/state.json
process::Future<process::http::Response> state(
const process::http::Request& request);
@@ -495,6 +499,7 @@ private:
const static std::string OBSERVE_HELP;
const static std::string REDIRECT_HELP;
const static std::string SHUTDOWN_HELP;
+ const static std::string SLAVES_HELP;
const static std::string TASKS_HELP;
private:
http://git-wip-us.apache.org/repos/asf/mesos/blob/4ed15230/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index b52d2ca..18eabd4 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -1567,6 +1567,88 @@ TEST_F(MasterTest, MetricsInStatsEndpoint)
}
+// Ensures that an empty response arrives if information about
+// registered slaves is requested from a master where no slaves
+// have been registered.
+TEST_F(MasterTest, SlavesEndpointWithoutSlaves)
+{
+ // Start up.
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ // Query the master.
+ const Future<process::http::Response> response =
+ process::http::get(master.get(), "slaves");
+
+ AWAIT_READY(response);
+
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
+
+ const Try<JSON::Value> parse =
+ JSON::parse(response.get().body);
+ ASSERT_SOME(parse);
+
+ Try<JSON::Value> expected = JSON::parse(
+ "{"
+ " \"slaves\" : []"
+ "}");
+
+ ASSERT_SOME(expected);
+ EXPECT_SOME_EQ(expected.get(), parse);
+
+ Shutdown();
+}
+
+
+// Ensures that the number of registered slaves resported by
+// /master/slaves coincides with the actual number of registered
+// slaves.
+TEST_F(MasterTest, SlavesEndpointTwoSlaves)
+{
+ // Start up the master.
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ // Start a couple of slaves. Their only use is for them to register
+ // to the master.
+ Future<SlaveRegisteredMessage> slave1RegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), master.get(), _);
+ Future<SlaveRegisteredMessage> slave2RegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), master.get(), _);
+
+ StartSlave();
+ StartSlave();
+
+ // Wait for the slaves to be registered.
+ AWAIT_READY(slave1RegisteredMessage);
+ AWAIT_READY(slave2RegisteredMessage);
+
+ // Query the master.
+ const Future<process::http::Response> response =
+ process::http::get(master.get(), "slaves");
+
+ AWAIT_READY(response);
+
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
+
+ const Try<JSON::Object> parse =
+ JSON::parse<JSON::Object>(response.get().body);
+
+ ASSERT_SOME(parse);
+
+ // Check that there are at least two elements in the array.
+ Result<JSON::Array> array = parse.get().find<JSON::Array>("slaves");
+ ASSERT_SOME(array);
+ EXPECT_EQ(2u, array.get().values.size());
+
+ Shutdown();
+}
+
+
// This test ensures that when a slave is recovered from the registry
// but does not re-register with the master, it is removed from the
// registry and the framework is informed that the slave is lost, and