54 parseInternal(config_storage, config);
55 logConfigStatus(config_storage);
60 }
catch (
const std::exception& ex) {
66 HAConfigParser::parseInternal(
const HAConfigPtr& config_storage,
79 const auto& config_vec = config->listValue();
80 if (config_vec.size() != 1) {
81 isc_throw(ConfigError,
"invalid number of configurations in the HA configuration"
82 " list. Expected exactly one configuration");
89 setDefaults(c, HA_CONFIG_DEFAULTS);
93 isc_throw(ConfigError,
"expected list of maps in the HA configuration");
97 if (!c->contains(
"peers")) {
98 isc_throw(ConfigError,
"'peers' parameter missing in HA configuration");
104 isc_throw(ConfigError,
"'peers' parameter must be a list");
112 isc_throw(ConfigError,
"'state-machine' parameter must be a map");
115 states_list = state_machine->get(
"states");
116 if (states_list && (states_list->getType() !=
Element::list)) {
117 isc_throw(ConfigError,
"'states' parameter must be a list");
125 config_storage->setThisServerName(getString(c,
"this-server-name"));
128 config_storage->setHAMode(getString(c,
"mode"));
131 config_storage->setSendLeaseUpdates(getBoolean(c,
"send-lease-updates"));
134 config_storage->setSyncLeases(getBoolean(c,
"sync-leases"));
137 uint32_t sync_timeout = getAndValidateInteger<uint32_t>(c,
"sync-timeout");
138 config_storage->setSyncTimeout(sync_timeout);
141 uint32_t sync_page_limit = getAndValidateInteger<uint32_t>(c,
"sync-page-limit");
142 config_storage->setSyncPageLimit(sync_page_limit);
145 uint16_t heartbeat_delay = getAndValidateInteger<uint16_t>(c,
"heartbeat-delay");
146 config_storage->setHeartbeatDelay(heartbeat_delay);
149 uint16_t max_response_delay = getAndValidateInteger<uint16_t>(c,
"max-response-delay");
150 config_storage->setMaxResponseDelay(max_response_delay);
153 uint16_t max_ack_delay = getAndValidateInteger<uint16_t>(c,
"max-ack-delay");
154 config_storage->setMaxAckDelay(max_ack_delay);
157 uint32_t max_unacked_clients = getAndValidateInteger<uint32_t>(c,
"max-unacked-clients");
158 config_storage->setMaxUnackedClients(max_unacked_clients);
161 const auto& peers_vec = peers->listValue();
164 if (peers_vec.size() < 2) {
165 isc_throw(ConfigError,
"peers configuration requires at least two peers"
170 for (
auto p = peers_vec.begin(); p != peers_vec.end(); ++p) {
174 isc_throw(ConfigError,
"peer configuration must be a map");
177 setDefaults(*p, HA_CONFIG_PEER_DEFAULTS);
180 auto cfg = config_storage->selectNextPeerConfig(getString(*p,
"name"));
183 cfg->setUrl(
Url(getString((*p),
"url")));
186 cfg->setRole(getString(*p,
"role"));
189 cfg->setAutoFailover(getBoolean(*p,
"auto-failover"));
194 const auto& states_vec = states_list->listValue();
196 std::set<int> configured_states;
199 for (
auto s = states_vec.begin(); s != states_vec.end(); ++s) {
203 isc_throw(ConfigError,
"state configuration must be a map");
206 setDefaults(*s, HA_CONFIG_STATE_DEFAULTS);
209 std::string state_name = getString(*s,
"state");
213 if (configured_states.count(state) > 0) {
214 isc_throw(ConfigError,
"duplicated configuration for the '"
215 << state_name <<
"' state");
217 configured_states.insert(state);
219 config_storage->getStateMachineConfig()->
220 getStateConfig(state)->setPausing(getString(*s,
"pause"));
227 config_storage->validate();
232 const std::string& parameter_name)
const {
233 int64_t value = getInteger(config, parameter_name);
235 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be negative");
237 }
else if (value > std::numeric_limits<T>::max()) {
238 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be greater than "
239 << std::numeric_limits<T>::max());
242 return (
static_cast<T
>(value));
246 HAConfigParser::logConfigStatus(
const HAConfigPtr& config_storage)
const {
252 if (!config_storage->amSendingLeaseUpdates()) {
257 if (!config_storage->amSyncingLeases()) {
262 if (config_storage->amSendingLeaseUpdates() !=
263 config_storage->amSyncingLeases()) {
265 .arg(config_storage->amSendingLeaseUpdates() ?
"true" :
"false")
266 .arg(config_storage->amSyncingLeases() ?
"true" :
"false");
276 if (!config_storage->getThisServerConfig()->isAutoFailover()) {
278 .arg(config_storage->getThisServerName());