// WatchVolumeRuntimes watches the runtime portions of the volume and yields // back any information received through the activity channel. func (c *Client) WatchVolumeRuntimes(activity chan *watch.Watch) { w := watch.NewWatcher(activity, c.prefixed(rootVolume), func(resp *client.Response, w *watch.Watcher) { vw := &watch.Watch{Key: strings.TrimPrefix(resp.Node.Key, c.prefixed(rootVolume)+"/")} if !resp.Node.Dir && path.Base(resp.Node.Key) == "runtime" { logrus.Debugf("Handling watch event %q for volume %q", resp.Action, vw.Key) if resp.Action != "delete" { if resp.Node.Value != "" { volName := strings.TrimPrefix(path.Dir(vw.Key), c.prefixed(rootVolume)+"/") policy, vol := path.Split(volName) vw.Key = volName volume, err := c.GetVolume(policy, vol) if err != nil { logrus.Errorf("Could not retrieve volume %q after watch notification: %v", volName, err) return } vw.Config = volume } } w.Channel <- vw } }) watch.Create(w) }
// WatchSnapshotSignal watches for a signal to be provided to // /volplugin/snapshots via writing an empty file to the policy/volume name. func (c *Client) WatchSnapshotSignal(activity chan *watch.Watch) { w := watch.NewWatcher(activity, c.prefixed(rootSnapshots), func(resp *client.Response, w *watch.Watcher) { if !resp.Node.Dir && resp.Action != "delete" { vw := &watch.Watch{Key: strings.Replace(resp.Node.Key, c.prefixed(rootSnapshots)+"/", "", -1), Config: nil} w.Channel <- vw } }) watch.Create(w) }
// WatchGlobal watches a global and updates it as soon as the config changes. func (tlc *Client) WatchGlobal(activity chan *watch.Watch) { w := watch.NewWatcher(activity, tlc.prefixed("global-config"), func(resp *client.Response, w *watch.Watcher) { global := &Global{} if resp.Action == "delete" { global = NewGlobalConfig() } else { if err := json.Unmarshal([]byte(resp.Node.Value), global); err != nil { logrus.Error("Error decoding global config, not updating") time.Sleep(time.Second) return } } w.Channel <- &watch.Watch{Key: resp.Node.Key, Config: global} }) watch.Create(w) }
// WatchForPolicyChanges creates a watch which returns the policy name and revision // whenever a new policy is uploaded. func (c *Client) WatchForPolicyChanges(activity chan *watch.Watch) { keyspace := c.prefixed(rootPolicyArchive) w := watch.NewWatcher(activity, keyspace, func(resp *client.Response, w *watch.Watcher) { // skip anything not happening _below_ our watch. // we don't care about updates happening to the root of our watch here. if !strings.HasPrefix(resp.Node.Key, keyspace+"/") { return } s := strings.TrimPrefix(resp.Node.Key, keyspace+"/") name, revision := path.Split(s) name = name[:len(name)-1] // remove trailing slash w.Channel <- &watch.Watch{Key: resp.Node.Key, Config: []string{name, revision}} }) watch.Create(w) }