69 parseInternal(config_storage, config);
70 logConfigStatus(config_storage);
75 }
catch (
const std::exception& ex) {
81 HAConfigParser::parseInternal(
const HAConfigPtr& config_storage,
94 const auto& config_vec = config->listValue();
95 if (config_vec.size() != 1) {
96 isc_throw(ConfigError,
"invalid number of configurations in the HA configuration"
97 " list. Expected exactly one configuration");
105 config_storage->setHAMode(getString(c,
"mode"));
108 if (config_storage->getHAMode() == HAConfig::LOAD_BALANCING) {
109 setDefaults(c, HA_CONFIG_LB_DEFAULTS);
112 setDefaults(c, HA_CONFIG_DEFAULTS);
116 isc_throw(ConfigError,
"expected list of maps in the HA configuration");
120 if (!c->contains(
"peers")) {
121 isc_throw(ConfigError,
"'peers' parameter missing in HA configuration");
127 isc_throw(ConfigError,
"'peers' parameter must be a list");
135 isc_throw(ConfigError,
"'state-machine' parameter must be a map");
138 states_list = state_machine->get(
"states");
139 if (states_list && (states_list->getType() !=
Element::list)) {
140 isc_throw(ConfigError,
"'states' parameter must be a list");
147 config_storage->setThisServerName(getString(c,
"this-server-name"));
150 config_storage->setSendLeaseUpdates(getBoolean(c,
"send-lease-updates"));
153 config_storage->setSyncLeases(getBoolean(c,
"sync-leases"));
156 uint32_t sync_timeout = getAndValidateInteger<uint32_t>(c,
"sync-timeout");
157 config_storage->setSyncTimeout(sync_timeout);
160 uint32_t sync_page_limit = getAndValidateInteger<uint32_t>(c,
"sync-page-limit");
161 config_storage->setSyncPageLimit(sync_page_limit);
164 uint32_t delayed_updates_limit = getAndValidateInteger<uint32_t>(c,
"delayed-updates-limit");
165 config_storage->setDelayedUpdatesLimit(delayed_updates_limit);
168 uint16_t heartbeat_delay = getAndValidateInteger<uint16_t>(c,
"heartbeat-delay");
169 config_storage->setHeartbeatDelay(heartbeat_delay);
172 uint16_t max_response_delay = getAndValidateInteger<uint16_t>(c,
"max-response-delay");
173 config_storage->setMaxResponseDelay(max_response_delay);
176 uint16_t max_ack_delay = getAndValidateInteger<uint16_t>(c,
"max-ack-delay");
177 config_storage->setMaxAckDelay(max_ack_delay);
180 uint32_t max_unacked_clients = getAndValidateInteger<uint32_t>(c,
"max-unacked-clients");
181 config_storage->setMaxUnackedClients(max_unacked_clients);
184 config_storage->setWaitBackupAck(getBoolean(c,
"wait-backup-ack"));
187 ElementPtr mt_config = boost::const_pointer_cast<
Element>(c->get(
"multi-threading"));
191 c->set(
"multi-threading", mt_config);
193 isc_throw(ConfigError,
"multi-threading configuration must be a map");
197 setDefaults(mt_config, HA_CONFIG_MT_DEFAULTS);
200 config_storage->setEnableMultiThreading(getBoolean(mt_config,
"enable-multi-threading"));
203 config_storage->setHttpDedicatedListener(getBoolean(mt_config,
"http-dedicated-listener"));
206 uint32_t threads = getAndValidateInteger<uint32_t>(mt_config,
"http-listener-threads");
207 config_storage->setHttpListenerThreads(threads);
210 threads = getAndValidateInteger<uint32_t>(mt_config,
"http-client-threads");
211 config_storage->setHttpClientThreads(threads);
216 config_storage->setTrustAnchor(getString(c, (
"trust-anchor")));
222 config_storage->setCertFile(getString(c, (
"cert-file")));
228 config_storage->setKeyFile(getString(c, (
"key-file")));
232 const auto& peers_vec = peers->listValue();
235 for (
auto p = peers_vec.begin(); p != peers_vec.end(); ++p) {
239 isc_throw(ConfigError,
"peer configuration must be a map");
242 setDefaults(*p, HA_CONFIG_PEER_DEFAULTS);
245 auto cfg = config_storage->selectNextPeerConfig(getString(*p,
"name"));
248 cfg->setUrl(
Url(getString((*p),
"url")));
251 if ((*p)->contains(
"trust-anchor")) {
252 cfg->setTrustAnchor(getString(*p, (
"trust-anchor")));
256 if ((*p)->contains(
"cert-file")) {
257 cfg->setCertFile(getString(*p, (
"cert-file")));
261 if ((*p)->contains(
"key-file")) {
262 cfg->setKeyFile(getString(*p, (
"key-file")));
266 cfg->setRole(getString(*p,
"role"));
269 cfg->setAutoFailover(getBoolean(*p,
"auto-failover"));
272 std::string password;
273 if ((*p)->contains(
"basic-auth-password")) {
274 password = getString((*p),
"basic-auth-password");
278 if ((*p)->contains(
"basic-auth-user")) {
279 std::string user = getString((*p),
"basic-auth-user");
286 }
catch (
const std::exception& ex) {
287 isc_throw(dhcp::DhcpConfigError, ex.what() <<
" in peer '"
288 << cfg->getName() <<
"'");
295 const auto& states_vec = states_list->listValue();
297 std::set<int> configured_states;
300 for (
auto s = states_vec.begin(); s != states_vec.end(); ++s) {
304 isc_throw(ConfigError,
"state configuration must be a map");
307 setDefaults(*s, HA_CONFIG_STATE_DEFAULTS);
310 std::string state_name = getString(*s,
"state");
314 if (configured_states.count(state) > 0) {
315 isc_throw(ConfigError,
"duplicated configuration for the '"
316 << state_name <<
"' state");
318 configured_states.insert(state);
320 config_storage->getStateMachineConfig()->
321 getStateConfig(state)->setPausing(getString(*s,
"pause"));
328 config_storage->validate();
333 const std::string& parameter_name)
const {
334 int64_t value = getInteger(config, parameter_name);
336 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be negative");
338 }
else if (value > std::numeric_limits<T>::max()) {
339 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be greater than "
340 << +std::numeric_limits<T>::max());
343 return (static_cast<T>(value));
347 HAConfigParser::logConfigStatus(
const HAConfigPtr& config_storage)
const {
353 if (!config_storage->amSendingLeaseUpdates()) {
358 if (!config_storage->amSyncingLeases()) {
363 if (config_storage->amSendingLeaseUpdates() !=
364 config_storage->amSyncingLeases()) {
366 .arg(config_storage->amSendingLeaseUpdates() ?
"true" :
"false")
367 .arg(config_storage->amSyncingLeases() ?
"true" :
"false");
377 if (!config_storage->getThisServerConfig()->isAutoFailover()) {
379 .arg(config_storage->getThisServerName());
int stringToState(const std::string &state_name)
Returns state for a given name.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID HA_CONFIG_LEASE_SYNCING_DISABLED
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
Represents a basic HTTP authentication.
const isc::log::MessageID HA_CONFIG_AUTO_FAILOVER_DISABLED
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID HA_CONFIG_LEASE_UPDATES_DISABLED
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
An exception that is thrown if an error occurs while configuring any server.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Defines the logger used by the top-level component of kea-dhcp-ddns.
The Element class represents a piece of data, used by the command channel and configuration parts...
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
isc::log::Logger ha_logger("ha-hooks")
const isc::log::MessageID HA_CONFIG_LEASE_UPDATES_AND_SYNCING_DIFFER
const isc::log::MessageID HA_CONFIGURATION_SUCCESSFUL
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.