]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#92,!13] Refactored libkea-dhcpsrv to use libkea-database
authorMarcin Siodelski <marcin@isc.org>
Tue, 28 Aug 2018 11:09:25 +0000 (13:09 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 3 Sep 2018 07:31:33 +0000 (03:31 -0400)
72 files changed:
src/bin/dhcp4/Makefile.am
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp6/Makefile.am
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.h
src/bin/dhcp6/tests/Makefile.am
src/lib/database/.gitignore [new file with mode: 0644]
src/lib/database/Makefile.am
src/lib/database/database_log.cc [new file with mode: 0644]
src/lib/database/database_log.h [new file with mode: 0644]
src/lib/database/db_log.cc
src/lib/database/db_log.h
src/lib/database/db_messages.mes [new file with mode: 0644]
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_db_access.h
src/lib/dhcpsrv/cql_connection.cc
src/lib/dhcpsrv/cql_connection.h
src/lib/dhcpsrv/cql_exchange.cc
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/cql_host_data_source.h
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/database_connection.cc [deleted file]
src/lib/dhcpsrv/database_connection.h [deleted file]
src/lib/dhcpsrv/dhcpsrv_db_log.cc [deleted file]
src/lib/dhcpsrv/dhcpsrv_db_log.h [deleted file]
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/host_data_source_factory.h
src/lib/dhcpsrv/host_mgr.h
src/lib/dhcpsrv/lease_mgr.cc
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/lease_mgr_factory.cc
src/lib/dhcpsrv/lease_mgr_factory.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/mysql_connection.cc
src/lib/dhcpsrv/mysql_connection.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/mysql_host_data_source.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/pgsql_connection.cc
src/lib/dhcpsrv/pgsql_connection.h
src/lib/dhcpsrv/pgsql_exchange.cc
src/lib/dhcpsrv/pgsql_exchange.h
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.h
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.h
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/alloc_engine_utils.h
src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
src/lib/dhcpsrv/tests/host_cache_unittest.cc
src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc
src/lib/dhcpsrv/tests/host_mgr_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_exchange_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/Makefile.am
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.cc
src/lib/dhcpsrv/testutils/memory_host_data_source.h

index cc19d70882d5ca4b2a7754b52741806644e52448..5486dfe500652e198ee66be9769e4dfc4a74da97 100644 (file)
@@ -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
index 6f62bd5642761a774e7227d86694fadf5c97498d..25a13d88dd695c9943f2cb413ba1552820e46574 100644 (file)
@@ -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;
index 06d5ee6472c6791bb7c6ffb8d657d88f5ddc186d..1978a5880d3b6340eb96e8b193fe252e0cd7e374 100644 (file)
@@ -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.
     ///
index d9d58779d9164df62a461edf8f318f1134380d6b..e02b18a9c9870b5576f091d84616161e5e7b8d00 100644 (file)
@@ -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
index 88cfdec69e20cb7bc7eae09b4acf0424f7844170..ff14c320d86f23e1d5e4c3621ddf830203fd8dd9 100644 (file)
@@ -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
index e50ed9fef9c8dbd9b90f389e8f12077ed9998d73..ffd6ac6e8dce05e2a17954ec15d436f659409579 100644 (file)
@@ -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;
index 31e738a91ed170f0765942f5b2a9fc655044c862..a747fec833d4916595ec56042af49435971988f4 100644 (file)
@@ -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.
     ///
index f862c374a13bd606a4d8da110b1d2acfcf0f0eae..6d587d5dd4d301af6de26f26af4daa786923f645 100644 (file)
@@ -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 (file)
index 0000000..1647c12
--- /dev/null
@@ -0,0 +1,3 @@
+/db_messages.cc
+/db_messages.h
+/s-messages
index fac6488b2f1bfb5aa33d914aa41a09ab788a9476..6e8a66747bcbe01ed3f517f700e49896bd681eae 100644 (file)
@@ -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 (file)
index 0000000..602a223
--- /dev/null
@@ -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 (file)
index 0000000..33b1e75
--- /dev/null
@@ -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
index 75ee637d2a9fc3c90e626455e85d49371959d5ab..8b775dba259959d89be375ef523ff05b9266ee54 100644 (file)
 
 #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 {
index de7bd9f93fdf85f4d34a31746a5c0f6f24ada888..5096ad9543b8d6fe52b09e555a483143f9f9ba09 100644 (file)
@@ -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 (file)
index 0000000..9d26a06
--- /dev/null
@@ -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.
index 77817aef12a49b49883352401aeccfb68ad0b7b2..13fccc288516dca6e8cd2c1131dce87d49e36f16 100644 (file)
@@ -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 \
index f3f043983d24488025883d6d81df23ace568ee26..db4ae335b8dff777abc2fd002877437b780c45a7 100644 (file)
@@ -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>
index 3b18f02a5b7ef8c7fe701a1125ccc092752031a1..3c32cff8208b20c74e2e3988274290089fa16c96 100644 (file)
@@ -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>
 
 #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 {
 
index 9d81d93626e0b4aef8042e07ffb0f34201100c3e..f7bb96313352612e50f90d6f65030611adc032ca 100644 (file)
@@ -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.
index c84d7b72f43fb1e71017ba843ea90b9f509617cb..75a5a8911cf254cddd85e2f74c5fa80007147b07 100644 (file)
@@ -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 {
 
index 25375f5fc7d08932b19edff8a10a12868324dd91..56ad30ca2045750f52b1f6b5921a574d712261ec 100644 (file)
@@ -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;
index 2d472ff76e58fe21edbf822de39c01464108e619..091372bc09a80c23d251cfea585864b73d5358ed 100644 (file)
@@ -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;
 
index 5b41e6d852ca16c21eaccb2f3b7fef821bb079a6..79f184c11d6ea886ff5d6e0c53a1db62eada246e 100644 (file)
@@ -27,6 +27,7 @@
 #include <asiolink/io_address.h>
 
 using namespace isc::data;
+using namespace isc::db;
 using isc::asiolink::IOAddress;
 
 namespace isc {
index 5b7650786abf102651232712e9aac56c1e30c50d..89600fa3d4deeabd373852797e60209651eaa9f2 100644 (file)
@@ -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 (file)
index 6363492..0000000
+++ /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 (file)
index 8dcbe56..0000000
+++ /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 (file)
index 4afff06..0000000
+++ /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 (file)
index d505624..0000000
+++ /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
index 76b8cd595e973eac5157d6ae7c24466ec8117ea3..e80b3348c910d52e9a1ae869fbb57a2ec47c85be 100644 (file)
@@ -34,6 +34,7 @@
 #include <sstream>
 #include <utility>
 
+using namespace isc::db;
 using namespace std;
 
 namespace isc {
index 20f5fe7a577b608a70e49b77213b54aa50e3ca36..113f5f944dfddd0a10742166d53284b04717d496 100644 (file)
@@ -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
     ///
index bc7b6c211c439710e7b0d46b7fb4ee66abc0757b..fa6248f0250930922e1502ab77cedd78dd828060 100644 (file)
@@ -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>
index 235b3495e32ffe60a3673051bb95efbf4ce05e2c..b314f8d707d3c01b8e7c123d506cda2b91221d61 100644 (file)
@@ -25,6 +25,7 @@
 #include <time.h>
 
 
+using namespace isc::db;
 using namespace std;
 
 namespace isc {
index 167645ee320549f50a1404d031123baf2399b5f1..99e8ec936e774fce98e3a552db8aa882a5010a59 100644 (file)
@@ -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;
 
index 0e5251cd099f222ef5da35b6e9364dd03374555a..73b2734a9876289fffa6033a13a381b46a3b5b7a 100644 (file)
@@ -29,6 +29,7 @@
 #include <sstream>
 #include <utility>
 
+using namespace isc::db;
 using namespace std;
 
 namespace isc {
index 1ac67046b522966de488424820df3a36ba405d92..9938643868858d78720072d6f838d40d9ec6f65f 100644 (file)
@@ -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>
index 57563edd9b7e075450dae3438ab7c4070ad1d8a8..58e80bcfa9cc3414233eea20486bb1a8770eb132 100644 (file)
@@ -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 {
index 2db242b0b684b24b0ac0de38793ea90605ae80f8..dc4e07fc62f36163f3721130320226a73de2b6b3 100644 (file)
@@ -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_;
 
     //@}
 };
index 7929aa3924f946f70d742427d56226da3b28c2ff..6f9785ed3e49f408c9f25420a5d65a85f2876c6e 100644 (file)
@@ -19,6 +19,7 @@
 #include <limits>
 
 using namespace isc;
+using namespace isc::db;
 using namespace isc::dhcp;
 using namespace std;
 
index 5ad549d61d3c87853cfbaa0b01ea2ba8a00538d0..ca29521386cd237a3980752424ea9019ed217a8a 100644 (file)
@@ -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 "
index 513f025b6f52faca25fecb99c2dbc6efa6cd3f1d..b5e62a7a0b6b937a991b8a34439a8e56c81580be 100644 (file)
@@ -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);
 
index 5e47c1dc1277720151d6ccef703617fd541164ce..719aa04fe02ba30c4aa6b5524bef8b5738626293 100644 (file)
@@ -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;
 
index 2d5fbf6c330c686e72aad71fa43859bbbeb16e09..2ba750c89ecd82bee6fa4fbf7a7700025293ef9b 100644 (file)
@@ -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;
index 4a3975359f5faa4a04ff19a009fbfbbb5ae69d65..08aab94817a642e5dfe5490822039a3f59cb3107 100644 (file)
@@ -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;
index a64ce7f7798b737c94b51070bfea86f15250f5eb..29b1f1dd8ec062ac8f959486fc54bcb870d61ac3 100644 (file)
@@ -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_);
     }
 }
index 081aeedd4975e49f73bc96ca0ea2d53722aa740c..20b3f3ffe10b054ad59f25c4b3b5b4f3aca078ec 100644 (file)
@@ -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[];
index 713ad8acd8004e7ba4924e871c9f7883215b8755..f32d07ca63f6211cb03022d05096993944dc16f7 100644 (file)
@@ -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 {
 
index 381b4b1891c9526f2789deee6d9b49f0f4e65221..fd506dd26ccd617fb9dcb838fa2ff4dc1d865d0f 100644 (file)
@@ -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());
         }
index 2acf36e068271e44a4b4805264252522bf9ab255..6c2aa8cb5dcfde27e3f48fc69b50185dacdcb437 100644 (file)
@@ -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;
 
index 569c0cf2fe1d944b5209c9472daff9723c7fe9e0..5da08a89e87e888693244f283cfee7faaaa34f45 100644 (file)
@@ -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
index 3ec3d50bf92c0e10a068d7b69feb974b31d61e4b..a30eea14e609b0a66f9902e1b5578182be1bd273 100644 (file)
@@ -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;
index e6ea5242437741f07058335abc8f34f275d5d8f1..9bb58ec2d7782754a8b08a1ec9cb2bbd47691eaa 100644 (file)
@@ -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);
index d2ec70d85b3c34338bd6728f0443df800dbb410d..4ab3d561251c0af6fbe2ba085311d30b81d5dcd4 100644 (file)
@@ -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
index 9a0e9b5b6681391f720390a9da5a405f079a1d63..e7207a561d3683d7dd52efa884592c600439dee4 100644 (file)
@@ -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());
index 3c5433292767503b7b6036aa128bcd99d79e22bf..0afdf5dc276c8294735c8a255eb76b853c4c5b10 100644 (file)
@@ -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;
index 43984bcdf7064b40bf979abdcc0dcdf8a722961b..6fb33717bf14099f0f507be116c6b0c9f924f2c3 100644 (file)
@@ -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;
index b963306f9cb67de1b9167eebecb436b9b2b74a39..0b8f833f16774431a4ce3582732e4baef5a36f5b 100644 (file)
@@ -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;
index dcb4bafef4ed3d814a54455f35ebe599cfd649a5..245c5fca495633cc1df2912ac223c4df83f78c24 100644 (file)
@@ -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
index fe7ecdce0c33425647dcd15c3a80be50c9d1e2c4..5da24ffa0740c7573ce1150e8aae1de107c10e60 100644 (file)
@@ -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);
     }
 
