30 HAConfig::PeerConfig::PeerConfig()
31 : tls_context_(),
name_(), url_(
""), trust_anchor_(), cert_file_(),
32 key_file_(), role_(STANDBY), auto_failover_(false), basic_auth_() {
48 role_ = stringToRole(role);
53 std::ostringstream label;
54 label << getName() <<
" (" << getUrl().toText() <<
")";
60 if (role ==
"primary") {
63 }
else if (role ==
"secondary") {
66 }
else if (role ==
"standby") {
69 }
else if (role ==
"backup") {
98 if (!request || !auth) {
110 pausing_ = stringToPausing(pausing);
115 if (pausing ==
"always") {
118 }
else if (pausing ==
"never") {
121 }
else if (pausing ==
"once") {
144 isc_throw(
BadValue,
"unsupported pause enumeration " << static_cast<int>(pausing));
150 auto state_config = states_.find(state);
151 if (state_config != states_.end()) {
152 return (state_config->second);
157 states_[state] = new_state_config;
159 return (new_state_config);
177 if (
peers_.count(name) > 0) {
210 if (ha_mode ==
"load-balancing") {
213 }
else if (ha_mode ==
"hot-standby") {
216 }
else if (ha_mode ==
"passive-backup") {
227 return (
"load-balancing");
229 return (
"hot-standby");
231 return (
"passive-backup");
240 auto peer =
peers_.find(name);
241 if (peer ==
peers_.end()) {
245 return (peer->second);
251 for (
auto peer = servers.begin(); peer != servers.end(); ++peer) {
253 return (peer->second);
282 std::map<PeerConfig::Role, unsigned> peers_cnt;
284 if (!p->second->getUrl().isValid()) {
286 << p->second->getUrl().getErrorMessage()
287 <<
" for server " << p->second->getName());
293 addr =
IOAddress(p->second->getUrl().getHostname());
296 << p->second->getUrl().toText()
297 <<
"': " << ex.
what()
298 <<
" for server " << p->second->getName());
318 bool use_tls = (have_ca || have_cert || have_key);
324 <<
" is missing or empty: all or none of"
325 <<
" TLS parameters must be set");
329 <<
" is missing or empty: all or none of"
330 <<
" TLS parameters must be set");
334 <<
" is missing or empty: all or none of"
335 <<
" TLS parameters must be set");
337 TlsContext::configure(p->second->tls_context_,
344 << p->second->getName() <<
": " << ex.
what());
348 if (p->second->getUrl().getScheme() == Url::HTTPS) {
350 << p->second->getUrl().toText()
351 <<
"': https scheme is not supported"
352 <<
" for server " << p->second->getName()
353 <<
" where TLS is disabled");
357 ++peers_cnt[p->second->getRole()];
379 "balancing configuration");
385 " balancing configuration");
391 " balancing configuration");
397 " load balancing configuration");
404 " standby configuration");
410 " standby configuration");
416 " standby configuration");
422 " hot standby configuration");
429 " the hot standby configuration");
435 " passive backup configuration");
440 " passive backup configuration");
445 " passive backup configuration");
452 " the passive backup configuration");
459 auto mcfg = CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading();
460 bool dhcp_mt_enabled =
false;
461 uint32_t dhcp_threads = 0;
462 uint32_t dummy_queue_size = 0;
463 CfgMultiThreading::extract(mcfg, dhcp_mt_enabled, dhcp_threads, dummy_queue_size);
465 if (!dhcp_mt_enabled) {
474 dhcp_threads = MultiThreadingMgr::detectThreadCount();
uint32_t max_unacked_clients_
Maximum number of unacked clients.
Configuration specific to a single HA state.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
StatePausing
State machine pausing modes.
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
std::string getThisServerName() const
Returns name of this server.
PeerConfigMap peers_
Map of peers' configurations.
void setThisServerName(const std::string &this_server_name)
Sets name of this server.
void setName(const std::string &name)
Sets server name.
State machine configuration information.
void setHAMode(const std::string &ha_mode)
Sets new mode of operation.
bool enable_multi_threading_
Enable multi-threading.
void setPausing(const std::string &pausing)
Sets pausing mode for the given state.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
std::map< std::string, PeerConfigPtr > PeerConfigMap
Map of the servers' configurations.
static Role stringToRole(const std::string &role)
Decodes role provided as a string.
std::string this_server_name_
This server name.
util::Optional< std::string > key_file_
Private key file.
StateConfigPtr getStateConfig(const int state)
Returns pointer to the state specific configuration.
StateConfig(const int state)
Constructor.
util::Optional< std::string > cert_file_
Certificate file.
uint32_t max_response_delay_
Max delay in response to heartbeats.
bool sync_leases_
Synchronize databases on startup?
bool http_dedicated_listener_
Enable use of own HTTP listener.
bool wait_backup_ack_
Wait for lease update ack from backup?
util::Optional< std::string > trust_anchor_
Trust anchor.
StateMachineConfigPtr state_machine_
State machine configuration.
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Exception thrown when configuration validation fails.
boost::shared_ptr< PostHttpRequestJson > PostHttpRequestJsonPtr
Pointer to PostHttpRequestJson.
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool send_lease_updates_
Send lease updates to partner?
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
T get() const
Retrieves the encapsulated value.
std::string getLogLabel() const
Returns a string identifying a server used in logging.
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
void setRole(const std::string &role)
Sets servers role.
A generic exception that is thrown if a function is called in a prohibited way.
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
isc::log::Logger ha_logger("ha-hooks")
An exception that is thrown if an error occurs within the IO module.
Role
Server's role in the High Availability setup.
static std::string pausingToString(const util::StatePausing &pausing)
Returns pausing mode in the textual form.
uint32_t delayed_updates_limit_
Maximum number of lease updates held for later send in communication-recovery.
string trim(const string &instring)
Trim Leading and Trailing Spaces.
static std::string roleToString(const HAConfig::PeerConfig::Role &role)
Returns role name.
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
static util::StatePausing stringToPausing(const std::string &pausing)
Converts pausing mode from the textual form.
uint32_t http_listener_threads_
Number of HTTP listener threads.
The IOAddress class represents an IP addresses (version agnostic)
void validate()
Validates configuration.
const isc::log::MessageID HA_CONFIG_SYSTEM_MT_UNSUPPORTED
uint32_t http_client_threads_
Number of HTTP client threads.
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
PeerConfigPtr getThisServerConfig() const
Returns configuration of this server.
HAMode ha_mode_
Mode of operation.
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.