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 <<
"' is not compiled in. Did you forget to use --with-"
54 << with <<
" during compilation or to load libdhcp_"
55 << with <<
"_hb hook library?");
58 db_type <<
"' is not supported");
62 sources.push_back(index->second.first(parameters));
65 if (!sources.back()) {
68 " factory returned null");
74 const string& db_type) {
75 for (
auto it = sources.begin(); it != sources.end(); ++it) {
76 if ((*it)->getType() != db_type) {
89 const string& db_type,
90 const string& dbaccess,
99 for (
auto it = sources.begin(); it != sources.end(); ++it) {
100 if ((*it)->getType() != db_type || (*it)->getParameters() != parameters) {
103 if (if_unusable && (!(*it)->isUnusable())) {
108 .arg((*it)->getType());
117 const Factory& factory,
120 if (map_.count(db_type)) {
124 static auto default_db_version = []() -> std::string {
125 return (std::string());
129 db_version = default_db_version;
132 map_.insert(pair<
string, pair<Factory, DBVersion>>(db_type, pair<Factory, DBVersion>(factory, db_version)));
147 auto index = map_.find(db_type);
148 if (index != map_.end()) {
163 auto index = map_.find(db_type);
164 return (index != map_.end());
169 std::stringstream txt;
171 for (
auto const& x : map_) {
172 if (!txt.str().empty()) {
182std::list<std::string>
184 std::list<std::string> result;
185 for (
auto const& x : map_) {
186 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.