mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-04 16:05:17 +00:00
[master] Tomek's changes + init + deinit fixes
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include <dhcpsrv/parsers/option_data_parser.h>
|
#include <dhcpsrv/parsers/option_data_parser.h>
|
||||||
#include <dhcpsrv/parsers/simple_parser4.h>
|
#include <dhcpsrv/parsers/simple_parser4.h>
|
||||||
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
|
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
|
||||||
|
#include <dhcpsrv/host_data_source_factory.h>
|
||||||
#include <dhcpsrv/timer_mgr.h>
|
#include <dhcpsrv/timer_mgr.h>
|
||||||
#include <hooks/hooks_parser.h>
|
#include <hooks/hooks_parser.h>
|
||||||
#include <config/command_mgr.h>
|
#include <config/command_mgr.h>
|
||||||
@@ -297,6 +298,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set,
|
|||||||
// for option definitions. This is equivalent to committing empty container.
|
// for option definitions. This is equivalent to committing empty container.
|
||||||
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
|
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
|
||||||
|
|
||||||
|
// Print the list of known backends.
|
||||||
|
HostDataSourceFactory::printRegistered();
|
||||||
|
|
||||||
// Answer will hold the result.
|
// Answer will hold the result.
|
||||||
ConstElementPtr answer;
|
ConstElementPtr answer;
|
||||||
// Rollback informs whether error occurred and original data
|
// Rollback informs whether error occurred and original data
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include <dhcpsrv/parsers/option_data_parser.h>
|
#include <dhcpsrv/parsers/option_data_parser.h>
|
||||||
#include <dhcpsrv/parsers/simple_parser6.h>
|
#include <dhcpsrv/parsers/simple_parser6.h>
|
||||||
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
|
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
|
||||||
|
#include <dhcpsrv/host_data_source_factory.h>
|
||||||
#include <hooks/hooks_parser.h>
|
#include <hooks/hooks_parser.h>
|
||||||
#include <log/logger_support.h>
|
#include <log/logger_support.h>
|
||||||
#include <util/encode/hex.h>
|
#include <util/encode/hex.h>
|
||||||
@@ -395,6 +396,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set,
|
|||||||
// for option definitions. This is equivalent to committing empty container.
|
// for option definitions. This is equivalent to committing empty container.
|
||||||
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
|
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
|
||||||
|
|
||||||
|
// Print the list of known backends.
|
||||||
|
HostDataSourceFactory::printRegistered();
|
||||||
|
|
||||||
// This is a way to convert ConstElementPtr to ElementPtr.
|
// This is a way to convert ConstElementPtr to ElementPtr.
|
||||||
// We need a config that can be edited, because we will insert
|
// We need a config that can be edited, because we will insert
|
||||||
// default values and will insert derived values as well.
|
// default values and will insert derived values as well.
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <dhcpsrv/dhcpsrv_log.h>
|
#include <dhcpsrv/dhcpsrv_log.h>
|
||||||
#include <dhcpsrv/host_data_source_factory.h>
|
#include <dhcpsrv/host_data_source_factory.h>
|
||||||
#include <dhcpsrv/hosts_log.h>
|
#include <dhcpsrv/hosts_log.h>
|
||||||
|
#include <log/logger_support.h>
|
||||||
|
|
||||||
#ifdef HAVE_MYSQL
|
#ifdef HAVE_MYSQL
|
||||||
#include <dhcpsrv/mysql_host_data_source.h>
|
#include <dhcpsrv/mysql_host_data_source.h>
|
||||||
@@ -81,7 +82,7 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
|
|||||||
if ((*it)->getType() != db_type) {
|
if ((*it)->getType() != db_type) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
|
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
|
||||||
.arg(db_type);
|
.arg(db_type);
|
||||||
sources.erase(it);
|
sources.erase(it);
|
||||||
return (true);
|
return (true);
|
||||||
@@ -91,33 +92,51 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
HostDataSourceFactory::registerFactory(const string& db_type,
|
HostDataSourceFactory::registerFactory(const string& db_type,
|
||||||
const Factory& factory) {
|
const Factory& factory,
|
||||||
|
bool no_log) {
|
||||||
if (map_.count(db_type)) {
|
if (map_.count(db_type)) {
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
map_.insert(pair<string, Factory>(db_type, factory));
|
map_.insert(pair<string, Factory>(db_type, factory));
|
||||||
// As registerFactory can be called before logging is established
|
|
||||||
// remove temporary this until a better solution is found.
|
// We are dealing here with static logger initialization fiasco.
|
||||||
#if 0
|
// registerFactory may be called from constructors of static global
|
||||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
|
// objects for built in backends. The logging is not initialized yet,
|
||||||
.arg(db_type);
|
// so the LOG_DEBUG would throw.
|
||||||
#endif
|
if (!no_log) {
|
||||||
|
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
|
||||||
|
.arg(db_type);
|
||||||
|
}
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
HostDataSourceFactory::deregisterFactory(const string& db_type) {
|
HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) {
|
||||||
auto index = map_.find(db_type);
|
auto index = map_.find(db_type);
|
||||||
if (index != map_.end()) {
|
if (index != map_.end()) {
|
||||||
map_.erase(index);
|
map_.erase(index);
|
||||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER)
|
if (!no_log) {
|
||||||
.arg(db_type);
|
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE,
|
||||||
|
HOSTS_BACKEND_DEREGISTER)
|
||||||
|
.arg(db_type);
|
||||||
|
}
|
||||||
return (true);
|
return (true);
|
||||||
} else {
|
} else {
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HostDataSourceFactory::printRegistered() {
|
||||||
|
std::stringstream txt;
|
||||||
|
|
||||||
|
for (auto x : map_) {
|
||||||
|
txt << x.first << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dhcp
|
} // namespace dhcp
|
||||||
} // namespace isc
|
} // namespace isc
|
||||||
|
|
||||||
@@ -133,18 +152,18 @@ namespace {
|
|||||||
struct MySqlHostDataSourceInit {
|
struct MySqlHostDataSourceInit {
|
||||||
// Constructor registers
|
// Constructor registers
|
||||||
MySqlHostDataSourceInit() {
|
MySqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::registerFactory("mysql", factory);
|
HostDataSourceFactory::registerFactory("mysql", factory, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor deregisters
|
// Destructor deregisters
|
||||||
~MySqlHostDataSourceInit() {
|
~MySqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::deregisterFactory("mysql");
|
HostDataSourceFactory::deregisterFactory("mysql", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory class method
|
// Factory class method
|
||||||
static HostDataSourcePtr
|
static HostDataSourcePtr
|
||||||
factory(const DatabaseConnection::ParameterMap& parameters) {
|
factory(const DatabaseConnection::ParameterMap& parameters) {
|
||||||
LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB)
|
LOG_INFO(hosts_logger, DHCPSRV_MYSQL_HOST_DB)
|
||||||
.arg(DatabaseConnection::redactedAccessString(parameters));
|
.arg(DatabaseConnection::redactedAccessString(parameters));
|
||||||
return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
|
return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
|
||||||
}
|
}
|
||||||
@@ -158,18 +177,18 @@ MySqlHostDataSourceInit mysql_init_;
|
|||||||
struct PgSqlHostDataSourceInit {
|
struct PgSqlHostDataSourceInit {
|
||||||
// Constructor registers
|
// Constructor registers
|
||||||
PgSqlHostDataSourceInit() {
|
PgSqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::registerFactory("postgresql", factory);
|
HostDataSourceFactory::registerFactory("postgresql", factory, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor deregisters
|
// Destructor deregisters
|
||||||
~PgSqlHostDataSourceInit() {
|
~PgSqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::deregisterFactory("postgresql");
|
HostDataSourceFactory::deregisterFactory("postgresql", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory class method
|
// Factory class method
|
||||||
static HostDataSourcePtr
|
static HostDataSourcePtr
|
||||||
factory(const DatabaseConnection::ParameterMap& parameters) {
|
factory(const DatabaseConnection::ParameterMap& parameters) {
|
||||||
LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_HOST_DB)
|
LOG_INFO(hosts_logger, DHCPSRV_PGSQL_HOST_DB)
|
||||||
.arg(DatabaseConnection::redactedAccessString(parameters));
|
.arg(DatabaseConnection::redactedAccessString(parameters));
|
||||||
return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
|
return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
|
||||||
}
|
}
|
||||||
@@ -183,12 +202,12 @@ PgSqlHostDataSourceInit pgsql_init_;
|
|||||||
struct CqlHostDataSourceInit {
|
struct CqlHostDataSourceInit {
|
||||||
// Constructor registers
|
// Constructor registers
|
||||||
CqlHostDataSourceInit() {
|
CqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::registerFactory("cql", factory);
|
HostDataSourceFactory::registerFactory("cql", factory, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor deregisters
|
// Destructor deregisters
|
||||||
~CqlHostDataSourceInit() {
|
~CqlHostDataSourceInit() {
|
||||||
HostDataSourceFactory::deregisterFactory("cql");
|
HostDataSourceFactory::deregisterFactory("cql", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Factory class method
|
// Factory class method
|
||||||
@@ -205,4 +224,3 @@ CqlHostDataSourceInit cql_init_;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace isc {
|
namespace isc {
|
||||||
@@ -83,22 +84,35 @@ public:
|
|||||||
/// @brief Register a host data source factory
|
/// @brief Register a host data source factory
|
||||||
///
|
///
|
||||||
/// Associate the factory to a database type in the map.
|
/// Associate the factory to a database type in the map.
|
||||||
|
/// The no_log is to avoid logging before the logger is initialized
|
||||||
|
/// as when called at global object initialization.
|
||||||
///
|
///
|
||||||
/// @param db_type database type
|
/// @param db_type database type
|
||||||
/// @param factory host data source factory
|
/// @param factory host data source factory
|
||||||
|
/// @param no_log do not log (default false)
|
||||||
/// @return true if the factory was successfully added to the map, false
|
/// @return true if the factory was successfully added to the map, false
|
||||||
/// if it already exists.
|
/// if it already exists.
|
||||||
static bool registerFactory(const std::string& db_type,
|
static bool registerFactory(const std::string& db_type,
|
||||||
const Factory& factory);
|
const Factory& factory, bool no_log = false);
|
||||||
|
|
||||||
/// @brief Deregister a host data source factory
|
/// @brief Deregister a host data source factory
|
||||||
///
|
///
|
||||||
/// Disassociate the factory to a database type in the map.
|
/// Disassociate the factory to a database type in the map.
|
||||||
|
/// The no_log is to avoid logging during global object deinitialization.
|
||||||
///
|
///
|
||||||
/// @param db_type database type
|
/// @param db_type database type
|
||||||
|
/// @param no_log do not log (default false)
|
||||||
/// @return true if the factory was successfully removed from the map,
|
/// @return true if the factory was successfully removed from the map,
|
||||||
/// false if it was not found.
|
/// false if it was not found.
|
||||||
static bool deregisterFactory(const std::string& db_type);
|
static bool deregisterFactory(const std::string& db_type,
|
||||||
|
bool no_log = false);
|
||||||
|
|
||||||
|
/// @brief Prints out all registered backends.
|
||||||
|
///
|
||||||
|
/// We need a dedicated method for this, because we sometimes can't log
|
||||||
|
/// the backend type when doing early initialization for backends
|
||||||
|
/// initialized statically.
|
||||||
|
static void printRegistered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief Factory map
|
/// @brief Factory map
|
||||||
|
@@ -6,14 +6,18 @@
|
|||||||
|
|
||||||
$NAMESPACE isc::dhcp
|
$NAMESPACE isc::dhcp
|
||||||
|
|
||||||
% HOSTS_BACKEND_DEREGISTER deregistered backend type: %1
|
% HOSTS_BACKEND_DEREGISTER deregistered host backend type: %1
|
||||||
This debug message is issued when a backend factory was deregistered.
|
This debug message is issued when a backend factory was deregistered.
|
||||||
It is no longer possible to use host backend of this type.
|
It is no longer possible to use host backend of this type.
|
||||||
|
|
||||||
% HOSTS_BACKEND_REGISTER registered backend type: %1
|
% HOSTS_BACKEND_REGISTER registered host backend type: %1
|
||||||
This debug message is issued when a backend factory was successfully
|
This debug message is issued when a backend factory was successfully
|
||||||
registered. It is now possible to use host backend of this type.
|
registered. It is now possible to use host backend of this type.
|
||||||
|
|
||||||
|
% HOSTS_BACKENDS_REGISTERED the following host backend types are available: %1
|
||||||
|
This informational message lists all possible host backends that could
|
||||||
|
be used in hosts-database[s].
|
||||||
|
|
||||||
% HOSTS_CFG_ADD_HOST add the host for reservations: %1
|
% HOSTS_CFG_ADD_HOST add the host for reservations: %1
|
||||||
This debug message is issued when new host (with reservations) is added to
|
This debug message is issued when new host (with reservations) is added to
|
||||||
the server's configuration. The argument describes the host and its
|
the server's configuration. The argument describes the host and its
|
||||||
|
Reference in New Issue
Block a user