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 5d06e3874b When updating server status, only queue updates on children 
in same CDN (#6765)
5d06e3874b is described below

commit 5d06e3874b004f04f1e035f41301dbdbc6ece1bb
Author: Rawlin Peters <[email protected]>
AuthorDate: Wed Apr 20 19:37:12 2022 -0600

    When updating server status, only queue updates on children in same CDN 
(#6765)
---
 CHANGELOG.md                                       |  1 +
 .../testing/api/v4/serverupdatestatus_test.go      | 84 ++++++++++++++--------
 .../traffic_ops_golang/server/put_status.go        |  8 +--
 3 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 269a30baa5..9ac6841b14 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Only `operations` and `admin` roles should have the 
`DELIVERY-SERVICE:UPDATE` permission.
 - [#6369](https://github.com/apache/trafficcontrol/pull/6369) Fixed 
`/acme_accounts` endpoint to validate email and URL fields
 - Fixed searching of the ds parameter merge_parent_groups slice.
+- Fixed TO API `PUT /servers/:id/status` to only queue updates on the same CDN 
as the updated server
 - t3c-generate fix for combining remapconfig and cachekeyconfig parameters for 
MakeRemapDotConfig call.
 
 ### Removed
diff --git a/traffic_ops/testing/api/v4/serverupdatestatus_test.go 
b/traffic_ops/testing/api/v4/serverupdatestatus_test.go
index 8d7b42689a..e4dc57ffd5 100644
--- a/traffic_ops/testing/api/v4/serverupdatestatus_test.go
+++ b/traffic_ops/testing/api/v4/serverupdatestatus_test.go
@@ -468,7 +468,7 @@ func TestSetTopologiesServerUpdateStatuses(t *testing.T) {
                        midCacheGroup       = "topology-mid-cg-04"
                )
                cacheGroupNames := []string{edgeCacheGroup, 
otherEdgeCacheGroup, midCacheGroup}
-               cachesByCacheGroup := map[string]tc.ServerV40{}
+               cachesByCDNCacheGroup := 
make(map[string]map[string][]tc.ServerV4)
                updateStatusByCacheGroup := 
map[string]tc.ServerUpdateStatusV40{}
 
                opts := client.NewRequestOptions()
@@ -511,11 +511,25 @@ func TestSetTopologiesServerUpdateStatuses(t *testing.T) {
                        if len(srvs.Response) < 1 {
                                t.Fatalf("Expected at least one server in Cache 
Group #%d - found none", *cacheGroup.ID)
                        }
-                       cachesByCacheGroup[cacheGroupName] = srvs.Response[0]
+                       for _, s := range srvs.Response {
+                               if _, ok := cachesByCDNCacheGroup[*s.CDNName]; 
!ok {
+                                       cachesByCDNCacheGroup[*s.CDNName] = 
make(map[string][]tc.ServerV4)
+                               }
+                               
cachesByCDNCacheGroup[*s.CDNName][cacheGroupName] = 
append(cachesByCDNCacheGroup[*s.CDNName][cacheGroupName], s)
+                       }
+               }
+               cdnNames := make([]string, 0, len(cachesByCDNCacheGroup))
+               for cdn := range cachesByCDNCacheGroup {
+                       cdnNames = append(cdnNames, cdn)
+               }
+               if len(cdnNames) < 2 {
+                       t.Fatalf("expected servers in at least two CDNs, actual 
number of CDNs: %d", len(cdnNames))
                }
+               cdn1 := cdnNames[0]
+               cdn2 := cdnNames[1]
 
                // update status of MID server to OFFLINE
-               resp, _, err := 
TOSession.UpdateServerStatus(*cachesByCacheGroup[midCacheGroup].ID, 
tc.ServerPutStatus{
+               resp, _, err := 
TOSession.UpdateServerStatus(*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].ID, 
tc.ServerPutStatus{
                        Status:        util.JSONNameOrIDStr{Name: 
util.StrPtr("OFFLINE")},
                        OfflineReason: util.StrPtr("testing")}, 
client.RequestOptions{})
                if err != nil {
@@ -524,7 +538,7 @@ func TestSetTopologiesServerUpdateStatuses(t *testing.T) {
 
                opts = client.NewRequestOptions()
                for _, cacheGroupName := range cacheGroupNames {
-                       cgID := *cachesByCacheGroup[cacheGroupName].CachegroupID
+                       cgID := 
*cachesByCDNCacheGroup[cdn1][cacheGroupName][0].CachegroupID
                        opts.QueryParameters.Set("cachegroup", 
strconv.Itoa(cgID))
                        srvs, _, err := TOSession.GetServers(opts)
                        if err != nil {
@@ -533,52 +547,64 @@ func TestSetTopologiesServerUpdateStatuses(t *testing.T) {
                        if len(srvs.Response) < 1 {
                                t.Fatalf("Expected at least one Server in Cache 
Group #%d, found none", cgID)
                        }
-                       srv := srvs.Response[0]
-                       if srv.HostName == nil || srv.UpdPending == nil || 
srv.ID == nil {
-                               t.Fatal("Traffic Ops returned a representation 
of a server with null or undefined Host Name and/or ID and/or Update Pending 
flag")
+                       for _, s := range srvs.Response {
+                               if s.HostName == nil || s.UpdPending == nil || 
s.ID == nil {
+                                       t.Fatal("Traffic Ops returned a 
representation of a server with null or undefined Host Name and/or ID and/or 
Update Pending flag")
+                               }
+                               if 
len(cachesByCDNCacheGroup[*s.CDNName][cacheGroupName]) > 0 {
+                                       
cachesByCDNCacheGroup[*s.CDNName][cacheGroupName] = []tc.ServerV4{}
+                               }
+                               
cachesByCDNCacheGroup[*s.CDNName][cacheGroupName] = 
append(cachesByCDNCacheGroup[*s.CDNName][cacheGroupName], s)
                        }
-                       cachesByCacheGroup[cacheGroupName] = srvs.Response[0]
                }
                for _, cacheGroupName := range cacheGroupNames {
-                       updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCacheGroup[cacheGroupName].HostName, 
client.RequestOptions{})
+                       updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCDNCacheGroup[cdn1][cacheGroupName][0].HostName,
 client.RequestOptions{})
                        if err != nil {
                                t.Fatalf("unable to get update status for a 
server from Cache Group '%s': %v - alerts: %+v", cacheGroupName, err, 
updResp.Alerts)
                        }
                        if len(updResp.Response) < 1 {
-                               t.Fatalf("Expected at least one server with 
Host Name '%s' to have an update status", 
*cachesByCacheGroup[cacheGroupName].HostName)
+                               t.Fatalf("Expected at least one server with 
Host Name '%s' to have an update status", 
*cachesByCDNCacheGroup[cdn1][cacheGroupName][0].HostName)
                        }
                        updateStatusByCacheGroup[cacheGroupName] = 
updResp.Response[0]
                }
-               // updating the server status does not queue updates within the 
same cachegroup
-               if *cachesByCacheGroup[midCacheGroup].UpdPending {
-                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCacheGroup[midCacheGroup].UpdPending)
+               // updating the server status does not queue updates within the 
same cachegroup in same CDN
+               if *cachesByCDNCacheGroup[cdn1][midCacheGroup][0].UpdPending {
+                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].UpdPending)
+               }
+               // updating the server status does not queue updates within the 
same cachegroup in different CDN
+               if *cachesByCDNCacheGroup[cdn2][midCacheGroup][0].UpdPending {
+                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCDNCacheGroup[cdn2][midCacheGroup][0].UpdPending)
                }
                // edgeCacheGroup is a descendant of midCacheGroup
-               if !*cachesByCacheGroup[edgeCacheGroup].UpdPending {
-                       t.Fatalf("expected UpdPending: %t, actual: %t", true, 
*cachesByCacheGroup[edgeCacheGroup].UpdPending)
+               if !*cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].UpdPending {
+                       t.Fatalf("expected UpdPending: %t, actual: %t", true, 
*cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].UpdPending)
+               }
+               // descendant of midCacheGroup in different CDN should not be 
queued
+               if *cachesByCDNCacheGroup[cdn2][edgeCacheGroup][0].UpdPending {
+                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCDNCacheGroup[cdn2][edgeCacheGroup][0].UpdPending)
                }
                if !updateStatusByCacheGroup[edgeCacheGroup].UpdatePending {
                        t.Fatalf("expected UpdPending: %t, actual: %t", true, 
updateStatusByCacheGroup[edgeCacheGroup].UpdatePending)
                }
                // otherEdgeCacheGroup is not a descendant of midCacheGroup but 
is still in the same topology
-               if *cachesByCacheGroup[otherEdgeCacheGroup].UpdPending {
-                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCacheGroup[otherEdgeCacheGroup].UpdPending)
+               if 
*cachesByCDNCacheGroup[cdn1][otherEdgeCacheGroup][0].UpdPending {
+                       t.Fatalf("expected UpdPending: %t, actual: %t", false, 
*cachesByCDNCacheGroup[cdn1][otherEdgeCacheGroup][0].UpdPending)
                }
                if updateStatusByCacheGroup[otherEdgeCacheGroup].UpdatePending {
                        t.Fatalf("expected UpdPending: %t, actual: %t", false, 
updateStatusByCacheGroup[otherEdgeCacheGroup].UpdatePending)
                }
 
-               squResp, _, err := 
TOSession.SetServerQueueUpdate(*cachesByCacheGroup[midCacheGroup].ID, true, 
client.RequestOptions{})
+               squResp, _, err := 
TOSession.SetServerQueueUpdate(*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].ID,
 true, client.RequestOptions{})
                if err != nil {
-                       t.Fatalf("cannot update server status on %s: %v - 
alerts: %+v", *cachesByCacheGroup[midCacheGroup].HostName, err, squResp.Alerts)
+                       t.Fatalf("cannot update server status on %s: %v - 
alerts: %+v", *cachesByCDNCacheGroup[cdn1][midCacheGroup][0].HostName, err, 
squResp.Alerts)
                }
                for _, cacheGroupName := range cacheGroupNames {
-                       updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCacheGroup[cacheGroupName].HostName, 
client.RequestOptions{})
+                       updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCDNCacheGroup[cdn1][cacheGroupName][0].HostName,
 client.RequestOptions{})
                        if err != nil {
                                t.Fatalf("unable to get an update status for a 
server from Cache Group '%s': %v - alerts: %+v", cacheGroupName, err, 
updResp.Alerts)
                        }
                        if len(updResp.Response) < 1 {
-                               t.Fatalf("Expected at least one server with 
Host Name '%s' to have an update status", 
*cachesByCacheGroup[cacheGroupName].HostName)
+                               t.Fatalf("Expected at least one server with 
Host Name '%s' to have an update status", 
*cachesByCDNCacheGroup[cdn1][cacheGroupName][0].HostName)
                        }
                        updateStatusByCacheGroup[cacheGroupName] = 
updResp.Response[0]
                }
@@ -592,20 +618,20 @@ func TestSetTopologiesServerUpdateStatuses(t *testing.T) {
                        t.Fatalf("expected UpdPending: %t, actual: %t", false, 
updateStatusByCacheGroup[otherEdgeCacheGroup].ParentPending)
                }
 
-               edgeHostName := *cachesByCacheGroup[edgeCacheGroup].HostName
-               *cachesByCacheGroup[edgeCacheGroup].HostName = 
*cachesByCacheGroup[midCacheGroup].HostName
-               _, _, err = 
TOSession.UpdateServer(*cachesByCacheGroup[edgeCacheGroup].ID, 
cachesByCacheGroup[edgeCacheGroup], client.RequestOptions{})
+               edgeHostName := 
*cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].HostName
+               *cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].HostName = 
*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].HostName
+               _, _, err = 
TOSession.UpdateServer(*cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].ID, 
cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0], client.RequestOptions{})
                if err != nil {
-                       t.Fatalf("unable to update %s's hostname to %s: %s", 
edgeHostName, *cachesByCacheGroup[midCacheGroup].HostName, err)
+                       t.Fatalf("unable to update %s's hostname to %s: %s", 
edgeHostName, *cachesByCDNCacheGroup[cdn1][midCacheGroup][0].HostName, err)
                }
 
