Kea 2.7.5
|
Config Backend selector. More...
#include <backend_selector.h>
Public Types | |
enum class | Type { MYSQL , POSTGRESQL , UNSPEC } |
Supported database types. More... | |
Public Member Functions | |
BackendSelector () | |
Default constructor. | |
BackendSelector (const data::ConstElementPtr &access_map) | |
Constructor for selecting a backend using JSON access map. | |
BackendSelector (const std::string &host, const uint16_t port=0) | |
Constructor for specifying host and optionally port as a selection criteria. | |
BackendSelector (const Type &backend_type) | |
Constructor specifying backend type as a selection criteria. | |
bool | amUnspecified () const |
Checks if selector is "unspecified". | |
std::string | getBackendHost () const |
Returns host selected. | |
uint16_t | getBackendPort () const |
Returns port selected. | |
Type | getBackendType () const |
Returns backend type selected. | |
virtual data::ElementPtr | toElement () const |
Unparse a backend selector object. | |
std::string | toText () const |
Returns selections as text. | |
Public Member Functions inherited from isc::data::CfgToElement | |
virtual | ~CfgToElement () |
Destructor. | |
Static Public Member Functions | |
static std::string | backendTypeToString (const Type &type) |
Converts backend type to string. | |
static Type | stringToBackendType (const std::string &type) |
Converts string to backend type. | |
static const BackendSelector & | UNSPEC () |
Returns instance of the "unspecified" backend selector. | |
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 | |
POSTGRESQL | |
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 in conjunction 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::data::Element::integer, isc_throw, isc::data::Element::map, isc::data::Element::string, 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 toText().
|
static |
Converts backend type to string.
type | Backend type to be converted. |
Definition at line 144 of file backend_selector.cc.
References MYSQL, and POSTGRESQL.
Referenced by toElement(), and toText().
|
inline |
Returns host selected.
Definition at line 156 of file backend_selector.h.
|
inline |
Returns port selected.
Definition at line 164 of file backend_selector.h.
|
inline |
Returns backend type selected.
Definition at line 148 of file backend_selector.h.
|
static |
Converts string to backend type.
type | Backend type as string. |
Definition at line 131 of file backend_selector.cc.
References isc_throw, MYSQL, and POSTGRESQL.
Referenced by BackendSelector().
|
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::data::Element::create(), isc::data::Element::createMap(), 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.
|
static |
Returns instance of the "unspecified" backend selector.
Definition at line 74 of file backend_selector.cc.