36 :
tls_context_(), name_(), url_(
""), trust_anchor_(), cert_file_(),
37 key_file_(), role_(
STANDBY), auto_failover_(false), basic_auth_(),
38 basic_auth_config_() {
59 std::ostringstream label;
66 if (role ==
"primary") {
69 }
else if (role ==
"secondary") {
72 }
else if (role ==
"standby") {
75 }
else if (role ==
"backup") {
104 if (!request || !auth) {
121 if (pausing ==
"always") {
124 }
else if (pausing ==
"never") {
127 }
else if (pausing ==
"once") {
150 isc_throw(
BadValue,
"unsupported pause enumeration " <<
static_cast<int>(pausing));
156 auto state_config = states_.find(state);
157 if (state_config != states_.end()) {
158 return (state_config->second);
163 states_[state] = new_state_config;
165 return (new_state_config);
182 return (boost::make_shared<HAConfig>());
189 if (
peers_.count(name) > 0) {
222 if (ha_mode ==
"load-balancing") {
225 }
else if (ha_mode ==
"hot-standby") {
228 }
else if (ha_mode ==
"passive-backup") {
239 return (
"load-balancing");
241 return (
"hot-standby");
243 return (
"passive-backup");
252 auto peer =
peers_.find(name);
253 if (peer ==
peers_.end()) {
257 return (peer->second);
263 for (
auto const& peer : servers) {
265 return (peer.second);
294 std::map<PeerConfig::Role, unsigned> peers_cnt;
295 for (
auto const& p :
peers_) {
296 if (!p.second->getUrl().isValid()) {
298 << p.second->getUrl().getErrorMessage()
299 <<
" for server " << p.second->getName());
305 addr =
IOAddress(p.second->getUrl().getStrippedHostname());
308 << p.second->getUrl().toText()
309 <<
"': " << ex.
what()
310 <<
" for server " << p.second->getName());
330 bool use_tls = (have_ca || have_cert || have_key);
336 <<
" is missing or empty: all or none of"
337 <<
" TLS parameters must be set");
341 <<
" is missing or empty: all or none of"
342 <<
" TLS parameters must be set");
346 <<
" is missing or empty: all or none of"
347 <<
" TLS parameters must be set");
350 bool cert_required =
true;
356 TlsContext::configure(p.second->tls_context_,
364 << p.second->getName() <<
": " << ex.
what());
368 if (p.second->getUrl().getScheme() ==
Url::HTTPS) {
370 << p.second->getUrl().toText()
371 <<
"': https scheme is not supported"
372 <<
" for server " << p.second->getName()
373 <<
" where TLS is disabled");
377 ++peers_cnt[p.second->getRole()];
399 "balancing configuration");
405 " balancing configuration");
411 " balancing configuration");
417 " load balancing configuration");
424 " standby configuration");
430 " standby configuration");
436 " standby configuration");
442 " hot standby configuration");
449 " the hot standby configuration");
455 " passive backup configuration");
460 " passive backup configuration");
465 " passive backup configuration");
472 " the passive backup configuration");
479 bool dhcp_mt_enabled =
false;
480 uint32_t dhcp_threads = 0;
481 uint32_t dummy_queue_size = 0;
485 if (!dhcp_mt_enabled) {
517 if (dhcp_mt_enabled) {
528 const std::string parameter_name =
"ha-server-name";
529 auto context = subnet->getContext();
530 if (!context || (context->getType() !=
Element::map) || !context->contains(parameter_name)) {
532 subnet->getSharedNetwork(shared_network);
533 if (shared_network) {
534 context = shared_network->getContext();
537 if (context && (context->getType() ==
Element::map) && context->contains(parameter_name)) {
538 auto server_name_element = context->get(parameter_name);
539 if ((server_name_element->getType() !=
Element::string) || server_name_element->stringValue().empty()) {
542 return (server_name_element->stringValue());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
The IOAddress class represents an IP addresses (version agnostic).
An exception that is thrown if an error occurs within the IO module.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
static void extract(data::ConstElementPtr value, bool &enabled, uint32_t &thread_count, uint32_t &queue_size)
Extract multi-threading parameters from a given configuration.
Exception thrown when configuration validation fails.
std::string getLogLabel() const
Returns a string identifying a server used in logging.
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
asiolink::TlsContextPtr tls_context_
Server TLS context.
void setRole(const std::string &role)
Sets servers role.
std::string getName() const
Returns server name.
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
Role
Server's role in the High Availability setup.
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
void setName(const std::string &name)
Sets server name.
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
http::Url getUrl() const
Returns URL of the server's control channel.
Configuration specific to a single HA state.
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
StateConfig(const int state)
Constructor.
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
State machine configuration information.
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
uint32_t max_response_delay_
Max delay in response to heartbeats.
uint32_t http_listener_threads_
Number of HTTP listener threads.
static HAConfigPtr create()
Instantiates a HAConfig.
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
std::string getThisServerName() const
Returns name of this server.
bool require_client_certs_
Require client certs flag.
bool http_dedicated_listener_
Enable use of own HTTP listener.
void validate()
Validates configuration.
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
bool getRequireClientCerts() const
Returns require-client-certs.
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
HAMode ha_mode_
Mode of operation.
bool send_lease_updates_
Send lease updates to partner?
uint32_t max_unacked_clients_
Maximum number of unacked clients.
PeerConfigMap peers_
Map of peers' configurations.
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
util::Optional< std::string > cert_file_
Certificate file.
bool restrict_commands_
Restrict commands to HA flag.
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
util::Optional< std::string > key_file_
Private key file.
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
bool sync_leases_
Synchronize databases on startup?
bool wait_backup_ack_
Wait for lease update ack from backup?
StateMachineConfigPtr state_machine_
State machine configuration.
util::Optional< std::string > trust_anchor_
Trust anchor.
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
uint32_t http_client_threads_
Number of HTTP client threads.
uint32_t sync_timeout_
Timeout for syncing lease database (ms).
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
bool enable_multi_threading_
Enable multi-threading.
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
static std::string getSubnetServerName(const dhcp::ConstSubnetPtr &subnet)
Convenience function extracting a value of the ha-server-name parameter from a subnet context.
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
std::string this_server_name_
This server name.
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.
static uint32_t detectThreadCount()
The system current detected hardware concurrency thread count.
A template representing an optional value.
T get() const
Retrieves the encapsulated value.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
TlsRole
Client and server roles.
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
boost::shared_ptr< const Subnet > ConstSubnetPtr
A generic pointer to either const Subnet4 or const Subnet6 object.
boost::shared_ptr< Network > NetworkPtr
Pointer to the Network object.
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED
isc::log::Logger ha_logger("ha-hooks")
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED_AND_KEA_MT_ENABLED
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
const isc::log::MessageID HA_CONFIG_SYSTEM_MT_UNSUPPORTED
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
string trim(const string &input)
Trim leading and trailing spaces.
StatePausing
State machine pausing modes.
Defines the logger used by the top-level component of kea-lfc.