5
"launchpad.net/gozk/zookeeper"
6
"launchpad.net/juju-core/trivial"
12
// stateChanged is a common error inside the state processing.
13
stateChanged = errors.New("environment state has changed")
14
// zkPermAll is a convenience variable for creating new nodes.
15
zkPermAll = zookeeper.WorldACL(zookeeper.PERM_ALL)
18
// zkRemoveTree recursively removes a zookeeper node and all its
19
// children. It does not delete "/zookeeper" or the root node itself
20
// and it does not consider deleting a nonexistent node to be an error.
21
func zkRemoveTree(zk *zookeeper.Conn, path string) (err error) {
22
defer trivial.ErrorContextf(&err, "cannot clean up data")
23
// If we try to delete the zookeeper node (for example when
24
// calling ZkRemoveTree(zk, "/")) we silently ignore it.
25
if path == "/zookeeper" {
28
// First recursively delete the children.
29
children, _, err := zk.Children(path)
31
if zookeeper.IsError(err, zookeeper.ZNONODE) {
36
for _, child := range children {
37
if err = zkRemoveTree(zk, pathpkg.Join(path, child)); err != nil {
41
// Now delete the path itself unless it's the root node.
45
err = zk.Delete(path, -1)
46
if err != nil && !zookeeper.IsError(err, zookeeper.ZNONODE) {
52
// diff returns all the elements that exist in A but not B.
53
func diff(A, B []string) (missing []string) {
61
missing = append(missing, a)
68
func (p portSlice) Len() int { return len(p) }
69
func (p portSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
70
func (p portSlice) Less(i, j int) bool {
73
if p1.Protocol != p2.Protocol {
74
return p1.Protocol < p2.Protocol
76
return p1.Number < p2.Number
79
// SortPorts sorts the given ports, first by protocol,
81
func SortPorts(ports []Port) {
82
sort.Sort(portSlice(ports))