mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[#2438] add MySqlLeaseMgr::isJsonSupported()
This commit is contained in:
@@ -724,6 +724,12 @@ public:
|
|||||||
/// string if no limits are exceeded
|
/// string if no limits are exceeded
|
||||||
virtual std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const = 0;
|
virtual std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const = 0;
|
||||||
|
|
||||||
|
/// @brief Checks if JSON support is enabled in the database.
|
||||||
|
/// Abstract method.
|
||||||
|
///
|
||||||
|
/// @return true if there is JSON support, false otherwise
|
||||||
|
virtual bool isJsonSupported() const = 0;
|
||||||
|
|
||||||
/// @brief Return backend type
|
/// @brief Return backend type
|
||||||
///
|
///
|
||||||
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
||||||
|
@@ -2069,6 +2069,10 @@ Memfile_LeaseMgr::checkLimits6(ConstElementPtr const& /* user_context */) const
|
|||||||
isc_throw(NotImplemented, "Memfile_LeaseMgr::checkLimits4() not implemented");
|
isc_throw(NotImplemented, "Memfile_LeaseMgr::checkLimits4() not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Memfile_LeaseMgr::isJsonSupported() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dhcp
|
} // namespace dhcp
|
||||||
} // namespace isc
|
} // namespace isc
|
||||||
|
|
||||||
|
@@ -530,6 +530,12 @@ public:
|
|||||||
/// string if no limits are exceeded
|
/// string if no limits are exceeded
|
||||||
std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
|
std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
|
||||||
|
|
||||||
|
/// @brief Checks if JSON support is enabled in the database.
|
||||||
|
/// Memfile implementation assumes JSON support is always enabled.
|
||||||
|
///
|
||||||
|
/// @return true if there is JSON support, false otherwise
|
||||||
|
bool isJsonSupported() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// @name Internal methods called while holding the mutex in multi threading
|
/// @name Internal methods called while holding the mutex in multi threading
|
||||||
|
@@ -329,6 +329,7 @@ tagged_statements = { {
|
|||||||
// TODO: remove single quotes from the following two SELECTs when the functions are implemented
|
// TODO: remove single quotes from the following two SELECTs when the functions are implemented
|
||||||
{MySqlLeaseMgr::CHECK_LEASE4_LIMITS, "SELECT 'checkLease4Limits(?)'"},
|
{MySqlLeaseMgr::CHECK_LEASE4_LIMITS, "SELECT 'checkLease4Limits(?)'"},
|
||||||
{MySqlLeaseMgr::CHECK_LEASE6_LIMITS, "SELECT 'checkLease6Limits(?)'"},
|
{MySqlLeaseMgr::CHECK_LEASE6_LIMITS, "SELECT 'checkLease6Limits(?)'"},
|
||||||
|
{MySqlLeaseMgr::IS_JSON_SUPPORTED, "SELECT isJsonSupported()"},
|
||||||
} }; // tagged_statements
|
} }; // tagged_statements
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -3278,6 +3279,28 @@ MySqlLeaseMgr::wipeLeases6(const SubnetID& /*subnet_id*/) {
|
|||||||
isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend");
|
isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MySqlLeaseMgr::isJsonSupported() const {
|
||||||
|
// Get a context.
|
||||||
|
MySqlLeaseContextAlloc get_context(*this);
|
||||||
|
MySqlLeaseContextPtr ctx = get_context.ctx_;
|
||||||
|
|
||||||
|
// Create bindings.
|
||||||
|
MySqlBindingCollection in_bindings;
|
||||||
|
MySqlBindingCollection out_bindings({
|
||||||
|
MySqlBinding::createBool()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Execute the select.
|
||||||
|
bool json_supported(false);
|
||||||
|
ctx->conn_.selectQuery(IS_JSON_SUPPORTED, in_bindings, out_bindings,
|
||||||
|
[&json_supported] (MySqlBindingCollection const& result) {
|
||||||
|
json_supported = result[0]->getBool();
|
||||||
|
});
|
||||||
|
|
||||||
|
return json_supported;
|
||||||
|
}
|
||||||
|
|
||||||
// Miscellaneous database methods.
|
// Miscellaneous database methods.
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
@@ -638,6 +638,12 @@ public:
|
|||||||
/// @return number of leases removed.
|
/// @return number of leases removed.
|
||||||
virtual size_t wipeLeases6(const SubnetID& subnet_id);
|
virtual size_t wipeLeases6(const SubnetID& subnet_id);
|
||||||
|
|
||||||
|
/// @brief Checks if JSON support is enabled in the database.
|
||||||
|
/// MySQL implementation.
|
||||||
|
///
|
||||||
|
/// @return true if there is JSON support, false otherwise
|
||||||
|
bool isJsonSupported() const override;
|
||||||
|
|
||||||
/// @brief Return backend type
|
/// @brief Return backend type
|
||||||
///
|
///
|
||||||
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
||||||
@@ -726,6 +732,7 @@ public:
|
|||||||
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
|
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
|
||||||
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
|
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
|
||||||
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
|
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
|
||||||
|
IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
|
||||||
NUM_STATEMENTS // Number of statements
|
NUM_STATEMENTS // Number of statements
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -2425,6 +2425,11 @@ PgSqlLeaseMgr::wipeLeases6(const SubnetID& /*subnet_id*/) {
|
|||||||
isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend");
|
isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PgSqlLeaseMgr::isJsonSupported() const {
|
||||||
|
isc_throw(NotImplemented, "PgSqlLeaseMgr::isJsonSupported() not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
PgSqlLeaseMgr::getName() const {
|
PgSqlLeaseMgr::getName() const {
|
||||||
// Get a context
|
// Get a context
|
||||||
|
@@ -613,6 +613,12 @@ public:
|
|||||||
/// @return number of leases removed.
|
/// @return number of leases removed.
|
||||||
virtual size_t wipeLeases6(const SubnetID& subnet_id);
|
virtual size_t wipeLeases6(const SubnetID& subnet_id);
|
||||||
|
|
||||||
|
/// @brief Checks if JSON support is enabled in the database.
|
||||||
|
/// PostgreSQL implementation.
|
||||||
|
///
|
||||||
|
/// @return true if there is JSON support, false otherwise
|
||||||
|
bool isJsonSupported() const override;
|
||||||
|
|
||||||
/// @brief Return backend type
|
/// @brief Return backend type
|
||||||
///
|
///
|
||||||
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
||||||
|
@@ -369,6 +369,13 @@ public:
|
|||||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::checkLimits6() not implemented");
|
isc_throw(NotImplemented, "ConcreteLeaseMgr::checkLimits6() not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Checks if JSON support is enabled in the database.
|
||||||
|
///
|
||||||
|
/// @return true if there is JSON support, false otherwise
|
||||||
|
bool isJsonSupported() const override {
|
||||||
|
isc_throw(NotImplemented, "ConcreteLeaseMgr::isJsonSupported() not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Returns backend type.
|
/// @brief Returns backend type.
|
||||||
///
|
///
|
||||||
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
|
||||||
|
@@ -1072,4 +1072,13 @@ TEST_F(MySqlLeaseMgrTest, leaseStatsQueryAttribution6MultiThreading) {
|
|||||||
testLeaseStatsQueryAttribution6();
|
testLeaseStatsQueryAttribution6();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Checks that no exceptions are thrown when inquiring about JSON
|
||||||
|
/// support and prints an informative message.
|
||||||
|
TEST_F(MySqlLeaseMgrTest, isJsonSupported) {
|
||||||
|
bool json_supported;
|
||||||
|
ASSERT_NO_THROW(json_supported = LeaseMgrFactory::instance().isJsonSupported());
|
||||||
|
std::cout << "JSON support is " << (json_supported ? "" : "not ") <<
|
||||||
|
"enabled in the database." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@@ -131,6 +131,11 @@ MySqlBinding::createFloat(const float value) {
|
|||||||
return (createInteger<float>(value));
|
return (createInteger<float>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MySqlBindingPtr
|
||||||
|
MySqlBinding::createBool() {
|
||||||
|
return (createInteger<uint8_t>(static_cast<uint8_t>(false)));
|
||||||
|
}
|
||||||
|
|
||||||
MySqlBindingPtr
|
MySqlBindingPtr
|
||||||
MySqlBinding::createBool(const bool value) {
|
MySqlBinding::createBool(const bool value) {
|
||||||
return (createInteger<uint8_t>(static_cast<uint8_t>(value)));
|
return (createInteger<uint8_t>(static_cast<uint8_t>(value)));
|
||||||
|
@@ -447,6 +447,12 @@ public:
|
|||||||
createInteger<float> (static_cast<float>(value.get())));
|
createInteger<float> (static_cast<float>(value.get())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Creates binding having a bool type for receiving data.
|
||||||
|
///
|
||||||
|
/// @return Pointer to the created binding holding an @c uint8_t
|
||||||
|
/// value representing the boolean value.
|
||||||
|
static MySqlBindingPtr createBool();
|
||||||
|
|
||||||
/// @brief Creates binding having a bool type for sending data.
|
/// @brief Creates binding having a bool type for sending data.
|
||||||
///
|
///
|
||||||
/// @param value Boolean value to be sent to the database.
|
/// @param value Boolean value to be sent to the database.
|
||||||
|
Reference in New Issue
Block a user