diff options
author | Marcin Siodelski <marcin@isc.org> | 2018-08-28 13:09:25 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2018-09-03 09:31:33 +0200 |
commit | 012a97a87cd633f2a122f8ea3ee1218c04cf4259 (patch) | |
tree | 458166e64edb2f03559b8a08c57952d731c5d18a | |
parent | [#92,!13] New libkea-database library created. (diff) | |
download | kea-012a97a87cd633f2a122f8ea3ee1218c04cf4259.tar.xz kea-012a97a87cd633f2a122f8ea3ee1218c04cf4259.zip |
[#92,!13] Refactored libkea-dhcpsrv to use libkea-database
72 files changed, 398 insertions, 651 deletions
diff --git a/src/bin/dhcp4/Makefile.am b/src/bin/dhcp4/Makefile.am index cc19d70882..5486dfe500 100644 --- a/src/bin/dhcp4/Makefile.am +++ b/src/bin/dhcp4/Makefile.am @@ -84,6 +84,7 @@ kea_dhcp4_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +kea_dhcp4_LDADD += $(top_builddir)/src/lib/database/libkea-database.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/log/libkea-log.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la kea_dhcp4_LDADD += $(top_builddir)/src/lib/util/libkea-util.la diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 6f62bd5642..25a13d88dd 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -23,6 +23,7 @@ #include <sstream> using namespace isc::data; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::hooks; using namespace isc::config; diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.h b/src/bin/dhcp4/ctrl_dhcp4_srv.h index 06d5ee6472..1978a5880d 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.h +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.h @@ -11,7 +11,7 @@ #include <asiolink/asiolink.h> #include <cc/data.h> #include <cc/command_interpreter.h> -#include <dhcpsrv/database_connection.h> +#include <database/database_connection.h> #include <dhcpsrv/timer_mgr.h> #include <dhcp4/dhcp4_srv.h> @@ -336,7 +336,7 @@ private: /// @param db_reconnect_ctl pointer to the ReconnectCtl containing the /// configured reconnect parameters /// - void dbReconnect(ReconnectCtlPtr db_reconnect_ctl); + void dbReconnect(db::ReconnectCtlPtr db_reconnect_ctl); /// @brief Callback DB backends should invoke upon loss of connectivity /// @@ -356,7 +356,7 @@ private: /// configured reconnect parameters /// /// @return false if reconnect is not configured, true otherwise - bool dbLostCallback(ReconnectCtlPtr db_reconnect_ctl); + bool dbLostCallback(db::ReconnectCtlPtr db_reconnect_ctl); /// @brief Static pointer to the sole instance of the DHCP server. /// diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am index d9d58779d9..e02b18a9c9 100644 --- a/src/bin/dhcp4/tests/Makefile.am +++ b/src/bin/dhcp4/tests/Makefile.am @@ -135,6 +135,7 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +dhcp4_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la dhcp4_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la diff --git a/src/bin/dhcp6/Makefile.am b/src/bin/dhcp6/Makefile.am index 88cfdec69e..ff14c320d8 100644 --- a/src/bin/dhcp6/Makefile.am +++ b/src/bin/dhcp6/Makefile.am @@ -84,6 +84,7 @@ kea_dhcp6_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +kea_dhcp6_LDADD += $(top_builddir)/src/lib/database/libkea-database.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/log/libkea-log.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la kea_dhcp6_LDADD += $(top_builddir)/src/lib/util/libkea-util.la diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index e50ed9fef9..ffd6ac6e8d 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -11,7 +11,6 @@ #include <dhcp/libdhcp++.h> #include <dhcpsrv/cfgmgr.h> #include <dhcpsrv/cfg_db_access.h> -#include <dhcpsrv/database_connection.h> #include <dhcp6/ctrl_dhcp6_srv.h> #include <dhcp6/dhcp6to4_ipc.h> #include <dhcp6/dhcp6_log.h> @@ -24,6 +23,7 @@ #include <sstream> using namespace isc::config; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::data; using namespace isc::hooks; diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.h b/src/bin/dhcp6/ctrl_dhcp6_srv.h index 31e738a91e..a747fec833 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.h +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.h @@ -11,7 +11,7 @@ #include <asiolink/asiolink.h> #include <cc/data.h> #include <cc/command_interpreter.h> -#include <dhcpsrv/database_connection.h> +#include <database/database_connection.h> #include <dhcpsrv/timer_mgr.h> #include <dhcp6/dhcp6_srv.h> @@ -335,7 +335,7 @@ private: /// @param db_reconnect_ctl pointer to the ReconnectCtl containing the /// configured reconnect parameters /// - void dbReconnect(ReconnectCtlPtr db_reconnect_ctl); + void dbReconnect(db::ReconnectCtlPtr db_reconnect_ctl); /// @brief Callback DB backends should invoke upon loss of connectivity /// @@ -353,7 +353,7 @@ private: /// /// @param db_reconnect_ctl pointer to the ReconnectCtl containing the /// configured reconnect parameters - bool dbLostCallback(ReconnectCtlPtr db_reconnect_ctl); + bool dbLostCallback(db::ReconnectCtlPtr db_reconnect_ctl); /// @brief Static pointer to the sole instance of the DHCP server. /// diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index f862c374a1..6d587d5dd4 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/src/bin/dhcp6/tests/Makefile.am @@ -135,6 +135,7 @@ dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +dhcp6_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la dhcp6_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la diff --git a/src/lib/database/.gitignore b/src/lib/database/.gitignore new file mode 100644 index 0000000000..1647c12a13 --- /dev/null +++ b/src/lib/database/.gitignore @@ -0,0 +1,3 @@ +/db_messages.cc +/db_messages.h +/s-messages diff --git a/src/lib/database/Makefile.am b/src/lib/database/Makefile.am index fac6488b2f..6e8a66747b 100644 --- a/src/lib/database/Makefile.am +++ b/src/lib/database/Makefile.am @@ -5,11 +5,30 @@ AM_CPPFLAGS += $(BOOST_INCLUDES) AM_CXXFLAGS = $(KEA_CXXFLAGS) +# Define rule to build logging source files from message file +db_messages.h db_messages.cc: s-messages + +s-messages: db_messages.mes + $(top_builddir)/src/lib/log/compiler/kea-msg-compiler $(top_srcdir)/src/lib/database/db_messages.mes + touch $@ + +# Tell automake that the message files are built as part of the build process +# (so that they are built before the main library is built). +BUILT_SOURCES = db_messages.h db_messages.cc + +# Ensure that the message file is included in the distribution +EXTRA_DIST = db_messages.mes + +# Get rid of generated message files on a clean +CLEANFILES = *.gcno *.gcda http_messages.h http_messages.cc s-messages + lib_LTLIBRARIES = libkea-database.la libkea_database_la_SOURCES = database_connection.cc database_connection.h libkea_database_la_SOURCES += db_exceptions.h libkea_database_la_SOURCES += db_log.cc db_log.h +nodist_libkea_database_la_SOURCES = db_messages.cc db_messages.h + libkea_database_la_LIBADD = $(top_builddir)/src/lib/log/libkea-log.la libkea_database_la_LIBADD += $(top_builddir)/src/lib/log/interprocess/libkea-log_interprocess.la libkea_database_la_LIBADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la @@ -23,8 +42,6 @@ libkea_database_la_LDFLAGS = -no-undefined -version-info 0:0:0 # The message file should be in the distribution. #EXTRA_DIST = config_backend.dox -CLEANFILES = *.gcno *.gcda - # Specify the headers for copying into the installation directory tree. #libkea_cb_includedir = $(pkgincludedir)/config #libkea_cb_include_HEADERS = diff --git a/src/lib/database/database_log.cc b/src/lib/database/database_log.cc new file mode 100644 index 0000000000..602a223621 --- /dev/null +++ b/src/lib/database/database_log.cc @@ -0,0 +1,16 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <config.h> +#include <database/database_log.h> + +namespace isc { +namespace db { + +isc::log::Logger database_logger("database"); + +} // end of namespace db +} // end of namespace isc diff --git a/src/lib/database/database_log.h b/src/lib/database/database_log.h new file mode 100644 index 0000000000..33b1e757a3 --- /dev/null +++ b/src/lib/database/database_log.h @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef DATABASE_LOG_H +#define DATABASE_LOG_H + +namespace isc { +namespace db { + +/// @brief Common database library logger. +extern isc::log::Logger database_logger; + +} // end of namespace isc::db +} // end of namespace isc + +#endif // DATABASE_LOG_H diff --git a/src/lib/database/db_log.cc b/src/lib/database/db_log.cc index 75ee637d2a..8b775dba25 100644 --- a/src/lib/database/db_log.cc +++ b/src/lib/database/db_log.cc @@ -10,13 +10,42 @@ #include <exceptions/exceptions.h> #include <database/db_log.h> +#include <database/db_messages.h> using namespace isc::log; namespace isc { namespace db { -DbLoggerStack db_logger_stack; +/// @brief Map of translated messages. +const DbLogger::MessageMap db_message_map = { + { DB_INVALID_ACCESS, DATABASE_INVALID_ACCESS }, + + { PGSQL_DEALLOC_ERROR, DATABASE_PGSQL_DEALLOC_ERROR }, + { PGSQL_FATAL_ERROR, DATABASE_PGSQL_FATAL_ERROR }, + { PGSQL_START_TRANSACTION, DATABASE_PGSQL_START_TRANSACTION }, + { PGSQL_COMMIT, DATABASE_PGSQL_COMMIT }, + { PGSQL_ROLLBACK, DATABASE_PGSQL_ROLLBACK }, + + { MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR }, + { MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION }, + { MYSQL_COMMIT, DATABASE_MYSQL_COMMIT }, + { MYSQL_ROLLBACK, DATABASE_MYSQL_ROLLBACK }, + + { CQL_DEALLOC_ERROR, DATABASE_CQL_DEALLOC_ERROR }, + { CQL_CONNECTION_BEGIN_TRANSACTION, + DATABASE_CQL_CONNECTION_BEGIN_TRANSACTION }, + { CQL_CONNECTION_COMMIT, DATABASE_CQL_CONNECTION_COMMIT }, + { CQL_CONNECTION_ROLLBACK, DATABASE_CQL_CONNECTION_ROLLBACK } +}; + + +isc::log::Logger database_logger("database"); + +DbLogger db_logger_translator(database_logger, db_message_map); + +DbLoggerStack db_logger_stack = { db_logger_translator }; + const MessageID& DbLogger::translateMessage(const DbMessageID& id) const { diff --git a/src/lib/database/db_log.h b/src/lib/database/db_log.h index de7bd9f93f..5096ad9543 100644 --- a/src/lib/database/db_log.h +++ b/src/lib/database/db_log.h @@ -41,6 +41,10 @@ const int DB_DBG_TRACE_DETAIL = isc::log::DBGLVL_TRACE_DETAIL; ///@} +/// @brief Common database library logger. +extern isc::log::Logger database_logger; + + ///@{ /// @brief Database messages /// @@ -109,43 +113,49 @@ void checkDbLoggerStack(); /// @brief Macros #define DB_LOG_DEBUG(LEVEL, MESSAGE) \ - checkDbLoggerStack(); \ + isc::db::checkDbLoggerStack(); \ if (!db_logger_stack.back().logger_.isDebugEnabled((LEVEL))) { \ } else \ - db_logger_stack.back().logger_.debug((LEVEL), \ - db_logger_stack.back().translateMessage((MESSAGE))) + isc::db::db_logger_stack.back().logger_.debug((LEVEL), \ + isc::db::db_logger_stack.back().translateMessage((MESSAGE))) #define DB_LOG_INFO(MESSAGE) \ - checkDbLoggerStack(); \ - if (!db_logger_stack.back().logger_.isInfoEnabled()) { \ + isc::db::checkDbLoggerStack(); \ + if (!isc::db::db_logger_stack.back().logger_.isInfoEnabled()) { \ } else \ - db_logger_stack.back().logger_.info( \ - db_logger_stack.back().translateMessage((MESSAGE))) + isc::db::db_logger_stack.back().logger_.info( \ + isc::db::db_logger_stack.back().translateMessage((MESSAGE))) #define DB_LOG_WARN(MESSAGE) \ - checkDbLoggerStack(); \ - if (!db_logger_stack.back().logger_.isWarnEnabled()) { \ + isc::db::checkDbLoggerStack(); \ + if (!isc::db::db_logger_stack.back().logger_.isWarnEnabled()) { \ } else \ - db_logger_stack.back().logger_.warn( \ - db_logger_stack.back().translateMessage((MESSAGE))) + isc::db::db_logger_stack.back().logger_.warn( \ + isc::db::db_logger_stack.back().translateMessage((MESSAGE))) #define DB_LOG_ERROR(MESSAGE) \ - checkDbLoggerStack(); \ - if (!db_logger_stack.back().logger_.isErrorEnabled()) { \ + isc::db::checkDbLoggerStack(); \ + if (!isc::db::db_logger_stack.back().logger_.isErrorEnabled()) { \ } else \ - db_logger_stack.back().logger_.error( \ - db_logger_stack.back().translateMessage((MESSAGE))) + isc::db::db_logger_stack.back().logger_.error( \ + isc::db::db_logger_stack.back().translateMessage((MESSAGE))) #define DB_LOG_FATAL(MESSAGE) \ - checkDbLoggerStack(); \ - if (!db_logger_stack.back().logger_.isFatalEnabled()) { \ + isc::db::checkDbLoggerStack(); \ + if (!isc::db::db_logger_stack.back().logger_.isFatalEnabled()) { \ } else \ - db_logger_stack.back().logger_.fatal( \ - db_logger_stack.back().translateMessage((MESSAGE))) + isc::db::db_logger_stack.back().logger_.fatal( \ + isc::db::db_logger_stack.back().translateMessage((MESSAGE))) ///@} +/// @brief DHCP server database message map +extern const db::DbLogger::MessageMap db_message_map; + +/// @brief Database logger translator. +extern db::DbLogger db_logger_translator; + } // namespace db } // namespace isc diff --git a/src/lib/database/db_messages.mes b/src/lib/database/db_messages.mes new file mode 100644 index 0000000000..9d26a06e03 --- /dev/null +++ b/src/lib/database/db_messages.mes @@ -0,0 +1,86 @@ +# Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +$NAMESPACE isc::db + +% DATABASE_CQL_CONNECTION_BEGIN_TRANSACTION begin transaction on current connection. +The server has issued a begin transaction call. + +% DATABASE_CQL_CONNECTION_COMMIT committing to Cassandra database on current connection. +A commit call been issued on the server. For Cassandra, this is a no-op. + +% DATABASE_CQL_CONNECTION_ROLLBACK rolling back Cassandra database on current connection. +The code has issued a rollback call. For Cassandra, this is a no-op. + +% DATABASE_CQL_DEALLOC_ERROR An error occurred while closing the CQL connection: %1 +This is an error message issued when a DHCP server (either V4 or V6) experienced +and error freeing CQL database resources as part of closing its connection to +the Cassandra database. The connection is closed as part of normal server +shutdown. This error is most likely a programmatic issue that is highly +unlikely to occur or negatively impact server operation. + +% DATABASE_INVALID_ACCESS invalid database access string: %1 +This is logged when an attempt has been made to parse a database access string +and the attempt ended in error. The access string in question - which +should be of the form 'keyword=value keyword=value...' is included in +the message. + +% DATABASE_MYSQL_COMMIT committing to MySQL database +The code has issued a commit call. All outstanding transactions will be +committed to the database. Note that depending on the MySQL settings, +the committal may not include a write to disk. + +% DATABASE_MYSQL_FATAL_ERROR Unrecoverable MySQL error occurred: %1 for <%2>, reason: %3 (error code: %4). +An error message indicating that communication with the MySQL database server +has been lost. If automatic recovery has been enabled, then the server will +attempt to recover connectivity. If not the server wil exit with a +non-zero exit code. The cause of such an error is most likely a network issue +or the MySQL server has gone down. + +% DATABASE_MYSQL_ROLLBACK rolling back MySQL database +The code has issued a rollback call. All outstanding transaction will +be rolled back and not committed to the database. + +% DATABASE_MYSQL_START_TRANSACTION starting new MySQL transaction +A debug message issued when a new MySQL transaction is being started. +This message is typically not issued when inserting data into a +single table because the server doesn't explicitly start +transactions in this case. This message is issued when data is +inserted into multiple tables with multiple INSERT statements +and there may be a need to rollback the whole transaction if +any of these INSERT statements fail. + +% DATABASE_PGSQL_COMMIT committing to PostgreSQL database +The code has issued a commit call. All outstanding transactions will be +committed to the database. Note that depending on the PostgreSQL settings, +the committal may not include a write to disk. + +% DATABASE_PGSQL_DEALLOC_ERROR An error occurred deallocating SQL statements while closing the PostgreSQL lease database: %1 +This is an error message issued when a DHCP server (either V4 or V6) experienced +and error freeing database SQL resources as part of closing its connection to +the PostgreSQL database. The connection is closed as part of normal server +shutdown. This error is most likely a programmatic issue that is highly +unlikely to occur or negatively impact server operation. + +% DATABASE_PGSQL_FATAL_ERROR Unrecoverable PostgreSQL error occurred: Statement: <%1>, reason: %2 (error code: %3). +An error message indicating that communication with the PostgreSQL database server +has been lost. If automatic recovery has been enabled, then the server will +attempt to recover the connectivity. If not the server wil exit with a +non-zero exit code. The cause of such an error is most likely a network issue +or the PostgreSQL server has gone down. + +% DATABASE_PGSQL_ROLLBACK rolling back PostgreSQL database +The code has issued a rollback call. All outstanding transaction will +be rolled back and not committed to the database. + +% DATABASE_PGSQL_START_TRANSACTION starting a new PostgreSQL transaction +A debug message issued when a new PostgreSQL transaction is being started. +This message is typically not issued when inserting data into a +single table because the server doesn't explicitly start +transactions in this case. This message is issued when data is +inserted into multiple tables with multiple INSERT statements +and there may be a need to rollback the whole transaction if +any of these INSERT statements fail. diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index 77817aef12..13fccc2885 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -118,7 +118,6 @@ libkea_dhcpsrv_la_SOURCES += daemon.cc daemon.h libkea_dhcpsrv_la_SOURCES += db_type.h libkea_dhcpsrv_la_SOURCES += dhcp4o6_ipc.cc dhcp4o6_ipc.h libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h -libkea_dhcpsrv_la_SOURCES += dhcpsrv_db_log.cc dhcpsrv_db_log.h libkea_dhcpsrv_la_SOURCES += host.cc host.h libkea_dhcpsrv_la_SOURCES += host_container.h libkea_dhcpsrv_la_SOURCES += host_data_source_factory.cc host_data_source_factory.h @@ -276,13 +275,8 @@ libkea_dhcpsrv_include_HEADERS = \ d2_client_cfg.h \ d2_client_mgr.h \ daemon.h \ - database_connection.h \ - db_exceptions.h \ - db_log.h \ db_type.h \ dhcp4o6_ipc.h \ - dhcpsrv_db_log.h \ - dhcpsrv_log.h \ host.h \ host_container.h \ host_data_source_factory.h \ diff --git a/src/lib/dhcpsrv/cfg_db_access.h b/src/lib/dhcpsrv/cfg_db_access.h index f3f043983d..db4ae335b8 100644 --- a/src/lib/dhcpsrv/cfg_db_access.h +++ b/src/lib/dhcpsrv/cfg_db_access.h @@ -8,7 +8,7 @@ #define CFG_DBACCESS_H #include <cc/cfg_to_element.h> -#include <dhcpsrv/database_connection.h> +#include <database/database_connection.h> #include <boost/shared_ptr.hpp> #include <string> diff --git a/src/lib/dhcpsrv/cql_connection.cc b/src/lib/dhcpsrv/cql_connection.cc index 3b18f02a5b..3c32cff820 100644 --- a/src/lib/dhcpsrv/cql_connection.cc +++ b/src/lib/dhcpsrv/cql_connection.cc @@ -1,3 +1,4 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2015-2018 Deutsche Telekom AG. // // Authors: Razvan Becheriu <razvan.becheriu@qualitance.com> @@ -17,13 +18,15 @@ #include <config.h> +#include <database/db_exceptions.h> +#include <database/db_log.h> #include <dhcpsrv/cql_connection.h> #include <dhcpsrv/cql_exchange.h> -#include <dhcpsrv/db_exceptions.h> -#include <dhcpsrv/db_log.h> #include <string> +using namespace isc::db; + namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/cql_connection.h b/src/lib/dhcpsrv/cql_connection.h index 9d81d93626..f7bb963133 100644 --- a/src/lib/dhcpsrv/cql_connection.h +++ b/src/lib/dhcpsrv/cql_connection.h @@ -19,7 +19,7 @@ #ifndef CQL_CONNECTION_H #define CQL_CONNECTION_H -#include <dhcpsrv/database_connection.h> +#include <database/database_connection.h> #include <cassandra.h> @@ -116,7 +116,7 @@ typedef std::pair<StatementTag, CqlTaggedStatement> StatementMapEntry; /// to the Cassandra database and preparing of compiled statements. Its fields /// are public because they are used (both set and retrieved) in classes that /// use instances of CqlConnection. -class CqlConnection : public DatabaseConnection { +class CqlConnection : public db::DatabaseConnection { public: /// @brief Constructor /// @@ -133,7 +133,7 @@ public: /// by the CQL backend. /// @param statements statements to be prepared /// - /// @throw isc::dhcp::DbOperationError if an operation on the open database + /// @throw isc::db::DbOperationError if an operation on the open database /// has failed /// @throw isc::InvalidParameter if there is an invalid access in the /// vector. This represents an internal error within the code. diff --git a/src/lib/dhcpsrv/cql_exchange.cc b/src/lib/dhcpsrv/cql_exchange.cc index c84d7b72f4..75a5a8911c 100644 --- a/src/lib/dhcpsrv/cql_exchange.cc +++ b/src/lib/dhcpsrv/cql_exchange.cc @@ -1,3 +1,4 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2016-2017 Deutsche Telekom AG. // // Authors: Razvan Becheriu <razvan.becheriu@qualitance.com> @@ -17,9 +18,9 @@ #include <config.h> +#include <database/db_exceptions.h> #include <dhcpsrv/cql_connection.h> #include <dhcpsrv/cql_exchange.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/sql_common.h> #include <boost/multi_index/hashed_index.hpp> @@ -36,6 +37,8 @@ #include <utility> #include <vector> +using namespace isc::db; + namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc index 25375f5fc7..56ad30ca20 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.cc +++ b/src/lib/dhcpsrv/cql_host_data_source.cc @@ -17,8 +17,8 @@ #include <config.h> +#include <database/db_exceptions.h> #include <dhcpsrv/cql_host_data_source.h> - #include <dhcp/duid.h> #include <dhcp/libdhcp++.h> #include <dhcp/option.h> @@ -26,7 +26,6 @@ #include <dhcpsrv/cfg_option.h> #include <dhcpsrv/cfgmgr.h> #include <dhcpsrv/cql_exchange.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/dhcpsrv_log.h> #include <util/buffer.h> #include <util/hash.h> @@ -45,6 +44,7 @@ #include <string> // for std::string using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::util; using namespace isc::data; diff --git a/src/lib/dhcpsrv/cql_host_data_source.h b/src/lib/dhcpsrv/cql_host_data_source.h index 2d472ff76e..091372bc09 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.h +++ b/src/lib/dhcpsrv/cql_host_data_source.h @@ -1,3 +1,4 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2016-2018 Deutsche Telekom AG. // // Author: Andrei Pavel <andrei.pavel@qualitance.com> @@ -77,12 +78,12 @@ public: /// @param parameters a data structure relating keywords and values /// concerned with the database. /// - /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database or if the + /// @throw isc::db::NoDatabaseName Mandatory database name not given + /// @throw isc::db::DbOpenError Error opening the database or if the /// schema version is invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - explicit CqlHostDataSource(const DatabaseConnection::ParameterMap& parameters); + explicit CqlHostDataSource(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Virtual destructor. /// @@ -278,7 +279,7 @@ public: /// integers. "first" is the major version number, "second" is the /// minor version number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database + /// @throw isc::db::DbOperationError An operation on the open database /// has failed. virtual VersionPair getVersion() const; diff --git a/src/lib/dhcpsrv/cql_lease_mgr.cc b/src/lib/dhcpsrv/cql_lease_mgr.cc index 5b41e6d852..79f184c11d 100644 --- a/src/lib/dhcpsrv/cql_lease_mgr.cc +++ b/src/lib/dhcpsrv/cql_lease_mgr.cc @@ -27,6 +27,7 @@ #include <asiolink/io_address.h> using namespace isc::data; +using namespace isc::db; using isc::asiolink::IOAddress; namespace isc { diff --git a/src/lib/dhcpsrv/cql_lease_mgr.h b/src/lib/dhcpsrv/cql_lease_mgr.h index 5b7650786a..89600fa3d4 100644 --- a/src/lib/dhcpsrv/cql_lease_mgr.h +++ b/src/lib/dhcpsrv/cql_lease_mgr.h @@ -1,3 +1,4 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2015-2018 Deutsche Telekom AG. // // Authors: Razvan Becheriu <razvan.becheriu@qualitance.com> @@ -65,12 +66,12 @@ public: /// @param parameters a data structure relating keywords and values /// concerned with the database. /// - /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database or the schema + /// @throw isc::db::NoDatabaseName Mandatory database name not given + /// @throw isc::db::DbOpenError Error opening the database or the schema /// version is invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - explicit CqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters); + explicit CqlLeaseMgr(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Destructor (closes database) virtual ~CqlLeaseMgr(); @@ -85,7 +86,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease4Ptr& lease) override; @@ -96,7 +97,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease6Ptr& lease) override; @@ -117,7 +118,7 @@ public: /// /// @return smart pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const override; @@ -133,7 +134,7 @@ public: /// /// @return lease collection /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const override; @@ -149,7 +150,7 @@ public: /// /// @return a pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr, SubnetID subnet_id) const override; @@ -165,7 +166,7 @@ public: /// /// @return lease collection /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const ClientId& clientid) const override; @@ -194,7 +195,7 @@ public: /// /// @return a pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const ClientId& clientid, SubnetID subnet_id) const override; @@ -256,7 +257,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Ptr getLease6(Lease::Type type, @@ -277,7 +278,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, @@ -294,7 +295,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, @@ -320,7 +321,7 @@ public: /// @brief Returns all IPv6 leases. /// /// @return Lease collection (may be empty if no IPv6 lease found). - virtual Lease6Collection getLeases6(const DUID& duid) const; + virtual Lease6Collection getLeases6(const DUID& duid) const override; /// @brief Returns range of IPv6 leases using paging. /// @@ -392,9 +393,9 @@ public: /// /// @param lease4 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not /// exist. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease4(const Lease4Ptr& lease4) override; @@ -405,9 +406,9 @@ public: /// /// @param lease6 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease6(const Lease6Ptr& lease6) override; @@ -418,7 +419,7 @@ public: /// /// @return true if deletion was successful, false if no such lease exists /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool deleteLease(const isc::asiolink::IOAddress& addr) override; @@ -550,7 +551,7 @@ public: /// @return Version number as a pair of unsigned integers. "first" is the /// major version number, "second" the minor number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual VersionPair getVersion() const override; diff --git a/src/lib/dhcpsrv/database_connection.cc b/src/lib/dhcpsrv/database_connection.cc deleted file mode 100644 index 6363492b17..0000000000 --- a/src/lib/dhcpsrv/database_connection.cc +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include <config.h> - -#include <dhcpsrv/database_connection.h> -#include <dhcpsrv/db_exceptions.h> -#include <dhcpsrv/db_log.h> -#include <exceptions/exceptions.h> - -#include <boost/algorithm/string.hpp> -#include <boost/foreach.hpp> -#include <vector> - -using namespace std; - -namespace isc { -namespace dhcp { - -const time_t DatabaseConnection::MAX_DB_TIME = 2147483647; - -std::string -DatabaseConnection::getParameter(const std::string& name) const { - ParameterMap::const_iterator param = parameters_.find(name); - if (param == parameters_.end()) { - isc_throw(BadValue, "Parameter " << name << " not found"); - } - return (param->second); -} - -DatabaseConnection::ParameterMap -DatabaseConnection::parse(const std::string& dbaccess) { - DatabaseConnection::ParameterMap mapped_tokens; - - if (!dbaccess.empty()) { - vector<string> tokens; - - // We need to pass a string to is_any_of, not just char*. Otherwise - // there are cryptic warnings on Debian6 running g++ 4.4 in - // /usr/include/c++/4.4/bits/stl_algo.h:2178 "array subscript is above - // array bounds" - boost::split(tokens, dbaccess, boost::is_any_of(string("\t "))); - BOOST_FOREACH(std::string token, tokens) { - size_t pos = token.find("="); - if (pos != string::npos) { - string name = token.substr(0, pos); - string value = token.substr(pos + 1); - mapped_tokens.insert(make_pair(name, value)); - } else { - DB_LOG_ERROR(DB_INVALID_ACCESS).arg(dbaccess); - isc_throw(InvalidParameter, "Cannot parse " << token - << ", expected format is name=value"); - } - } - } - - return (mapped_tokens); -} - -std::string -DatabaseConnection::redactedAccessString(const ParameterMap& parameters) { - // Reconstruct the access string: start of with an empty string, then - // work through all the parameters in the original string and add them. - std::string access; - for (DatabaseConnection::ParameterMap::const_iterator i = parameters.begin(); - i != parameters.end(); ++i) { - - // Separate second and subsequent tokens are preceded by a space. - if (!access.empty()) { - access += " "; - } - - // Append name of parameter... - access += i->first; - access += "="; - - // ... and the value, except in the case of the password, where a - // redacted value is appended. - if (i->first == std::string("password")) { - access += "*****"; - } else { - access += i->second; - } - } - - return (access); -} - -bool -DatabaseConnection::configuredReadOnly() const { - std::string readonly_value = "false"; - try { - readonly_value = getParameter("readonly"); - boost::algorithm::to_lower(readonly_value); - } catch (...) { - // Parameter "readonly" hasn't been specified so we simply use - // the default value of "false". - } - - if ((readonly_value != "false") && (readonly_value != "true")) { - isc_throw(DbInvalidReadOnly, "invalid value '" << readonly_value - << "' specified for boolean parameter 'readonly'"); - } - - return (readonly_value == "true"); -} - -ReconnectCtlPtr -DatabaseConnection::makeReconnectCtl() const { - ReconnectCtlPtr retry; - string type = "unknown"; - unsigned int retries = 0; - unsigned int interval = 0; - - // Assumes that parsing ensurse only valid values are present - try { - type = getParameter("type"); - } catch (...) { - // Wasn't specified so we'll use default of "unknown". - } - - std::string parm_str; - try { - parm_str = getParameter("max-reconnect-tries"); - retries = boost::lexical_cast<unsigned int>(parm_str); - } catch (...) { - // Wasn't specified so we'll use default of 0; - } - - try { - parm_str = getParameter("reconnect-wait-time"); - interval = boost::lexical_cast<unsigned int>(parm_str); - } catch (...) { - // Wasn't specified so we'll use default of 0; - } - - retry.reset(new ReconnectCtl(type, retries, interval)); - return (retry); -} - -bool -DatabaseConnection::invokeDbLostCallback() const { - if (DatabaseConnection::db_lost_callback) { - // Invoke the callback, passing in a new instance of ReconnectCtl - return (DatabaseConnection::db_lost_callback)(makeReconnectCtl()); - } - - return (false); -} - - -DatabaseConnection::DbLostCallback -DatabaseConnection::db_lost_callback = 0; - -}; -}; diff --git a/src/lib/dhcpsrv/database_connection.h b/src/lib/dhcpsrv/database_connection.h deleted file mode 100644 index 8dcbe56115..0000000000 --- a/src/lib/dhcpsrv/database_connection.h +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef DATABASE_CONNECTION_H -#define DATABASE_CONNECTION_H - -#include <boost/noncopyable.hpp> -#include <boost/function.hpp> -#include <boost/shared_ptr.hpp> -#include <exceptions/exceptions.h> -#include <map> -#include <string> - -namespace isc { -namespace dhcp { - -/// @brief Exception thrown if name of database is not specified -class NoDatabaseName : public Exception { -public: - NoDatabaseName(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Exception thrown on failure to open database -class DbOpenError : public Exception { -public: - DbOpenError(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Exception thrown on failure to execute a database function -class DbOperationError : public Exception { -public: - DbOperationError(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Invalid type exception -/// -/// Thrown when the factory doesn't recognize the type of the backend. -class InvalidType : public Exception { -public: - InvalidType(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Invalid Timeout -/// -/// Thrown when the timeout specified for the database connection is invalid. -class DbInvalidTimeout : public Exception { -public: - DbInvalidTimeout(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Invalid 'readonly' value specification. -/// -/// Thrown when the value of the 'readonly' boolean parameter is invalid. -class DbInvalidReadOnly : public Exception { -public: - DbInvalidReadOnly(const char* file, size_t line, const char* what) : - isc::Exception(file, line, what) {} -}; - -/// @brief Warehouses DB reconnect control values -/// -/// When a DatabaseConnection loses connectivity to its backend, it -/// creates an instance of this class based on its configuration parameters and -/// passes the instance into connection's DB lost callback. This allows -/// the layer(s) above the connection to know how to proceed. -/// -class ReconnectCtl { -public: - /// @brief Constructor - /// @param backend_type type of the caller backend. - /// @param max_retries maximum number of reconnect attempts to make - /// @param retry_interval amount of time to between reconnect attempts - ReconnectCtl(const std::string& backend_type, unsigned int max_retries, - unsigned int retry_interval) - : backend_type_(backend_type), max_retries_(max_retries), - retries_left_(max_retries), retry_interval_(retry_interval) {} - - /// @brief Returns the type of the caller backend. - std::string backendType() const { - return (backend_type_); - } - - /// @brief Decrements the number of retries remaining - /// - /// Each call decrements the number of retries by one until zero is reached. - /// @return true the number of retries remaining is greater than zero. - bool checkRetries() { - return (retries_left_ ? --retries_left_ : false); - } - - /// @brief Returns the maximum number for retries allowed - unsigned int maxRetries() { - return (max_retries_); - } - - /// @brief Returns the number for retries remaining - unsigned int retriesLeft() { - return (retries_left_); - } - - /// @brief Returns the amount of time to wait between reconnect attempts - unsigned int retryInterval() { - return (retry_interval_); - } - -private: - /// @brief Caller backend type. - const std::string backend_type_; - - /// @brief Maximum number of retry attempts to make - unsigned int max_retries_; - - /// @brief Number of attempts remaining - unsigned int retries_left_; - - /// @brief The amount of time to wait between reconnect attempts - unsigned int retry_interval_; -}; - -/// @brief Pointer to an instance of ReconnectCtl -typedef boost::shared_ptr<ReconnectCtl> ReconnectCtlPtr; - -/// @brief Common database connection class. -/// -/// This class provides functions that are common for establishing -/// connection with different types of databases; enables operations -/// on access parameters strings. In particular, it provides a way -/// to parse parameters in key=value format. This class is expected -/// to be a base class for all @ref LeaseMgr and possibly -/// @ref BaseHostDataSource derived classes. -class DatabaseConnection : public boost::noncopyable { -public: - - /// @brief Defines maximum value for time that can be reliably stored. - /// - /// @todo: Is this common for MySQL and Postgres? Maybe we should have - /// specific values for each backend? - /// - /// If I'm still alive I'll be too old to care. You fix it. - static const time_t MAX_DB_TIME; - - /// @brief Database configuration parameter map - typedef std::map<std::string, std::string> ParameterMap; - - /// @brief Constructor - /// - /// @param parameters A data structure relating keywords and values - /// concerned with the database. - DatabaseConnection(const ParameterMap& parameters) - :parameters_(parameters) { - } - - /// @brief Destructor - virtual ~DatabaseConnection(){}; - - /// @brief Instantiates a ReconnectCtl based on the connection's - /// reconnect parameters - /// @return pointer to the new ReconnectCtl object - virtual ReconnectCtlPtr makeReconnectCtl() const; - - /// @brief Returns value of a connection parameter. - /// - /// @param name Name of the parameter which value should be returned. - /// @return Value of one of the connection parameters. - /// @throw BadValue if parameter is not found - std::string getParameter(const std::string& name) const; - - /// @brief Parse database access string - /// - /// Parses the string of "keyword=value" pairs and separates them - /// out into the map. - /// - /// @param dbaccess Database access string. - /// - /// @return @ref ParameterMap of keyword/value pairs. - static ParameterMap parse(const std::string& dbaccess); - - /// @brief Redact database access string - /// - /// Takes the database parameters and returns a database access string - /// passwords replaced by asterisks. This string is used in log messages. - /// - /// @param parameters Database access parameters (output of "parse"). - /// - /// @return Redacted database access string. - static std::string redactedAccessString(const ParameterMap& parameters); - - /// @brief Convenience method checking if database should be opened with - /// read only access. - /// - /// @return true if "readonly" parameter is specified and set to true; - /// false if "readonly" parameter is not specified or it is specified - /// and set to false. - bool configuredReadOnly() const; - - /// @brief Defines a callback prototype for propogating events upward - typedef boost::function<bool (ReconnectCtlPtr db_retry)> DbLostCallback; - - /// @brief Invokes the connection's lost connectivity callback - /// - /// This function may be called by derivations when the connectivity - /// to their data server is lost. If connectivity callback was specified, - /// this function will instantiate a ReconnectCtl and pass it to the - /// callback. - /// - /// @return Returns the result of the callback or false if there is no - /// callback. - bool invokeDbLostCallback() const; - - /// @brief Optional call back function to invoke if a successfully - /// open connection subsequently fails - static DbLostCallback db_lost_callback; - -private: - - /// @brief List of parameters passed in dbconfig - /// - /// That will be mostly used for storing database name, username, - /// password and other parameters required for DB access. It is not - /// intended to keep any DHCP-related parameters. - ParameterMap parameters_; - -}; - -}; // end of isc::dhcp namespace -}; // end of isc namespace - -#endif // DATABASE_CONNECTION_H diff --git a/src/lib/dhcpsrv/dhcpsrv_db_log.cc b/src/lib/dhcpsrv/dhcpsrv_db_log.cc deleted file mode 100644 index 4afff06545..0000000000 --- a/src/lib/dhcpsrv/dhcpsrv_db_log.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -/// Defines the logger used by the NSAS - -#include <config.h> - -#include <dhcpsrv/dhcpsrv_db_log.h> -#include <dhcpsrv/dhcpsrv_log.h> - -using namespace isc::db; - -namespace isc { -namespace dhcp { - -const DbLogger::MessageMap dhcpsrv_db_message_map = { - { DB_INVALID_ACCESS, DHCPSRV_INVALID_ACCESS }, - - { PGSQL_DEALLOC_ERROR, DHCPSRV_PGSQL_DEALLOC_ERROR }, - { PGSQL_FATAL_ERROR, DHCPSRV_PGSQL_FATAL_ERROR }, - { PGSQL_START_TRANSACTION, DHCPSRV_PGSQL_START_TRANSACTION }, - { PGSQL_COMMIT, DHCPSRV_PGSQL_COMMIT }, - { PGSQL_ROLLBACK, DHCPSRV_PGSQL_ROLLBACK }, - - { MYSQL_FATAL_ERROR, DHCPSRV_MYSQL_FATAL_ERROR }, - { MYSQL_START_TRANSACTION, DHCPSRV_MYSQL_START_TRANSACTION }, - { MYSQL_COMMIT, DHCPSRV_MYSQL_COMMIT }, - { MYSQL_ROLLBACK, DHCPSRV_MYSQL_ROLLBACK }, - - { CQL_DEALLOC_ERROR, DHCPSRV_CQL_DEALLOC_ERROR }, - { CQL_CONNECTION_BEGIN_TRANSACTION, - DHCPSRV_CQL_CONNECTION_BEGIN_TRANSACTION }, - { CQL_CONNECTION_COMMIT, DHCPSRV_CQL_CONNECTION_COMMIT }, - { CQL_CONNECTION_ROLLBACK, DHCPSRV_CQL_CONNECTION_ROLLBACK } -}; - -DbLogger dhcpsrv_db_logger(dhcpsrv_logger, dhcpsrv_db_message_map); - -// Do this initialization here! -//DbLoggerStack db_logger_stack = { dhcpsrv_db_logger }; - - -} // namespace dhcp -} // namespace isc diff --git a/src/lib/dhcpsrv/dhcpsrv_db_log.h b/src/lib/dhcpsrv/dhcpsrv_db_log.h deleted file mode 100644 index d5056243fd..0000000000 --- a/src/lib/dhcpsrv/dhcpsrv_db_log.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#ifndef DHCPSRV_DB_LOG_H -#define DHCPSRV_DB_LOG_H - -#include <database/db_log.h> - -namespace isc { -namespace dhcp { - -/// @brief DHCP server database message map -extern const db::DbLogger::MessageMap dhcpsrv_db_message_map; - -/// @brief DHCP server database Logger -/// -/// It is the default database logger. -extern db::DbLogger dhcpsrv_db_logger; - -} // namespace dhcp -} // namespace isc - -#endif // DHCPSRV_DB_LOG_H diff --git a/src/lib/dhcpsrv/host_data_source_factory.cc b/src/lib/dhcpsrv/host_data_source_factory.cc index 76b8cd595e..e80b3348c9 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.cc +++ b/src/lib/dhcpsrv/host_data_source_factory.cc @@ -34,6 +34,7 @@ #include <sstream> #include <utility> +using namespace isc::db; using namespace std; namespace isc { diff --git a/src/lib/dhcpsrv/host_data_source_factory.h b/src/lib/dhcpsrv/host_data_source_factory.h index 20f5fe7a57..113f5f944d 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.h +++ b/src/lib/dhcpsrv/host_data_source_factory.h @@ -7,8 +7,8 @@ #ifndef HOST_DATA_SOURCE_FACTORY_H #define HOST_DATA_SOURCE_FACTORY_H +#include <database/database_connection.h> #include <dhcpsrv/base_host_data_source.h> -#include <dhcpsrv/database_connection.h> #include <exceptions/exceptions.h> #include <boost/scoped_ptr.hpp> #include <boost/function.hpp> @@ -79,7 +79,7 @@ public: /// /// A factory takes a parameter map and returns a pointer to a host /// data source. In case of failure it must throw and not return NULL. - typedef boost::function<HostDataSourcePtr (const DatabaseConnection::ParameterMap&)> Factory; + typedef boost::function<HostDataSourcePtr (const db::DatabaseConnection::ParameterMap&)> Factory; /// @brief Register a host data source factory /// diff --git a/src/lib/dhcpsrv/host_mgr.h b/src/lib/dhcpsrv/host_mgr.h index bc7b6c211c..fa6248f025 100644 --- a/src/lib/dhcpsrv/host_mgr.h +++ b/src/lib/dhcpsrv/host_mgr.h @@ -7,9 +7,9 @@ #ifndef HOST_MGR_H #define HOST_MGR_H +#include <database/database_connection.h> #include <dhcpsrv/base_host_data_source.h> #include <dhcpsrv/cache_host_data_source.h> -#include <dhcpsrv/database_connection.h> #include <dhcpsrv/host.h> #include <dhcpsrv/subnet_id.h> #include <boost/noncopyable.hpp> diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index 235b3495e3..b314f8d707 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -25,6 +25,7 @@ #include <time.h> +using namespace isc::db; using namespace std; namespace isc { diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index 167645ee32..99e8ec936e 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -537,7 +537,7 @@ public: /// /// @return true if deletion was successful, false if no such lease exists /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool deleteLease(const isc::asiolink::IOAddress& addr) = 0; diff --git a/src/lib/dhcpsrv/lease_mgr_factory.cc b/src/lib/dhcpsrv/lease_mgr_factory.cc index 0e5251cd09..73b2734a98 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.cc +++ b/src/lib/dhcpsrv/lease_mgr_factory.cc @@ -29,6 +29,7 @@ #include <sstream> #include <utility> +using namespace isc::db; using namespace std; namespace isc { diff --git a/src/lib/dhcpsrv/lease_mgr_factory.h b/src/lib/dhcpsrv/lease_mgr_factory.h index 1ac67046b5..9938643868 100644 --- a/src/lib/dhcpsrv/lease_mgr_factory.h +++ b/src/lib/dhcpsrv/lease_mgr_factory.h @@ -7,8 +7,8 @@ #ifndef LEASE_MGR_FACTORY_H #define LEASE_MGR_FACTORY_H +#include <database/database_connection.h> #include <dhcpsrv/lease_mgr.h> -#include <dhcpsrv/database_connection.h> #include <exceptions/exceptions.h> #include <boost/scoped_ptr.hpp> diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 57563edd9b..58e80bcfa9 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -5,12 +5,12 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include <config.h> +#include <database/database_connection.h> #include <dhcpsrv/cfgmgr.h> #include <dhcpsrv/dhcpsrv_log.h> #include <dhcpsrv/lease_file_loader.h> #include <dhcpsrv/memfile_lease_mgr.h> #include <dhcpsrv/timer_mgr.h> -#include <dhcpsrv/database_connection.h> #include <exceptions/exceptions.h> #include <util/pid_file.h> #include <util/process_spawn.h> @@ -39,6 +39,7 @@ const char* KEA_LFC_EXECUTABLE_ENV_NAME = "KEA_LFC_EXECUTABLE"; } // end of anonymous namespace using namespace isc::asiolink; +using namespace isc::db; using namespace isc::util; namespace isc { diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.h b/src/lib/dhcpsrv/memfile_lease_mgr.h index 2db242b0b6..dc4e07fc62 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.h +++ b/src/lib/dhcpsrv/memfile_lease_mgr.h @@ -8,11 +8,11 @@ #define MEMFILE_LEASE_MGR_H #include <asiolink/interval_timer.h> +#include <database/database_connection.h> #include <dhcp/hwaddr.h> #include <dhcpsrv/csv_lease_file4.h> #include <dhcpsrv/csv_lease_file6.h> #include <dhcpsrv/memfile_lease_storage.h> -#include <dhcpsrv/database_connection.h> #include <dhcpsrv/lease_mgr.h> #include <util/process_spawn.h> @@ -130,7 +130,7 @@ public: /// /// @param parameters A data structure relating keywords and values /// concerned with the database. - Memfile_LeaseMgr(const DatabaseConnection::ParameterMap& parameters); + Memfile_LeaseMgr(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Destructor (closes file) virtual ~Memfile_LeaseMgr(); @@ -838,7 +838,7 @@ private: /// /// DatabaseConnection object is used only for storing, accessing and /// printing parameter map. - DatabaseConnection conn_; + db::DatabaseConnection conn_; //@} }; diff --git a/src/lib/dhcpsrv/mysql_connection.cc b/src/lib/dhcpsrv/mysql_connection.cc index 7929aa3924..6f9785ed3e 100644 --- a/src/lib/dhcpsrv/mysql_connection.cc +++ b/src/lib/dhcpsrv/mysql_connection.cc @@ -19,6 +19,7 @@ #include <limits> using namespace isc; +using namespace isc::db; using namespace isc::dhcp; using namespace std; diff --git a/src/lib/dhcpsrv/mysql_connection.h b/src/lib/dhcpsrv/mysql_connection.h index 5ad549d61d..ca29521386 100644 --- a/src/lib/dhcpsrv/mysql_connection.h +++ b/src/lib/dhcpsrv/mysql_connection.h @@ -231,7 +231,7 @@ public: /// to be valid, else an exception will be thrown. /// @param text Text of the SQL statement to be prepared. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. /// @throw isc::InvalidParameter 'index' is not valid for the vector. void prepareStatement(uint32_t index, const char* text); @@ -246,7 +246,7 @@ public: /// @param end_statement Pointer to the statement marking end of the /// range of statements to be compiled. This last statement is not compiled. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. /// @throw isc::InvalidParameter 'index' is not valid for the vector. This /// represents an internal error within the code. @@ -373,7 +373,7 @@ public: /// @tparam Enumeration representing index of a statement to which an /// error pertains. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. template<typename StatementIndex> void checkError(const int status, const StatementIndex& index, @@ -390,7 +390,7 @@ public: case CR_SERVER_LOST: case CR_OUT_OF_MEMORY: case CR_CONNECTION_ERROR: - DB_LOG_ERROR(MYSQL_FATAL_ERROR) + DB_LOG_ERROR(db::MYSQL_FATAL_ERROR) .arg(what) .arg(text_statements_[static_cast<int>(index)]) .arg(mysql_error(mysql_)) @@ -404,11 +404,11 @@ public: // We still need to throw so caller can error out of the current // processing. - isc_throw(DbOperationError, + isc_throw(db::DbOperationError, "fatal database errror or connectivity lost"); default: // Connection is ok, so it must be an SQL error - isc_throw(DbOperationError, what << " for <" + isc_throw(db::DbOperationError, what << " for <" << text_statements_[static_cast<int>(index)] << ">, reason: " << mysql_error(mysql_) << " (error code " diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index 513f025b6f..b5e62a7a0b 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -6,15 +6,14 @@ #include <config.h> +#include <database/db_exceptions.h> #include <dhcp/libdhcp++.h> #include <dhcp/option.h> #include <dhcp/option_definition.h> #include <dhcp/option_space.h> #include <dhcpsrv/cfg_option.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/dhcpsrv_log.h> #include <dhcpsrv/mysql_host_data_source.h> -#include <dhcpsrv/db_exceptions.h> #include <util/buffer.h> #include <util/optional_value.h> @@ -32,6 +31,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::util; using namespace isc::data; @@ -1991,7 +1991,7 @@ public: /// @param bind Vector of MYSQL_BIND objects to be used when making the /// query. /// - /// @throw isc::dhcp::DuplicateEntry Database throws duplicate entry error + /// @throw isc::db::DuplicateEntry Database throws duplicate entry error void addStatement(MySqlHostDataSourceImpl::StatementIndex stindex, std::vector<MYSQL_BIND>& bind); diff --git a/src/lib/dhcpsrv/mysql_host_data_source.h b/src/lib/dhcpsrv/mysql_host_data_source.h index 5e47c1dc12..719aa04fe0 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.h +++ b/src/lib/dhcpsrv/mysql_host_data_source.h @@ -49,11 +49,11 @@ public: /// concerned with the database. /// /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database or the + /// @throw isc::db::DbOpenError Error opening the database or the /// schema version is invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - MySqlHostDataSource(const DatabaseConnection::ParameterMap& parameters); + MySqlHostDataSource(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Virtual destructor. /// @@ -237,7 +237,7 @@ public: /// integers. "first" is the major version number, "second" the /// minor number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database + /// @throw isc::db::DbOperationError An operation on the open database /// has failed. virtual std::pair<uint32_t, uint32_t> getVersion() const; diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 2d5fbf6c33..2ba750c89e 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -26,6 +26,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::data; using namespace std; diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h index 4a3975359f..08aab94817 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h @@ -53,11 +53,11 @@ public: /// concerned with the database. /// /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database or the schema + /// @throw isc::db::DbOpenError Error opening the database or the schema /// version is incorrect. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters); + MySqlLeaseMgr(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Destructor (closes database) virtual ~MySqlLeaseMgr(); @@ -72,7 +72,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease4Ptr& lease); @@ -83,7 +83,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease6Ptr& lease); @@ -103,7 +103,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const; @@ -122,7 +122,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const; @@ -140,7 +140,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr, SubnetID subnet_id) const; @@ -159,7 +159,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const ClientId& clientid) const; @@ -189,7 +189,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const ClientId& clientid, SubnetID subnet_id) const; @@ -250,7 +250,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress& addr) const; @@ -273,7 +273,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, uint32_t iaid) const; @@ -292,7 +292,7 @@ public: /// @throw isc::dhcp::DataTruncation Data was truncated on retrieval to /// fit into the space allocated for the result. This indicates a /// programming error. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, uint32_t iaid, SubnetID subnet_id) const; @@ -377,9 +377,9 @@ public: /// /// @param lease4 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not /// exist. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease4(const Lease4Ptr& lease4); @@ -390,9 +390,9 @@ public: /// /// @param lease6 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not /// exist. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease6(const Lease6Ptr& lease6); @@ -403,7 +403,7 @@ public: /// /// @return true if deletion was successful, false if no such lease exists /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool deleteLease(const isc::asiolink::IOAddress& addr); @@ -544,7 +544,7 @@ public: /// @return Version number as a pair of unsigned integers. "first" is the /// major version number, "second" the minor number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual std::pair<uint32_t, uint32_t> getVersion() const; @@ -616,7 +616,7 @@ private: /// @return true if the lease was added, false if it was not added because /// a lease with that address already exists in the database. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. bool addLeaseCommon(StatementIndex stindex, std::vector<MYSQL_BIND>& bind); @@ -636,9 +636,9 @@ private: /// be thrown. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. template <typename Exchange, typename LeaseCollection> void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* bind, @@ -657,9 +657,9 @@ private: /// new data is appended to the end. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* bind, Lease4Collection& result) const { @@ -677,9 +677,9 @@ private: /// data in the collection is erased first. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. void getLeaseCollection(StatementIndex stindex, MYSQL_BIND* bind, Lease6Collection& result) const { @@ -744,7 +744,7 @@ private: /// /// @throw NoSuchLease Could not update a lease because no lease matches /// the address given. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. template <typename LeasePtr> void updateLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind, @@ -763,7 +763,7 @@ private: /// /// @return Number of deleted leases. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. uint64_t deleteLeaseCommon(StatementIndex stindex, MYSQL_BIND* bind); @@ -787,7 +787,7 @@ private: /// @param index Index of statement that caused the error /// @param what High-level description of the error /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. void checkError(int status, StatementIndex index, const char* what) const; diff --git a/src/lib/dhcpsrv/pgsql_connection.cc b/src/lib/dhcpsrv/pgsql_connection.cc index a64ce7f779..29b1f1dd8e 100644 --- a/src/lib/dhcpsrv/pgsql_connection.cc +++ b/src/lib/dhcpsrv/pgsql_connection.cc @@ -6,7 +6,7 @@ #include <config.h> -#include <dhcpsrv/db_log.h> +#include <database/db_log.h> #include <dhcpsrv/pgsql_connection.h> // PostgreSQL errors should be tested based on the SQL state code. Each state @@ -25,6 +25,7 @@ #define PGSQL_STATECODE_LEN 5 #include <utils/errcodes.h> +using namespace isc::db; using namespace std; namespace isc { @@ -55,7 +56,7 @@ PgSqlResult::PgSqlResult(PGresult *result) void PgSqlResult::rowCheck(int row) const { if (row < 0 || row >= rows_) { - isc_throw (DbOperationError, "row: " << row + isc_throw (db::DbOperationError, "row: " << row << ", out of range: 0.." << rows_); } } diff --git a/src/lib/dhcpsrv/pgsql_connection.h b/src/lib/dhcpsrv/pgsql_connection.h index 081aeedd49..20b3f3ffe1 100644 --- a/src/lib/dhcpsrv/pgsql_connection.h +++ b/src/lib/dhcpsrv/pgsql_connection.h @@ -296,7 +296,7 @@ private: /// to the database and preparing compiled statements. Its fields are /// public, because they are used (both set and retrieved) in classes /// that use instances of PgSqlConnection. -class PgSqlConnection : public DatabaseConnection { +class PgSqlConnection : public db::DatabaseConnection { public: /// @brief Define the PgSql error state for a duplicate key error. static const char DUPLICATE_KEY[]; diff --git a/src/lib/dhcpsrv/pgsql_exchange.cc b/src/lib/dhcpsrv/pgsql_exchange.cc index 713ad8acd8..f32d07ca63 100644 --- a/src/lib/dhcpsrv/pgsql_exchange.cc +++ b/src/lib/dhcpsrv/pgsql_exchange.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -14,6 +14,8 @@ #include <sstream> #include <vector> +using namespace isc::db; + namespace isc { namespace dhcp { diff --git a/src/lib/dhcpsrv/pgsql_exchange.h b/src/lib/dhcpsrv/pgsql_exchange.h index 381b4b1891..fd506dd26c 100644 --- a/src/lib/dhcpsrv/pgsql_exchange.h +++ b/src/lib/dhcpsrv/pgsql_exchange.h @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -355,7 +355,7 @@ public: try { value = boost::lexical_cast<T>(data); } catch (const std::exception& ex) { - isc_throw(DbOperationError, "Invalid data:[" << data + isc_throw(db::DbOperationError, "Invalid data:[" << data << "] for row: " << row << " col: " << col << "," << getColumnLabel(r, col) << " : " << ex.what()); } diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.cc b/src/lib/dhcpsrv/pgsql_host_data_source.cc index 2acf36e068..6c2aa8cb5d 100644 --- a/src/lib/dhcpsrv/pgsql_host_data_source.cc +++ b/src/lib/dhcpsrv/pgsql_host_data_source.cc @@ -6,15 +6,14 @@ #include <config.h> +#include <database/db_exceptions.h> #include <dhcp/libdhcp++.h> #include <dhcp/option.h> #include <dhcp/option_definition.h> #include <dhcp/option_space.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/cfg_option.h> #include <dhcpsrv/dhcpsrv_log.h> #include <dhcpsrv/pgsql_host_data_source.h> -#include <dhcpsrv/db_exceptions.h> #include <util/buffer.h> #include <util/optional_value.h> @@ -29,6 +28,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::util; using namespace isc::data; @@ -1326,7 +1326,7 @@ public: /// @return 0 if return_last_id is false, otherwise it returns the /// the value in the result set in the first col of the first row. /// - /// @throw isc::dhcp::DuplicateEntry Database throws duplicate entry error + /// @throw isc::db::DuplicateEntry Database throws duplicate entry error uint64_t addStatement(PgSqlHostDataSourceImpl::StatementIndex stindex, PsqlBindArrayPtr& bind, const bool return_last_id = false); @@ -1429,7 +1429,7 @@ public: /// integers. "first" is the major version number, "second" the /// minor number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database + /// @throw isc::db::DbOperationError An operation on the open database /// has failed. std::pair<uint32_t, uint32_t> getVersion() const; diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.h b/src/lib/dhcpsrv/pgsql_host_data_source.h index 569c0cf2fe..5da08a89e8 100644 --- a/src/lib/dhcpsrv/pgsql_host_data_source.h +++ b/src/lib/dhcpsrv/pgsql_host_data_source.h @@ -53,11 +53,11 @@ public: /// @param parameters A data structure relating keywords and values /// concerned with the database. /// - /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::NoDatabaseName Mandatory database name not given + /// @throw isc::db::DbOpenError Error opening the database + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - PgSqlHostDataSource(const DatabaseConnection::ParameterMap& parameters); + PgSqlHostDataSource(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Virtual destructor. /// Frees database resources and closes the database connection through diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index 3ec3d50bf9..a30eea14e6 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -22,6 +22,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::data; using namespace std; diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.h b/src/lib/dhcpsrv/pgsql_lease_mgr.h index e6ea524243..9bb58ec2d7 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.h +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.h @@ -52,10 +52,10 @@ public: /// concerned with the database. /// /// @throw isc::dhcp::NoDatabaseName Mandatory database name not given - /// @throw isc::dhcp::DbOpenError Error opening the database - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOpenError Error opening the database + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters); + PgSqlLeaseMgr(const db::DatabaseConnection::ParameterMap& parameters); /// @brief Destructor (closes database) virtual ~PgSqlLeaseMgr(); @@ -69,7 +69,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease4Ptr& lease); @@ -80,7 +80,7 @@ public: /// @result true if the lease was added, false if not (because a lease /// with the same address was already there). /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool addLease(const Lease6Ptr& lease); @@ -97,7 +97,7 @@ public: /// /// @return smart pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::asiolink::IOAddress& addr) const; @@ -112,7 +112,7 @@ public: /// /// @return lease collection /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const isc::dhcp::HWAddr& hwaddr) const; @@ -127,7 +127,7 @@ public: /// /// @return a pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const isc::dhcp::HWAddr& hwaddr, SubnetID subnet_id) const; @@ -143,7 +143,7 @@ public: /// /// @return lease collection /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Collection getLease4(const ClientId& clientid) const; @@ -170,7 +170,7 @@ public: /// /// @return a pointer to the lease (or NULL if a lease is not found) /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease4Ptr getLease4(const ClientId& clientid, SubnetID subnet_id) const; @@ -228,7 +228,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Ptr getLease6(Lease::Type type, const isc::asiolink::IOAddress& addr) const; @@ -248,7 +248,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, uint32_t iaid) const; @@ -264,7 +264,7 @@ public: /// /// @throw isc::BadValue record retrieved from database had an invalid /// lease type field. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid, uint32_t iaid, SubnetID subnet_id) const; @@ -349,9 +349,9 @@ public: /// /// @param lease4 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not /// exist. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease4(const Lease4Ptr& lease4); @@ -362,9 +362,9 @@ public: /// /// @param lease6 The lease to be updated. /// - /// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not + /// @throw isc::db::NoSuchLease Attempt to update a lease that did not /// exist. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual void updateLease6(const Lease6Ptr& lease6); @@ -375,7 +375,7 @@ public: /// /// @return true if deletion was successful, false if no such lease exists /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual bool deleteLease(const isc::asiolink::IOAddress& addr); @@ -513,7 +513,7 @@ public: /// @return Version number as a pair of unsigned integers. "first" is the /// major version number, "second" the minor number. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. virtual std::pair<uint32_t, uint32_t> getVersion() const; @@ -585,7 +585,7 @@ private: /// @return true if the lease was added, false if it was not added because /// a lease with that address already exists in the database. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. bool addLeaseCommon(StatementIndex stindex, PsqlBindArray& bind_array); @@ -605,9 +605,9 @@ private: /// be thrown. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. template <typename Exchange, typename LeaseCollection> void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array, @@ -626,9 +626,9 @@ private: /// new data is appended to the end. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array, Lease4Collection& result) const { @@ -646,9 +646,9 @@ private: /// data in the collection is erased first. /// /// @throw isc::dhcp::BadValue Data retrieved from the database was invalid. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. - /// @throw isc::dhcp::MultipleRecords Multiple records were retrieved + /// @throw isc::db::MultipleRecords Multiple records were retrieved /// from the database where only one was expected. void getLeaseCollection(StatementIndex stindex, PsqlBindArray& bind_array, Lease6Collection& result) const { @@ -711,7 +711,7 @@ private: /// /// @throw NoSuchLease Could not update a lease because no lease matches /// the address given. - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. template <typename LeasePtr> void updateLeaseCommon(StatementIndex stindex, PsqlBindArray& bind_array, @@ -729,7 +729,7 @@ private: /// /// @return Number of deleted leases. /// - /// @throw isc::dhcp::DbOperationError An operation on the open database has + /// @throw isc::db::DbOperationError An operation on the open database has /// failed. uint64_t deleteLeaseCommon(StatementIndex stindex, PsqlBindArray& bind_array); diff --git a/src/lib/dhcpsrv/tests/Makefile.am b/src/lib/dhcpsrv/tests/Makefile.am index d2ec70d85b..4ab3d56125 100644 --- a/src/lib/dhcpsrv/tests/Makefile.am +++ b/src/lib/dhcpsrv/tests/Makefile.am @@ -85,7 +85,6 @@ libdhcpsrv_unittests_SOURCES += csv_lease_file6_unittest.cc libdhcpsrv_unittests_SOURCES += d2_client_unittest.cc libdhcpsrv_unittests_SOURCES += d2_udp_unittest.cc libdhcpsrv_unittests_SOURCES += daemon_unittest.cc -libdhcpsrv_unittests_SOURCES += database_connection_unittest.cc libdhcpsrv_unittests_SOURCES += dbaccess_parser_unittest.cc libdhcpsrv_unittests_SOURCES += dhcp4o6_ipc_unittest.cc libdhcpsrv_unittests_SOURCES += duid_config_parser_unittest.cc @@ -172,6 +171,7 @@ libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la +libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/database/libkea-database.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/log/libkea-log.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la libdhcpsrv_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la diff --git a/src/lib/dhcpsrv/tests/alloc_engine_utils.h b/src/lib/dhcpsrv/tests/alloc_engine_utils.h index 9a0e9b5b66..e7207a561d 100644 --- a/src/lib/dhcpsrv/tests/alloc_engine_utils.h +++ b/src/lib/dhcpsrv/tests/alloc_engine_utils.h @@ -153,7 +153,7 @@ public: /// @return Lease6 pointer (or NULL if collection was empty) Lease6Ptr expectOneLease(const Lease6Collection& col) { if (col.size() > 1) { - isc_throw(MultipleRecords, "More than one lease found in collection"); + isc_throw(db::MultipleRecords, "More than one lease found in collection"); } if (col.empty()) { return (Lease6Ptr()); diff --git a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc index 3c54332927..0afdf5dc27 100644 --- a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc @@ -40,6 +40,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::data; diff --git a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc index 43984bcdf7..6fb33717bf 100644 --- a/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc @@ -37,6 +37,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace std; diff --git a/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc b/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc index b963306f9c..0b8f833f16 100644 --- a/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc @@ -21,6 +21,7 @@ using namespace std; using namespace isc; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::data; diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index dcb4bafef4..245c5fca49 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -7,13 +7,13 @@ #include <config.h> #include <asiolink/io_address.h> -#include <exceptions/exceptions.h> +#include <database/database_connection.h> +#include <database/db_exceptions.h> #include <dhcpsrv/cfgmgr.h> -#include <dhcpsrv/database_connection.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/lease_mgr_factory.h> #include <dhcpsrv/tests/generic_lease_mgr_unittest.h> #include <dhcpsrv/tests/test_utils.h> +#include <exceptions/exceptions.h> #include <stats/stats_mgr.h> #include <boost/foreach.hpp> @@ -27,6 +27,7 @@ using namespace std; using namespace isc::asiolink; using namespace isc::data; +using namespace isc::db; namespace isc { namespace dhcp { @@ -1052,7 +1053,7 @@ GenericLeaseMgrTest::testGetLease4HWAddrSize() { // Database should not let us add one that is too big // (The 42 is a random value put in each byte of the address.) leases[1]->hwaddr_->hwaddr_.resize(HWAddr::MAX_HWADDR_LEN + 100, 42); - EXPECT_THROW(lmptr_->addLease(leases[1]), isc::dhcp::DbOperationError); + EXPECT_THROW(lmptr_->addLease(leases[1]), isc::db::DbOperationError); } void @@ -1104,7 +1105,7 @@ GenericLeaseMgrTest::testGetLease4HWAddrSubnetId() { /// @todo: Simply use HWAddr directly once 2589 is implemented EXPECT_THROW(returned = lmptr_->getLease4(*leases[1]->hwaddr_, leases[1]->subnet_id_), - isc::dhcp::MultipleRecords); + isc::db::MultipleRecords); } @@ -1129,7 +1130,7 @@ GenericLeaseMgrTest::testGetLease4HWAddrSubnetIdSize() { // Database should not let us add one that is too big // (The 42 is a random value put in each byte of the address.) leases[1]->hwaddr_->hwaddr_.resize(HWAddr::MAX_HWADDR_LEN + 100, 42); - EXPECT_THROW(lmptr_->addLease(leases[1]), isc::dhcp::DbOperationError); + EXPECT_THROW(lmptr_->addLease(leases[1]), isc::db::DbOperationError); } void @@ -1752,11 +1753,11 @@ GenericLeaseMgrTest::testUpdateLease4() { // Try to update the lease with the too long hostname. leases[1]->hostname_.assign(256, 'a'); - EXPECT_THROW(lmptr_->updateLease4(leases[1]), isc::dhcp::DbOperationError); + EXPECT_THROW(lmptr_->updateLease4(leases[1]), isc::db::DbOperationError); // Try updating a lease not in the database. lmptr_->deleteLease(ioaddress4_[2]); - EXPECT_THROW(lmptr_->updateLease4(leases[2]), isc::dhcp::NoSuchLease); + EXPECT_THROW(lmptr_->updateLease4(leases[2]), isc::db::NoSuchLease); } void @@ -1812,10 +1813,10 @@ GenericLeaseMgrTest::testUpdateLease6() { // Try to update the lease with the too long hostname. leases[1]->hostname_.assign(256, 'a'); - EXPECT_THROW(lmptr_->updateLease6(leases[1]), isc::dhcp::DbOperationError); + EXPECT_THROW(lmptr_->updateLease6(leases[1]), isc::db::DbOperationError); // Try updating a lease not in the database. - EXPECT_THROW(lmptr_->updateLease6(leases[2]), isc::dhcp::NoSuchLease); + EXPECT_THROW(lmptr_->updateLease6(leases[2]), isc::db::NoSuchLease); } void diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h index fe7ecdce0c..5da24ffa07 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h @@ -467,11 +467,11 @@ public: class LeaseMgrDbLostCallbackTest : public ::testing::Test { public: LeaseMgrDbLostCallbackTest() { - DatabaseConnection::db_lost_callback = 0; + db::DatabaseConnection::db_lost_callback = 0; } virtual ~LeaseMgrDbLostCallbackTest() { - DatabaseConnection::db_lost_callback = 0; + db::DatabaseConnection::db_lost_callback = 0; } /// @brief Prepares the class for a test. @@ -520,7 +520,7 @@ public: void testDbLostCallback(); /// @brief Callback function registered with the host manager - bool db_lost_callback(ReconnectCtlPtr /* not_used */) { + bool db_lost_callback(db::ReconnectCtlPtr /* not_used */) { return (callback_called_ = true); } diff --git a/src/lib/dhcpsrv/tests/host_cache_unittest.cc b/src/lib/dhcpsrv/tests/host_cache_unittest.cc index 0f589f0db1..2a3d4269a9 100644 --- a/src/lib/dhcpsrv/tests/host_cache_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_cache_unittest.cc @@ -21,6 +21,7 @@ using namespace std; using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; diff --git a/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc b/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc index 596b908a8e..dba626d866 100644 --- a/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc @@ -17,6 +17,7 @@ using namespace std; using namespace isc; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; diff --git a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc index 9432ae9468..0fb3bf5175 100644 --- a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc @@ -29,6 +29,7 @@ #include <vector> using namespace isc; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::asiolink; diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc index 63969acc1b..da389a56aa 100644 --- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc @@ -22,6 +22,7 @@ using namespace std; using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 2dfc829769..263d24a4d1 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -35,6 +35,7 @@ using namespace std; using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::util; diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index 8c88716993..356b776216 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -28,6 +28,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::data; diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index af9f572570..c5f1c4c361 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -25,6 +25,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace std; diff --git a/src/lib/dhcpsrv/tests/pgsql_exchange_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_exchange_unittest.cc index 6f6ba77dc5..df3339aa6d 100644 --- a/src/lib/dhcpsrv/tests/pgsql_exchange_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_exchange_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -17,6 +17,7 @@ #include <vector> using namespace isc; +using namespace isc::db; using namespace isc::dhcp; namespace { diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index f20d27279a..f892a58817 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -28,6 +28,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace isc::data; diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 47fed01580..4a128b40b3 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -25,6 +25,7 @@ using namespace isc; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::dhcp; using namespace isc::dhcp::test; using namespace std; diff --git a/src/lib/dhcpsrv/testutils/Makefile.am b/src/lib/dhcpsrv/testutils/Makefile.am index f825e6a2f3..257a4612e4 100644 --- a/src/lib/dhcpsrv/testutils/Makefile.am +++ b/src/lib/dhcpsrv/testutils/Makefile.am @@ -54,7 +54,8 @@ if HAVE_CQL libdhcpsrvtest_la_LDFLAGS += $(CQL_LIBS) endif -libdhcpsrvtest_la_LIBADD = $(top_builddir)/src/lib/cc/libkea-cc.la +libdhcpsrvtest_la_LIBADD = $(top_builddir)/src/lib/database/libkea-database.la +libdhcpsrvtest_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la libdhcpsrvtest_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la endif diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index 2a863fd197..e6b797f0c4 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -6,6 +6,8 @@ #include <config.h> +#include <database/database_connection.h> +#include <database/db_exceptions.h> #include <dhcp/dhcp6.h> #include <dhcp/libdhcp++.h> #include <dhcp/option4_addrlst.h> @@ -13,8 +15,6 @@ #include <dhcp/option_int.h> #include <dhcp/option_string.h> #include <dhcp/option_vendor.h> -#include <dhcpsrv/database_connection.h> -#include <dhcpsrv/db_exceptions.h> #include <dhcpsrv/host_mgr.h> #include <dhcpsrv/host_data_source_factory.h> #include <dhcpsrv/testutils/generic_host_data_source_unittest.h> @@ -34,6 +34,7 @@ using namespace std; using namespace isc::asiolink; +using namespace isc::db; using namespace isc::util; using namespace isc::data; diff --git a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc index 9ce958b169..d5589476f5 100644 --- a/src/lib/dhcpsrv/testutils/memory_host_data_source.cc +++ b/src/lib/dhcpsrv/testutils/memory_host_data_source.cc @@ -8,6 +8,7 @@ #include <dhcpsrv/testutils/memory_host_data_source.h> +using namespace isc::db; using namespace std; namespace isc { diff --git a/src/lib/dhcpsrv/testutils/memory_host_data_source.h b/src/lib/dhcpsrv/testutils/memory_host_data_source.h index d95ba9a282..ce43090e0b 100644 --- a/src/lib/dhcpsrv/testutils/memory_host_data_source.h +++ b/src/lib/dhcpsrv/testutils/memory_host_data_source.h @@ -205,7 +205,7 @@ typedef boost::shared_ptr<MemHostDataSource> MemHostDataSourcePtr; /// @param parameters /// @return A pointer to a base host data source instance. HostDataSourcePtr -memFactory(const DatabaseConnection::ParameterMap& /*parameters*/); +memFactory(const db::DatabaseConnection::ParameterMap& /*parameters*/); } // namespace isc::dhcp::test } // namespace isc::dhcp |