mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1131895 - in /incubator/mesos/trunk/src: Makefile.in launcher.cpp launcher.hpp local.cpp nexus_local.cpp slave.cpp slave.hpp slave_main.cpp
Date Sun, 05 Jun 2011 05:46:02 GMT
Author: benh
Date: Sun Jun  5 05:46:02 2011
New Revision: 1131895

URL: http://svn.apache.org/viewvc?rev=1131895&view=rev
Log:
Made cpus and mem options be registered through Slave to reduce code
duplication, and fixed a bug introduced in the previous commit (launcher
was not properly creating directories when given an absolute path to the
work dir).

Modified:
    incubator/mesos/trunk/src/Makefile.in
    incubator/mesos/trunk/src/launcher.cpp
    incubator/mesos/trunk/src/launcher.hpp
    incubator/mesos/trunk/src/local.cpp
    incubator/mesos/trunk/src/nexus_local.cpp
    incubator/mesos/trunk/src/slave.cpp
    incubator/mesos/trunk/src/slave.hpp
    incubator/mesos/trunk/src/slave_main.cpp

Modified: incubator/mesos/trunk/src/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/Makefile.in?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/Makefile.in (original)
+++ incubator/mesos/trunk/src/Makefile.in Sun Jun  5 05:46:02 2011
@@ -196,8 +196,8 @@ slave_webui.o: slave_webui.cpp config.hp
 nexus-slave: slave_main.cpp $(SLAVE_OBJ) $(COMMON_OBJ) slave_webui.o webui/slave/swig/slave_wrap.o
 	$(CXX) $(CXXFLAGS) $(WEBUI_FLAGS) -o $@ $< $(SLAVE_OBJ) slave_webui.o webui/slave/swig/slave_wrap.o
$(COMMON_OBJ) $(LDFLAGS) $(LIBS)
 
-nexus-launcher: launcher_main.cpp launcher.o fatal.o
-	$(CXX) $(CXXFLAGS) -o $@ $< launcher.o fatal.o $(LDFLAGS) $(LIBS)
+nexus-launcher: launcher_main.cpp launcher.o $(COMMON_OBJ)
+	$(CXX) $(CXXFLAGS) -o $@ $< launcher.o $(COMMON_OBJ) $(LDFLAGS) $(LIBS)
 
 nexus-projd: projd.cpp $(COMMON_OBJ)
 	$(CXX) $(CXXFLAGS) -o $@ $< $(COMMON_OBJ) $(LDFLAGS) $(LIBS)

Modified: incubator/mesos/trunk/src/launcher.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/launcher.cpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/launcher.cpp (original)
+++ incubator/mesos/trunk/src/launcher.cpp Sun Jun  5 05:46:02 2011
@@ -16,6 +16,7 @@
 #include <boost/lexical_cast.hpp>
 
 #include "foreach.hpp"
+#include "string_utils.hpp"
 
 using std::cerr;
 using std::cout;
@@ -82,15 +83,17 @@ void ExecutorLauncher::run()
 void ExecutorLauncher::createWorkingDirectory()
 {
   // Split the path into tokens by "/" and make each directory
+  cout << "WORK DIR: " << workDirectory << endl;
   vector<string> tokens;
-  split(workDirectory, "/", &tokens);
-  string dir;
+  StringUtils::split(workDirectory, "/", &tokens);
+  string dir = "";
+  if (workDirectory.find_first_of("/") == 0) // We got an absolute path, so
+    dir = "/";                               // keep the leading slash
   foreach (const string& token, tokens) {
-    if (dir != "")
-      dir += "/";
     dir += token;
     if (mkdir(dir.c_str(), 0755) < 0 && errno != EEXIST)
       fatalerror("Failed to mkdir %s", dir.c_str());
+    dir += "/";
   }
   // TODO: chown the final directory to the framework's user
 }
@@ -211,21 +214,3 @@ void ExecutorLauncher::switchUser()
   if (setuid(passwd->pw_uid) < 0)
     fatalerror("failed to setuid");
 }
-
-
-void ExecutorLauncher::split(const string& str, const string& delims,
-                             vector<string>* tokens)
-{
-  // Start and end of current token; initialize these to the first token in
-  // the string, skipping any leading delimiters
-  size_t start = str.find_first_not_of(delims, 0);
-  size_t end = str.find_first_of(delims, start);
-  while (start != string::npos || end != string::npos) {
-    // Add current token to the vector
-    tokens->push_back(str.substr(start, end-start));
-    // Advance start to first non-delimiter past the current end
-    start = str.find_first_not_of(delims, end);
-    // Advance end to the next delimiter after the new start
-    end = str.find_first_of(delims, start);
-  }
-}

Modified: incubator/mesos/trunk/src/launcher.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/launcher.hpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/launcher.hpp (original)
+++ incubator/mesos/trunk/src/launcher.hpp Sun Jun  5 05:46:02 2011
@@ -59,9 +59,6 @@ protected:
 
   // Switch to a framework's user in preparation for exec()'ing its executor.
   virtual void switchUser();
-
-  // Split a string into non-empty tokens using the given delimiter chars.
-  void split(const string& str, const string& delims, vector<string>* tokens);
 };
 
 }}}

