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 2011/06/05 10:22:21 UTC

svn commit: r1132002 - in /incubator/mesos/trunk/src: Makefile.in conf/mesos.conf conf/mesos.conf.template configurator/configurator.cpp configurator/configurator.hpp tests/test_configurator.cpp tests/test_sample_frameworks.cpp

Author: benh
Date: Sun Jun  5 08:22:21 2011
New Revision: 1132002

URL: http://svn.apache.org/viewvc?rev=1132002&view=rev
Log:
A couple of fixes:
- Configurator was not loading config file values for options that had a
  default value registered
- Wrong header was included in test_sample_frameworks.cpp, leading to
  MESOS_HAS_JAVA and MESOS_HAS_PYTHON not being found
- Added Makefile rules to create conf directory and empty mesos.conf

Added:
    incubator/mesos/trunk/src/conf/mesos.conf.template
      - copied, changed from r1132001, incubator/mesos/trunk/src/conf/mesos.conf
Removed:
    incubator/mesos/trunk/src/conf/mesos.conf
Modified:
    incubator/mesos/trunk/src/Makefile.in
    incubator/mesos/trunk/src/configurator/configurator.cpp
    incubator/mesos/trunk/src/configurator/configurator.hpp
    incubator/mesos/trunk/src/tests/test_configurator.cpp
    incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp

Modified: incubator/mesos/trunk/src/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/Makefile.in?rev=1132002&r1=1132001&r2=1132002&view=diff
==============================================================================
--- incubator/mesos/trunk/src/Makefile.in (original)
+++ incubator/mesos/trunk/src/Makefile.in Sun Jun  5 08:22:21 2011
@@ -4,6 +4,7 @@ SHELL = '/bin/sh'
 
 BINDIR = @top_builddir@/bin
 LIBDIR = @top_builddir@/lib
+CONFDIR = @top_builddir@/conf
 
 CC = @CC@
 CXX = @CXX@
@@ -198,6 +199,9 @@ WEBUI_FILES = $(BINDIR)/webui/bottle-0.5
               $(BINDIR)/webui/slave/webui.py		\
               $(BINDIR)/webui/static/stylesheet.css
 
+# We copy template config files into the conf directory.
+CONF_FILES = $(CONFDIR)/mesos.conf
+
 # Create rules for building the directories that aren't created
 # automagically by configure.
 OBJ_DIRECTORIES = common configurator detector exec launcher local	\
@@ -209,7 +213,7 @@ WEBUI_DIRECTORIES = $(BINDIR)/webui/comm
                     $(BINDIR)/webui/slave/swig
 
 DIRECTORIES = $(BINDIR) $(LIBDIR) $(LIBDIR)/java $(LIBDIR)/python	\
-              $(OBJ_DIRECTORIES) $(WEBUI_DIRECTORIES)
+              $(OBJ_DIRECTORIES) $(WEBUI_DIRECTORIES) $(CONFDIR)
 
 
 default: all
@@ -312,10 +316,13 @@ ifeq ($(WITH_WEBUI),1)
 	cp -r $< $@
 endif
 
+$(CONFDIR)/mesos.conf: @srcdir@/conf/mesos.conf.template | $(CONFDIR)
+	cp -r $^ $@
+
 test: all
 	$(MAKE) -C tests test
 
-all: $(MESOS_LIBS) $(MESOS_EXES) java python $(WEBUI_FILES)
+all: $(MESOS_LIBS) $(MESOS_EXES) java python $(WEBUI_FILES) $(CONF_FILES)
 	$(MAKE) -C examples
 	$(MAKE) -C tests
 

Copied: incubator/mesos/trunk/src/conf/mesos.conf.template (from r1132001, incubator/mesos/trunk/src/conf/mesos.conf)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/conf/mesos.conf.template?p2=incubator/mesos/trunk/src/conf/mesos.conf.template&p1=incubator/mesos/trunk/src/conf/mesos.conf&r1=1132001&r2=1132002&rev=1132002&view=diff
==============================================================================
    (empty)

Modified: incubator/mesos/trunk/src/configurator/configurator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator/configurator.cpp?rev=1132002&r1=1132001&r2=1132002&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator/configurator.cpp (original)
+++ incubator/mesos/trunk/src/configurator/configurator.cpp Sun Jun  5 08:22:21 2011
@@ -64,6 +64,7 @@ Params& Configurator::load(int argc, cha
   loadEnv();
   loadCommandLine(argc, argv, inferMesosHomeFromArg0);
   loadConfigFileIfGiven();
+  loadDefaults();
   validate();
   return params;
 }
@@ -73,6 +74,7 @@ Params& Configurator::load()
 {
   loadEnv();
   loadConfigFileIfGiven();
+  loadDefaults();
   validate();
   return params;
 }
@@ -83,6 +85,7 @@ Params& Configurator::load(const map<str
   loadEnv();
   params.loadMap(_params);
   loadConfigFileIfGiven();
+  loadDefaults();
   validate();
   return params;
 }
