From 11c3a26c23659b3a9bfa8b6c10dcc14f83638f0c Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 15 May 2017 11:37:20 -0400 Subject: [PATCH] pgraph: Move the AutoEdges mechanism into the resource package Remove the pgraph->resource dependency. --- lib/main.go | 4 ++-- {pgraph => resources}/autoedge.go | 26 ++++++++++++++++++-------- resources/resources.go | 10 ---------- 3 files changed, 20 insertions(+), 20 deletions(-) rename {pgraph => resources}/autoedge.go (84%) diff --git a/lib/main.go b/lib/main.go index a41d8e2a..9e79923e 100644 --- a/lib/main.go +++ b/lib/main.go @@ -483,8 +483,8 @@ func (obj *Main) Run() error { oldGraph = newFullGraph // save old graph G = oldGraph.Copy() // copy to active graph - G.AutoEdges() // add autoedges; modifies the graph - G.AutoGroup() // run autogroup; modifies the graph + resources.AutoEdges(G) // add autoedges; modifies the graph + G.AutoGroup() // run autogroup; modifies the graph // TODO: do we want to do a transitive reduction? // FIXME: run a type checker that verifies all the send->recv relationships diff --git a/pgraph/autoedge.go b/resources/autoedge.go similarity index 84% rename from pgraph/autoedge.go rename to resources/autoedge.go index acdea1ca..ba1815f2 100644 --- a/pgraph/autoedge.go +++ b/resources/autoedge.go @@ -15,19 +15,29 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -// Package pgraph represents the internal "pointer graph" that we use. -package pgraph +package resources import ( "fmt" "log" - "github.com/purpleidea/mgmt/resources" + "github.com/purpleidea/mgmt/pgraph" "github.com/purpleidea/mgmt/util" ) -// add edges to the vertex in a graph based on if it matches a uid list -func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []bool { +// UIDExistsInUIDs wraps the IFF method when used with a list of UID's. +func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool { + for _, u := range uids { + if uid.IFF(u) { + return true + } + } + return false +} + +// addEdgesByMatchingUIDS adds edges to the vertex in a graph based on if it +// matches a uid list. +func addEdgesByMatchingUIDS(g *pgraph.Graph, v *pgraph.Vertex, uids []ResUID) []bool { // search for edges and see what matches! var result []bool @@ -46,7 +56,7 @@ func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []boo // that is to say, the name value of a res is a helpful // handle, but it is not necessarily a unique identity! // remember, resources can return multiple UID's each! - if resources.UIDExistsInUIDs(uid, vv.UIDs()) { + if UIDExistsInUIDs(uid, vv.UIDs()) { // add edge from: vv -> v if uid.IsReversed() { txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", vv.GetKind(), vv.GetName(), v.GetKind(), v.GetName()) @@ -67,7 +77,7 @@ func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []boo } // AutoEdges adds the automatic edges to the graph. -func (g *Graph) AutoEdges() { +func AutoEdges(g *pgraph.Graph) { log.Println("Compile: Adding AutoEdges...") for _, v := range g.Vertices() { // for each vertexes autoedges if !v.Meta().AutoEdge { // is the metaparam true? @@ -93,7 +103,7 @@ func (g *Graph) AutoEdges() { } // match and add edges - result := g.addEdgesByMatchingUIDS(v, uids) + result := addEdgesByMatchingUIDS(g, v, uids) // report back, and find out if we should continue if !autoEdgeObj.Test(result) { diff --git a/resources/resources.go b/resources/resources.go index 60797d50..feaa4325 100644 --- a/resources/resources.go +++ b/resources/resources.go @@ -299,16 +299,6 @@ type BaseRes struct { // return nil //} -// UIDExistsInUIDs wraps the IFF method when used with a list of UID's. -func UIDExistsInUIDs(uid ResUID, uids []ResUID) bool { - for _, u := range uids { - if uid.IFF(u) { - return true - } - } - return false -} - // GetName returns the name of the resource. func (obj *BaseUID) GetName() string { return obj.Name