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:46:19 UTC
svn commit: r1131897 - in /incubator/mesos/trunk: include/ src/
src/swig/java/ src/tests/external/SampleFrameworks/
Author: benh
Date: Sun Jun 5 05:46:19 2011
New Revision: 1131897
URL: http://svn.apache.org/viewvc?rev=1131897&view=rev
Log:
Made NexusSchedulerDriver load config values from the environment, and
also added constructors that allow them to be loaded from a map or from
command-line arguments.
Also removed a debug statement left by mistake in launcher.cpp.
Modified:
incubator/mesos/trunk/include/nexus_sched.hpp
incubator/mesos/trunk/src/configurator.cpp
incubator/mesos/trunk/src/configurator.hpp
incubator/mesos/trunk/src/launcher.cpp
incubator/mesos/trunk/src/nexus_sched.cpp
incubator/mesos/trunk/src/swig/java/TestFramework.java
incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFramework.sh
incubator/mesos/trunk/src/tests/external/SampleFrameworks/CppFramework.sh
incubator/mesos/trunk/src/tests/external/SampleFrameworks/JavaFramework.sh
incubator/mesos/trunk/src/tests/external/SampleFrameworks/PythonFramework.sh
Modified: incubator/mesos/trunk/include/nexus_sched.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/include/nexus_sched.hpp?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/include/nexus_sched.hpp (original)
+++ incubator/mesos/trunk/include/nexus_sched.hpp Sun Jun 5 05:46:19 2011
@@ -11,7 +11,11 @@ namespace nexus {
class SchedulerDriver;
-namespace internal { class SchedulerProcess; class MasterDetector; }
+namespace internal {
+class SchedulerProcess;
+class MasterDetector;
+class Params;
+}
/**
@@ -77,10 +81,57 @@ public:
class NexusSchedulerDriver : public SchedulerDriver
{
public:
+ /**
+ * Create a scheduler driver with a given Mesos master URL.
+ * Additional Mesos config options are read from the environment, as well
+ * as any config files found through it.
+ *
+ * @param sched scheduler to make callbacks into
+ * @param url Mesos master URL
+ * @param fid optional framework ID for registering redundant schedulers
+ * for the same framework
+ */
NexusSchedulerDriver(Scheduler* sched,
const std::string& url,
FrameworkID fid = "");
+ /**
+ * Create a scheduler driver with a configuration, which the master URL
+ * and possibly other options are read from.
+ * Additional Mesos config options are read from the environment, as well
+ * as any config files given through conf or found in the environment.
+ *
+ * @param sched scheduler to make callbacks into
+ * @param params Map containing configuration options
+ * @param fid optional framework ID for registering redundant schedulers
+ * for the same framework
+ */
+ NexusSchedulerDriver(Scheduler* sched,
+ const string_map& params,
+ FrameworkID fid = "");
+
+#ifndef SWIG
+ /**
+ * Create a scheduler driver with a config read from command-line arguments.
+ * Additional Mesos config options are read from the environment, as well
+ * as any config files given through conf or found in the environment.
+ *
+ * This constructor is not available through SWIG since it's difficult
+ * for it to properly map arrays to an argc/argv pair.
+ *
+ * @param sched scheduler to make callbacks into
+ * @param argc argument count
+ * @param argv argument values (argument 0 is expected to be program name
+ * and will not be looked at for options)
+ * @param fid optional framework ID for registering redundant schedulers
+ * for the same framework
+ */
+ NexusSchedulerDriver(Scheduler* sched,
+ int argc,
+ char** argv,
+ FrameworkID fid = "");
+#endif
+
virtual ~NexusSchedulerDriver();
// Lifecycle methods
@@ -102,6 +153,9 @@ public:
virtual Scheduler* getScheduler() { return sched; }
private:
+ // Initialization method used by constructors
+ void init(Scheduler* sched, internal::Params* conf, FrameworkID fid);
+
// Internal utility method to report an error to the scheduler
void error(int code, const std::string& message);
@@ -115,6 +169,10 @@ private:
// Coordination between masters
internal::MasterDetector* detector;
+ // Configuration options. We're using a pointer here because we don't
+ // want to #include params.hpp into the public API.
+ internal::Params* conf;
+
// Are we currently registered with the master
bool running;
Modified: incubator/mesos/trunk/src/configurator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator.cpp?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator.cpp (original)
+++ incubator/mesos/trunk/src/configurator.cpp Sun Jun 5 05:46:19 2011
@@ -10,9 +10,6 @@
#include "params.hpp"
#include "string_utils.hpp"
-extern char** environ; // libc's environment variable list; for some reason,
- // this is not in headers on all platforms
-
using namespace nexus::internal;
@@ -21,6 +18,22 @@ const char* Configurator::CONFIG_FILE_NA
const char* Configurator::ENV_VAR_PREFIX = "MESOS_";
+// Define a function for accessing the list of environment variables
+// in a platform-independent way.
+// On Mac OS X, the environ symbol isn't visible to shared libraries,
+// so we must use the _NSGetEnviron() function (see man environ on OS X).
+// On other platforms, it's fine to access environ from shared libraries.
+namespace {
+#ifdef __APPLE__
+ #include "crt_externs.h"
+ char** getEnviron() { return *_NSGetEnviron(); }
+#else
+ extern char** environ;
+ char** getEnviron() { return environ; }
+#endif /* __APPLE__ */
+}
+
+
void Configurator::validate()
{
foreachpair (const string& key, const Option& opt, options) {
@@ -75,6 +88,7 @@ void Configurator::loadConfigFileIfGiven
void Configurator::loadEnv(bool overwrite)
{
+ char** environ = getEnviron();
int i = 0;
while (environ[i] != NULL) {
string line = environ[i];
@@ -96,9 +110,9 @@ void Configurator::loadEnv(bool overwrit
void Configurator::loadCommandLine(int argc,
- char** argv,
- bool inferMesosHomeFromArg0,
- bool overwrite)
+ char** argv,
+ bool inferMesosHomeFromArg0,
+ bool overwrite)
{
// Set home based on argument 0 if asked to do so
if (inferMesosHomeFromArg0) {
Modified: incubator/mesos/trunk/src/configurator.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator.hpp?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator.hpp (original)
+++ incubator/mesos/trunk/src/configurator.hpp Sun Jun 5 05:46:19 2011
@@ -277,7 +277,9 @@ private:
* @param overwrite whether to overwrite keys that already have values
* in the internal params (true by default)
**/
- void loadCommandLine(int argc, char** argv, bool inferMesosHomeFromArg0,
+ void loadCommandLine(int argc,
+ char** argv,
+ bool inferMesosHomeFromArg0,
bool overwrite=true);
/**
Modified: incubator/mesos/trunk/src/launcher.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/launcher.cpp?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/launcher.cpp (original)
+++ incubator/mesos/trunk/src/launcher.cpp Sun Jun 5 05:46:19 2011
@@ -83,7 +83,6 @@ void ExecutorLauncher::run()
void ExecutorLauncher::createWorkingDirectory()
{
// Split the path into tokens by "/" and make each directory
- cout << "WORK DIR: " << workDirectory << endl;
vector<string> tokens;
StringUtils::split(workDirectory, "/", &tokens);
string dir = "";
Modified: incubator/mesos/trunk/src/nexus_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_sched.cpp?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_sched.cpp (original)
+++ incubator/mesos/trunk/src/nexus_sched.cpp Sun Jun 5 05:46:19 2011
@@ -405,12 +405,50 @@ void Scheduler::error(SchedulerDriver* d
}
-NexusSchedulerDriver::NexusSchedulerDriver(Scheduler* _sched,
- const string &_url,
- FrameworkID _fid)
- : sched(_sched), url(_url), fid(_fid), running(false),
- process(NULL), detector(NULL)
+NexusSchedulerDriver::NexusSchedulerDriver(Scheduler* sched,
+ const string &url,
+ FrameworkID fid)
{
+ Configurator configurator;
+ Params* conf = new Params(configurator.load());
+ conf->set("url", url); // Override URL param with the one from the user
+ init(sched, conf, fid);
+}
+
+
+NexusSchedulerDriver::NexusSchedulerDriver(Scheduler* sched,
+ const string_map ¶ms,
+ FrameworkID fid)
+{
+ Configurator configurator;
+ Params* conf = new Params(configurator.load(params));
+ init(sched, conf, fid);
+}
+
+
+NexusSchedulerDriver::NexusSchedulerDriver(Scheduler* sched,
+ int argc,
+ char** argv,
+ FrameworkID fid)
+{
+ Configurator configurator;
+ Params* conf = new Params(configurator.load(argc, argv, false));
+ init(sched, conf, fid);
+}
+
+
+void NexusSchedulerDriver::init(Scheduler* _sched,
+ Params* _conf,
+ FrameworkID _fid)
+{
+ sched = _sched;
+ conf = _conf;
+ fid = _fid;
+ url = conf->get<string>("url", "local");
+ process = NULL;
+ detector = NULL;
+ running = false;
+
// Create mutex and condition variable
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
@@ -439,10 +477,17 @@ NexusSchedulerDriver::~NexusSchedulerDri
// that we could add a method to libprocess that told us whether or
// not this was about to be deadlock, and possibly report this back
// to the user somehow.
- Process::wait(process);
- delete process;
+ if (process != NULL) {
+ Process::wait(process);
+ delete process;
+ }
- MasterDetector::destroy(detector);
+ if (detector != NULL) {
+ MasterDetector::destroy(detector);
+ }
+
+ // Delete conf since we always create it ourselves with new
+ delete conf;
// Check and see if we need to shutdown a local cluster.
if (url == "local" || url == "localquiet")
@@ -467,14 +512,11 @@ int NexusSchedulerDriver::start()
// Check and see if we need to launch a local cluster.
if (url == "local") {
- // TODO(benh): Get number of slaves and resources per slave from
- // command line (or environment or configuration?).
- PID master = local::launch(1, 1, 1073741824, true, false);
+ PID master = local::launch(*conf, true);
detector = new BasicMasterDetector(master, pid);
} else if (url == "localquiet") {
- // TODO(benh): Get number of slaves and resources per slave from
- // command line (or environment?).
- PID master = local::launch(1, 1, 1073741824, true, true);
+ conf->set("quiet", 1);
+ PID master = local::launch(*conf, true);
detector = new BasicMasterDetector(master, pid);
} else {
detector = MasterDetector::create(url, pid, false, true);
@@ -832,7 +874,14 @@ int nexus_sched_reg(struct nexus_sched*
return -1;
}
- cs->driver = new NexusSchedulerDriver(cs, master);
+ try {
+ cs->driver = new NexusSchedulerDriver(cs, master);
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(sched, 2, message.c_str());
+ return -2;
+ }
+
cs->driver->start();
return 0;
Modified: incubator/mesos/trunk/src/swig/java/TestFramework.java
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/swig/java/TestFramework.java?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/swig/java/TestFramework.java (original)
+++ incubator/mesos/trunk/src/swig/java/TestFramework.java Sun Jun 5 05:46:19 2011
@@ -40,18 +40,20 @@ public class TestFramework {
SlaveOfferVector offers) {
System.out.println("Got offer offer " + oid);
TaskDescriptionVector tasks = new TaskDescriptionVector();
- if (launchedTasks < totalTasks) {
- SlaveOffer offer = offers.get(0);
- int taskId = launchedTasks++;
- StringMap taskParams = new StringMap();
- taskParams.set("cpus", "1");
- taskParams.set("mem", "134217728");
- System.out.println("Launching task " + taskId);
- tasks.add(new TaskDescription(taskId,
- offer.getSlaveId(),
- "task " + taskId,
- taskParams,
- new byte[0]));
+ for (int i = 0; i < offers.size(); i++) {
+ if (launchedTasks < totalTasks) {
+ SlaveOffer offer = offers.get(i);
+ int taskId = launchedTasks++;
+ StringMap taskParams = new StringMap();
+ taskParams.set("cpus", "1");
+ taskParams.set("mem", "134217728");
+ System.out.println("Launching task " + taskId);
+ tasks.add(new TaskDescription(taskId,
+ offer.getSlaveId(),
+ "task " + taskId,
+ taskParams,
+ new byte[0]));
+ }
}
StringMap params = new StringMap();
params.set("timeout", "1");
Modified: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFramework.sh?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/CFramework.sh Sun Jun 5 05:46:19 2011
@@ -1,4 +1,7 @@
#!/bin/sh
+# Set local Mesos runner to use 3 slaves
+export MESOS_SLAVES=3
+
# Check that the C test framework executes without crashing (returns 0).
exec $MESOS_HOME/test-framework local
Modified: incubator/mesos/trunk/src/tests/external/SampleFrameworks/CppFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/CppFramework.sh?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/CppFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/CppFramework.sh Sun Jun 5 05:46:19 2011
@@ -1,4 +1,7 @@
#!/bin/sh
+# Set local Mesos runner to use 3 slaves
+export MESOS_SLAVES=3
+
# Check that the C++ test framework executes without crashing (returns 0).
exec $MESOS_HOME/cpp-test-framework local
Modified: incubator/mesos/trunk/src/tests/external/SampleFrameworks/JavaFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/JavaFramework.sh?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/JavaFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/JavaFramework.sh Sun Jun 5 05:46:19 2011
@@ -1,4 +1,7 @@
#!/bin/sh
+# Set local Mesos runner to use 3 slaves
+export MESOS_SLAVES=3
+
# Check that the Java test framework executes without crashing (returns 0).
exec $MESOS_HOME/swig/java/test_framework local
Modified: incubator/mesos/trunk/src/tests/external/SampleFrameworks/PythonFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/SampleFrameworks/PythonFramework.sh?rev=1131897&r1=1131896&r2=1131897&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/SampleFrameworks/PythonFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/SampleFrameworks/PythonFramework.sh Sun Jun 5 05:46:19 2011
@@ -1,4 +1,7 @@
#!/bin/sh
+# Set local Mesos runner to use 3 slaves
+export MESOS_SLAVES=3
+
# Check that the Java test framework executes without crashing (returns 0).
exec $MESOS_HOME/swig/python/test_framework local