}
}
- // Print the list of known backends.
- LeaseMgrFactory::printRegistered();
+ // Log the list of known backends.
+ LeaseMgrFactory::logRegistered();
- // Print the list of known backends.
- HostDataSourceFactory::printRegistered();
+ // Log the list of known backends.
+ HostDataSourceFactory::logRegistered();
// Moved from the commit block to add the config backend indication.
if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
-
try {
// If there are config backends, fetch and merge into staging config
server.getCBControl()->databaseConfigFetch(srv_config,
}
}
- // Print the list of known backends.
- LeaseMgrFactory::printRegistered();
+ // Log the list of known backends.
+ LeaseMgrFactory::logRegistered();
- // Print the list of known backends.
- HostDataSourceFactory::printRegistered();
+ // Log the list of known backends.
+ HostDataSourceFactory::logRegistered();
// Moved from the commit block to add the config backend indication.
if (status_code == CONTROL_RESULT_SUCCESS && (!check_only || extra_checks)) {
DatabaseConnection::ParameterMap parameters =
DatabaseConnection::parse(dbaccess);
- // Get the database type and open the corresponding database
+ // Get the database type and open the corresponding database.
DatabaseConnection::ParameterMap::iterator it = parameters.find("type");
if (it == parameters.end()) {
isc_throw(InvalidParameter, "Host database configuration does not "
// No match?
if (index == map_.end()) {
- if ((db_type == "mysql") ||
- (db_type == "postgresql")) {
+ if ((db_type == "mysql") || (db_type == "postgresql")) {
string with = (db_type == "postgresql" ? "pgsql" : db_type);
isc_throw(InvalidType, "The type of host backend: '" << db_type
<< "' is not compiled in. Did you forget to use --with-"
// Call the factory and push the pointer on sources.
sources.push_back(index->second(parameters));
- // Check the factory did not return NULL.
+ // Check the factory did not return null.
if (!sources.back()) {
sources.pop_back();
isc_throw(Unexpected, "Hosts database " << db_type <<
- " factory returned NULL");
+ " factory returned null");
}
}
}
void
-HostDataSourceFactory::printRegistered() {
+HostDataSourceFactory::logRegistered() {
std::stringstream txt;
for (auto const& x : map_) {
- txt << x.first << " ";
+ if (!txt.str().empty()) {
+ txt << " ";
+ }
+ txt << x.first;
}
- LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str());
+ LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED)
+ .arg(txt.str());
}
} // namespace dhcp
/// @brief Type of host data source factory
///
/// 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.
+ /// data source. In case of failure it must throw and not return null.
typedef std::function<HostDataSourcePtr (const db::DatabaseConnection::ParameterMap&)> Factory;
/// @brief Register a host data source factory
/// @return true if a factory was registered for db_type, false if not.
static bool registeredFactory(const std::string& db_type);
- /// @brief Prints out all registered backends.
+ /// @brief Logs out all registered backends.
///
/// We need a dedicated method for this, because we sometimes can't log
/// the backend type when doing early initialization for backends
/// initialized statically.
- static void printRegistered();
+ static void logRegistered();
private:
/// @brief Factory map
DatabaseConnection::ParameterMap parameters = DatabaseConnection::parse(dbaccess);
std::string redacted = DatabaseConnection::redactedAccessString(parameters);
- // Get the database type and open the corresponding database
+ // Get the database type and open the corresponding database.
DatabaseConnection::ParameterMap::iterator it = parameters.find(type);
if (it == parameters.end()) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_NOTYPE_DB).arg(dbaccess);
// No match?
if (index == map_.end()) {
- if ((db_type == "mysql") ||
- (db_type == "postgresql")) {
+ if ((db_type == "mysql") || (db_type == "postgresql")) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_UNKNOWN_DB).arg(db_type);
string with = (db_type == "postgresql" ? "pgsql" : db_type);
isc_throw(InvalidType, "The Kea server has not been compiled with "
// Call the factory.
getLeaseMgrPtr() = index->second(parameters);
- // Check the factory did not return NULL.
+ // Check the factory did not return null.
if (!getLeaseMgrPtr()) {
isc_throw(Unexpected, "Lease database " << db_type <<
- " factory returned NULL");
+ " factory returned null");
}
}
TrackingLeaseMgr&
LeaseMgrFactory::instance() {
TrackingLeaseMgr* lmptr = getLeaseMgrPtr().get();
- if (lmptr == NULL) {
+ if (!lmptr) {
isc_throw(NoLeaseManager, "no current lease manager is available");
}
return (*lmptr);
}
void
-LeaseMgrFactory::printRegistered() {
+LeaseMgrFactory::logRegistered() {
std::stringstream txt;
for (auto const& x : map_) {
- txt << x.first << " ";
+ if (!txt.str().empty()) {
+ txt << " ";
+ }
+ txt << x.first;
}
- LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED).arg(txt.str());
+ LOG_INFO(dhcpsrv_logger, DHCPSRV_LEASE_MGR_BACKENDS_REGISTERED)
+ .arg(txt.str());
}
} // namespace dhcp
namespace isc {
namespace dhcp {
-
/// @brief No lease manager exception
///
/// Thrown if an attempt is made to get a reference to the current lease
/// @brief Type of lease mgr factory
///
/// A factory takes a parameter map and returns a pointer to a lease mgr.
- /// In case of failure it must throw and not return NULL.
+ /// In case of failure it must throw and not return null.
typedef std::function<TrackingLeaseMgrPtr (const db::DatabaseConnection::ParameterMap&)> Factory;
/// @brief Register a lease mgr factory
/// @return true if the factory was successfully added to the map, false
/// if it already exists.
static bool registerFactory(const std::string& db_type,
- const Factory& factory, bool no_log = false);
+ const Factory& factory,
+ bool no_log = false);
/// @brief Deregister a lease mgr factory
///
/// @return true if a factory was registered for db_type, false if not.
static bool registeredFactory(const std::string& db_type);
- /// @brief Prints out all registered backends.
+ /// @brief Logs out all registered backends.
///
/// We need a dedicated method for this, because we sometimes can't log
/// the backend type when doing early initialization for backends
/// initialized statically.
- static void printRegistered();
+ static void logRegistered();
private:
/// @brief Hold pointer to lease manager
InvalidType);
}
-// Verify that factory must not return NULL
+// Verify that factory must not return null
TEST_F(HostDataSourceFactoryTest, null) {
EXPECT_TRUE(HostDataSourceFactory::registerFactory("mem", factory0));
EXPECT_THROW(HostDataSourceFactory::add(sources_, "type=mem"),
EXPECT_FALSE(LeaseMgrFactory::haveInstance());
}
-// Verify that factory must not return NULL
+// Verify that factory must not return null
TEST_F(LeaseMgrFactoryTest, null) {
EXPECT_TRUE(LeaseMgrFactory::registerFactory("mem", factory0));
EXPECT_THROW(LeaseMgrFactory::create("type=mem"),
};
/// @brief TrackingLeaseMgr pointer
-typedef boost::shared_ptr<TrackingLeaseMgr> TrackingLeaseMgrPtr;
+typedef std::unique_ptr<TrackingLeaseMgr> TrackingLeaseMgrPtr;
} // end of namespace isc::dhcp
} // end of namespace isc