You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by kl...@apache.org on 2017/09/26 14:37:19 UTC

mesos git commit: Added 'master' key as an acceptable key in the CLI's config.toml.

Repository: mesos
Updated Branches:
  refs/heads/master 016a565f3 -> b35e8169d


Added 'master' key as an acceptable key in the CLI's config.toml.

This key is a field that has to be composed of
an `address` or `zookeeper` field, but not both.

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


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

Branch: refs/heads/master
Commit: b35e8169d200d41118793993f5007e2c573ece06
Parents: 016a565
Author: Armand Grillet <ag...@mesosphere.io>
Authored: Tue Sep 26 16:35:42 2017 +0200
Committer: Kevin Klues <kl...@gmail.com>
Committed: Tue Sep 26 16:35:42 2017 +0200

----------------------------------------------------------------------
 src/python/cli_new/README.md         | 14 ++++++
 src/python/cli_new/lib/cli/config.py | 76 +++++++++++++++++++++++++++++++
 src/python/cli_new/lib/cli/util.py   |  9 ++++
 3 files changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b35e8169/src/python/cli_new/README.md
----------------------------------------------------------------------
diff --git a/src/python/cli_new/README.md b/src/python/cli_new/README.md
index c5475c7..a4b270d 100644
--- a/src/python/cli_new/README.md
+++ b/src/python/cli_new/README.md
@@ -77,6 +77,20 @@ plugins = [
   "</absolute/path/to/plugin-1/directory>",
   "</absolute/path/to/plugin-2/directory>"
 ]
+
+# The `master` is a field that has to be composed of an
+# `address` or `zookeeper` field, but not both. For example:
+[master]
+  address = "10.10.0.30:5050"
+  # The `zookeeper` field has an `addresses` array and a `path` field.
+  # It exists but its backend has not been implemented yet (MESOS-8012).
+  # [master.zookeeper]
+  #   addresses = [
+  #     "10.10.0.31:5050",
+  #     "10.10.0.32:5050",
+  #     "10.10.0.33:5050"
+  #   ]
+  #   path = "/mesos"
 ```
 
 You can override the location of this configuration file using

http://git-wip-us.apache.org/repos/asf/mesos/blob/b35e8169/src/python/cli_new/lib/cli/config.py
----------------------------------------------------------------------
diff --git a/src/python/cli_new/lib/cli/config.py b/src/python/cli_new/lib/cli/config.py
index 36a32f9..6f92622 100644
--- a/src/python/cli_new/lib/cli/config.py
+++ b/src/python/cli_new/lib/cli/config.py
@@ -21,6 +21,10 @@ Config class to manage the configuration file.
 import os
 import toml
 
+import cli
+
+from cli.constants import DEFAULT_MASTER_IP
+from cli.constants import DEFAULT_MASTER_PORT
 from cli.exceptions import CLIException
 
 
@@ -44,6 +48,78 @@ class Config(object):
             raise CLIException("Error loading config file as TOML: {error}"
                                .format(error=exception))
 
+    def master(self):
+        """
+        Parse the master info in the configuration file and return
+        its IP address and the port where Mesos is running.
+        """
+        master = "{ip}:{port}".format(ip=DEFAULT_MASTER_IP,
+                                      port=DEFAULT_MASTER_PORT)
+
+        if "master" in self.data:
+            if not isinstance(self.data["master"], dict):
+                raise CLIException("The 'master' field must be a dictionary")
+
+            if ("address" not in self.data["master"] and
+                    "zookeeper" not in self.data["master"]):
+                raise CLIException("The 'master' field must either"
+                                   " contain an 'address' field or"
+                                   " a 'zookeeper' dictionary")
+            if ("address" in self.data["master"] and
+                    "zookeeper" in self.data["master"]):
+                raise CLIException("The 'master' field should only contain "
+                                   " an 'address' field or a 'zookeeper'"
+                                   " dictionary but not both")
+
+            if "address" in self.data["master"]:
+                master_address = self.data["master"]["address"]
+                try:
+                    cli.util.verify_address_format(master_address)
+                except Exception as exception:
+                    raise CLIException("The 'master' address {address} is"
+                                       " formatted incorrectly: {error}"
+                                       .format(address=master_address,
+                                               error=exception))
+                master = self.data["master"]["address"]
+
+            if "zookeeper" in self.data["master"]:
+                zk_field = self.data["master"]["zookeeper"]
+
+                if ("addresses" not in zk_field or
+                        not isinstance(zk_field["addresses"], list)):
+                    raise CLIException("The 'zookeeper' field must contain"
+                                       " an 'addresses' list")
+
+                if ("path" not in zk_field or
+                        not isinstance(zk_field["path"], unicode)):
+                    raise CLIException("The 'zookeeper' field must contain"
+                                       " a 'path' field")
+
+                if not zk_field["path"].startswith("/"):
+                    raise CLIException("The 'zookeeper' field 'path'"
+                                       " must start with a '/'")
+                if len(zk_field["path"]) == 1:
+                    raise CLIException("The 'zookeeper' field 'path' should"
+                                       " be nested ('/' is not supported)")
+
+                for address in zk_field["addresses"]:
+                    try:
+                        cli.util.verify_address_format(address)
+                    except Exception as exception:
+                        raise CLIException("The 'zookeeper' address {address}"
+                                           " is formatted incorrectly: {error}"
+                                           .format(address=address,
+                                                   error=exception))
+                try:
+                    master = cli.util.zookeeper_resolve_leader(
+                        zk_field["addresses"], zk_field["path"])
+                except Exception as exception:
+                    raise CLIException("Could not resolve the"
+                                       " leading master: {error}"
+                                       .format(error=exception))
+
+        return master
+
     def plugins(self):
         """
         Parse the plugins listed in the configuration file and return them.

http://git-wip-us.apache.org/repos/asf/mesos/blob/b35e8169/src/python/cli_new/lib/cli/util.py
----------------------------------------------------------------------
diff --git a/src/python/cli_new/lib/cli/util.py b/src/python/cli_new/lib/cli/util.py
index 8c96a6a..a9803d1 100644
--- a/src/python/cli_new/lib/cli/util.py
+++ b/src/python/cli_new/lib/cli/util.py
@@ -199,6 +199,15 @@ def join_plugin_paths(settings, config):
     return builtin_paths + config_paths
 
 
+# TODO(agrillet): Implement this function appropriately (MESOS-8012).
+def zookeeper_resolve_leader(addresses, path):
+    """Resolve the leader using a znode path."""
+    # pylint: disable=unused-argument, unreachable
+    raise CLIException("Using ZooKeeper to resolve the leading master"
+                       " is not yet supported. See MESOS-8012")
+    return ""
+
+
 class Table(object):
     """
     Defines a custom table structure for printing to the terminal.