traeak commented on code in PR #7137:
URL: https://github.com/apache/trafficcontrol/pull/7137#discussion_r1003289241


##########
lib/go-atscfg/parentdotconfig.go:
##########
@@ -383,258 +390,112 @@ func makeParentDotConfigData(
                        continue
                }
 
-               isMSO := ds.MultiSiteOrigin != nil && *ds.MultiSiteOrigin
+               // manufacture a topology for this DS.
+               if ds.Topology == nil || *ds.Topology == "" {
+                       // only populate if there are non topology ds's
+                       if len(ocgmap) == 0 {
+                               ocgmap = makeOCGMap(parentInfos)
+                               if len(ocgmap) == 0 {
+                                       ocgmap[""] = []string{}
+                               }
+                       }
 
-               // TODO put these in separate functions. No if-statement should 
be this long.
-               if ds.Topology != nil && *ds.Topology != "" {
-                       pasvc, topoWarnings, err := getTopologyParentConfigLine(
-                               server,
-                               serversWithParams,
-                               &ds,
-                               serverParams,
-                               parentConfigParams,
-                               nameTopologies,
-                               serverCapabilities,
-                               dsRequiredCapabilities,
-                               cacheGroups,
-                               profileParentConfigParams,
-                               isMSO,
-                               atsMajorVersion,
-                               dsOrigins[DeliveryServiceID(*ds.ID)],
-                               opt.AddComments,
-                       )
-                       warnings = append(warnings, topoWarnings...)
+                       orgFQDNStr := *ds.OrgServerFQDN
+                       orgURI, orgWarns, err := getOriginURI(orgFQDNStr)
+                       warnings = append(warnings, orgWarns...)
                        if err != nil {
-                               // we don't want to fail generation with an 
error if one ds is malformed
-                               warnings = append(warnings, err.Error()) // 
getTopologyParentConfigLine includes error context
+                               warnings = append(warnings, "DS '"+*ds.XMLID+"' 
has malformed origin URI: '"+orgFQDNStr+"': skipping!"+err.Error())
                                continue
                        }
 
-                       if pasvc != nil { // will be nil with no error if this 
server isn't in the Topology, or if it doesn't have the Required Capabilities
-                               parentAbstraction.Services = 
append(parentAbstraction.Services, pasvc)
-                       }
-               } else {
-                       isLastCacheTier := 
noTopologyServerIsLastCacheForDS(server, &ds, cacheGroups)
-                       serverPlacement := TopologyPlacement{
-                               IsLastCacheTier:  isLastCacheTier,
-                               IsFirstCacheTier: !isLastCacheTier || 
!ds.Type.UsesMidCache(),
-                       }
-
-                       dsParams, dswarns := getParentDSParams(ds, 
profileParentConfigParams, serverPlacement, isMSO)
-                       warnings = append(warnings, dswarns...)
-
-                       if cacheIsTopLevel {
-                               parentQStr := false
-                               if dsParams.QueryStringHandling == "" && 
dsParams.Algorithm == tc.AlgorithmConsistentHash && ds.QStringIgnore != nil && 
tc.QStringIgnore(*ds.QStringIgnore) == tc.QStringIgnoreUseInCacheKeyAndPassUp {
-                                       parentQStr = true
-                               }
-
-                               orgFQDNStr := *ds.OrgServerFQDN
-                               // if this cache isn't the last tier, i.e. 
we're not going to the origin, use http not https
-                               if !isLastCacheTier {
-                                       orgFQDNStr = 
strings.Replace(orgFQDNStr, `https://`, `http://`, -1)
-                               }
-                               orgURI, orgWarns, err := 
getOriginURI(orgFQDNStr)
-                               warnings = append(warnings, orgWarns...)
-                               if err != nil {
-                                       warnings = append(warnings, "DS 
'"+*ds.XMLID+"' has malformed origin URI: '"+orgFQDNStr+"': 
skipping!"+err.Error())
+                       // use the topology name for the fqdn
+                       topoName := orgURI.Hostname()
+                       cgnames, ok := ocgmap[OriginHost(topoName)]
+                       if !ok {
+                               topoName = deliveryServicesAllParentsKey
+                               cgnames, ok = ocgmap[OriginHost(topoName)]
+                               if !ok {
+                                       warnings = append(warnings, "DS 
'"+*ds.XMLID+"' has no parent cache groups! Skipping!")
                                        continue
                                }
+                       }
 
-                               pasvc := &ParentAbstractionService{}
-                               pasvc.Name = *ds.XMLID
-
-                               if ds.OriginShield != nil && *ds.OriginShield 
!= "" {
-
-                                       policy := 
ParentAbstractionServiceRetryPolicyConsistentHash
-
-                                       if parentSelectAlg := 
serverParams[ParentConfigRetryKeysDefault.Algorithm]; 
strings.TrimSpace(parentSelectAlg) != "" {
-                                               paramPolicy := 
ParentSelectAlgorithmToParentAbstractionServiceRetryPolicy(parentSelectAlg)
-                                               if paramPolicy != 
ParentAbstractionServiceRetryPolicyInvalid {
-                                                       policy = paramPolicy
-                                               } else {
-                                                       warnings = 
append(warnings, "DS '"+*ds.XMLID+"' had malformed 
"+ParentConfigRetryKeysDefault.Algorithm+" parameter '"+parentSelectAlg+"', not 
using!")
-                                               }
-                                       }
-                                       pasvc.Comment = 
makeParentComment(opt.AddComments, *ds.XMLID, "")
-                                       pasvc.DestDomain = orgURI.Hostname()
-                                       pasvc.Port, err = 
strconv.Atoi(orgURI.Port())
-                                       if err != nil {
-                                               if 
strings.ToLower(orgURI.Scheme) == "https" {
-                                                       pasvc.Port = 443
-                                               } else {
-                                                       pasvc.Port = 80
-                                               }
-                                               warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had malformed origin  port: '"+orgURI.Port()+"': using 
"+strconv.Itoa(pasvc.Port)+"! : "+err.Error())
-                                       }
-
-                                       fqdnPort := 
strings.Split(*ds.OriginShield, ":")
-                                       parent := 
&ParentAbstractionServiceParent{}
-                                       parent.FQDN = fqdnPort[0]
-                                       if len(fqdnPort) > 1 {
-                                               parent.Port, err = 
strconv.Atoi(fqdnPort[1])
-                                               if err != nil {
-                                                       parent.Port = 80
-                                                       warnings = 
append(warnings, "DS '"+*ds.XMLID+"' had malformed origin  port: 
'"+*ds.OriginShield+"': using "+strconv.Itoa(parent.Port)+"! : "+err.Error())
-                                               }
-                                       } else {
-                                               parent.Port = 80
-                                               warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had no origin port: '"+*ds.OriginShield+"': using 
"+strconv.Itoa(parent.Port)+"!")
-                                       }
-                                       pasvc.Parents = append(pasvc.Parents, 
parent)
-                                       pasvc.RetryPolicy = policy
-                                       pasvc.GoDirect = true
-
-                                       // textLine += "dest_domain=" + 
orgURI.Hostname() + " port=" + orgURI.Port() + " parent=" + *ds.OriginShield + 
" " + algorithm + " go_direct=true\n"
-
-                               } else if ds.MultiSiteOrigin != nil && 
*ds.MultiSiteOrigin {
-                                       pasvc.Comment = 
makeParentComment(opt.AddComments, *ds.XMLID, "")
-                                       pasvc.DestDomain = orgURI.Hostname()
-                                       pasvc.Port, err = 
strconv.Atoi(orgURI.Port())
-                                       if err != nil {
-                                               pasvc.Port = 80
-                                               warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had malformed origin  port: '"+orgURI.Port()+"': using 
"+strconv.Itoa(pasvc.Port)+"! : "+err.Error())
-                                       }
-
-                                       // textLine += "dest_domain=" + 
orgURI.Hostname() + " port=" + orgURI.Port() + " "
-                                       if len(parentInfos) == 0 {
-                                       }
-
-                                       if 
len(parentInfos[OriginHost(orgURI.Hostname())]) == 0 {
-                                               // TODO error? emulates Perl
-                                               warnings = append(warnings, "DS 
"+*ds.XMLID+" has no parent servers")
-                                       }
-
-                                       parents, secondaryParents, 
secondaryMode, parentWarns := getMSOParentStrs(&ds, 
parentInfos[OriginHost(orgURI.Hostname())], atsMajorVersion, 
dsParams.Algorithm, dsParams.TryAllPrimariesBeforeSecondary)
-                                       warnings = append(warnings, 
parentWarns...)
-                                       pasvc.Parents = parents
-                                       pasvc.SecondaryParents = 
secondaryParents
-                                       pasvc.SecondaryMode = secondaryMode
-                                       pasvc.RetryPolicy = dsParams.Algorithm 
// TODO convert
-                                       
pasvc.IgnoreQueryStringInParentSelection = !parentQStr
-                                       pasvc.GoDirect = true
-
-                                       // textLine += parents + 
secondaryParents + ` round_robin=` + dsParams.Algorithm + ` qstring=` + 
parentQStr + ` go_direct=false parent_is_proxy=false`
-
-                                       prWarns := 
dsParams.FillParentSvcRetries(cacheIsTopLevel, atsMajorVersion, pasvc)
-                                       warnings = append(warnings, prWarns...)
+                       // Manufactured topology
+                       topo := tc.Topology{Name: topoName}
 
-                                       parentAbstraction.Services = 
append(parentAbstraction.Services, pasvc)
+                       if IsGoDirect(ds) {
+                               node := tc.TopologyNode{
+                                       Cachegroup: *server.Cachegroup,
                                }
+                               topo.Nodes = append(topo.Nodes, node)
                        } else {
-                               queryStringHandling := 
ParentSelectParamQStringHandlingToBool(serverParams[ParentConfigParamQStringHandling])
 // "qsh" in Perl
-                               if queryStringHandling == nil && 
serverParams[ParentConfigParamQStringHandling] != "" {
-                                       warnings = append(warnings, "Server 
Parameter '"+ParentConfigParamQStringHandling+"' value 
'"+serverParams[ParentConfigParamQStringHandling]+"' malformed, not using!")
+                               // If mid cache group, insert fake edge cache 
group.
+                               // This is incorrect if there are multiple MID 
tiers.
+                               pind := 1
+                               if strings.HasPrefix(server.Type, 
tc.MidTypePrefix) {
+                                       parents := []int{pind}
+                                       pind++
+                                       edgeNode := tc.TopologyNode{
+                                               Cachegroup: "fake_edgecg",
+                                               Parents:    parents,
+                                       }
+                                       topo.Nodes = append(topo.Nodes, 
edgeNode)
                                }
 
-                               roundRobin := 
ParentAbstractionServiceRetryPolicyConsistentHash
-                               // roundRobin := `round_robin=consistent_hash`
-                               goDirect := false
-                               // goDirect := `go_direct=false`
-
-                               parents, secondaryParents, secondaryMode, 
parentWarns := getParentStrs(&ds, dsRequiredCapabilities, 
parentInfos[deliveryServicesAllParentsKey], atsMajorVersion, 
dsParams.TryAllPrimariesBeforeSecondary)
-                               warnings = append(warnings, parentWarns...)
-
-                               pasvc := &ParentAbstractionService{}
-                               pasvc.Name = *ds.XMLID
-
-                               // peering ring check
-                               if dsParams.UsePeering {
-                                       secondaryMode = 
ParentAbstractionServiceParentSecondaryModePeering
+                               parents := []int{}
+                               for ind := 0; ind < len(cgnames); ind++ {
+                                       parents = append(parents, pind)
+                                       pind++
                                }
 
-                               orgFQDNStr := *ds.OrgServerFQDN
-                               // if this cache isn't the last tier, i.e. 
we're not going to the origin, use http not https
-                               if !isLastCacheTier {
-                                       orgFQDNStr = 
strings.Replace(orgFQDNStr, `https://`, `http://`, -1)
+                               node := tc.TopologyNode{
+                                       Cachegroup: *server.Cachegroup,
+                                       Parents:    parents,
                                }
-                               orgURI, orgWarns, err := 
getOriginURI(orgFQDNStr)
-                               warnings = append(warnings, orgWarns...)
-                               if err != nil {
-                                       warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had malformed origin  URI: '"+*ds.OrgServerFQDN+"': 
skipping!"+err.Error())
-                                       continue
-                               }
-
-                               pasvc.Comment = 
makeParentComment(opt.AddComments, *ds.XMLID, "")
-
-                               // TODO encode this in a DSType func, 
IsGoDirect() ?
-                               if *ds.Type == tc.DSTypeHTTPNoCache || *ds.Type 
== tc.DSTypeHTTPLive || *ds.Type == tc.DSTypeDNSLive {
-                                       pasvc.DestDomain = orgURI.Hostname()
-                                       pasvc.Port, err = 
strconv.Atoi(orgURI.Port())
-                                       if err != nil {
-                                               if 
strings.ToLower(orgURI.Scheme) == "https" {
-                                                       pasvc.Port = 443
-                                               } else {
-                                                       pasvc.Port = 80
-                                               }
-                                               warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had malformed origin  port: '"+orgURI.Port()+"': using 
"+strconv.Itoa(pasvc.Port)+"! : "+err.Error())
-                                       }
-
-                                       pasvc.GoDirect = true
-
-                                       pasvc.Parents = 
[]*ParentAbstractionServiceParent{&ParentAbstractionServiceParent{
-                                               FQDN:   pasvc.DestDomain,
-                                               Port:   pasvc.Port,
-                                               Weight: 1.0,
-                                       }}
+                               topo.Nodes = append(topo.Nodes, node)
 
-                                       // text += `dest_domain=` + 
orgURI.Hostname() + ` port=` + orgURI.Port() + ` go_direct=true` + "\n"
-                               } else {
-
-                                       // check for profile 
psel.qstring_handling.  If this parameter is assigned to the server profile,
-                                       // then edges will use the qstring 
handling value specified in the parameter for all profiles.
-
-                                       // If there is no defined parameter in 
the profile, then check the delivery service profile.
-                                       // If psel.qstring_handling exists in 
the DS profile, then we use that value for the specified DS only.
-                                       // This is used only if not overridden 
by a server profile qstring handling parameter.
+                               for _, cg := range cgnames {
+                                       topo.Nodes = append(topo.Nodes, 
tc.TopologyNode{Cachegroup: cg})
+                               }
+                       }
 
-                                       // TODO refactor this logic, hard to 
understand (transliterated from Perl)
-                                       dsQSH := queryStringHandling
-                                       if dsQSH == nil {
-                                               dsQSH = 
ParentSelectParamQStringHandlingToBool(dsParams.QueryStringHandling)
-                                               if dsQSH == nil && 
dsParams.QueryStringHandling != "" {
-                                                       warnings = 
append(warnings, "Delivery Service parameter 
'"+ParentConfigParamQStringHandling+"' value '"+dsParams.QueryStringHandling+"' 
malformed, not using!")
-                                               }
+                       nameTopologies[TopologyName(topoName)] = topo
+                       ds.Topology = util.StrPtr(topoName)
+               }
 
-                                       }
-                                       parentQStr := dsQSH
-                                       if parentQStr == nil {
-                                               v := false
-                                               parentQStr = &v
-                                       }
-                                       if ds.QStringIgnore != nil && 
tc.QStringIgnore(*ds.QStringIgnore) == tc.QStringIgnoreUseInCacheKeyAndPassUp 
&& dsQSH == nil {
-                                               v := true
-                                               parentQStr = &v
-                                       }
-                                       if parentQStr == nil {
-                                               b := 
!DefaultIgnoreQueryStringInParentSelection
-                                               parentQStr = &b
-                                       }
+               isMSO := ds.MultiSiteOrigin != nil && *ds.MultiSiteOrigin
 
-                                       pasvc.DestDomain = orgURI.Hostname()
-                                       pasvc.Port, err = 
strconv.Atoi(orgURI.Port())
-                                       if err != nil {
-                                               if 
strings.ToLower(orgURI.Scheme) == "https" {
-                                                       pasvc.Port = 443
-                                               } else {
-                                                       pasvc.Port = 80
-                                               }
-                                               warnings = append(warnings, "DS 
'"+*ds.XMLID+"' had malformed origin  port: '"+orgURI.Port()+"': using 
"+strconv.Itoa(pasvc.Port)+"! : "+err.Error())
-                                       }
-                                       pasvc.Parents = parents
-                                       pasvc.SecondaryParents = 
secondaryParents
-                                       pasvc.SecondaryMode = secondaryMode
-                                       pasvc.RetryPolicy = roundRobin
-                                       pasvc.GoDirect = goDirect
-                                       
pasvc.IgnoreQueryStringInParentSelection = !*parentQStr
-                                       // text += `dest_domain=` + 
orgURI.Hostname() + ` port=` + orgURI.Port() + ` ` + parents + ` ` + 
secondaryParents + ` ` + roundRobin + ` ` + goDirect + ` qstring=` + parentQStr 
+ "\n"
-                               }
+               // TODO put these in separate functions. No if-statement should 
be this long.
+               if ds.Topology == nil || *ds.Topology == "" {

Review Comment:
   Removed as it does seem like checks would call continue before this code 
would be hit.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to