# Check 7.0 to 8.0 upgrade
pgsql_upgrade_7_0_to_8_0
- # Check 7.0 to 8.0 upgrade
+ # Check 8.0 to 9.0 upgrade
pgsql_upgrade_8_0_to_9_0
# Let's wipe the whole database
const std::string& name) {
StampedValueCollection parameters;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createString(name)
last_subnet->addPool(last_pool);
}
- // Parse pool specific option from 25 to 36.
+ // Parse pool-specific option from 25 to 36.
if (last_pool && !out_bindings[25]->amNull() &&
(last_pool_option_id < out_bindings[25]->getInteger<uint64_t>())) {
last_pool_option_id = out_bindings[25]->getInteger<uint64_t>();
}
}
- // Parse subnet specific option from 37 to 48.
+ // Parse subnet-specific option from 37 to 48.
if (!out_bindings[37]->amNull() &&
(last_option_id < out_bindings[37]->getInteger<uint64_t>())) {
last_option_id = out_bindings[37]->getInteger<uint64_t>();
MySqlBindingCollection in_bindings = { MySqlBinding::createInteger<uint32_t>(subnet_id) };
auto index = GET_SUBNET4_ID_NO_TAG;
-
if (server_selector.amUnassigned()) {
index = GET_SUBNET4_ID_UNASSIGNED;
-
} else if (server_selector.amAny()) {
index = GET_SUBNET4_ID_ANY;
}
MySqlBindingCollection in_bindings = { MySqlBinding::createString(subnet_prefix) };
auto index = GET_SUBNET4_PREFIX_NO_TAG;
-
if (server_selector.amUnassigned()) {
index = GET_SUBNET4_PREFIX_UNASSIGNED;
-
} else if (server_selector.amAny()) {
index = GET_SUBNET4_PREFIX_ANY;
}
MySqlBinding::createInteger<uint32_t>(pool_end_address.toUint32())
};
getPools(GET_POOL4_RANGE_ANY, in_bindings, pools, pool_ids);
-
} else {
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createInteger<uint32_t>(pool_start_address.toUint32()),
MySqlBindingCollection in_bindings = { MySqlBinding::createString(name) };
auto index = GET_SHARED_NETWORK4_NAME_NO_TAG;
-
if (server_selector.amUnassigned()) {
index = GET_SHARED_NETWORK4_NAME_UNASSIGNED;
-
} else if (server_selector.amAny()) {
index = GET_SHARED_NETWORK4_NAME_ANY;
}
MySqlConfigBackendDHCPv4::getAllGlobalParameters4(const ServerSelector& server_selector) const {
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_ALL_GLOBAL_PARAMETERS4);
StampedValueCollection parameters;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag.get()) };
impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4,
in_bindings, parameters);
LOG_DEBUG(mysql_cb_logger, DBGLVL_TRACE_BASIC, MYSQL_CB_GET_MODIFIED_GLOBAL_PARAMETERS4)
.arg(util::ptimeToText(modification_time));
StampedValueCollection parameters;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
/// audit entry is when there is a single server tag, i.e. "all" or explicit
/// server name. In fact, these are the most common two cases.
std::string tag = ServerTag::ALL;
- auto tags = server_selector.getTags();
+ auto const& tags = server_selector.getTags();
if (tags.size() == 1) {
tag = tags.begin()->get();
}
MySqlBinding::createString(AUDIT_ENTRY_LOG_MESSAGE_BUF_LENGTH) // log_message
};
- auto tags = server_selector.getTags();
-
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
// There are only a few input bindings
MySqlBindingCollection in_bindings = {
// server_tag
ServerTag last_param_server_tag(out_bindings[5]->getString());
last_param->setServerTag(last_param_server_tag.get());
+
// If we're fetching parameters for a given server (explicit server
// tag is provided), it takes precedence over the same parameter
// specified for all servers. Therefore, we check if the given
void
MySqlConfigBackendImpl::getAllOptionDefs(const int index,
- const ServerSelector& server_selector,
- OptionDefContainer& option_defs) {
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ const ServerSelector& server_selector,
+ OptionDefContainer& option_defs) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get())
};
const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time,
OptionDefContainer& option_defs) {
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
const ServerSelector& server_selector) {
OptionContainer options;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get())
};
const boost::posix_time::ptime& modification_time) {
OptionContainer options;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ auto const& tags = server_selector.getTags();
+ for (auto const& tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag.get()),
MySqlBinding::createTimestamp(modification_time)
isc_throw(BadValue, "invalid record_types value "
<< (*(first_binding + 8))->getString());
}
+
// This element must contain a list of integers specifying
// types of the record fields.
for (auto i = 0; i < record_types_element->size(); ++i) {
if (type_element->getType() != Element::integer) {
isc_throw(BadValue, "record type values must be integers");
}
+
def->addRecordField(static_cast<OptionDataType>(type_element->intValue()));
}
}
MySqlConfigBackendImpl::attachElementToServers(const int index,
const ServerSelector& server_selector,
const MySqlBindingPtr& first_binding,
- const MySqlBindingPtr& in_bindings...) {
+ const MySqlBindingPtr& in_bindings) {
// Create the vector from the parameter pack.
MySqlBindingCollection in_server_bindings = { first_binding, in_bindings };
- for (auto tag : server_selector.getTags()) {
+ for (auto const& tag : server_selector.getTags()) {
in_server_bindings.push_back(MySqlBinding::createString(tag.get()));
// Handles the case where the server does not exists.
try {
const ServerPtr& server) {
// The server tag 'all' is reserved.
if (server->getServerTag().amAll()) {
- isc_throw(InvalidOperation, "'all' is a name reserved for the server tag which"
+ isc_throw(InvalidOperation,
+ "'all' is a name reserved for the server tag which"
" associates the configuration elements with all servers connecting"
" to the database and a server with this name may not be created");
}
/// is more than one server tag associated with the selector.
std::string getServerTag(const db::ServerSelector& server_selector,
const std::string& operation) const {
- auto tags = server_selector.getTags();
+ auto const& tags = server_selector.getTags();
if (tags.size() != 1) {
isc_throw(InvalidOperation, "expected exactly one server tag to be specified"
" while " << operation << ". Got: "
/// This method is useful for logging purposes.
std::string getServerTagsAsText(const db::ServerSelector& server_selector) const {
std::ostringstream s;
- auto server_tags = server_selector.getTags();
- for (auto tag : server_tags) {
+ auto const& server_tags = server_selector.getTags();
+ for (auto const& tag : server_tags) {
if (s.tellp() != 0) {
s << ", ";
}
///
/// @return Pointer to the returned option or NULL if such option
/// doesn't exist.
- OptionDescriptorPtr
- getOption(const int index, const Option::Universe& universe,
- const db::ServerSelector& server_selector, const uint16_t code,
- const std::string& space);
+ OptionDescriptorPtr getOption(const int index,
+ const Option::Universe& universe,
+ const db::ServerSelector& server_selector,
+ const uint16_t code,
+ const std::string& space);
/// @brief Sends query to retrieve all global options.
///
/// @param universe Option universe, i.e. V4 or V6.
/// @param server_selector Server selector.
/// @return Container holding returned options.
- OptionContainer
- getAllOptions(const int index, const Option::Universe& universe,
- const db::ServerSelector& server_selector);
+ OptionContainer getAllOptions(const int index,
+ const Option::Universe& universe,
+ const db::ServerSelector& server_selector);
/// @brief Sends query to retrieve global options with modification
/// time later than specified timestamp.
/// @param universe Option universe, i.e. V4 or V6.
/// @param server_selector Server selector.
/// @return Container holding returned options.
- OptionContainer
- getModifiedOptions(const int index, const Option::Universe& universe,
- const db::ServerSelector& server_selector,
- const boost::posix_time::ptime& modification_time);
+ OptionContainer getModifiedOptions(const int index,
+ const Option::Universe& universe,
+ const db::ServerSelector& server_selector,
+ const boost::posix_time::ptime& modification_time);
/// @brief Sends query to retrieve single option by code and option space
/// for a given subnet id.
/// @param universe V4 or V6.
/// @param first_binding Iterator of the output binding containing
/// option_id.
- OptionDescriptorPtr
- processOptionRow(const Option::Universe& universe,
- db::MySqlBindingCollection::iterator first_binding);
+ OptionDescriptorPtr processOptionRow(const Option::Universe& universe,
+ db::MySqlBindingCollection::iterator first_binding);
/// @brief Returns DHCP option definition instance from output bindings.
///
void attachElementToServers(const int index,
const db::ServerSelector& server_selector,
const db::MySqlBindingPtr& first_binding,
- const db::MySqlBindingPtr& in_bindings...);
+ const db::MySqlBindingPtr& in_bindings);
/// @brief Creates input binding for relay addresses.
///
}
// Go over the collection of elements.
- for (auto elem = index.begin(); elem != index.end(); ) {
+ for (auto elem = index.begin(); elem != index.end();) {
// If we're asking for shared networks matching all servers,
// we have to make sure that the fetched element has "all"
// Server selector contains explicit server tags, so
// let's see if the returned elements includes any of
// them.
- auto tags = server_selector.getTags();
+ auto const& tags = server_selector.getTags();
bool tag_found = false;
- for (auto tag : tags) {
+ for (auto const& tag : tags) {
if ((*elem)->hasServerTag(tag) ||
(*elem)->hasAllServerTag()) {
tag_found = true;
return (parameters_);
}
- /// @brief Sets IO service to be used by the MySql config backend.
+ /// @brief Sets IO service to be used by the MySQL config backend.
///
/// @param IOService object, used for all ASIO operations.
static void setIOService(const isc::asiolink::IOServicePtr& io_service) {
/// @brief Connection parameters
isc::db::DatabaseConnection::ParameterMap parameters_;
- /// The IOService object, used for all ASIO operations.
+ /// @brief The IOService object, used for all ASIO operations.
static isc::asiolink::IOServicePtr io_service_;
};
destroyMySQLSchema();
}
- /// @brief Returns a valid PostgreSQL back end specific connection
+ /// @brief Returns a valid MySQL back end specific connection
/// string
std::string validConnectionString() {
return (validMySQLConnectionString());
StampedValuePtr getGlobalParameter4(const ServerSelector& server_selector,
const std::string& name) {
StampedValueCollection parameters;
+
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
/// @param value StampedValue describing the parameter to create/update.
void createUpdateGlobalParameter4(const db::ServerSelector& server_selector,
const StampedValuePtr& value) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
PsqlBindArray attach_bindings;
uint64_t pid = getLastInsertId("dhcp4_global_parameter", "id");
attach_bindings.add(pid); // id of newly inserted global.
- attach_bindings.add(value->getModificationTime());
+ attach_bindings.addTimestamp(value->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv4Impl::INSERT_GLOBAL_PARAMETER4_SERVER,
server_selector, attach_bindings);
}
last_subnet = *subnets.rbegin();
}
// Subnet_id is column 0.
- SubnetID subnet_id = worker.getBigInt(0) ;
+ SubnetID subnet_id = worker.getInt(0) ;
// Subnet has been returned. Assuming that subnets are ordered by
// subnet identifier, if the subnet identifier of the current row
// 4o6_interface_id at 3.
if (!worker.isColumnNull(3)) {
- std::string interface_id_str = worker.getString(3);
- OptionBuffer dhcp4o6_interface_id_buf(interface_id_str.begin(),
- interface_id_str.end());
+ std::string dhcp4o6_interface_id = worker.getString(3);
+ OptionBuffer dhcp4o6_interface_id_buf(dhcp4o6_interface_id.begin(),
+ dhcp4o6_interface_id.end());
OptionPtr option_dhcp4o6_interface_id =
Option::create(Option::V6, D6O_INTERFACE_ID, dhcp4o6_interface_id_buf);
last_subnet->get4o6().setInterfaceId(option_dhcp4o6_interface_id);
// 4o6_subnet at 4.
if (!worker.isColumnNull(4)) {
- std::string dhcp4o6_prefix_str = worker.getString(4);
std::pair<IOAddress, uint8_t> dhcp4o6_subnet_prefix_pair =
- Subnet6::parsePrefix(dhcp4o6_prefix_str);
+ Subnet6::parsePrefix(worker.getString(4));
last_subnet->get4o6().setSubnet4o6(dhcp4o6_subnet_prefix_pair.first,
dhcp4o6_subnet_prefix_pair.second);
}
tossNonMatchingElements(server_selector, subnet_index);
}
-
/// @brief Sends query to retrieve single subnet by id.
///
/// @param server_selector Server selector.
/// doesn't exist.
Subnet4Ptr getSubnet4(const ServerSelector& server_selector,
const SubnetID& subnet_id) {
+
if (server_selector.hasMultipleTags()) {
isc_throw(InvalidOperation, "expected one server tag to be specified"
" while fetching a subnet. Got: "
auto index = (server_selector.amUnassigned() ? GET_MODIFIED_SUBNETS4_UNASSIGNED :
GET_MODIFIED_SUBNETS4);
getSubnets4(index, server_selector, in_bindings, subnets);
-
}
/// @brief Sends query to retrieve all subnets belonging to a shared network.
// pool start_address (1)
// pool end_address (2)
last_pool_id = id;
+
last_pool = Pool4::create(worker.getInet4(1), worker.getInet4(2));
// pool subnet_id (3) (ignored)
auto const& tags = server_selector.getTags();
for (auto const& tag : tags) {
PsqlBindArray in_bindings;
- in_bindings.add(tag.get());
+ in_bindings.addTempString(tag.get());
in_bindings.addInet4(pool_start_address);
in_bindings.addInet4(pool_end_address);
}
pool_id = 0;
+
return (Pool4Ptr());
}
/// @param subnet Pointer to the subnet to be inserted or updated.
void createUpdateSubnet4(const ServerSelector& server_selector,
const Subnet4Ptr& subnet) {
+
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "creating or updating a subnet for ANY"
" server is not supported");
if (dhcp4o6_interface_id) {
in_bindings.addTempString(std::string(dhcp4o6_interface_id->getData().begin(),
dhcp4o6_interface_id->getData().end()));
+
} else {
in_bindings.addNull();
}
// Insert associations with the servers.
PsqlBindArray attach_bindings;
attach_bindings.add(subnet->getID());
- attach_bindings.add(subnet->getModificationTime());
+ attach_bindings.addTimestamp(subnet->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv4Impl::INSERT_SUBNET4_SERVER,
server_selector, attach_bindings);
// (Re)create pools.
for (auto pool : subnet->getPools(Lease::TYPE_V4)) {
- createPool4(server_selector, boost::dynamic_pointer_cast<Pool4>(pool), subnet);
+ createPool4(server_selector, boost::dynamic_pointer_cast<Pool4>(pool),
+ subnet);
}
// (Re)create options.
for (auto desc = options->begin(); desc != options->end(); ++desc) {
OptionDescriptorPtr desc_copy = OptionDescriptor::create(*desc);
desc_copy->space_name_ = option_space;
- createUpdateOption4(server_selector, subnet->getID(), desc_copy, true);
+ createUpdateOption4(server_selector, subnet->getID(), desc_copy,
+ true);
}
}
last_network->allowClientClass(worker.getString(2));
}
- // Interface at 3.
+ // interface at 3.
if (!worker.isColumnNull(3)) {
last_network->setIface(worker.getString(3));
}
/// network doesn't exist.
SharedNetwork4Ptr getSharedNetwork4(const ServerSelector& server_selector,
const std::string& name) {
+
if (server_selector.hasMultipleTags()) {
isc_throw(InvalidOperation, "expected one server tag to be specified"
" while fetching a shared network. Got: "
/// structure where shared networks should be inserted.
void getAllSharedNetworks4(const ServerSelector& server_selector,
SharedNetwork4Collection& shared_networks) {
- if (server_selector.amAny()) {
+ if (server_selector.amAny()) {
isc_throw(InvalidOperation, "fetching all shared networks for ANY "
"server is not supported");
}
auto index = (server_selector.amUnassigned() ?
PgSqlConfigBackendDHCPv4Impl::GET_MODIFIED_SHARED_NETWORKS4_UNASSIGNED :
PgSqlConfigBackendDHCPv4Impl::GET_MODIFIED_SHARED_NETWORKS4);
-
getSharedNetworks4(index, server_selector, in_bindings, shared_networks);
}
/// @param subnet Pointer to the shared network to be inserted or updated.
void createUpdateSharedNetwork4(const ServerSelector& server_selector,
const SharedNetwork4Ptr& shared_network) {
+
if (server_selector.amAny()) {
isc_throw(InvalidOperation, "creating or updating a shared network for ANY"
" server is not supported");
// Associate the shared network with the servers.
PsqlBindArray attach_bindings;
attach_bindings.addTempString(shared_network->getName());
- attach_bindings.add(shared_network->getModificationTime());
+ attach_bindings.addTimestamp(shared_network->getModificationTime());
attachElementToServers(PgSqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4_SERVER,
server_selector, attach_bindings);
PsqlBindArray attach_bindings;
attach_bindings.add(option_id); // id of newly inserted global.
- attach_bindings.add(modification_ts);
+ attach_bindings.addTimestamp(modification_ts);
// Associate the option with the servers.
attachElementToServers(PgSqlConfigBackendDHCPv4Impl::INSERT_OPTION4_SERVER,
/// @param option Pointer to the option descriptor encapsulating the option.
void createUpdateOption4(const ServerSelector& server_selector,
const OptionDescriptorPtr& option) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
const SubnetID& subnet_id,
const OptionDescriptorPtr& option,
const bool cascade_update) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
const uint64_t pool_id,
const OptionDescriptorPtr& option,
const bool cascade_update) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
const std::string& shared_network_name,
const OptionDescriptorPtr& option,
const bool cascade_update) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
/// @param option_def Pointer to the option definition to be inserted or updated.
void createUpdateOptionDef4(const ServerSelector& server_selector,
const OptionDefinitionPtr& option_def) {
+
createUpdateOptionDef(server_selector, option_def, DHCP4_OPTION_SPACE,
PgSqlConfigBackendDHCPv4Impl::GET_OPTION_DEF4_CODE_SPACE,
PgSqlConfigBackendDHCPv4Impl::INSERT_OPTION_DEF4,
"deleting options for a shared network",
"shared network specific options deleted",
true, in_bindings));
-
}
/// @brief Deletes options belonging to a client class from the database.
/// audit entry is when there is a single server tag, i.e. "all" or explicit
/// server name. In fact, these are the most common two cases.
std::string tag = ServerTag::ALL;
- const auto& tags = server_selector.getTags();
+ auto const& tags = server_selector.getTags();
if (tags.size() == 1) {
tag = tags.begin()->get();
}
if (audit_revision_ref_count_ <= 0) {
isc_throw(Unexpected, "attempted to clear audit revision that does not exist - coding error");
}
-
--audit_revision_ref_count_;
}
const ServerSelector& server_selector,
const uint16_t code,
const std::string& space) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
" (unassigned) is unsupported at the moment");
void
PgSqlConfigBackendImpl::getOptionDefs(const int index,
const PsqlBindArray& in_bindings,
- OptionDefContainer& option_defs ) {
+ OptionDefContainer& option_defs) {
uint64_t last_def_id = 0;
+
OptionDefContainer local_option_defs;
// Run select query.
// Create a worker for the row.
PgSqlResultRowWorker worker(r, row);
-
// Get pointer to last fetched option definition.
OptionDefinitionPtr last_def;
if (!local_option_defs.empty()) {
const int& create_audit_revision,
const int& insert_option_def_server,
const std::string& client_class_name) {
+
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
- " (unassigned) is unsupported at the moment");
+ " (unassigned) is unsupported at the moment");
}
auto tag = getServerTag(server_selector, "creating or updating option definition");
if (server_selector.amUnassigned()) {
isc_throw(NotImplemented, "managing configuration for no particular server"
- " (unassigned) is unsupported at the moment");
+ " (unassigned) is unsupported at the moment");
}
auto tag = getServerTag(server_selector, "fetching global option");
const Option::Universe& universe,
const ServerSelector& server_selector,
const boost::posix_time::ptime& modification_time) {
-
OptionContainer options;
PsqlBindArray in_bindings;
const PsqlBindArray& in_bindings) {
// Copy the bindings because we're going to modify them.
PsqlBindArray server_bindings = in_bindings;
- for (auto tag : server_selector.getTags()) {
+ for (auto const& tag : server_selector.getTags()) {
// Add the server tag to end of the bindings.
std::string server_tag = tag.get();
server_bindings.add(server_tag);
"be valid strings");
}
- network.addRelayAddress(IOAddress(relay_element->get(i)->stringValue()));
+ network.addRelayAddress(IOAddress(relay_address_element->stringValue()));
}
}
/// @brief Base class for PostgreSQL Config Backend implementations.
///
/// This class contains common methods for manipulating data in the
-/// Postgres database, used by all servers.
+/// PostgreSQL database, used by all servers.
///
/// All POSIX times specified in the methods belonging to this
/// class must be local times.
class PgSqlConfigBackendImpl {
protected:
+
/// @brief RAII object used to protect against creating multiple
/// audit revisions during cascade configuration updates.
///
/// transaction with the database.
class ScopedAuditRevision {
public:
+
/// @brief Constructor.
///
/// Creates new audit revision and sets the flag in the
- /// Postgres CB implementation object which prevents new audit
+ /// PostgreSQL CB implementation object which prevents new audit
/// revisions to be created while this instance exists.
///
- /// @param impl pointer to the Postgres CB implementation.
+ /// @param impl pointer to the PostgreSQL CB implementation.
/// @param index index of the query to set session variables
/// used for creation of the audit revision and the audit
/// entries.
~ScopedAuditRevision();
private:
- /// @brief Pointer to the Postgres CB implementation.
+
+ /// @brief Pointer to the PostgreSQL CB implementation.
PgSqlConfigBackendImpl* impl_;
};
public:
+
/// @brief Constructor.
///
/// @param parameters A data structure relating keywords and values
/// use when fetching the last insert id for a given table.
explicit PgSqlConfigBackendImpl(const db::DatabaseConnection::ParameterMap& parameters,
const db::DbCallback db_reconnect_callback,
- const size_t last_insert_id_index_);
+ const size_t last_insert_id_index);
/// @brief Destructor.
virtual ~PgSqlConfigBackendImpl();
/// @return Server tag.
/// @throw InvalidOperation if the server selector is unassigned or if there
/// is more than one server tag associated with the selector.
- std::string
- getServerTag(const db::ServerSelector& server_selector, const std::string& operation) const {
- auto tags = server_selector.getTags();
+ std::string getServerTag(const db::ServerSelector& server_selector,
+ const std::string& operation) const {
+ auto const& tags = server_selector.getTags();
if (tags.size() != 1) {
isc_throw(InvalidOperation, "expected exactly one server tag to be specified"
- " while "
- << operation
- << ". Got: " << getServerTagsAsText(server_selector));
+ " while " << operation << ". Got: "
+ << getServerTagsAsText(server_selector));
}
return (tags.begin()->get());
/// This method is useful for logging purposes.
std::string getServerTagsAsText(const db::ServerSelector& server_selector) const {
std::ostringstream s;
- auto server_tags = server_selector.getTags();
- for (auto tag : server_tags) {
+ auto const& server_tags = server_selector.getTags();
+ for (auto const& tag : server_tags) {
if (s.tellp() != 0) {
s << ", ";
}
}
/// @brief Iterates over the class names in a JSON list element at a
- /// given column, invoking a setter function each one.
+ /// given column, invoking a setter function for each one.
///
/// Has no effect if the column is null or is an empty list.
///
/// @param bindings Reference to the PgSQL input bindings.
/// @param [out] servers Reference to the container where fetched servers
/// will be inserted.
- void
- getServers(const int index, const db::PsqlBindArray& bindings, db::ServerCollection& servers);
+ void getServers(const int index,
+ const db::PsqlBindArray& bindings,
+ db::ServerCollection& servers);
/// @brief Creates or updates a server.
///
/// @param server_selector Server selector.
/// @param index Reference to the index holding the returned configuration
/// elements to be processed.
- template <typename CollectionIndex>
- void
- tossNonMatchingElements(const db::ServerSelector& server_selector, CollectionIndex& index) {
+ template<typename CollectionIndex>
+ void tossNonMatchingElements(const db::ServerSelector& server_selector,
+ CollectionIndex& index) {
// Don't filter the matching server tags if the server selector is
// set to ANY.
if (server_selector.amAny()) {
// Server selector contains explicit server tags, so
// let's see if the returned elements includes any of
// them.
- auto tags = server_selector.getTags();
+ auto const& tags = server_selector.getTags();
bool tag_found = false;
- for (auto tag : tags) {
- if ((*elem)->hasServerTag(tag) || (*elem)->hasAllServerTag()) {
+ for (auto const& tag : tags) {
+ if ((*elem)->hasServerTag(tag) ||
+ (*elem)->hasAllServerTag()) {
tag_found = true;
break;
}
/// @brief Returns backend type in the textual format.
///
- /// @return "pgsql".
+ /// @return "postgresql".
std::string getType() const;
/// @brief Returns backend host.
return (parameters_);
}
- /// @brief Sets IO service to be used by the Postgres config backend.
+ /// @brief Sets IO service to be used by the PostgreSQL config backend.
///
/// @param IOService object, used for all ASIO operations.
static void setIOService(const isc::asiolink::IOServicePtr& io_service) {
/// @return Number of affected rows.
uint64_t updateDeleteQuery(size_t index, const db::PsqlBindArray& in_bindings);
- /// @brief Represents connection to the Postgres database.
+ /// @brief Represents connection to the PostgreSQL database.
db::PgSqlConnection conn_;
protected:
+
/// @brief Timer name used to register database reconnect timer.
std::string timer_name_;
private:
+
/// @brief Reference counter for @ScopedAuditRevision instances.
int audit_revision_ref_count_;
// Server tag is 'all'.
tag = "all";
} else {
- auto tags = server_selector.getTags();
+ const auto& tags = server_selector.getTags();
// This test is not meant to handle multiple server tags all at once.
if (tags.size() > 1) {
ADD_FAILURE() << "Test error: do not use multiple server tags";
// Server tag is 'all'.
tag = "all";
} else {
- auto tags = server_selector.getTags();
+ const auto& tags = server_selector.getTags();
// This test is not meant to handle multiple server tags all at once.
if (tags.size() > 1) {
ADD_FAILURE() << "Test error: do not use multiple server tags";
// Store shared network in the database.
ASSERT_NO_THROW_LOG(cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(),
- shared_network));
+ shared_network));
// Store subnet associated with the shared network in the database.
ASSERT_NO_THROW_LOG(cbptr_->createUpdateSubnet4(ServerSelector::ALL(), subnet));
},
{
"dhcp4_subnet",
- AuditEntry::ModificationType::UPDATE, "deleted all shared networks"
+ AuditEntry::ModificationType::UPDATE, "deleted all shared networks"
}
});
/// checks that number and content of the expected new entries have been
/// added to the end of this collection.
///
- /// @param exp_entries a list of the new audit entries expected.
+ /// @param exp_entries a list of the expected new audit entries.
/// @param server_selector Server selector to be used for next query.
void testNewAuditEntry(const std::vector<ExpAuditEntry>& exp_entries,
const db::ServerSelector& server_selector);
}
bound_strs_.push_back(ConstStringPtr(new std::string(value)));
+
values_.insert(values_.begin() + index, bound_strs_.back()->c_str());
lengths_.insert(lengths_.begin() + index, value.size());
formats_.insert(formats_.begin() + index, TEXT_FMT);
void PsqlBindArray::addTempBinary(const std::vector<uint8_t>& data) {
bound_strs_.push_back(ConstStringPtr(new std::string(
- (reinterpret_cast<const char*>(data.data())), data.size())));
+ reinterpret_cast<const char*>(data.data()), data.size())));
values_.push_back(reinterpret_cast<const char*>(bound_strs_.back()->data()));
lengths_.push_back(data.size());
}
bound_strs_.push_back(ConstStringPtr(new std::string(
- reinterpret_cast<const char*>(data),len)));
+ reinterpret_cast<const char*>(data), len)));
+
values_.push_back(bound_strs_.back()->data());
lengths_.push_back(len);
formats_.push_back(BINARY_FMT);
}
-
-void PsqlBindArray::add(const bool& value) {
+void PsqlBindArray::add(const bool& value) {
add(value ? TRUE_STR : FALSE_STR);
}
/// mean duplicating strings where it isn't strictly necessary.
void PsqlBindArray::addTempString(const std::string& str) {
bound_strs_.push_back(ConstStringPtr(new std::string(str)));
+
PsqlBindArray::add((bound_strs_.back())->c_str());
}
//
// Sadly boost::posix_time::to_time_t() was not added until 1.58,
// so do it ourselves.
- ptime epoch(boost::gregorian::date(1970,1,1));
+ ptime epoch(boost::gregorian::date(1970, 1, 1));
time_duration::sec_type since_epoch = (timestamp - epoch).total_seconds();
time_t input_time(since_epoch);
return ( (values_.at(index) == NULL) && (lengths_.at(index) == 0) );
}
-
std::string
PgSqlExchange::convertToDatabaseTime(const time_t input_time) {
struct tm tinfo;
PgSqlExchange::convertFromDatabaseTime(const std::string& db_time_val) {
// Convert string time value to time_t
time_t new_time;
- try {
+ try {
new_time = (boost::lexical_cast<time_t>(db_time_val));
} catch (const std::exception& ex) {
isc_throw(BadValue, "Database time value is invalid: " << db_time_val);
}
}
-
isc::asiolink::IOAddress
PgSqlExchange::getInetValue6(const PgSqlResult& r, const int row,
const size_t col) {
/// the buffer values.
///
/// @param data buffer of binary data.
- /// @param len number of bytes of data in buffer
+ /// @param len number of bytes of data in buffer
/// @throw DbOperationError if data is NULL.
void addTempBuffer(const uint8_t* data, const size_t len);
-- Fix constraint typo on dhcp4_option_def_server
ALTER TABLE dhcp4_option_def_server
DROP CONSTRAINT dhcp4_option_def_server_option_def_id_fkey,
- ADD CONSTRAINT dhcp4_option_def_server_option_def_id_fkey
+ ADD CONSTRAINT dhcp4_option_def_server_option_def_id_fkey
FOREIGN KEY (option_def_id) REFERENCES dhcp4_option_def(id) ON DELETE CASCADE;
-- DROP shared-network ADEL triggers that should not exist.
-- a parent object when an option is modified.
--
-- The following parameters are passed to the procedure:
--- - modification_type: 'create', 'update' or 'delete'
+-- - modification_type: "create", "update" or "delete"
-- - scope_id: identifier of the option scope, e.g.
--- global, subnet specific etc.
+-- global, subnet specific etc. See dhcp_option_scope
+-- for specific values.
-- - option_id: identifier of the option.
-- - p_subnet_id: identifier of the subnet if the option
-- belongs to the subnet.
snid BIGINT;
sid BIGINT;
cascade_transaction BOOLEAN := true;
- ct TEXT;
BEGIN
-- Cascade transaction flag is set to true to prevent creation of
-- the audit entries for the options when the options are
--
-- -----------------------------------------------------
--
+-- Stored procedure which updates modification timestamp of
+-- a parent object when an option is modified.
+--
-- The following parameters are passed to the procedure:
-- - modification_type: "create", "update" or "delete"
-- - scope_id: identifier of the option scope, e.g.
-- global, subnet specific etc. See dhcp_option_scope
-- for specific values.
-- - option_id: identifier of the option.
--- - subnet_id: identifier of the subnet if the option
+-- - p_subnet_id: identifier of the subnet if the option
-- belongs to the subnet.
-- - host_id: identifier of the host if the option
-- - belongs to the host.
-- belongs to the pool.
-- - pd_pool_id: identifier of the pool if the option
-- belongs to the pd pool.
--- - modification_ts: modification timestamp of the
+-- - p_modification_ts: modification timestamp of the
-- option.
-- Some arguments are prefixed with "p_" to avoid ambiguity
-- with column names in SQL statements. PostgreSQL does not
snid BIGINT;
sid BIGINT;
cascade_transaction BOOLEAN := false;
-
BEGIN
-- Cascade transaction flag is set to true to prevent creation of
-- the audit entries for the options when the options are
-- entire subnet. The only case when the object_type will be
-- set to 'dhcp6_options' is when a global option is added.
-- Global options do not have the owner.
+
cascade_transaction := get_session_boolean('kea.cascade_transaction');
IF cascade_transaction = false THEN
-- todo: host manager hasn't been updated to use audit
-- Fix constraint typo on dhcp4_option_def_server
ALTER TABLE dhcp4_option_def_server
DROP CONSTRAINT dhcp4_option_def_server_option_def_id_fkey,
- ADD CONSTRAINT dhcp4_option_def_server_option_def_id_fkey
+ ADD CONSTRAINT dhcp4_option_def_server_option_def_id_fkey
FOREIGN KEY (option_def_id) REFERENCES dhcp4_option_def(id) ON DELETE CASCADE;
-- DROP shared-network ADEL triggers that should not exist.
-- a parent object when an option is modified.
--
-- The following parameters are passed to the procedure:
--- - modification_type: 'create', 'update' or 'delete'
+-- - modification_type: "create", "update" or "delete"
-- - scope_id: identifier of the option scope, e.g.
--- global, subnet specific etc.
+-- global, subnet specific etc. See dhcp_option_scope
+-- for specific values.
-- - option_id: identifier of the option.
-- - p_subnet_id: identifier of the subnet if the option
-- belongs to the subnet.
snid BIGINT;
sid BIGINT;
cascade_transaction BOOLEAN := true;
- ct TEXT;
BEGIN
-- Cascade transaction flag is set to true to prevent creation of
-- the audit entries for the options when the options are
--
-- -----------------------------------------------------
--
+-- Stored procedure which updates modification timestamp of
+-- a parent object when an option is modified.
+--
-- The following parameters are passed to the procedure:
-- - modification_type: "create", "update" or "delete"
-- - scope_id: identifier of the option scope, e.g.
-- global, subnet specific etc. See dhcp_option_scope
-- for specific values.
-- - option_id: identifier of the option.
--- - subnet_id: identifier of the subnet if the option
+-- - p_subnet_id: identifier of the subnet if the option
-- belongs to the subnet.
-- - host_id: identifier of the host if the option
-- - belongs to the host.
-- belongs to the pool.
-- - pd_pool_id: identifier of the pool if the option
-- belongs to the pd pool.
--- - modification_ts: modification timestamp of the
+-- - p_modification_ts: modification timestamp of the
-- option.
-- Some arguments are prefixed with "p_" to avoid ambiguity
-- with column names in SQL statements. PostgreSQL does not
snid BIGINT;
sid BIGINT;
cascade_transaction BOOLEAN := false;
-
BEGIN
-- Cascade transaction flag is set to true to prevent creation of
-- the audit entries for the options when the options are
-- entire subnet. The only case when the object_type will be
-- set to 'dhcp6_options' is when a global option is added.
-- Global options do not have the owner.
+
cascade_transaction := get_session_boolean('kea.cascade_transaction');
IF cascade_transaction = false THEN
-- todo: host manager hasn't been updated to use audit