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:20:47 UTC

svn commit: r1131546 - in /incubator/mesos/trunk/src: slave.cpp slave.hpp

Author: benh
Date: Sun Jun  5 03:20:47 2011
New Revision: 1131546

URL: http://svn.apache.org/viewvc?rev=1131546&view=rev
Log:
Added a URL processor that currently understands nexus://<master> zoo://<zoosvr1>,<zoosvr2>... and zoofile://<filename>, where filename contains one ip:port to zooservers per line

Modified:
    incubator/mesos/trunk/src/slave.cpp
    incubator/mesos/trunk/src/slave.hpp

Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131546&r1=1131545&r2=1131546&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun  5 03:20:47 2011
@@ -1,5 +1,7 @@
 #include <getopt.h>
 
+#include <fstream>
+#include <algorithm>
 #include "slave.hpp"
 #include "slave_webui.hpp"
 #include "isolation_module_factory.hpp"
@@ -63,7 +65,7 @@ Slave::Slave(const string &_master, Reso
     resources(_resources), local(_local), id("-1"),
     isolationType("process"), isolationModule(NULL), slaveLeaderListener(this, getPID())
 {
-  pair<Slave::URLType, string> urlPair = parseUrl(_master);
+  pair<Slave::URLType, string> urlPair = processUrl(_master);
   if (urlPair.first == Slave::ZOOURL) {
     isFT=true;
     zkserver = urlPair.second;
@@ -87,7 +89,7 @@ Slave::Slave(const string &_master, Reso
     resources(_resources), local(_local), id("-1"),
     isolationType(_isolationType), isolationModule(NULL), slaveLeaderListener(this, getPID())
 {
-  pair<Slave::URLType, string> urlPair = parseUrl(_master);
+  pair<Slave::URLType, string> urlPair = processUrl(_master);
   if (urlPair.first == Slave::ZOOURL) {
     isFT=true;
     zkserver = urlPair.second;
@@ -95,29 +97,54 @@ Slave::Slave(const string &_master, Reso
     isFT=false;
     istringstream iss(urlPair.second);
     if (!(iss >> master)) {
-      cerr << "Failed to resolve master PID " << urlPair.second << endl;
+      LOG(ERROR) << "Failed to resolve master PID " << urlPair.second;
       exit(1);
     }
   } else {
-    cerr << "Failed to parse URL for Nexus master or ZooKeeper servers ";
+    LOG(ERROR) << "Failed to parse URL for Nexus master or ZooKeeper servers ";
     exit(1);
   }
 }
 
 //  enum URLType {ZOOURL, NEXUSURL};
-pair<Slave::URLType, string> Slave::parseUrl(const string &url) {
+pair<Slave::URLType, string> Slave::processUrl(const string &_url) {
   
-  // alig: I'd love to replace this with boost string.hpp, which isn't currently third_party
-  if (url.size()>6 && tolower(url[0])=='z' && tolower(url[1])=='o' && 
-      tolower(url[2])=='o' && url[3]==':' && url[4]=='/' && url[5]=='/') {
+  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.size()>8 && tolower(url[0])=='n' && tolower(url[1])=='e' && 
-	     tolower(url[2])=='x' && tolower(url[3])=='u' && tolower(url[4])=='s' && 
-	     url[5]==':' && url[6]=='/' && url[7]=='/') {
+  } 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, "");
 }
 

Modified: incubator/mesos/trunk/src/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.hpp?rev=1131546&r1=1131545&r2=1131546&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave.hpp Sun Jun  5 03:20:47 2011
@@ -243,7 +243,7 @@ protected:
   virtual IsolationModule * createIsolationModule();
 
   enum URLType {ZOOURL, NEXUSURL, NONEURL};
-  pair<URLType, string> parseUrl(const string &url);
+  pair<URLType, string> processUrl(const string &_url);
 };
 
 }}}