rimashah25 commented on a change in pull request #5307:
URL: https://github.com/apache/trafficcontrol/pull/5307#discussion_r527874619
##########
File path: traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
##########
@@ -1009,3 +1010,49 @@ GROUP BY t.name, ds.topology
}
return dsType, reqCap, topology, true, nil
}
+
+// CheckOriginServerInCacheGroupTopology checks if a DS has ORG server and if
it does, to make sure the cachegroup is part of DS
+func CheckOriginServerInCacheGroupTopology(tx *sql.Tx, dsID int, dsTopology
string) (error, error, int) {
+ // get servers and respective cachegroup name that have ORG type in a
delivery service
+ q := `
+ SELECT s2.host_name, c.name
+ FROM server s2
+ INNER JOIN deliveryservice_server ds ON ds.server =
s2.id
+ inner join type t on t.id = s2.type
+ INNER JOIN cachegroup c ON c.id = s2.cachegroup
+ WHERE ds.deliveryservice=$1 and t.name='ORG'
+ GROUP BY s2.host_name, c.name
+ `
+
+ serverName := ""
+ cacheGroupName := ""
+ rows, err := tx.Query(q, dsID)
+ if err != nil {
+ return nil, fmt.Errorf("querying deliveryservice origin server:
%s", err), http.StatusInternalServerError
+ }
+ for rows.Next() {
+ if err := rows.Scan(&serverName, &cacheGroupName); err != nil {
+ return nil, fmt.Errorf("querying deliveryservice origin
server: %s", err), http.StatusInternalServerError
+ }
+ }
+ fmt.Println("CacheName:", cacheGroupName)
+
+ servers := make(map[string]string)
+ servers[cacheGroupName] = serverName
+ fmt.Println(servers)
+
+ if len(servers) > 0 {
+ cachegroups, sysErr := GetTopologyCachegroups(tx, dsTopology)
+ if sysErr != nil {
+ return nil, fmt.Errorf("validating %s servers in
topology: %v", tc.OriginTypeName, sysErr), http.StatusInternalServerError
+ }
+ for _, cg := range cachegroups {
+ if _, ok := servers[cg]; ok {
Review comment:
Ok.. Updated the logic.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]