You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/04/07 00:48:34 UTC

[04/11] mesos git commit: Added MasterContender and MasterDetector abstract classes.

Added MasterContender and MasterDetector abstract classes.

MasterContender and MasterDetector abstract classes can be subclassed by
user-provided classes to allow for arbitrary contender/detector implementations.

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


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

Branch: refs/heads/master
Commit: f24f2820a3c945f8b870d9ccd5faf187554bcb4e
Parents: 18f60da
Author: Anurag Singh <an...@gmail.com>
Authored: Wed Apr 6 15:07:48 2016 -0400
Committer: Kapil Arya <ka...@mesosphere.io>
Committed: Wed Apr 6 18:36:18 2016 -0400

----------------------------------------------------------------------
 include/mesos/master/contender.hpp | 96 +++++++++++++++++++++++++++++++++
 include/mesos/master/detector.hpp  | 85 +++++++++++++++++++++++++++++
 2 files changed, 181 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f24f2820/include/mesos/master/contender.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/contender.hpp b/include/mesos/master/contender.hpp
new file mode 100644
index 0000000..268dc50
--- /dev/null
+++ b/include/mesos/master/contender.hpp
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __MESOS_MASTER_CONTENDER_HPP__
+#define __MESOS_MASTER_CONTENDER_HPP__
+
+#include <string>
+
+#include <mesos/mesos.hpp>
+
+#include <process/future.hpp>
+
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+namespace mesos {
+namespace master {
+namespace contender {
+
+/**
+ * An abstraction for contending to be a leading master.
+ *
+ * TODO(benh): Support contending with a v1::MasterInfo.
+ */
+class MasterContender
+{
+public:
+  /**
+   * Creates a master contender. If `masterContenderModule` contains a valid
+   * module name (that is, a name that matches the name specified in a JSON
+   * file/string passed into the command-line invocations using the `--modules`
+   * flag). Additional parameters required to create an object of the contender
+   * type are expected to be specified in the JSON's `parameter` object. In
+   * command-line invocations, the value of `masterContenderModule` is expected
+   * to come from the `--master_contender` flag.
+   *
+   * If `masterContenderModule` is `None`, `zk` is checked and if it contains a
+   * valid `zk://` or `file://` path (passed in using the `--zk` flag), an
+   * instance of ZooKeeperMasterContender is returned.
+   *
+   * If both arguments are `None`, `StandaloneMasterDetector` is returned.
+   *
+   * 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);
+
+  /**
+   * Note that the contender's membership, if obtained, is scheduled
+   * to be cancelled during destruction.
+   */
+  virtual ~MasterContender() = 0;
+
+  /**
+   * Initializes the contender with the MasterInfo of the master it
+   * contends on behalf of.
+   */
+  virtual void initialize(const MasterInfo& masterInfo) = 0;
+
+  /**
+   * Returns a Future<Nothing> once the contender has entered the
+   * contest (by obtaining a membership) and an error otherwise.
+   * A failed future is returned if this method is called before
+   * initialize().
+   * The inner Future returns Nothing when the contender is out of
+   * the contest (i.e. its membership is lost).
+   *
+   * This method can be used to contend again after candidacy is
+   * obtained (the outer future satisfied), otherwise the future for
+   * the pending election is returned.
+   * Recontending after candidacy is obtained causes the previous
+   * candidacy to be withdrawn.
+   */
+  virtual process::Future<process::Future<Nothing>> contend() = 0;
+};
+
+} // namespace contender {
+} // namespace master {
+} // namespace mesos {
+
+#endif // __MESOS_MASTER_CONTENDER_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f24f2820/include/mesos/master/detector.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/detector.hpp b/include/mesos/master/detector.hpp
new file mode 100644
index 0000000..0cb9fe1
--- /dev/null
+++ b/include/mesos/master/detector.hpp
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __MESOS_MASTER_DETECTOR_HPP__
+#define __MESOS_MASTER_DETECTOR_HPP__
+
+#include <string>
+
+#include <mesos/mesos.hpp>
+
+#include <process/future.hpp>
+
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+namespace mesos {
+namespace master {
+namespace detector {
+
+/**
+ * An abstraction of a Master detector which can be used to
+ * detect the leading master from a group.
+ */
+class MasterDetector
+{
+public:
+  /**
+   * Creates a master detector. If `masterDetectorModule` contains a valid
+   * module name (that is, a name that matches the name specified in a JSON
+   * file/string passed into the command-line invocation using the `--modules`
+   * flag), the result is the `MasterDetector` returned by the module.
+   * Additional parameters required to create an object of the detector type are
+   * expected to be specified in the JSON's `parameter` object. In command-line
+   * invocations, the value of `masterDetectorModule` is expected to come from
+   * the `--master_detector` flag.
+   *
+   * If `masterDetectorModule` is `None`, `zk` is checked and if it contains a
+   * valid `zk://` or `file://` path (passed in using the `--master` flag), an
+   * instance of ZooKeeperMasterDetector is returned.
+   *
+   * If both arguments are `None`, `StandaloneMasterDetector` is returned.
+   */
+  static Try<MasterDetector*> create(
+      const Option<std::String>& masterDetectorModule,
+      const Option<std::string>& zk);
+
+  virtual ~MasterDetector() = 0;
+
+  /**
+   * Returns MasterInfo after an election has occurred and the elected
+   * master is different than that specified (if any), or NONE if an
+   * election occurs and no master is elected (e.g., all masters are
+   * lost). A failed future is returned if the detector is unable to
+   * detect the leading master due to a non-retryable error.
+   * Note that the detector transparently tries to recover from
+   * retryable errors.
+   * The future is never discarded unless it stays pending when the
+   * detector destructs.
+   *
+   * The 'previous' result (if any) should be passed back if this
+   * method is called repeatedly so the detector only returns when it
+   * gets a different result.
+   */
+  virtual process::Future<Option<MasterInfo>> detect(
+      const Option<MasterInfo>& previous = None()) = 0;
+};
+
+} // namespace detector {
+} // namespace master {
+} // namespace mesos {
+
+#endif // __MESOS_MASTER_DETECTOR_HPP__