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/06/14 23:44:22 UTC

[2/2] mesos git commit: Changed initialization order of `Anonymous` modules in Master.

Changed initialization order of `Anonymous` modules in Master.

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


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

Branch: refs/heads/master
Commit: ea3f69ca9b392b21102827d283812333be427d2f
Parents: 28bcd91
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Tue Jun 14 17:46:03 2016 -0400
Committer: Kapil Arya <ka...@mesosphere.io>
Committed: Tue Jun 14 19:29:14 2016 -0400

----------------------------------------------------------------------
 src/master/main.cpp | 126 ++++++++++++++++++++++++++++-------------------
 1 file changed, 75 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ea3f69ca/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index ce6291f..9163205 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -123,6 +123,30 @@ using std::vector;
 
 int main(int argc, char** argv)
 {
+  // The order of initialization of various master components is as follows:
+  // * Validate flags.
+  // * Log build information.
+  // * Libprocess.
+  // * Logging.
+  // * Version process.
+  // * Firewall rules: should be initialized before initializing HTTP endpoints.
+  // * Modules: Load module libraries and manifests before they
+  //   can be instantiated.
+  // * Anonymous modules: Later components such as Allocators, and master
+  //   contender/detector might depend upon anonymous modules.
+  // * Hooks.
+  // * Allocator.
+  // * Registry storage.
+  // * State.
+  // * Master contendor.
+  // * Master detector.
+  // * Authorizer.
+  // * Slave removal rate limiter.
+  // * `Master` process.
+  //
+  // TODO(avinash): Add more comments discussing the rationale behind for this
+  // particular component ordering.
+
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
   master::Flags flags;
@@ -235,6 +259,18 @@ int main(int argc, char** argv)
     }
   }
 
+  // Log build information.
+  LOG(INFO) << "Build: " << build::DATE << " by " << build::USER;
+  LOG(INFO) << "Version: " << MESOS_VERSION;
+
+  if (build::GIT_TAG.isSome()) {
+    LOG(INFO) << "Git tag: " << build::GIT_TAG.get();
+  }
+
+  if (build::GIT_SHA.isSome()) {
+    LOG(INFO) << "Git SHA: " << build::GIT_SHA.get();
+  }
+
   // This should be the first invocation of `process::initialize`. If it returns
   // `false`, then it has already been called, which means that the
   // authentication realm for libprocess-level HTTP endpoints was not set to the
@@ -251,8 +287,28 @@ int main(int argc, char** argv)
     LOG(WARNING) << warning.message;
   }
 
-  // Initialize modules. Note that since other subsystems may depend
-  // upon modules, we should initialize modules before anything else.
+  spawn(new VersionProcess(), true);
+
+  // Initialize firewall rules.
+  if (flags.firewall_rules.isSome()) {
+    vector<Owned<FirewallRule>> rules;
+
+    const Firewall firewall = flags.firewall_rules.get();
+
+    if (firewall.has_disabled_endpoints()) {
+      hashset<string> paths;
+
+      foreach (const string& path, firewall.disabled_endpoints().paths()) {
+        paths.insert(path);
+      }
+
+      rules.emplace_back(new DisabledEndpointsFirewallRule(paths));
+    }
+
+    process::firewall::install(move(rules));
+  }
+
+  // Initialize modules.
   if (flags.modules.isSome() && flags.modulesDir.isSome()) {
     EXIT(EXIT_FAILURE) <<
       flags.usage("Only one of --modules or --modules_dir should be specified");
@@ -272,6 +328,23 @@ int main(int argc, char** argv)
     }
   }
 
+  // Create anonymous modules.
+  foreach (const string& name, ModuleManager::find<Anonymous>()) {
+    Try<Anonymous*> create = ModuleManager::create<Anonymous>(name);
+    if (create.isError()) {
+      EXIT(EXIT_FAILURE)
+        << "Failed to create anonymous module named '" << name << "'";
+    }
+
+    // We don't bother keeping around the pointer to this anonymous
+    // module, when we exit that will effectively free it's memory.
+    //
+    // TODO(benh): We might want to add explicit finalization (and
+    // maybe explicit initialization too) in order to let the module
+    // do any housekeeping necessary when the master is cleanly
+    // terminating.
+  }
+
   // Initialize hooks.
   if (flags.hooks.isSome()) {
     Try<Nothing> result = HookManager::initialize(flags.hooks.get());
@@ -280,20 +353,6 @@ int main(int argc, char** argv)
     }
   }
 
-  spawn(new VersionProcess(), true);
-
-  LOG(INFO) << "Build: " << build::DATE << " by " << build::USER;
-
-  LOG(INFO) << "Version: " << MESOS_VERSION;
-
-  if (build::GIT_TAG.isSome()) {
-    LOG(INFO) << "Git tag: " << build::GIT_TAG.get();
-  }
-
-  if (build::GIT_SHA.isSome()) {
-    LOG(INFO) << "Git SHA: " << build::GIT_SHA.get();
-  }
-
   // Create an instance of allocator.
   const string allocatorName = flags.allocator;
   Try<Allocator*> allocator = Allocator::create(allocatorName);
@@ -481,41 +540,6 @@ int main(int argc, char** argv)
     slaveRemovalLimiter = new RateLimiter(permits.get(), duration.get());
   }
 
-  if (flags.firewall_rules.isSome()) {
-    vector<Owned<FirewallRule>> rules;
-
-    const Firewall firewall = flags.firewall_rules.get();
-
-    if (firewall.has_disabled_endpoints()) {
-      hashset<string> paths;
-
-      foreach (const string& path, firewall.disabled_endpoints().paths()) {
-        paths.insert(path);
-      }
-
-      rules.emplace_back(new DisabledEndpointsFirewallRule(paths));
-    }
-
-    process::firewall::install(move(rules));
-  }
-
-  // Create anonymous modules.
-  foreach (const string& name, ModuleManager::find<Anonymous>()) {
-    Try<Anonymous*> create = ModuleManager::create<Anonymous>(name);
-    if (create.isError()) {
-      EXIT(EXIT_FAILURE)
-        << "Failed to create anonymous module named '" << name << "'";
-    }
-
-    // We don't bother keeping around the pointer to this anonymous
-    // module, when we exit that will effectively free it's memory.
-    //
-    // TODO(benh): We might want to add explicit finalization (and
-    // maybe explicit initialization too) in order to let the module
-    // do any housekeeping necessary when the master is cleanly
-    // terminating.
-  }
-
   LOG(INFO) << "Starting Mesos master";
 
   Master* master =