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:26 UTC
svn commit: r1131898 - in /incubator/mesos/trunk: include/nexus_sched.h
src/nexus_sched.cpp
Author: benh
Date: Sun Jun 5 05:46:26 2011
New Revision: 1131898
URL: http://svn.apache.org/viewvc?rev=1131898&view=rev
Log:
Further updates to NexusSchedulerDriver config support:
- Added C API functions for passing parameters or argc/argv
- Report config errors through error() callback in C++
Modified:
incubator/mesos/trunk/include/nexus_sched.h
incubator/mesos/trunk/src/nexus_sched.cpp
Modified: incubator/mesos/trunk/include/nexus_sched.h
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/include/nexus_sched.h?rev=1131898&r1=1131897&r2=1131898&view=diff
==============================================================================
--- incubator/mesos/trunk/include/nexus_sched.h (original)
+++ incubator/mesos/trunk/include/nexus_sched.h Sun Jun 5 05:46:26 2011
@@ -41,7 +41,17 @@ struct nexus_sched {
int nexus_sched_init(struct nexus_sched*);
int nexus_sched_destroy(struct nexus_sched*);
-int nexus_sched_reg(struct nexus_sched*, const char*);
+// Register a scheduler, connecting to a given URL
+int nexus_sched_reg(struct nexus_sched*, const char* url);
+
+// Register a scheduler, connecting to the master URL specified through the
+// given options string (which should contain key=value pairs, one per line).
+int nexus_sched_reg_with_params(struct nexus_sched*, const char* params);
+
+// Register a scheduler, connecting to the master URL specified through the
+// given command line arguments. Note that argv[0] is expected to be the
+// program name and is therefore ignored by Mesos.
+int nexus_sched_reg_with_cmdline(struct nexus_sched*, int argc, char** argv);
int nexus_sched_unreg(struct nexus_sched*);
Modified: incubator/mesos/trunk/src/nexus_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_sched.cpp?rev=1131898&r1=1131897&r2=1131898&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_sched.cpp (original)
+++ incubator/mesos/trunk/src/nexus_sched.cpp Sun Jun 5 05:46:26 2011
@@ -136,7 +136,7 @@ protected:
// Get username of current user.
struct passwd* passwd;
if ((passwd = getpwuid(getuid())) == NULL)
- fatal("failed to get username information");
+ fatal("NexusSchedulerDriver failed to get username information");
const string user(passwd->pw_name);
@@ -410,7 +410,14 @@ NexusSchedulerDriver::NexusSchedulerDriv
FrameworkID fid)
{
Configurator configurator;
- Params* conf = new Params(configurator.load());
+ Params* conf;
+ try {
+ conf = new Params(configurator.load());
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(this, 2, message);
+ conf = new Params();
+ }
conf->set("url", url); // Override URL param with the one from the user
init(sched, conf, fid);
}
@@ -421,7 +428,13 @@ NexusSchedulerDriver::NexusSchedulerDriv
FrameworkID fid)
{
Configurator configurator;
- Params* conf = new Params(configurator.load(params));
+ try {
+ conf = new Params(configurator.load(params));
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(this, 2, message);
+ conf = new Params();
+ }
init(sched, conf, fid);
}
@@ -432,7 +445,13 @@ NexusSchedulerDriver::NexusSchedulerDriv
FrameworkID fid)
{
Configurator configurator;
- Params* conf = new Params(configurator.load(argc, argv, false));
+ try {
+ conf = new Params(configurator.load(argc, argv, false));
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(this, 2, message);
+ conf = new Params();
+ }
init(sched, conf, fid);
}
@@ -888,6 +907,65 @@ int nexus_sched_reg(struct nexus_sched*
}
+int nexus_sched_reg_with_params(struct nexus_sched* sched, const char* params)
+{
+ if (sched == NULL || params == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ CScheduler* cs = lookupCScheduler(sched);
+
+ if (cs->driver != NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ try {
+ Params paramsObj(params);
+ cs->driver = new NexusSchedulerDriver(cs, paramsObj.getMap());
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(sched, 2, message.c_str());
+ return -2;
+ }
+
+ cs->driver->start();
+
+ return 0;
+}
+
+
+int nexus_sched_reg_with_cmdline(struct nexus_sched* sched,
+ int argc,
+ char** argv)
+{
+ if (sched == NULL || argc < 0 || argv == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ CScheduler* cs = lookupCScheduler(sched);
+
+ if (cs->driver != NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ try {
+ cs->driver = new NexusSchedulerDriver(cs, argc, argv);
+ } catch (ConfigurationException& e) {
+ string message = string("Configuration error: ") + e.what();
+ sched->error(sched, 2, message.c_str());
+ return -2;
+ }
+
+ cs->driver->start();
+
+ return 0;
+}
+
+
int nexus_sched_unreg(struct nexus_sched* sched)
{
if (sched == NULL) {