示例#1
0
func dial(addr string) *doozer.Conn {
	c, err := doozer.Dial(addr)
	if err != nil {
		panic(err)
	}
	return c
}
示例#2
0
// IsCal checks if addr is a CAL in the cluster named name.
// Returns a client if so, nil if not.
func isCal(name, addr string) (*doozer.Conn, error) {
	c, err := doozer.Dial(addr)
	if err != nil {
		return nil, err
	}

	err = c.Access(rwsk)
	if err != nil {
		return nil, err
	}

	v, _, _ := c.Get("/ctl/name", nil)
	if string(v) != name {
		return nil, nil
	}

	rev, err := c.Rev()
	if err != nil {
		return nil, err
	}

	var cals []string
	names, err := c.Getdir("/ctl/cal", rev, 0, -1)
	if err != nil {
		return nil, err
	}
	for _, name := range names {
		cals = append(cals, name)
	}

	for _, cal := range cals {
		body, _, err := c.Get("/ctl/cal/"+cal, nil)
		if err != nil || len(body) == 0 {
			continue
		}

		id := string(body)

		v, _, err := c.Get("/ctl/node/"+id+"/addr", nil)
		if err != nil {
			return nil, err
		}
		if string(v) == addr {
			return c, nil
		}
	}

	return nil, nil
}