Kea 2.7.5
|
Base class for Configuration Backend Managers (CBM). More...
#include <base_config_backend_mgr.h>
Public Types | |
typedef boost::shared_ptr< ConfigBackendPoolType > | ConfigBackendPoolPtr |
Pointer to the configuration backend pool. | |
typedef std::function< typename ConfigBackendPoolType::ConfigBackendTypePtr(const db::DatabaseConnection::ParameterMap &) | Factory) |
Type of the backend factory function. | |
Public Member Functions | |
BaseConfigBackendMgr () | |
Constructor. | |
void | addBackend (const std::string &dbaccess) |
Create an instance of a configuration backend. | |
void | delAllBackends () |
Removes all backends from the pool. | |
bool | delBackend (const std::string &db_type, const std::string &dbaccess, bool if_unusable) |
Delete a config backend manager. | |
ConfigBackendPoolPtr | getPool () const |
Returns underlying config backend pool. | |
bool | registerBackendFactory (const std::string &db_type, const Factory &factory) |
Registers new backend factory function for a given backend type. | |
bool | unregisterBackendFactory (const std::string &db_type) |
Unregisters the backend factory function for a given backend type. | |
Protected Attributes | |
std::map< std::string, Factory > | factories_ |
A map holding registered backend factory functions. | |
ConfigBackendPoolPtr | pool_ |
Pointer to the configuration backends pool. | |
Base class for Configuration Backend Managers (CBM).
Each Kea server supporting Configuration Backend feature implements a "manager" class which holds information about supported and configured backends and provides access to the backends. This is similar to HostMgr
and LeaseMgr
singletons being used by the DHCP servers.
The Config Backend Managers are typically implemented as singletons which can be accessed from any place within the server code. This includes server configuration, data fetching during normal server operation and data management, including processing of control commands implemented within hooks libraries.
The BaseConfigBackendMgr
is a base class for all CBMs implemented for respective Kea servers. It includes mechanisms to register config backend factory functions and to create instances of the backends using those factory functions as a result of server configuration. The mechanism of factory functions registration is useful in cases when the config backend is implemented within the hook library. Such hook library registers factory function in its load
function and the server simply calls this function to create the instance of this backend when instructed to do so via configuration. Similar mechanism exists in DHCP HostMgr
.
Unlike HostMgr
, the CBMs do not directly expose API to fetch and manipulate the data in the database. This is done via, so called, Configuration Backends Pools. See BaseConfigBackendPool
for details. The BaseConfigBackendMgr
is provided with the pool type via class template parameter. Respective CBM implementations use their own pools, which provide APIs appropriate for those implementations.
ConfgBackendPoolType | Type of the configuration backend pool to be used by the manager. It must derive from BaseConfigBackendPool template class. |
Definition at line 59 of file base_config_backend_mgr.h.
typedef boost::shared_ptr<ConfigBackendPoolType> isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::ConfigBackendPoolPtr |
Pointer to the configuration backend pool.
Definition at line 63 of file base_config_backend_mgr.h.
typedef std::function<typename ConfigBackendPoolType::ConfigBackendTypePtr (const db::DatabaseConnection::ParameterMap&) isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::Factory) |
Type of the backend factory function.
Factory function returns a pointer to the instance of the configuration backend created.
Definition at line 70 of file base_config_backend_mgr.h.
|
inline |
Constructor.
Definition at line 73 of file base_config_backend_mgr.h.
|
inline |
Create an instance of a configuration backend.
This method uses provided dbaccess
string representing database connection information to create an instance of the database backend. If the specified backend type is not supported, i.e. there is no relevant factory function registered, an exception is thrown.
dbaccess | Database access string being a collection of key=value pairs. |
InvalidParameter | if access string lacks database type value. |
db::InvalidType | if the type of the database backend is not supported. |
Unexpected | if the backend factory function returned NULL. |
Definition at line 148 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_, isc_throw, isc::db::DatabaseConnection::parse(), and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.
|
inline |
Removes all backends from the pool.
Definition at line 189 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.
|
inline |
Delete a config backend manager.
Delete the first instance of a config database manager which matches specific parameters. This should have the effect of closing the database connection.
db_type | Backend to remove. |
dbaccess | Database access string being a collection of key=value pairs. |
if_unusable | Flag which indicates if the config backend should be deleted only if it is unusable. |
Definition at line 206 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.
|
inline |
Returns underlying config backend pool.
Definition at line 212 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.
|
inline |
Registers new backend factory function for a given backend type.
The typical usage of this function is to make the CBM aware of a configuration backend implementation. This implementation may exist in a hooks library. In such case, this function should be called from the load
function in this library. When the backend is registered, the server will use it when required by the configuration, i.e. a user includes configuration backend of that type in the "config-databases" list.
If the backend of the given type has already been registered, perhaps by another hooks library, the CBM will refuse to register another backend of the same type.
db_type | Backend type, e.g. "mysql". |
factory | Pointer to the backend factory function. |
Definition at line 96 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_.
|
inline |
Unregisters the backend factory function for a given backend type.
This function is used to remove the factory function and all backend instances for a given backend type. Typically, it would be called when unloading the a config backend hook library, and thus called by the library's unload
function.
db_type | Backend type, e.g. "mysql". |
Definition at line 119 of file base_config_backend_mgr.h.
References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_, and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.
|
protected |
A map holding registered backend factory functions.
Definition at line 219 of file base_config_backend_mgr.h.
Referenced by isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::addBackend(), isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::registerBackendFactory(), and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::unregisterBackendFactory().
|
protected |
Pointer to the configuration backends pool.
Definition at line 222 of file base_config_backend_mgr.h.
Referenced by isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::addBackend(), isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::delAllBackends(), isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::delBackend(), isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::getPool(), and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::unregisterBackendFactory().