2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-04 07:55:18 +00:00

[master] Tomek's changes + init + deinit fixes

This commit is contained in:
Francis Dupont
2018-03-27 19:22:45 +02:00
parent 8ed5619ca3
commit 4e05c4fa66
5 changed files with 68 additions and 24 deletions

View File

@@ -24,6 +24,7 @@
#include <dhcpsrv/parsers/option_data_parser.h>
#include <dhcpsrv/parsers/simple_parser4.h>
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/timer_mgr.h>
#include <hooks/hooks_parser.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.
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
// Print the list of known backends.
HostDataSourceFactory::printRegistered();
// Answer will hold the result.
ConstElementPtr answer;
// Rollback informs whether error occurred and original data

View File

@@ -32,6 +32,7 @@
#include <dhcpsrv/parsers/option_data_parser.h>
#include <dhcpsrv/parsers/simple_parser6.h>
#include <dhcpsrv/parsers/shared_networks_list_parser.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <hooks/hooks_parser.h>
#include <log/logger_support.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.
LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer());
// Print the list of known backends.
HostDataSourceFactory::printRegistered();
// This is a way to convert ConstElementPtr to ElementPtr.
// We need a config that can be edited, because we will insert
// default values and will insert derived values as well.

View File

@@ -9,6 +9,7 @@
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/hosts_log.h>
#include <log/logger_support.h>
#ifdef HAVE_MYSQL
#include <dhcpsrv/mysql_host_data_source.h>
@@ -81,7 +82,7 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
if ((*it)->getType() != db_type) {
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);
sources.erase(it);
return (true);
@@ -91,33 +92,51 @@ HostDataSourceFactory::del(HostDataSourceList& sources,
bool
HostDataSourceFactory::registerFactory(const string& db_type,
const Factory& factory) {
const Factory& factory,
bool no_log) {
if (map_.count(db_type)) {
return (false);
}
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.
#if 0
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
.arg(db_type);
#endif
// We are dealing here with static logger initialization fiasco.
// registerFactory may be called from constructors of static global
// objects for built in backends. The logging is not initialized yet,
// so the LOG_DEBUG would throw.
if (!no_log) {
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER)
.arg(db_type);
}
return (true);
}
bool
HostDataSourceFactory::deregisterFactory(const string& db_type) {
HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) {
auto index = map_.find(db_type);
if (index != map_.end()) {
map_.erase(index);
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER)
.arg(db_type);
if (!no_log) {
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE,
HOSTS_BACKEND_DEREGISTER)
.arg(db_type);
}
return (true);
} else {
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 isc
@@ -133,18 +152,18 @@ namespace {
struct MySqlHostDataSourceInit {
// Constructor registers
MySqlHostDataSourceInit() {
HostDataSourceFactory::registerFactory("mysql", factory);
HostDataSourceFactory::registerFactory("mysql", factory, true);
}
// Destructor deregisters
~MySqlHostDataSourceInit() {
HostDataSourceFactory::deregisterFactory("mysql");
HostDataSourceFactory::deregisterFactory("mysql", true);
}
// Factory class method
static HostDataSourcePtr
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));
return (HostDataSourcePtr(new MySqlHostDataSource(parameters)));
}
@@ -158,18 +177,18 @@ MySqlHostDataSourceInit mysql_init_;
struct PgSqlHostDataSourceInit {
// Constructor registers
PgSqlHostDataSourceInit() {
HostDataSourceFactory::registerFactory("postgresql", factory);
HostDataSourceFactory::registerFactory("postgresql", factory, true);
}
// Destructor deregisters
~PgSqlHostDataSourceInit() {
HostDataSourceFactory::deregisterFactory("postgresql");
HostDataSourceFactory::deregisterFactory("postgresql", true);
}
// Factory class method
static HostDataSourcePtr
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));
return (HostDataSourcePtr(new PgSqlHostDataSource(parameters)));
}
@@ -183,12 +202,12 @@ PgSqlHostDataSourceInit pgsql_init_;
struct CqlHostDataSourceInit {
// Constructor registers
CqlHostDataSourceInit() {
HostDataSourceFactory::registerFactory("cql", factory);
HostDataSourceFactory::registerFactory("cql", factory, true);
}
// Destructor deregisters
~CqlHostDataSourceInit() {
HostDataSourceFactory::deregisterFactory("cql");
HostDataSourceFactory::deregisterFactory("cql", true);
}
// Factory class method
@@ -205,4 +224,3 @@ CqlHostDataSourceInit cql_init_;
#endif
} // end of anonymous namespace

View File

@@ -14,6 +14,7 @@
#include <boost/function.hpp>
#include <string>
#include <vector>
#include <map>
namespace isc {
@@ -83,22 +84,35 @@ public:
/// @brief Register a host data source factory
///
/// 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 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
/// if it already exists.
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
///
/// 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 no_log do not log (default false)
/// @return true if the factory was successfully removed from the map,
/// 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:
/// @brief Factory map

View File

@@ -6,14 +6,18 @@
$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.
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
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
This debug message is issued when new host (with reservations) is added to
the server's configuration. The argument describes the host and its