You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/10/15 01:54:52 UTC

mesos git commit: Cleaned up function signatures to use Option.

Repository: mesos
Updated Branches:
  refs/heads/master edd520b3e -> 2391f84fb


Cleaned up function signatures to use Option<T>.

Also make use of delegating constructors to reduce redundancy in the
master detector and master contender.

Review: https://reviews.apache.org/r/38734


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2391f84f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2391f84f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2391f84f

Branch: refs/heads/master
Commit: 2391f84fb0beda7b643e24b6fbb6c3cbf178ad6f
Parents: edd520b
Author: Neil Conway <ne...@gmail.com>
Authored: Wed Oct 14 16:54:22 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Wed Oct 14 16:54:22 2015 -0700

----------------------------------------------------------------------
 src/master/contender.cpp | 15 +++++++++------
 src/master/contender.hpp |  2 +-
 src/master/detector.cpp  | 23 ++++++++++++-----------
 src/master/detector.hpp  |  2 +-
 src/master/main.cpp      |  8 ++------
 5 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2391f84f/src/master/contender.cpp
----------------------------------------------------------------------
diff --git a/src/master/contender.cpp b/src/master/contender.cpp
index 67562f1..c641305 100644
--- a/src/master/contender.cpp
+++ b/src/master/contender.cpp
@@ -72,11 +72,15 @@ private:
 };
 
 
-Try<MasterContender*> MasterContender::create(const string& mechanism)
+Try<MasterContender*> MasterContender::create(const Option<string>& _mechanism)
 {
-  if (mechanism == "") {
+  if (_mechanism.isNone()) {
     return new StandaloneMasterContender();
-  } else if (strings::startsWith(mechanism, "zk://")) {
+  }
+
+  string mechanism = _mechanism.get();
+
+  if (strings::startsWith(mechanism, "zk://")) {
     Try<zookeeper::URL> url = zookeeper::URL::parse(mechanism);
     if (url.isError()) {
       return Error(url.error());
@@ -196,9 +200,8 @@ Future<Future<Nothing> > ZooKeeperMasterContender::contend()
 
 ZooKeeperMasterContenderProcess::ZooKeeperMasterContenderProcess(
     const zookeeper::URL& url)
-  : ProcessBase(ID::generate("zookeeper-master-contender")),
-    group(new Group(url, MASTER_CONTENDER_ZK_SESSION_TIMEOUT)),
-    contender(NULL) {}
+  : ZooKeeperMasterContenderProcess(Owned<Group>(
+    new Group(url, MASTER_CONTENDER_ZK_SESSION_TIMEOUT))) {}
 
 
 ZooKeeperMasterContenderProcess::ZooKeeperMasterContenderProcess(

http://git-wip-us.apache.org/repos/asf/mesos/blob/2391f84f/src/master/contender.hpp
----------------------------------------------------------------------
diff --git a/src/master/contender.hpp b/src/master/contender.hpp
index 927601c..05c3cd1 100644
--- a/src/master/contender.hpp
+++ b/src/master/contender.hpp
@@ -60,7 +60,7 @@ public:
   //   - zk://host1:port1,host2:port2,.../path
   //   - zk://username:password@host1:port1,host2:port2,.../path
   // Note that the returned contender still needs to be 'initialize()'d.
-  static Try<MasterContender*> create(const std::string& mechanism);
+  static Try<MasterContender*> create(const Option<std::string>& _mechanism);
 
   // Note that the contender's membership, if obtained, is scheduled
   // to be cancelled during destruction.

http://git-wip-us.apache.org/repos/asf/mesos/blob/2391f84f/src/master/detector.cpp
----------------------------------------------------------------------
diff --git a/src/master/detector.cpp b/src/master/detector.cpp
index d0d10e5..105a409 100644
--- a/src/master/detector.cpp
+++ b/src/master/detector.cpp
@@ -197,11 +197,15 @@ private:
 };
 
 
-Try<MasterDetector*> MasterDetector::create(const string& mechanism)
+Try<MasterDetector*> MasterDetector::create(const Option<string>& _mechanism)
 {
-  if (mechanism == "") {
+  if (_mechanism.isNone()) {
     return new StandaloneMasterDetector();
-  } else if (strings::startsWith(mechanism, "zk://")) {
+  }
+
+  string mechanism = _mechanism.get();
+
+  if (strings::startsWith(mechanism, "zk://")) {
     Try<zookeeper::URL> url = zookeeper::URL::parse(mechanism);
     if (url.isError()) {
       return Error(url.error());
@@ -309,16 +313,13 @@ Future<Option<MasterInfo> > StandaloneMasterDetector::detect(
 
 
 // TODO(benh): Get ZooKeeper timeout from configuration.
-// TODO(xujyan): Use peer constructor after switching to C++ 11.
 ZooKeeperMasterDetectorProcess::ZooKeeperMasterDetectorProcess(
     const zookeeper::URL& url)
-  : ProcessBase(ID::generate("zookeeper-master-detector")),
-    group(new Group(url.servers,
-                    MASTER_DETECTOR_ZK_SESSION_TIMEOUT,
-                    url.path,
-                    url.authentication)),
-    detector(group.get()),
-    leader(None()) {}
+  : ZooKeeperMasterDetectorProcess(Owned<Group>(
+    new Group(url.servers,
+              MASTER_DETECTOR_ZK_SESSION_TIMEOUT,
+              url.path,
+              url.authentication))) {}
 
 
 ZooKeeperMasterDetectorProcess::ZooKeeperMasterDetectorProcess(

http://git-wip-us.apache.org/repos/asf/mesos/blob/2391f84f/src/master/detector.hpp
----------------------------------------------------------------------
diff --git a/src/master/detector.hpp b/src/master/detector.hpp
index d31ce53..1d67c79 100644
--- a/src/master/detector.hpp
+++ b/src/master/detector.hpp
@@ -55,7 +55,7 @@ public:
   //   - host:port
   //   - zk://host1:port1,host2:port2,.../path
   //   - zk://username:password@host1:port1,host2:port2,.../path
-  static Try<MasterDetector*> create(const std::string& mechanism);
+  static Try<MasterDetector*> create(const Option<std::string>& _mechanism);
   virtual ~MasterDetector() = 0;
 
   // Returns MasterInfo after an election has occurred and the elected

http://git-wip-us.apache.org/repos/asf/mesos/blob/2391f84f/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index dd8f355..4352ec0 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -327,18 +327,14 @@ int main(int argc, char** argv)
   MasterContender* contender;
   MasterDetector* detector;
 
-  // TODO(vinod): 'MasterContender::create()' should take
-  // Option<string>.
-  Try<MasterContender*> contender_ = MasterContender::create(zk.getOrElse(""));
+  Try<MasterContender*> contender_ = MasterContender::create(zk);
   if (contender_.isError()) {
     EXIT(EXIT_FAILURE)
       << "Failed to create a master contender: " << contender_.error();
   }
   contender = contender_.get();
 
-  // TODO(vinod): 'MasterDetector::create()' should take
-  // Option<string>.
-  Try<MasterDetector*> detector_ = MasterDetector::create(zk.getOrElse(""));
+  Try<MasterDetector*> detector_ = MasterDetector::create(zk);
   if (detector_.isError()) {
     EXIT(EXIT_FAILURE)
       << "Failed to create a master detector: " << detector_.error();