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 05:22:47 UTC
svn commit: r1131558 - in /incubator/mesos/trunk: include/ src/
Author: benh
Date: Sun Jun 5 03:22:46 2011
New Revision: 1131558
URL: http://svn.apache.org/viewvc?rev=1131558&view=rev
Log:
1) URL processor refactored 2) schedulers now use leader detection and reconnect to master 3) files renamed according to our conventions
Added:
incubator/mesos/trunk/src/leader_detector.cpp
- copied, changed from r1131557, incubator/mesos/trunk/src/getleader.cpp
incubator/mesos/trunk/src/leader_detector.hpp
- copied, changed from r1131557, incubator/mesos/trunk/src/getleader.hpp
incubator/mesos/trunk/src/task_info.hpp
- copied, changed from r1131557, incubator/mesos/trunk/src/internalinfo.hpp
incubator/mesos/trunk/src/url_processor.cpp
incubator/mesos/trunk/src/url_processor.hpp
Removed:
incubator/mesos/trunk/src/getleader.cpp
incubator/mesos/trunk/src/getleader.hpp
incubator/mesos/trunk/src/internalinfo.hpp
Modified:
incubator/mesos/trunk/include/nexus_sched.hpp
incubator/mesos/trunk/src/Makefile.in
incubator/mesos/trunk/src/master.cpp
incubator/mesos/trunk/src/master.hpp
incubator/mesos/trunk/src/master_main.cpp
incubator/mesos/trunk/src/messages.hpp
incubator/mesos/trunk/src/nexus_sched.cpp
incubator/mesos/trunk/src/slave.cpp
incubator/mesos/trunk/src/slave.hpp
Modified: incubator/mesos/trunk/include/nexus_sched.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/include/nexus_sched.hpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/include/nexus_sched.hpp (original)
+++ incubator/mesos/trunk/include/nexus_sched.hpp Sun Jun 5 03:22:46 2011
@@ -116,6 +116,7 @@ private:
// Condition variable for waiting until scheduler terminates
pthread_cond_t cond;
+
};
Modified: incubator/mesos/trunk/src/Makefile.in
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/Makefile.in?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/Makefile.in (original)
+++ incubator/mesos/trunk/src/Makefile.in Sun Jun 5 03:22:46 2011
@@ -24,6 +24,8 @@ LIBEV = third_party/libprocess/third_par
GLOG = third_party/glog-0.3.0
GTEST = third_party/gtest-1.4.0-patched
+ZOOKEEPER = third_party/zookeeper-3.2.2/src/c
+
# Ensure that we get better debugging info.
CFLAGS += -g
CXXFLAGS += -g
@@ -48,11 +50,13 @@ LDFLAGS += -Lthird_party/libprocess
# Add libev to LDFLAGS.
LDFLAGS += -L$(LIBEV)/.libs
-# Add glog and gtest to include and lib paths
+# Add glog and gtest and zookeeper to include and lib paths
CXXFLAGS += -I$(GLOG)/src
CXXFLAGS += -I$(GTEST)/include
+CXXFLAGS += -I$(ZOOKEEPER)/include -I$(ZOOKEEPER)/generated -DTHREADED
LDFLAGS += -L$(GLOG)/.libs
LDFLAGS += -L$(GTEST)/lib/.libs
+LDFLAGS += -L$(ZOOKEEPER)/.libs
# Add dependency tracking to CFLAGS, CXXFLAGS.
CFLAGS += -MMD -MP
@@ -67,7 +71,7 @@ CFLAGS += -DBUILD_USER="\"$$USER\""
CXXFLAGS += -DBUILD_USER="\"$$USER\""
# Add libev, libprocess, pthread, and dl to LIBS.
-LIBS += -lglog -lgtest -lprocess -lev -lpthread -ldl
+LIBS += -lglog -lgtest -lprocess -lev -lpthread -ldl -lzookeeper_mt
NEXUS_EXES = nexus-master nexus-slave nexus-local nexus-launcher alltests \
test-framework test-executor cpp-test-framework cpp-test-executor \
@@ -88,7 +92,7 @@ NEXUS_LIBS = $(SCHED_LIB) $(EXEC_LIB) $(
MASTER_OBJ = master.o allocator_factory.o simple_allocator.o
SLAVE_OBJ = slave.o launcher.o isolation_module_factory.o \
process_based_isolation_module.o
-COMMON_OBJ = fatal.o hash_pid.o lock.o messages.o
+COMMON_OBJ = fatal.o hash_pid.o messages.o getleader.o processurl.o
EXEC_LIB_OBJ = nexus_exec.o
SCHED_LIB_OBJ = nexus_sched.o nexus_local.o params.o
TEST_OBJ = tests/main.o tests/test_master.o tests/test_resources.o
@@ -129,7 +133,7 @@ $(NEXUS_LIBS): $(COMMON_OBJ) third_party
$(NEXUS_EXES): $(COMMON_OBJ) third_party/libprocess/libprocess.a
$(SCHED_LIB): $(SCHED_LIB_OBJ) $(MASTER_OBJ) $(SLAVE_OBJ) $(COMMON_OBJ)
- $(AR) rcs $@ $^ third_party/libprocess/libprocess.a $(GLOG)/.libs/libglog.a $(LIBEV)/.libs/libev.a
+ $(AR) rcs $@ $^ third_party/libprocess/libprocess.a $(GLOG)/.libs/libglog.a $(LIBEV)/.libs/libev.a $(ZOOKEEPER)/.libs/libzookeeper_mt.a
$(EXEC_LIB): $(EXEC_LIB_OBJ) $(COMMON_OBJ)
$(AR) rcs $@ $^
@@ -248,6 +252,7 @@ third_party:
$(MAKE) -C third_party/libprocess
$(MAKE) -C $(GLOG)
$(MAKE) -C $(GTEST)
+ $(MAKE) -C $(ZOOKEEPER)
all: third_party $(NEXUS_LIBS) $(NEXUS_EXES) java python ruby
@@ -255,6 +260,7 @@ clean:
$(MAKE) -C third_party/libprocess clean
$(MAKE) -C $(GLOG) clean
$(MAKE) -C $(GTEST) clean
+ $(MAKE) -C $(ZOOKEEPER) clean
rm -f $(patsubst %.o, %.d, $(ALL_OBJ))
rm -f $(ALL_OBJ)
rm -f $(NEXUS_LIBS)
Copied: incubator/mesos/trunk/src/leader_detector.cpp (from r1131557, incubator/mesos/trunk/src/getleader.cpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/leader_detector.cpp?p2=incubator/mesos/trunk/src/leader_detector.cpp&p1=incubator/mesos/trunk/src/getleader.cpp&r1=1131557&r2=1131558&rev=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/getleader.cpp (original)
+++ incubator/mesos/trunk/src/leader_detector.cpp Sun Jun 5 03:22:46 2011
@@ -4,7 +4,7 @@
#include <cstdlib>
#include <zookeeper.h>
#include <glog/logging.h>
-#include "getleader.hpp"
+#include "leader_detector.hpp"
using namespace std;
@@ -121,7 +121,7 @@ string LeaderDetector::getCurrentLeaderD
}
void LeaderDetector::newLeader(string leader, string leaderData) {
- LOG(INFO)<<"## NEW LEADER ## ephemeral id:"<<leader<<" data:"<<leaderData;
+ LOG(INFO)<<"New leader ephemeral_id:"<<leader<<" data:"<<leaderData;
if (leaderListener!=NULL)
leaderListener->newLeaderElected(leader,leaderData);
}
Copied: incubator/mesos/trunk/src/leader_detector.hpp (from r1131557, incubator/mesos/trunk/src/getleader.hpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/leader_detector.hpp?p2=incubator/mesos/trunk/src/leader_detector.hpp&p1=incubator/mesos/trunk/src/getleader.hpp&r1=1131557&r2=1131558&rev=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/getleader.hpp (original)
+++ incubator/mesos/trunk/src/leader_detector.hpp Sun Jun 5 03:22:46 2011
@@ -1,5 +1,5 @@
-#ifndef GETLEADER_HPP_
-#define GETLEADER_HPP_
+#ifndef _LEADER_DETECTOR_HPP_
+#define _LEADER_DETECTOR_HPP_
#include <string>
#include <iostream>
@@ -72,4 +72,4 @@ private:
};
-#endif /* GETLEADER_HPP_ */
+#endif /* _LEADER_DETECTOR_HPP_ */
Modified: incubator/mesos/trunk/src/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.cpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.cpp (original)
+++ incubator/mesos/trunk/src/master.cpp Sun Jun 5 03:22:46 2011
@@ -110,16 +110,38 @@ public:
}
-Master::Master(const bool ft, const string zk)
- : isFT(ft), zkserver(zk), leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
+Master::Master(const string zk)
+ : leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
nextSlotOfferId(0), allocatorType("simple"), masterId(0)
-{}
+{
+ if (zk!="") {
+ pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(zk);
+ if (urlPair.first == UrlProcessor::ZOO) {
+ isFT=true;
+ zkservers = urlPair.second;
+ } else {
+ LOG(ERROR) << "Failed to parse URL for ZooKeeper servers. URL must start with zoo:// or zoofile://";
+ exit(1);
+ }
+ }
+}
-Master::Master(const string& _allocatorType, const bool ft, const string zk)
- : isFT(ft), zkserver(zk), leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
+Master::Master(const string& _allocatorType, const string zk)
+ : leaderDetector(NULL), nextFrameworkId(0), nextSlaveId(0),
nextSlotOfferId(0), allocatorType(_allocatorType), masterId(0)
-{}
+{
+ if (zk!="") {
+ pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(zk);
+ if (urlPair.first == UrlProcessor::ZOO) {
+ isFT=true;
+ zkservers = urlPair.second;
+ } else {
+ LOG(ERROR) << "Failed to parse URL for ZooKeeper servers. URL must start with zoo:// or zoofile://";
+ exit(1);
+ }
+ }
+}
Master::~Master()
@@ -237,13 +259,13 @@ SlotOffer * Master::lookupSlotOffer(Offe
void Master::operator () ()
{
- LOG(INFO) << "Master started at " << self();
+ LOG(INFO) << "Master started at nexus://" << self();
if (isFT) {
- LOG(INFO) << "Conencting to ZooKeeper at "<<zkserver;
+ LOG(INFO) << "Conencting to ZooKeeper at "<<zkservers;
ostringstream lpid;
lpid<<self();
- leaderDetector = new LeaderDetector(zkserver, true, lpid.str());
+ leaderDetector = new LeaderDetector(zkservers, true, lpid.str());
masterId = lexical_cast<long>(leaderDetector->getSequence());
LOG(INFO)<<"Master ID:"<<masterId;
@@ -423,7 +445,8 @@ void Master::operator () ()
removeTask(task, TRR_TASK_ENDED);
}
}
- }
+ } else
+ DLOG(INFO) << "S2M_STATUS_UPDATE error: couldn't lookup slave id" << sid;
break;
}
}
@@ -484,15 +507,10 @@ void Master::operator () ()
framework->removeExpiredFilters();
allocator->timerTick();
- // int cnts=0;
- // foreachpair(_, Slave *slave, slaves) {
- // LOG(INFO)<<(cnts++)<<" resourceInUse:"<<slave->resourcesInUse;
- // pair<FrameworkID, TaskID> par;
- // int cntt=0;
- // foreachpair(par, TaskInfo *t, slave->tasks) {
- // LOG(INFO)<<(cntt++)<<" fid:"<<par.first<<" tid:"<<par.second;
- // }
- // }
+ int cnts=0;
+ foreachpair(_, Framework *framework, frameworks) {
+ LOG(INFO)<<(cnts++)<<" resourceInUse:"<<framework->resources;
+ }
break;
}
Modified: incubator/mesos/trunk/src/master.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.hpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.hpp (original)
+++ incubator/mesos/trunk/src/master.hpp Sun Jun 5 03:22:46 2011
@@ -27,8 +27,9 @@
#include "messages.hpp"
#include "params.hpp"
#include "resources.hpp"
-#include "getleader.hpp"
-#include "internalinfo.hpp"
+#include "leader_detector.hpp"
+#include "task_info.hpp"
+#include "url_processor.hpp"
namespace nexus { namespace internal { namespace master {
@@ -258,8 +259,8 @@ enum TaskRemovalReason
class Master : public Tuple<Process>
{
protected:
- const bool isFT;
- string zkserver;
+ bool isFT;
+ string zkservers;
LeaderDetector *leaderDetector;
unordered_map<FrameworkID, Framework *> frameworks;
unordered_map<SlaveID, Slave *> slaves;
@@ -279,9 +280,9 @@ protected:
long masterId; // Used to differentiate different master in FT mode, will be ephemeral id
public:
- Master(const bool =false, const string ="");
+ Master(const string ="");
- Master(const string& _allocatorType, const bool =false, const string ="");
+ Master(const string& _allocatorType, const string ="");
~Master();
Modified: incubator/mesos/trunk/src/master_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master_main.cpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master_main.cpp (original)
+++ incubator/mesos/trunk/src/master_main.cpp Sun Jun 5 03:22:46 2011
@@ -2,6 +2,7 @@
#include "master.hpp"
#include "master_webui.hpp"
+#include "url_prcessor.hpp"
using std::cerr;
using std::endl;
@@ -11,7 +12,9 @@ using namespace nexus::internal::master;
void usage(const char* programName)
{
cerr << "Usage: " << programName
- << " [--port PORT] [--allocator ALLOCATOR] [--fault-tolerant ZOOKEEPERSERVER] [--quiet]"
+ << " [--port PORT] [--allocator ALLOCATOR] [--fault-tolerant ZOO_SERVERS] [--quiet]"
+ << endl
+ << "ZOO_SERVERS is a url of the form zoo://<zoosrv1>,<zoosrv2>..., or zoofile://listfile"
<< endl;
}
@@ -31,7 +34,7 @@ int main (int argc, char **argv)
};
bool isFT = false;
- string zkserver = "";
+ string zooarg = "";
bool quiet = false;
string allocator = "simple";
@@ -47,7 +50,7 @@ int main (int argc, char **argv)
break;
case 'f':
isFT = true;
- zkserver = optarg;
+ zooarg = optarg;
break;
case 'q':
quiet = true;
@@ -72,7 +75,7 @@ int main (int argc, char **argv)
LOG(INFO) << "Starting Nexus master";
if (isFT)
LOG(INFO) << "Nexus in fault-tolerant mode";
- PID master = Process::spawn(new Master(allocator, isFT, zkserver));
+ PID master = Process::spawn(new Master(allocator, zooarg));
#undef NEXUS_WEBUI
#ifdef NEXUS_WEBUI
Modified: incubator/mesos/trunk/src/messages.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/messages.hpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/messages.hpp (original)
+++ incubator/mesos/trunk/src/messages.hpp Sun Jun 5 03:22:46 2011
@@ -13,7 +13,7 @@
#include "params.hpp"
#include "resources.hpp"
#include "foreach.hpp"
-#include "internalinfo.hpp"
+#include "task_info.hpp"
namespace nexus { namespace internal {
@@ -47,7 +47,7 @@ enum MessageType {
SH2M_HEARTBEAT,
/* From leader election listener to slave */
- LE2S_NEWLEADER,
+ LE_NEWLEADER,
/* From master to slave. */
M2S_REGISTER_REPLY,
@@ -188,7 +188,7 @@ TUPLE(S2M_LOST_EXECUTOR,
TUPLE(SH2M_HEARTBEAT,
(SlaveID));
-TUPLE(LE2S_NEWLEADER,
+TUPLE(LE_NEWLEADER,
(std::string /*PID of new leader*/));
TUPLE(M2S_REGISTER_REPLY,
Modified: incubator/mesos/trunk/src/nexus_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/nexus_sched.cpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/nexus_sched.cpp (original)
+++ incubator/mesos/trunk/src/nexus_sched.cpp Sun Jun 5 03:22:46 2011
@@ -26,7 +26,8 @@
#include "messages.hpp"
#include "nexus_local.hpp"
#include "nexus_sched.hpp"
-
+#include "url_prcessor.hpp"
+#include "leader_detector.hpp"
using std::cerr;
using std::cout;
@@ -66,22 +67,66 @@ private:
FrameworkID fid;
string frameworkName;
ExecutorInfo execInfo;
+ bool isFT;
+ string zkservers;
+ LeaderDetector *leaderDetector;
volatile bool terminate;
+ class SchedLeaderListener;
+ friend class SchedLeaderListener;
+
+ class SchedLeaderListener : public LeaderListener {
+ public:
+ // TODO(alig): make thread safe
+ SchedLeaderListener(SchedulerProcess *s, PID pp) : parent(s), parentPID(pp) {}
+
+ virtual void newLeaderElected(string zkId, string pidStr) {
+ if (zkId!="") {
+ LOG(INFO) << "Leader listener detected leader at " << pidStr <<" with ephemeral id:"<<zkId;
+
+ parent->zkservers = pidStr;
+
+ LOG(INFO) << "Sending message to parent "<<parentPID<<" about new leader";
+ parent->send(parentPID, parent->pack<LE_NEWLEADER>(pidStr));
+
+ }
+ }
+
+ private:
+ SchedulerProcess *parent;
+ PID parentPID;
+ } schedLeaderListener;
+
+
public:
SchedulerProcess(const PID &_master,
NexusSchedulerDriver* _driver,
Scheduler* _sched,
const string& _frameworkName,
- const ExecutorInfo& _execInfo)
+ const ExecutorInfo& _execInfo,
+ const string& _zkservers="")
: master(_master),
driver(_driver),
sched(_sched),
fid("-1"),
terminate(false),
frameworkName(_frameworkName),
- execInfo(_execInfo) {}
+ execInfo(_execInfo),
+ leaderDetector(NULL),
+ schedLeaderListener(this, getPID())
+{
+ if (_zkservers!="") {
+ pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_zkservers);
+ if (urlPair.first == UrlProcessor::ZOO) {
+ isFT=true;
+ zkservers = urlPair.second;
+ } else {
+ cerr << "Failed to parse URL for ZooKeeper servers";
+ exit(1);
+ }
+ }
+}
protected:
void operator () ()
@@ -92,6 +137,20 @@ protected:
fatal("failed to get username information");
string user(passwd->pw_name);
+ if (isFT) {
+ LOG(INFO) << "Connecting to ZooKeeper at " << zkservers;
+ leaderDetector = new LeaderDetector(zkservers, false, "", NULL);
+ leaderDetector->setListener(&schedLeaderListener); // use this instead of constructor to avoid race condition
+
+ pair<string,string> zkleader = leaderDetector->getCurrentLeader();
+ LOG(INFO) << "Detected leader at " << zkleader.second <<" with ephemeral id:"<<zkleader.first;
+
+ istringstream iss(zkleader.second);
+ if (!(iss >> master)) {
+ cerr << "Failed to resolve master PID " << zkleader.second << endl;
+ }
+ }
+
link(master);
send(master, pack<F2M_REGISTER_FRAMEWORK>(frameworkName, user, execInfo));
@@ -167,11 +226,27 @@ protected:
case PROCESS_EXIT: {
- const char* message = "connection to master failed";
- invoke(bind(&Scheduler::error, sched, driver, -1, message));
+ const char* message = "Connection to master failed";
+ LOG(INFO) << message;
+ // invoke(bind(&Scheduler::error, sched, driver, -1, message));
break;
}
+ case LE_NEWLEADER: {
+ LOG(INFO) << "Slave got notified of new leader " << from();
+ string newLeader;
+ unpack<LE_NEWLEADER>(newLeader);
+ istringstream iss(newLeader);
+ if (!(iss >> master)) {
+ cerr << "Failed to resolve master PID " << newLeader << endl;
+ break;
+ }
+
+ LOG(INFO) << "Connecting to Nexus master at " << master;
+ link(master);
+ send(master, pack<F2M_REGISTER_FRAMEWORK>(frameworkName, user, execInfo));
+ break;
+ }
default: {
ostringstream oss;
oss << "SchedulerProcess received unknown message " << msgid()
@@ -278,6 +353,7 @@ void NexusSchedulerDriver::start()
}
PID pid;
+ bool passString = false;
if (master == string("localquiet")) {
// TODO(benh): Look up resources in environment variables.
@@ -285,18 +361,16 @@ void NexusSchedulerDriver::start()
} else if (master == string("local")) {
// TODO(benh): Look up resources in environment variables.
pid = run_nexus(1, 1, 1073741824, true, false);
- } else {
- std::istringstream iss(master);
- if (!(iss >> pid)) {
- error(errno, "register failed - bad master PID");
- return;
- }
- }
+ } else
+ passString = true;
const string& frameworkName = sched->getFrameworkName(this);
const ExecutorInfo& executorInfo = sched->getExecutorInfo(this);
- process = new SchedulerProcess(pid, this, sched, frameworkName, executorInfo);
+ if (passString)
+ process = new SchedulerProcess(pid, this, sched, frameworkName, executorInfo, master);
+ else
+ process = new SchedulerProcess(pid, this, sched, frameworkName, executorInfo);
Process::spawn(process);
running = true;
Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun 5 03:22:46 2011
@@ -5,6 +5,7 @@
#include "slave.hpp"
#include "slave_webui.hpp"
#include "isolation_module_factory.hpp"
+#include "process_url.hpp"
using std::list;
using std::make_pair;
@@ -65,11 +66,11 @@ Slave::Slave(const string &_master, Reso
resources(_resources), local(_local), id("-1"),
isolationType("process"), isolationModule(NULL), slaveLeaderListener(this, getPID())
{
- pair<Slave::URLType, string> urlPair = processUrl(_master);
- if (urlPair.first == Slave::ZOOURL) {
+ pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_master);
+ if (urlPair.first == UrlProcessor::ZOO) {
isFT=true;
zkserver = urlPair.second;
- } else if (urlPair.first == Slave::NEXUSURL) {
+ } else if (urlPair.first == UrlProcessor::NEXUS) {
isFT=false;
istringstream iss(urlPair.second);
if (!(iss >> master)) {
@@ -89,65 +90,23 @@ Slave::Slave(const string &_master, Reso
resources(_resources), local(_local), id("-1"),
isolationType(_isolationType), isolationModule(NULL), slaveLeaderListener(this, getPID())
{
- pair<Slave::URLType, string> urlPair = processUrl(_master);
- if (urlPair.first == Slave::ZOOURL) {
+ pair<UrlProcessor::URLType, string> urlPair = UrlProcessor::process(_master);
+ if (urlPair.first == UrlProcessor::ZOO) {
isFT=true;
zkserver = urlPair.second;
- } else if (urlPair.first == Slave::NEXUSURL) {
+ } else if (urlPair.first == UrlProcessor::NEXUS) {
isFT=false;
istringstream iss(urlPair.second);
if (!(iss >> master)) {
- LOG(ERROR) << "Failed to resolve master PID " << urlPair.second;
+ cerr << "Failed to resolve master PID " << urlPair.second << endl;
exit(1);
}
} else {
- LOG(ERROR) << "Failed to parse URL for Nexus master or ZooKeeper servers ";
+ cerr << "Failed to parse URL for Nexus master or ZooKeeper servers ";
exit(1);
}
}
-// enum URLType {ZOOURL, NEXUSURL};
-pair<Slave::URLType, string> Slave::processUrl(const string &_url) {
-
- string url = _url;
-
- transform(url.begin(), url.end(), url.begin(), (int (*)(int))toupper);
-
- if (url.find("ZOO://")==0) {
-
- return pair<Slave::URLType, string>(Slave::ZOOURL, url.substr(6,1024));
-
- } else if (url.find("ZOOFILE://")==0) {
- string zfname = _url.substr(10,1024);
- string zoos="";
-
- LOG(INFO)<<"Opening ZooFile: "<<zfname;
- ifstream zoofile(zfname.c_str());
- if (!zoofile)
- LOG(ERROR)<<"ZooFile "<<zfname<<" could not be opened";
-
- while(!zoofile.eof()) {
- string line;
- getline(zoofile, line);
- if (line=="")
- continue;
- if (zoos!="")
- zoos+=',';
- zoos+=line;
- }
-
- remove_if(zoos.begin(),zoos.end(), (int (*)(int)) isspace);
- zoofile.close();
-
- return pair<Slave::URLType, string>(Slave::ZOOURL, zoos);
-
- } else if (url.find("NEXUS://")==0) {
- return pair<Slave::URLType, string>(Slave::NEXUSURL, url.substr(8,1024));
- } else
- LOG(ERROR)<<"Could not parse master/zoo URL";
- return pair<Slave::URLType, string>(Slave::NONEURL, "");
-}
-
Slave::~Slave() {}
@@ -400,10 +359,10 @@ void Slave::operator () ()
return;
}
- case LE2S_NEWLEADER: {
+ case LE_NEWLEADER: {
LOG(INFO) << "Slave got notified of new leader " << from();
string newLeader;
- unpack<LE2S_NEWLEADER>(newLeader);
+ unpack<LE_NEWLEADER>(newLeader);
istringstream iss(newLeader);
if (!(iss >> master)) {
cerr << "Failed to resolve master PID " << newLeader << endl;
Modified: incubator/mesos/trunk/src/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.hpp?rev=1131558&r1=1131557&r2=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave.hpp Sun Jun 5 03:22:46 2011
@@ -34,8 +34,8 @@
#include "params.hpp"
#include "resources.hpp"
#include "slave_state.hpp"
-#include "getleader.hpp"
-#include "internalinfo.hpp"
+#include "leader_detector.hpp"
+#include "task_info.hpp"
namespace nexus { namespace internal { namespace slave {
@@ -191,7 +191,7 @@ public:
parent->zkserver = pidStr;
LOG(INFO) << "Sending message to parent "<<parentPID<<" about new leader";
- parent->send(parentPID, parent->pack<LE2S_NEWLEADER>(pidStr));
+ parent->send(parentPID, parent->pack<LE_NEWLEADER>(pidStr));
}
}
@@ -242,8 +242,6 @@ protected:
// it is easy to override in tests
virtual IsolationModule * createIsolationModule();
- enum URLType {ZOOURL, NEXUSURL, NONEURL};
- pair<URLType, string> processUrl(const string &_url);
};
}}}
Copied: incubator/mesos/trunk/src/task_info.hpp (from r1131557, incubator/mesos/trunk/src/internalinfo.hpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/task_info.hpp?p2=incubator/mesos/trunk/src/task_info.hpp&p1=incubator/mesos/trunk/src/internalinfo.hpp&r1=1131557&r2=1131558&rev=1131558&view=diff
==============================================================================
--- incubator/mesos/trunk/src/internalinfo.hpp (original)
+++ incubator/mesos/trunk/src/task_info.hpp Sun Jun 5 03:22:46 2011
@@ -1,5 +1,5 @@
-#ifndef __INTERNALINFO_HPP__
-#define __INTERNALINFO_HPP__
+#ifndef _TASK_INFO_HPP_
+#define _TASK_INFO_HPP_
#include <string>
#include <glog/logging.h>
@@ -31,5 +31,5 @@ struct TaskInfo
}}
-#endif /* __INTERNALINFO_HPP__ */
+#endif /* _TASK_INFO_HPP_ */
Added: incubator/mesos/trunk/src/url_processor.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/url_processor.cpp?rev=1131558&view=auto
==============================================================================
--- incubator/mesos/trunk/src/url_processor.cpp (added)
+++ incubator/mesos/trunk/src/url_processor.cpp Sun Jun 5 03:22:46 2011
@@ -0,0 +1,58 @@
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <algorithm>
+#include <glog/logging.h>
+#include "url_processor.hpp"
+
+using namespace std;
+
+namespace nexus { namespace internal {
+
+string UrlProcessor::parseZooFile(const string &zooFilename) {
+ string zoos="";
+
+ LOG(INFO)<<"Opening ZooFile: "<<zooFilename;
+ ifstream zoofile(zooFilename.c_str());
+ if (!zoofile)
+ LOG(ERROR)<<"ZooFile "<<zooFilename<<" could not be opened";
+
+ while(!zoofile.eof()) {
+ string line;
+ getline(zoofile, line);
+ if (line=="")
+ continue;
+ if (zoos!="")
+ zoos+=',';
+ zoos+=line;
+ }
+ remove_if(zoos.begin(),zoos.end(), (int (*)(int)) isspace);
+ zoofile.close();
+ return zoos;
+}
+
+pair<UrlProcessor::URLType, string> UrlProcessor::process(const string &url) {
+
+ string urlCap = url;
+
+ transform(urlCap.begin(), urlCap.end(), urlCap.begin(), (int (*)(int))toupper);
+
+ if (urlCap.find("ZOO://")==0) {
+
+ return pair<UrlProcessor::URLType, string>(UrlProcessor::ZOO, url.substr(6,1024));
+
+ } else if (urlCap.find("ZOOFILE://")==0) {
+
+ string zoos = parseZooFile( url.substr(10,1024) );
+
+ return pair<UrlProcessor::URLType, string>(UrlProcessor::ZOO, zoos);
+
+ } else if (urlCap.find("NEXUS://")==0) {
+ return pair<UrlProcessor::URLType, string>(UrlProcessor::NEXUS, url.substr(8,1024));
+ } else {
+ LOG(ERROR)<<"Could not parse master/zoo URL";
+ return pair<UrlProcessor::URLType, string>(UrlProcessor::UNKNOWN, "");
+ }
+}
+
+}}
Added: incubator/mesos/trunk/src/url_processor.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/url_processor.hpp?rev=1131558&view=auto
==============================================================================
--- incubator/mesos/trunk/src/url_processor.hpp (added)
+++ incubator/mesos/trunk/src/url_processor.hpp Sun Jun 5 03:22:46 2011
@@ -0,0 +1,25 @@
+#ifndef _URL_PRCESSOR_HPP_
+#define _URL_PRCESSOR_HPP_
+
+#include <iostream>
+#include <string>
+#include <glog/logging.h>
+
+using std::string;
+using std::pair;
+
+namespace nexus { namespace internal {
+
+class UrlProcessor {
+
+public:
+ enum URLType {ZOO, NEXUS, UNKNOWN};
+
+ static string parseZooFile(const string &zooFilename);
+
+ static pair<UrlProcessor::URLType, string> process(const string &_url);
+};
+
+}}
+
+#endif /* _URL_PROCESSOR_HPP_ */