Repository: mesos Updated Branches: refs/heads/master d458158fb -> 6001cfc41
Add /master/frameworks to master endpoint. Review: https://reviews.apache.org/r/39432 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6001cfc4 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6001cfc4 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6001cfc4 Branch: refs/heads/master Commit: 6001cfc41c886f34517b07962b3b4a2678f345d7 Parents: d458158 Author: Guangya Liu <[email protected]> Authored: Tue Nov 3 10:14:11 2015 -0800 Committer: Vinod Kone <[email protected]> Committed: Tue Nov 3 10:15:07 2015 -0800 ---------------------------------------------------------------------- src/master/http.cpp | 57 +++++++++++++++++++++++++++++ src/master/master.cpp | 6 ++++ src/master/master.hpp | 5 +++ src/tests/master_tests.cpp | 80 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/6001cfc4/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 093f793..fdb50d5 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -525,6 +525,63 @@ Future<Response> Master::Http::scheduler(const Request& request) const } +string Master::Http::FRAMEWORKS() +{ + return HELP(TLDR("Exposes the frameworks info.")); +} + + +Future<Response> Master::Http::frameworks(const Request& request) const +{ + JSON::Object object; + + // Model all of the frameworks. + { + JSON::Array array; + array.values.reserve(master->frameworks.registered.size()); // MESOS-2353. + + foreachvalue (Framework* framework, master->frameworks.registered) { + array.values.push_back(model(*framework)); + } + + object.values["frameworks"] = std::move(array); + } + + // Model all of the completed frameworks. + { + JSON::Array array; + array.values.reserve(master->frameworks.completed.size()); // MESOS-2353. + + foreach (const std::shared_ptr<Framework>& framework, + master->frameworks.completed) { + array.values.push_back(model(*framework)); + } + + object.values["completed_frameworks"] = std::move(array); + } + + // Model all currently unregistered frameworks. + // This could happen when the framework has yet to re-register + // after master failover. + { + JSON::Array array; + + // Find unregistered frameworks. + foreachvalue (const Slave* slave, master->slaves.registered) { + foreachkey (const FrameworkID& frameworkId, slave->tasks) { + if (!master->frameworks.registered.contains(frameworkId)) { + array.values.push_back(frameworkId.value()); + } + } + } + + object.values["unregistered_frameworks"] = std::move(array); + } + + return OK(object, request.url.query.get("jsonp")); +} + + string Master::Http::FLAGS_HELP() { return HELP(TLDR("Exposes the master's flag configuration.")); http://git-wip-us.apache.org/repos/asf/mesos/blob/6001cfc4/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index 2bc5a97..cbae27e 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -753,6 +753,12 @@ void Master::initialize() Http::log(request); return http.scheduler(request); }); + route("/frameworks", + Http::FRAMEWORKS(), + [http](const process::http::Request& request) { + Http::log(request); + return http.frameworks(request); + }); route("/flags", Http::FLAGS_HELP(), [http](const process::http::Request& request) { http://git-wip-us.apache.org/repos/asf/mesos/blob/6001cfc4/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index b76d301..b19f23b 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -855,6 +855,10 @@ private: process::Future<process::http::Response> flags( const process::http::Request& request) const; + // /master/frameworks + process::Future<process::http::Response> frameworks( + const process::http::Request& request) const; + // /master/health process::Future<process::http::Response> health( const process::http::Request& request) const; @@ -917,6 +921,7 @@ private: static std::string SCHEDULER_HELP(); static std::string FLAGS_HELP(); + static std::string FRAMEWORKS(); static std::string HEALTH_HELP(); static std::string OBSERVE_HELP(); static std::string REDIRECT_HELP(); http://git-wip-us.apache.org/repos/asf/mesos/blob/6001cfc4/src/tests/master_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp index ee24739..67531db 100644 --- a/src/tests/master_tests.cpp +++ b/src/tests/master_tests.cpp @@ -3830,6 +3830,86 @@ TEST_F(MasterTest, FrameworkInfoLabels) Shutdown(); } + +TEST_F(MasterTest, FrameworksEndpointWithoutFrameworks) +{ + master::Flags flags = CreateMasterFlags(); + + flags.hostname = "localhost"; + flags.cluster = "test-cluster"; + + // Capture the start time deterministically. + Clock::pause(); + + Try<PID<Master>> master = StartMaster(flags); + ASSERT_SOME(master); + + Future<process::http::Response> response = + process::http::get(master.get(), "frameworks"); + + AWAIT_EXPECT_RESPONSE_STATUS_EQ(process::http::OK().status, response); + EXPECT_SOME_EQ( + "application/json", + response.get().headers.get("Content-Type")); + + Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body); + ASSERT_SOME(parse); + + JSON::Object frameworks = parse.get(); + + ASSERT_TRUE(frameworks.values["frameworks"].is<JSON::Array>()); + EXPECT_TRUE(frameworks.values["frameworks"].as<JSON::Array>().values.empty()); + + ASSERT_TRUE( + frameworks.values["completed_frameworks"].is<JSON::Array>()); + EXPECT_TRUE( + frameworks.values["completed_frameworks"].as<JSON::Array>().values + .empty()); + + ASSERT_TRUE( + frameworks.values["unregistered_frameworks"].is<JSON::Array>()); + EXPECT_TRUE( + frameworks.values["unregistered_frameworks"].as<JSON::Array>().values + .empty()); +} + + +TEST_F(MasterTest, FrameworksEndpointOneFramework) +{ + Try<PID<Master>> master = StartMaster(); + ASSERT_SOME(master); + + FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO; + + MockScheduler sched; + MesosSchedulerDriver driver( + &sched, framework, master.get(), DEFAULT_CREDENTIAL); + + Future<Nothing> registered; + EXPECT_CALL(sched, registered(&driver, _, _)) + .WillOnce(FutureSatisfy(®istered)); + + driver.start(); + + AWAIT_READY(registered); + + Future<process::http::Response> response = + process::http::get(master.get(), "frameworks"); + AWAIT_EXPECT_RESPONSE_STATUS_EQ(process::http::OK().status, response); + + Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body); + ASSERT_SOME(parse); + + Result<JSON::Array> array = parse.get().find<JSON::Array>("frameworks"); + ASSERT_SOME(array); + EXPECT_EQ(1u, array.get().values.size()); + + driver.stop(); + driver.join(); + + Shutdown(); +} + } // namespace tests { } // namespace internal { } // namespace mesos {
