22 #include "event_trigger_manager.h" 24 #include <boost/bind.hpp> 27 using namespace mongo;
47 mongo_connection_manager_ = mongo_connection_manager;
49 con_local_ = mongo_connection_manager_->
create_client(
"robot-memory-local");
50 if (config_->
exists(
"/plugins/mongodb/clients/robot-memory-distributed/enabled")
51 && config_->
get_bool(
"/plugins/mongodb/clients/robot-memory-distributed/enabled")) {
52 con_replica_ = mongo_connection_manager_->
create_client(
"robot-memory-distributed");
56 std::string local_db = config_->
get_string(
"/plugins/robot-memory/database");
57 dbnames_local_.push_back(local_db);
58 dbnames_distributed_ = config_->
get_strings(
"/plugins/robot-memory/distributed-db-names");
63 cfg_debug_ = config->
get_bool(
"/plugins/robot-memory/more-debug-output");
68 EventTriggerManager::~EventTriggerManager()
79 EventTriggerManager::check_events()
87 while (trigger->oplog_cursor->more()) {
88 BSONObj change = trigger->oplog_cursor->next();
91 trigger->callback(change);
93 }
catch (mongo::DBException &e) {
94 logger_->
log_error(name.c_str(),
"Error while reading the oplog");
97 if (!ok || trigger->oplog_cursor->isDead()) {
99 logger_->
log_debug(name.c_str(),
"Tailable Cursor is dead, requerying");
101 mongo::DBClientBase *con;
102 if (std::find(dbnames_distributed_.begin(),
103 dbnames_distributed_.end(),
105 != dbnames_distributed_.end()) {
111 trigger->oplog_cursor = create_oplog_cursor(con,
"local.oplog.rs", trigger->oplog_query);
123 triggers.remove(trigger);
128 EventTriggerManager::create_oplog_cursor(mongo::DBClientBase *con,
132 QResCursor res = con->query(oplog, query, 0, 0, 0, QueryOption_CursorTailable);
134 while (res->more()) {
147 std::string::size_type dot_pos = ns.find(
".");
148 if (dot_pos == std::string::npos) {
151 return ns.substr(0, dot_pos);
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
Class holding all information about an EventTrigger.
static std::string get_db_name(const std::string &ns)
Split database name from namespace.
virtual mongo::DBClientBase * create_client(const std::string &config_name="")=0
Create a new MongoDB client.
Interface for a MongoDB connection creator.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual std::vector< std::string > get_strings(const char *path)=0
Get list of values from configuration which is of type string.
void remove_trigger(EventTrigger *trigger)
Remove a previously registered trigger.
EventTriggerManager(fawkes::Logger *logger, fawkes::Configuration *config, fawkes::MongoDBConnCreator *mongo_connection_manager)
Constructor for class managing EventTriggers.
virtual bool exists(const char *path)=0
Check if a given value exists.
Mutex mutual exclusion lock.
Interface for configuration handling.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
virtual void delete_client(mongo::DBClientBase *client)=0
Delete a client.