[Fawkes Git] branch/fzwilling/robot-memory: 3 revs updated. (0.5.0-3397-gae75a1b)

Frederik Zwilling zwilling at kbsg.rwth-aachen.de
Wed Sep 21 19:58:28 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, fzwilling/robot-memory has been updated
        to  ae75a1bf012916533f7c608c5d61ed8b53e706c0 (commit)
       via  553e17b178e18bd0dc814b99ed22a28331e248cd (commit)
       via  04a3c63656cd488bbd7b3f06f976333f9db6e5d2 (commit)
      from  69195c38a75ac601772b9cabd4dad09040d421eb (commit)

http://git.fawkesrobotics.org/fawkes.git/fzwilling/robot-memory

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 04a3c63656cd488bbd7b3f06f976333f9db6e5d2
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Wed Sep 21 17:55:02 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Wed Sep 21 19:58:16 2016 +0200

    robot-memory: startup local mongod processes
    
    Startup a local mongod process when it is not already running.
    Requires the fzwilling/sub_process branch.

http://git.fawkesrobotics.org/fawkes.git/commit/04a3c63
http://trac.fawkesrobotics.org/changeset/04a3c63

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 553e17b178e18bd0dc814b99ed22a28331e248cd
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Wed Sep 21 19:48:29 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Wed Sep 21 19:58:20 2016 +0200

    utils: string_conversions: resolve ~ in path

http://git.fawkesrobotics.org/fawkes.git/commit/553e17b
http://trac.fawkesrobotics.org/changeset/553e17b

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit ae75a1bf012916533f7c608c5d61ed8b53e706c0
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Wed Sep 21 19:48:59 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Wed Sep 21 19:58:25 2016 +0200

    robot-memory: setup config server for distributed robot memory

http://git.fawkesrobotics.org/fawkes.git/commit/ae75a1b
http://trac.fawkesrobotics.org/changeset/ae75a1b

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/libs/utils/misc/string_conversions.cpp       |    1 +
 src/plugins/robot-memory/robot_memory_plugin.cpp |   16 ++-
 src/plugins/robot-memory/robot_memory_setup.cpp  |  156 ++++++++++++++++++++++
 src/plugins/robot-memory/robot_memory_setup.h    |   57 ++++++++
 src/plugins/robot-memory/robot_memory_thread.cpp |    6 +-
 src/plugins/robot-memory/robot_memory_thread.h   |    2 +-
 6 files changed, 234 insertions(+), 4 deletions(-)
 create mode 100644 src/plugins/robot-memory/robot_memory_setup.cpp
 create mode 100644 src/plugins/robot-memory/robot_memory_setup.h


- *Diffs* -------------------------------------------------------------

- *commit* 04a3c63656cd488bbd7b3f06f976333f9db6e5d2 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Wed Sep 21 17:55:02 2016 +0200
Subject: robot-memory: startup local mongod processes

 src/plugins/robot-memory/robot_memory_plugin.cpp |   16 +++-
 src/plugins/robot-memory/robot_memory_setup.cpp  |  122 ++++++++++++++++++++++
 src/plugins/robot-memory/robot_memory_setup.h    |   56 ++++++++++
 src/plugins/robot-memory/robot_memory_thread.cpp |    6 +-
 src/plugins/robot-memory/robot_memory_thread.h   |    2 +-
 5 files changed, 198 insertions(+), 4 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/robot_memory_plugin.cpp b/src/plugins/robot-memory/robot_memory_plugin.cpp
index 2160ed6..c0d4b0f 100644
--- a/src/plugins/robot-memory/robot_memory_plugin.cpp
+++ b/src/plugins/robot-memory/robot_memory_plugin.cpp
@@ -19,6 +19,9 @@
  */
 
 #include "robot_memory_thread.h"
+#include "robot_memory_setup.h"
+#include <string>
+#include <logging/console.h>
 
 #include <core/plugin.h>
 
