Implemented create methods in MasterContender and MasterDetector. The create method can be used to create a MasterContender/Detector from a module (specified using the --modules flag on the command line). If the contender/detector module names have not been specified, the method will fall back to its prior behavior.
Review: https://reviews.apache.org/r/44669/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e4a82b00 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e4a82b00 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e4a82b00 Branch: refs/heads/master Commit: e4a82b00d28998ab9a165950e683e5b46a7eb386 Parents: cbbc8f0 Author: Anurag Singh <anurag.prakash.si...@gmail.com> Authored: Wed Apr 6 15:08:48 2016 -0400 Committer: Kapil Arya <ka...@mesosphere.io> Committed: Wed Apr 6 18:36:18 2016 -0400 ---------------------------------------------------------------------- include/mesos/master/contender.hpp | 4 ++-- include/mesos/master/detector.hpp | 4 ++-- src/master/contender/contender.cpp | 29 ++++++++++++++++++-------- src/master/detector/detector.cpp | 37 ++++++++++++++++++++------------- 4 files changed, 47 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e4a82b00/include/mesos/master/contender.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/master/contender.hpp b/include/mesos/master/contender.hpp index 268dc50..2c485ef 100644 --- a/include/mesos/master/contender.hpp +++ b/include/mesos/master/contender.hpp @@ -57,8 +57,8 @@ public: * Note that the returned contender still needs to be `initialize()`d. */ static Try<MasterContender*> create( - const Option<std::String>& masterContenderModule, - const Option<std::string>& zk); + const Option<std::string>& zk, + const Option<std::string>& masterContenderModule = None()); /** * Note that the contender's membership, if obtained, is scheduled http://git-wip-us.apache.org/repos/asf/mesos/blob/e4a82b00/include/mesos/master/detector.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/master/detector.hpp b/include/mesos/master/detector.hpp index 0cb9fe1..f53c7c0 100644 --- a/include/mesos/master/detector.hpp +++ b/include/mesos/master/detector.hpp @@ -54,8 +54,8 @@ public: * If both arguments are `None`, `StandaloneMasterDetector` is returned. */ static Try<MasterDetector*> create( - const Option<std::String>& masterDetectorModule, - const Option<std::string>& zk); + const Option<std::string>& zk, + const Option<std::string>& masterDetectorModule = None()); virtual ~MasterDetector() = 0; http://git-wip-us.apache.org/repos/asf/mesos/blob/e4a82b00/src/master/contender/contender.cpp ---------------------------------------------------------------------- diff --git a/src/master/contender/contender.cpp b/src/master/contender/contender.cpp index 07735d0..9ad6252 100644 --- a/src/master/contender/contender.cpp +++ b/src/master/contender/contender.cpp @@ -16,6 +16,8 @@ #include <mesos/master/contender.hpp> +#include <mesos/module/contender.hpp> + #include <process/defer.hpp> #include <process/id.hpp> #include <process/process.hpp> @@ -30,6 +32,8 @@ #include "master/contender/standalone.hpp" #include "master/contender/zookeeper.hpp" +#include "module/manager.hpp" + #include "zookeeper/url.hpp" using std::string; @@ -40,16 +44,23 @@ namespace mesos { namespace master { namespace contender { -Try<MasterContender*> MasterContender::create(const Option<string>& _mechanism) +Try<MasterContender*> MasterContender::create( + const Option<std::string>& zk_, + const Option<std::string>& masterContenderModule_) { - if (_mechanism.isNone()) { + if (masterContenderModule_.isSome()) { + return modules::ModuleManager::create<MasterContender>( + masterContenderModule_.get()); + } + + if (zk_.isNone()) { return new StandaloneMasterContender(); } - string mechanism = _mechanism.get(); + string zk = zk_.get(); - if (strings::startsWith(mechanism, "zk://")) { - Try<zookeeper::URL> url = zookeeper::URL::parse(mechanism); + if (strings::startsWith(zk, "zk://")) { + Try<zookeeper::URL> url = zookeeper::URL::parse(zk); if (url.isError()) { return Error(url.error()); } @@ -58,7 +69,7 @@ Try<MasterContender*> MasterContender::create(const Option<string>& _mechanism) "Expecting a (chroot) path for ZooKeeper ('/' is not supported)"); } return new ZooKeeperMasterContender(url.get()); - } else if (strings::startsWith(mechanism, "file://")) { + } else if (strings::startsWith(zk, "file://")) { // Load the configuration out of a file. While Mesos and related // programs always use <stout/flags> to process the command line // arguments (and therefore file://) this entrypoint is exposed by @@ -76,7 +87,7 @@ Try<MasterContender*> MasterContender::create(const Option<string>& _mechanism) LOG(WARNING) << "Specifying master election mechanism / ZooKeeper URL to " "be read out of a file via 'file://' is deprecated inside " "Mesos and will be removed in a future release."; - const string& path = mechanism.substr(7); + const string& path = zk.substr(7); const Try<string> read = os::read(path); if (read.isError()) { return Error("Failed to read from file at '" + path + "'"); @@ -85,9 +96,9 @@ Try<MasterContender*> MasterContender::create(const Option<string>& _mechanism) return create(strings::trim(read.get())); } - CHECK(!strings::startsWith(mechanism, "file://")); + CHECK(!strings::startsWith(zk, "file://")); - return Error("Failed to parse '" + mechanism + "'"); + return Error("Failed to parse '" + zk + "'"); } http://git-wip-us.apache.org/repos/asf/mesos/blob/e4a82b00/src/master/detector/detector.cpp ---------------------------------------------------------------------- diff --git a/src/master/detector/detector.cpp b/src/master/detector/detector.cpp index b5fe9ec..3851732 100644 --- a/src/master/detector/detector.cpp +++ b/src/master/detector/detector.cpp @@ -19,6 +19,8 @@ #include <mesos/master/detector.hpp> +#include <mesos/module/detector.hpp> + #include <process/defer.hpp> #include <process/dispatch.hpp> #include <process/future.hpp> @@ -42,6 +44,8 @@ #include "messages/messages.hpp" +#include "module/manager.hpp" + #include "zookeeper/url.hpp" using namespace process; @@ -54,17 +58,23 @@ namespace mesos { namespace master { namespace detector { - -Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism) +Try<MasterDetector*> MasterDetector::create( + const Option<std::string>& zk_, + const Option<std::string>& masterDetectorModule_) { - if (_mechanism.isNone()) { + if (masterDetectorModule_.isSome()) { + return modules::ModuleManager::create<MasterDetector>( + masterDetectorModule_.get()); + } + + if (zk_.isNone()) { return new StandaloneMasterDetector(); } - string mechanism = _mechanism.get(); + string zk = zk_.get(); - if (strings::startsWith(mechanism, "zk://")) { - Try<zookeeper::URL> url = zookeeper::URL::parse(mechanism); + if (strings::startsWith(zk, "zk://")) { + Try<zookeeper::URL> url = zookeeper::URL::parse(zk); if (url.isError()) { return Error(url.error()); } @@ -73,7 +83,7 @@ Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism) "Expecting a (chroot) path for ZooKeeper ('/' is not supported)"); } return new ZooKeeperMasterDetector(url.get()); - } else if (strings::startsWith(mechanism, "file://")) { + } else if (strings::startsWith(zk, "file://")) { // Load the configuration out of a file. While Mesos and related // programs always use <stout/flags> to process the command line // arguments (and therefore file://) this entrypoint is exposed by @@ -91,7 +101,7 @@ Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism) LOG(WARNING) << "Specifying master detection mechanism / ZooKeeper URL to " "be read out of a file via 'file://' is deprecated inside " "Mesos and will be removed in a future release."; - const string& path = mechanism.substr(7); + const string& path = zk.substr(7); const Try<string> read = os::read(path); if (read.isError()) { return Error("Failed to read from file at '" + path + "'"); @@ -100,15 +110,15 @@ Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism) return create(strings::trim(read.get())); } - CHECK(!strings::startsWith(mechanism, "file://")); + CHECK(!strings::startsWith(zk, "file://")); // Okay, try and parse what we got as a PID. - UPID pid = mechanism.find("master@") == 0 - ? UPID(mechanism) - : UPID("master@" + mechanism); + UPID pid = zk.find("master@") == 0 + ? UPID(zk) + : UPID("master@" + zk); if (!pid) { - return Error("Failed to parse '" + mechanism + "'"); + return Error("Failed to parse '" + zk + "'"); } return new StandaloneMasterDetector( @@ -118,7 +128,6 @@ Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism) MasterDetector::~MasterDetector() {} - } // namespace detector { } // namespace master { } // namespace mesos {