You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2018/03/27 15:31:15 UTC
[incubator-trafficcontrol] 05/05: updates TO client and api tests
for dsr comments
This is an automated email from the ASF dual-hosted git repository.
dewrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 59fea8a5f418c631bc35e5e7ed7ea407bba600fc
Author: Jeremy Mitchell <mi...@gmail.com>
AuthorDate: Mon Mar 26 14:48:38 2018 -0600
updates TO client and api tests for dsr comments
---
CHANGELOG.md | 1 +
lib/go-tc/deliveryservice_request_comments.go | 14 +--
.../client/v13/deliveryservice_request_comments.go | 118 +++++++++++++++++++++
.../v13/deliveryservice_request_comments_test.go | 115 ++++++++++++++++++++
traffic_ops/testing/api/v13/tc-fixtures.json | 14 +++
traffic_ops/testing/api/v13/traffic_control.go | 27 ++---
.../select/status/dialog.select.status.tpl.html | 2 +-
7 files changed, 270 insertions(+), 21 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a694fd..a3cc28b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- Per-DeliveryService Routing Names: you can now choose a Delivery Service's Routing Name (rather than a hardcoded "tr" or "edge" name). This might require a few pre-upgrade steps detailed [here](http://traffic-control-cdn.readthedocs.io/en/latest/admin/traffic_ops/migration_from_20_to_22.html#per-deliveryservice-routing-names)
+- [Delivery Service Requests](http://traffic-control-cdn.readthedocs.io/en/latest/admin/quick_howto/ds_requests.html#ds-requests): When enabled, delivery service requests are created when ALL users attempt to create, update or delete a delivery service. This allows users with higher level permissions to review delivery service changes for completeness and accuracy before deploying the changes.
- Traffic Ops Golang Proxy Endpoints (R=REST endpoints for GET, POST, PUT, DELETE)
- /api/1.3/about
- /api/1.3/asns (R)
diff --git a/lib/go-tc/deliveryservice_request_comments.go b/lib/go-tc/deliveryservice_request_comments.go
index 45d15ae..55d3761 100644
--- a/lib/go-tc/deliveryservice_request_comments.go
+++ b/lib/go-tc/deliveryservice_request_comments.go
@@ -24,13 +24,13 @@ type DeliveryServiceRequestCommentsResponse struct {
}
type DeliveryServiceRequestComment struct {
- AuthorID *IDNoMod `json:"authorId" db:"author_id"`
- Author string `json:"author"`
- DeliveryServiceRequestID *int `json:"deliveryServiceRequestId" db:"deliveryservice_request_id"`
- ID *int `json:"id" db:"id"`
- LastUpdated *TimeNoMod `json:"lastUpdated" db:"last_updated"`
- Value *string `json:"value" db:"value"`
- XMLID string `json:"xmlId" db:"xml_id"`
+ AuthorID IDNoMod `json:"authorId" db:"author_id"`
+ Author string `json:"author"`
+ DeliveryServiceRequestID int `json:"deliveryServiceRequestId" db:"deliveryservice_request_id"`
+ ID int `json:"id" db:"id"`
+ LastUpdated TimeNoMod `json:"lastUpdated" db:"last_updated"`
+ Value string `json:"value" db:"value"`
+ XMLID string `json:"xmlId" db:"xml_id"`
}
type DeliveryServiceRequestCommentNullable struct {
diff --git a/traffic_ops/client/v13/deliveryservice_request_comments.go b/traffic_ops/client/v13/deliveryservice_request_comments.go
new file mode 100644
index 0000000..c168dc4
--- /dev/null
+++ b/traffic_ops/client/v13/deliveryservice_request_comments.go
@@ -0,0 +1,118 @@
+/*
+
+ 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.
+*/
+
+package v13
+
+import (
+ "encoding/json"
+ "net"
+ "net/http"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+ "github.com/apache/incubator-trafficcontrol/lib/go-log"
+
+ "fmt"
+)
+
+const (
+ API_v13_DeliveryServiceRequestComments = "/api/1.3/deliveryservice_request_comments"
+)
+
+// Create a delivery service request comment
+func (to *Session) CreateDeliveryServiceRequestComment(comment tc.DeliveryServiceRequestComment) (tc.Alerts, ReqInf, error) {
+
+ var remoteAddr net.Addr
+ reqBody, err := json.Marshal(comment)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ resp, remoteAddr, err := to.request(http.MethodPost, API_v13_DeliveryServiceRequestComments, reqBody)
+ log.Infof("%s", reqBody)
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ defer resp.Body.Close()
+ var alerts tc.Alerts
+ err = json.NewDecoder(resp.Body).Decode(&alerts)
+ return alerts, reqInf, nil
+}
+
+// Update a delivery service request by ID
+func (to *Session) UpdateDeliveryServiceRequestCommentByID(id int, comment tc.DeliveryServiceRequestComment) (tc.Alerts, ReqInf, error) {
+
+ var remoteAddr net.Addr
+ reqBody, err := json.Marshal(comment)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ route := fmt.Sprintf("%s/%d", API_v13_DeliveryServiceRequestComments, id)
+ resp, remoteAddr, err := to.request(http.MethodPut, route, reqBody)
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ defer resp.Body.Close()
+ var alerts tc.Alerts
+ err = json.NewDecoder(resp.Body).Decode(&alerts)
+ return alerts, reqInf, nil
+}
+
+// Returns a list of delivery service request comments
+func (to *Session) GetDeliveryServiceRequestComments() ([]tc.DeliveryServiceRequestComment, ReqInf, error) {
+ resp, remoteAddr, err := to.request(http.MethodGet, API_v13_DeliveryServiceRequestComments, nil)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+ if err != nil {
+ return nil, reqInf, err
+ }
+ defer resp.Body.Close()
+
+ var data tc.DeliveryServiceRequestCommentsResponse
+ err = json.NewDecoder(resp.Body).Decode(&data)
+ return data.Response, reqInf, nil
+}
+
+// GET a delivery service request comment by ID
+func (to *Session) GetDeliveryServiceRequestCommentByID(id int) ([]tc.DeliveryServiceRequestComment, ReqInf, error) {
+ route := fmt.Sprintf("%s/%d", API_v13_DeliveryServiceRequestComments, id)
+ resp, remoteAddr, err := to.request(http.MethodGet, route, nil)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+ if err != nil {
+ return nil, reqInf, err
+ }
+ defer resp.Body.Close()
+
+ var data tc.DeliveryServiceRequestCommentsResponse
+ if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+ return nil, reqInf, err
+ }
+
+ return data.Response, reqInf, nil
+}
+
+// DELETE a delivery service request comment by ID
+func (to *Session) DeleteDeliveryServiceRequestCommentByID(id int) (tc.Alerts, ReqInf, error) {
+ route := fmt.Sprintf("%s/%d", API_v13_DeliveryServiceRequestComments, id)
+ resp, remoteAddr, err := to.request(http.MethodDelete, route, nil)
+ reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: remoteAddr}
+ if err != nil {
+ return tc.Alerts{}, reqInf, err
+ }
+ defer resp.Body.Close()
+ var alerts tc.Alerts
+ err = json.NewDecoder(resp.Body).Decode(&alerts)
+ return alerts, reqInf, nil
+}
+
diff --git a/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go b/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go
new file mode 100644
index 0000000..b5eda00
--- /dev/null
+++ b/traffic_ops/testing/api/v13/deliveryservice_request_comments_test.go
@@ -0,0 +1,115 @@
+package v13
+
+/*
+
+ 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.
+*/
+
+import (
+ "testing"
+
+ "github.com/apache/incubator-trafficcontrol/lib/go-log"
+ "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+)
+
+func TestDeliveryServiceRequestComments(t *testing.T) {
+
+ CreateTestDeliveryServiceRequests(t)
+ CreateTestDeliveryServiceRequestComments(t)
+ UpdateTestDeliveryServiceRequestComments(t)
+ GetTestDeliveryServiceRequestComments(t)
+ DeleteTestDeliveryServiceRequestComments(t)
+ DeleteTestDeliveryServiceRequests(t)
+
+}
+
+func CreateTestDeliveryServiceRequestComments(t *testing.T) {
+
+ // Retrieve a delivery service request by xmlId so we can get the ID needed to create a dsr comment
+ dsr := testData.DeliveryServiceRequests[0].DeliveryService
+
+ resp, _, err := TOSession.GetDeliveryServiceRequestByXMLID(dsr.XMLID)
+ if err != nil {
+ t.Errorf("cannot GET delivery service request by xml id: %v - %v\n", dsr.XMLID, err)
+ }
+ respDSR := resp[0]
+
+ for _, comment := range testData.DeliveryServiceRequestComments {
+ comment.DeliveryServiceRequestID = respDSR.ID
+ resp, _, err := TOSession.CreateDeliveryServiceRequestComment(comment)
+ log.Debugln("Response: ", resp)
+ if err != nil {
+ t.Errorf("could not CREATE delivery service request comment: %v\n", err)
+ }
+ }
+
+}
+
+func UpdateTestDeliveryServiceRequestComments(t *testing.T) {
+
+ comments, _, err := TOSession.GetDeliveryServiceRequestComments()
+
+ firstComment := comments[0]
+ newFirstCommentValue := "new comment value"
+ firstComment.Value = newFirstCommentValue
+
+ var alert tc.Alerts
+ alert, _, err = TOSession.UpdateDeliveryServiceRequestCommentByID(firstComment.ID, firstComment)
+ if err != nil {
+ t.Errorf("cannot UPDATE delivery service request comment by id: %v - %v\n", err, alert)
+ }
+
+ // Retrieve the delivery service request comment to check that the value got updated
+ resp, _, err := TOSession.GetDeliveryServiceRequestCommentByID(firstComment.ID)
+ if err != nil {
+ t.Errorf("cannot GET delivery service request comment by id: '$%s' %v - %v\n", firstComment.ID, err)
+ }
+ respDSRC := resp[0]
+ if respDSRC.Value != newFirstCommentValue {
+ t.Errorf("results do not match actual: %s, expected: %s\n", respDSRC.Value, newFirstCommentValue)
+ }
+
+}
+
+func GetTestDeliveryServiceRequestComments(t *testing.T) {
+
+ comments, _, _ := TOSession.GetDeliveryServiceRequestComments()
+
+ for _, comment := range comments {
+ resp, _, err := TOSession.GetDeliveryServiceRequestCommentByID(comment.ID)
+ if err != nil {
+ t.Errorf("cannot GET delivery service request comment by id: %v - %v\n", err, resp)
+ }
+ }
+}
+
+func DeleteTestDeliveryServiceRequestComments(t *testing.T) {
+
+ comments, _, _ := TOSession.GetDeliveryServiceRequestComments()
+
+ for _, comment := range comments {
+ _, _, err := TOSession.DeleteDeliveryServiceRequestCommentByID(comment.ID)
+ if err != nil {
+ t.Errorf("cannot DELETE delivery service request comment by id: '%s' %v\n", comment.ID, err)
+ }
+
+ // Retrieve the delivery service request comment to see if it got deleted
+ comments, _, err := TOSession.GetDeliveryServiceRequestCommentByID(comment.ID)
+ if err != nil {
+ t.Errorf("error deleting delivery service request comment: %s\n", err.Error())
+ }
+ if len(comments) > 0 {
+ t.Errorf("expected delivery service request comment: %s to be deleted\n", comment.ID)
+ }
+ }
+}
diff --git a/traffic_ops/testing/api/v13/tc-fixtures.json b/traffic_ops/testing/api/v13/tc-fixtures.json
index 783b0fc..b5be3ec 100644
--- a/traffic_ops/testing/api/v13/tc-fixtures.json
+++ b/traffic_ops/testing/api/v13/tc-fixtures.json
@@ -148,6 +148,20 @@
"status": "draft"
}
],
+ "deliveryServiceRequestComments": [
+ {
+ "value": "this is comment one"
+ },
+ {
+ "value": "this is comment two"
+ },
+ {
+ "value": "this is comment three"
+ },
+ {
+ "value": "this is comment four"
+ }
+ ],
"deliveryServices": [
{
"active": false,
diff --git a/traffic_ops/testing/api/v13/traffic_control.go b/traffic_ops/testing/api/v13/traffic_control.go
index a350cb1..d13f998 100644
--- a/traffic_ops/testing/api/v13/traffic_control.go
+++ b/traffic_ops/testing/api/v13/traffic_control.go
@@ -22,17 +22,18 @@ import (
// TrafficControl - maps to the tc-fixtures.json file
type TrafficControl struct {
- ASNs []tcapi.ASN `json:"asns"`
- CDNs []v13.CDN `json:"cdns"`
- CacheGroups []tcapi.CacheGroup `json:"cachegroups"`
- DeliveryServiceRequests []tcapi.DeliveryServiceRequest `json:"deliveryServiceRequests"`
- DeliveryServices []tcapi.DeliveryService `json:"deliveryservices"`
- Divisions []tcapi.Division `json:"divisions"`
- Profiles []tcapi.Profile `json:"profiles"`
- Parameters []tcapi.Parameter `json:"parameters"`
- PhysLocations []tcapi.PhysLocation `json:"physLocations"`
- Regions []tcapi.Region `json:"regions"`
- Statuses []tcapi.Status `json:"statuses"`
- Tenants []tcapi.Tenant `json:"tenants"`
- Types []tcapi.Type `json:"types"`
+ ASNs []tcapi.ASN `json:"asns"`
+ CDNs []v13.CDN `json:"cdns"`
+ CacheGroups []tcapi.CacheGroup `json:"cachegroups"`
+ DeliveryServiceRequests []tcapi.DeliveryServiceRequest `json:"deliveryServiceRequests"`
+ DeliveryServiceRequestComments []tcapi.DeliveryServiceRequestComment `json:"deliveryServiceRequestComments"`
+ DeliveryServices []tcapi.DeliveryService `json:"deliveryservices"`
+ Divisions []tcapi.Division `json:"divisions"`
+ Profiles []tcapi.Profile `json:"profiles"`
+ Parameters []tcapi.Parameter `json:"parameters"`
+ PhysLocations []tcapi.PhysLocation `json:"physLocations"`
+ Regions []tcapi.Region `json:"regions"`
+ Statuses []tcapi.Status `json:"statuses"`
+ Tenants []tcapi.Tenant `json:"tenants"`
+ Types []tcapi.Type `json:"types"`
}
diff --git a/traffic_portal/app/src/common/modules/dialog/select/status/dialog.select.status.tpl.html b/traffic_portal/app/src/common/modules/dialog/select/status/dialog.select.status.tpl.html
index 6ef4afd..335a190 100644
--- a/traffic_portal/app/src/common/modules/dialog/select/status/dialog.select.status.tpl.html
+++ b/traffic_portal/app/src/common/modules/dialog/select/status/dialog.select.status.tpl.html
@@ -27,7 +27,7 @@ under the License.
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="form-group" ng-class="{'has-error': hasError(statusForm.status), 'has-feedback': hasError(statusForm.status)}">
- <label class="control-label" for="status"><a href="foo">Status</a> *
+ <label class="control-label" for="status">Status *
<small class="input-error" ng-show="hasPropertyError(statusForm.status, 'required')">Required</small>
</label>
<select id="status" name="status" class="form-control" ng-model="selectedStatusId" ng-options="status.id as status.name for status in statuses" required>
--
To stop receiving notification emails like this one, please contact
dewrich@apache.org.