Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cope with one->many topology mappings #2996

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func (cr conditionalRenderer) Render(rpt report.Report) Nodes {
// joinResults is used by Renderers that join sets of nodes
type joinResults struct {
nodes report.Nodes
mapped map[string]string // input node ID -> output node ID
mapped map[string]string // input node ID -> output node ID - common case
multi map[string][]string // input node ID -> output node IDs - exceptional case
}

func newJoinResults(inputNodes report.Nodes) joinResults {
Expand All @@ -172,12 +173,16 @@ func newJoinResults(inputNodes report.Nodes) joinResults {
n.Adjacency = nil // result() assumes all nodes start with no adjacencies
nodes[id] = n
}
return joinResults{nodes: nodes, mapped: map[string]string{}}
return joinResults{nodes: nodes, mapped: map[string]string{}, multi: map[string][]string{}}
}

func (ret *joinResults) add(m report.Node, n report.Node) {
ret.nodes[n.ID] = n
ret.mapped[m.ID] = n.ID
if _, ok := ret.mapped[m.ID]; !ok {
ret.mapped[m.ID] = n.ID
} else {
ret.multi[m.ID] = append(ret.multi[m.ID], n.ID)
}
}

// Add m as a child of the node at id, creating a new result node if
Expand Down Expand Up @@ -222,19 +227,27 @@ func (ret *joinResults) result(input Nodes) Nodes {
if !ok {
continue
}
out := ret.nodes[outID]
// for each adjacency in the original node, find out what it maps to (if any),
// and add that to the new node
for _, a := range n.Adjacency {
if mappedDest, found := ret.mapped[a]; found {
out.Adjacency = out.Adjacency.Add(mappedDest)
}
ret.rewriteAdjacency(outID, n.Adjacency)
for _, outID := range ret.multi[n.ID] {
ret.rewriteAdjacency(outID, n.Adjacency)
}
ret.nodes[outID] = out
}
return Nodes{Nodes: ret.nodes}
}

func (ret *joinResults) rewriteAdjacency(outID string, adjacency report.IDList) {
out := ret.nodes[outID]
// for each adjacency in the original node, find out what it maps
// to (if any), and add that to the new node
for _, a := range adjacency {
if mappedDest, found := ret.mapped[a]; found {
out.Adjacency = out.Adjacency.Add(mappedDest)
out.Adjacency = out.Adjacency.Add(ret.multi[a]...)

This comment was marked as abuse.

This comment was marked as abuse.

}
}
ret.nodes[outID] = out
}

// ResetCache blows away the rendered node cache, and known service
// cache.
func ResetCache() {
Expand Down