lib, pgraph, resources: Refactor data association API
This should make things cleaner and help avoid as much churn every time we change a property.
This commit is contained in:
@@ -440,6 +440,7 @@ func (obj *Main) Run() error {
|
|||||||
newGraph.Flags = pgraph.Flags{Debug: obj.Flags.Debug}
|
newGraph.Flags = pgraph.Flags{Debug: obj.Flags.Debug}
|
||||||
// pass in the information we need
|
// pass in the information we need
|
||||||
newGraph.AssociateData(&resources.Data{
|
newGraph.AssociateData(&resources.Data{
|
||||||
|
Hostname: hostname,
|
||||||
Converger: converger,
|
Converger: converger,
|
||||||
Prometheus: prom,
|
Prometheus: prom,
|
||||||
Prefix: pgraphPrefix,
|
Prefix: pgraphPrefix,
|
||||||
|
|||||||
@@ -658,7 +658,7 @@ func (g *Graph) AssociateData(data *resources.Data) {
|
|||||||
g.prometheus = data.Prometheus
|
g.prometheus = data.Prometheus
|
||||||
|
|
||||||
for k := range g.Adjacency {
|
for k := range g.Adjacency {
|
||||||
k.Res.AssociateData(data)
|
*k.Res.Data() = *data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const refreshPathToken = "refresh"
|
|||||||
|
|
||||||
// Data is the set of input values passed into the pgraph for the resources.
|
// Data is the set of input values passed into the pgraph for the resources.
|
||||||
type Data struct {
|
type Data struct {
|
||||||
//Hostname string // uuid for the host
|
Hostname string // uuid for the host
|
||||||
//Noop bool
|
//Noop bool
|
||||||
Converger converger.Converger
|
Converger converger.Converger
|
||||||
Prometheus *prometheus.Prometheus
|
Prometheus *prometheus.Prometheus
|
||||||
@@ -142,7 +142,7 @@ type Base interface {
|
|||||||
Kind() string
|
Kind() string
|
||||||
Meta() *MetaParams
|
Meta() *MetaParams
|
||||||
Events() chan *event.Event
|
Events() chan *event.Event
|
||||||
AssociateData(*Data)
|
Data() *Data
|
||||||
IsWorking() bool
|
IsWorking() bool
|
||||||
WaitGroup() *sync.WaitGroup
|
WaitGroup() *sync.WaitGroup
|
||||||
Setup()
|
Setup()
|
||||||
@@ -200,6 +200,7 @@ type BaseRes struct {
|
|||||||
Recv map[string]*Send // mapping of key to receive on from value
|
Recv map[string]*Send // mapping of key to receive on from value
|
||||||
|
|
||||||
kind string
|
kind string
|
||||||
|
data Data
|
||||||
state ResState
|
state ResState
|
||||||
prefix string // base prefix for this resource
|
prefix string // base prefix for this resource
|
||||||
|
|
||||||
@@ -318,9 +319,9 @@ func (obj *BaseRes) Init() error {
|
|||||||
return fmt.Errorf("resource did not set kind")
|
return fmt.Errorf("resource did not set kind")
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.cuid = obj.converger.Register()
|
obj.cuid = obj.Converger().Register()
|
||||||
obj.wcuid = obj.converger.Register() // get a cuid for the worker!
|
obj.wcuid = obj.Converger().Register() // get a cuid for the worker!
|
||||||
obj.pcuid = obj.converger.Register() // get a cuid for the process
|
obj.pcuid = obj.Converger().Register() // get a cuid for the process
|
||||||
|
|
||||||
obj.eventsLock = &sync.Mutex{}
|
obj.eventsLock = &sync.Mutex{}
|
||||||
obj.eventsDone = false
|
obj.eventsDone = false
|
||||||
@@ -400,12 +401,9 @@ func (obj *BaseRes) Events() chan *event.Event {
|
|||||||
return obj.eventsChan
|
return obj.eventsChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssociateData associates some data with the object in question.
|
// Data returns an associable handle to some data passed in to the resource.
|
||||||
func (obj *BaseRes) AssociateData(data *Data) {
|
func (obj *BaseRes) Data() *Data {
|
||||||
obj.converger = data.Converger
|
return &obj.data
|
||||||
obj.prometheus = data.Prometheus
|
|
||||||
obj.prefix = data.Prefix
|
|
||||||
obj.debug = data.Debug
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsWorking tells us if the Worker() function is running. Not thread safe.
|
// IsWorking tells us if the Worker() function is running. Not thread safe.
|
||||||
@@ -434,7 +432,7 @@ func (obj *BaseRes) Reset() {
|
|||||||
// Converger returns the converger object used by the system. It can be used to
|
// Converger returns the converger object used by the system. It can be used to
|
||||||
// register new convergers if needed.
|
// register new convergers if needed.
|
||||||
func (obj *BaseRes) Converger() converger.Converger {
|
func (obj *BaseRes) Converger() converger.Converger {
|
||||||
return obj.converger
|
return obj.data.Converger
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvergerUIDs returns the ConvergerUIDs for the resource. This is called by
|
// ConvergerUIDs returns the ConvergerUIDs for the resource. This is called by
|
||||||
|
|||||||
Reference in New Issue
Block a user