You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/06/15 13:54:38 UTC

[GitHub] [trafficcontrol] zrhoffman commented on a change in pull request #4786: Permit edge -> edge topology node parentage

zrhoffman commented on a change in pull request #4786:
URL: https://github.com/apache/trafficcontrol/pull/4786#discussion_r440192559



##########
File path: traffic_ops/traffic_ops_golang/topology/validation.go
##########
@@ -53,17 +53,41 @@ func checkForSelfParents(nodes []tc.TopologyNode, index int) error {
 	return nil
 }
 
-func checkForEdgeParents(nodes []tc.TopologyNode, cachegroups []tc.CacheGroupNullable, nodeIndex int) error {
-	node := nodes[nodeIndex]
+// checkForEdgeParents returns an error if an index given in the parents array, adds a warning + returns a nil error if
+// an edge parents an edge, and returns an error if an edge parents a non-edge cachegroup.
+func (topology *TOTopology) checkForEdgeParents(cacheGroups []tc.CacheGroupNullable, nodeIndex int) error {
+	node := topology.Nodes[nodeIndex]
 	errs := make([]error, len(node.Parents))
-	for parentIndex, cachegroupIndex := range node.Parents {
-		if cachegroupIndex < 0 || cachegroupIndex >= len(cachegroups) {
-			errs = append(errs, fmt.Errorf("parent %d of cachegroup %s refers to a cachegroup at index %d, but no such cachegroup exists", parentIndex, node.Cachegroup, cachegroupIndex))
+	for parentIndex, parentCacheGroupIndex := range node.Parents {
+		if parentCacheGroupIndex < 0 || parentCacheGroupIndex >= len(topology.Nodes) {
+			errs = append(errs, fmt.Errorf("parent %d of cachegroup %s refers to a cachegroup at index %d, but no such cachegroup exists", parentIndex, node.Cachegroup, parentCacheGroupIndex))
 			break
 		}
-		cacheGroupType := cachegroups[cachegroupIndex].Type
-		if *cacheGroupType == tc.CacheGroupEdgeTypeName {
-			errs = append(errs, fmt.Errorf("cachegroup %v's type is %v; it cannot be a parent of %v", nodes[cachegroupIndex].Cachegroup, tc.CacheGroupEdgeTypeName, node.Cachegroup))
+		parentCacheGroupType := *cacheGroups[parentCacheGroupIndex].Type
+		if parentCacheGroupType != tc.CacheGroupEdgeTypeName {
+			continue
+		}
+		switch cacheGroupType := *cacheGroups[nodeIndex].Type; cacheGroupType {
+		case tc.CacheGroupEdgeTypeName:
+			parentTerm := "parent"
+			if parentIndex == 1 {
+				parentTerm = "secondary " + parentTerm
+			}
+			topology.Alerts.AddNewAlert(tc.WarnLevel, fmt.Sprintf(
+				"%s-typed cachegroup %s is a %s of %s, unexpected behavior may result",
+				parentCacheGroupType,
+				topology.Nodes[parentCacheGroupIndex].Cachegroup,
+				parentTerm,
+				node.Cachegroup))
+			break

Review comment:
       Removed break in a70986165




----------------------------------------------------------------
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:
users@infra.apache.org