30 HAConfig::PeerConfig::PeerConfig()
31 : tls_context_(),
name_(), url_(
""), trust_anchor_(), cert_file_(),
32 key_file_(), role_(STANDBY), auto_failover_(false), basic_auth_() {
53 std::ostringstream label;
60 if (role ==
"primary") {
63 }
else if (role ==
"secondary") {
66 }
else if (role ==
"standby") {
69 }
else if (role ==
"backup") {
98 if (!request || !auth) {
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);
178 if (
peers_.count(name) > 0) {
211 if (ha_mode ==
"load-balancing") {
214 }
else if (ha_mode ==
"hot-standby") {
217 }
else if (ha_mode ==
"passive-backup") {
228 return (
"load-balancing");
230 return (
"hot-standby");
232 return (
"passive-backup");
241 auto peer =
peers_.find(name);
242 if (peer ==
peers_.end()) {
246 return (peer->second);
252 for (
auto peer = servers.begin(); peer != servers.end(); ++peer) {
254 return (peer->second);
283 std::map<PeerConfig::Role, unsigned> peers_cnt;
285 if (!p->second->getUrl().isValid()) {
287 << p->second->getUrl().getErrorMessage()
288 <<
" for server " << p->second->getName());
294 addr =
IOAddress(p->second->getUrl().getStrippedHostname());
297 << p->second->getUrl().toText()
298 <<
"': " << ex.
what()
299 <<
" for server " << p->second->getName());
307 if (ca.unspecified()) {
316 bool have_ca = (!ca.unspecified() && !ca.get().empty());
319 bool use_tls = (have_ca || have_cert || have_key);
325 <<
" is missing or empty: all or none of" 326 <<
" TLS parameters must be set");
330 <<
" is missing or empty: all or none of" 331 <<
" TLS parameters must be set");
335 <<
" is missing or empty: all or none of" 336 <<
" TLS parameters must be set");
339 bool cert_required =
true;
345 TlsContext::configure(p->second->tls_context_,
353 << p->second->getName() <<
": " << ex.
what());
357 if (p->second->getUrl().getScheme() == Url::HTTPS) {
359 << p->second->getUrl().toText()
360 <<
"': https scheme is not supported" 361 <<
" for server " << p->second->getName()
362 <<
" where TLS is disabled");
366 ++peers_cnt[p->second->getRole()];
388 "balancing configuration");
394 " balancing configuration");
400 " balancing configuration");
406 " load balancing configuration");
413 " standby configuration");
419 " standby configuration");
425 " standby configuration");
431 " hot standby configuration");
438 " the hot standby configuration");
444 " passive backup configuration");
449 " passive backup configuration");
454 " passive backup configuration");
461 " the passive backup configuration");
467 auto mcfg = CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading();
468 bool dhcp_mt_enabled =
false;
469 uint32_t dhcp_threads = 0;
470 uint32_t dummy_queue_size = 0;
471 CfgMultiThreading::extract(mcfg, dhcp_mt_enabled, dhcp_threads, dummy_queue_size);
474 if (!dhcp_mt_enabled) {
483 dhcp_threads = MultiThreadingMgr::detectThreadCount();
504 if (dhcp_mt_enabled) {
PeerConfigPtr getPeerConfig(const std::string &name) const
Returns configuration of the specified server.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
uint32_t max_unacked_clients_
Maximum number of unacked clients.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
StatePausing
State machine pausing modes.
PeerConfigMap peers_
Map of peers' configurations.
bool getRequireClientCerts() const
Returns require-client-certs.
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.
T get() const
Retrieves the encapsulated value.
PeerConfigPtr getFailoverPeerConfig() const
Returns configuration of the partner which takes part in failover.
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?
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
util::Optional< std::string > trust_anchor_
Trust anchor.
StateMachineConfigPtr state_machine_
State machine configuration.
http::BasicHttpAuthPtr & getBasicAuth()
Returns non-const basic HTTP authentication.
uint32_t sync_page_limit_
Page size limit while synchronizing leases.
uint32_t heartbeat_delay_
Heartbeat delay in milliseconds.
void addBasicAuthHttpHeader(http::PostHttpRequestJsonPtr request) const
Adds a basic HTTP authentication header to a request when credentials are specified.
uint32_t max_ack_delay_
Maximum DHCP message ack delay.
std::string getLogLabel() const
Returns a string identifying a server used in logging.
#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.
std::string getThisServerName() const
Returns name of this server.
uint32_t sync_timeout_
Timeout for syncing lease database (ms)
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED_AND_KEA_MT_ENABLED
bool require_client_certs_
Require client certs flag.
boost::shared_ptr< StateConfig > StateConfigPtr
Pointer to the state configuration.
bool restrict_commands_
Restrict commands to HA flag.
uint32_t max_rejected_lease_updates_
Limit of rejected lease updates before termination.
bool send_lease_updates_
Send lease updates to partner?
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED
std::string toText() const
Returns textual representation of the URL.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
PeerConfigMap getOtherServersConfig() const
Returns configuration of other servers.
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 getThisServerConfig() const
Returns configuration of this server.
PeerConfigPtr selectNextPeerConfig(const std::string &name)
Creates and returns pointer to the new peer's configuration.
std::string getName() const
Returns server name.
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.
TlsRole
Client and server roles.
http::Url getUrl() const
Returns URL of the server's control channel.
static HAMode stringToHAMode(const std::string &ha_mode)
Decodes HA mode provided as string.
HAMode ha_mode_
Mode of operation.
boost::shared_ptr< PeerConfig > PeerConfigPtr
Pointer to the server's configuration.