14#include <boost/algorithm/string.hpp>
29map<string, pair<HostDataSourceFactory::Factory, HostDataSourceFactory::DBVersion>> HostDataSourceFactory::map_;
33 const string& dbaccess) {
39 DatabaseConnection::ParameterMap::iterator it = parameters.find(
"type");
40 if (it == parameters.end()) {
42 "contain the 'type' keyword");
45 string db_type = it->second;
46 auto index = map_.find(db_type);
49 if (index == map_.end()) {
50 if ((db_type ==
"mysql") || (db_type ==
"postgresql")) {
51 string with = (db_type ==
"postgresql" ?
"pgsql" : db_type);
53 "support for host database type: " << db_type
54 <<
". Did you forget to use --with-"
55 << with <<
" during compilation or to load libdhcp_"
56 << with <<
" hook library?");
59 db_type <<
"' is not supported");
63 sources.push_back(index->second.first(parameters));
66 if (!sources.back()) {
69 " factory returned null");
75 const string& db_type) {
76 for (
auto it = sources.begin(); it != sources.end(); ++it) {
77 if ((*it)->getType() != db_type) {
90 const string& db_type,
91 const string& dbaccess,
100 for (
auto it = sources.begin(); it != sources.end(); ++it) {
101 if ((*it)->getType() != db_type || (*it)->getParameters() != parameters) {
104 if (if_unusable && (!(*it)->isUnusable())) {
109 .arg((*it)->getType());
118 const Factory& factory,
121 if (map_.count(db_type)) {
125 static auto default_db_version = []() -> std::string {
126 return (std::string());
130 db_version = default_db_version;
133 map_.insert(pair<
string, pair<Factory, DBVersion>>(db_type, pair<Factory, DBVersion>(factory, db_version)));
148 auto index = map_.find(db_type);
149 if (index != map_.end()) {
164 auto index = map_.find(db_type);
165 return (index != map_.end());
170 std::stringstream txt;
172 for (
auto const& x : map_) {
173 if (!txt.str().empty()) {
183std::list<std::string>
185 std::list<std::string> result;
186 for (
auto const& x : map_) {
187 auto version = x.second.second();
int version()
returns Kea hooks version.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static void logRegistered()
Logs out all registered backends.
static bool deregisterFactory(const std::string &db_type, bool no_log=false)
Deregister a host data source factory.
static void add(HostDataSourceList &sources, const std::string &dbaccess)
Create and add an instance of a host data source.
static bool registerFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Register a host data source factory.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
static bool del(HostDataSourceList &sources, const std::string &db_type)
Delete a host data source.
static bool registeredFactory(const std::string &db_type)
Check if a host data source factory was registered.
std::function< std::string()> DBVersion
Type of host mgr version.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Logging initialization functions.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
isc::log::Logger hosts_logger("hosts")
Logger for the HostMgr and the code it calls.
const isc::log::MessageID HOSTS_BACKEND_DEREGISTER
std::vector< HostDataSourcePtr > HostDataSourceList
HostDataSource list.
const isc::log::MessageID HOSTS_CFG_CLOSE_HOST_DATA_SOURCE
const isc::log::MessageID HOSTS_BACKEND_REGISTER
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
const isc::log::MessageID HOSTS_BACKENDS_REGISTERED
Defines the logger used by the top-level component of kea-lfc.