Commit 9346fb88 authored by Francis Dupont's avatar Francis Dupont Committed by Marcin Siodelski

[642-update-mysql-cb-with-calls-to-set-delete-and-retrieve-servers] Changed...

[642-update-mysql-cb-with-calls-to-set-delete-and-retrieve-servers] Changed new schema to 8.1 (vs 9.0) and addressed trivial comments
parent a621db70
......@@ -267,7 +267,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
std::string name = out_bindings[1]->getString();
if (!name.empty()) {
last_param = StampedValue::create(out_bindings[1]->getString(),
last_param = StampedValue::create(name,
out_bindings[2]->getString(),
static_cast<Element::types>
(out_bindings[3]->getInteger<uint8_t>()));
......@@ -287,7 +287,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
// parameter already exists and belongs to 'all'.
auto& index = local_parameters.get<StampedValueNameIndexTag>();
auto existing = index.find(name);
if (existing != local_parameters.end()) {
if (existing != index.end()) {
// This parameter was already fetched. Let's check if we should
// replace it or not.
if (!last_param_server_tag.amAll() && (*existing)->hasAllServerTag()) {
......@@ -302,7 +302,7 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
// If there is no such parameter yet or the existing parameter
// belongs to a different server and the inserted parameter is
// not for all servers.
if ((existing == local_parameters.end()) ||
if ((existing == index.end()) ||
(!(*existing)->hasServerTag(last_param_server_tag) &&
!last_param_server_tag.amAll())) {
local_parameters.insert(last_param);
......@@ -930,14 +930,14 @@ MySqlConfigBackendImpl::getServers(const int index,
}
void
MySqlConfigBackendImpl::createUpdateServer(const int create_audit_revision_index,
const int create_index,
const int update_index,
MySqlConfigBackendImpl::createUpdateServer(const int& create_audit_revision,
const int& create_index,
const int& update_index,
const ServerPtr& server) {
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision audit_revision(this,
create_audit_revision_index,
create_audit_revision,
ServerSelector::ALL(),
"server set",
true);
......@@ -962,8 +962,8 @@ MySqlConfigBackendImpl::createUpdateServer(const int create_audit_revision_index
}
uint64_t
MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index,
const int delete_index,
MySqlConfigBackendImpl::deleteServer(const int& create_audit_revision,
const int& delete_index,
const std::string& server_tag) {
MySqlTransaction transaction(conn_);
......@@ -971,7 +971,7 @@ MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index,
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this, create_audit_revision_index,
audit_revision(this, create_audit_revision,
ServerSelector::ALL(), "deleting a server", false);
// Specify which server should be deleted.
......@@ -987,16 +987,16 @@ MySqlConfigBackendImpl::deleteServer(const int create_audit_revision_index,
}
uint64_t
MySqlConfigBackendImpl::deleteAllServers(const int create_audit_revision_index,
const int delete_index) {
MySqlConfigBackendImpl::deleteAllServers(const int& create_audit_revision,
const int& delete_index) {
MySqlTransaction transaction(conn_);
// Create scoped audit revision. As long as this instance exists
// no new audit revisions are created in any subsequent calls.
ScopedAuditRevision
audit_revision(this, create_audit_revision_index,
ServerSelector::ALL(), "deleting a server", false);
audit_revision(this, create_audit_revision,
ServerSelector::ALL(), "deleting all servers", false);
MySqlBindingCollection in_bindings;
......
......@@ -643,9 +643,9 @@ public:
/// @param create_index Index of the INSERT query to be used.
/// @param update_index Index of the UPDATE query to be used.
/// @param server Pointer to the server to be inserted or updated.
void createUpdateServer(const int create_audit_revision_index,
const int create_index,
const int update_index,
void createUpdateServer(const int& create_audit_revision,
const int& create_index,
const int& update_index,
const db::ServerPtr& server);
/// @brief Attempts to delete a server having a given tag.
......@@ -655,7 +655,7 @@ public:
/// @param create_index Index of the DELETE query to be executed.
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
uint64_t deleteServer(const int create_audit_revision_index, const int index,
uint64_t deleteServer(const int& create_audit_revision, const int& index,
const std::string& server_tag);
/// @brief Attempts to delete all servers.
......@@ -667,8 +667,8 @@ public:
/// revision.
/// @param server_tag Tag of the server to be deleted.
/// @return Number of deleted servers.
uint64_t deleteAllServers(const int create_audit_revision_index,
const int index);
uint64_t deleteAllServers(const int& create_audit_revision,
const int& index);
/// @brief Returns backend type in the textual format.
///
......
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Mon Jun 17 2019 14:28
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
#include <cstddef>
#include <log/message_types.h>
......@@ -196,7 +196,7 @@ const char* values[] = {
"MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK_OPTION6", "create or update shared network: %1 option",
"MYSQL_CB_CREATE_UPDATE_SUBNET4", "create or update subnet: %1",
"MYSQL_CB_CREATE_UPDATE_SUBNET6", "create or update subnet: %1",
"MYSQL_CB_DEINIT_OK", "unloading MYSQAL CB hooks library successful",
"MYSQL_CB_DEINIT_OK", "unloading MYSQL CB hooks library successful",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4", "delete all global parameters",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS4_RESULT", "deleted: %1 entries",
"MYSQL_CB_DELETE_ALL_GLOBAL_PARAMETERS6", "delete all global parameters",
......
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Mon Jun 17 2019 14:28
// File created from ../../../../src/hooks/dhcp/mysql_cb/mysql_cb_messages.mes on Tue Jun 25 2019 16:12
#ifndef MYSQL_CB_MESSAGES_H
#define MYSQL_CB_MESSAGES_H
......
......@@ -35,6 +35,14 @@ Debug message issued when triggered an action to create or update option definit
% MYSQL_CB_CREATE_UPDATE_OPTION_DEF6 create or update option definition: %1 code: %2
Debug message issued when triggered an action to create or update option definition
% MYSQL_CB_CREATE_UPDATE_SERVER4 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv4
server information.
% MYSQL_CB_CREATE_UPDATE_SERVER6 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv6
server information.
% MYSQL_CB_CREATE_UPDATE_SHARED_NETWORK4 create or update shared network: %1
Debug message issued when triggered an action to create or update shared network
......@@ -53,15 +61,7 @@ Debug message issued when triggered an action to create or update subnet
% MYSQL_CB_CREATE_UPDATE_SUBNET6 create or update subnet: %1
Debug message issued when triggered an action to create or update subnet
% MYSQL_CB_CREATE_UPDATE_SERVER4 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv4
server information.
% MYSQL_CB_CREATE_UPDATE_SERVER6 create or update server: %1
Debug message issued when triggered an action to create or update a DHCPv6
server information.
% MYSQL_CB_DEINIT_OK unloading MYSQAL CB hooks library successful
% MYSQL_CB_DEINIT_OK unloading MYSQL CB hooks library successful
This informational message indicates that the MySQL Configuration Backend hooks
library has been unloaded successfully.
......@@ -89,18 +89,6 @@ Debug message issued when triggered an action to delete all option definitions
% MYSQL_CB_DELETE_ALL_OPTION_DEFS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all option definitions
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SERVERS4 delete all DHCPv4 servers
Debug message issued when triggered an action to delete all servers.
......@@ -113,6 +101,18 @@ Debug message issued when triggered an action to delete all servers.
% MYSQL_CB_DELETE_ALL_SERVERS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all servers.
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS4_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6 delete all shared networks
Debug message issued when triggered an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SHARED_NETWORKS6_RESULT deleted: %1 entries
Debug message indicating the result of an action to delete all shared networks
% MYSQL_CB_DELETE_ALL_SUBNETS4 delete all subnets
Debug message issued when triggered an action to delete all subnets
......
......@@ -492,7 +492,7 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteServer) {
"server set");
}
// Verify that the server has been updated.
// Verify that the server has been updated.
EXPECT_NO_THROW(returned_server = cbptr_->getServer4(ServerTag("server1")));
ASSERT_TRUE(returned_server);
EXPECT_EQ("server1", returned_server->getServerTag().get());
......
......@@ -533,7 +533,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteServer) {
"server set");
}
// Verify that the server has been updated.
// Verify that the server has been updated.
EXPECT_NO_THROW(returned_server = cbptr_->getServer6(ServerTag("server1")));
ASSERT_TRUE(returned_server);
EXPECT_EQ("server1", returned_server->getServerTag().get());
......
......@@ -38,6 +38,60 @@ ALTER TABLE dhcp6_subnet
ADD COLUMN min_valid_lifetime INT(10) DEFAULT NULL,
ADD COLUMN max_valid_lifetime INT(10) DEFAULT NULL;
# Create dhcp4_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AINS AFTER INSERT ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp4_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AUPD AFTER UPDATE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp4_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_ADEL AFTER DELETE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', OLD.id, "delete");
END $$
DELIMITER ;
# Create dhcp6_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AINS AFTER INSERT ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp6_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AUPD AFTER UPDATE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp6_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_ADEL AFTER DELETE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', OLD.id, "delete");
END $$
DELIMITER ;
# Update the schema version number
UPDATE schema_version
SET version = '8', minor = '1';
......
#!/bin/sh
# Include utilities. Use installed version if available and
# use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
fi
VERSION=`mysql_version "$@"`
if [ "$VERSION" != "8.0" ]; then
printf "This script upgrades 8.0 to 9.0. Reported version is $VERSION. Skipping upgrade.\n"
exit 0
fi
mysql "$@" <<EOF
# Create dhcp4_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AINS AFTER INSERT ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp4_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_AUPD AFTER UPDATE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp4_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp4_server_ADEL AFTER DELETE ON dhcp4_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP4('dhcp4_server', OLD.id, "delete");
END $$
DELIMITER ;
# Create dhcp6_server insert trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AINS AFTER INSERT ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "create");
END $$
DELIMITER ;
# Create dhcp6_server update trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_AUPD AFTER UPDATE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', NEW.id, "update");
END $$
DELIMITER ;
# Create dhcp6_server delete trigger
DELIMITER $$
CREATE TRIGGER dhcp6_server_ADEL AFTER DELETE ON dhcp6_server
FOR EACH ROW
BEGIN
CALL createAuditEntryDHCP6('dhcp6_server', OLD.id, "delete");
END $$
DELIMITER ;
# Update the schema version number
UPDATE schema_version
SET version = '9', minor = '0';
# This line concludes database upgrade to version 9.0.
EOF
RESULT=$?
exit $?
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment