You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/02/14 00:32:12 UTC

mesos git commit: Added agent capabilities to /state endpoint of master.

Repository: mesos
Updated Branches:
  refs/heads/master 17394a11e -> b3929ac54


Added agent capabilities to /state endpoint of master.

Master should be able to reflect agent capabilities via  `/state`(v0)
and `getState`(v1) endpoints.

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


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

Branch: refs/heads/master
Commit: b3929ac541977320af6155d6123172e6163b7d3b
Parents: 17394a1
Author: Jay Guo <gu...@gmail.com>
Authored: Mon Feb 13 16:24:36 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Feb 13 16:32:05 2017 -0800

----------------------------------------------------------------------
 include/mesos/master/master.proto    |  2 ++
 include/mesos/v1/master/master.proto |  2 ++
 src/common/protobuf_utils.cpp        |  3 +++
 src/common/protobuf_utils.hpp        | 11 ++++++++
 src/master/http.cpp                  | 12 ++++++++-
 src/tests/master_tests.cpp           | 43 +++++++++++++++++++++++++++++++
 6 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/include/mesos/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/master/master.proto b/include/mesos/master/master.proto
index a2228db..472348b 100644
--- a/include/mesos/master/master.proto
+++ b/include/mesos/master/master.proto
@@ -306,6 +306,8 @@ message Response {
 
       repeated Resource allocated_resources = 8;
       repeated Resource offered_resources = 9;
+
+      repeated SlaveInfo.Capability capabilities = 10;
     }
 
     // Registered agents.

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/include/mesos/v1/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/master/master.proto b/include/mesos/v1/master/master.proto
index cfdca74..9d2f38e 100644
--- a/include/mesos/v1/master/master.proto
+++ b/include/mesos/v1/master/master.proto
@@ -306,6 +306,8 @@ message Response {
 
       repeated Resource allocated_resources = 8;
       repeated Resource offered_resources = 9;
+
+      repeated AgentInfo.Capability capabilities = 10;
     }
 
     // Registered agents.

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
index ed84e9a..4421849 100644
--- a/src/common/protobuf_utils.cpp
+++ b/src/common/protobuf_utils.cpp
@@ -651,6 +651,9 @@ mesos::master::Response::GetAgents::Agent createAgentResponse(
     agent.add_offered_resources()->CopyFrom(resource);
   }
 
+  agent.mutable_capabilities()->CopyFrom(
+      slave.capabilities.toRepeatedPtrField());
+
   return agent;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/src/common/protobuf_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.hpp b/src/common/protobuf_utils.hpp
index 3ba689f..4f69483 100644
--- a/src/common/protobuf_utils.hpp
+++ b/src/common/protobuf_utils.hpp
@@ -159,6 +159,17 @@ struct Capabilities
 
   // See mesos.proto for the meaning of agent capabilities.
   bool multiRole = false;
+
+  google::protobuf::RepeatedPtrField<SlaveInfo::Capability>
+  toRepeatedPtrField() const
+  {
+    google::protobuf::RepeatedPtrField<SlaveInfo::Capability> result;
+    if (multiRole) {
+      result.Add()->set_type(SlaveInfo::Capability::MULTI_ROLE);
+    }
+
+    return result;
+  }
 };
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index c5324ab..caa1fab 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -127,12 +127,21 @@ using std::vector;
 namespace mesos {
 
 static void json(
-    JSON::StringWriter* writer, const FrameworkInfo::Capability& capability)
+    JSON::StringWriter* writer,
+    const FrameworkInfo::Capability& capability)
 {
   writer->append(FrameworkInfo::Capability::Type_Name(capability.type()));
 }
 
 
+static void json(
+    JSON::StringWriter* writer,
+    const SlaveInfo::Capability& capability)
+{
+  writer->append(SlaveInfo::Capability::Type_Name(capability.type()));
+}
+
+
 static void json(JSON::ObjectWriter* writer, const Offer& offer)
 {
   writer->field("id", offer.id().value());
@@ -377,6 +386,7 @@ static void json(JSON::ObjectWriter* writer, const Summary<Slave>& summary)
 
   writer->field("active", slave.active);
   writer->field("version", slave.version);
+  writer->field("capabilities", slave.capabilities.toRepeatedPtrField());
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3929ac5/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 9a7a953..c8ef9d6 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -4055,6 +4055,49 @@ TEST_F(MasterTest, StateSummaryEndpoint)
 }
 
 
+// This ensures that agent capabilities are included in
+// the response of master's /state endpoint.
+TEST_F(MasterTest, StateEndpointAgentCapabilities)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+    FUTURE_PROTOBUF(SlaveRegisteredMessage(), master.get()->pid, _);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
+  ASSERT_SOME(slave);
+
+  AWAIT_READY(slaveRegisteredMessage);
+
+  Future<Response> response = process::http::get(
+      master.get()->pid,
+      "state",
+      None(),
+      createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+
+  Try<JSON::Object> parse = JSON::parse<JSON::Object>(response->body);
+  ASSERT_SOME(parse);
+
+  Result<JSON::Array> slaveArray = parse->find<JSON::Array>("slaves");
+  ASSERT_SOME(slaveArray);
+  EXPECT_EQ(1u, slaveArray->values.size());
+
+  JSON::Object slaveInfo = slaveArray->values[0].as<JSON::Object>();
+
+  ASSERT_EQ(1u, slaveInfo.values.count("capabilities"));
+  JSON::Value slaveCapabilities = slaveInfo.values.at("capabilities");
+
+  // Agents should always have MULTI_ROLE capability in current implementation.
+  Try<JSON::Value> expectedCapabilities = JSON::parse("[\"MULTI_ROLE\"]");
+  ASSERT_SOME(expectedCapabilities);
+  EXPECT_TRUE(slaveCapabilities.contains(expectedCapabilities.get()));
+}
+
+
 // This test verifies that recovered but yet to reregister agents are returned
 // in `recovered_slaves` field of `/state` and `/slaves` endpoints.
 TEST_F(MasterTest, RecoveredSlaves)