Exemple #1
0
func dial(addr string) *doozer.Conn {
	c, err := doozer.Dial(addr)
	if err != nil {
		panic(err)
	}
	return c
}
Exemple #2
0
func Dial(addr string) *Conn {
	dzr, err := doozer.Dial(addr)
	if err != nil {
		log.Fatal("failed to connect to %s: %s", addr, err)
	}
	return &Conn{Conn: *dzr, Address: addr}
}
// Dial calls doozer.Dial and returns a Snapshot of the coordinator
// at the latest revision.
func Dial(addr string, root string) (s Snapshot, err error) {
	dconn, err := doozer.Dial(addr)
	if err != nil {
		return
	}

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

	s = Snapshot{rev, &conn{addr, root, dconn}}
	return
}
Exemple #4
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
}