gapi: Move separate etcd Watch method into GAPI

This cleans up the API to not have a special case for etcd anymore. In
particular, this also adds the requirement that the GAPI must generate
an event on startup as soon as it is ready to generate a graph.
This commit is contained in:
James Shubin
2017-03-20 15:10:27 -04:00
parent 66d9c7091c
commit 6fd5623b1f
6 changed files with 62 additions and 40 deletions

View File

@@ -2096,11 +2096,12 @@ func Leader(obj *EmbdEtcd) (string, error) {
return "", fmt.Errorf("members map is not current") // not found
}
// WatchAll returns a channel that outputs a true bool when activity occurs
// WatchResources returns a channel that outputs events when exported resources
// change.
// TODO: Filter our watch (on the server side if possible) based on the
// collection prefixes and filters that we care about...
func WatchAll(obj *EmbdEtcd) chan bool {
ch := make(chan bool, 1) // buffer it so we can measure it
func WatchResources(obj *EmbdEtcd) chan error {
ch := make(chan error, 1) // buffer it so we can measure it
path := fmt.Sprintf("/%s/exported/", NS)
callback := func(re *RE) error {
// TODO: is this even needed? it used to happen on conn errors
@@ -2118,7 +2119,7 @@ func WatchAll(obj *EmbdEtcd) chan bool {
// this check avoids multiple events all queueing up and then
// being released continuously long after the changes stopped
// do not block!
ch <- true // event
ch <- nil // event
}
return nil
}

View File

@@ -27,6 +27,12 @@ type World struct {
EmbdEtcd *EmbdEtcd
}
// ResWatch returns a channel which spits out events on possible exported
// resource changes.
func (obj *World) ResWatch() chan error {
return WatchResources(obj.EmbdEtcd)
}
// ResExport exports a list of resources under our hostname namespace.
// Subsequent calls replace the previously set collection atomically.
func (obj *World) ResExport(resourceList []resources.Res) error {