Repository: mesos Updated Branches: refs/heads/master 0bb1f4496 -> 5cbd5a716
Implemented 'GetAgent' call in v1 agent API. Review: https://reviews.apache.org/r/51624 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5cbd5a71 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5cbd5a71 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5cbd5a71 Branch: refs/heads/master Commit: 5cbd5a7167ccc368db3ee66860e1bfd91e1de872 Parents: 0bb1f44 Author: haosdent huang <[email protected]> Authored: Tue Mar 7 11:43:40 2017 +0800 Committer: Haosdent Huang <[email protected]> Committed: Tue Mar 7 11:52:33 2017 +0800 ---------------------------------------------------------------------- include/mesos/agent/agent.proto | 8 ++++++++ include/mesos/v1/agent/agent.proto | 8 ++++++++ src/slave/http.cpp | 20 ++++++++++++++++++++ src/slave/slave.hpp | 6 ++++++ src/slave/validation.cpp | 3 +++ src/tests/api_tests.cpp | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 78 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/include/mesos/agent/agent.proto ---------------------------------------------------------------------- diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto index 61c3e8c..9149724 100644 --- a/include/mesos/agent/agent.proto +++ b/include/mesos/agent/agent.proto @@ -56,6 +56,7 @@ message Call { GET_FRAMEWORKS = 11; // Retrieves the information about known frameworks. GET_EXECUTORS = 12; // Retrieves the information about known executors. GET_TASKS = 13; // Retrieves the information about known tasks. + GET_AGENT = 20; // Retrieves the agent information. // Calls for managing nested containers underneath an executor's container. LAUNCH_NESTED_CONTAINER = 14; // See 'LaunchNestedContainer' below. @@ -204,6 +205,7 @@ message Response { GET_FRAMEWORKS = 10; // See 'GetFrameworks' below. GET_EXECUTORS = 11; // See 'GetExecutors' below. GET_TASKS = 12; // See 'GetTasks' below. + GET_AGENT = 14; // See 'GetAgent' below. WAIT_NESTED_CONTAINER = 13; // See 'WaitNestedContainer' below. } @@ -314,6 +316,11 @@ message Response { repeated Task completed_tasks = 5; } + // Contains the agent's information. + message GetAgent { + optional SlaveInfo slave_info = 1; + } + // Returns termination information about the nested container. message WaitNestedContainer { optional int32 exit_status = 1; @@ -333,6 +340,7 @@ message Response { optional GetFrameworks get_frameworks = 11; optional GetExecutors get_executors = 12; optional GetTasks get_tasks = 13; + optional GetAgent get_agent = 15; optional WaitNestedContainer wait_nested_container = 14; } http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/include/mesos/v1/agent/agent.proto ---------------------------------------------------------------------- diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto index 9b82cc1..34210c3 100644 --- a/include/mesos/v1/agent/agent.proto +++ b/include/mesos/v1/agent/agent.proto @@ -56,6 +56,7 @@ message Call { GET_FRAMEWORKS = 11; // Retrieves the information about known frameworks. GET_EXECUTORS = 12; // Retrieves the information about known executors. GET_TASKS = 13; // Retrieves the information about known tasks. + GET_AGENT = 20; // Retrieves the agent information. // Calls for managing nested containers underneath an executor's container. LAUNCH_NESTED_CONTAINER = 14; // See 'LaunchNestedContainer' below. @@ -203,6 +204,7 @@ message Response { GET_FRAMEWORKS = 10; // See 'GetFrameworks' below. GET_EXECUTORS = 11; // See 'GetExecutors' below. GET_TASKS = 12; // See 'GetTasks' below. + GET_AGENT = 14; // See 'GetAgent' below. WAIT_NESTED_CONTAINER = 13; // See 'WaitNestedContainer' below. } @@ -313,6 +315,11 @@ message Response { repeated Task completed_tasks = 5; } + // Contains the agent's information. + message GetAgent { + optional AgentInfo agent_info = 1; + } + // Returns termination information about the nested container. message WaitNestedContainer { optional int32 exit_status = 1; @@ -332,6 +339,7 @@ message Response { optional GetFrameworks get_frameworks = 11; optional GetExecutors get_executors = 12; optional GetTasks get_tasks = 13; + optional GetAgent get_agent = 15; optional WaitNestedContainer wait_nested_container = 14; } http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/src/slave/http.cpp ---------------------------------------------------------------------- diff --git a/src/slave/http.cpp b/src/slave/http.cpp index 3ab89f0..bc8209c 100644 --- a/src/slave/http.cpp +++ b/src/slave/http.cpp @@ -587,6 +587,9 @@ Future<Response> Slave::Http::_api( case agent::Call::GET_TASKS: return getTasks(call, mediaTypes.accept, principal); + case agent::Call::GET_AGENT: + return getAgent(call, mediaTypes.accept, principal); + case agent::Call::LAUNCH_NESTED_CONTAINER: return launchNestedContainer(call, mediaTypes.accept, principal); @@ -1681,6 +1684,23 @@ agent::Response::GetTasks Slave::Http::_getTasks( } +Future<Response> Slave::Http::getAgent( + const agent::Call& call, + ContentType acceptType, + const Option<Principal>& principal) const +{ + CHECK_EQ(agent::Call::GET_AGENT, call.type()); + + agent::Response response; + response.set_type(agent::Response::GET_AGENT); + + response.mutable_get_agent()->mutable_slave_info()->CopyFrom(slave->info); + + return OK(serialize(acceptType, evolve(response)), + stringify(acceptType)); +} + + Future<Response> Slave::Http::getState( const agent::Call& call, ContentType acceptType, http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/src/slave/slave.hpp ---------------------------------------------------------------------- diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp index 33897fa..978edd6 100644 --- a/src/slave/slave.hpp +++ b/src/slave/slave.hpp @@ -652,6 +652,12 @@ private: const process::Owned<ObjectApprover>& tasksApprover, const process::Owned<ObjectApprover>& executorsApprover) const; + process::Future<process::http::Response> getAgent( + const mesos::agent::Call& call, + ContentType acceptType, + const Option<process::http::authentication::Principal>& + principal) const; + process::Future<process::http::Response> getState( const mesos::agent::Call& call, ContentType acceptType, http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/src/slave/validation.cpp ---------------------------------------------------------------------- diff --git a/src/slave/validation.cpp b/src/slave/validation.cpp index 2c5335b..3dbd0fa 100644 --- a/src/slave/validation.cpp +++ b/src/slave/validation.cpp @@ -150,6 +150,9 @@ Option<Error> validate( case mesos::agent::Call::GET_TASKS: return None(); + case mesos::agent::Call::GET_AGENT: + return None(); + case mesos::agent::Call::LAUNCH_NESTED_CONTAINER: { if (!call.has_launch_nested_container()) { return Error("Expecting 'launch_nested_container' to be present"); http://git-wip-us.apache.org/repos/asf/mesos/blob/5cbd5a71/src/tests/api_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp index 607392f..52f58a4 100644 --- a/src/tests/api_tests.cpp +++ b/src/tests/api_tests.cpp @@ -3284,6 +3284,39 @@ TEST_P_TEMP_DISABLED_ON_WINDOWS(AgentAPITest, GetTasks) } +TEST_P(AgentAPITest, GetAgent) +{ + Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover); + + slave::Flags flags = CreateSlaveFlags(); + flags.hostname = "host"; + + StandaloneMasterDetector detector; + Try<Owned<cluster::Slave>> slave = this->StartSlave(&detector, flags); + ASSERT_SOME(slave); + + AWAIT_READY(__recover); + + // Wait until the agent has finished recovery. + Clock::pause(); + Clock::settle(); + + v1::agent::Call v1Call; + v1Call.set_type(v1::agent::Call::GET_AGENT); + + ContentType contentType = GetParam(); + + Future<v1::agent::Response> v1Response = + post(slave.get()->pid, v1Call, contentType); + + AWAIT_READY(v1Response); + ASSERT_TRUE(v1Response.get().IsInitialized()); + ASSERT_EQ(v1::agent::Response::GET_AGENT, v1Response.get().type()); + ASSERT_EQ(flags.hostname, + v1Response->get_agent().agent_info().hostname()); +} + + TEST_P_TEMP_DISABLED_ON_WINDOWS(AgentAPITest, GetState) { Try<Owned<cluster::Master>> master = StartMaster();
