Kea  1.9.9-git
isc::db::BackendSelector Class Reference

Config Backend selector. More...

#include <backend_selector.h>

+ Inheritance diagram for isc::db::BackendSelector:

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 BackendSelectorUNSPEC ()
 Returns instance of the "unspecified" backend selector. More...

Detailed Description

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.

Member Enumeration Documentation

Supported database types.

The UNSPEC indicates that the database type is not specified as selection criteria.


Definition at line 62 of file backend_selector.h.

Constructor & Destructor Documentation

isc::db::BackendSelector::BackendSelector ( )

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

isc::db::BackendSelector::BackendSelector ( const Type backend_type)

Constructor specifying backend type as a selection criteria.

backend_typeType of the backend to be selected.

Definition at line 24 of file

isc::db::BackendSelector::BackendSelector ( const std::string &  host,
const uint16_t  port = 0 

Constructor for specifying host and optionally port as a selection criteria.

hostHostname to be used for selecting a backend.
portPort 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

isc::db::BackendSelector::BackendSelector ( const data::ConstElementPtr access_map)

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:

"type": "mysql"
"host": ""
"host": "",
"port": 1234
"type": "mysql"
"host": "",
"type": "mysql"
"host": "",
"port": 1234

where "type" can be any of the supported backend types.

This constructor is useful for creating backend selectors from the received control commands.

access_mapAccess map as provided above.

Definition at line 36 of file

References isc_throw, and stringToBackendType().

+ Here is the call graph for this function:

Member Function Documentation

bool isc::db::BackendSelector::amUnspecified ( ) const
std::string isc::db::BackendSelector::backendTypeToString ( const Type type)

Converts backend type to string.

typeBackend type to be converted.

Definition at line 147 of file

References CQL, MYSQL, and PGSQL.

Referenced by toElement(), and toText().

std::string isc::db::BackendSelector::getBackendHost ( ) const

Returns host selected.

host if specified or empty string if host is not specified.

Definition at line 157 of file backend_selector.h.

Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().

uint16_t isc::db::BackendSelector::getBackendPort ( ) const

Returns port selected.

port number of the selected backend or 0 if port number is not specified.

Definition at line 165 of file backend_selector.h.

Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().

Type isc::db::BackendSelector::getBackendType ( ) const

Returns backend type selected.

Definition at line 149 of file backend_selector.h.

Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().

BackendSelector::Type isc::db::BackendSelector::stringToBackendType ( const std::string &  type)

Converts string to backend type.

typeBackend type as string.

Definition at line 131 of file

References CQL, isc_throw, MYSQL, and PGSQL.

Referenced by BackendSelector(), and isc::cb::BaseConfigBackendPool< ConfigBackendDHCPv6 >::selectBackends().

ElementPtr isc::db::BackendSelector::toElement ( ) const

Unparse a backend selector object.

The caller must ensure that the selector type is specified.

A pointer to unparsed backend selector configuration.
BadValueIf the backend selector type is unspecified.

Implements isc::data::CfgToElement.

Definition at line 115 of file

References backendTypeToString(), isc_throw, and UNSPEC.

+ Here is the call graph for this function:

const BackendSelector & isc::db::BackendSelector::UNSPEC ( )

Returns instance of the "unspecified" backend selector.

Definition at line 74 of file

The documentation for this class was generated from the following files: