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:49:33 UTC

svn commit: r1132137 - in /incubator/mesos/trunk/src: common/ event_history/

Author: benh
Date: Sun Jun  5 08:49:33 2011
New Revision: 1132137

URL: http://svn.apache.org/viewvc?rev=1132137&view=rev
Log:
Factoring in more of Matei's feedback. Moved sqlite error message to
local variable in necessary functions. Replaced '-'s with '_'s in option
flags, switched to using date_utils class, fixed minor coding convention
typos.

Modified:
    incubator/mesos/trunk/src/common/date_utils.cpp
    incubator/mesos/trunk/src/common/date_utils.hpp
    incubator/mesos/trunk/src/event_history/event_history.cpp
    incubator/mesos/trunk/src/event_history/event_history.hpp
    incubator/mesos/trunk/src/event_history/file_event_writer.cpp
    incubator/mesos/trunk/src/event_history/sqlite_event_writer.cpp
    incubator/mesos/trunk/src/event_history/sqlite_event_writer.hpp

Modified: incubator/mesos/trunk/src/common/date_utils.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/date_utils.cpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/date_utils.cpp (original)
+++ incubator/mesos/trunk/src/common/date_utils.cpp Sun Jun  5 08:49:33 2011
@@ -33,7 +33,7 @@ string DateUtils::currentDate()
 
 
 // Get the current time in microseconds.