Modified: incubator/mesos/trunk/src/local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local.cpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local.cpp (original)
+++ incubator/mesos/trunk/src/local.cpp Sun Jun  5 05:46:02 2011
@@ -19,7 +19,11 @@ using nexus::internal::slave::Slave;
 void usage(const char* programName, const Configurator& conf)
 {
   cerr << "Usage: " << programName
-       << " [--port=PORT] [--slaves=NUM] [--cpus=NUM] [--mem=NUM] [...]" << endl
+       << " [--port=PORT] [--slaves=N] [--cpus=CPUS] [--mem=MEM] [...]" << endl
+       << endl
+       << "Launches a single-process cluster containing N slaves, each of "
+       << "which report" << endl << "CPUS cores and MEM bytes of memory."
+       << endl
        << endl
        << "Supported options:" << endl
        << conf.getUsage();
@@ -31,9 +35,6 @@ int main (int argc, char **argv)
   Configurator conf;
   conf.addOption<int>("port", 'p', "Port to listen on", 50010);
   conf.addOption<int>("slaves", 's', "Number of slaves", 1);
-  conf.addOption<int32_t>("cpus", 'c', "CPU cores for tasks per slave", 1);
-  conf.addOption<int64_t>("mem", 'm', "Memory for tasks per slave, in bytes\n",
-                          1 * Gigabyte);
   Logging::registerOptions(&conf);
   Master::registerOptions(&conf);
   Slave::registerOptions(&conf);

Modified: incubator/mesos/trunk/src/nexus_local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_local.cpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_local.cpp (original)
+++ incubator/mesos/trunk/src/nexus_local.cpp Sun Jun  5 05:46:02 2011
@@ -56,8 +56,6 @@ PID launch(int numSlaves, int32_t cpus, 
 PID launch(const Params& conf, bool initLogging)
 {
   int numSlaves = conf.get<int>("slaves", 1);
-  int32_t cpus = conf.get<int32_t>("cpus", 1);
-  int64_t mem = conf.get<int64_t>("mem", 1 * Gigabyte);
   bool quiet = conf.get<bool>("quiet", false);
 
   if (master != NULL)
@@ -79,7 +77,7 @@ PID launch(const Params& conf, bool init
     // TODO(benh): Create a local isolation module?
     ProcessBasedIsolationModule *isolationModule =
       new ProcessBasedIsolationModule();
-    Slave* slave = new Slave(conf, Resources(cpus, mem), true, isolationModule);
+    Slave* slave = new Slave(conf, true, isolationModule);
     slaves[isolationModule] = slave;
     pids.push_back(Process::spawn(slave));
   }

Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun  5 05:46:02 2011
@@ -58,6 +58,12 @@ public:
     : master(_master), slave(_slave), sid(_sid), interval(_interval) {}
 };
 
+
+// Default values for CPU cores and memory to include in configuration
+const int32_t DEFAULT_CPUS = 1;
+const int64_t DEFAULT_MEM = 1 * Gigabyte;
+
+
 } /* namespace */
 
 
@@ -67,14 +73,20 @@ Slave::Slave(Resources _resources, bool 
     isolationModule(_isolationModule) {}
 
 
-Slave::Slave(const Params& _conf, Resources _resources, bool _local,
-             IsolationModule *_isolationModule)
-  : id(""), conf(_conf), resources(_resources), local(_local),
-    isolationModule(_isolationModule) {}
+Slave::Slave(const Params& _conf, bool _local, IsolationModule *_module)
+  : id(""), conf(_conf), local(_local), isolationModule(_module)
+{
+  resources = Resources(conf.get<int32_t>("cpus", DEFAULT_CPUS),
+                        conf.get<int64_t>("mem", DEFAULT_MEM));
+}
 
 
 void Slave::registerOptions(Configurator* conf)
 {
+  conf->addOption<int32_t>("cpus", 'c', "CPU cores for use by tasks",
+                           DEFAULT_CPUS);
+  conf->addOption<int64_t>("mem", 'm', "Memory for use by tasks, in bytes\n",
+                           DEFAULT_MEM);
   conf->addOption<string>("work_dir",
                           "Where to place framework work directories\n"
                           "(default: MESOS_HOME/work)");

Modified: incubator/mesos/trunk/src/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.hpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave.hpp Sun Jun  5 05:46:02 2011
@@ -178,10 +178,7 @@ public:
 public:
   Slave(Resources resources, bool local, IsolationModule* isolationModule);
 
-  Slave(const Params& conf,
-        Resources resources,
-        bool local,
-        IsolationModule *isolationModule);
+  Slave(const Params& conf, bool local, IsolationModule *isolationModule);
 
   virtual ~Slave();
 

Modified: incubator/mesos/trunk/src/slave_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave_main.cpp?rev=1131895&r1=1131894&r2=1131895&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave_main.cpp (original)
+++ incubator/mesos/trunk/src/slave_main.cpp Sun Jun  5 05:46:02 2011
@@ -36,9 +36,6 @@ int main(int argc, char **argv)
   conf.addOption<string>("url", 'u', "Master URL");
   conf.addOption<int>("port", 'p', "Port to bind to (default: random)");
   conf.addOption<string>("isolation", 'i', "Isolation module name", "process");
-  conf.addOption<int32_t>("cpus", 'c', "CPU cores to use for tasks", 1);
-  conf.addOption<int64_t>("mem", 'm', "Memory to use for tasks, in bytes\n",
-                          1 * Gigabyte);
 #ifdef NEXUS_WEBUI
   conf.addOption<int>("webui_port", 'w', "Web UI port", 8081);
 #endif
@@ -84,9 +81,7 @@ int main(int argc, char **argv)
   if (chdir(dirname(argv[0])) != 0)
     fatalerror("Could not chdir into %s", dirname(argv[0]));
 
-  Resources resources(params.get<int32_t>("cpus", 1),
-                      params.get<int64_t>("mem", 1 * Gigabyte));
-  Slave* slave = new Slave(params, resources, false, isolationModule);
+  Slave* slave = new Slave(params, false, isolationModule);
   PID pid = Process::spawn(slave);
 
   bool quiet = Logging::isQuiet(params);



Mime
View raw message