pgraph: Move the AutoEdges mechanism into the resource package
Remove the pgraph->resource dependency.
This commit is contained in:
@@ -483,8 +483,8 @@ func (obj *Main) Run() error {
|
|||||||
oldGraph = newFullGraph // save old graph
|
oldGraph = newFullGraph // save old graph
|
||||||
G = oldGraph.Copy() // copy to active graph
|
G = oldGraph.Copy() // copy to active graph
|
||||||
|
|
||||||
G.AutoEdges() // add autoedges; modifies the graph
|
resources.AutoEdges(G) // add autoedges; modifies the graph
|
||||||
G.AutoGroup() // run autogroup; modifies the graph
|
G.AutoGroup() // run autogroup; modifies the graph
|
||||||
// TODO: do we want to do a transitive reduction?
|
// TODO: do we want to do a transitive reduction?
|
||||||
// FIXME: run a type checker that verifies all the send->recv relationships
|
// FIXME: run a type checker that verifies all the send->recv relationships
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,29 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package pgraph represents the internal "pointer graph" that we use.
|
package resources
|
||||||
package pgraph
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/resources"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
"github.com/purpleidea/mgmt/util"
|
"github.com/purpleidea/mgmt/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// add edges to the vertex in a graph based on if it matches a uid list
|
// UIDExistsInUIDs wraps the IFF method when used with a list of UID's.
|
||||||
func (g *Graph) addEdgesByMatchingUIDS(v *Vertex, uids []resources.ResUID) []bool {
|
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!
|
// search for edges and see what matches!
|
||||||
var result []bool
|
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
|
// that is to say, the name value of a res is a helpful
|
||||||
// handle, but it is not necessarily a unique identity!
|
// handle, but it is not necessarily a unique identity!
|
||||||
// remember, resources can return multiple UID's each!
|
// remember, resources can return multiple UID's each!
|
||||||
if resources.UIDExistsInUIDs(uid, vv.UIDs()) {
|
if UIDExistsInUIDs(uid, vv.UIDs()) {
|
||||||
// add edge from: vv -> v
|
// add edge from: vv -> v
|
||||||
if uid.IsReversed() {
|
if uid.IsReversed() {
|
||||||
txt := fmt.Sprintf("AutoEdge: %s[%s] -> %s[%s]", vv.GetKind(), vv.GetName(), v.GetKind(), v.GetName())
|
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.
|
// AutoEdges adds the automatic edges to the graph.
|
||||||
func (g *Graph) AutoEdges() {
|
func AutoEdges(g *pgraph.Graph) {
|
||||||
log.Println("Compile: Adding AutoEdges...")
|
log.Println("Compile: Adding AutoEdges...")
|
||||||
for _, v := range g.Vertices() { // for each vertexes autoedges
|
for _, v := range g.Vertices() { // for each vertexes autoedges
|
||||||
if !v.Meta().AutoEdge { // is the metaparam true?
|
if !v.Meta().AutoEdge { // is the metaparam true?
|
||||||
@@ -93,7 +103,7 @@ func (g *Graph) AutoEdges() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match and add edges
|
// match and add edges
|
||||||
result := g.addEdgesByMatchingUIDS(v, uids)
|
result := addEdgesByMatchingUIDS(g, v, uids)
|
||||||
|
|
||||||
// report back, and find out if we should continue
|
// report back, and find out if we should continue
|
||||||
if !autoEdgeObj.Test(result) {
|
if !autoEdgeObj.Test(result) {
|
||||||
@@ -299,16 +299,6 @@ type BaseRes struct {
|
|||||||
// return nil
|
// 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.
|
// GetName returns the name of the resource.
|
||||||
func (obj *BaseUID) GetName() string {
|
func (obj *BaseUID) GetName() string {
|
||||||
return obj.Name
|
return obj.Name
|
||||||
|
|||||||
Reference in New Issue
Block a user