Kea
1.9.9-git
|
Config Backend selector. More...
#include <backend_selector.h>
Public Types | |
enum | Type { Type::MYSQL, Type::PGSQL, Type::CQL, Type::UNSPEC } |
Supported database types. More... | |
Public Member Functions | |
BackendSelector () | |
Default constructor. More... | |
BackendSelector (const Type &backend_type) | |
Constructor specifying backend type as a selection criteria. More... | |
BackendSelector (const std::string &host, const uint16_t port=0) | |
Constructor for specifying host and optionally port as a selection criteria. More... | |
BackendSelector (const data::ConstElementPtr &access_map) | |
Constructor for selecting a backend using JSON access map. More... | |
bool | amUnspecified () const |
Checks if selector is "unspecified". More... | |
std::string | getBackendHost () const |
Returns host selected. More... | |
uint16_t | getBackendPort () const |
Returns port selected. More... | |
Type | getBackendType () const |
Returns backend type selected. More... | |
virtual data::ElementPtr | toElement () const |
Unparse a backend selector object. More... | |
std::string | toText () const |
Returns selections as text. More... | |
Public Member Functions inherited from isc::data::CfgToElement | |
virtual | ~CfgToElement () |
Destructor. More... | |
Static Public Member Functions | |
static std::string | backendTypeToString (const Type &type) |
Converts backend type to string. More... | |
static Type | stringToBackendType (const std::string &type) |
Converts string to backend type. More... | |
static const BackendSelector & | UNSPEC () |
Returns instance of the "unspecified" backend selector. More... | |
Config Backend selector.
Each Kea server using database as a configuration respository may use multiple configuration backends simultaneously. The most typical case is to use a single configuration backend per server, but there are use cases when configuration information is distributed accross multiple database instances. In the future, there may be also caching mechanisms implemented, which will allow for storing results of certain database queries in memory.
From the server perspective, the most common use of the configuration backend is to fetch entire configuration information from the databases (upon startup) or fetch the latest updates to the configuration, e.g. new subnet added, DHCP option modified etc. In those cases, it is not so important from the server which backend this data come from. Therefore, the server would fetch this information from all available backends.
When the server administrator wants to insert some new data into the database, modify existing data or simply wants to check the contents of one of the database instance, he would specify which database backend he wants to direct queries to.
The BackendSelector
class provides means to specify whether the queries should be directed to any backend (see server case above) or to a specific backend (data insertion case above). In addition, the BackendSelector
allows for using various criteria for selecting a backend to use. Currently those criteria are: database type (e.g. mysql), database host and database port. In order to use a specific port, the database host must also be specified. Note that in a general case multiple backends of the same type can be used simultaneously, e.g. multiple MySQL backends. In that case, it may be necessary to specify host (and port) to issue a query to the right one.
The BackendSelector
class may be extended in the future to provide additional backend selection criteria.
Definition at line 55 of file backend_selector.h.
|
strong |
Supported database types.
The UNSPEC
indicates that the database type is not specified as selection criteria.
Enumerator | |
---|---|
MYSQL | |
PGSQL | |
CQL | |
UNSPEC |
Definition at line 62 of file backend_selector.h.
|
explicit |
Default constructor.
It sets the selector to "unspecified". When this selector is used the backend pool will use "any" backend. This has a different meaning for each type of query. See the BaseConfigBackendPool
for details.
Definition at line 19 of file backend_selector.cc.
|
explicit |
Constructor specifying backend type as a selection criteria.
backend_type | Type of the backend to be selected. |
Definition at line 24 of file backend_selector.cc.
|
explicit |
Constructor for specifying host and optionally port as a selection criteria.
host | Hostname to be used for selecting a backend. |
port | Port number to be used for selecting a backend. This value is optional and is ignored when set to 0. It must be used on conjuction with hostname. |
Definition at line 29 of file backend_selector.cc.
|
explicit |
Constructor for selecting a backend using JSON access map.
The provided access map must have the same structure as an element of the "config-databases" configuration parameter. However, it merely takes into account: "type", "host" and "port" parameters. In addition, these parameters are optional. The following are valid combinations:
where "type" can be any of the supported backend types.
This constructor is useful for creating backend selectors from the received control commands.
access_map | Access map as provided above. |
Definition at line 36 of file backend_selector.cc.
References isc_throw, and stringToBackendType().
bool isc::db::BackendSelector::amUnspecified | ( | ) | const |
Checks if selector is "unspecified".
UNSPEC
, hostname is empty and port number 0, false otherwise. Definition at line 80 of file backend_selector.cc.
References UNSPEC.
Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getAllPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getMultiplePropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getPropertyPtrConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends(), and toText().
|
static |
Converts backend type to string.
type | Backend type to be converted. |
Definition at line 147 of file backend_selector.cc.
References CQL, MYSQL, and PGSQL.
Referenced by toElement(), and toText().
|
inline |
Returns host selected.
Definition at line 157 of file backend_selector.h.
Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().
|
inline |
Returns port selected.
Definition at line 165 of file backend_selector.h.
Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().
|
inline |
Returns backend type selected.
Definition at line 149 of file backend_selector.h.
Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().
|
static |
Converts string to backend type.
type | Backend type as string. |
Definition at line 131 of file backend_selector.cc.
References CQL, isc_throw, MYSQL, and PGSQL.
Referenced by BackendSelector(), and isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().
|
virtual |
Unparse a backend selector object.
The caller must ensure that the selector type is specified.
BadValue | If the backend selector type is unspecified. |
Implements isc::data::CfgToElement.
Definition at line 115 of file backend_selector.cc.
References backendTypeToString(), isc_throw, and UNSPEC.
std::string isc::db::BackendSelector::toText | ( | ) | const |
Returns selections as text.
Definition at line 87 of file backend_selector.cc.
References amUnspecified(), backendTypeToString(), and UNSPEC.
Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::createUpdateDeleteBackendProperty(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::createUpdateDeleteProperty(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getAllBackendPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getAllPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getBackendPropertyPtrConst(), isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getMultiplePropertiesConst(), and isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::getPropertyPtrConst().
|
static |
Returns instance of the "unspecified" backend selector.
Definition at line 74 of file backend_selector.cc.