34 : tls_context_(),
name_(), url_(
""), trust_anchor_(), cert_file_(),
35 key_file_(), role_(STANDBY), auto_failover_(false), basic_auth_() {
51 role_ = stringToRole(role);
56 std::ostringstream label;
57 label << getName() <<
" (" << getUrl().toText() <<
")";
63 if (role ==
"primary") {
66 }
else if (role ==
"secondary") {
69 }
else if (role ==
"standby") {
72 }
else if (role ==
"backup") {
101 if (!request || !auth) {
113 pausing_ = stringToPausing(pausing);
118 if (pausing ==
"always") {
121 }
else if (pausing ==
"never") {
124 }
else if (pausing ==
"once") {
147 isc_throw(
BadValue,
"unsupported pause enumeration " <<
static_cast<int>(pausing));
153 auto state_config = states_.find(state);
154 if (state_config != states_.end()) {
155 return (state_config->second);
160 states_[state] = new_state_config;
162 return (new_state_config);
179 return (boost::make_shared<HAConfig>());
186 if (
peers_.count(name) > 0) {
219 if (ha_mode ==
"load-balancing") {
222 }
else if (ha_mode ==
"hot-standby") {
225 }
else if (ha_mode ==
"passive-backup") {
236 return (
"load-balancing");
238 return (
"hot-standby");
240 return (
"passive-backup");
249 auto peer =
peers_.find(name);
250 if (peer ==
peers_.end()) {
254 return (peer->second);
260 for (
auto const& peer : servers) {
262 return (peer.second);
291 std::map<PeerConfig::Role, unsigned> peers_cnt;
292 for (
auto const& p :
peers_) {
293 if (!p.second->getUrl().isValid()) {
295 << p.second->getUrl().getErrorMessage()
296 <<
" for server " << p.second->getName());
302 addr =
IOAddress(p.second->getUrl().getStrippedHostname());
305 << p.second->getUrl().toText()
306 <<
"': " << ex.
what()
307 <<
" for server " << p.second->getName());
311 Optional<std::string> ca = p.second->getTrustAnchor();
312 Optional<std::string> cert = p.second->getCertFile();
313 Optional<std::string> key = p.second->getKeyFile();
315 if (ca.unspecified()) {
318 if (cert.unspecified()) {
321 if (key.unspecified()) {
324 bool have_ca = (!ca.unspecified() && !ca.get().empty());
325 bool have_cert = (!cert.unspecified() && !cert.get().empty());
326 bool have_key = (!key.unspecified() && !key.get().empty());
327 bool use_tls = (have_ca || have_cert || have_key);
333 <<
" is missing or empty: all or none of"
334 <<
" TLS parameters must be set");
338 <<
" is missing or empty: all or none of"
339 <<
" TLS parameters must be set");
343 <<
" is missing or empty: all or none of"
344 <<
" TLS parameters must be set");
346 TlsRole tls_role = TlsRole::CLIENT;
347 bool cert_required =
true;
350 tls_role = TlsRole::SERVER;
353 TlsContext::configure(p.second->tls_context_,
361 << p.second->getName() <<
": " << ex.
what());
365 if (p.second->getUrl().getScheme() ==
Url::HTTPS) {
367 << p.second->getUrl().toText()
368 <<
"': https scheme is not supported"
369 <<
" for server " << p.second->getName()
370 <<
" where TLS is disabled");
374 ++peers_cnt[p.second->getRole()];
396 "balancing configuration");
402 " balancing configuration");
408 " balancing configuration");
414 " load balancing configuration");
421 " standby configuration");
427 " standby configuration");
433 " standby configuration");
439 " hot standby configuration");
446 " the hot standby configuration");
452 " passive backup configuration");
457 " passive backup configuration");
462 " passive backup configuration");
469 " the passive backup configuration");
476 bool dhcp_mt_enabled =
false;
477 uint32_t dhcp_threads = 0;
478 uint32_t dummy_queue_size = 0;
482 if (!dhcp_mt_enabled) {
514 if (dhcp_mt_enabled) {
525 const std::string parameter_name =
"ha-server-name";
526 auto context = subnet->getContext();
527 if (!context || (context->getType() !=
Element::map) || !context->contains(parameter_name)) {
529 subnet->getSharedNetwork(shared_network);
530 if (shared_network) {
531 context = shared_network->getContext();
534 if (context && (context->getType() ==
Element::map) && context->contains(parameter_name)) {
535 auto server_name_element = context->get(parameter_name);
536 if ((server_name_element->getType() !=
Element::string) || server_name_element->stringValue().empty()) {
539 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
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.
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.
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.
#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, int 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.