Example #1
0
func (z *Zk) getMasters() error {
	zkPath := fmt.Sprintf("%s/masters", z.c.Zk.BaseDir)

	exists, _, err := z.conn.Exists(zkPath)
	if err != nil {
		return err
	} else if !exists {
		if _, err = z.conn.Create(zkPath, nil, 0, zkhelper.DefaultFileACLs()); err != nil {
			return err
		}
	}

	data, _, err := z.conn.Get(zkPath)
	if err != nil {
		return err
	}

	if len(data) > 0 {
		var masters []string
		if err = json.Unmarshal(data, &masters); err != nil {
			return err
		}

		z.fsm.SetMasters(masters)
	}
	return nil
}
Example #2
0
func (t *Topo) CreateAgent(nodeAddr string) (string, error) {
	zkhelper.CreateRecursive(t.conn, t.GetAgentBasePath(), "", 0, zkhelper.DefaultDirACLs())

	return t.conn.Create(path.Join(t.GetAgentBasePath(), nodeAddr), nil, zk.FlagEphemeral, zkhelper.DefaultFileACLs())
}