From 7e052e24ee29fc75c0c6ce3e06b171e54f3ffe99 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 7 May 2020 13:16:11 -0600 Subject: [PATCH 1/5] Added interfaces tables migration --- .../migrations/20200507000000_interfaces.sql | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 traffic_ops/app/db/migrations/20200507000000_interfaces.sql diff --git a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql new file mode 100644 index 0000000000..7b8b49a1a9 --- /dev/null +++ b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql @@ -0,0 +1,113 @@ +/* + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +-- +goose Up +CREATE TABLE interface ( + max_bandwidth bigint DEFAULT NULL CHECK (max_bandwidth IS NULL OR max_bandwidth >= 0), + monitor boolean NOT NULL, + mtu bigint DEFAULT 1500 CHECK (mtu IS NULL OR mtu > 1280), + name text NOT NULL CHECK (name != ''), + server bigint NOT NULL, + PRIMARY KEY (name, server), + FOREIGN KEY (server) REFERENCES server(id) ON DELETE RESTRICT ON UPDATE CASCADE +); +CREATE TABLE ip_address ( + address inet NOT NULL, + gateway inet CHECK ( + gateway IS NULL OR ( + family(gateway) = 4 AND + masklen(gateway) = 32 + ) OR ( + family(gateway) = 6 AND + masklen(gateway) = 128 + ) + ), + interface text NOT NULL, + server bigint NOT NULL, + service_address boolean NOT NULL DEFAULT FALSE, + PRIMARY KEY (address, interface, server), + FOREIGN KEY (server) REFERENCES server(id) ON DELETE RESTRICT ON UPDATE CASCADE, + FOREIGN KEY (interface, server) REFERENCES interface(name, server) ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TYPE server_ip_address AS (address inet, gateway inet, service_address boolean); +CREATE TYPE server_interface AS (ip_addresses server_ip_address ARRAY, max_bandwidth bigint, monitor boolean, mtu bigint, name text); + +INSERT INTO interface( + max_bandwidth, + monitor, + mtu, + name, + server +) +SELECT NULL, TRUE, server.interface_mtu::bigint, server.interface_name, id +FROM server; + +INSERT INTO ip_address( + address, + gateway, + interface, + server, + service_address +) +SELECT + set_masklen( + server.ip_address::inet, + CASE + WHEN server.ip_netmask IS NULL THEN 32 + WHEN server.ip_netmask = '' THEN 32 + ELSE + (SELECT SUM( + get_bit(digit, 0) + + get_bit(digit, 1) + + get_bit(digit, 2) + + get_bit(digit, 3) + + get_bit(digit, 4) + + get_bit(digit, 5) + + get_bit(digit, 6) + + get_bit(digit, 7) + )::int FROM ( + SELECT regexp_split_to_table::int::bit(8) AS digit + FROM regexp_split_to_table(server.ip_netmask, '\.') + ) AS digits) + END + ), + NULLIF(regexp_replace(server.ip_gateway, '/\d+$', ''), '')::inet, + server.interface_name, + server.id, + server.ip_address_is_service +FROM server +WHERE server.ip_address IS NOT NULL +AND server.ip_address != ''; + +INSERT INTO ip_address( + address, + gateway, + interface, + server, + service_address +) +SELECT + trim(BOTH '[]' FROM server.ip6_address)::inet, + NULLIF(regexp_replace(server.ip6_gateway, '/\d+$', ''), '')::inet, + server.interface_name, + server.id, + server.ip6_address_is_service +FROM server +WHERE server.ip6_address IS NOT NULL +AND server.ip6_address != ''; + +-- +goose Down +DROP TABLE IF EXISTS ip_address; +DROP TABLE IF EXISTS interface; From c526ad5a3e6cf81bb882050e70629da79b160bb6 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 7 May 2020 14:37:06 -0600 Subject: [PATCH 2/5] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e9f915dd6..06dadaa126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Changed some Traffic Ops Go Client methods to use `DeliveryServiceNullable` inputs and outputs. - Changed Traffic Portal to use Traffic Ops API v3 - Changed the access logs in Traffic Ops to now show the route ID with every API endpoint call. The Route ID is appended to the end of the access log line. +- With the addition of multiple server interfaces, interface data is constructed from IP Address/Gateway/Netmask (and their IPv6 counterparts) and Interface Name and Interface MTU fields on services. These **MUST** have proper, valid data before attempting to upgrade or the upgrade **WILL** fail. In particular IP fields need to be valid IP addresses/netmasks, and MTU must only be positive integers of at least 1280. ### Deprecated - Deprecated the non-nullable `DeliveryService` Go struct and other structs that use it. `DeliveryServiceNullable` structs should be used instead. From fcb4ddf9b03b677534a9cbc61d1da8d62e5356dc Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 14 May 2020 09:56:07 -0600 Subject: [PATCH 3/5] Added type drop statements --- traffic_ops/app/db/migrations/20200507000000_interfaces.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql index 7b8b49a1a9..65fa0d8bde 100644 --- a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql +++ b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql @@ -111,3 +111,6 @@ AND server.ip6_address != ''; -- +goose Down DROP TABLE IF EXISTS ip_address; DROP TABLE IF EXISTS interface; + +DROP TYPE IF EXISTS server_ip; +DROP TYPE IF EXISTS server_interface; From 98d79a7e671c11f9d1a45a18f7bc09173a183499 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 14 May 2020 11:54:26 -0600 Subject: [PATCH 4/5] Fixed typo --- traffic_ops/app/db/migrations/20200507000000_interfaces.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql index 65fa0d8bde..c7719c6dc3 100644 --- a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql +++ b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql @@ -112,5 +112,5 @@ AND server.ip6_address != ''; DROP TABLE IF EXISTS ip_address; DROP TABLE IF EXISTS interface; -DROP TYPE IF EXISTS server_ip; +DROP TYPE IF EXISTS server_ip_address; DROP TYPE IF EXISTS server_interface; From 416a7fe06691cf2ce1a775a21cfe77d9d11db25a Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Fri, 15 May 2020 13:19:13 -0600 Subject: [PATCH 5/5] Fixed type drop ordering --- traffic_ops/app/db/migrations/20200507000000_interfaces.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql index c7719c6dc3..6cfbee1a68 100644 --- a/traffic_ops/app/db/migrations/20200507000000_interfaces.sql +++ b/traffic_ops/app/db/migrations/20200507000000_interfaces.sql @@ -112,5 +112,5 @@ AND server.ip6_address != ''; DROP TABLE IF EXISTS ip_address; DROP TABLE IF EXISTS interface; -DROP TYPE IF EXISTS server_ip_address; DROP TYPE IF EXISTS server_interface; +DROP TYPE IF EXISTS server_ip_address;