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



##########
File path: lib/go-atscfg/atscfg.go
##########
@@ -139,24 +140,109 @@ func GetConfigFile(prefix string, xmlId string) string {
 
 // topologyIncludesServer returns whether the given topology includes the 
given server
 func topologyIncludesServer(topology tc.Topology, server tc.Server) bool {
-       _, inTopology := serverTopologyTier(server, topology)
-       return inTopology
+       for _, node := range topology.Nodes {
+               if node.Cachegroup == server.Cachegroup {
+                       return true
+               }
+       }
+       return false
 }
 
-// serverTopologyTier returns whether the server is the last tier in the 
topology, and whether the server is in the topology at all.
-func serverTopologyTier(server tc.Server, topology tc.Topology) (bool, bool) {
+// TopologyCacheTier is the position of a cache in the topology.
+// Note this is the cache tier itself, notwithstanding MSO. So for an MSO 
service,
+// Caches immediately before the origin are the TopologyCacheTierLast, even 
for MSO.
+type TopologyCacheTier string
+
+const (
+       TopologyCacheTierFirst   = TopologyCacheTier("first")
+       TopologyCacheTierInner   = TopologyCacheTier("inner")
+       TopologyCacheTierLast    = TopologyCacheTier("last")
+       TopologyCacheTierInvalid = TopologyCacheTier("")
+)
+
+// TopologyPlacement contains data about the placement of a server in a 
topology.
+type TopologyPlacement struct {
+       // InTopology is whether the server is in the topology at all.
+       InTopology bool
+       // IsLastTier is whether the server is the last tier in the topology.
+       // Note this is different for MSO vs non-MSO. For MSO, the last tier is 
the Origin. For non-MSO, the last tier is the last cache tier.
+       IsLastTier bool
+       // CacheTier is the position of the cache in the topology.
+       // Note this is whether the cache is the last cache, even if it has 
parents in the topology who are origins (MSO).
+       // Thus, it's possible for a server to be CacheTierLast and not 
IsLastTier.
+       CacheTier TopologyCacheTier
+}
+
+// getTopologyPlacement returns information about the cachegroup's placement 
in the topology.
+// - Whether the cachegroup is the last tier in the topology.
+// - Whether the cachegroup is in the topology at all.
+// - Whether it's the first, inner, or last cache tier before the Origin.
+func getTopologyPlacement(cacheGroup tc.CacheGroupName, topology tc.Topology, 
cacheGroups map[tc.CacheGroupName]tc.CacheGroupNullable) TopologyPlacement {
        serverNode := tc.TopologyNode{}
-       for _, node := range topology.Nodes {
-               if node.Cachegroup == server.Cachegroup {
+       serverNodeIndex := -1
+       for nodeI, node := range topology.Nodes {
+               if node.Cachegroup == string(cacheGroup) {
                        serverNode = node
+                       serverNodeIndex = nodeI
                        break
                }
        }
        if serverNode.Cachegroup == "" {
-               return false, false
+               return TopologyPlacement{InTopology: false}
        }
 
-       return len(serverNode.Parents) == 0, true
+       topologyHasChildren := false
+       for _, node := range topology.Nodes {
+               for _, parent := range node.Parents {
+                       if parent == serverNodeIndex {
+                               topologyHasChildren = true
+                               break
+                       }
+               }
+       }

Review comment:
       Done




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