From 74956aaf4d5d07d43af9a5c586a5868eee35e4a5 Mon Sep 17 00:00:00 2001 From: Rima Shah Date: Mon, 21 Nov 2022 18:10:00 -0700 Subject: [PATCH 01/21] Added description field to server capabilities --- CHANGELOG.md | 1 + lib/go-tc/server_capabilities.go | 1 + ...04800_add_description_in_sc_table.down.sql | 18 +++++ ...6304800_add_description_in_sc_table.up.sql | 18 +++++ .../api/v3/server_capabilities_test.go | 2 +- traffic_ops/testing/api/v3/tc-fixtures.json | 18 +++-- .../api/v4/server_capabilities_test.go | 12 +-- traffic_ops/testing/api/v4/tc-fixtures.json | 18 +++-- .../api/v5/server_capabilities_test.go | 12 +-- traffic_ops/testing/api/v5/tc-fixtures.json | 18 +++-- .../servercapability/servercapability.go | 21 ++++-- .../form.serverCapability.tpl.html | 8 ++ .../table.serverCapabilities.tpl.html | 2 + .../integration/Data/servercapabilities.ts | 73 ++++++++++++------- .../specs/ServerCapabilities.spec.ts | 8 +- 15 files changed, 159 insertions(+), 71 deletions(-) create mode 100644 traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.down.sql create mode 100644 traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dd5d1675d..64c4a14f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [unreleased] ### Added +- [#6234](https://github.com/apache/trafficcontrol/issues/6234) *Traffic Ops, Traffic Portal* Added description field to Server Capabilities - [#6033](https://github.com/apache/trafficcontrol/issues/6033) *Traffic Ops, Traffic Portal* Added ability to assign multiple servers per capability. - [#7081](https://github.com/apache/trafficcontrol/issues/7081) *Traffic Router* Added better log messages for TR connection exceptions. - [#7089](https://github.com/apache/trafficcontrol/issues/7089) *Traffic Router* Added the ability to specify HTTPS certificate attributes. diff --git a/lib/go-tc/server_capabilities.go b/lib/go-tc/server_capabilities.go index 45ab68b2c2..7050902435 100644 --- a/lib/go-tc/server_capabilities.go +++ b/lib/go-tc/server_capabilities.go @@ -28,6 +28,7 @@ type ServerCapabilitiesResponse struct { // ServerCapability contains information about a given ServerCapability in Traffic Ops. type ServerCapability struct { Name string `json:"name" db:"name"` + Description string `json:"description" db:"description"` LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"` } diff --git a/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.down.sql b/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.down.sql new file mode 100644 index 0000000000..1974712758 --- /dev/null +++ b/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.down.sql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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. + */ + +ALTER TABLE public.server_capability DROP column description; diff --git a/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.up.sql b/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.up.sql new file mode 100644 index 0000000000..ef929918be --- /dev/null +++ b/traffic_ops/app/db/migrations/2022112116304800_add_description_in_sc_table.up.sql @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you 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. + */ + +ALTER TABLE public.server_capability ADD COLUMN IF NOT EXISTS description text DEFAULT NULL; diff --git a/traffic_ops/testing/api/v3/server_capabilities_test.go b/traffic_ops/testing/api/v3/server_capabilities_test.go index 961c665925..0be3a6d3da 100644 --- a/traffic_ops/testing/api/v3/server_capabilities_test.go +++ b/traffic_ops/testing/api/v3/server_capabilities_test.go @@ -46,7 +46,7 @@ func TestServerCapabilities(t *testing.T) { "POST": { "BAD REQUEST when INVALID NAME": { ClientSession: TOSession, - RequestBody: tc.ServerCapability{Name: "b@dname"}, + RequestBody: tc.ServerCapability{Name: "b@dname", Description: "Server Capability"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, }, diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json index f392b2d5f1..66eaa1ef91 100644 --- a/traffic_ops/testing/api/v3/tc-fixtures.json +++ b/traffic_ops/testing/api/v3/tc-fixtures.json @@ -4822,22 +4822,28 @@ ], "serverCapabilities": [ { - "name": "foo" + "name": "foo", + "description": "server capability foo" }, { - "name": "bar" + "name": "bar", + "description": "server capability bar" }, { - "name": "ram" + "name": "ram", + "description": "server capability ram" }, { - "name": "disk" + "name": "disk", + "description": "server capability disk" }, { - "name": "asdf" + "name": "asdf", + "description": "server capability asdf" }, { - "name": "blah" + "name": "blah", + "description": "server capability blah" } ], "serverServerCapabilities": [ diff --git a/traffic_ops/testing/api/v4/server_capabilities_test.go b/traffic_ops/testing/api/v4/server_capabilities_test.go index c34e926387..118954e4fb 100644 --- a/traffic_ops/testing/api/v4/server_capabilities_test.go +++ b/traffic_ops/testing/api/v4/server_capabilities_test.go @@ -57,12 +57,12 @@ func TestServerCapabilities(t *testing.T) { "POST": { "BAD REQUEST when ALREADY EXISTS": { ClientSession: TOSession, - RequestBody: tc.ServerCapability{Name: "foo"}, + RequestBody: tc.ServerCapability{Name: "foo", Description: "foo servers"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, "BAD REQUEST when INVALID NAME": { ClientSession: TOSession, - RequestBody: tc.ServerCapability{Name: "b@dname"}, + RequestBody: tc.ServerCapability{Name: "b@dname", Description: "Server Capability"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, }, @@ -70,7 +70,7 @@ func TestServerCapabilities(t *testing.T) { "OK when VALID request": { ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"name": {"blah"}}}, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), validateServerCapabilitiesUpdateFields(map[string]interface{}{"Name": "newname"}), validateSSCFieldsOnServerCapabilityUpdate("newname", map[string]interface{}{"ServerCapability": "newname"})), @@ -78,7 +78,7 @@ func TestServerCapabilities(t *testing.T) { "BAD REQUEST when NAME DOESNT EXIST": { ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"name": {"invalid"}}}, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, "PRECONDITION FAILED when updating with IMS & IUS Headers": { @@ -87,7 +87,7 @@ func TestServerCapabilities(t *testing.T) { QueryParameters: url.Values{"name": {"disk"}}, Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}, }, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)), }, "PRECONDITION FAILED when updating with IFMATCH ETAG Header": { @@ -96,7 +96,7 @@ func TestServerCapabilities(t *testing.T) { QueryParameters: url.Values{"name": {"disk"}}, Header: http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}}, }, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)), }, }, diff --git a/traffic_ops/testing/api/v4/tc-fixtures.json b/traffic_ops/testing/api/v4/tc-fixtures.json index f0d73e79c5..f6ba73db48 100644 --- a/traffic_ops/testing/api/v4/tc-fixtures.json +++ b/traffic_ops/testing/api/v4/tc-fixtures.json @@ -5519,22 +5519,28 @@ ], "serverCapabilities": [ { - "name": "foo" + "name": "foo", + "description": "server capability foo" }, { - "name": "bar" + "name": "bar", + "description": "server capability bar" }, { - "name": "ram" + "name": "ram", + "description": "server capability ram" }, { - "name": "disk" + "name": "disk", + "description": "server capability disk" }, { - "name": "asdf" + "name": "asdf", + "description": "server capability asdf" }, { - "name": "blah" + "name": "blah", + "description": "server capability blah" } ], "serverServerCapabilities": [ diff --git a/traffic_ops/testing/api/v5/server_capabilities_test.go b/traffic_ops/testing/api/v5/server_capabilities_test.go index a1b9f899f3..db5f7b7e33 100644 --- a/traffic_ops/testing/api/v5/server_capabilities_test.go +++ b/traffic_ops/testing/api/v5/server_capabilities_test.go @@ -57,12 +57,12 @@ func TestServerCapabilities(t *testing.T) { "POST": { "BAD REQUEST when ALREADY EXISTS": { ClientSession: TOSession, - RequestBody: tc.ServerCapability{Name: "foo"}, + RequestBody: tc.ServerCapability{Name: "foo", Description: "foo servers"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, "BAD REQUEST when INVALID NAME": { ClientSession: TOSession, - RequestBody: tc.ServerCapability{Name: "b@dname"}, + RequestBody: tc.ServerCapability{Name: "b@dname", Description: "Server Capability"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, }, @@ -70,7 +70,7 @@ func TestServerCapabilities(t *testing.T) { "OK when VALID request": { ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"name": {"blah"}}}, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.NoError(), utils.HasStatus(http.StatusOK), validateServerCapabilitiesUpdateFields(map[string]interface{}{"Name": "newname"}), validateSSCFieldsOnServerCapabilityUpdate("newname", map[string]interface{}{"ServerCapability": "newname"})), @@ -78,7 +78,7 @@ func TestServerCapabilities(t *testing.T) { "BAD REQUEST when NAME DOESNT EXIST": { ClientSession: TOSession, RequestOpts: client.RequestOptions{QueryParameters: url.Values{"name": {"invalid"}}}, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), }, "PRECONDITION FAILED when updating with IMS & IUS Headers": { @@ -87,7 +87,7 @@ func TestServerCapabilities(t *testing.T) { QueryParameters: url.Values{"name": {"disk"}}, Header: http.Header{rfc.IfUnmodifiedSince: {currentTimeRFC}}, }, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)), }, "PRECONDITION FAILED when updating with IFMATCH ETAG Header": { @@ -96,7 +96,7 @@ func TestServerCapabilities(t *testing.T) { QueryParameters: url.Values{"name": {"disk"}}, Header: http.Header{rfc.IfMatch: {rfc.ETag(currentTime)}}, }, - RequestBody: tc.ServerCapability{Name: "newname"}, + RequestBody: tc.ServerCapability{Name: "newname", Description: "Server Capability for new name"}, Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusPreconditionFailed)), }, }, diff --git a/traffic_ops/testing/api/v5/tc-fixtures.json b/traffic_ops/testing/api/v5/tc-fixtures.json index 18dc10c256..8df76f8d48 100644 --- a/traffic_ops/testing/api/v5/tc-fixtures.json +++ b/traffic_ops/testing/api/v5/tc-fixtures.json @@ -5431,22 +5431,28 @@ ], "serverCapabilities": [ { - "name": "foo" + "name": "foo", + "description": "server capability foo" }, { - "name": "bar" + "name": "bar", + "description": "server capability bar" }, { - "name": "ram" + "name": "ram", + "description": "server capability ram" }, { - "name": "disk" + "name": "disk", + "description": "server capability disk" }, { - "name": "asdf" + "name": "asdf", + "description": "server capability asdf" }, { - "name": "blah" + "name": "blah", + "description": "server capability blah" } ], "serverServerCapabilities": [ diff --git a/traffic_ops/traffic_ops_golang/servercapability/servercapability.go b/traffic_ops/traffic_ops_golang/servercapability/servercapability.go index cd4f122d5e..c7ebb06ef8 100644 --- a/traffic_ops/traffic_ops_golang/servercapability/servercapability.go +++ b/traffic_ops/traffic_ops_golang/servercapability/servercapability.go @@ -45,10 +45,12 @@ func (v *TOServerCapability) NewReadObj() interface{} { return &tc.ServerC func (v *TOServerCapability) InsertQuery() string { return ` INSERT INTO server_capability ( - name + name, + description ) VALUES ( - :name + :name, + :description ) RETURNING last_updated ` @@ -58,6 +60,7 @@ func (v *TOServerCapability) SelectQuery() string { return ` SELECT name, + description, last_updated FROM server_capability sc @@ -67,9 +70,10 @@ FROM func (v *TOServerCapability) updateQuery() string { return ` UPDATE server_capability sc SET - name = $1 -WHERE sc.name = $2 -RETURNING sc.name, sc.last_updated + name = $1, + description = $2 +WHERE sc.name = $3 +RETURNING sc.name, sc.description, sc.last_updated ` } @@ -110,7 +114,8 @@ func (v *TOServerCapability) GetType() string { func (v *TOServerCapability) Validate() (error, error) { rule := validation.NewStringRule(tovalidate.IsAlphanumericUnderscoreDash, "must consist of only alphanumeric, dash, or underscore characters") errs := validation.Errors{ - "name": validation.Validate(v.Name, validation.Required, rule), + "name": validation.Validate(v.Name, validation.Required, rule), + "description": validation.Validate(v.Description, validation.Required), } return util.JoinErrs(tovalidate.ToErrors(errs)), nil } @@ -136,14 +141,14 @@ func (v *TOServerCapability) Update(h http.Header) (error, error, int) { } // udpate server capability name - rows, err := v.ReqInfo.Tx.Query(v.updateQuery(), v.RequestedName, v.Name) + rows, err := v.ReqInfo.Tx.Query(v.updateQuery(), v.RequestedName, v.Description, v.Name) if err != nil { return nil, fmt.Errorf("server capability update: error setting the name for server capability %v: %v", v.Name, err.Error()), http.StatusInternalServerError } defer log.Close(rows, "unable to close DB connection") for rows.Next() { - err = rows.Scan(&v.Name, &v.LastUpdated) + err = rows.Scan(&v.Name, &v.Description, &v.LastUpdated) if err != nil { return api.ParseDBError(err) } diff --git a/traffic_portal/app/src/common/modules/form/serverCapability/form.serverCapability.tpl.html b/traffic_portal/app/src/common/modules/form/serverCapability/form.serverCapability.tpl.html index f2875fda32..4469f249ce 100644 --- a/traffic_portal/app/src/common/modules/form/serverCapability/form.serverCapability.tpl.html +++ b/traffic_portal/app/src/common/modules/form/serverCapability/form.serverCapability.tpl.html @@ -41,6 +41,14 @@ +
+ +
+ + Required + +
+
-
- +
+
- - +