73 parseInternal(config_storage, config);
74 logConfigStatus(config_storage);
79 }
catch (
const std::exception& ex) {
85 HAConfigParser::parseInternal(
const HAConfigPtr& config_storage,
98 const auto& config_vec = config->listValue();
99 if (config_vec.size() != 1) {
100 isc_throw(ConfigError,
"invalid number of configurations in the HA configuration"
101 " list. Expected exactly one configuration");
109 config_storage->setHAMode(getString(c,
"mode"));
112 if (config_storage->getHAMode() == HAConfig::LOAD_BALANCING) {
113 setDefaults(c, HA_CONFIG_LB_DEFAULTS);
116 setDefaults(c, HA_CONFIG_DEFAULTS);
120 isc_throw(ConfigError,
"expected list of maps in the HA configuration");
124 if (!c->contains(
"peers")) {
125 isc_throw(ConfigError,
"'peers' parameter missing in HA configuration");
131 isc_throw(ConfigError,
"'peers' parameter must be a list");
139 isc_throw(ConfigError,
"'state-machine' parameter must be a map");
142 states_list = state_machine->get(
"states");
143 if (states_list && (states_list->getType() !=
Element::list)) {
144 isc_throw(ConfigError,
"'states' parameter must be a list");
151 config_storage->setThisServerName(getString(c,
"this-server-name"));
154 config_storage->setSendLeaseUpdates(getBoolean(c,
"send-lease-updates"));
157 config_storage->setSyncLeases(getBoolean(c,
"sync-leases"));
160 uint32_t sync_timeout = getAndValidateInteger<uint32_t>(c,
"sync-timeout");
161 config_storage->setSyncTimeout(sync_timeout);
164 uint32_t sync_page_limit = getAndValidateInteger<uint32_t>(c,
"sync-page-limit");
165 config_storage->setSyncPageLimit(sync_page_limit);
168 uint32_t delayed_updates_limit = getAndValidateInteger<uint32_t>(c,
"delayed-updates-limit");
169 config_storage->setDelayedUpdatesLimit(delayed_updates_limit);
172 uint16_t heartbeat_delay = getAndValidateInteger<uint16_t>(c,
"heartbeat-delay");
173 config_storage->setHeartbeatDelay(heartbeat_delay);
176 uint16_t max_response_delay = getAndValidateInteger<uint16_t>(c,
"max-response-delay");
177 config_storage->setMaxResponseDelay(max_response_delay);
180 uint16_t max_ack_delay = getAndValidateInteger<uint16_t>(c,
"max-ack-delay");
181 config_storage->setMaxAckDelay(max_ack_delay);
184 uint32_t max_unacked_clients = getAndValidateInteger<uint32_t>(c,
"max-unacked-clients");
185 config_storage->setMaxUnackedClients(max_unacked_clients);
188 uint32_t max_rejected_lease_updates = getAndValidateInteger<uint32_t>(c,
"max-rejected-lease-updates");
189 config_storage->setMaxRejectedLeaseUpdates(max_rejected_lease_updates);
192 config_storage->setWaitBackupAck(getBoolean(c,
"wait-backup-ack"));
195 ElementPtr mt_config = boost::const_pointer_cast<Element>(c->get(
"multi-threading"));
199 c->set(
"multi-threading", mt_config);
201 isc_throw(ConfigError,
"multi-threading configuration must be a map");
205 setDefaults(mt_config, HA_CONFIG_MT_DEFAULTS);
208 config_storage->setEnableMultiThreading(getBoolean(mt_config,
"enable-multi-threading"));
211 config_storage->setHttpDedicatedListener(getBoolean(mt_config,
"http-dedicated-listener"));
214 uint32_t threads = getAndValidateInteger<uint32_t>(mt_config,
"http-listener-threads");
215 config_storage->setHttpListenerThreads(threads);
218 threads = getAndValidateInteger<uint32_t>(mt_config,
"http-client-threads");
219 config_storage->setHttpClientThreads(threads);
224 config_storage->setTrustAnchor(getString(c,
"trust-anchor"));
230 config_storage->setCertFile(getString(c,
"cert-file"));
236 config_storage->setKeyFile(getString(c,
"key-file"));
240 config_storage->setRequireClientCerts(getBoolean(c,
"require-client-certs"));
243 config_storage->setRestrictCommands(getBoolean(c,
"restrict-commands"));
246 const auto& peers_vec = peers->listValue();
249 for (
auto p = peers_vec.begin(); p != peers_vec.end(); ++p) {
253 isc_throw(ConfigError,
"peer configuration must be a map");
256 setDefaults(*p, HA_CONFIG_PEER_DEFAULTS);
259 auto cfg = config_storage->selectNextPeerConfig(getString(*p,
"name"));
262 cfg->setUrl(
Url(getString((*p),
"url")));
265 if ((*p)->contains(
"trust-anchor")) {
266 cfg->setTrustAnchor(getString(*p, (
"trust-anchor")));
270 if ((*p)->contains(
"cert-file")) {
271 cfg->setCertFile(getString(*p, (
"cert-file")));
275 if ((*p)->contains(
"key-file")) {
276 cfg->setKeyFile(getString(*p, (
"key-file")));
280 cfg->setRole(getString(*p,
"role"));
283 cfg->setAutoFailover(getBoolean(*p,
"auto-failover"));
286 std::string password;
287 if ((*p)->contains(
"basic-auth-password")) {
288 if ((*p)->contains(
"basic-auth-password-file")) {
289 isc_throw(dhcp::DhcpConfigError,
"only one of "
290 <<
"basic-auth-password and "
291 <<
"basic-auth-password-file parameter can be "
292 <<
"configured in peer '"
293 << cfg->getName() <<
"'");
295 password = getString((*p),
"basic-auth-password");
297 if ((*p)->contains(
"basic-auth-password-file")) {
298 std::string password_file =
299 getString((*p),
"basic-auth-password-file");
302 }
catch (
const std::exception& ex) {
303 isc_throw(dhcp::DhcpConfigError,
"bad password file in peer '"
304 << cfg->getName() <<
"': " << ex.what());
309 if ((*p)->contains(
"basic-auth-user")) {
310 std::string user = getString((*p),
"basic-auth-user");
317 }
catch (
const std::exception& ex) {
318 isc_throw(dhcp::DhcpConfigError, ex.what() <<
" in peer '"
319 << cfg->getName() <<
"'");
326 const auto& states_vec = states_list->listValue();
328 std::set<int> configured_states;
331 for (
auto s = states_vec.begin(); s != states_vec.end(); ++s) {
335 isc_throw(ConfigError,
"state configuration must be a map");
338 setDefaults(*s, HA_CONFIG_STATE_DEFAULTS);
341 std::string state_name = getString(*s,
"state");
345 if (configured_states.count(state) > 0) {
346 isc_throw(ConfigError,
"duplicated configuration for the '"
347 << state_name <<
"' state");
349 configured_states.insert(state);
351 config_storage->getStateMachineConfig()->
352 getStateConfig(state)->setPausing(getString(*s,
"pause"));
359 config_storage->validate();
364 const std::string& parameter_name)
const {
365 int64_t value = getInteger(config, parameter_name);
367 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be negative");
369 }
else if (value > std::numeric_limits<T>::max()) {
370 isc_throw(ConfigError,
"'" << parameter_name <<
"' must not be greater than "
371 << +std::numeric_limits<T>::max());
374 return (
static_cast<T
>(value));
378 HAConfigParser::logConfigStatus(
const HAConfigPtr& config_storage)
const {
384 if (!config_storage->amSendingLeaseUpdates()) {
389 if (!config_storage->amSyncingLeases()) {
394 if (config_storage->amSendingLeaseUpdates() !=
395 config_storage->amSyncingLeases()) {
397 .arg(config_storage->amSendingLeaseUpdates() ?
"true" :
"false")
398 .arg(config_storage->amSyncingLeases() ?
"true" :
"false");
408 if (!config_storage->getThisServerConfig()->isAutoFailover()) {
410 .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 ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
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.
string getContent(const string &file_name)
Get the content of a regular file.
Defines the logger used by the top-level component of kea-lfc.