You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by zr...@apache.org on 2021/07/16 21:00:55 UTC
[trafficcontrol] branch master updated: Add Go TO client method for
getting servers by deliveryservice (#6015)
This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 3ec6d7c Add Go TO client method for getting servers by deliveryservice (#6015)
3ec6d7c is described below
commit 3ec6d7cb2c5ca22d9158ffc1957379dfe4ee2c5d
Author: Rawlin Peters <ra...@apache.org>
AuthorDate: Fri Jul 16 15:00:44 2021 -0600
Add Go TO client method for getting servers by deliveryservice (#6015)
---
CHANGELOG.md | 1 +
lib/go-tc/deliveryservice_servers.go | 5 +++++
traffic_ops/testing/api/v4/deliveryserviceservers_test.go | 11 +++++++++++
traffic_ops/v3-client/deliveryserviceserver.go | 8 ++++++++
traffic_ops/v4-client/deliveryserviceserver.go | 9 +++++++++
5 files changed, 34 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1af1b5..c3e12c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- ORT config generation: Added a rule to ip_allow such that PURGE requests are allowed over localhost
- Added integration to use ACME to generate new SSL certificates.
- Add a Federation to the Ansible Dataset Loader
+- Added `GetServersByDeliveryService` method to the TO Go client
- Added asynchronous status to ACME certificate generation.
- Added per Delivery Service HTTP/2 and TLS Versions support, via ssl_server_name.yaml and sni.yaml. See overview/delivery_services and t3c docs.
- Added headers to Traffic Portal, Traffic Ops, and Traffic Monitor to opt out of tracking users via Google FLoC.
diff --git a/lib/go-tc/deliveryservice_servers.go b/lib/go-tc/deliveryservice_servers.go
index d732080..78deb84 100644
--- a/lib/go-tc/deliveryservice_servers.go
+++ b/lib/go-tc/deliveryservice_servers.go
@@ -159,6 +159,11 @@ type DSServer struct {
ServerInterfaces *[]ServerInterfaceInfo `json:"interfaces" db:"interfaces"`
}
+type DSServerResponseV30 struct {
+ Response []DSServer `json:"response"`
+ Alerts
+}
+
// DSServerV4 contains information for a V4.x Delivery Service Server.
type DSServerV4 struct {
DSServerBaseV4
diff --git a/traffic_ops/testing/api/v4/deliveryserviceservers_test.go b/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
index 72f0dc6..e071604 100644
--- a/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
+++ b/traffic_ops/testing/api/v4/deliveryserviceservers_test.go
@@ -605,6 +605,17 @@ func DeleteTestDeliveryServiceServers(t *testing.T) {
t.Error("POST delivery service servers returned success, but ds-server not in GET")
}
+ serversByDS, _, err := TOSession.GetServersByDeliveryService(*ds.ID, client.RequestOptions{})
+ if err != nil {
+ t.Errorf("unexpected error getting servers by delivery service: %v", err)
+ }
+ if len(serversByDS.Response) != 1 {
+ t.Errorf("getting servers by delivery service - expected: 1 server, actual: %d servers", len(serversByDS.Response))
+ }
+ if *serversByDS.Response[0].ID != *server.ID {
+ t.Errorf("getting servers by delivery service - expected: server ID %d, actual: %d", *server.ID, *serversByDS.Response[0].ID)
+ }
+
if *ds.Active {
*ds.Active = false
_, _, err = TOSession.UpdateDeliveryService(*ds.ID, ds, client.RequestOptions{})
diff --git a/traffic_ops/v3-client/deliveryserviceserver.go b/traffic_ops/v3-client/deliveryserviceserver.go
index de863d1..529d9c2 100644
--- a/traffic_ops/v3-client/deliveryserviceserver.go
+++ b/traffic_ops/v3-client/deliveryserviceserver.go
@@ -60,6 +60,14 @@ func (to *Session) AssignServersToDeliveryService(servers []string, xmlId string
return resp, reqInf, err
}
+// GetServersByDeliveryService gets the servers that are assigned to the delivery service with the given ID.
+func (to *Session) GetServersByDeliveryService(id int) (tc.DSServerResponseV30, toclientlib.ReqInf, error) {
+ route := fmt.Sprintf(APIDeliveryServicesServers, strconv.Itoa(id))
+ resp := tc.DSServerResponseV30{}
+ reqInf, err := to.get(route, nil, &resp)
+ return resp, reqInf, err
+}
+
// GetDeliveryServiceServer returns associations between Delivery Services and servers using the
// provided pagination controls.
// Deprecated: GetDeliveryServiceServer will be removed in 6.0. Use GetDeliveryServiceServerWithHdr.
diff --git a/traffic_ops/v4-client/deliveryserviceserver.go b/traffic_ops/v4-client/deliveryserviceserver.go
index 3909401..225870b 100644
--- a/traffic_ops/v4-client/deliveryserviceserver.go
+++ b/traffic_ops/v4-client/deliveryserviceserver.go
@@ -18,6 +18,7 @@ package client
import (
"fmt"
"net/url"
+ "strconv"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
@@ -57,6 +58,14 @@ func (to *Session) AssignServersToDeliveryService(servers []string, xmlID string
return resp, reqInf, err
}
+// GetServersByDeliveryService gets the servers that are assigned to the delivery service with the given ID.
+func (to *Session) GetServersByDeliveryService(id int, opts RequestOptions) (tc.DSServerResponseV4, toclientlib.ReqInf, error) {
+ route := fmt.Sprintf(apiDeliveryServicesServers, strconv.Itoa(id))
+ resp := tc.DSServerResponseV4{}
+ reqInf, err := to.get(route, opts, &resp)
+ return resp, reqInf, err
+}
+
// GetDeliveryServiceServers returns associations between Delivery Services and
// servers.
func (to *Session) GetDeliveryServiceServers(opts RequestOptions) (tc.DeliveryServiceServerResponse, toclientlib.ReqInf, error) {