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:43:46 UTC

svn commit: r1131877 - in /incubator/mesos/trunk/src: master_webui.hpp slave_main.cpp slave_webui.cpp slave_webui.hpp webui/slave/webui.py

Author: benh
Date: Sun Jun  5 05:43:45 2011
New Revision: 1131877

URL: http://svn.apache.org/viewvc?rev=1131877&view=rev
Log:
Adding optional --webui-port flag to the nexus-slave. Similar to issue #51
(which added this flag to nexus-master).  Closes issue #67.

Modified:
    incubator/mesos/trunk/src/master_webui.hpp
    incubator/mesos/trunk/src/slave_main.cpp
    incubator/mesos/trunk/src/slave_webui.cpp
    incubator/mesos/trunk/src/slave_webui.hpp
    incubator/mesos/trunk/src/webui/slave/webui.py

Modified: incubator/mesos/trunk/src/master_webui.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master_webui.hpp?rev=1131877&r1=1131876&r2=1131877&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master_webui.hpp (original)
+++ incubator/mesos/trunk/src/master_webui.hpp Sun Jun  5 05:43:45 2011
@@ -10,7 +10,7 @@
 
 namespace nexus { namespace internal { namespace master {
 
-void startMasterWebUI(const PID &master, char* webuiport);
+void startMasterWebUI(const PID &master, char* webuiPort);
 
 }}} /* namespace */
 

Modified: incubator/mesos/trunk/src/slave_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave_main.cpp?rev=1131877&r1=1131876&r2=1131877&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave_main.cpp (original)
+++ incubator/mesos/trunk/src/slave_main.cpp Sun Jun  5 05:43:45 2011
@@ -4,6 +4,9 @@
 #include "slave.hpp"
 #include "slave_webui.hpp"
 
+using boost::lexical_cast;
+using boost::bad_lexical_cast;
+
 using namespace std;
 
 using namespace nexus::internal::slave;
@@ -16,6 +19,7 @@ void usage(const char *programName)
        << " [--cpus NUM]"
        << " [--mem NUM]"
        << " [--isolation TYPE]"
+       << " [--webui-port PORT]"
        << " [--quiet]" << endl
        << endl
        << "MASTER_URL may be one of:" << endl
@@ -38,29 +42,34 @@ int main(int argc, char **argv)
     {"cpus", required_argument, 0, 'c'},
     {"mem", required_argument, 0, 'm'},
     {"isolation", required_argument, 0, 'i'},
+    {"webui-port", required_argument, 0, 'w'}, 
     {"quiet", no_argument, 0, 'q'},
   };
 
   string url = "";
   Resources resources(1, 1 * Gigabyte);
   string isolation = "process";
+  char* webuiPortStr = "8081"; // C string because it is sent to python C API
   bool quiet = false;
 
   int opt;
   int index;
-  while ((opt = getopt_long(argc, argv, "u:c:m:i:q", options, &index)) != -1) {
+  while ((opt = getopt_long(argc, argv, "u:c:m:i:w:q", options, &index)) != -1) {
     switch (opt) {
       case 'u':
         url = optarg;
         break;
       case 'c': 
-	resources.cpus = atoi(optarg);
+        resources.cpus = atoi(optarg);
         break;
       case 'm':
-	resources.mem = atoll(optarg);
+        resources.mem = atoll(optarg);
         break;
       case 'i':
-	isolation = optarg;
+        isolation = optarg;
+        break;
+      case 'w':
+        webuiPortStr = optarg;
         break;
       case 'q':
         quiet = true;
@@ -90,7 +99,7 @@ int main(int argc, char **argv)
   IsolationModule *isolationModule = IsolationModule::create(isolation);
 
   if (isolationModule == NULL)
-    fatal("unrecognized isolation type: %s", isolation);
+    fatal("unrecognized isolation type: %s", isolation.c_str());
 
   LOG(INFO) << "Build: " << BUILD_DATE << " by " << BUILD_USER;
   LOG(INFO) << "Starting Nexus slave";
@@ -103,7 +112,18 @@ int main(int argc, char **argv)
 #ifdef NEXUS_WEBUI
   if (chdir(dirname(argv[0])) != 0)
     fatalerror("could not change into %s for running webui", dirname(argv[0]));
-  startSlaveWebUI(pid);
+
+  // TODO(*): Since we normally don't use exceptions in Mesos, replace
+  // use of an exception here with use of a utility to handle checking
+  // that the input string is actually a number that fits
+  // in the type being used (in this case, short).
+  try {
+    lexical_cast<short>(webuiPortStr);
+  } catch(bad_lexical_cast &) {
+    fatal("Passed invalid string for webui port number.\n");
+  }
+
+  startSlaveWebUI(pid, webuiPortStr);
 #endif
 
   Process::wait(pid);

Modified: incubator/mesos/trunk/src/slave_webui.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave_webui.cpp?rev=1131877&r1=1131876&r2=1131877&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave_webui.cpp (original)
+++ incubator/mesos/trunk/src/slave_webui.cpp Sun Jun  5 05:43:45 2011
@@ -20,10 +20,14 @@ PID slave;
 namespace nexus { namespace internal { namespace slave {
 
 
-void *runSlaveWebUI(void *)
+void *runSlaveWebUI(void* webuiPort)
 {
   LOG(INFO) << "Web UI thread started";
   Py_Initialize();
+  char* nargv[2]; 
+  nargv[0] = const_cast<char*>("webui/master/webui.py");
+  nargv[1] = reinterpret_cast<char*>(webuiPort);
+  PySys_SetArgv(2,nargv);
   PyRun_SimpleString("import sys\n"
       "sys.path.append('webui/slave/swig')\n"
       "sys.path.append('webui/common')\n"
@@ -37,12 +41,12 @@ void *runSlaveWebUI(void *)
 }
 
 
-void startSlaveWebUI(PID slave)
+void startSlaveWebUI(const PID &slave, char* webuiPort)
 {
   LOG(INFO) << "Starting slave web UI";
   ::slave = slave;
   pthread_t thread;
-  pthread_create(&thread, 0, runSlaveWebUI, 0);
+  pthread_create(&thread, 0, runSlaveWebUI, webuiPort);
 }
 
 

Modified: incubator/mesos/trunk/src/slave_webui.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave_webui.hpp?rev=1131877&r1=1131876&r2=1131877&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave_webui.hpp (original)
+++ incubator/mesos/trunk/src/slave_webui.hpp Sun Jun  5 05:43:45 2011
@@ -10,7 +10,7 @@
 
 namespace nexus { namespace internal { namespace slave {
 
-void startSlaveWebUI(PID slave);
+void startSlaveWebUI(const PID &slave, char* webuiPort);
 
 }}} /* namespace */
 

Modified: incubator/mesos/trunk/src/webui/slave/webui.py
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/slave/webui.py?rev=1131877&r1=1131876&r2=1131877&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/slave/webui.py (original)
+++ incubator/mesos/trunk/src/webui/slave/webui.py Sun Jun  5 05:43:45 2011
@@ -1,3 +1,4 @@
+import sys
 import bottle
 import commands
 import datetime
@@ -60,4 +61,8 @@ def framework_log_tail(fid, log_type, li
 
 
 bottle.TEMPLATE_PATH.append('./webui/slave/%s.tpl')
-bottle.run(host = '0.0.0.0', port = 8081)
+if sys.argv[1]:
+  init_port = sys.argv[1]
+else:
+  init_port = 8080
+bottle.run(host = '0.0.0.0', port = init_port)