You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/11/01 20:43:25 UTC

[2/2] incubator-trafficcontrol git commit: add `DeliveryServiceServer` method

add `DeliveryServiceServer` method

Add a `DeliveryServiceServer` method to the `traffic_ops` client.


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a61ef2e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a61ef2e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a61ef2e8

Branch: refs/heads/master
Commit: a61ef2e8a18b4d4332ec83fe93e833b098d88561
Parents: 7182647
Author: Mike Ball <mi...@gmail.com>
Authored: Thu Oct 27 10:46:48 2016 -0400
Committer: Dave Neuman <ne...@apache.org>
Committed: Tue Nov 1 14:35:52 2016 -0600

----------------------------------------------------------------------
 traffic_ops/client/delivery_service.go          | 26 ++++++++++++++++++++
 .../client/delivery_service_endpoints.go        | 11 ++++++---
 .../client/delivery_service_endpoints_test.go   | 12 +++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service.go b/traffic_ops/client/delivery_service.go
index beea2ff..da28590 100644
--- a/traffic_ops/client/delivery_service.go
+++ b/traffic_ops/client/delivery_service.go
@@ -145,6 +145,21 @@ type DeliveryServiceRouting struct {
 	RegionalDenied    int     `json:"regionalDenied"`
 }
 
+// DeliveryServiceServerResponse ...
+type DeliveryServiceServerResponse struct {
+	Response []DeliveryServiceServer `json:"response"`
+	Page     int                     `json:"page"`
+	OrderBy  string                  `json:"orderby"`
+	Limit    int                     `json:"limit"`
+}
+
+// DeliveryServiceServer ...
+type DeliveryServiceServer struct {
+	LastUpdated     string `json:"lastUpdated"`
+	Server          string `json:"server"`
+	DeliveryService string `json:"deliveryService"`
+}
+
 // DeliveryServices gets an array of DeliveryServices
 func (to *Session) DeliveryServices() ([]DeliveryService, error) {
 	var data DeliveryServiceResponse
@@ -211,6 +226,17 @@ func (to *Session) DeliveryServiceRouting(id string) (*DeliveryServiceRouting, e
 	return &data.Response, nil
 }
 
+// DeliveryServiceServer gets the DeliveryServiceServer
+func (to *Session) DeliveryServiceServer(page, limit string) (*[]DeliveryServiceServer, error) {
+	var data DeliveryServiceServerResponse
+	err := get(to, deliveryServiceServerEp(page, limit), &data)
+	if err != nil {
+		return nil, err
+	}
+
+	return &data.Response, nil
+}
+
 func get(to *Session, endpoint string, respStruct interface{}) error {
 	resp, err := to.request(endpoint, nil)
 	if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service_endpoints.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints.go b/traffic_ops/client/delivery_service_endpoints.go
index 39779a4..862a727 100644
--- a/traffic_ops/client/delivery_service_endpoints.go
+++ b/traffic_ops/client/delivery_service_endpoints.go
@@ -15,14 +15,15 @@
 
 package client
 
-const dsPath = "/api/1.2/deliveryservices"
+const apiBase = "/api/1.2"
+const dsPath = "/deliveryservices"
 
 func deliveryServicesEp() string {
-	return dsPath + ".json"
+	return apiBase + dsPath + ".json"
 }
 
 func deliveryServiceBaseEp(id string) string {
-	return dsPath + "/" + id
+	return apiBase + dsPath + "/" + id
 }
 
 func deliveryServiceEp(id string) string {
@@ -44,3 +45,7 @@ func deliveryServiceCapacityEp(id string) string {
 func deliveryServiceRoutingEp(id string) string {
 	return deliveryServiceBaseEp(id) + "/routing.json"
 }
+
+func deliveryServiceServerEp(page, limit string) string {
+	return apiBase + "/deliveryserviceserver.json?page=" + page + "&limit=" + limit
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a61ef2e8/traffic_ops/client/delivery_service_endpoints_test.go
----------------------------------------------------------------------
diff --git a/traffic_ops/client/delivery_service_endpoints_test.go b/traffic_ops/client/delivery_service_endpoints_test.go
index 4ce98e8..93163af 100644
--- a/traffic_ops/client/delivery_service_endpoints_test.go
+++ b/traffic_ops/client/delivery_service_endpoints_test.go
@@ -92,3 +92,15 @@ func TestDeliveryServiceRoutingEp(t *testing.T) {
 		testHelper.Success(t, "Should be able to get the correct delivery service routing endpoint")
 	}
 }
+
+func TestDeliveryServiceServerEp(t *testing.T) {
+	testHelper.Context(t, "Given the need to test that DeliveryServiceServer uses the correct URL")
+
+	ep := deliveryServiceServerEp("1", "2")
+	expected := "/api/1.2/deliveryserviceserver.json?page=1&limit=2"
+	if ep != expected {
+		testHelper.Error(t, "Should get back %s for \"deliveryServiceServerEp\", got: %s", expected, ep)
+	} else {
+		testHelper.Success(t, "Should be able to get the correct delivery service server endpoint")
+	}
+}