26 #include <boost/algorithm/string.hpp>
27 #include <boost/foreach.hpp>
28 #include <boost/scoped_ptr.hpp>
43 map<string, HostDataSourceFactory::Factory> HostDataSourceFactory::map_;
47 const string& dbaccess) {
53 DatabaseConnection::ParameterMap::iterator it = parameters.find(
"type");
54 if (it == parameters.end()) {
56 "contain the 'type' keyword");
59 string db_type = it->second;
60 auto index = map_.find(db_type);
63 if (index == map_.end()) {
64 if ((db_type ==
"mysql") ||
65 (db_type ==
"postgresql") ||
67 string with = (db_type ==
"postgresql" ?
"pgsql" : db_type);
69 <<
"' is not compiled in. Did you forget to use --with-"
70 << with <<
" during compilation?");
73 db_type <<
"' is not supported");
77 sources.push_back(index->second(parameters));
80 if (!sources.back()) {
83 " factory returned NULL");
89 const string& db_type) {
90 for (
auto it = sources.begin(); it != sources.end(); ++it) {
91 if ((*it)->getType() != db_type) {
104 const string& db_type,
105 const string& dbaccess,
109 bool deleted =
false;
114 for (
auto it = sources.begin(); it != sources.end(); ++it) {
115 if ((*it)->getType() != db_type || (*it)->getParameters() != parameters) {
118 if (if_unusable && (!(*it)->isUnusable())) {
123 .arg((*it)->getType());
131 HostDataSourceFactory::registerFactory(
const string& db_type,
134 if (map_.count(db_type)) {
137 map_.insert(pair<string, Factory>(db_type, factory));
151 HostDataSourceFactory::deregisterFactory(
const string& db_type,
bool no_log) {
152 auto index = map_.find(db_type);
153 if (index != map_.end()) {
167 HostDataSourceFactory::registeredFactory(
const std::string& db_type) {
168 auto index = map_.find(db_type);
169 return (index != map_.end());
173 HostDataSourceFactory::printRegistered() {
174 std::stringstream txt;
176 for (
auto x : map_) {
177 txt << x.first <<
" ";
195 struct MySqlHostDataSourceInit {
197 MySqlHostDataSourceInit() {
198 HostDataSourceFactory::registerFactory(
"mysql", factory,
true);
202 ~MySqlHostDataSourceInit() {
203 HostDataSourceFactory::deregisterFactory(
"mysql",
true);
216 MySqlHostDataSourceInit mysql_init_;
220 struct PgSqlHostDataSourceInit {
222 PgSqlHostDataSourceInit() {
223 HostDataSourceFactory::registerFactory(
"postgresql", factory,
true);
227 ~PgSqlHostDataSourceInit() {
228 HostDataSourceFactory::deregisterFactory(
"postgresql",
true);
241 PgSqlHostDataSourceInit pgsql_init_;
245 struct CqlHostDataSourceInit {
247 CqlHostDataSourceInit() {
248 HostDataSourceFactory::registerFactory(
"cql", factory,
true);
252 ~CqlHostDataSourceInit() {
253 HostDataSourceFactory::deregisterFactory(
"cql",
true);
266 CqlHostDataSourceInit cql_init_;
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
boost::shared_ptr< BaseHostDataSource > HostDataSourcePtr
HostDataSource pointer.
const isc::log::MessageID HOSTS_BACKENDS_REGISTERED
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::function< HostDataSourcePtr(const db::DatabaseConnection::ParameterMap &)> Factory
Type of host data source factory.
isc::log::Logger hosts_logger("hosts")
Logger for the HostMgr and the code it calls.
A generic exception that is thrown when an unexpected error condition occurs.
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::log::MessageID DHCPSRV_PGSQL_HOST_DB
Logging initialization functions.
const isc::log::MessageID HOSTS_BACKEND_REGISTER
const isc::log::MessageID DHCPSRV_CQL_HOST_DB
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
const isc::log::MessageID HOSTS_BACKEND_DEREGISTER
PostgreSQL Host Data Source.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
Cassandra host data source.
const isc::log::MessageID DHCPSRV_MYSQL_HOST_DB
const isc::log::MessageID HOSTS_CFG_CLOSE_HOST_DATA_SOURCE