12#include <cc/command_interpreter.h>
13#include <hooks/hooks.h>
14#include <log/macros.h>
21#include "log_admindb_host_reservation_importer.h"
27std::unique_ptr<ahri::Config>
config{
nullptr};
34constexpr const char* DEFAULT_CONFIG_FILE_LOCATION{
"/etc/admindb-host-reservation-importer.conf"};
37std::unique_ptr<ahri::AdminDBClient> admindb{
nullptr};
38std::unique_ptr<ahri::LocalDBClient> localdb{
nullptr};
43void update_dhcp_incrementally();
44int full_sync_command_hdl(isc::hooks::CalloutHandle& hdl);
51int load(isc::hooks::LibraryHandle& hdl)
53 std::string config_path = DEFAULT_CONFIG_FILE_LOCATION;
55 auto raw_config_path = hdl.getParameter(
"config");
57 if (raw_config_path) {
58 config_path = raw_config_path->stringValue();
61 catch (isc::data::TypeError& e) {
66 std::ifstream config_file{config_path};
67 if (config_file.bad()) {
69 .arg(
"Failed to load configuration file ");
86 hdl.registerCommandCallout(
"ahri-full-sync", full_sync_command_hdl);
92 catch (
const std::exception& e) {
102 catch (
const std::exception& e) {
114 catch (
const std::exception& e) {
122 admindb->handle_notifications(update_dhcp_incrementally);
124 catch (
const std::exception& e) {
140 admindb.reset(
nullptr);
143 localdb.reset(
nullptr);
153 return std::make_unique<ahri::LocalDBClient>(
160 assert(!
config.admindb().servers.empty());
161 return std::make_unique<ahri::AdminDBClient>(
162 config.admindb().servers.at(0).host,
config.admindb().servers.at(0).port,
166void update_dhcp_incrementally()
170 const std::vector<ahri::AdminDBClient::HostUpdate> updates =
171 admindb->fetch_pending_host_updates();
172 localdb->apply_host_updates(updates);
174 catch (pqxx::sql_error& e) {
183int full_sync_command_hdl(isc::hooks::CalloutHandle& hdl)
185 isc::data::ConstElementPtr response;
187 const size_t full_sync_diff = full_sync();
188 response = isc::config::createAnswer(
189 isc::config::CONTROL_RESULT_SUCCESS,
190 isc::data::Element::create(
static_cast<long long int>(full_sync_diff)));
192 catch (std::exception& e) {
193 response = isc::config::createAnswer(isc::config::CONTROL_RESULT_ERROR,
194 "Exception during command execution");
197 hdl.setArgument(
"response", response);
204 const std::vector<ahri::AdminDBClient::HostUpdate> full_sync =
205 admindb->fetch_all_host_reservations();
207 const std::vector<ahri::AdminDBClient::HostUpdate> table_diff =
208 localdb->compare_full_sync(full_sync);
210 localdb->apply_host_updates(table_diff);
212 return table_diff.size();
int unload()
Unitialization/cleanup point for admindb-arpwatch-exporter.
int load(isc::hooks::LibraryHandle &handle)
Initialization/starting point for admindb-arpwatch-exporter.
Declarations for all ahri-related Kea callout handlers.
Exception for errors during configuration parsing.
Configuration parser for admindb-host-reservation-importer configuration.
Collection of common variables used throughout the library.
Library-global variables.
std::unique_ptr< ahri::Config > config
isc::asiolink::IOServicePtr io_context