You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/11/25 22:31:28 UTC

mesos git commit: Updated WhitelistWatcher to watch only if a file is given.

Repository: mesos
Updated Branches:
  refs/heads/master 01b8b7651 -> 042553404


Updated WhitelistWatcher to watch only if a file is given.

Whitelist may be represented either by a filepath or a by a wildcard.
In the latter case WhitelistWatcher should not constantly try reload
the whitelist.

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


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

Branch: refs/heads/master
Commit: 042553404161b2e64f4d6bcb06520fd3113107b2
Parents: 01b8b76
Author: Alexander Rukletsov <al...@mesosphere.io>
Authored: Tue Nov 25 11:10:20 2014 -0800
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Tue Nov 25 11:10:20 2014 -0800

----------------------------------------------------------------------
 src/watcher/whitelist_watcher.cpp | 50 ++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/04255340/src/watcher/whitelist_watcher.cpp
----------------------------------------------------------------------
diff --git a/src/watcher/whitelist_watcher.cpp b/src/watcher/whitelist_watcher.cpp
index 113ff15..32713bb 100644
--- a/src/watcher/whitelist_watcher.cpp
+++ b/src/watcher/whitelist_watcher.cpp
@@ -55,38 +55,40 @@ WhitelistWatcher::WhitelistWatcher(
 
 void WhitelistWatcher::initialize()
 {
-  watch();
+  // If no whitelist file is given, no need to watch. Notify the
+  // subscriber that there is no whitelist.
+  if (path == "*") { // Accept all nodes.
+    VLOG(1) << "No whitelist given";
+    subscriber(Option<hashset<string>>(None()));
+  } else {
+    watch();
+  }
 }
 
 
 void WhitelistWatcher::watch()
 {
-  // Get the list of white listed nodes.
+  // Read the list of white listed nodes from local file.
+  // TODO(vinod): Add support for reading from ZooKeeper.
+  // TODO(vinod): Ensure this read is atomic w.r.t external
+  // writes/updates to this file.
   Option<hashset<string>> whitelist;
-  if (path == "*") { // Accept all nodes.
-    VLOG(1) << "No whitelist given";
+  Try<string> read = os::read(
+      strings::remove(path, "file://", strings::PREFIX));
+  if (read.isError()) {
+    LOG(ERROR) << "Error reading whitelist file: " << read.error() << ". "
+               << "Retrying";
+    whitelist = lastWhitelist;
+  } else if (read.get().empty()) {
+    VLOG(1) << "Empty whitelist file " << path;
+    whitelist = hashset<string>();
   } else {
-    // Read from local file.
-    // TODO(vinod): Add support for reading from ZooKeeper.
-    // TODO(vinod): Ensure this read is atomic w.r.t external
-    // writes/updates to this file.
-    Try<string> read = os::read(
-        strings::remove(path, "file://", strings::PREFIX));
-    if (read.isError()) {
-      LOG(ERROR) << "Error reading whitelist file: " << read.error() << ". "
-                 << "Retrying";
-      whitelist = lastWhitelist;
-    } else if (read.get().empty()) {
-      VLOG(1) << "Empty whitelist file " << path;
-      whitelist = hashset<string>();
-    } else {
-      hashset<string> hostnames;
-      vector<string> lines = strings::tokenize(read.get(), "\n");
-      foreach (const string& hostname, lines) {
-        hostnames.insert(hostname);
-      }
-      whitelist = hostnames;
+    hashset<string> hostnames;
+    vector<string> lines = strings::tokenize(read.get(), "\n");
+    foreach (const string& hostname, lines) {
+      hostnames.insert(hostname);
     }
+    whitelist = hostnames;
   }
 
   // Send the whitelist to subscriber, if necessary.