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 07:45:54 UTC
svn commit: r1131894 - in /incubator/mesos/trunk/src: configurator.cpp
configurator.hpp launcher.cpp local.cpp master_main.cpp nexus_local.cpp
nexus_local.hpp slave.cpp slave_main.cpp
Author: benh
Date: Sun Jun 5 05:45:54 2011
New Revision: 1131894
URL: http://svn.apache.org/viewvc?rev=1131894&view=rev
Log:
Made work directory configurable for both nexus-slave and nexus-local.
In the process, made it possible for local to be given a configuration, so
that the slave, master, etc actually load the correct parameters. Also
made Configurator::load slightly easier to use.
Fixes #20.
Modified:
incubator/mesos/trunk/src/configurator.cpp
incubator/mesos/trunk/src/configurator.hpp
incubator/mesos/trunk/src/launcher.cpp
incubator/mesos/trunk/src/local.cpp
incubator/mesos/trunk/src/master_main.cpp
incubator/mesos/trunk/src/nexus_local.cpp
incubator/mesos/trunk/src/nexus_local.hpp
incubator/mesos/trunk/src/slave.cpp
incubator/mesos/trunk/src/slave_main.cpp
Modified: incubator/mesos/trunk/src/configurator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator.cpp (original)
+++ incubator/mesos/trunk/src/configurator.cpp Sun Jun 5 05:45:54 2011
@@ -33,29 +33,32 @@ void Configurator::validate()
}
-void Configurator::load(int argc, char** argv, bool inferMesosHomeFromArg0)
+Params& Configurator::load(int argc, char** argv, bool inferMesosHomeFromArg0)
{
loadEnv();
loadCommandLine(argc, argv, inferMesosHomeFromArg0);
loadConfigFileIfGiven();
validate();
+ return params;
}
-void Configurator::load()
+Params& Configurator::load()
{
loadEnv();
loadConfigFileIfGiven();
validate();
+ return params;
}
-void Configurator::load(const map<string, string>& _params)
+Params& Configurator::load(const map<string, string>& _params)
{
loadEnv();
params.loadMap(_params);
loadConfigFileIfGiven();
validate();
+ return params;
}
Modified: incubator/mesos/trunk/src/configurator.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator.hpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator.hpp (original)
+++ incubator/mesos/trunk/src/configurator.hpp Sun Jun 5 05:45:54 2011
@@ -202,7 +202,7 @@ public:
* <i>Environment:</i><br>
* Parses the environment variables and populates a Params.
* It picks all environment variables that start with MESOS_.
- * The environment variable MESOS_HOME=/dir would lead to key=HOME val=/dir<br>
+ * The environment var MESOS_HOME=/dir would lead to key=HOME val=/dir<br>
* <i>Command line:</i><br>
* It extracts four type of command line parameters:
* "--key=val", "-key val", "--key", "-key". The two last cases will
@@ -215,8 +215,9 @@ public:
* @param argv is an array of c-strings containing params
* @param inferMesosHomeFromArg0 whether to set mesos home to directory
* containing argv[0] (the program being run)
+ * @return the loaded Params object
**/
- void load(int argc, char** argv, bool inferMesosHomeFromArg0=false);
+ Params& load(int argc, char** argv, bool inferMesosHomeFromArg0=false);
/**
@@ -225,12 +226,14 @@ public:
* <i>Environment:</i><br>
* Parses the environment variables and populates a Params.
* It picks all environment variables that start with MESOS_.
- * The environment variable MESOS_HOME=/dir would lead to key=HOME val=/dir <br>
+ * The environment var MESOS_HOME=/dir would lead to key=home val=/dir <br>
* <i>Config file:</i><br>
* The config file should contain key=value pairs, one per line.
* Comments, which should start with #, are ignored.
+ *
+ * @return the loaded Params object
**/
- void load();
+ Params& load();
/**
@@ -239,7 +242,7 @@ public:
* <i>Environment:</i><br>
* Parses the environment variables and populates a Params.
* It picks all environment variables that start with MESOS_.
- * The environment variable MESOS_HOME=/dir would lead to key=HOME val=/dir <br>
+ * The environment var MESOS_HOME=/dir would lead to key=HOME val=/dir <br>
* <i>Map:</i><br>
* Containing a string to string map. <br>
* <i>Config file:</i><br>
@@ -247,8 +250,9 @@ public:
* Comments, which should start with #, are ignored.
*
* @param _params map containing key value pairs to be loaded
+ * @return the loaded Params object
**/
- void load(const map<string, string>& _params);
+ Params& load(const map<string, string>& _params);
private:
/**
Modified: incubator/mesos/trunk/src/launcher.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/launcher.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/launcher.cpp (original)
+++ incubator/mesos/trunk/src/launcher.cpp Sun Jun 5 05:45:54 2011
@@ -90,7 +90,7 @@ void ExecutorLauncher::createWorkingDire
dir += "/";
dir += token;
if (mkdir(dir.c_str(), 0755) < 0 && errno != EEXIST)
- fatalerror("mkdir failed");
+ fatalerror("Failed to mkdir %s", dir.c_str());
}
// TODO: chown the final directory to the framework's user
}
Modified: incubator/mesos/trunk/src/local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/local.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/local.cpp (original)
+++ incubator/mesos/trunk/src/local.cpp Sun Jun 5 05:45:54 2011
@@ -45,8 +45,7 @@ int main (int argc, char **argv)
Params params;
try {
- conf.load(argc, argv, true);
- params = conf.getParams();
+ params = conf.load(argc, argv, true);
} catch (ConfigurationException& e) {
cerr << "Configuration error: " << e.what() << endl;
exit(1);
@@ -57,12 +56,7 @@ int main (int argc, char **argv)
if (params.contains("port"))
setenv("LIBPROCESS_PORT", params["port"].c_str(), 1);
- int slaves = params.get<int>("slaves", 1);
- int32_t cpus = params.get<int32_t>("cpus", 1);
- int64_t mem = params.get<int64_t>("mem", 1 * Gigabyte);
- bool quiet = Logging::isQuiet(params);
-
- const PID &master = local::launch(slaves, cpus, mem, false, quiet);
+ const PID &master = local::launch(params, false);
Process::wait(master);
Modified: incubator/mesos/trunk/src/master_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master_main.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master_main.cpp (original)
+++ incubator/mesos/trunk/src/master_main.cpp Sun Jun 5 05:45:54 2011
@@ -45,8 +45,7 @@ int main(int argc, char **argv)
Params params;
try {
- conf.load(argc, argv, true);
- params = conf.getParams();
+ params = conf.load(argc, argv, true);
} catch (ConfigurationException& e) {
cerr << "Configuration error: " << e.what() << endl;
exit(1);
Modified: incubator/mesos/trunk/src/nexus_local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_local.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_local.cpp (original)
+++ incubator/mesos/trunk/src/nexus_local.cpp Sun Jun 5 05:45:54 2011
@@ -44,6 +44,22 @@ static MasterDetector *detector = NULL;
PID launch(int numSlaves, int32_t cpus, int64_t mem,
bool initLogging, bool quiet)
{
+ Params conf;
+ conf.set("slaves", numSlaves);
+ conf.set("cpus", cpus);
+ conf.set("mem", mem);
+ conf.set("quiet", quiet);
+ return launch(conf, initLogging);
+}
+
+
+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)
fatal("can only launch one local cluster at a time (for now)");
@@ -53,7 +69,6 @@ PID launch(int numSlaves, int32_t cpus,
google::SetStderrLogging(google::INFO);
}
- Params conf;
master = new Master(conf);
PID pid = Process::spawn(master);
Modified: incubator/mesos/trunk/src/nexus_local.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_local.hpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_local.hpp (original)
+++ incubator/mesos/trunk/src/nexus_local.hpp Sun Jun 5 05:45:54 2011
@@ -6,11 +6,15 @@
#include "master.hpp"
#include "slave.hpp"
+#include "params.hpp"
+
namespace nexus { namespace internal { namespace local {
PID launch(int numSlaves, int32_t cpus, int64_t mem,
bool initLogging, bool quiet);
+PID launch(const Params& conf, bool initLogging);
+
void shutdown();
}}}
Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun 5 05:45:54 2011
@@ -75,6 +75,9 @@ Slave::Slave(const Params& _conf, Resour
void Slave::registerOptions(Configurator* conf)
{
+ conf->addOption<string>("work_dir",
+ "Where to place framework work directories\n"
+ "(default: MESOS_HOME/work)");
}
@@ -488,9 +491,17 @@ void Slave::executorExited(FrameworkID f
string Slave::getWorkDirectory(FrameworkID fid) {
- ostringstream workDir;
- workDir << "work/slave-" << id << "/framework-" << fid;
- return workDir.str();
+ string workDir;
+ if (conf.contains("work_dir")) {
+ workDir = conf["work_dir"];
+ } else if (conf.contains("home")) {
+ workDir = conf["home"] + "/work";
+ } else {
+ workDir = "work";
+ }
+ ostringstream fwDir;
+ fwDir << workDir << "/slave-" << id << "/fw-" << fid;
+ return fwDir.str();
}
Modified: incubator/mesos/trunk/src/slave_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave_main.cpp?rev=1131894&r1=1131893&r2=1131894&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave_main.cpp (original)
+++ incubator/mesos/trunk/src/slave_main.cpp Sun Jun 5 05:45:54 2011
@@ -24,6 +24,8 @@ void usage(const char *programName, cons
<< " zoo://host1:port1,host2:port2,..." << endl
<< " zoofile://file where file contains a host:port pair per line"
<< endl
+ << endl
+ << "Supported options:" << endl
<< conf.getUsage();
}
@@ -32,7 +34,7 @@ int main(int argc, char **argv)
{
Configurator conf;
conf.addOption<string>("url", 'u', "Master URL");
- conf.addOption<int>("port", 'p', "Port to listen on (default: random)");
+ 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",
@@ -50,8 +52,7 @@ int main(int argc, char **argv)
Params params;
try {
- conf.load(argc, argv, true);
- params = conf.getParams();
+ params = conf.load(argc, argv, true);
} catch (ConfigurationException& e) {
cerr << "Configuration error: " << e.what() << endl;
exit(1);