13#include <boost/algorithm/string.hpp>
28map<string, pair<LeaseMgrFactory::Factory, LeaseMgrFactory::DBVersion>> LeaseMgrFactory::map_;
33isc::dhcp::MemfileLeaseMgrInit memfile_init;
38LeaseMgrFactory::getLeaseMgrPtr() {
40 return (lease_mgr_ptr);
53 cfg->getCfgSubnets4()->initAllocatorsAfterConfigure();
55 cfg->getCfgSubnets6()->initAllocatorsAfterConfigure();
62 const std::string type =
"type";
69 DatabaseConnection::ParameterMap::iterator it = parameters.find(type);
70 if (it == parameters.end()) {
73 "contain the 'type' keyword");
76 string db_type = it->second;
77 auto index = map_.find(db_type);
80 if (index == map_.end()) {
81 if ((db_type ==
"mysql") || (db_type ==
"postgresql")) {
83 string libdhcp(db_type ==
"postgresql" ?
"pgsql" : db_type);
85 "support for lease database type: " << db_type
86 <<
". Did you forget to use -D "
87 << db_type <<
"=enabled during setup or to load libdhcp_"
88 << libdhcp <<
" hook library?");
93 "not specify a supported database backend: " << parameters[type]);
97 getLeaseMgrPtr() = index->second.first(parameters);
100 if (!getLeaseMgrPtr()) {
102 " factory returned null");
110 if (getLeaseMgrPtr()) {
112 .arg(getLeaseMgrPtr()->getType());
113 getLeaseMgrPtr().reset();
144 return (!!getLeaseMgrPtr());
161 if (map_.count(db_type)) {
165 static auto default_db_version = []() -> std::string {
166 return (std::string());
170 db_version = default_db_version;
173 map_.insert(pair<
string, pair<Factory, DBVersion>>(db_type, pair<Factory, DBVersion>(factory, db_version)));
188 auto index = map_.find(db_type);
189 if (index != map_.end()) {
204 auto index = map_.find(db_type);
205 return (index != map_.end());
210 std::stringstream txt;
212 for (
auto const& x : map_) {
213 if (!txt.str().empty()) {
223std::list<std::string>
225 std::list<std::string> result;
226 for (
auto const& x : map_) {
227 auto version = x.second.second();
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 std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
static void create(const std::string &dbaccess)
Create an instance of a lease manager.
static TrackingLeaseMgr & instance()
Return current lease manager.
static bool registerFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Register a lease mgr factory.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
static bool init_allocators_
Flag which indicates if allocators must be initialized.
std::function< TrackingLeaseMgrPtr(const db::DatabaseConnection::ParameterMap &)> Factory
Type of lease mgr factory.
static void destroy()
Destroy lease manager.
static bool registeredFactory(const std::string &db_type)
Check if a lease mgr factory was registered.
std::function< std::string()> DBVersion
Type of lease mgr version.
static void initAllocators(bool use_staging=false)
Initializes the lease allocators for all subnets.
static bool haveInstance()
Indicates if the lease manager has been instantiated.
static bool deregisterFactory(const std::string &db_type, bool no_log=false)
Deregister a lease mgr factory.
static void logRegistered()
Logs out all registered backends.
static void recreate(const std::string &dbaccess, bool preserve_callbacks=true)
Recreate an instance of a lease manager with optionally preserving registered callbacks.
No lease manager exception.
Introduces callbacks into the LeaseMgr.
boost::shared_ptr< CallbackContainer > CallbackContainerPtr
Pointer to the callback container.
CallbackContainerPtr callbacks_
The multi-index container holding registered callbacks.
int version()
returns Kea hooks version.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#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 dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED
const isc::log::MessageID DHCPSRV_LEASE_MGR_BACKEND_DEREGISTER
const isc::log::MessageID DHCPSRV_CLOSE_DB
const isc::log::MessageID DHCPSRV_UNKNOWN_DB
const isc::log::MessageID DHCPSRV_LEASE_MGR_BACKEND_REGISTER
const isc::log::MessageID DHCPSRV_NOTYPE_DB
std::unique_ptr< TrackingLeaseMgr > TrackingLeaseMgrPtr
TrackingLeaseMgr pointer.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Defines the logger used by the top-level component of kea-lfc.