Refactored 'Master::Http::getAgents()' into helper function. This helper function will be reused by both `GET_AGENTS` and `GET_STATE` calls.
Review: https://reviews.apache.org/r/49488/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2517ce8f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2517ce8f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2517ce8f Branch: refs/heads/master Commit: 2517ce8f4ebf419589b9298b183149d221d9aecc Parents: a318264 Author: Zhitao Li <zhitaoli...@gmail.com> Authored: Tue Jul 5 21:25:43 2016 -0700 Committer: Anand Mazumdar <an...@apache.org> Committed: Tue Jul 5 22:32:57 2016 -0700 ---------------------------------------------------------------------- src/master/http.cpp | 24 ++++++++++++++++++------ src/master/master.hpp | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2517ce8f/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 9dee513..2341f15 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -2089,12 +2089,25 @@ Future<process::http::Response> Master::Http::getAgents( { CHECK_EQ(mesos::master::Call::GET_AGENTS, call.type()); - mesos::master::Response response; - response.set_type(mesos::master::Response::GET_AGENTS); + return _getAgents(principal) + .then([contentType](const mesos::master::Response::GetAgents& getAgents) + -> Future<Response> { + mesos::master::Response response; + response.set_type(mesos::master::Response::GET_AGENTS); + response.mutable_get_agents()->CopyFrom(getAgents); + + return OK(serialize(contentType, evolve(response)), + stringify(contentType)); + }); +} + +Future<mesos::master::Response::GetAgents> Master::Http::_getAgents( + const Option<string>& principal) const +{ + mesos::master::Response::GetAgents getAgents; foreachvalue (const Slave* slave, master->slaves.registered) { - mesos::master::Response::GetAgents::Agent* agent = - response.mutable_get_agents()->add_agents(); + mesos::master::Response::GetAgents::Agent* agent = getAgents.add_agents(); agent->mutable_agent_info()->CopyFrom(slave->info); @@ -2123,8 +2136,7 @@ Future<process::http::Response> Master::Http::getAgents( } } - return OK(serialize(contentType, evolve(response)), - stringify(contentType)); + return getAgents; } http://git-wip-us.apache.org/repos/asf/mesos/blob/2517ce8f/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index b9d91c4..09e5105 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -1388,6 +1388,9 @@ private: const Option<std::string>& principal, ContentType contentType) const; + process::Future<mesos::master::Response::GetAgents> _getAgents( + const Option<std::string>& principal) const; + process::Future<process::http::Response> getFlags( const mesos::master::Call& call, const Option<std::string>& principal,