Repository: mesos Updated Branches: refs/heads/master 8c3748abd -> 190cd7236
Adding ability to decode JSON from ZK. The Leader detector will now also try to read nodes with label master::MASTER_INFO_JSON_LABEL and parse the contents as JSON, converting the data to a mesos::MasterInfo protobuf. The ability to support binary data in PB format is still supported and the master::Contender will continue to serialize the binary data, so as to be compatible with 0.22 Mesos Masters. Review: https://reviews.apache.org/r/35571 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/190cd723 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/190cd723 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/190cd723 Branch: refs/heads/master Commit: 190cd72361f23c27efd41499774221cbcf00741c Parents: 8c3748a Author: Marco Massenzio <[email protected]> Authored: Fri Jun 19 10:38:26 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Fri Jun 19 11:13:02 2015 -0700 ---------------------------------------------------------------------- src/master/constants.cpp | 2 ++ src/master/constants.hpp | 13 ++++++++++++- src/master/detector.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/190cd723/src/master/constants.cpp ---------------------------------------------------------------------- diff --git a/src/master/constants.cpp b/src/master/constants.cpp index 8c7174a..997b792 100644 --- a/src/master/constants.cpp +++ b/src/master/constants.cpp @@ -41,6 +41,8 @@ const uint32_t MAX_COMPLETED_TASKS_PER_FRAMEWORK = 1000; const Duration WHITELIST_WATCH_INTERVAL = Seconds(5); const uint32_t TASK_LIMIT = 100; const std::string MASTER_INFO_LABEL = "info"; +const std::string MASTER_INFO_JSON_LABEL = "json.info"; + const Duration ZOOKEEPER_SESSION_TIMEOUT = Seconds(10); const std::string DEFAULT_AUTHENTICATOR = "crammd5"; const std::string DEFAULT_ALLOCATOR = "HierarchicalDRF"; http://git-wip-us.apache.org/repos/asf/mesos/blob/190cd723/src/master/constants.hpp ---------------------------------------------------------------------- diff --git a/src/master/constants.hpp b/src/master/constants.hpp index 57cf8fb..072d59c 100644 --- a/src/master/constants.hpp +++ b/src/master/constants.hpp @@ -98,9 +98,20 @@ extern const Duration WHITELIST_WATCH_INTERVAL; // Default number of tasks (limit) for /master/tasks.json endpoint. extern const uint32_t TASK_LIMIT; -// Label used by the Leader Contender and Detector. +/** + * Label used by the Leader Contender and Detector. + * + * \deprecated Will be deprecated as of Mesos 0.24: see MESOS-2340. + */ extern const std::string MASTER_INFO_LABEL; +/** + * Label used by the Leader Contender and Detector, for JSON content. + * + * \since Mesos 0.23 (see MESOS-2340). + */ +extern const std::string MASTER_INFO_JSON_LABEL; + // Timeout used for ZooKeeper related operations. // TODO(vinod): Master detector/contender should use this timeout. extern const Duration ZOOKEEPER_SESSION_TIMEOUT; http://git-wip-us.apache.org/repos/asf/mesos/blob/190cd723/src/master/detector.cpp ---------------------------------------------------------------------- diff --git a/src/master/detector.cpp b/src/master/detector.cpp index 5700711..d0d10e5 100644 --- a/src/master/detector.cpp +++ b/src/master/detector.cpp @@ -31,6 +31,7 @@ #include <stout/duration.hpp> #include <stout/foreach.hpp> #include <stout/lambda.hpp> +#include <stout/protobuf.hpp> #include "common/protobuf_utils.hpp" @@ -440,7 +441,35 @@ void ZooKeeperMasterDetectorProcess::fetched( promises::fail(&promises, "Failed to parse data into MasterInfo"); return; } + LOG(WARNING) << "Leading master " << info.pid() + << " is using a Protobuf binary format when registering with " + << "ZooKeeper (" << label.get() << "): this will be deprecated" + << " as of Mesos 0.24 (see MESOS-2340)"; leader = info; + } else if (label.isSome() && label.get() == master::MASTER_INFO_JSON_LABEL) { + Try<JSON::Object> object = JSON::parse<JSON::Object>(data.get().get()); + + if (object.isError()) { + leader = None(); + promises::fail( + &promises, + "Failed to parse data into valid JSON: " + object.error()); + return; + } + + Try<mesos::MasterInfo> info = + ::protobuf::parse<mesos::MasterInfo>(object.get()); + + if (info.isError()) { + leader = None(); + promises::fail( + &promises, + "Failed to parse JSON into a valid MasterInfo protocol buffer: " + + info.error()); + return; + } + + leader = info.get(); } else { leader = None(); promises::fail(
