rob05c commented on a change in pull request #4790:
URL: https://github.com/apache/trafficcontrol/pull/4790#discussion_r451711379



##########
File path: lib/go-atscfg/remapdotconfig.go
##########
@@ -196,7 +224,11 @@ func GetServerConfigRemapDotConfigForEdge(
                        if ds.ProfileID != nil {
                                profilecacheKeyConfigParams = 
profilesCacheKeyConfigParams[*ds.ProfileID]
                        }
-                       remapText = BuildRemapLine(cacheURLConfigParams, 
atsMajorVersion, server, serverPackageParamData, remapText, ds, line.From, 
line.To, profilecacheKeyConfigParams)
+                       remapText = BuildRemapLine(cacheURLConfigParams, 
atsMajorVersion, serverInfo, serverPackageParamData, remapText, ds, line.From, 
line.To, profilecacheKeyConfigParams)
+                       if hasTopology {
+                               remapText += " # topology" // debug

Review comment:
       Done.

##########
File path: lib/go-atscfg/remapdotconfig.go
##########
@@ -74,28 +75,49 @@ func MakeRemapDotConfig(
        serverPackageParamData map[string]string, // map[paramName]paramVal for 
this server, config file 'package'
        serverInfo *ServerInfo, // ServerInfo for this server
        remapDSData []RemapConfigDSData,
+       topologies []tc.Topology,
 ) string {
-       hdr := GenericHeaderComment(string(serverName), toToolName, toURL)
-       text := ""
+       dsTopologies := makeDSTopologies(remapDSData, topologies)
+       hdr := GenericHeaderComment(server.HostName, toToolName, toURL)
        if tc.CacheTypeFromString(serverInfo.Type) == tc.CacheTypeMid {
-               text = GetServerConfigRemapDotConfigForMid(atsMajorVersion, 
dsProfilesCacheKeyConfigParams, serverInfo, remapDSData, hdr)
-       } else {
-               text = 
GetServerConfigRemapDotConfigForEdge(cacheURLConfigParams, 
dsProfilesCacheKeyConfigParams, serverPackageParamData, serverInfo, 
remapDSData, atsMajorVersion, hdr)
+               return GetServerConfigRemapDotConfigForMid(atsMajorVersion, 
dsProfilesCacheKeyConfigParams, serverInfo, remapDSData, hdr, server, 
dsTopologies)
        }
-       return text
+       return GetServerConfigRemapDotConfigForEdge(cacheURLConfigParams, 
dsProfilesCacheKeyConfigParams, serverPackageParamData, serverInfo, 
remapDSData, atsMajorVersion, hdr, server, dsTopologies)
+}
+
+func makeDSTopologies(dses []RemapConfigDSData, topologies []tc.Topology) 
map[tc.DeliveryServiceName]tc.Topology {
+       dsTops := map[tc.DeliveryServiceName]tc.Topology{}
+       topNames := map[string]tc.Topology{}
+       for _, to := range topologies {
+               topNames[to.Name] = to
+       }
+       for _, ds := range dses {
+               if to, ok := topNames[ds.Topology]; ok {
+                       dsTops[tc.DeliveryServiceName(ds.Name)] = to
+               } else if ds.Topology != "" {
+                       log.Errorln("Making remap.config for Delivery Service 
'" + ds.Name + "': has topology '" + ds.Topology + "', but that topology 
doesn't exist! Treating as if DS has no Topology!")
+               }
+       }
+       return dsTops
 }
 
 func GetServerConfigRemapDotConfigForMid(
        atsMajorVersion int,
        profilesCacheKeyConfigParams map[int]map[string]string,
-       server *ServerInfo,
+       serverInfo *ServerInfo,

Review comment:
       Removed

##########
File path: lib/go-atscfg/parentdotconfig.go
##########
@@ -331,13 +345,270 @@ func MakeParentDotConfig(
                        defaultDestText += ` qstring=` + qStr
                }
                defaultDestText += "\n"
-
-               sort.Sort(sort.StringSlice(textArr))
-               text = hdr + strings.Join(textArr, "") + defaultDestText
        }
+
+       sort.Sort(sort.StringSlice(textArr))
+       text := hdr + strings.Join(textArr, "") + defaultDestText
        return text
 }
 
+func GetTopologyParentConfigLine(
+       server tc.Server,
+       servers []tc.Server,
+       ds ParentConfigDSTopLevel,
+       serverParams map[string]string,
+       parentConfigParams []ParameterWithProfilesMap, // all params with 
configFile parent.config
+       topologies []tc.Topology,
+       serverCapabilities map[int]map[ServerCapability]struct{},
+) (string, error) {
+       txt := ""
+
+       if !HasRequiredCapabilities(serverCapabilities[server.ID], 
ds.RequiredCapabilities) {
+               return "", nil
+       }
+
+       orgURI, err := GetOriginURI(ds.OriginFQDN)
+       if err != nil {
+               return "", errors.New("Malformed ds '" + string(ds.Name) + "' 
origin  URI: '" + ds.OriginFQDN + "': skipping!" + err.Error())
+       }
+
+       // This could be put in a map beforehand to only iterate once, if 
performance mattered
+       topology := tc.Topology{}
+       for _, to := range topologies {
+               if to.Name == ds.Topology {
+                       topology = to
+                       break
+               }
+       }
+       if topology.Name == "" {
+               return "", errors.New("DS " + string(ds.Name) + " topology '" + 
ds.Topology + "' not found in Topologies!")
+       }
+
+       txt += "dest_domain=" + orgURI.Hostname() + " port=" + orgURI.Port()
+
+       serverIsLastTier, serverInTopology := serverTopologyTier(server, 
topology)
+       if !serverInTopology {
+               return "", nil // server isn't in topology, no error
+       }
+       // TODO omit server and parents without necessary Capabilities
+       // TODO add Topology/Capabilities to remap.config
+
+       parents, secondaryParents, err := GetTopologyParents(server, ds, 
serverParams, servers, parentConfigParams, topology, serverIsLastTier, 
serverCapabilities)
+       if err != nil {
+               return "", errors.New("getting topology parents for '" + 
string(ds.Name) + "': skipping! " + err.Error())
+       }
+       txt += ` parent="` + strings.Join(parents, `;`) + `"`
+       if len(secondaryParents) > 0 {
+               txt += ` secondary_parent="` + strings.Join(secondaryParents, 
`;`) + `"`
+       }
+       txt += ` round_robin=` + getTopologyRoundRobin(server, ds, topology, 
serverParams, serverIsLastTier)
+       txt += ` go_direct=` + getTopologyGoDirect(server, ds, topology, 
serverIsLastTier)
+       txt += ` qstring=` + getTopologyQueryString(server, ds, topology, 
serverParams, serverIsLastTier)
+       txt += getTopologyParentIsProxyStr(serverIsLastTier)
+       txt += " # topology"
+       txt += "\n"
+       return txt, nil
+}
+
+func getTopologyParentIsProxyStr(serverIsLastTier bool) string {
+       if serverIsLastTier { // && ds.MultiSiteOrigin

Review comment:
       Removed




----------------------------------------------------------------
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]


Reply via email to