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);
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());
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");
338 TlsRole tls_role = TlsRole::CLIENT;
339 bool cert_required =
true;
342 tls_role = TlsRole::SERVER;
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");
469 bool dhcp_mt_enabled =
false;
470 uint32_t dhcp_threads = 0;
471 uint32_t dummy_queue_size = 0;
474 if (!dhcp_mt_enabled) {
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
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.
Role
Server's role in the High Availability setup.
void setRole(const std::string &role)
Sets servers role.
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.
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.
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.
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 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.
TlsRole
Client and server roles.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
const isc::log::MessageID HA_CONFIG_DHCP_MT_DISABLED
isc::log::Logger ha_logger("ha-hooks")
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 &instring)
Trim Leading and Trailing Spaces.
StatePausing
State machine pausing modes.
Defines the logger used by the top-level component of kea-lfc.