rimashah25 commented on a change in pull request #5350:
URL: https://github.com/apache/trafficcontrol/pull/5350#discussion_r543606703
##########
File path: traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
##########
@@ -1150,3 +1151,68 @@ func CheckOriginServerInCacheGroupTopology(tx *sql.Tx,
dsID int, dsTopology stri
}
return nil, nil, http.StatusOK
}
+
+//GetDSByCDNIdTopology return the id of delivery service based on cdn_id and
topology_name
+func GetDSByCDNIdTopology(tx *sql.Tx, cdnId int, topology string) (error,
[]int) {
+ dsId := []int64{}
+ q := `
+ SELECT COALESCE(ARRAY_AGG(id), '{}'::BIGINT[])
+ FROM deliveryservice
+ WHERE cdn_id=$1 AND topology=$2
+ `
+ err := tx.QueryRow(q, cdnId, topology).Scan(pq.Array(&dsId))
+ if err != nil {
+ return fmt.Errorf("querying delivery services: %s", err), nil
+ }
+ res := make([]int, len(dsId))
+ for i, id := range dsId {
+ res[i] = int(id)
+ }
+ return err, res
+}
+
+// CheckTopologyOrgServerCGInDSCG checks if ORG server are part of DS. IF they
are then the user is not allowed to remove the ORG servers from the associated
DS's topology
+func CheckTopologyOrgServerCGInDSCG(tx *sql.Tx, dsIDs []int, dsTopology
string, topologyCGNames []string) (error, error, int) {
+ // get servers and respective cachegroup name that have ORG type for
evert delivery service
+ q := `
+ SELECT d.xml_id, s.host_name, c.name
+ FROM server s
+ INNER JOIN deliveryservice_server ds ON ds.server = s.id
+ INNER JOIN deliveryservice d ON d.id =
ds.deliveryservice
+ INNER JOIN type t ON t.id = s.type
+ INNER JOIN cachegroup c ON c.id = s.cachegroup
+ WHERE ds.deliveryservice =ANY($1) AND t.name=$2
+ `
+ serverName := ""
+ cacheGroupName := ""
+ dsName := ""
+ servers := make(map[string]string)
+ rows, err := tx.Query(q, pq.Array(dsIDs), tc.OriginTypeName)
+ if err != nil {
+ return nil, fmt.Errorf("querying deliveryservice origin server:
%s", err), http.StatusInternalServerError
+ }
+ defer log.Close(rows, "error closing rows")
+ for rows.Next() {
+ if err := rows.Scan(&dsName, &serverName, &cacheGroupName); err
!= nil {
+ return nil, fmt.Errorf("querying deliveryservice origin
server: %s", err), http.StatusInternalServerError
+ }
+ servers[cacheGroupName] = serverName
+ }
+
+ var offendingDSSerCG []string
+ // put slice values into map for Topology's validation
+ topoCacheGroupNames := make(map[string]string)
+ for _, currentCG := range topologyCGNames {
+ topoCacheGroupNames[currentCG] = ""
+ }
+ for cg, s := range servers {
+ _, currentTopoCGOk := topoCacheGroupNames[cg]
+ if !currentTopoCGOk {
+ offendingDSSerCG = append(offendingDSSerCG,
fmt.Sprintf("%s (%s)", cg, s))
Review comment:
sigh.. ok
----------------------------------------------------------------
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]