Commit 00e880ae authored by Marcin Siodelski's avatar Marcin Siodelski

[#93,!63] Server selection partially working for global paramneters.

parent 1d48686b
......@@ -482,9 +482,9 @@ EOF
qry="select id, tag, description, modification_ts from dhcp4_server"
run_statement "dhcp4_server" "$qry"
# table: dhcp4_server - check if it contains default entries
# table: dhcp4_server - check if it contains default entry
qry="select count(*) from dhcp4_server"
run_statement "dhcp4_server" "$qry" 2
run_statement "dhcp4_server" "$qry" 1
# table: dhcp4_audit
qry="select id, object_type, object_id, modification_type, modification_ts, log_message from dhcp4_audit"
......@@ -538,9 +538,9 @@ EOF
qry="select id, tag, description, modification_ts from dhcp6_server"
run_statement "dhcp6_server" "$qry"
# table: dhcp6_server - check if it contains default entries
# table: dhcp6_server - check if it contains default entry
qry="select count(*) from dhcp6_server"
run_statement "dhcp6_server" "$qry" 2
run_statement "dhcp6_server" "$qry" 1
# table: dhcp6_audit
qry="select id, object_type, object_id, modification_type, modification_ts, log_message from dhcp6_audit"
......
......@@ -179,6 +179,7 @@ public:
/// @param value Value of the global parameter.
void createUpdateGlobalParameter4(const db::ServerSelector& /* server_selector */,
const StampedValuePtr& value) {
MySqlTransaction transaction(conn_);
auto tags = getServerTags(server_selector);
......@@ -1570,8 +1571,8 @@ TaggedStatementArray tagged_statements = { {
"INNER JOIN dhcp4_global_parameter_server AS a "
" ON g.id = a.parameter_id "
"INNER JOIN dhcp4_server AS s "
" ON a.server_id = s.id "
"WHERE s.tag = ? AND g.name = ? "
" ON (a.server_id = s.id) OR (a.server_id = 1) "
"WHERE (s.tag = ? OR s.id = 1) AND g.name = ? "
"ORDER BY g.id"
},
......@@ -1586,8 +1587,8 @@ TaggedStatementArray tagged_statements = { {
"INNER JOIN dhcp4_global_parameter_server AS a "
" ON g.id = a.parameter_id "
"INNER JOIN dhcp4_server AS s "
" ON a.server_id = s.id "
"WHERE s.tag = ? "
" ON (a.server_id = s.id) OR (a.server_id = 1) "
"WHERE (s.tag = ? OR s.id = 1)"
"ORDER BY g.id"
},
......@@ -1602,8 +1603,8 @@ TaggedStatementArray tagged_statements = { {
"INNER JOIN dhcp4_global_parameter_server AS a "
" ON g.id = a.parameter_id "
"INNER JOIN dhcp4_server AS s "
" ON a.server_id = s.id "
"WHERE s.tag = ? AND g.modification_ts > ? "
" ON (a.server_id = s.id) OR (a.server_id = 1) "
"WHERE (s.tag = ? OR s.id=1) AND g.modification_ts > ? "
"ORDER BY g.id"
},
......@@ -2379,13 +2380,22 @@ TaggedStatementArray tagged_statements = { {
// Delete global parameter by name.
{ MySqlConfigBackendDHCPv4Impl::DELETE_GLOBAL_PARAMETER4,
"DELETE FROM dhcp4_global_parameter "
"WHERE name = ?"
"DELETE g FROM dhcp4_global_parameter AS g "
"INNER JOIN dhcp4_global_parameter_server AS a "
" ON g.id = a.parameter_id "
"INNER JOIN dhcp4_server AS s"
" ON (a.server_id = s.id) "
"WHERE s.tag = ? AND g.name = ? "
},
// Delete all global parameters.
{ MySqlConfigBackendDHCPv4Impl::DELETE_ALL_GLOBAL_PARAMETERS4,
"DELETE FROM dhcp4_global_parameter"
"DELETE g FROM dhcp4_global_parameter AS g "
"INNER JOIN dhcp4_global_parameter_server AS a "
" ON g.id = a.parameter_id "
"INNER JOIN dhcp4_server AS s"
" ON (a.server_id = s.id) "
"WHERE s.tag = ?"
},
// Delete subnet by id.
......@@ -2747,12 +2757,13 @@ uint64_t
MySqlConfigBackendDHCPv4::deleteGlobalParameter4(const ServerSelector& /*server_selector*/,
const std::string& name) {
return (impl_->deleteFromTable(MySqlConfigBackendDHCPv4Impl::DELETE_GLOBAL_PARAMETER4,
name));
server_selector, name));
}
uint64_t
MySqlConfigBackendDHCPv4::deleteAllGlobalParameters4(const ServerSelector& /* server_selector */) {
return (impl_->deleteFromTable(MySqlConfigBackendDHCPv4Impl::DELETE_ALL_GLOBAL_PARAMETERS4));
MySqlConfigBackendDHCPv4::deleteAllGlobalParameters4(const ServerSelector& server_selector) {
return (impl_->deleteFromTable(MySqlConfigBackendDHCPv4Impl::DELETE_ALL_GLOBAL_PARAMETERS4,
server_selector));
}
std::string
......
......@@ -72,10 +72,6 @@ std::set<std::string>
MySqlConfigBackendImpl::getServerTags(const ServerSelector& server_selector) const {
std::set<std::string> tags;
switch (server_selector.getType()) {
case ServerSelector::Type::UNASSIGNED:
tags.insert("unassigned");
return (tags);
case ServerSelector::Type::ALL:
tags.insert("all");
return (tags);
......@@ -84,7 +80,7 @@ MySqlConfigBackendImpl::getServerTags(const ServerSelector& server_selector) con
return (server_selector.getTags());
}
// Impossible condition.
// Unassigned server case.
return (tags);
}
......@@ -116,6 +112,29 @@ MySqlConfigBackendImpl::deleteFromTable(const int index, const std::string& key)
return (conn_.updateDeleteQuery(index, in_bindings));
}
uint64_t
MySqlConfigBackendImpl::deleteFromTable(const int index,
const ServerSelector& server_selector,
const std::string& key) {
uint64_t deleted_entries = 0;
auto tags = getServerTags(server_selector);
for (auto tag : tags) {
MySqlBindingCollection in_bindings = {
MySqlBinding::createString(tag)
};
// Optionally add the key.
if (!key.empty()) {
in_bindings.push_back(MySqlBinding::createString(key));
}
deleted_entries += conn_.updateDeleteQuery(index, in_bindings);
}
return (deleted_entries);
}
void
MySqlConfigBackendImpl::getOptionDefs(const int index,
const MySqlBindingCollection& in_bindings,
......
......@@ -64,6 +64,18 @@ public:
uint64_t deleteFromTable(const int index,
const std::string& key);
/// @brief Sends query to delete rows from a table.
///
/// @param index Index of the statement to be executed.
/// @param server_selector Server selector.
/// @param key String value to be used as input binding to the delete
/// statement. The default value is empty which indicates that the
/// key should not be used in the query.
/// @return number of deleted rows.
uint64_t deleteFromTable(const int index,
const db::ServerSelector& server_selector,
const std::string& key = "");
/// @brief Sends query to the database to retrieve multiple option
/// definitions.
///
......
......@@ -812,17 +812,10 @@ CREATE TABLE IF NOT EXISTS dhcp4_server (
KEY key_dhcp4_server_modification_ts (modification_ts)
) ENGINE=InnoDB;
# Special server entry meaning "unassigned server". This refers
# to configuration entries that shouldn't be used by any of the
# servers, e.g. when configuration entry is created but an
# administrator doesn't want the servers to start using it yet.
INSERT INTO dhcp4_server(id, tag, description, modification_ts)
VALUES(1, "unassigned", "special type: unassigned server", NOW());
# Special server entry meaning "all servers". This refers to
# the configuration entries owned by all servers.
INSERT INTO dhcp4_server(id, tag, description, modification_ts)
VALUES(2, "all", "special type: all servers", NOW());
VALUES(1, "all", "special type: all servers", NOW());
-- -----------------------------------------------------
-- Table `dhcp4_audit`
......@@ -1077,17 +1070,10 @@ CREATE TABLE IF NOT EXISTS dhcp6_server (
KEY key_dhcp6_server_modification_ts (modification_ts)
) ENGINE=InnoDB;
# Special server entry meaning "unassigned server". This refers
# to configuration entries that shouldn't be used by any of the
# servers, e.g. when configuration entry is created but an
# administrator doesn't want the servers to start using it yet.
INSERT INTO dhcp6_server(id, tag, description, modification_ts)
VALUES(1, "unassigned", "special type: unassigned server", NOW());
# Special server entry meaning "all servers". This refers to
# the configuration entries owned by all servers.
INSERT INTO dhcp6_server(id, tag, description, modification_ts)
VALUES(2, "all", "special type: all servers", NOW());
VALUES(1, "all", "special type: all servers", NOW());
-- -----------------------------------------------------
-- Table `dhcp6_audit`
......
......@@ -152,17 +152,10 @@ CREATE TABLE IF NOT EXISTS dhcp4_server (
KEY key_dhcp4_server_modification_ts (modification_ts)
) ENGINE=InnoDB;
# Special server entry meaning "unassigned server". This refers
# to configuration entries that shouldn't be used by any of the
# servers, e.g. when configuration entry is created but an
# administrator doesn't want the servers to start using it yet.
INSERT INTO dhcp4_server(id, tag, description, modification_ts)
VALUES(1, "unassigned", "special type: unassigned server", NOW());
# Special server entry meaning "all servers". This refers to
# the configuration entries owned by all servers.
INSERT INTO dhcp4_server(id, tag, description, modification_ts)
VALUES(2, "all", "special type: all servers", NOW());
VALUES(1, "all", "special type: all servers", NOW());
# Create table dhcp4_audit
#
......@@ -402,17 +395,10 @@ CREATE TABLE IF NOT EXISTS dhcp6_server (
KEY key_dhcp6_server_modification_ts (modification_ts)
) ENGINE=InnoDB;
# Special server entry meaning "unassigned server". This refers
# to configuration entries that shouldn't be used by any of the
# servers, e.g. when configuration entry is created but an
# administrator doesn't want the servers to start using it yet.
INSERT INTO dhcp6_server(id, tag, description, modification_ts)
VALUES(1, "unassigned", "special type: unassigned server", NOW());
# Special server entry meaning "all servers". This refers to
# the configuration entries owned by all servers.
INSERT INTO dhcp6_server(id, tag, description, modification_ts)
VALUES(2, "all", "special type: all servers", NOW());
VALUES(1, "all", "special type: all servers", NOW());
# Create table dhcp6_audit
#
......
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