rob05c commented on a change in pull request #5247:
URL: https://github.com/apache/trafficcontrol/pull/5247#discussion_r524816128
##########
File path: lib/go-atscfg/headerrewritemiddotconfig.go
##########
@@ -20,24 +20,134 @@ package atscfg
*/
import (
+ "fmt"
"math"
"regexp"
"strconv"
+ "strings"
"github.com/apache/trafficcontrol/lib/go-tc"
)
const HeaderRewriteMidPrefix = "hdr_rw_mid_"
func MakeHeaderRewriteMidDotConfig(
- cdnName tc.CDNName,
- toToolName string, // tm.toolname global parameter (TODO: cache itself?)
- toURL string, // tm.url global parameter (TODO: cache itself?)
- ds HeaderRewriteDS,
- assignedMids []HeaderRewriteServer, // the mids assigned to ds (mids
whose cachegroup is the parent of the cachegroup of any edge assigned to this
ds)
-) string {
- text := GenericHeaderComment(string(cdnName), toToolName, toURL)
+ fileName string,
+ deliveryServices []tc.DeliveryServiceNullableV30,
+ deliveryServiceServers []tc.DeliveryServiceServer,
+ server *tc.ServerNullable,
+ servers []tc.ServerNullable,
+ cacheGroups []tc.CacheGroupNullable,
+ hdrComment string,
+) (Cfg, error) {
+ warnings := []string{}
+ if server.CDNName == nil {
+ return Cfg{}, makeErr(warnings, "this server missing CDNName")
+ }
+
+ dsName := strings.TrimSuffix(strings.TrimPrefix(fileName,
HeaderRewriteMidPrefix), ConfigSuffix) // TODO verify prefix and suffix? Perl
doesn't
+
+ tcDS := tc.DeliveryServiceNullableV30{}
+ for _, ds := range deliveryServices {
+ if ds.XMLID == nil || *ds.XMLID != dsName {
+ continue
+ }
+ tcDS = ds
+ break
+ }
+ if tcDS.ID == nil {
+ return Cfg{}, makeErr(warnings, "ds '"+dsName+"' not found")
+ }
+
+ if tcDS.CDNName == nil {
+ return Cfg{}, makeErr(warnings, "ds '"+dsName+"' missing cdn")
+ }
+
+ ds, err := headerRewriteDSFromDS(&tcDS)
+ if err != nil {
+ return Cfg{}, makeErr(warnings, "converting ds to config ds:
"+err.Error())
+ }
+
+ assignedServers := map[int]struct{}{}
+ for _, dss := range deliveryServiceServers {
+ if dss.Server == nil || dss.DeliveryService == nil {
+ continue
+ }
+ if *dss.DeliveryService != *tcDS.ID {
+ continue
+ }
+ assignedServers[*dss.Server] = struct{}{}
+ }
+ serverCGs := map[tc.CacheGroupName]struct{}{}
+ for _, sv := range servers {
+ if sv.CDNName == nil {
+ warnings = append(warnings, "TO returned Servers server
with missing CDNName, skipping!")
+ continue
+ } else if sv.ID == nil {
+ warnings = append(warnings, "TO returned Servers server
with missing ID, skipping!")
+ continue
+ } else if sv.Status == nil {
+ warnings = append(warnings, "TO returned Servers server
with missing Status, skipping!")
+ continue
+ } else if sv.Cachegroup == nil {
+ warnings = append(warnings, "TO returned Servers server
with missing Cachegroup, skipping!")
+ continue
+ }
+
+ if sv.CDNName != server.CDNName {
+ continue
+ }
+ if _, ok := assignedServers[*sv.ID]; !ok && (tcDS.Topology ==
nil || *tcDS.Topology == "") {
+ continue
+ }
+ if tc.CacheStatus(*sv.Status) != tc.CacheStatusReported &&
tc.CacheStatus(*sv.Status) != tc.CacheStatusOnline {
+ continue
+ }
+ serverCGs[tc.CacheGroupName(*sv.Cachegroup)] = struct{}{}
+ }
+
+ parentCGs := map[string]struct{}{} // names of cachegroups which are
parent cachegroups of the cachegroup of any edge assigned to the given DS
+ for _, cg := range cacheGroups {
+ if cg.Name == nil {
+ continue // TODO warn?
+ }
+ if cg.ParentName == nil {
+ continue // TODO warn?
Review comment:
Same as above, fixed
----------------------------------------------------------------
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]