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 10:25:37 UTC

svn commit: r1132023 - in /incubator/mesos/trunk/src: common/logging.cpp master/main.cpp master/webui.cpp master/webui.hpp slave/main.cpp slave/slave.cpp slave/webui.cpp slave/webui.hpp webui/master/webui.py webui/slave/webui.py

Author: benh
Date: Sun Jun  5 08:25:36 2011
New Revision: 1132023

URL: http://svn.apache.org/viewvc?rev=1132023&view=rev
Log:
Updated links in master and slave webui.

Modified:
    incubator/mesos/trunk/src/common/logging.cpp
    incubator/mesos/trunk/src/master/main.cpp
    incubator/mesos/trunk/src/master/webui.cpp
    incubator/mesos/trunk/src/master/webui.hpp
    incubator/mesos/trunk/src/slave/main.cpp
    incubator/mesos/trunk/src/slave/slave.cpp
    incubator/mesos/trunk/src/slave/webui.cpp
    incubator/mesos/trunk/src/slave/webui.hpp
    incubator/mesos/trunk/src/webui/master/webui.py
    incubator/mesos/trunk/src/webui/slave/webui.py

Modified: incubator/mesos/trunk/src/common/logging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/logging.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/logging.cpp (original)
+++ incubator/mesos/trunk/src/common/logging.cpp Sun Jun  5 08:25:36 2011
@@ -33,6 +33,8 @@ void Logging::init(const char* programNa
 
   if (!isQuiet(conf))
     google::SetStderrLogging(google::INFO);
+
+  LOG(INFO) << "Logging to " << FLAGS_log_dir;
 }
 
 

Modified: incubator/mesos/trunk/src/master/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/main.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/main.cpp (original)
+++ incubator/mesos/trunk/src/master/main.cpp Sun Jun  5 08:25:36 2011
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
   MasterDetector *detector = MasterDetector::create(url, pid, true, quiet);
 
 #ifdef MESOS_WEBUI
-  startMasterWebUI(pid, (char*) params["webui_port"].c_str());
+  startMasterWebUI(pid, params);
 #endif
   
   Process::wait(pid);

Modified: incubator/mesos/trunk/src/master/webui.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/webui.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/webui.cpp (original)
+++ incubator/mesos/trunk/src/master/webui.cpp Sun Jun  5 08:25:36 2011
@@ -1,6 +1,7 @@
 #include <pthread.h>
 
 #include <sstream>
+#include <string>
 
 #include "webui.hpp"
 #include "state.hpp"
@@ -9,25 +10,31 @@
 
 #include <Python.h>
 