@@ -37,14 +40,25 @@ class RobotMemoryPlugin : public fawkes::Plugin
    */
   RobotMemoryPlugin(Configuration *config) : Plugin(config)
   {
-	  thread_list.push_back(new RobotMemoryThread());
+    //before starting the robot memory (thread), we have to setup the mongod and mongos processes
+    //because the mongodb aspect of the robot memory hat to connect to it
+    logger_for_setup = new ConsoleLogger(Logger::LL_WARN);
+    setup = new RobotMemorySetup(config, logger_for_setup);
+    setup->setup_mongods();
+
+    std::string mongo_client_connection = config->get_string("plugins/robot-memory/setup/mongo-client-connection");
+	  thread_list.push_back(new RobotMemoryThread(mongo_client_connection));
   }
 
 
   ~RobotMemoryPlugin()
   {
+    delete setup;
+    delete logger_for_setup;
   }
 
+  RobotMemorySetup* setup;
+  Logger *logger_for_setup;
 };
 
 
diff --git a/src/plugins/robot-memory/robot_memory_thread.cpp b/src/plugins/robot-memory/robot_memory_thread.cpp
index 5ba2c0c..807c55d 100644
--- a/src/plugins/robot-memory/robot_memory_thread.cpp
+++ b/src/plugins/robot-memory/robot_memory_thread.cpp
@@ -35,9 +35,11 @@ using namespace fawkes;
  */
 
 /** Constructor. */
-RobotMemoryThread::RobotMemoryThread()
+RobotMemoryThread::RobotMemoryThread(std::string mongo_client_connection)
 	: Thread("RobotMemoryThread", Thread::OPMODE_WAITFORWAKEUP),
-	  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS),
+    ConfigurableAspect(),
+    MongoDBAspect(mongo_client_connection.c_str()),
+    BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_PROCESS),
     AspectProviderAspect(&robot_memory_inifin_)
 {
 }
