54 parseInternal(config_storage, config);
55 logConfigStatus(config_storage);
60 }
catch (
const std::exception& ex) {
66HAConfigParser::parseInternal(
const HAConfigPtr& config_storage,
79 const auto& config_vec = config->listValue();
80 if (config_vec.size() != 1) {
82 " list. Expected exactly one configuration");
97 if (!c->contains(
"peers")) {
115 states_list = state_machine->get(
"states");
116 if (states_list && (states_list->getType() !=
Element::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) {
170 for (
auto p = peers_vec.begin(); p != peers_vec.end(); ++p) {
180 auto cfg = config_storage->selectNextPeerConfig(
getString(*p,
"name"));
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) {
209 std::string state_name =
getString(*s,
"state");
213 if (configured_states.count(state) > 0) {
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);
237 }
else if (value > std::numeric_limits<T>::max()) {
239 << std::numeric_limits<T>::max());
242 return (
static_cast<T
>(value));
246HAConfigParser::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());
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.
#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")
boost::shared_ptr< HAConfig > HAConfigPtr
Pointer to the High Availability configuration structure.
int stringToState(const std::string &state_name)
Returns state for a given name.
Defines the logger used by the top-level component of kea-dhcp-ddns.