Repository: mesos Updated Branches: refs/heads/master 45ae9fbd9 -> 041fa2e2e
Implemented GET_LEADING_MASTER Call in v1 master API. Implemented GET_LEADING_MASTER Call in v1 master API and made a minor change in the test case for GET_LOGGING_LEVEL. Review: https://reviews.apache.org/r/48049/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/041fa2e2 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/041fa2e2 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/041fa2e2 Branch: refs/heads/master Commit: 041fa2e2e51d0d6652b15820ef195fb5db70cee8 Parents: 45ae9fb Author: Abhishek Dasgupta <a10gu...@linux.vnet.ibm.com> Authored: Tue May 31 13:27:03 2016 -0600 Committer: Vinod Kone <vinodk...@gmail.com> Committed: Tue May 31 13:27:03 2016 -0600 ---------------------------------------------------------------------- src/internal/evolve.cpp | 6 ++++++ src/internal/evolve.hpp | 1 + src/master/http.cpp | 22 +++++++++++++++++++++- src/master/master.hpp | 4 ++++ src/tests/api_tests.cpp | 21 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/041fa2e2/src/internal/evolve.cpp ---------------------------------------------------------------------- diff --git a/src/internal/evolve.cpp b/src/internal/evolve.cpp index 4f25f1a..7d3d450 100644 --- a/src/internal/evolve.cpp +++ b/src/internal/evolve.cpp @@ -143,6 +143,12 @@ v1::TaskStatus evolve(const TaskStatus& status) } +v1::MasterInfo evolve(const MasterInfo& masterInfo) +{ + return evolve<v1::MasterInfo>(masterInfo); +} + + v1::scheduler::Call evolve(const scheduler::Call& call) { return evolve<v1::scheduler::Call>(call); http://git-wip-us.apache.org/repos/asf/mesos/blob/041fa2e2/src/internal/evolve.hpp ---------------------------------------------------------------------- diff --git a/src/internal/evolve.hpp b/src/internal/evolve.hpp index 0fdda31..0bf0844 100644 --- a/src/internal/evolve.hpp +++ b/src/internal/evolve.hpp @@ -55,6 +55,7 @@ v1::OfferID evolve(const OfferID& offerId); v1::TaskID evolve(const TaskID& taskId); v1::TaskInfo evolve(const TaskInfo& taskInfo); v1::TaskStatus evolve(const TaskStatus& status); +v1::MasterInfo evolve(const MasterInfo& masterInfo); v1::scheduler::Call evolve(const scheduler::Call& call); http://git-wip-us.apache.org/repos/asf/mesos/blob/041fa2e2/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index b63d2e0..d26e26d 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -653,7 +653,8 @@ Future<Response> Master::Http::api( return NotImplemented(); case v1::master::Call::GET_LEADING_MASTER: - return NotImplemented(); + return getLeadingMaster(call, principal) + .then(serializer); case v1::master::Call::RESERVE_RESOURCES: return NotImplemented(); @@ -1351,6 +1352,25 @@ Future<v1::master::Response> Master::Http::getLoggingLevel( } +Future<v1::master::Response> Master::Http::getLeadingMaster( + const v1::master::Call& call, + const Option<string>& principal) const +{ + CHECK_EQ(v1::master::Call::GET_LEADING_MASTER, call.type()); + + v1::master::Response response; + response.set_type(v1::master::Response::GET_LEADING_MASTER); + + // It is guaranteed that this master has been elected as the leader. + CHECK(master->elected()); + + response.mutable_get_leading_master()->mutable_master_info()->CopyFrom( + evolve(master->info())); + + return response; +} + + string Master::Http::REDIRECT_HELP() { return HELP( http://git-wip-us.apache.org/repos/asf/mesos/blob/041fa2e2/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index dc00989..3be0497 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -1290,6 +1290,10 @@ private: const v1::master::Call& call, const Option<std::string>& principal) const; + process::Future<v1::master::Response> getLeadingMaster( + const v1::master::Call& call, + const Option<std::string>& principal) const; + Master* master; // NOTE: The quota specific pieces of the Operator API are factored http://git-wip-us.apache.org/repos/asf/mesos/blob/041fa2e2/src/tests/api_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp index 0b6bfad..3a482ca 100644 --- a/src/tests/api_tests.cpp +++ b/src/tests/api_tests.cpp @@ -182,6 +182,27 @@ TEST_P(MasterAPITest, GetLoggingLevel) } +TEST_P(MasterAPITest, GetLeadingMaster) +{ + Try<Owned<cluster::Master>> master = this->StartMaster(); + ASSERT_SOME(master); + + v1::master::Call v1Call; + v1Call.set_type(v1::master::Call::GET_LEADING_MASTER); + + ContentType contentType = GetParam(); + + Future<v1::master::Response> v1Response = + post(master.get()->pid, v1Call, contentType); + + AWAIT_READY(v1Response); + ASSERT_TRUE(v1Response->IsInitialized()); + ASSERT_EQ(v1::master::Response::GET_LEADING_MASTER, v1Response->type()); + ASSERT_EQ(master.get()->getMasterInfo().ip(), + v1Response->get_leading_master().master_info().ip()); +} + + class AgentAPITest : public MesosTest, public WithParamInterface<ContentType>