43 auto configs =
config_->getAll();
44 for (
auto id = 0;
id < configs.size(); ++id) {
46 auto service = boost::make_shared<HAService>(
id, io_service, network_state,
47 configs[
id], server_type);
48 for (
auto peer_config : configs[
id]->getAllServersConfig()) {
49 services_->map(peer_config.first, service);
59 io_service->post([&]() {
60 for (
auto service :
services_->getAll()) {
61 service->startClientAndListener();
67 for (
auto service :
services_->getAll()) {
70 service->stopClientAndListener();
84 if (callout_handle.
getStatus() != CalloutHandle::NEXT_STEP_SKIP) {
95 }
catch (
const std::exception& ex) {
98 .arg(query4->getRemoteAddr().toText())
99 .arg(query4->getLocalAddr().toText())
100 .arg(query4->getIface())
105 static_cast<int64_t
>(1));
107 static_cast<int64_t
>(1));
110 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
115 if (!
services_->get()->inScope(query4)) {
117 .arg(query4->getLabel());
118 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
123 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_SKIP);
132 if (!
config_->get()->amSendingLeaseUpdates()) {
149 callout_handle.
getArgument(
"deleted_leases4", deleted_leases4);
152 if (leases4->empty() && deleted_leases4->empty()) {
154 .arg(query4->getLabel());
164 parking_lot->reference(query4);
171 if (
services_->get()->asyncSendLeaseUpdates(query4, leases4, deleted_leases4, parking_lot) == 0) {
173 parking_lot->dereference(query4);
178 parking_lot->dereference(query4);
185 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_PARK);
191 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
192 size_t peers_to_update = 0;
197 if (!
config_->get()->amSendingLeaseUpdates()) {
200 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
217 peers_to_update =
services_->get()->asyncSendSingleLeaseUpdate(query4, lease4, 0);
218 callout_handle.
setArgument(
"peers_to_update", peers_to_update);
231 if (callout_handle.
getStatus() != CalloutHandle::NEXT_STEP_SKIP) {
242 }
catch (
const std::exception& ex) {
245 .arg(query6->getRemoteAddr().toText())
246 .arg(query6->getLocalAddr().toText())
247 .arg(query6->getIface())
252 static_cast<int64_t
>(1));
254 static_cast<int64_t
>(1));
257 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
262 if (!
services_->get()->inScope(query6)) {
264 .arg(query6->getLabel());
265 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_DROP);
270 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_SKIP);
279 if (!
config_->get()->amSendingLeaseUpdates()) {
296 callout_handle.
getArgument(
"deleted_leases6", deleted_leases6);
299 if (leases6->empty() && deleted_leases6->empty()) {
301 .arg(query6->getLabel());
311 parking_lot->reference(query6);
318 if (
services_->get()->asyncSendLeaseUpdates(query6, leases6, deleted_leases6, parking_lot) == 0) {
320 parking_lot->dereference(query6);
325 parking_lot->dereference(query6);
332 callout_handle.
setStatus(CalloutHandle::NEXT_STEP_PARK);
337 std::string command_name;
339 if (command_name ==
"status-get") {
343 if (!response || (response->getType() != Element::map)) {
348 if (!resp_args || (resp_args->getType() != Element::map)) {
353 boost::const_pointer_cast<Element>(resp_args);
356 auto ha_relationships = Element::createList();
357 for (
auto service :
services_->getAll()) {
358 auto ha_relationship = Element::createMap();
360 ha_relationship->set(
"ha-servers", ha_servers);
362 ha_relationships->add(ha_relationship);
363 mutable_resp_args->set(
"high-availability", ha_relationships);
382 }
catch (
const std::exception& ex) {
406 unsigned int max_period_value = 0;
416 if (args->getType() != Element::map) {
422 server_name = args->get(
"server-name");
428 if (server_name->getType() != Element::string) {
436 if ((max_period->getType() != Element::integer) ||
437 (max_period->intValue() <= 0)) {
438 isc_throw(
BadValue,
"'max-period' must be a positive integer in the 'ha-sync' command");
441 max_period_value =
static_cast<unsigned int>(max_period->intValue());
446 }
catch (
const std::exception& ex) {
455 ConstElementPtr response = service->processSynchronize(server_name->stringValue(),
471 std::vector<std::string> scopes_vector;
479 if (args->getType() != Element::map) {
490 if (scopes->getType() != Element::list) {
496 for (
size_t i = 0; i < scopes->size(); ++i) {
498 if (!scope || scope->getType() != Element::string) {
501 scopes_vector.push_back(scope->stringValue());
506 }
catch (
const std::exception& ex) {
533 }
catch (
const std::exception& ex) {
558 isc_throw(
BadValue,
"'cancel' is mandatory for the 'ha-maintenance-notify' command");
561 if (cancel_op->getType() != Element::boolean) {
562 isc_throw(
BadValue,
"'cancel' must be a boolean in the 'ha-maintenance-notify' command");
567 ConstElementPtr response = service->processMaintenanceNotify(cancel_op->boolValue());
570 }
catch (
const std::exception& ex) {
581 for (
auto service :
services_->getAll()) {
582 response = service->processMaintenanceStart();
595 for (
auto service :
services_->getAll()) {
596 response = service->processMaintenanceCancel();
615 }
catch (
const std::exception& ex) {
638 auto origin_value = NetworkState::HA_REMOTE_COMMAND+1;
641 auto origin = args->get(
"origin");
643 if (origin->getType() != Element::integer) {
644 isc_throw(
BadValue,
"'origin' must be an integer in the 'ha-sync-complete-notify' command");
646 origin_value = origin->intValue();
652 }
catch (
const std::exception& ex) {
660 ConstElementPtr response = service->processSyncCompleteNotify(origin_value);
669 if (args->getType() != Element::map) {
670 isc_throw(
BadValue,
"arguments in the '" << command_name <<
"' command are not a map");
673 auto server_name = args->get(
"server-name");
676 if (server_name->getType() != Element::string) {
677 isc_throw(
BadValue,
"'server-name' must be a string in the '" << command_name <<
"' command");
679 service =
services_->get(server_name->stringValue());
682 <<
" 'server-name'");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown during option unpacking This exception is thrown when an error has occurred,...
static HAConfigMapperPtr parse(const data::ConstElementPtr &config)
Parses HA configuration.
static std::string HAModeToString(const HAMode &ha_mode)
Returns HA mode name.
void scopesHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-scopes command.
void continueHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-continue command.
HAConfigMapperPtr config_
Holds parsed configuration.
void syncCompleteNotifyHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-sync-complete-notify command.
HAServicePtr getHAServiceByServerName(const std::string &command_name, data::ConstElementPtr args) const
Attempts to get an HAService by server name.
HAServiceMapperPtr services_
Pointer to the high availability services (state machines).
void configure(const data::ConstElementPtr &input_config)
Parses configuration.
void maintenanceCancelHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-cancel command.
void haResetHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-reset command.
void maintenanceNotifyHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-notify command.
void synchronizeHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-sync command.
void maintenanceStartHandler(hooks::CalloutHandle &callout_handle)
Implements handler for the ha-maintenance-start command.
void leases4Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases4_committed" callout.
void startServices(const asiolink::IOServicePtr &io_service, const dhcp::NetworkStatePtr &network_state, const HAServerType &server_type)
Creates high availability services using current configuration.
void buffer4Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer4_receive" callout.
void buffer6Receive(hooks::CalloutHandle &callout_handle)
Implementation of the "buffer6_receive" callout.
void commandProcessed(hooks::CalloutHandle &callout_handle)
Implementation of the "command_processed" callout.
void leases6Committed(hooks::CalloutHandle &callout_handle)
Implementation of the "leases6_committed" callout.
void lease4ServerDecline(hooks::CalloutHandle &callout_handle)
Implementation of the "lease4_server_decline" callout.
void heartbeatHandler(hooks::CalloutHandle &callout_handle)
Implements handle for the heartbeat command.
Holds associations between objects and HA relationships.
Per-packet callout handle.
ParkingLotHandlePtr getParkingLotHandlePtr() const
Returns pointer to the parking lot handle for this hook point.
CalloutNextStep getStatus() const
Returns the next processing step.
void setStatus(const CalloutNextStep next)
Sets the next processing step.
void getArgument(const std::string &name, T &value) const
Get argument.
void setArgument(const std::string &name, T value)
Set argument.
static StatsMgr & instance()
Statistics Manager accessor method.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
std::string parseCommandWithArgs(ConstElementPtr &arg, ConstElementPtr command)
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< Lease4Collection > Lease4CollectionPtr
A shared pointer to the collection of IPv4 leases.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< NetworkState > NetworkStatePtr
Pointer to the NetworkState object.
boost::shared_ptr< Lease6Collection > Lease6CollectionPtr
A shared pointer to the collection of IPv6 leases.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
boost::shared_ptr< Lease4 > Lease4Ptr
Pointer to a Lease4 structure.
const isc::log::MessageID HA_BUFFER4_RECEIVE_UNPACK_FAILED
const isc::log::MessageID HA_LEASES6_COMMITTED_NOTHING_TO_UPDATE
const isc::log::MessageID HA_BUFFER4_RECEIVE_PACKET_OPTIONS_SKIPPED
const isc::log::MessageID HA_BUFFER6_RECEIVE_UNPACK_FAILED
isc::log::Logger ha_logger("ha-hooks")
const isc::log::MessageID HA_BUFFER6_RECEIVE_PACKET_OPTIONS_SKIPPED
HAServerType
Lists possible server types for which HA service is created.
const isc::log::MessageID HA_LEASES4_COMMITTED_NOTHING_TO_UPDATE
const isc::log::MessageID HA_BUFFER4_RECEIVE_NOT_FOR_US
const isc::log::MessageID HA_BUFFER6_RECEIVE_NOT_FOR_US
boost::shared_ptr< HAService > HAServicePtr
Pointer to the HAService class.
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
const int DBGLVL_TRACE_BASIC
Trace basic operations.
Defines the logger used by the top-level component of kea-lfc.