-long DateUtils::currentDateTimeInMicro(){
+long DateUtils::currentDateTimeInMicro() {
   struct timeval curr_time;
   struct timezone tzp;
   gettimeofday(&curr_time, &tzp);
@@ -41,15 +41,6 @@ long DateUtils::currentDateTimeInMicro()
 }
 
 
-// Get a human readable timestamp in microseconds.
-  string DateUtils::humanReadableDateTimeInMicro(){
-  time_t currTime;
-  currTime=time(NULL);
-  string timestamp = asctime(localtime(&currTime));
-  return timestamp.erase(24); /* chop off the newline */
-}
-
-
 // Unit test utility method that makes this class return a fixed string
 // as the date instead of looking up the current time.
 void DateUtils::setMockDate(string date)

Modified: incubator/mesos/trunk/src/common/date_utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/date_utils.hpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/date_utils.hpp (original)
+++ incubator/mesos/trunk/src/common/date_utils.hpp Sun Jun  5 08:49:33 2011
@@ -22,11 +22,6 @@ public:
    */
   static long currentDateTimeInMicro();
 
-   /**
-    * Get a human readable timestamp in microseconds.
-    */
-  static std::string humanReadableDateTimeInMicro();
-
   /**
    * Unit test utility method that makes this class return a fixed string
    * as the date instead of looking up the current time.

Modified: incubator/mesos/trunk/src/event_history/event_history.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/event_history/event_history.cpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/event_history/event_history.cpp (original)
+++ incubator/mesos/trunk/src/event_history/event_history.cpp Sun Jun  5 08:49:33 2011
@@ -15,9 +15,9 @@ void EventLogger::registerOptions(Config
   //TODO(andyk): We don't set the default value here, since this would
   //             override the defaults set at the param.get() calls later.
   //             We would like to set the default here and override it later.
-  conf->addOption<bool>("event-history-file",
+  conf->addOption<bool>("event_history_file",
         "Enable file event history logging(default: true)");
-  conf->addOption<bool>("event-history-sqlite",
+  conf->addOption<bool>("event_history_sqlite",
         "Enable SQLite event history logging (default: false)");
 }
 

Modified: incubator/mesos/trunk/src/event_history/event_history.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/event_history/event_history.hpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/event_history/event_history.hpp (original)
+++ incubator/mesos/trunk/src/event_history/event_history.hpp Sun Jun  5 08:49:33 2011
@@ -1,10 +1,7 @@
 #ifndef __EVENT_HISTORY_HPP__
 #define __EVENT_HISTORY_HPP__
 
-//#include <fstream>
-//#include <iostream>
 #include <list>
-//#include <map>
 #include <string>
 
 #include <glog/logging.h>

Modified: incubator/mesos/trunk/src/event_history/file_event_writer.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/event_history/file_event_writer.cpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/event_history/file_event_writer.cpp (original)
+++ incubator/mesos/trunk/src/event_history/file_event_writer.cpp Sun Jun  5 08:49:33 2011
@@ -11,9 +11,9 @@ using namespace mesos::internal::eventhi
 
 /* Pre-condition: params["log_dir"] exists and is writable */
 FileEventWriter::FileEventWriter(const Params& params) {
-  string logDir = params.get("log_dir","");
+  string logDir = params.get("log_dir", "");
   CHECK_NE(logDir, "") << "FileEventWriter was created when no log_dir was set";
-  logfile.open ((logDir + "/event_history_log.txt").c_str(),ios::app|ios::out);
+  logfile.open((logDir + "/event_history_log.txt").c_str(), ios::app|ios::out);
 }
 
 
@@ -31,7 +31,7 @@ FileEventWriter::~FileEventWriter() {
 int FileEventWriter::logTaskCreated(TaskID tid, FrameworkID fwid, SlaveID sid,
                                     string webuiUrl, Resources resVec)
 {
-  logfile << DateUtils::humanReadableDateTimeInMicro() << ",CreateTask, "
+  logfile << DateUtils::currentDate() << ",CreateTask, "
           << "taskid: " << tid << ", "
           << "fwid: " << fwid << ", "
           << "sid: " << sid << ","
@@ -44,7 +44,7 @@ int FileEventWriter::logTaskCreated(Task
 int FileEventWriter::logTaskStateUpdated(TaskID tid, FrameworkID fwid,
                                          TaskState state)
 {
-  logfile << DateUtils::humanReadableDateTimeInMicro() << ", TaskStateUpdate, "
+  logfile << DateUtils::currentDate() << ", TaskStateUpdate, "
           << "taskid: " << tid << ", "
           << "fwid: " << fwid << ", "
           << "state: " << state << endl;
@@ -54,7 +54,7 @@ int FileEventWriter::logTaskStateUpdated
 
 
 int FileEventWriter::logFrameworkRegistered(FrameworkID fwid, string user) {
-  logfile << DateUtils::humanReadableDateTimeInMicro() << ", CreateFramework, "
+  logfile << DateUtils::currentDate() << ", CreateFramework, "
           << "fwid: " << fwid << ", "
           << "userid: " << user << endl;
 

Modified: incubator/mesos/trunk/src/event_history/sqlite_event_writer.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/event_history/sqlite_event_writer.cpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/event_history/sqlite_event_writer.cpp (original)
+++ incubator/mesos/trunk/src/event_history/sqlite_event_writer.cpp Sun Jun  5 08:49:33 2011
@@ -2,9 +2,9 @@
 
 using namespace mesos::internal::eventhistory;
 
-static int callback(void *NotUsed, int argc, char **argv, char **azColName){
+static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
   int i;
-  for(i=0; i<argc; i++){
+  for(i=0; i<argc; i++) {
     printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
   }
   printf("\n");
@@ -12,20 +12,19 @@ static int callback(void *NotUsed, int a
 }
 
 
-string SqlLiteEventWriter::getName(){
+string SqlLiteEventWriter::getName() {
   return "Sqlite Event Writer";
 }
 
 
-/* Pre-condition: params["log_dir"] exists and is writable */
-SqlLiteEventWriter::SqlLiteEventWriter(const Params& params) {
-  zErrMsg = 0;
-  string logDir = params.get("log_dir","");
+/* Pre-condition: conf["log_dir"] exists and is writable */
+SqlLiteEventWriter::SqlLiteEventWriter(const Params& conf) {
+  string logDir = conf.get("log_dir", "");
   CHECK_NE(logDir, "") << "SqlLiteEventWriter constructor failed pre-condition."
-                       << " params[\"log_dir\" must be set.";
+                       << " conf[\"log_dir\" must be set.";
 
   //set up log file in log dir
-  int rc = sqlite3_open((logDir + "/event_history_db.sqlite3").c_str(),&db);
+  int rc = sqlite3_open((logDir + "/event_history_db.sqlite3").c_str(), &db);
   if( rc ) {
     LOG(ERROR) << "Can't open database: " << sqlite3_errmsg(db) << endl;
     sqlite3_close(db);
@@ -34,19 +33,20 @@ SqlLiteEventWriter::SqlLiteEventWriter(c
   }
   //create task table in case it doesn't already exist,
   //if it does this shouldn't destroy it
+  char *errMsg = 0;
   sqlite3_exec(db, "CREATE TABLE task (taskid Varchar(255), fwid Varchar(255), \
                     sid Varchar(255), webuiUrl Varchar(255), \
                     datetime_created integer, resource_list Varchar(255))",
-               ::callback, 0, &zErrMsg);
+               ::callback, 0, &errMsg);
 
   sqlite3_exec(db, "CREATE TABLE taskstate (taskid Varchar(255), \
                     fwid Varchar(255), state Varchar(255), \
                     datetime_updated integer)",
-               ::callback, 0, &zErrMsg);
+               ::callback, 0, &errMsg);
 
   sqlite3_exec(db, "CREATE TABLE framework (fwid Varchar(255), \
                     user Varchar(255), datetime_registered integer)",
-               ::callback, 0, &zErrMsg);
+               ::callback, 0, &errMsg);
 }
 
 
@@ -73,7 +73,8 @@ int SqlLiteEventWriter::logTaskCreated(T
      << "}'"
      << ")" << endl;
   DLOG(INFO) << "executing " << ss.str() << endl;
-  sqlite3_exec(db, ss.str().c_str(), callback, 0, &zErrMsg);
+  char *errMsg = 0;
+  sqlite3_exec(db, ss.str().c_str(), callback, 0, &errMsg);
 
   return 0;
 }
@@ -89,7 +90,8 @@ int SqlLiteEventWriter::logTaskStateUpda
      << "\"" << state << "\"" << ","
      << DateUtils::currentDateTimeInMicro() << ")" << endl;
   DLOG(INFO) << "executing " << ss.str() << endl;
-  sqlite3_exec(db, ss.str().c_str(), callback, 0, &zErrMsg);
+  char *errMsg = 0;
+  sqlite3_exec(db, ss.str().c_str(), callback, 0, &errMsg);
 
   return 0;
 }

Modified: incubator/mesos/trunk/src/event_history/sqlite_event_writer.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/event_history/sqlite_event_writer.hpp?rev=1132137&r1=1132136&r2=1132137&view=diff
==============================================================================
--- incubator/mesos/trunk/src/event_history/sqlite_event_writer.hpp (original)
+++ incubator/mesos/trunk/src/event_history/sqlite_event_writer.hpp Sun Jun  5 08:49:33 2011
@@ -12,7 +12,6 @@ namespace mesos { namespace internal { n
 class SqlLiteEventWriter : public EventWriter {
 private:
   sqlite3 *db; 
-  char *zErrMsg;
   time_t currTime;
 public:
   string getName();