+using std::string;
+
+
 extern "C" void init_master();  // Initializer for the Python master module
 
 namespace {
 
 PID master;
+string webuiPort;
+string logDir;
 
 }
 
 namespace mesos { namespace internal { namespace master {
 
 
-void *runMasterWebUI(void* webuiPort)
+void *runMasterWebUI(void *)
 {
   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);
+  char* argv[3];
+  argv[0] = const_cast<char*>("webui/master/webui.py");
+  argv[1] = const_cast<char*>(webuiPort.c_str());
+  argv[2] = const_cast<char*>(logDir.c_str());
+  PySys_SetArgv(3, argv);
   PyRun_SimpleString("import sys\n"
       "sys.path.append('webui/master/swig')\n"
       "sys.path.append('webui/common')\n"
@@ -41,12 +48,23 @@ void *runMasterWebUI(void* webuiPort)
 }
 
 
-void startMasterWebUI(const PID &master, char* webuiPort)
+void startMasterWebUI(const PID &master, const Params &params)
 {
-  LOG(INFO) << "Starting master web UI";
+  // TODO(*): It would be nice if we didn't have to be specifying
+  // default values for configuration options in the code like
+  // this. For example, we specify /tmp for log_dir because that is
+  // what glog does, but it would be nice if at this point in the game
+  // all of the configuration options have been set (from defaults or
+  // from the command line, environment, or configuration file) and we
+  // can just query what their values are.
+  webuiPort = params.get("webui_port", "8080");
+  logDir = params.get("log_dir", FLAGS_log_dir);
+
+  LOG(INFO) << "Starting master web UI on port " << webuiPort;
+
   ::master = master;
   pthread_t thread;
-  pthread_create(&thread, 0, runMasterWebUI, webuiPort);
+  pthread_create(&thread, 0, runMasterWebUI, NULL);
 }
 
 

Modified: incubator/mesos/trunk/src/master/webui.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/webui.hpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/webui.hpp (original)
+++ incubator/mesos/trunk/src/master/webui.hpp Sun Jun  5 08:25:36 2011
@@ -3,15 +3,18 @@
 
 #include <process.hpp>
 
+#include "master.hpp"
+
+#include "common/params.hpp"
+
 #include "config/config.hpp"
 
-#include "master.hpp"
 
 #ifdef MESOS_WEBUI
 
 namespace mesos { namespace internal { namespace master {
 
-void startMasterWebUI(const PID &master, char* webuiPort);
+void startMasterWebUI(const PID &master, const Params &params);
 
 }}} /* namespace */
 

Modified: incubator/mesos/trunk/src/slave/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/main.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/main.cpp (original)
+++ incubator/mesos/trunk/src/slave/main.cpp Sun Jun  5 08:25:36 2011
@@ -84,7 +84,7 @@ int main(int argc, char **argv)
   MasterDetector *detector = MasterDetector::create(url, pid, false, quiet);
 
 #ifdef MESOS_WEBUI
-  startSlaveWebUI(pid, (char*) params["webui_port"].c_str());
+  startSlaveWebUI(pid, params);
 #endif
 
   Process::wait(pid);

Modified: incubator/mesos/trunk/src/slave/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave/slave.cpp Sun Jun  5 08:25:36 2011
@@ -528,18 +528,7 @@ string Slave::getUniqueWorkDirectory(Fra
   // Find a unique directory based on the path given by the slave
   // (this is because we might launch multiple executors from the same
   // framework on this slave).
-  time_t rawtime;
-  struct tm* timeinfo;
-
-  time(&rawtime);
-  timeinfo = localtime(&rawtime);
-
-  char timestr[32];
-  if (strftime(timestr, sizeof(timestr), "%Y%m%d%H%M", timeinfo) == 0)
-    LOG(FATAL) << "Could not get a unique working directory; "
-               << "failed to format a string with the given time";
-
-  os << "/" << timestr << "-";
+  os << "/";
 
   string dir;
   dir = os.str();

Modified: incubator/mesos/trunk/src/slave/webui.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/webui.cpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/webui.cpp (original)
+++ incubator/mesos/trunk/src/slave/webui.cpp Sun Jun  5 08:25:36 2011
@@ -1,6 +1,7 @@
 #include <pthread.h>
 
 #include <sstream>
+#include <string>
 
 #include "state.hpp"
 #include "webui.hpp"
@@ -9,25 +10,33 @@
 
 #include <Python.h>
 
+using std::string;
+
+
 extern "C" void init_slave();  // Initializer for the Python slave module
 
 namespace {
 
 PID slave;
+string webuiPort;
+string logDir;
+string workDir;
 
 }
 
 namespace mesos { namespace internal { namespace slave {
 
 
-void *runSlaveWebUI(void* webuiPort)
+void *runSlaveWebUI(void *)
 {
   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);
+  char* argv[4];
+  argv[0] = const_cast<char*>("webui/master/webui.py");
+  argv[1] = const_cast<char*>(webuiPort.c_str());
+  argv[2] = const_cast<char*>(logDir.c_str());
+  argv[3] = const_cast<char*>(workDir.c_str());
+  PySys_SetArgv(4, argv);
   PyRun_SimpleString("import sys\n"
       "sys.path.append('webui/slave/swig')\n"
       "sys.path.append('webui/common')\n"
@@ -41,12 +50,30 @@ void *runSlaveWebUI(void* webuiPort)
 }
 
 
-void startSlaveWebUI(const PID &slave, char* webuiPort)
+void startSlaveWebUI(const PID &slave, const Params &params)
 {
-  LOG(INFO) << "Starting slave web UI";
+  // TODO(*): See the note in master/webui.cpp about having to
+  // determine default values. These should be set by now and can just
+  // be used! For example, what happens when the slave code changes
+  // their default location for the work directory, it might not get
+  // changed here!
+  webuiPort = params.get("webui_port", "8081");
+  logDir = params.get("log_dir", FLAGS_log_dir);
+  if (params.contains("work_dir")) {
+    workDir = params.get("work_dir", "");
+  } else if (params.contains("home")) {
+    workDir = params.get("home", "") + "/work";
+  } else {
+    workDir = "work";
+  }
+
+  CHECK(workDir != "");
+
+  LOG(INFO) << "Starting slave web UI on port " << webuiPort;
+
   ::slave = slave;
   pthread_t thread;
-  pthread_create(&thread, 0, runSlaveWebUI, webuiPort);
+  pthread_create(&thread, 0, runSlaveWebUI, NULL);
 }
 
 

Modified: incubator/mesos/trunk/src/slave/webui.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/webui.hpp?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/webui.hpp (original)
+++ incubator/mesos/trunk/src/slave/webui.hpp Sun Jun  5 08:25:36 2011
@@ -5,13 +5,15 @@
 
 #include "slave.hpp"
 
+#include "common/params.hpp"
+
 #include "config/config.hpp"
 
 #ifdef MESOS_WEBUI
 
 namespace mesos { namespace internal { namespace slave {
 
-void startSlaveWebUI(const PID &slave, char* webuiPort);
+void startSlaveWebUI(const PID &slave, const Params &params);
 
 }}} /* namespace */
 

Modified: incubator/mesos/trunk/src/webui/master/webui.py
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/webui.py?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/webui.py (original)
+++ incubator/mesos/trunk/src/webui/master/webui.py Sun Jun  5 08:25:36 2011
@@ -27,19 +27,23 @@ def static(filename):
 
 @route('/log/:level#[A-Z]*#')
 def log_full(level):
-  send_file('mesos-master.' + level, root = '/tmp',
+  send_file('mesos-master.' + level, root = log_dir,
             guessmime = False, mimetype = 'text/plain')
 
 
 @route('/log/:level#[A-Z]*#/:lines#[0-9]*#')
 def log_tail(level, lines):
   bottle.response.content_type = 'text/plain'
-  return commands.getoutput('tail -%s /tmp/mesos-master.%s' % (lines, level))
+  return commands.getoutput('tail -%s %s/mesos-master.%s' % (lines, log_dir, level))
 
 
 bottle.TEMPLATE_PATH.append('./webui/master/%s.tpl')
-if sys.argv[1]:
-  init_port = sys.argv[1] 
-else:
-  init_port = 8080
+
+# TODO(*): Add an assert to confirm that all the arguments we are
+# expecting have been passed to us, which will give us a better error
+# message when they aren't!
+
+init_port = sys.argv[1]
+log_dir = sys.argv[2]
+
 bottle.run(host = '0.0.0.0', port = init_port)

Modified: incubator/mesos/trunk/src/webui/slave/webui.py
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/slave/webui.py?rev=1132023&r1=1132022&r2=1132023&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/slave/webui.py (original)
+++ incubator/mesos/trunk/src/webui/slave/webui.py Sun Jun  5 08:25:36 2011
@@ -1,3 +1,4 @@
+import os
 import sys
 import bottle
 import commands
@@ -28,21 +29,21 @@ def static(filename):
 
 @route('/log/:level#[A-Z]*#')
 def log_full(level):
-  send_file('mesos-slave.' + level, root = '/tmp',
+  send_file('mesos-slave.' + level, root = log_dir,
             guessmime = False, mimetype = 'text/plain')
 
 
 @route('/log/:level#[A-Z]*#/:lines#[0-9]*#')
 def log_tail(level, lines):
   bottle.response.content_type = 'text/plain'
-  return commands.getoutput('tail -%s /tmp/mesos-slave.%s' % (lines, level))
+  return commands.getoutput('tail -%s %s/mesos-slave.%s' % (lines, log_dir, level))
 
 
 @route('/framework-logs/:fid#[0-9]*#/:log_type#[a-z]*#')
 def framework_log_full(fid, log_type):
   sid = get_slave().id
   if sid != -1:
-    send_file(log_type, root = './work/slave-%d/framework-%s' % (sid, fid),
+    send_file(log_type, root = '%s/slave-%s/fw-%s' % (work_dir, sid, fid),
               guessmime = False, mimetype = 'text/plain')
   else:
     abort(403, 'Slave not yet registered with master')
@@ -53,7 +54,9 @@ def framework_log_tail(fid, log_type, li
   bottle.response.content_type = 'text/plain'
   sid = get_slave().id
   if sid != -1:
-    filename = './work/slave-%d/framework-%s/%s' % (sid, fid, log_type)
+    dir = '%s/slave-%s/fw-%s' % (work_dir, sid, fid)
+    i = max(os.listdir(dir))
+    filename = '%s/slave-%s/fw-%s/%s/%s' % (work_dir, sid, fid, i, log_type)
     print filename
     return commands.getoutput('tail -%s %s' % (lines, filename))
   else:
@@ -61,8 +64,13 @@ def framework_log_tail(fid, log_type, li
 
 
 bottle.TEMPLATE_PATH.append('./webui/slave/%s.tpl')
-if sys.argv[1]:
-  init_port = sys.argv[1]
-else:
-  init_port = 8080
+
+# TODO(*): Add an assert to confirm that all the arguments we are
+# expecting have been passed to us, which will give us a better error
+# message when they aren't!
+
+init_port = sys.argv[1]
+log_dir = sys.argv[2]
+work_dir = sys.argv[3]
+
 bottle.run(host = '0.0.0.0', port = init_port)