}
}
-string
-CqlConnection::getName() const {
- string name = "";
- try {
- name = getParameter("name");
- } catch (...) {
- // Return an empty name
- }
- return (name);
-}
-
-string
-CqlConnection::getDescription() const {
- return (string("Cassandra Database"));
-}
-
-pair<uint32_t, uint32_t>
-CqlConnection::getVersion() const {
- LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
- DHCPSRV_CQL_GET_VERSION);
-
- uint32_t version = CASS_VERSION_MAJOR;
- uint32_t minor = CASS_VERSION_MINOR;
-
- return make_pair<uint32_t, uint32_t>(version, minor);
-}
-
void
CqlConnection::commit() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_COMMIT);
};
// Defines CQL backend version: 2.3
-const uint32_t CQL_CURRENT_VERSION = CASS_VERSION_MAJOR;
-const uint32_t CQL_CURRENT_MINOR = CASS_VERSION_MINOR;
+const uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR;
+const uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR;
+
+/// Defines CQL schema version: 1.0
+const uint32_t CQL_SCHEMA_VERSION_MAJOR = 1;
+const uint32_t CQL_SCHEMA_VERSION_MINOR = 0;
class CqlConnection : public DatabaseConnection {
public:
/// @throw DbOpenError Error opening the database
void openDatabase();
- /// @brief Return backend type
- ///
- /// @return Type of the backend.
- virtual std::string getType() const {
- return (std::string("cql"));
- }
-
- /// @brief Returns name of the database.
- ///
- /// @return database name
- virtual std::string getName() const;
-
- /// @brief Returns description of the backend.
- ///
- /// This description may be multiline text that describes the backend.
- ///
- /// @return Description of the backend.
- virtual std::string getDescription() const;
-
- /// @brief Returns backend version.
- ///
- /// @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
- /// failed.
- virtual std::pair<uint32_t, uint32_t> getVersion() const;
-
/// @brief Commit Transactions
///
/// Commits all pending database operations.
{ NULL, NULL, NULL }
};
-class CqlExchange : public virtual SqlExchange {
-public:
- // Time conversion methods.
- static void
- convertToDatabaseTime(const time_t& cltt,
- const uint32_t& valid_lifetime,
- uint64_t& expire) {
- // Calculate expiry time. Store it in the 64-bit value so as we can
- // detect overflows.
- int64_t expire_time = static_cast<int64_t>(cltt) +
- static_cast<int64_t>(valid_lifetime);
-
- if (expire_time > DatabaseConnection::MAX_DB_TIME) {
- isc_throw(BadValue, "Time value is too large: " << expire_time);
- }
-
- expire = expire_time;
- }
-
- static void
- convertFromDatabaseTime(const uint64_t& expire,
- const uint32_t& valid_lifetime,
- time_t& cltt) {
- // Convert to local time
- cltt = expire - static_cast<int64_t>(valid_lifetime);
- }
-};
-
/// @brief Common CQL and Lease Data Methods
///
/// The CqlLease4Exchange and CqlLease6Exchange classes provide the
std::string
CqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
- tmp << "CQL backend " << CQL_CURRENT_VERSION;
- tmp << "." << CQL_CURRENT_MINOR;
+ tmp << "CQL backend " << CQL_SCHEMA_VERSION_MAJOR;
+ tmp << "." << CQL_SCHEMA_VERSION_MINOR;
tmp << ", library " << "cassandra_static";
return (tmp.str());
}
class CqlLease4Exchange;
class CqlLease6Exchange;
+/// @brief Cassandra Exchange
+///
+/// This class provides the basic conversion functions between Cassandra CQL and
+/// base types.
+class CqlExchange : public virtual SqlExchange {
+public:
+ // Time conversion methods.
+ static void
+ convertToDatabaseTime(const time_t& cltt,
+ const uint32_t& valid_lifetime,
+ uint64_t& expire) {
+ // Calculate expiry time. Store it in the 64-bit value so as we can
+ // detect overflows.
+ int64_t expire_time = static_cast<int64_t>(cltt) +
+ static_cast<int64_t>(valid_lifetime);
+
+ if (expire_time > DatabaseConnection::MAX_DB_TIME) {
+ isc_throw(BadValue, "Time value is too large: " << expire_time);
+ }
+
+ expire = expire_time;
+ }
+
+ static void
+ convertFromDatabaseTime(const uint64_t& expire,
+ const uint32_t& valid_lifetime,
+ time_t& cltt) {
+ // Convert to local time
+ cltt = expire - static_cast<int64_t>(valid_lifetime);
+ }
+};
+
/// @brief Cassandra Lease Manager
///
/// This class provides the \ref isc::dhcp::LeaseMgr interface to the Cassandra
/// @name Current database schema version values.
//@{
-const uint32_t CURRENT_VERSION_VERSION = 4;
-const uint32_t CURRENT_VERSION_MINOR = 2;
+const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 4;
+const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 2;
//@}
std::string
MySqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
- tmp << "MySQL backend " << CURRENT_VERSION_VERSION;
- tmp << "." << CURRENT_VERSION_MINOR;
+ tmp << "MySQL backend " << MYSQL_SCHEMA_VERSION_MAJOR;
+ tmp << "." << MYSQL_SCHEMA_VERSION_MINOR;
tmp << ", library " << mysql_get_client_info();
return (tmp.str());
}
std::string
PgSqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
- tmp << "PostgreSQL backend " << PG_CURRENT_VERSION;
- tmp << "." << PG_CURRENT_MINOR;
+ tmp << "PostgreSQL backend " << PG_SCHEMA_VERSION_MAJOR;
+ tmp << "." << PG_SCHEMA_VERSION_MINOR;
tmp << ", library " << PQlibVersion();
return (tmp.str());
}
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
- // Check that invalid login data causes an exception.
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
- DbOpenError);
-
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
- DbOpenError);
-
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
- DbOpenError);
-
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
- DbOpenError);
-
- // Check for invalid timeouts
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
- DbInvalidTimeout);
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
- DbInvalidTimeout);
-
- // Check for missing parameters
- EXPECT_THROW(LeaseMgrFactory::create(connectionString(
- CQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
- NoDatabaseName);
-
// Tidy up after the test
destroyCqlSchema(false, true);
}
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
- EXPECT_EQ(CQL_CURRENT_VERSION, version.first);
- EXPECT_EQ(CQL_CURRENT_MINOR, version.second);
+ EXPECT_EQ(CQL_SCHEMA_VERSION_MAJOR, version.first);
+ EXPECT_EQ(CQL_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
// Check that lease manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
- string connection_string = validMySQLConnectionString() + string(" ") +
+ string connection_string = validMySQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
LeaseMgrFactory::create(connection_string);
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
- EXPECT_EQ(CURRENT_VERSION_VERSION, version.first);
- EXPECT_EQ(CURRENT_VERSION_MINOR, version.second);
+ EXPECT_EQ(MYSQL_SCHEMA_VERSION_MAJOR, version.first);
+ EXPECT_EQ(MYSQL_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
- EXPECT_EQ(PG_CURRENT_VERSION, version.first);
- EXPECT_EQ(PG_CURRENT_MINOR, version.second);
+ EXPECT_EQ(PG_SCHEMA_VERSION_MAJOR, version.first);
+ EXPECT_EQ(PG_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
}
}; // namespace
-
SUBDIRS = .
sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/cql
-sqlscripts_DATA = dhcpdb_create.cql dhcpdb_drop.cql
+sqlscripts_DATA = dhcpdb_create.cql
+sqlscripts_DATA += dhcpdb_drop.cql
EXTRA_DIST = ${sqlscripts_DATA}