34 :
tls_context_(), name_(), url_(
""), trust_anchor_(), cert_file_(),
35 key_file_(), role_(
STANDBY), auto_failover_(false), basic_auth_(),
36 basic_auth_config_() {
57 std::ostringstream label;
64 if (role ==
"primary") {
67 }
else if (role ==
"secondary") {
70 }
else if (role ==
"standby") {
73 }
else if (role ==
"backup") {
102 if (!request || !auth) {
119 if (pausing ==
"always") {
122 }
else if (pausing ==
"never") {
125 }
else if (pausing ==
"once") {
148 isc_throw(
BadValue,
"unsupported pause enumeration " <<
static_cast<int>(pausing));
154 auto state_config = states_.find(state);
155 if (state_config != states_.end()) {
156 return (state_config->second);
161 states_[state] = new_state_config;
163 return (new_state_config);
180 return (boost::make_shared<HAConfig>());
187 if (
peers_.count(name) > 0) {
220 if (ha_mode ==
"load-balancing") {
223 }
else if (ha_mode ==
"hot-standby") {
226 }
else if (ha_mode ==
"passive-backup") {
237 return (
"load-balancing");
239 return (
"hot-standby");
241 return (
"passive-backup");
250 auto peer =
peers_.find(name);
251 if (peer ==
peers_.end()) {
255 return (peer->second);
261 for (
auto const& peer : servers) {
263 return (peer.second);
292 std::map<PeerConfig::Role, unsigned> peers_cnt;
293 for (
auto const& p :
peers_) {
294 if (!p.second->getUrl().isValid()) {
296 << p.second->getUrl().getErrorMessage()
297 <<
" for server " << p.second->getName());
303 addr =
IOAddress(p.second->getUrl().getStrippedHostname());
306 << p.second->getUrl().toText()
307 <<
"': " << ex.
what()
308 <<
" for server " << p.second->getName());
328 bool use_tls = (have_ca || have_cert || have_key);
334 <<
" is missing or empty: all or none of"
335 <<
" TLS parameters must be set");
339 <<
" is missing or empty: all or none of"
340 <<
" TLS parameters must be set");
344 <<
" is missing or empty: all or none of"
345 <<
" TLS parameters must be set");
348 bool cert_required =
true;
354 TlsContext::configure(p.second->tls_context_,
362 << p.second->getName() <<
": " << ex.
what());
366 if (p.second->getUrl().getScheme() ==
Url::HTTPS) {
368 << p.second->getUrl().toText()
369 <<
"': https scheme is not supported"
370 <<
" for server " << p.second->getName()
371 <<
" where TLS is disabled");
375 ++peers_cnt[p.second->getRole()];
397 "balancing configuration");
403 " balancing configuration");
409 " balancing configuration");
415 " load balancing configuration");
422 " standby configuration");
428 " standby configuration");
434 " standby configuration");
440 " hot standby configuration");
447 " the hot standby configuration");
453 " passive backup configuration");
458 " passive backup configuration");
463 " passive backup configuration");
470 " the passive backup configuration");
477 bool dhcp_mt_enabled =
false;
478 uint32_t dhcp_threads = 0;
479 uint32_t dummy_queue_size = 0;
483 if (!dhcp_mt_enabled) {
515 if (dhcp_mt_enabled) {
526 const std::string parameter_name =
"ha-server-name";
527 auto context = subnet->getContext();
528 if (!context || (context->getType() !=
Element::map) || !context->contains(parameter_name)) {
530 subnet->getSharedNetwork(shared_network);
531 if (shared_network) {
532 context = shared_network->getContext();
535 if (context && (context->getType() ==
Element::map) && context->contains(parameter_name)) {
536 auto server_name_element = context->get(parameter_name);
537 if ((server_name_element->getType() !=
Element::string) || server_name_element->stringValue().empty()) {
540 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.
Role
Server's role in the High Availability setup.
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.
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.