23 {
"delayed-updates-limit", Element::integer,
"100" },
28 {
"delayed-updates-limit", Element::integer,
"0" },
29 {
"heartbeat-delay", Element::integer,
"10000" },
30 {
"max-ack-delay", Element::integer,
"10000" },
31 {
"max-response-delay", Element::integer,
"60000" },
32 {
"max-unacked-clients", Element::integer,
"10" },
33 {
"send-lease-updates", Element::boolean,
"true" },
34 {
"sync-leases", Element::boolean,
"true" },
35 {
"sync-timeout", Element::integer,
"60000" },
36 {
"sync-page-limit", Element::integer,
"10000" },
37 {
"wait-backup-ack", Element::boolean,
"false" }
42 {
"enable-multi-threading", Element::boolean,
"false" },
43 {
"http-client-threads", Element::integer,
"0" },
44 {
"http-dedicated-listener", Element::boolean,
"false" },
45 {
"http-listener-threads", Element::integer,
"0" }
50 {
"auto-failover", Element::boolean,
"true" }
55 {
"pause", Element::string,
"never" }
69 parseInternal(config_storage, config);
70 logConfigStatus(config_storage);
75 }
catch (
const std::exception& ex) {
81HAConfigParser::parseInternal(
const HAConfigPtr& config_storage,
90 if (config->getType() != Element::list) {
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"));
115 if (c->getType() != Element::map) {
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");
126 if (peers->getType() != Element::list) {
127 isc_throw(ConfigError,
"'peers' parameter must be a list");
134 if (state_machine->getType() != Element::map) {
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"));
190 mt_config = Element::createMap();
191 c->set(
"multi-threading", mt_config);
192 }
else if (mt_config->getType() != Element::map) {
193 isc_throw(ConfigError,
"multi-threading configuration must be a map");
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) {
238 if ((*p)->getType() != Element::map) {
239 isc_throw(ConfigError,
"peer configuration must be a map");
245 auto cfg = config_storage->selectNextPeerConfig(
getString(*p,
"name"));
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")));
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) {
303 if ((*s)->getType() != Element::map) {
304 isc_throw(ConfigError,
"state configuration must be a map");
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));
347HAConfigParser::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());
An exception that is thrown if an error occurs while configuring any server.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static std::string getString(isc::data::ConstElementPtr scope, const std::string &name)
Returns a string parameter from a scope.
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
static int64_t getInteger(isc::data::ConstElementPtr scope, const std::string &name)
Returns an integer parameter from a scope.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
void parse(const HAConfigPtr &config_storage, const data::ConstElementPtr &config)
Parses HA configuration.
Represents a basic HTTP authentication.
#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.
boost::shared_ptr< const Element > ConstElementPtr
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
isc::log::Logger ha_logger("ha-hooks")
const isc::log::MessageID HA_CONFIGURATION_SUCCESSFUL
const isc::log::MessageID HA_CONFIG_AUTO_FAILOVER_DISABLED
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
const isc::log::MessageID HA_CONFIG_LEASE_UPDATES_AND_SYNCING_DIFFER
const isc::log::MessageID HA_CONFIG_LEASE_UPDATES_DISABLED
const isc::log::MessageID HA_CONFIG_LEASE_SYNCING_DISABLED
int stringToState(const std::string &state_name)
Returns state for a given name.
boost::shared_ptr< BasicHttpAuth > BasicHttpAuthPtr
Type of pointers to basic HTTP authentication objects.
Defines the logger used by the top-level component of kea-lfc.