@@ -224,6 +227,7 @@ void Configurator::loadCommandLine(int a
 
 void Configurator::loadConfigFile(const string& fname, bool overwrite) 
 {
+  LOG(INFO) << "Loading config file: " << fname;
   ifstream cfg(fname.c_str(), std::ios::in);
   if (!cfg.is_open()) {
     string message = "Couldn't read Mesos config file: " + fname;
@@ -332,6 +336,15 @@ string Configurator::getUsage() const 
 }
   
 
+void Configurator::loadDefaults() {
+  foreachpair (const string& key, const Option& option, options) {
+    if (option.hasDefault && !params.contains(key)) {
+      params[key] = option.defaultValue;
+    }
+  }
+}
+
+
 vector<string> Configurator::getOptions() const 
 {
   vector<string> ret;

Modified: incubator/mesos/trunk/src/configurator/configurator.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator/configurator.hpp?rev=1132002&r1=1132001&r2=1132002&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator/configurator.hpp (original)
+++ incubator/mesos/trunk/src/configurator/configurator.hpp Sun Jun  5 08:22:21 2011
@@ -118,10 +118,6 @@ private:
                            shortName,
                            hasDefault,
                            defaultValue);
-    if (hasDefault && !params.contains(name)) {
-      // insert default value into params
-      params[name] = defaultValue;
-    }
   }
 
 public:
@@ -315,6 +311,11 @@ private:
   void loadConfigFileIfGiven(bool overwrite = false);
 
   /**
+   * Load default values of options whose values have not already been set.
+   */
+  void loadDefaults();
+
+  /**
    * Gets the first long name option associated with the provided short name.
    * @param shortName character representing the short name of the option
    * @return first long name option matching the short name, "" if none found.

Modified: incubator/mesos/trunk/src/tests/test_configurator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_configurator.cpp?rev=1132002&r1=1132001&r2=1132002&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_configurator.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_configurator.cpp Sun Jun  5 08:22:21 2011
@@ -34,12 +34,13 @@ TEST(ConfiguratorTest, Environment)
 
 TEST(ConfiguratorTest, DefaultOptions)
 {
-  const int ARGC = 4;
+  const int ARGC = 5;
   char* argv[ARGC];
   argv[0] = (char*) "bin/filename";
   argv[1] = (char*) "--test1=501";
   argv[2] = (char*) "--test2";
   argv[3] = (char*) "--excp=txt";
+  argv[4] = (char*) "--test8=foo";
 
   Configurator conf;
 
@@ -48,9 +49,11 @@ TEST(ConfiguratorTest, DefaultOptions)
   EXPECT_NO_THROW(conf.addOption<long>("test3", "Tests the default", 2010));
   EXPECT_NO_THROW(conf.addOption<string>("test4", "Option without default"));
   EXPECT_NO_THROW(conf.addOption<string>("test5", "Option with a default", 
-                                         "arb"));
+                                         "default"));
   EXPECT_NO_THROW(conf.addOption<bool>("test6", "Toggler...", false));
   EXPECT_NO_THROW(conf.addOption<bool>("test7", "Toggler...", true));
+  EXPECT_NO_THROW(conf.addOption<string>("test8", "Overridden default", 
+                                         "default"));
   EXPECT_NO_THROW(conf.load(ARGC, argv, false));
 
   EXPECT_NO_THROW(conf.addOption<int>("excp", "Exception tester.", 50));
@@ -58,14 +61,15 @@ TEST(ConfiguratorTest, DefaultOptions)
   conf.getParams()["excp"] = "27";
   EXPECT_NO_THROW(conf.validate());
 
-  EXPECT_EQ("501",    conf.getParams()["test1"]);
-  EXPECT_EQ("1",      conf.getParams()["test2"]);
-  EXPECT_EQ("2010",   conf.getParams()["test3"]);
-  EXPECT_EQ("",       conf.getParams()["test4"]);
-  EXPECT_EQ("arb",    conf.getParams()["test5"]);
-  EXPECT_EQ("27",     conf.getParams()["excp"]);
-  EXPECT_EQ("0",      conf.getParams()["test6"]);
-  EXPECT_EQ("1",      conf.getParams()["test7"]);
+  EXPECT_EQ("501",     conf.getParams()["test1"]);
+  EXPECT_EQ("1",       conf.getParams()["test2"]);
+  EXPECT_EQ("2010",    conf.getParams()["test3"]);
+  EXPECT_EQ("",        conf.getParams()["test4"]);
+  EXPECT_EQ("default", conf.getParams()["test5"]);
+  EXPECT_EQ("27",      conf.getParams()["excp"]);
+  EXPECT_EQ("0",       conf.getParams()["test6"]);
+  EXPECT_EQ("1",       conf.getParams()["test7"]);
+  EXPECT_EQ("foo",     conf.getParams()["test8"]);
 }
 
 

Modified: incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp?rev=1132002&r1=1132001&r2=1132002&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_sample_frameworks.cpp Sun Jun  5 08:22:21 2011
@@ -1,6 +1,6 @@
 #include <gtest/gtest.h>
 
-#include "config.hpp"
+#include "config/config.hpp"
 #include "external_test.hpp"
 
 // Run each of the sample frameworks in local mode