pgraph: Move AssociateData function out of the package

This removes another dependency on the resource package.
This commit is contained in:
James Shubin
2017-05-15 10:06:52 -04:00
parent c2cb1c9168
commit 1c59712cbf
2 changed files with 11 additions and 16 deletions

View File

@@ -444,7 +444,7 @@ func (obj *Main) Run() error {
}
newGraph.SetValue("debug", obj.Flags.Debug)
// pass in the information we need
newGraph.AssociateData(&resources.Data{
associateData(newGraph, &resources.Data{
Hostname: hostname,
Converger: converger,
Prometheus: prom,
@@ -625,3 +625,13 @@ func graphMetas(g *pgraph.Graph) []*resources.MetaParams {
}
return metas
}
// associateData associates some data with the object in the graph in question.
func associateData(g *pgraph.Graph, data *resources.Data) {
// prometheus needs to be associated to this graph as well
g.SetValue("prometheus", data.Prometheus)
for _, v := range g.Vertices() {
*v.Res.Data() = *data
}
}

View File

@@ -24,7 +24,6 @@ import (
"sync"
"github.com/purpleidea/mgmt/event"
"github.com/purpleidea/mgmt/prometheus"
"github.com/purpleidea/mgmt/resources"
errwrap "github.com/pkg/errors"
@@ -58,8 +57,6 @@ type Graph struct {
fastPause bool // used to disable pokes for a fast pause
mutex *sync.Mutex // used when modifying graph State variable
wg *sync.WaitGroup
prometheus *prometheus.Prometheus // the prometheus instance
}
// Vertex is the primary vertex struct in this library.
@@ -151,8 +148,6 @@ func (g *Graph) Copy() *Graph {
mutex: g.mutex,
wg: g.wg,
fastPause: g.fastPause,
prometheus: g.prometheus,
}
for k, v := range g.adjacency {
newGraph.adjacency[k] = v // copy
@@ -687,16 +682,6 @@ func (g *Graph) GraphSync(oldGraph *Graph) (*Graph, error) {
return oldGraph, nil
}
// AssociateData associates some data with the object in the graph in question.
func (g *Graph) AssociateData(data *resources.Data) {
// prometheus needs to be associated to this graph as well
g.prometheus = data.Prometheus
for k := range g.adjacency {
*k.Res.Data() = *data
}
}
// VertexContains is an "in array" function to test for a vertex in a slice of vertices.
func VertexContains(needle *Vertex, haystack []*Vertex) bool {
for _, v := range haystack {