-               updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCacheGroup[midCacheGroup].HostName, 
client.RequestOptions{})
+               updResp, _, err := 
TOSession.GetServerUpdateStatus(*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].HostName,
 client.RequestOptions{})
                if err != nil {
-                       t.Fatalf("expected no error getting server updates for 
a non-unique hostname %s, got: %v - alerts: %+v", 
*cachesByCacheGroup[midCacheGroup].HostName, err, updResp.Alerts)
+                       t.Fatalf("expected no error getting server updates for 
a non-unique hostname %s, got: %v - alerts: %+v", 
*cachesByCDNCacheGroup[cdn1][midCacheGroup][0].HostName, err, updResp.Alerts)
                }
 
-               *cachesByCacheGroup[edgeCacheGroup].HostName = edgeHostName
-               _, _, err = 
TOSession.UpdateServer(*cachesByCacheGroup[edgeCacheGroup].ID, 
cachesByCacheGroup[edgeCacheGroup], client.RequestOptions{})
+               *cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].HostName = 
edgeHostName
+               _, _, err = 
TOSession.UpdateServer(*cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0].ID, 
cachesByCDNCacheGroup[cdn1][edgeCacheGroup][0], client.RequestOptions{})
                if err != nil {
                        t.Fatalf("unable to revert %s's hostname back to %s: 
%s", edgeHostName, edgeHostName, err)
                }
diff --git a/traffic_ops/traffic_ops_golang/server/put_status.go 
b/traffic_ops/traffic_ops_golang/server/put_status.go
index 80ba9b0b5c..d66060a49f 100644
--- a/traffic_ops/traffic_ops_golang/server/put_status.go
+++ b/traffic_ops/traffic_ops_golang/server/put_status.go
@@ -199,14 +199,14 @@ JOIN topology_descendants td ON c."name" = td.cachegroup
 )
 UPDATE public.server
 SET config_update_time = now()
-WHERE (server.cdn_id = $1
-          AND server.cachegroup IN (
+WHERE server.cdn_id = $1
+          AND (server.cachegroup IN (
                        SELECT id
                        FROM cachegroup
                        WHERE parent_cachegroup_id = $2
                                OR secondary_parent_cachegroup_id = $2
-                       ))
-               OR server.cachegroup IN (SELECT stc.id FROM 
server_topology_descendants stc);
+                       )
+                       OR server.cachegroup IN (SELECT stc.id FROM 
server_topology_descendants stc));
 `
        if _, err := tx.Exec(q, cdnID, parentCachegroupID); err != nil {
                return errors.New("queueing updates on child caches: " + 
err.Error())

Reply via email to