You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/07/11 23:48:06 UTC

svn commit: r1360429 - in /incubator/mesos/trunk/src: Makefile.am local/flags.hpp local/local.cpp local/local.hpp local/main.cpp log/main.cpp logging/logging.cpp logging/logging.hpp master/main.cpp sched/sched.cpp tests/flags_tests.cpp tests/main.cpp

Author: benh
Date: Wed Jul 11 21:48:05 2012
New Revision: 1360429

URL: http://svn.apache.org/viewvc?rev=1360429&view=rev
Log:
More integration of Flags (and replacement of Configuration)
(https://reviews.apache.org/r/5866).

Added:
    incubator/mesos/trunk/src/local/flags.hpp
      - copied, changed from r1360428, incubator/mesos/trunk/src/logging/logging.hpp
Modified:
    incubator/mesos/trunk/src/Makefile.am
    incubator/mesos/trunk/src/local/local.cpp
    incubator/mesos/trunk/src/local/local.hpp
    incubator/mesos/trunk/src/local/main.cpp
    incubator/mesos/trunk/src/log/main.cpp
    incubator/mesos/trunk/src/logging/logging.cpp
    incubator/mesos/trunk/src/logging/logging.hpp
    incubator/mesos/trunk/src/master/main.cpp
    incubator/mesos/trunk/src/sched/sched.cpp
    incubator/mesos/trunk/src/tests/flags_tests.cpp
    incubator/mesos/trunk/src/tests/main.cpp

Modified: incubator/mesos/trunk/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/Makefile.am?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/Makefile.am (original)
+++ incubator/mesos/trunk/src/Makefile.am Wed Jul 11 21:48:05 2012
@@ -198,13 +198,13 @@ libmesos_no_third_party_la_SOURCES += co
 	configurator/configurator.hpp configurator/option.hpp		\
 	detector/detector.hpp flags/flag.hpp flags/flags.hpp		\
 	flags/loader.hpp launcher/launcher.hpp linux/cgroups.hpp	\
-	linux/fs.hpp linux/proc.hpp local/local.hpp logging/flags.hpp	\
-	logging/logging.hpp master/allocator.hpp master/constants.hpp	\
-	master/frameworks_manager.hpp master/http.hpp			\
-	master/master.hpp master/dominant_share_allocator.hpp		\
-	master/slaves_manager.hpp master/webui.hpp			\
-	messages/messages.hpp slave/constants.hpp slave/flags.hpp	\
-	slave/http.hpp slave/isolation_module.hpp			\
+	linux/fs.hpp linux/proc.hpp local/flags.hpp local/local.hpp	\
+	logging/flags.hpp logging/logging.hpp master/allocator.hpp	\
+	master/constants.hpp master/frameworks_manager.hpp		\
+	master/http.hpp master/master.hpp				\
+	master/dominant_share_allocator.hpp master/slaves_manager.hpp	\
+	master/webui.hpp messages/messages.hpp slave/constants.hpp	\
+	slave/flags.hpp slave/http.hpp slave/isolation_module.hpp	\
 	slave/isolation_module_factory.hpp				\
 	slave/lxc_isolation_module.hpp					\
 	slave/process_based_isolation_module.hpp slave/reaper.hpp	\

Copied: incubator/mesos/trunk/src/local/flags.hpp (from r1360428, incubator/mesos/trunk/src/logging/logging.hpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local/flags.hpp?p2=incubator/mesos/trunk/src/local/flags.hpp&p1=incubator/mesos/trunk/src/logging/logging.hpp&r1=1360428&r2=1360429&rev=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.hpp (original)
+++ incubator/mesos/trunk/src/local/flags.hpp Wed Jul 11 21:48:05 2012
@@ -16,28 +16,31 @@
  * limitations under the License.
  */
 
-#ifndef __LOGGING_LOGGING_HPP__
-#define __LOGGING_LOGGING_HPP__
+#ifndef __LOCAL_FLAGS_HPP__
+#define __LOCAL_FLAGS_HPP__
 
-#include <string>
-
-#include <glog/logging.h> // Includes LOG(*), PLOG(*), CHECK, etc.
-
-#include "configurator/configuration.hpp"
-#include "configurator/configurator.hpp"
-
-#include "logging/flags.hpp"
+#include "flags/flags.hpp"
 
 namespace mesos {
 namespace internal {
-namespace logging {
+namespace local {
+
+class Flags : public virtual flags::FlagsBase
+{
+public:
+  Flags()
+  {
+    add(&Flags::num_slaves,
+        "num_slaves",
+        "Number of slaves to launch for local cluster",
+        1);
+  }
 
-void registerOptions(Configurator* configurator);
-void initialize(const std::string& argv0, const Configuration& conf);
-void initialize(const std::string& argv0, const Flags& flags);
+  int num_slaves;
+};
 
-} // namespace logging {
+} // namespace local {
 } // namespace internal {
 } // namespace mesos {
 
-#endif // __LOGGING_LOGGING_HPP__
+#endif // __LOCAL_FLAGS_HPP__

Modified: incubator/mesos/trunk/src/local/local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local/local.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local/local.cpp (original)
+++ incubator/mesos/trunk/src/local/local.cpp Wed Jul 11 21:48:05 2012
@@ -68,15 +68,6 @@ static map<IsolationModule*, Slave*> sla
 static MasterDetector* detector = NULL;
 
 
-void registerOptions(Configurator* configurator)
-{
-  configurator->addOption<int>(
-      "num_slaves",
-      "Number of slaves to create for local cluster",
-      1);
-}
-
-
 PID<Master> launch(int numSlaves,
                    int32_t cpus,
                    int64_t mem,

Modified: incubator/mesos/trunk/src/local/local.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local/local.hpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local/local.hpp (original)
+++ incubator/mesos/trunk/src/local/local.hpp Wed Jul 11 21:48:05 2012
@@ -30,11 +30,6 @@ namespace mesos {
 namespace internal {
 namespace local {
 
-// Register the options recognized by the local runner (a combination of
-// master and slave options) with a configurator.
-void registerOptions(Configurator* configurator);
-
-
 // Launch a local cluster with a given number of slaves and given numbers
 // of CPUs and memory per slave. Additionally one can also toggle whether
 // to initialize Google Logging and whether to log quietly.

Modified: incubator/mesos/trunk/src/local/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local/main.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local/main.cpp (original)
+++ incubator/mesos/trunk/src/local/main.cpp Wed Jul 11 21:48:05 2012
@@ -19,12 +19,14 @@
 #include <iostream>
 #include <string>
 
+#include "common/stringify.hpp"
 #include "common/utils.hpp"
 
 #include "configurator/configurator.hpp"
 
 #include "detector/detector.hpp"
 
+#include "local/flags.hpp"
 #include "local/local.hpp"
 
 #include "master/master.hpp"
@@ -58,42 +60,58 @@ int main(int argc, char **argv)
 {
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
-  Configurator configurator;
+  // TODO(benh): Add master and slave flags! This is impossible right
+  // now because both have 'webui_dir' and 'webui_port' that
+  // conflict. For now, all the flags will still get "validated" when
+  // we load them (i.e., in local::launch), they just won't be visible
+  // when you do '--help' (which is probably not a huge issue for
+  // mesos-local).
+  flags::Flags<logging::Flags, local::Flags> flags;
+
+  // The following flags are executable specific (e.g., since we only
+  // have one instance of libprocess per execution, we only want to
+  // advertise the port and ip option once, here).
+  short port;
+  flags.add(&port, "port", "Port to listen on", 5050);
+
+  Option<string> ip;
+  flags.add(&ip, "ip", "IP address to listen on");
+
+  bool help;
+  flags.add(&help,
+            "help",
+            "Prints this help message",
+            false);
 
-  logging::registerOptions(&configurator);
-
-  local::registerOptions(&configurator);
-
-  configurator.addOption<int>("port", 'p', "Port to listen on", 5050);
-  configurator.addOption<string>("ip", "IP address to listen on");
-
-  if (argc == 2 && string("--help") == argv[1]) {
-    usage(argv[0], configurator);
-    exit(1);
-  }
-
-  Configuration conf;
+  Configurator configurator(flags);
+  Configuration configuration;
   try {
-    conf = configurator.load(argc, argv);
+    configuration = configurator.load(argc, argv);
   } catch (ConfigurationException& e) {
     cerr << "Configuration error: " << e.what() << endl;
+    usage(argv[0], configurator);
     exit(1);
   }
 
-  if (conf.contains("port")) {
-    utils::os::setenv("LIBPROCESS_PORT", conf["port"]);
-  }
+  flags.load(configuration.getMap());
 
-  if (conf.contains("ip")) {
-    utils::os::setenv("LIBPROCESS_IP", conf["ip"]);
+  if (help) {
+    usage(argv[0], configurator);
+    exit(1);
   }
 
   // Initialize libprocess.
+  utils::os::setenv("LIBPROCESS_PORT", stringify(port));
+
+  if (ip.isSome()) {
+    utils::os::setenv("LIBPROCESS_IP", ip.get());
+  }
+
   process::initialize("master");
 
-  logging::initialize(argv[0], conf);
+  logging::initialize(argv[0], flags);
 
-  process::wait(local::launch(conf, false));
+  process::wait(local::launch(configuration, false));
 
   return 0;
 }

Modified: incubator/mesos/trunk/src/log/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/main.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/main.cpp (original)
+++ incubator/mesos/trunk/src/log/main.cpp Wed Jul 11 21:48:05 2012
@@ -23,13 +23,17 @@
 #include <process/process.hpp>
 
 #include "common/foreach.hpp"
+#include "common/option.hpp"
 #include "common/utils.hpp"
 
 #include "configurator/configurator.hpp"
 #include "configurator/configuration.hpp"
 
+#include "flags/flags.hpp"
+
 #include "log/replica.hpp"
 
+#include "logging/flags.hpp"
 #include "logging/logging.hpp"
 
 using namespace mesos;
@@ -53,40 +57,44 @@ void usage(const char* argv0, const Conf
 
 int main(int argc, char** argv)
 {
-  Configurator configurator;
-
-  logging::registerOptions(&configurator);
-
-  configurator.addOption<uint64_t>(
-      "from",
-      "Position from which to start reading in the log");
+  flags::Flags<logging::Flags> flags;
 
-  configurator.addOption<uint64_t>(
-      "to",
-      "Position from which to stop reading in the log");
+  Option<uint64_t> from;
+  flags.add(&from,
+            "from",
+            "Position from which to start reading in the log");
+
+  Option<uint64_t> to;
+  flags.add(&to,
+            "to",
+            "Position from which to stop reading in the log");
+
+  bool help;
+  flags.add(&help,
+            "help",
+            "Prints this help message",
+            false);
 
-  configurator.addOption<bool>(
-      "help",
-      'h',
-      "Prints this usage message");
-
-  Configuration conf;
+  Configurator configurator(flags);
+  Configuration configuration;
   try {
-    conf = configurator.load(argc, argv);
-  } catch (const ConfigurationException& e) {
+    configuration = configurator.load(argc, argv);
+  } catch (ConfigurationException& e) {
     cerr << "Configuration error: " << e.what() << endl;
     usage(argv[0], configurator);
     exit(1);
   }
 
-  if (argc < 2 || conf.contains("help")) {
+  flags.load(configuration.getMap());
+
+  if (help) {
     usage(argv[0], configurator);
     exit(1);
   }
 
   process::initialize();
 
-  logging::initialize(argv[0], conf);
+  logging::initialize(argv[0], flags);
 
   string path = argv[argc - 1];
 
@@ -101,13 +109,22 @@ int main(int argc, char** argv)
   CHECK(begin.isReady());
   CHECK(end.isReady());
 
-  uint64_t from = conf.get<uint64_t>("from", begin.get());
-  uint64_t to = conf.get<uint64_t>("to", end.get());
+  if (!from.isSome()) {
+    from = begin.get();
+  }
+
+  if (!to.isSome()) {
+    to = end.get();
+  }
+
+  CHECK(from.isSome());
+  CHECK(to.isSome());
 
   cerr << endl << "Attempting to read the log from "
-       << from << " to " << to << endl << endl;
+       << from.get() << " to " << to.get() << endl << endl;
 
-  process::Future<std::list<Action> > actions = replica.read(from, to);
+  process::Future<std::list<Action> > actions =
+    replica.read(from.get(), to.get());
 
   actions.await();
 

Modified: incubator/mesos/trunk/src/logging/logging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.cpp (original)
+++ incubator/mesos/trunk/src/logging/logging.cpp Wed Jul 11 21:48:05 2012
@@ -30,71 +30,6 @@ namespace mesos {
 namespace internal {
 namespace logging {
 
-void registerOptions(Configurator* configurator)
-{
-  configurator->addOption<bool>(
-      "quiet",
-      'q',
-      "Disable logging to stderr (default: false)",
-      false);
-
-  configurator->addOption<string>(
-      "log_dir",
-      "Location to put log files (no default, nothing"
-      " is written to disk unless specified; "
-      " does not affect logging to stderr)");
-
-  configurator->addOption<int>(
-      "logbufsecs",
-      "How many seconds to buffer log messages for (default: 0)",
-      0);
-}
-
-
-void initialize(const string& _argv0, const Configuration& conf)
-{
-  static process::Once initialized;
-
-  if (initialized.once()) {
-    return;
-  }
-
-  // Persistent copy of argv0 since InitGoogleLogging requires the
-  // string we pass to it to be accessible indefinitely.
-  static string argv0 = _argv0;
-
-  Option<string> directory = conf.get<string>("log_dir");
-
-  // Set glog's parameters through Google Flags variables.
-  if (directory.isSome()) {
-    if (!utils::os::mkdir(directory.get())) {
-      std::cerr << "Could not initialize logging: Failed to create directory "
-                << directory.get() << std::endl;
-      exit(1);
-    }
-    FLAGS_log_dir = directory.get();
-  }
-
-
-  // Log everything to stderr IN ADDITION to log files unless
-  // otherwise specified.
-  bool quiet = conf.get<bool>("quiet", false);
-
-  if (!quiet) {
-    FLAGS_stderrthreshold = 0; // INFO.
-  }
-
-  FLAGS_logbufsecs = conf.get<int>("logbufsecs", 0);
-
-  google::InitGoogleLogging(argv0.c_str());
-
-  LOG(INFO) << "Logging to " <<
-    (directory.isSome() ? directory.get() : "STDERR");
-
-  initialized.done();
-}
-
-
 void initialize(const string& _argv0, const Flags& flags)
 {
   static process::Once initialized;
@@ -117,7 +52,6 @@ void initialize(const string& _argv0, co
     FLAGS_log_dir = flags.log_dir.get();
   }
 
-
   // Log everything to stderr IN ADDITION to log files unless
   // otherwise specified.
   if (!flags.quiet) {

Modified: incubator/mesos/trunk/src/logging/logging.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.hpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.hpp (original)
+++ incubator/mesos/trunk/src/logging/logging.hpp Wed Jul 11 21:48:05 2012
@@ -32,8 +32,6 @@ namespace mesos {
 namespace internal {
 namespace logging {
 
-void registerOptions(Configurator* configurator);
-void initialize(const std::string& argv0, const Configuration& conf);
 void initialize(const std::string& argv0, const Flags& flags);
 
 } // namespace logging {

Modified: incubator/mesos/trunk/src/master/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/main.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/main.cpp (original)
+++ incubator/mesos/trunk/src/master/main.cpp Wed Jul 11 21:48:05 2012
@@ -21,6 +21,7 @@
 #include "common/try.hpp"
 #include "common/utils.hpp"
 
+#include "configurator/configuration.hpp"
 #include "configurator/configurator.hpp"
 
 #include "detector/detector.hpp"

Modified: incubator/mesos/trunk/src/sched/sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/sched/sched.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/sched/sched.cpp (original)
+++ incubator/mesos/trunk/src/sched/sched.cpp Wed Jul 11 21:48:05 2012
@@ -49,8 +49,11 @@
 
 #include "detector/detector.hpp"
 
+#include "flags/flags.hpp"
+
 #include "local/local.hpp"
 
+#include "logging/flags.hpp"
 #include "logging/logging.hpp"
 
 #include "messages/messages.hpp"
@@ -656,6 +659,10 @@ MesosSchedulerDriver::MesosSchedulerDriv
     return;
   }
 
+  flags::Flags<logging::Flags> flags;
+
+  flags.load(configuration.getMap());
+
   // Initialize libprocess.
   process::initialize();
 
@@ -665,7 +672,7 @@ MesosSchedulerDriver::MesosSchedulerDriv
   configuration.set("quiet", master == "localquiet");
 
   // TODO(benh): Replace whitespace in framework.name() with '_'?
-  logging::initialize(framework.name(), configuration);
+  logging::initialize(framework.name(), flags);
 
   // Initialize mutex and condition variable. TODO(benh): Consider
   // using a libprocess Latch rather than a pthread mutex and

Modified: incubator/mesos/trunk/src/tests/flags_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/flags_tests.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/flags_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/flags_tests.cpp Wed Jul 11 21:48:05 2012
@@ -174,8 +174,7 @@ TEST(FlagsTest, Configurator)
   try {
     configuration = configurator.load(argc, argv);
   } catch (mesos::internal::ConfigurationException& e) {
-    std::cerr << "Configuration error: " << e.what() << std::endl;
-    FAIL();
+    FAIL() << "Configuration error: " << e.what();
   }
 
   flags.load(configuration.getMap());

Modified: incubator/mesos/trunk/src/tests/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/main.cpp?rev=1360429&r1=1360428&r2=1360429&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/main.cpp (original)
+++ incubator/mesos/trunk/src/tests/main.cpp Wed Jul 11 21:48:05 2012
@@ -27,6 +27,7 @@
 #include "configurator/configuration.hpp"
 #include "configurator/configurator.hpp"
 
+#include "logging/flags.hpp"
 #include "logging/logging.hpp"
 
 #include "tests/utils.hpp"
@@ -126,32 +127,36 @@ int main(int argc, char** argv)
 {
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
-  Configurator configurator;
-
-  logging::registerOptions(&configurator);
+  flags::Flags<logging::Flags> flags;
 
   // We log to stderr by default, but when running tests we'd prefer
   // less junk to fly by, so force one to specify the verbosity.
-  configurator.addOption<bool>(
-      "verbose",
-      'v',
-      "Log all severity levels to stderr (default: serverity above ERROR)",
-      false);
-
-  configurator.addOption<bool>(
-      "help",
-      'h',
-      "Prints this usage message");
+  bool verbose;
+
+  flags.add(&verbose,
+            "verbose",
+            "Log all severity levels to stderr",
+            false);
+
+  bool help;
+  flags.add(&help,
+            "help",
+            "Prints this help message",
+            false);
 
-  Configuration conf;
+  Configurator configurator(flags);
+  Configuration configuration;
   try {
-    conf = configurator.load(argc, argv);
-  } catch (const ConfigurationException& e) {
+    configuration = configurator.load(argc, argv);
+  } catch (ConfigurationException& e) {
     cerr << "Configuration error: " << e.what() << endl;
+    usage(argv[0], configurator);
     exit(1);
   }
 
-  if (conf.contains("help")) {
+  flags.load(configuration.getMap());
+
+  if (help) {
     usage(argv[0], configurator);
     cerr << endl;
     testing::InitGoogleTest(&argc, argv); // Get usage from gtest too.
@@ -162,10 +167,12 @@ int main(int argc, char** argv)
   process::initialize();
 
   // Be quiet by default!
-  conf.set("quiet", !conf.get("verbose", false));
+  if (!verbose) {
+    flags.quiet = true;
+  }
 
   // Initialize logging.
-  logging::initialize(argv[0], conf);
+  logging::initialize(argv[0], flags);
 
   // Initialize gmock/gtest.
   testing::InitGoogleTest(&argc, argv);