index 0f589f0db1ed143f01e76b1b4fdf06a67bbc20d4..2a3d4269a94051f587b864f53846844c07fa99f7 100644 (file)
@@ -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;
 
index 596b908a8e154cfd66c9eaa258c34be4f00d3df7..dba626d8668d4d19be4dcb348f581898606a81a5 100644 (file)
@@ -17,6 +17,7 @@
 
 using namespace std;
 using namespace isc;
+using namespace isc::db;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 
index 9432ae9468ce1737b4db4116175018a8c7b7d27b..0fb3bf51753b34fcabf1b7f04782e81c3b960ebc 100644 (file)
@@ -29,6 +29,7 @@
 #include <vector>
 
 using namespace isc;
+using namespace isc::db;
 using namespace isc::dhcp;
 using namespace isc::asiolink;
 
index 63969acc1b4c8830483f5e8c4ea0f9c103043611..da389a56aab3db5b0bfbbb4de7e15ed0fccb6929 100644 (file)
@@ -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;
 
index 2dfc829769e3c8d6ffeb620abf61120734b8056c..263d24a4d18babef9dfe70a9bb3030b06afb133a 100644 (file)
@@ -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;
index 8c887169938bda5d52b066d82ec0ba033a0afd5c..356b776216f31049030cb370b79fbc7ac1e59508 100644 (file)
@@ -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;
index af9f5725708906352958b775812ead3a7ecc8268..c5f1c4c361c4a00cfa777f1b2d9f2c008a08eb07 100644 (file)
@@ -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;
index 6f6ba77dc5212bb0668cfc0184f6fc4d3ac3fc37..df3339aa6d706ec810e7b066c987f2ca3143e5ba 100644 (file)
@@ -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 {
index f20d27279acb00d118d4229f753690f699bbd149..f892a58817b76642b54357479bc15b90dec6cbc4 100644 (file)
@@ -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;
index 47fed015808bb5e2938bd98a6fe6fe1e9c693ff4..4a128b40b3861e7910817fd34fcbdb6c26b55984 100644 (file)
@@ -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;
index f825e6a2f380205cfa38701f8cc176dabc5517e0..257a4612e4343e14b4648d423a59bbcfc3bd3f89 100644 (file)
@@ -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
index 2a863fd197dbe96fb9809a89505e53dae3583c3c..e6b797f0c42d40a54e0485027361a405e3adcfe6 100644 (file)
@@ -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;
 
index 9ce958b1697ccffa5033b46c6b66739ed0538559..d5589476f5c47c369cf07399ddef4bdd18ad114a 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <dhcpsrv/testutils/memory_host_data_source.h>
 
+using namespace isc::db;
 using namespace std;
 
 namespace isc {
index d95ba9a28276ea3db77a999cd46f6bcb1e7a6d3f..ce43090e0bc0481a0e8eb52e6104e6eaa22793fb 100644 (file)
@@ -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