22#ifndef _PLUGINS_MONGODB_MONGODB_REPLICASET_CONFIG_H_
23#define _PLUGINS_MONGODB_MONGODB_REPLICASET_CONFIG_H_
25#include <aspect/blackboard.h>
26#include <aspect/clock.h>
27#include <aspect/configurable.h>
28#include <aspect/logging.h>
29#include <core/threading/thread.h>
30#include <interfaces/MongoDBManagedReplicaSetInterface.h>
32#include <bsoncxx/json.hpp>
34#include <mongocxx/client.hpp>
55 const std::string &prefix,
56 const std::string &bootstrap_prefix);
73 bool leader_elect(
bool force =
false);
76 struct ReplicaSetStatus
78 fawkes::MongoDBManagedReplicaSetInterface::ReplicaSetMemberStatus member_status;
79 fawkes::MongoDBManagedReplicaSetInterface::ReplicaSetPrimaryStatus primary_status;
80 std::string error_msg;
83 operator!=(
const ReplicaSetStatus &other)
const
85 return member_status != other.member_status || primary_status != other.primary_status
86 || error_msg != other.error_msg;
91 ReplicaSetStatus rs_status(bsoncxx::document::value &reply);
93 void rs_monitor(
const bsoncxx::document::view &reply);
94 bool check_alive(
const std::string &h);
95 bool rs_get_config(bsoncxx::document::value &rs_config);
108 std::string config_name_;
110 std::shared_ptr<mongocxx::client> bootstrap_client_;
111 bsoncxx::document::value leader_elec_query_;
112 bsoncxx::document::value leader_elec_query_force_;
113 bsoncxx::document::value leader_elec_update_;
115 std::string bootstrap_prefix_;
116 std::string bootstrap_database_;
117 std::string bootstrap_ns_;
119 std::string local_client_cfg_;
120 std::shared_ptr<mongocxx::client> local_client_;
121 std::string local_hostport_;
122 std::set<std::string> hosts_;
125 float loop_interval_;
126 int leader_expiration_;
129 ReplicaSetStatus last_status_;
131 fawkes::MongoDBManagedReplicaSetInterface *rs_status_if_;
MongoDB replica set configuration.
virtual void init()
Initialize the thread.
MongoDBReplicaSetConfig(const std::string &cfgname, const std::string &prefix, const std::string &bootstrap_prefix)
Constructor.
virtual void loop()
Code to execute in the thread.
bool is_enabled() const
Check if configuration is enabled.
virtual void finalize()
Finalize the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to access to BlackBoard.
Thread aspect that allows to obtain the current time from the clock.
Thread aspect to access configuration data.
Thread aspect to log output.
Thread class encapsulation of pthreads.
Fawkes library namespace.