You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2020/11/24 22:57:33 UTC

[trafficcontrol] branch master updated: Add ability to filter DS's by the active flag (#5313)

This is an automated email from the ASF dual-hosted git repository.

rawlin 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 347c0c9  Add ability to filter DS's by the active flag (#5313)
347c0c9 is described below

commit 347c0c93b8b37d9b9cad7bc4e6400e27a92f80b2
Author: Srijeet Chatterjee <30...@users.noreply.github.com>
AuthorDate: Tue Nov 24 15:57:18 2020 -0700

    Add ability to filter DS's by the active flag (#5313)
    
    * Add ability to filter DS's by the active flag
    
    * code review fixes
---
 CHANGELOG.md                                       |  1 +
 docs/source/api/v3/deliveryservices.rst            |  2 +
 .../testing/api/v3/deliveryservices_test.go        | 25 ++++++++
 traffic_ops/testing/api/v3/tc-fixtures.json        | 67 ++++++++++++++++++++++
 .../deliveryservice/deliveryservices.go            |  1 +
 5 files changed, 96 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 514fc97..30ccb47 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
+- Traffic Ops: added a feature to get delivery services filtered by the `active` flag
 - Traffic Ops: added validation for assigning ORG servers to topology-based delivery services
 - Traffic Ops: added validation for topology updates and server updates/deletions to ensure that topologies have at least one server per cachegroup in each CDN of any assigned delivery services
 - Traffic Ops: added validation for delivery service updates to ensure that topologies have at least one server per cachegroup in each CDN of any assigned delivery services
diff --git a/docs/source/api/v3/deliveryservices.rst b/docs/source/api/v3/deliveryservices.rst
index 5e68fbd..0ae07b5 100644
--- a/docs/source/api/v3/deliveryservices.rst
+++ b/docs/source/api/v3/deliveryservices.rst
@@ -66,6 +66,8 @@ Request Structure
 	| page              | no       | Return the n\ :sup:`th` page of results, where "n" is the value of this parameter, pages are ``limit`` long and the first page is 1.    |
 	|                   |          | If ``offset`` was defined, this query parameter has no effect. ``limit`` must be defined to make use of ``page``.                       |
 	+-------------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+
+    | active            | no       | Show only the :term:`Delivery Services` that have :ref:`ds-active` set or not based on this boolean (whether or not they are active)    |
+	+-------------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------+
 
 Response Structure
 ------------------
diff --git a/traffic_ops/testing/api/v3/deliveryservices_test.go b/traffic_ops/testing/api/v3/deliveryservices_test.go
index 2b9099f..5842990 100644
--- a/traffic_ops/testing/api/v3/deliveryservices_test.go
+++ b/traffic_ops/testing/api/v3/deliveryservices_test.go
@@ -56,6 +56,7 @@ func TestDeliveryServices(t *testing.T) {
 		GetTestDeliveryServicesIMSAfterChange(t, header)
 		UpdateDeliveryServiceTopologyHeaderRewriteFields(t)
 		GetTestDeliveryServices(t)
+		GetInactiveTestDeliveryServices(t)
 		GetTestDeliveryServicesCapacity(t)
 		DeliveryServiceMinorVersionsTest(t)
 		DeliveryServiceTenancyTest(t)
@@ -396,6 +397,30 @@ func GetTestDeliveryServices(t *testing.T) {
 	}
 }
 
