Repository: mesos Updated Branches: refs/heads/master cc9229612 -> b5ba769c6
Added `version` string to MasterInfo. Jira: MESOS-2957 Adds an optional version string to the `MasterInfo` protobuf, to simplify handling versioning in HTTP API calls. The version string is taken from <mesos/version.hpp> which is the same used when starting up Master (master/main.cpp). I've added a simple test on the back of the `MasterDetector` test, as this was the place where we would expect the `MasterInfo` to have been fully populated by real production code (as opposed to other places, where it is actually handled by mocks). Review: https://reviews.apache.org/r/36036 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b5ba769c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b5ba769c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b5ba769c Branch: refs/heads/master Commit: b5ba769c6619ba878d60c1bad1b5dfbafa71360b Parents: cc92296 Author: Marco Massenzio <[email protected]> Authored: Wed Jul 1 15:21:17 2015 -0700 Committer: Vinod Kone <[email protected]> Committed: Wed Jul 1 15:21:19 2015 -0700 ---------------------------------------------------------------------- include/mesos/mesos.proto | 1 + src/common/protobuf_utils.cpp | 17 ++++++++++++++++- src/common/type_utils.cpp | 3 ++- src/master/master.cpp | 1 + src/tests/master_tests.cpp | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/b5ba769c/include/mesos/mesos.proto ---------------------------------------------------------------------- diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto index 5ab3c4a..1168c2e 100644 --- a/include/mesos/mesos.proto +++ b/include/mesos/mesos.proto @@ -344,6 +344,7 @@ message MasterInfo { required uint32 port = 3 [default = 5050]; optional string pid = 4; optional string hostname = 5; + optional string version = 6; } http://git-wip-us.apache.org/repos/asf/mesos/blob/b5ba769c/src/common/protobuf_utils.cpp ---------------------------------------------------------------------- diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp index f0642ba..8a51daa 100644 --- a/src/common/protobuf_utils.cpp +++ b/src/common/protobuf_utils.cpp @@ -140,7 +140,22 @@ Option<bool> getTaskHealth(const Task& task) return healthy; } - +/** + * Creates a MasterInfo protobuf from the process's UPID. + * + * This is only used by the `StandaloneMasterDetector` (used in tests + * and outside tests when ZK is not used). + * + * For example, when we start a slave with + * `[email protected]:5050`, since the slave (and consequently + * its detector) doesn't have enough information about `MasterInfo`, it + * tries to construct it based on the only available information + * (`UPID`). + * + * @param pid The process's assigned untyped PID. + * @return A fully formed `MasterInfo` with the IP/hostname information + * as derived from the `UPID`. + */ MasterInfo createMasterInfo(const process::UPID& pid) { MasterInfo info; http://git-wip-us.apache.org/repos/asf/mesos/blob/b5ba769c/src/common/type_utils.cpp ---------------------------------------------------------------------- diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp index f7b21c6..19f79b4 100644 --- a/src/common/type_utils.cpp +++ b/src/common/type_utils.cpp @@ -309,7 +309,8 @@ bool operator == (const MasterInfo& left, const MasterInfo& right) left.ip() == right.ip() && left.port() == right.port() && left.pid() == right.pid() && - left.hostname() == right.hostname(); + left.hostname() == right.hostname() && + left.version() == right.version(); } http://git-wip-us.apache.org/repos/asf/mesos/blob/b5ba769c/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index 34ce744..a7486d8 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -320,6 +320,7 @@ Master::Master( info_.set_port(self().address.port); info_.set_pid(self()); + info_.set_version(MESOS_VERSION); // Determine our hostname or use the hostname provided. string hostname; http://git-wip-us.apache.org/repos/asf/mesos/blob/b5ba769c/src/tests/master_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp index 962455c..57721b7 100644 --- a/src/tests/master_tests.cpp +++ b/src/tests/master_tests.cpp @@ -1029,6 +1029,7 @@ TEST_F(MasterTest, MasterInfoOnReElection) AWAIT_READY(masterInfo); EXPECT_EQ(master.get().address.port, masterInfo.get().port()); EXPECT_EQ(master.get().address.ip, net::IP(ntohl(masterInfo.get().ip()))); + EXPECT_EQ(MESOS_VERSION, masterInfo.get().version()); // The re-registered framework should get offers. AWAIT_READY(resourceOffers2);
