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 <[email protected]> Authored: Tue Feb 21 13:03:07 2017 -0800 Committer: Benjamin Mahler <[email protected]> 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);
