Repository: mesos
Updated Branches:
  refs/heads/master 683551c92 -> 1f988a35b


Propagated work_dir flag from local runs to agents/masters.

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


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

Branch: refs/heads/master
Commit: 1f988a35b513b6c21484b34471a5171adf63ddd3
Parents: 683551c
Author: Ammar Askar <am...@ammaraskar.com>
Authored: Wed Aug 10 17:57:09 2016 -0700
Committer: Vinod Kone <vinodk...@gmail.com>
Committed: Wed Aug 10 17:57:09 2016 -0700

----------------------------------------------------------------------
 src/local/flags.hpp | 22 ++++++++++++++++++++++
 src/local/local.cpp | 42 +++++++++++++-----------------------------
 2 files changed, 35 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1f988a35/src/local/flags.hpp
----------------------------------------------------------------------
diff --git a/src/local/flags.hpp b/src/local/flags.hpp
index f0af0d2..c77eff1 100644
--- a/src/local/flags.hpp
+++ b/src/local/flags.hpp
@@ -18,6 +18,8 @@
 #define __LOCAL_FLAGS_HPP__
 
 #include <stout/flags.hpp>
+#include <stout/os.hpp>
+#include <stout/path.hpp>
 
 #include "logging/flags.hpp"
 
@@ -30,12 +32,32 @@ class Flags : public logging::Flags
 public:
   Flags()
   {
+    // `work_dir` is passed from here to the agents/master.
+    // This is necessary because `work_dir` is a required flag
+    // in agents/master and without this, the load call for their
+    // flags will spit out an error unless they have an env
+    // variable for the `work_dir` explicitly set.
+    // Since local mode is used strictly for non-production
+    // purposes, it is the one case where we deem it acceptable
+    // to set a default value for `work_dir`.
+    add(&Flags::work_dir,
+        "work_dir",
+        "Path of the master/agent work directory. This is where the\n"
+        "persistent information of the cluster will be stored.\n"
+        "Note that locations like `/tmp` which are cleaned\n"
+        "automatically are not suitable for the work directory\n"
+        "when running in production, since long-running masters\n"
+        "and agents could lose data when cleanup occurs.\n"
+        "(Example: `/var/lib/mesos`)",
+        path::join(os::temp(), "mesos", "local"));
+
     add(&Flags::num_slaves,
         "num_slaves",
         "Number of agents to launch for local cluster",
         1);
   }
 
+  std::string work_dir;
   int num_slaves;
 };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/1f988a35/src/local/local.cpp
----------------------------------------------------------------------
diff --git a/src/local/local.cpp b/src/local/local.cpp
index d6fe4d0..1e1d246 100644
--- a/src/local/local.cpp
+++ b/src/local/local.cpp
@@ -168,9 +168,20 @@ PID<Master> launch(const Flags& flags, Allocator* 
_allocator)
 
   files = new Files();
 
+  // Attempt to create the `work_dir` as a convenience.
+  Try<Nothing> mkdir = os::mkdir(flags.work_dir);
+  if (mkdir.isError()) {
+    EXIT(EXIT_FAILURE)
+      << "Failed to create the work_dir for agents/master '"
+      << flags.work_dir << "': " << mkdir.error();
+  }
+
+  std::map<std::string, std::string> propagated_flags;
+  propagated_flags["work_dir"] = flags.work_dir;
+
   {
     master::Flags flags;
-    Try<flags::Warnings> load = flags.load("MESOS_");
+    Try<flags::Warnings> load = flags.load(propagated_flags, false, "MESOS_");
     if (load.isError()) {
       EXIT(EXIT_FAILURE)
         << "Failed to start a local cluster while loading"
@@ -194,15 +205,6 @@ PID<Master> launch(const Flags& flags, Allocator* 
_allocator)
     if (flags.registry == "in_memory") {
       storage = new mesos::state::InMemoryStorage();
     } else if (flags.registry == "replicated_log") {
-      // For local runs, we use a temporary work directory.
-      if (flags.work_dir.isNone()) {
-        CHECK_SOME(os::mkdir("/tmp/mesos/local"));
-
-        Try<string> directory = os::mkdtemp("/tmp/mesos/local/XXXXXX");
-        CHECK_SOME(directory);
-        flags.work_dir = directory.get();
-      }
-
       // TODO(vinod): Add support for replicated log with ZooKeeper.
       log = new Log(
           1,
@@ -339,25 +341,7 @@ PID<Master> launch(const Flags& flags, Allocator* 
_allocator)
   for (int i = 0; i < flags.num_slaves; i++) {
     slave::Flags flags;
 
-    if (os::getenv("MESOS_WORK_DIR").isNone()) {
-      const string workDir = "/tmp/mesos/local/agents";
-      Try<Nothing> mkdir = os::mkdir(workDir);
-      if (mkdir.isError()) {
-        EXIT(EXIT_FAILURE)
-          << "Failed to create the root work directory for local agents '"
-          << workDir << "': " << mkdir.error();
-      }
-
-      flags.work_dir = path::join(workDir, stringify(i));
-      Try<Nothing> directory = os::mkdir(flags.work_dir);
-      if (directory.isError()) {
-        EXIT(EXIT_FAILURE)
-          << "Failed to create work directory for local agent '"
-          << flags.work_dir << "': " << directory.error();
-      }
-    }
-
-    Try<flags::Warnings> load = flags.load("MESOS_");
+    Try<flags::Warnings> load = flags.load(propagated_flags, false, "MESOS_");
 
     if (load.isError()) {
       EXIT(EXIT_FAILURE)

Reply via email to