| Kea 3.0.2-git

isc::db::BackendSelector Class Reference

Config Backend selector. More...

`#include <backend_selector.h>`

Inheritance diagram for isc::db::BackendSelector:
[legend]

## 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.

## 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

## ◆ Type

enum class isc::db::BackendSelector::Type
| 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.

## Constructor & Destructor Documentation

## ◆ BackendSelector() [1/4]

isc::db::BackendSelector::BackendSelector | ( |  | ) |
| 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.

References BackendSelector(), and UNSPEC().

Referenced by BackendSelector(), BackendSelector(), BackendSelector(), and UNSPEC().

Here is the call graph for this function:

## ◆ BackendSelector() [2/4]

isc::db::BackendSelector::BackendSelector | ( | const Type & | backend_type | ) |
| explicit

Constructor specifying backend type as a selection criteria.

Parameters

  backend_type | Type of the backend to be selected.

Definition at line 24 of file backend_selector.cc.

## ◆ BackendSelector() [3/4]

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

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

Parameters

  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.

References BackendSelector(), and UNSPEC().

Here is the call graph for this function:

## ◆ BackendSelector() [4/4]

isc::db::BackendSelector::BackendSelector | ( | const data::ConstElementPtr & | access_map | ) |
| 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:

{
"type": "mysql"
}
{
"host": "somehost.example.org"
}
{
"host": "somehost.example.org",
"port": 1234
}
{
"type": "mysql"
"host": "somehost.example.org",
}
{
"type": "mysql"
"host": "somehost.example.org",
"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.

Parameters

  access_map | Access map as provided above.

Definition at line 36 of file backend_selector.cc.

References BackendSelector(), if(), Element::integer, isc_throw, Element::map, Element::string, stringToBackendType(), and UNSPEC().

Here is the call graph for this function:

## Member Function Documentation

## ◆ amUnspecified()

bool isc::db::BackendSelector::amUnspecified | ( |  | ) | const

Checks if selector is "unspecified".

Returns
  true if backend type is `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< ConfigBackendType >::getAllPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getMultiplePropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getPropertyPtrConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::selectBackends(), and toText().

## ◆ backendTypeToString()

std::string isc::db::BackendSelector::backendTypeToString | ( | const Type & | type | ) |
| static

Converts backend type to string.

Parameters

  type | Backend type to be converted.

Definition at line 144 of file backend_selector.cc.

References MYSQL, and POSTGRESQL.

Referenced by toElement(), and toText().

## ◆ getBackendHost()

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

Returns host selected.

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

Definition at line 156 of file backend_selector.h.

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

## ◆ getBackendPort()

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

Returns port selected.

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

Definition at line 164 of file backend_selector.h.

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

## ◆ getBackendType()

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

Returns backend type selected.

Definition at line 148 of file backend_selector.h.

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

## ◆ stringToBackendType()

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

Converts string to backend type.

Parameters

  type | Backend type as string.

Definition at line 131 of file backend_selector.cc.

References isc_throw, MYSQL, and POSTGRESQL.

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

## ◆ toElement()

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

Unparse a backend selector object.

The caller must ensure that the selector type is specified.

Returns
  A pointer to unparsed backend selector configuration.

Exceptions

  BadValue | If the backend selector type is unspecified.

Implements isc::data::CfgToElement.

Definition at line 115 of file backend_selector.cc.

References backendTypeToString(), Element::create(), Element::createMap(), isc_throw, and UNSPEC.

Here is the call graph for this function:

## ◆ toText()

std::string isc::db::BackendSelector::toText | ( |  | ) | const

Returns selections as text.

Returns
  Collection of comma separated selections, e.g. "type=mysql,host=somehost.example.org,port=1234".

Definition at line 87 of file backend_selector.cc.

References amUnspecified(), backendTypeToString(), and UNSPEC.

Referenced by isc::cb::BaseConfigBackendPool< ConfigBackendType >::createUpdateDeleteBackendProperty(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::createUpdateDeleteProperty(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getAllBackendPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getAllPropertiesConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getBackendPropertyPtrConst(), isc::cb::BaseConfigBackendPool< ConfigBackendType >::getMultiplePropertiesConst(), and isc::cb::BaseConfigBackendPool< ConfigBackendType >::getPropertyPtrConst().

Here is the call graph for this function:

## ◆ UNSPEC()

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

Returns instance of the "unspecified" backend selector.

Definition at line 74 of file backend_selector.cc.

References BackendSelector().

Referenced by BackendSelector(), BackendSelector(), and BackendSelector().

Here is the call graph for this function:

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

- backend_selector.h
- backend_selector.cc