+func GetInactiveTestDeliveryServices(t *testing.T) {
+	params := url.Values{}
+	params.Set("active", strconv.FormatBool(false))
+	inactiveDSes, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
+	if err != nil {
+		t.Errorf("cannot GET DeliveryServices: %v - %v", err, inactiveDSes)
+	}
+	for _, ds := range inactiveDSes {
+		if *ds.Active != false {
+			t.Errorf("expected all delivery services to be inactive, but got atleast one active DS")
+		}
+	}
+	params.Set("active", strconv.FormatBool(true))
+	activeDSes, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, params)
+	if err != nil {
+		t.Errorf("cannot GET DeliveryServices: %v - %v", err, activeDSes)
+	}
+	for _, ds := range activeDSes {
+		if *ds.Active != true {
+			t.Errorf("expected all delivery services to be active, but got atleast one inactive DS")
+		}
+	}
+}
+
 func GetTestDeliveryServicesCapacity(t *testing.T) {
 	actualDSes, _, err := TOSession.GetDeliveryServicesV30WithHdr(nil, nil)
 	if err != nil {
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json b/traffic_ops/testing/api/v3/tc-fixtures.json
index 796c630..11bc1a7 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -1265,6 +1265,73 @@
             "type": "HTTP",
             "xmlId": "top-ds-in-cdn2",
             "anonymousBlockingEnabled": false
+        },
+        {
+            "active": false,
+            "cdnName": "cdn1",
+            "cacheurl": "cacheUrl1",
+            "ccrDnsTtl": 3600,
+            "checkPath": "",
+            "consistentHashQueryParams": [],
+            "deepCachingType": "NEVER",
+            "displayName": "inactiveDSDisplayName",
+            "dnsBypassCname": null,
+            "dnsBypassIp": "",
+            "dnsBypassIp6": "",
+            "dnsBypassTtl": 30,
+            "dscp": 40,
+            "edgeHeaderRewrite": "edgeHeader1\nedgeHeader2",
+            "exampleURLs": [
+                "http://ccr.inactiveds.example.net",
+                "https://ccr.inactiveds.example.net"
+            ],
+            "fqPacingRate": 0,
+            "geoLimit": 0,
+            "geoLimitCountries": "",
+            "geoLimitRedirectURL": null,
+            "geoProvider": 0,
+            "globalMaxMbps": 0,
+            "globalMaxTps": 0,
+            "httpBypassFqdn": "",
+            "infoUrl": "TBD",
+            "initialDispersion": 1,
+            "ipv6RoutingEnabled": true,
+            "lastUpdated": "2018-04-06 15:48:51+00",
+            "logsEnabled": false,
+            "longDesc": "d s inactive",
+            "longDesc1": "dsinactive",
+            "longDesc2": "dsinactive",
+            "matchList": [
+                {
+                    "pattern": ".*\\.dsinactive\\..*",
+                    "setNumber": 0,
+                    "type": "HOST_REGEXP"
+                }
+            ],
+            "maxDnsAnswers": 0,
+            "midHeaderRewrite": "midHeader1\nmidHeader2",
+            "missLat": 41.881944,
+            "missLong": -87.627778,
+            "multiSiteOrigin": false,
+            "orgServerFqdn": "http://origin.example.net",
+            "originShield": null,
+            "profileDescription": null,
+            "profileName": null,
+            "protocol": 2,
+            "qstringIgnore": 1,
+            "rangeRequestHandling": 0,
+            "regexRemap": "rr1\nrr2",
+            "regionalGeoBlocking": false,
+            "remapText": "@plugin=tslua.so @pparam=/opt/trafficserver/etc/trafficserver/remapPlugin1.lua",
+            "routingName": "ccr-inactiveds",
+            "signed": false,
+            "signingAlgorithm": "url_sig",
+            "sslKeyVersion": 2,
+            "tenant": "tenant1",
+            "tenantName": "tenant1",
+            "type": "HTTP",
+            "xmlId": "inactiveds",
+            "anonymousBlockingEnabled": true
         }
     ],
     "deliveryServicesRegexes": [
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
index d8adb48..199058a 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
@@ -1029,6 +1029,7 @@ func readGetDeliveryServices(h http.Header, params map[string]string, tx *sqlx.T
 		"signingAlgorithm": {"ds.signing_algorithm", nil},
 		"topology":         {"ds.topology", nil},
 		"serviceCategory":  {"ds.service_category", nil},
+		"active":           {"ds.active", api.IsBool},
 	}
 
 	where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(params, queryParamsToSQLCols)