pgraph: Move AssociateData function out of the package
This removes another dependency on the resource package.
This commit is contained in:
12
lib/main.go
12
lib/main.go
@@ -444,7 +444,7 @@ func (obj *Main) Run() error {
|
|||||||
}
|
}
|
||||||
newGraph.SetValue("debug", obj.Flags.Debug)
|
newGraph.SetValue("debug", obj.Flags.Debug)
|
||||||
// pass in the information we need
|
// pass in the information we need
|
||||||
newGraph.AssociateData(&resources.Data{
|
associateData(newGraph, &resources.Data{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
Converger: converger,
|
Converger: converger,
|
||||||
Prometheus: prom,
|
Prometheus: prom,
|
||||||
@@ -625,3 +625,13 @@ func graphMetas(g *pgraph.Graph) []*resources.MetaParams {
|
|||||||
}
|
}
|
||||||
return metas
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/event"
|
"github.com/purpleidea/mgmt/event"
|
||||||
"github.com/purpleidea/mgmt/prometheus"
|
|
||||||
"github.com/purpleidea/mgmt/resources"
|
"github.com/purpleidea/mgmt/resources"
|
||||||
|
|
||||||
errwrap "github.com/pkg/errors"
|
errwrap "github.com/pkg/errors"
|
||||||
@@ -58,8 +57,6 @@ type Graph struct {
|
|||||||
fastPause bool // used to disable pokes for a fast pause
|
fastPause bool // used to disable pokes for a fast pause
|
||||||
mutex *sync.Mutex // used when modifying graph State variable
|
mutex *sync.Mutex // used when modifying graph State variable
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
|
|
||||||
prometheus *prometheus.Prometheus // the prometheus instance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertex is the primary vertex struct in this library.
|
// Vertex is the primary vertex struct in this library.
|
||||||
@@ -151,8 +148,6 @@ func (g *Graph) Copy() *Graph {
|
|||||||
mutex: g.mutex,
|
mutex: g.mutex,
|
||||||
wg: g.wg,
|
wg: g.wg,
|
||||||
fastPause: g.fastPause,
|
fastPause: g.fastPause,
|
||||||
|
|
||||||
prometheus: g.prometheus,
|
|
||||||
}
|
}
|
||||||
for k, v := range g.adjacency {
|
for k, v := range g.adjacency {
|
||||||
newGraph.adjacency[k] = v // copy
|
newGraph.adjacency[k] = v // copy
|
||||||
@@ -687,16 +682,6 @@ func (g *Graph) GraphSync(oldGraph *Graph) (*Graph, error) {
|
|||||||
return oldGraph, nil
|
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.
|
// VertexContains is an "in array" function to test for a vertex in a slice of vertices.
|
||||||
func VertexContains(needle *Vertex, haystack []*Vertex) bool {
|
func VertexContains(needle *Vertex, haystack []*Vertex) bool {
|
||||||
for _, v := range haystack {
|
for _, v := range haystack {
|
||||||
|
|||||||
Reference in New Issue
Block a user