Пример #1
0
func loadToZK(conn *zk.Conn, data [][2]string) {
	for _, entry := range data {
		k := entry[0]
		v := entry[1]
		_, err := conn.Create(k, []byte(v), 0, defaultACL())
		orPanic(err)
	}
}
Пример #2
0
/*
   Read ZK ACL:
   http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html#sc_ACLPermissions
*/
func Create(conn *zk.Conn, zkConf conf.Zookeeper, appId string, domainValue string) (string, error) {
	path := concatPath(zkConf.Path, validateAppId(appId))
	resPath, err := conn.Create(path, []byte(domainValue), 0, defaultACL())
	if err != nil {
		return "", err
	}

	return resPath, nil
}
Пример #3
0
func ensurePathExists(conn *zk.Conn, path string) error {
	pathExists, _, _ := conn.Exists(path)
	if pathExists {
		return nil
	}

	_, err := conn.Create(path, []byte{}, 0, defaultACL())
	if err != nil {
		return err
	}

	return nil
}
Пример #4
0
func zkCreateNodes(path string, nodes []string, c *zk.Conn) error {
	if len(nodes) > 0 {
		// strings.Split will return empty-strings for leading split chars, lets skip over these.
		if len(nodes[0]) == 0 {
			return zkCreateNodes(path, nodes[1:], c)
		}
		fqPath := path + "/" + nodes[0]
		log.Printf("Creating path: %v", fqPath)
		exists, _, err := c.Exists(fqPath)
		if err != nil {
			return err
		}
		if !exists {
			_, err := c.Create(fqPath, []byte{}, 0, zk.WorldACL(zk.PermAll))
			if err != nil {
				return err
			}
		}
		return zkCreateNodes(fqPath, nodes[1:], c)
	}
	return nil
}