diff --git a/src/plugins/robot-memory/robot_memory_thread.h b/src/plugins/robot-memory/robot_memory_thread.h
index b23ed42..610252f 100644
--- a/src/plugins/robot-memory/robot_memory_thread.h
+++ b/src/plugins/robot-memory/robot_memory_thread.h
@@ -53,7 +53,7 @@ class RobotMemoryThread
   public fawkes::AspectProviderAspect
 {
  public:
-  RobotMemoryThread();
+  RobotMemoryThread(std::string mongo_client_connection);
   virtual ~RobotMemoryThread();
 
   virtual void init();

- *commit* 553e17b178e18bd0dc814b99ed22a28331e248cd - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Wed Sep 21 19:48:29 2016 +0200
Subject: utils: string_conversions: resolve ~ in path

 src/libs/utils/misc/string_conversions.cpp |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/utils/misc/string_conversions.cpp b/src/libs/utils/misc/string_conversions.cpp
index f3bac1d..7cf194c 100644
--- a/src/libs/utils/misc/string_conversions.cpp
+++ b/src/libs/utils/misc/string_conversions.cpp
@@ -289,6 +289,7 @@ StringConversions::resolve_path(std::string s)
   resolve_map["@CONFDIR@"] = CONFDIR;
   resolve_map["@SRCDIR@"] = SRCDIR;
   resolve_map["@FAWKES_BASEDIR@"] = FAWKES_BASEDIR;
+  resolve_map["~"] = getenv("HOME");
   std::string res = s;
   for(std::map<std::string, std::string>::iterator it = resolve_map.begin(); it != resolve_map.end(); it++)
   {

- *commit* ae75a1bf012916533f7c608c5d61ed8b53e706c0 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Wed Sep 21 19:48:59 2016 +0200
Subject: robot-memory: setup config server for distributed robot memory

 src/plugins/robot-memory/robot_memory_setup.cpp |   44 ++++++++++++++++++++---
 src/plugins/robot-memory/robot_memory_setup.h   |    3 +-
 2 files changed, 41 insertions(+), 6 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/robot_memory_setup.cpp b/src/plugins/robot-memory/robot_memory_setup.cpp
index dd56a12..49fffb1 100644
--- a/src/plugins/robot-memory/robot_memory_setup.cpp
+++ b/src/plugins/robot-memory/robot_memory_setup.cpp
@@ -20,8 +20,10 @@
  */
 
 #include "robot_memory_setup.h"
+#include <plugin/loader.h>
 #include <mongo/client/dbclient.h>
 #include <mongo/client/init.h>
+#include <utils/misc/string_conversions.h>
 
 using namespace fawkes;
 
@@ -43,17 +45,37 @@ RobotMemorySetup::~RobotMemorySetup()
 void RobotMemorySetup::setup_mongods()
 {
   //start local mongod if necessary
-  unsigned int local_port = config->get_uint("plugins/robot-memory/setup/local/port");
+  unsigned int local_port = config->get_int("plugins/robot-memory/setup/local/port");
   if (!is_mongo_running(local_port))
   {
     const char *argv[] = {"mongod","--port", std::to_string(local_port).c_str(), NULL};
     std::string cmd = command_args_tostring(argv);
-    //logger->log_debug("RobotMemorySetup", "Port: '%s'", std::to_string(local_port).c_str());
     logger->log_info("RobotMemorySetup", "Starting local mongod process: '%s'", cmd.c_str());
     local_mongod = new SubProcess("mongod-local", "mongod", argv, NULL, logger);
     logger->log_info("RobotMemorySetup", "Started local mongod");
     wait_until_started(local_port, cmd);
   }
+
+  //only start other processes when we want to run the robot memory distributed
+  if(!config->get_bool("plugins/robot-memory/setup/distributed"))
+    return;
+
+  unsigned int config_port = config->get_int("plugins/robot-memory/setup/config/port");
+  if (!is_mongo_running(config_port))
+  {
+    std::string repl_set_name = config->get_string("plugins/robot-memory/setup/config/replica-set-name");
+    std::string db_path = StringConversions::resolve_path(config->get_string("plugins/robot-memory/setup/config/db-path").c_str());
+    const char *argv[] = {"mongod", "--configsvr", "--port", std::to_string(config_port).c_str(),
+        //"--replSet", repl_set_name.c_str(),
+        "--dbpath", db_path.c_str(), NULL};
+    logger->log_info("RobotMemorySetup", "Running on port: %s", std::to_string(config_port));
+    std::string cmd = command_args_tostring(argv);
+    prepare_mongo_db_path(db_path);
+    logger->log_info("RobotMemorySetup", "Starting config mongod process: '%s'", cmd.c_str());
+    config_mongod = new SubProcess("mongod-config", "mongod", argv, NULL, logger);
+    logger->log_info("RobotMemorySetup", "Started config mongod");
+    wait_until_started(config_port, cmd);
+  }
 }
 
 /**
@@ -64,8 +86,12 @@ void RobotMemorySetup::shutdown_mongods()
 {
   if (local_mongod)
     delete local_mongod;
-
-  //TODO:remember and shutdown Subprocesses
+  if (config_mongod)
+    delete config_mongod;
+  if (distribuded_mongod)
+    delete distribuded_mongod;
+  if (mongos)
+    delete mongos;
 }
 
 /**
@@ -118,5 +144,13 @@ void RobotMemorySetup::wait_until_started(unsigned int port, std::string cmd, in
       return;
     usleep(wait_step);
   }
-  logger->log_error("RobotMemorySetup", "MongoDB did not starup in the given time. Please start '%s' manually once.", cmd.c_str());
+  std::string err_msg = "MongoDB did not starup in the given time. Please start '"
+      +cmd+"' manually once.";
+  throw PluginLoadException("robot-memory", err_msg.c_str());
+}
+
+void RobotMemorySetup::prepare_mongo_db_path(std::string path)
+{
+  std::string command = "mkdir -p " + path;
+  popen(command.c_str(), "r");
 }
diff --git a/src/plugins/robot-memory/robot_memory_setup.h b/src/plugins/robot-memory/robot_memory_setup.h
index 248b93e..c3bf1ea 100644
--- a/src/plugins/robot-memory/robot_memory_setup.h
+++ b/src/plugins/robot-memory/robot_memory_setup.h
@@ -45,7 +45,8 @@ class RobotMemorySetup
     fawkes::Logger *logger;
 
     bool is_mongo_running(unsigned int port);
-    void wait_until_started(unsigned int port, std::string cmd, int timout = 10000000);
+    void wait_until_started(unsigned int port, std::string cmd, int timout = 15000000);
+    void prepare_mongo_db_path(std::string path);
 
     fawkes::SubProcess *local_mongod;
     fawkes::SubProcess *config_mongod;




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list