Repository: mesos Updated Branches: refs/heads/master 1388f6c68 -> 66e3d0633
Added slave active field in state.json. Review: https://reviews.apache.org/r/28260 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/66e3d063 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/66e3d063 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/66e3d063 Branch: refs/heads/master Commit: 66e3d0633096834f233589b47424fe1723660326 Parents: 1388f6c Author: Niklas Nielsen <[email protected]> Authored: Wed Nov 19 13:59:52 2014 -0800 Committer: Niklas Q. Nielsen <[email protected]> Committed: Wed Nov 19 13:59:53 2014 -0800 ---------------------------------------------------------------------- src/master/http.cpp | 1 + src/tests/master_tests.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/66e3d063/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 9157a41..46890be 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -189,6 +189,7 @@ JSON::Object model(const Slave& slave) object.values["resources"] = model(slave.info.resources()); object.values["attributes"] = model(slave.info.attributes()); + object.values["active"] = slave.active; return object; } http://git-wip-us.apache.org/repos/asf/mesos/blob/66e3d063/src/tests/master_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp index b629cf7..21a642f 100644 --- a/src/tests/master_tests.cpp +++ b/src/tests/master_tests.cpp @@ -2674,3 +2674,61 @@ TEST_F(MasterTest, TaskLabels) Shutdown(); // Must shutdown before 'containerizer' gets deallocated. } + + +// This tests the 'active' field in slave entries from state.json. We +// first verify an active slave, deactivate it and verify that the +// 'active' field is false. +TEST_F(MasterTest, SlaveActiveEndpoint) +{ + // Start a master. + Try<PID<Master>> master = StartMaster(); + ASSERT_SOME(master); + + Future<process::Message> slaveRegisteredMessage = + FUTURE_MESSAGE(Eq(SlaveRegisteredMessage().GetTypeName()), _, _); + + // Start a checkpointing slave. + slave::Flags flags = CreateSlaveFlags(); + flags.checkpoint = true; + Try<PID<Slave>> slave = StartSlave(flags); + ASSERT_SOME(slave); + + AWAIT_READY(slaveRegisteredMessage); + + // Verify slave is active. + Future<process::http::Response> response = + process::http::get(master.get(), "state.json"); + AWAIT_READY(response); + + Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body); + ASSERT_SOME(parse); + + Result<JSON::Boolean> status = parse.get().find<JSON::Boolean>( + "slaves[0].active"); + + ASSERT_SOME_EQ(JSON::Boolean(true), status); + + Future<Nothing> slaveDeactivated = + FUTURE_DISPATCH(_, &AllocatorProcess::slaveDeactivated); + + // Inject a slave exited event at the master causing the master + // to mark the slave as disconnected. + process::inject::exited(slaveRegisteredMessage.get().to, master.get()); + + // Wait until master deactivates the slave. + AWAIT_READY(slaveDeactivated); + + // Verify slave is inactive. + response = process::http::get(master.get(), "state.json"); + AWAIT_READY(response); + + parse = JSON::parse<JSON::Object>(response.get().body); + ASSERT_SOME(parse); + + status = parse.get().find<JSON::Boolean>("slaves[0].active"); + + ASSERT_SOME_EQ(JSON::Boolean(false), status); + + Shutdown(); +}
