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/21 21:04:06 UTC

[1/2] mesos git commit: Added a constant to store agent capabilities.

Repository: mesos
Updated Branches:
  refs/heads/master cdbacc092 -> 5ad643fd7


Added a constant to store agent capabilities.

Instead of hardcoding in code, agent capabilities are stored in a
constant and could be used by both agent initialization and http
response generation.

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


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

Branch: refs/heads/master
Commit: 16c59fcefd75f00a2873e04b4943e51fd54b5046
Parents: cdbacc0
Author: Jay Guo <gu...@gmail.com>
Authored: Tue Feb 21 13:00:49 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Feb 21 13:01:45 2017 -0800

----------------------------------------------------------------------
 src/slave/constants.hpp |  5 +++++
 src/slave/slave.cpp     | 14 ++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/16c59fce/src/slave/constants.hpp
----------------------------------------------------------------------
diff --git a/src/slave/constants.hpp b/src/slave/constants.hpp
index 725689a..753756d 100644
--- a/src/slave/constants.hpp
+++ b/src/slave/constants.hpp
@@ -19,6 +19,8 @@
 
 #include <stdint.h>
 
+#include <mesos/mesos.hpp>
+
 #include <stout/bytes.hpp>
 #include <stout/duration.hpp>
 
@@ -149,6 +151,9 @@ Duration DEFAULT_MASTER_PING_TIMEOUT();
 // Name of the executable for default executor.
 constexpr char MESOS_DEFAULT_EXECUTOR[] = "mesos-default-executor";
 
+constexpr SlaveInfo::Capability::Type MESOS_AGENT_CAPABILITIES[] =
+  {SlaveInfo::Capability::MULTI_ROLE};
+
 } // namespace slave {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/16c59fce/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 7564e8d..4590529 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -1388,8 +1388,11 @@ void Slave::doReliableRegistration(Duration maxBackoff)
     // Registering for the first time.
     RegisterSlaveMessage message;
     message.set_version(MESOS_VERSION);
-    message.add_agent_capabilities()->set_type(
-        SlaveInfo::Capability::MULTI_ROLE);
+
+    foreach (const SlaveInfo::Capability::Type& capability,
+             MESOS_AGENT_CAPABILITIES) {
+      message.add_agent_capabilities()->set_type(capability);
+    }
 
     message.mutable_slave()->CopyFrom(info);
 
@@ -1401,8 +1404,11 @@ void Slave::doReliableRegistration(Duration maxBackoff)
     // Re-registering, so send tasks running.
     ReregisterSlaveMessage message;
     message.set_version(MESOS_VERSION);
-    message.add_agent_capabilities()->set_type(
-        SlaveInfo::Capability::MULTI_ROLE);
+
+    foreach (const SlaveInfo::Capability::Type& capability,
+             MESOS_AGENT_CAPABILITIES) {
+      message.add_agent_capabilities()->set_type(capability);
+    }
 
     // Include checkpointed resources.
     message.mutable_checkpointed_resources()->CopyFrom(checkpointedResources);


[2/2] mesos git commit: Added agent capabilities to `/state`(v0) endpoint of agent.

Posted by bm...@apache.org.
Added agent capabilities to `/state`(v0) endpoint of agent.

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


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

Branch: refs/heads/master
Commit: 5ad643fd7b83cf87a820c82e3c980e2ad21899f4
Parents: 16c59fc
Author: Jay Guo <gu...@gmail.com>
Authored: Tue Feb 21 13:03:07 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Feb 21 13:03:07 2017 -0800

----------------------------------------------------------------------
 src/slave/http.cpp        | 8 ++++++++
 src/tests/slave_tests.cpp | 9 +++++++++
 2 files changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5ad643fd/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index af70b6f..8a9fabf 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -138,6 +138,13 @@ static void json(JSON::ObjectWriter* writer, const TaskInfo& task)
   }
 }
 
+static void json(
+    JSON::StringWriter* writer,
+    const SlaveInfo::Capability::Type& capability)
+{
+  writer->append(SlaveInfo::Capability::Type_Name(capability));
+}
+
 namespace internal {
 namespace slave {
 
@@ -1222,6 +1229,7 @@ Future<Response> Slave::Http::state(
         writer->field("id", slave->info.id().value());
         writer->field("pid", string(slave->self()));
         writer->field("hostname", slave->info.hostname());
+        writer->field("capabilities", MESOS_AGENT_CAPABILITIES);
 
         const Resources& totalResources = slave->totalResources;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/5ad643fd/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index 16bb14b..61767b1 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -1525,6 +1525,15 @@ TEST_F(SlaveTest, StateEndpoint)
   EXPECT_EQ(stringify(slave.get()->pid), state.values["pid"]);
   EXPECT_EQ(agentFlags.hostname.get(), state.values["hostname"]);
 
+  ASSERT_TRUE(state.values["capabilities"].is<JSON::Array>());
+  EXPECT_FALSE(state.values["capabilities"].as<JSON::Array>().values.empty());
+  JSON::Value slaveCapabilities = state.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()));
+
   Try<Resources> resources = Resources::parse(
       agentFlags.resources.get(), agentFlags.default_role);