/// @return Type of the backend.
virtual std::string getType() const = 0;
+ /// @brief Commit Transactions
+ ///
+ /// Commits all pending database operations. On databases that don't
+ /// support transactions, this is a no-op.
+ virtual void commit() {};
+
+ /// @brief Rollback Transactions
+ ///
+ /// Rolls back all pending database operations. On databases that don't
+ /// support transactions, this is a no-op.
+ virtual void rollback() {};
};
}
public:
/// @brief Defines maximum value for time that can be reliably stored.
- // If I'm still alive I'll be too old to care. You fix it.
+ ///
+ /// @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
#include <dhcpsrv/dhcpsrv_log.h>
#include <dhcpsrv/host_data_source_factory.h>
+#include <dhcpsrv/hosts_log.h>
+
+#ifdef HAVE_MYSQL
#include <dhcpsrv/mysql_host_data_source.h>
+#endif
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
return;
}
#endif
+
#ifdef HAVE_PGSQL
if (parameters[type] == string("postgresql")) {
LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_DB).arg(redacted);
- // set pgsql data source here, when it will be featured
+ isc_throw(NotImplemented, "Sorry, Postgres backend for host reservations "
+ "is not implemented yet.");
+ // Set pgsql data source here, when it will be implemented.
return;
}
#endif
- // Get here on no match
+ // Get here on no match.
LOG_ERROR(dhcpsrv_logger, DHCPSRV_UNKNOWN_DB).arg(parameters[type]);
isc_throw(InvalidType, "Database access parameter 'type' does "
"not specify a supported database backend");
// Destroy current host data source instance. This is a no-op if no host
// data source is available.
if (getHostDataSourcePtr()) {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
- DHCPSRV_CLOSE_HOST_DATA_SOURCE)
- .arg(getHostDataSourcePtr()->getType());
+ LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
+ .arg(getHostDataSourcePtr()->getType());
}
getHostDataSourcePtr().reset();
}
BaseHostDataSource&
HostDataSourceFactory::instance() {
- BaseHostDataSource* hdsptr = getHostDataSourcePtr().get();
+ BaseHostDataSource* hdsptr = getHostDataSourcePtr().get();
if (hdsptr == NULL) {
isc_throw(NoHostDataSourceManager,
"no current host data source instance is available");
using namespace isc::asiolink;
+boost::shared_ptr<BaseHostDataSource> HostMgr::alternate_source;
+
boost::scoped_ptr<HostMgr>&
HostMgr::getHostMgrPtr() {
static boost::scoped_ptr<HostMgr> host_mgr_ptr;
}
void
-HostMgr::create(const std::string& /*access*/) {
+HostMgr::create(const std::string& access) {
getHostMgrPtr().reset(new HostMgr());
-/*
- try {
+
+ if (!access.empty()) {
HostDataSourceFactory::create(access);
- } catch (...) {
- std::cerr << "Unable to open database.";
- throw;
- }
-*/
- //alternate_source = &(HostDataSourceFactory::instance());
- //alternate_source.reset(&(HostDataSourceFactory::instance()));
- /// @todo Initialize alternate_source here, using the parameter.
- /// For example: alternate_source.reset(new MysqlHostDataSource(access)).
+ /// @todo Initialize alternate_source here.
+ //alternate_source = HostDataSourceFactory::getHostDataSourcePtr();
+ }
}
HostMgr&
/// @brief Pointer to an alternate host data source.
///
/// If this pointer is NULL, the source is not in use.
- boost::shared_ptr<BaseHostDataSource> alternate_source;
+ static boost::shared_ptr<BaseHostDataSource> alternate_source;
/// @brief Returns a pointer to the currently used instance of the
/// @c HostMgr.
the server's configuration. The argument describes the host and its
reservations in detail.
+% HOSTS_CFG_CLOSE_HOST_DATA_SOURCE Closing host data source: %1
+This is a normal message being printed when the server closes host data
+source connection.
+
% HOSTS_CFG_GET_ALL_ADDRESS4 get all hosts with reservations for IPv4 address %1
This debug message is issued when starting to retrieve all hosts, holding the
reservation for the specific IPv4 address, from the configuration. The
#include <dhcpsrv/database_connection.h>
#include <boost/scoped_ptr.hpp>
-#include <mysql.h>
+#include <mysql/mysql.h>
#include <vector>
namespace isc {
return (std::make_pair(major, minor));
}
+void
+MySqlHostDataSource::commit() {
+ conn_.commit();
+}
+
+
+void
+MySqlHostDataSource::rollback() {
+ conn_.rollback();
+}
+
}; // end of isc::dhcp namespace
}; // end of isc namespace
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
-#include <mysql.h>
+#include <mysql/mysql.h>
namespace isc {
namespace dhcp {
/// @brief MySQL Host Data Source
///
-/// This class provides the \ref isc::dhcp::BaseHostDataSource interface to the MySQL
+/// This class provides the @ref isc::dhcp::BaseHostDataSource interface to the MySQL
/// database. Use of this backend presupposes that a MySQL database is
/// available and that the Kea schema has been created within it.
-
class MySqlHostDataSource: public BaseHostDataSource {
public:
/// has failed.
virtual std::pair<uint32_t, uint32_t> getVersion() const;
+ /// @brief Commit Transactions
+ ///
+ /// Commits all pending database operations. On databases that don't
+ /// support transactions, this is a no-op.
+ virtual void commit();
+
+ /// @brief Rollback Transactions
+ ///
+ /// Rolls back all pending database operations. On databases that don't
+ /// support transactions, this is a no-op.
+ virtual void rollback();
+
MySqlConnection* getDatabaseConnection() {
return &conn_;
}
namespace test {
GenericHostDataSourceTest::GenericHostDataSourceTest()
- :hdsptr_(NULL){
+ :hdsptr_(NULL) {
}
-GenericHostDataSourceTest::~GenericHostDataSourceTest(){}
+GenericHostDataSourceTest::~GenericHostDataSourceTest() {
+}
/// @brief Virtual destructor.
virtual ~GenericHostDataSourceTest();
-
/// @brief Pointer to the host data source
BaseHostDataSource* hdsptr_;
-
};
}; // namespace test
#include <dhcpsrv/tests/generic_host_data_source_unittest.h>
#include <dhcpsrv/host_data_source_factory.h>
-
#include <gtest/gtest.h>
#include <algorithm>
const char* VALID_PASSWORD = "password=keatest";
const char* INVALID_PASSWORD = "password=invalid";
-MySqlHostDataSource* myhdsptr_;
-
// Given a combination of strings above, produce a connection string.
string connectionString(const char* type, const char* name, const char* host,
const char* user, const char* password) {
/// @brief Constructor
///
/// Deletes everything from the database and opens it.
- MySqlHostDataSourceTest() {
+ MySqlHostDataSourceTest() {
// Ensure schema is the correct one.
destroySchema();
"*** accompanying exception output.\n";
throw;
}
- myhdsptr_ = (MySqlHostDataSource *) &(HostDataSourceFactory::instance());
+
+ hdsptr_ = &(HostDataSourceFactory::instance());
}
/// @brief Destructor
/// Rolls back all pending transactions. The deletion of myhdsptr_ will close
/// the database. Then reopen it and delete everything created by the test.
virtual ~MySqlHostDataSourceTest() {
- myhdsptr_->getDatabaseConnection()->rollback();
+ hdsptr_->rollback();
HostDataSourceFactory::destroy();
destroySchema();
}
/// Parameter is ignored for MySQL backend as the v4 and v6 leases share
/// the same database.
void reopen(Universe) {
- HostDataSourceFactory::destroy();
- HostDataSourceFactory::create(validConnectionString());
- myhdsptr_ = (MySqlHostDataSource *) &(HostDataSourceFactory::instance());
+ HostDataSourceFactory::destroy();
+ HostDataSourceFactory::create(validConnectionString());
+ hdsptr_ = &(HostDataSourceFactory::instance());
}
};
/// @brief Check that database can be opened
///
-/// This test checks if the MySqlLeaseMgr can be instantiated. This happens
+/// This test checks if the MySqlHostDataSource can be instantiated. This happens
/// only if the database can be opened. Note that this is not part of the
/// MySqlLeaseMgr test fixure set. This test checks that the database can be
/// opened: the fixtures assume that and check basic operations.
-TEST(MySqlOpenTest, OpenDatabase) {
+TEST(MySqlHostDataSource, OpenDatabase) {
// Schema needs to be created for the test to work.
destroySchema();
// Check that lease manager open the database opens correctly and tidy up.
// If it fails, print the error message.
try {
- HostDataSourceFactory::create(validConnectionString());
+ HostDataSourceFactory::create(validConnectionString());
EXPECT_NO_THROW((void) HostDataSourceFactory::instance());
HostDataSourceFactory::destroy();
} catch (const isc::Exception& ex) {