Repository: mesos
Updated Branches:
  refs/heads/master 3758aa1c9 -> b2fc58883


Show the leading master's information in `/master/state` endpoint.

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


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

Branch: refs/heads/master
Commit: 34eb567c4e0ed605eeed02a20213f28d51a4e305
Parents: 3758aa1
Author: haosdent huang <haosd...@gmail.com>
Authored: Thu Oct 27 10:22:09 2016 -0700
Committer: Vinod Kone <vinodk...@gmail.com>
Committed: Thu Oct 27 10:22:09 2016 -0700

----------------------------------------------------------------------
 src/master/http.cpp        | 16 ++++++++++++++++
 src/tests/master_tests.cpp |  9 ++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/34eb567c/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 05d2990..716077a 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -143,6 +143,15 @@ static void json(JSON::ObjectWriter* writer, const Offer& 
offer)
   writer->field("resources", Resources(offer.resources()));
 }
 
+
+static void json(JSON::ObjectWriter* writer, const MasterInfo& info)
+{
+  writer->field("id", info.id());
+  writer->field("pid", info.pid());
+  writer->field("port", info.port());
+  writer->field("hostname", info.hostname());
+}
+
 namespace internal {
 namespace master {
 
@@ -2606,10 +2615,17 @@ Future<Response> Master::Http::state(
         writer->field("activated_slaves", master->_slaves_active());
         writer->field("deactivated_slaves", master->_slaves_inactive());
 
+        // TODO(haosdent): Deprecated this in favor of `leader_info` below.
         if (master->leader.isSome()) {
           writer->field("leader", master->leader.get().pid());
         }
 
+        if (master->leader.isSome()) {
+          writer->field("leader_info", [this](JSON::ObjectWriter* writer) {
+            json(writer, master->leader.get());
+          });
+        }
+
         if (approveViewFlags(flagsApprover)) {
           if (master->flags.cluster.isSome()) {
             writer->field("cluster", master->flags.cluster.get());

http://git-wip-us.apache.org/repos/asf/mesos/blob/34eb567c/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 56126de..968192c 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -3510,12 +3510,19 @@ TEST_F(MasterTest, StateEndpoint)
   EXPECT_EQ(stringify(master.get()->pid), state.values["pid"]);
   EXPECT_EQ(flags.hostname.get(), state.values["hostname"]);
 
+  JSON::Object leader = state.values["leader_info"].as<JSON::Object>();
+
+  EXPECT_EQ(flags.hostname.get(), leader.values["hostname"]);
+  EXPECT_EQ(
+      master.get()->pid.address.port,
+      leader.values["port"].as<JSON::Number>().as<int>());
+
   EXPECT_EQ(0, state.values["activated_slaves"]);
   EXPECT_EQ(0, state.values["deactivated_slaves"]);
 
   EXPECT_EQ(flags.cluster.get(), state.values["cluster"]);
 
-  // TODO(bmahler): Test "leader", "log_dir", "external_log_file".
+  // TODO(bmahler): Test "log_dir", "external_log_file".
 
   // TODO(bmahler): Ensure this contains all the flags.
   ASSERT_TRUE(state.values["flags"].is<JSON::Object>());

Reply via email to