当前位置: 首页>>代码示例>>Golang>>正文


Golang zk.WorldACL函数代码示例

本文整理汇总了Golang中github.com/samuel/go-zookeeper/zk.WorldACL函数的典型用法代码示例。如果您正苦于以下问题:Golang WorldACL函数的具体用法?Golang WorldACL怎么用?Golang WorldACL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了WorldACL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AddMigrateTask

func AddMigrateTask(taskMeta *MigrateMeta) error {
	appname := meta.appName
	zconn := meta.zconn
	taskspath := "/r3/app/" + appname + "/migrate"
	exists, _, err := zconn.Exists(taskspath)
	if err != nil {
		return err
	}
	if !exists {
		_, err = zconn.Create(taskspath, []byte(""), 0, zookeeper.WorldACL(zookeeper.PermAll))
		if err != nil {
			return err
		}
	}
	//add task to zk
	taskpath := fmt.Sprintf("%s/%s", taskspath, taskMeta.TaskId)
	exists, _, err = zconn.Exists(taskpath)
	if err != nil {
		return err
	}
	if !exists {
		taskmeta, _ := json.Marshal(taskMeta)
		_, err = zconn.Create(taskpath, taskmeta, 0, zookeeper.WorldACL(zookeeper.PermAll))
		if err != nil {
			return err
		}
	}
	return nil

}
开发者ID:ksarch-saas,项目名称:cc,代码行数:30,代码来源:migrate.go

示例2: createPathsForService

func (sm *ZookeeperServiceManager) createPathsForService(s skynet.ServiceInfo) error {
	_, err := sm.conn.Create(path.Join("/hosts", s.ServiceAddr.IPAddress), []byte{}, 0, zk.WorldACL(zk.PermAll))

	if err != nil && err != zk.ErrNodeExists {
		return err
	}

	_, err = sm.conn.Create(path.Join("/regions", s.Region), []byte{}, 0, zk.WorldACL(zk.PermAll))

	if err != nil && err != zk.ErrNodeExists {
		return err
	}

	_, err = sm.conn.Create(path.Join("/services", s.Name), []byte{}, 0, zk.WorldACL(zk.PermAll))

	if err != nil && err != zk.ErrNodeExists {
		return err
	}

	_, err = sm.conn.Create(path.Join("/services", s.Name, s.Version), []byte{}, 0, zk.WorldACL(zk.PermAll))

	if err != nil && err != zk.ErrNodeExists {
		return err
	}

	return nil
}
开发者ID:carriercomm,项目名称:zkmanager,代码行数:27,代码来源:manager.go

示例3: PersistFrameworkID

func PersistFrameworkID(
	fwid *mesos.FrameworkID,
	zkServers []string,
	zkChroot string,
	frameworkName string,
) error {
	c, _, err := zk.Connect(zkServers, RPC_TIMEOUT)
	if err != nil {
		return err
	}
	defer c.Close()
	// attempt to create the path
	_, err = c.Create(
		zkChroot,
		[]byte(""),
		0,
		zk.WorldACL(zk.PermAll),
	)
	if err != nil && err != zk.ErrNodeExists {
		return err
	}
	// attempt to write framework ID to <path> / <frameworkName>
	_, err = c.Create(zkChroot+"/"+frameworkName+"_framework_id",
		[]byte(fwid.GetValue()),
		0,
		zk.WorldACL(zk.PermAll))
	// TODO(tyler) when err is zk.ErrNodeExists, cross-check value
	if err != nil {
		return err
	}
	log.Info("Successfully persisted Framework ID to zookeeper.")

	return nil
}
开发者ID:puppetizeme,项目名称:etcd-mesos,代码行数:34,代码来源:zk.go

示例4: createPath

func createPath(path string, data []byte, client *zk.Conn) error {
	exists, _, err := client.Exists(path)
	if err != nil {
		return err
	}

	if exists {
		return nil
	}

	name := "/"
	p := strings.Split(path, "/")

	for _, v := range p[1 : len(p)-1] {
		name += v
		e, _, _ := client.Exists(name)
		if !e {
			_, err = client.Create(name, []byte{}, int32(0), zk.WorldACL(zk.PermAll))
			if err != nil {
				return err
			}
		}
		name += "/"
	}

	_, err = client.Create(path, data, int32(0), zk.WorldACL(zk.PermAll))
	return err
}
开发者ID:micro,项目名称:go-plugins,代码行数:28,代码来源:util.go

示例5: createZPath

func (zs *ZKStorage) createZPath(conn *zk.Conn, zpath string) error {
	_, err := conn.Create(zpath, nil, 0, zk.WorldACL(zk.PermAll))
	if err != nil {
		if zk.ErrNodeExists == err {
			return nil
		} else {
			parent, _ := path.Split(zpath)
			if len(parent) == 0 {
				return errors.New("Specified blank path")
			}
			err = zs.createZPath(conn, parent[:len(parent)-1])
			if err != nil {
				return err
			}

			_, err = conn.Create(zpath, nil, 0, zk.WorldACL(zk.PermAll))
			if err == zk.ErrNodeExists {
				err = nil
			}
		}
	}

	if zk.ErrNodeExists == err {
		return nil
	} else {
		return err
	}
}
开发者ID:elodina,项目名称:stack-deploy,代码行数:28,代码来源:storage.go

示例6: createNode

func (adapter *ZookeeperStoreAdapter) createNode(node StoreNode) error {
	root := path.Dir(node.Key)
	var err error
	exists, _, err := adapter.client.Exists(root)
	if err != nil {
		return err
	}
	if !exists {
		err = adapter.createNode(StoreNode{
			Key:   root,
			Value: []byte{},
			TTL:   0,
			Dir:   true,
		})

		if err != nil {
			return err
		}
	}

	if node.Dir {
		_, err = adapter.client.Create(node.Key, []byte{}, 0, zk.WorldACL(zk.PermAll))
	} else {
		_, err = adapter.client.Create(node.Key, adapter.encode(node.Value, node.TTL), 0, zk.WorldACL(zk.PermAll))
	}

	if err == zk.ErrNodeExists {
		err = nil
	}

	return err
}
开发者ID:Zhann,项目名称:hm9000,代码行数:32,代码来源:zookeeper_store_adapter.go

示例7: TestPruneActionLogs

// TestPruneActionLogs is a ZK specific unit test
func TestPruneActionLogs(t *testing.T) {
	ctx := context.Background()
	ts := newTestServer(t, []string{"test"})
	defer ts.Close()

	if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil {
		t.Fatalf("CreateKeyspace: %v", err)
	}

	actionLogPath := path.Join(zktopo.GlobalKeyspacesPath, "test_keyspace", "actionlog")
	zkts := ts.(*TestServer).Impl.(*zktopo.Server)

	if _, err := zk.CreateRecursive(zkts.GetZConn(), actionLogPath+"/0", "first", 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
		t.Fatalf("CreateRecursive(stale): %v", err)
	}
	if _, err := zk.CreateRecursive(zkts.GetZConn(), actionLogPath+"/1", "second", 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil {
		t.Fatalf("CreateRecursive(fresh): %v", err)
	}

	if count, err := zkts.PruneActionLogs(actionLogPath, 1); err != nil || count != 1 {
		t.Fatalf("PruneActionLogs: %v %v", err, count)
	}

	actionLogs, _, err := zkts.GetZConn().Children(actionLogPath)
	if err != nil || len(actionLogs) != 1 || actionLogs[0] != "1" {
		t.Errorf("PruneActionLogs kept the wrong things: %v %v", err, actionLogs)
	}
}
开发者ID:jmptrader,项目名称:vitess,代码行数:29,代码来源:zktopo_test.go

示例8: createZookeeperPath

func createZookeeperPath() error {
	zkPathCreated := false
	var data ServerData
	data.Weight = ssfCfg.Weight
	_, port, err := net.SplitHostPort(ssfCfg.ListenAddr)
	if nil != err {
		return err
	}
	localHostName, err = os.Hostname()
	if nil != err {
		return err
	}
	localHostNamePort = net.JoinHostPort(localHostName, port)
	data.Addr = localHostNamePort
	data.ConnectedTime = time.Now().Unix()
	serverPath := "/" + ssfCfg.ClusterName + "/servers/" + data.Addr
	zkConn.Create("/"+ssfCfg.ClusterName, nil, 0, zk.WorldACL(zk.PermAll))
	zkConn.Create("/"+ssfCfg.ClusterName+"/servers/", nil, 0, zk.WorldACL(zk.PermAll))
	zkData, _ := json.Marshal(&data)
	for !zkPathCreated {
		_, err := zkConn.Create(serverPath, zkData, zk.FlagEphemeral, zk.WorldACL(zk.PermAll))
		if nil != err {
			glog.Errorf("Failed to create zookeeper path:%s with reason:%v", serverPath, err)
			time.Sleep(1 * time.Second)
		} else {
			zkPathCreated = true
		}
	}
	return nil
}
开发者ID:yinqiwen,项目名称:ssf,代码行数:30,代码来源:agent.go

示例9: tryRegisterConsumer

func (this *ZookeeperCoordinator) tryRegisterConsumer(Consumerid string, Groupid string, TopicCount TopicsToNumStreams) (err error) {
	Debugf(this, "Trying to register consumer %s at group %s in Zookeeper", Consumerid, Groupid)
	registryDir := newZKGroupDirs(this.config.Root, Groupid).ConsumerRegistryDir
	pathToConsumer := fmt.Sprintf("%s/%s", registryDir, Consumerid)
	data, mappingError := json.Marshal(&ConsumerInfo{
		Version:      int16(1),
		Subscription: TopicCount.GetTopicsToNumStreamsMap(),
		Pattern:      TopicCount.Pattern(),
		Timestamp:    time.Now().Unix() * 1000,
	})
	if mappingError != nil {
		return mappingError
	}

	Debugf(this, "Path: %s", pathToConsumer)

	_, err = this.zkConn.Create(pathToConsumer, data, zk.FlagEphemeral, zk.WorldACL(zk.PermAll))
	if err == zk.ErrNoNode {
		err = this.createOrUpdatePathParentMayNotExistFailFast(registryDir, make([]byte, 0))
		if err != nil {
			return
		}
		_, err = this.zkConn.Create(pathToConsumer, data, zk.FlagEphemeral, zk.WorldACL(zk.PermAll))
	} else if err == zk.ErrNodeExists {
		var stat *zk.Stat
		_, stat, err = this.zkConn.Get(pathToConsumer)
		if err != nil {
			return
		}
		_, err = this.zkConn.Set(pathToConsumer, data, stat.Version)
	}

	return
}
开发者ID:yutongli,项目名称:go_kafka_client,代码行数:34,代码来源:zk_coordinator.go

示例10: createConsumersDir

func (z *ZookeeperCoordinator) createConsumersDir() (err error) {
	_, err = z.zkClient.zkConn.Create(z.groupPath, make([]byte, 0), 0, zk.WorldACL(zk.PermAll))
	if err != nil && err != zk.ErrNodeExists {
		logger.Output(1, fmt.Sprintf("path:%v , %v", z.groupPath, err))
		return err
	}
	_, err = z.zkClient.zkConn.Create(z.groupPath+"/ids", make([]byte, 0), 0, zk.WorldACL(zk.PermAll))
	if err != nil && err != zk.ErrNodeExists {
		logger.Output(1, fmt.Sprintf("path:%v , %v", z.groupPath+"/ids", err))
		return err
	}

	_, err = z.zkClient.zkConn.Create(z.groupPath+"/offsets", make([]byte, 0), 0, zk.WorldACL(zk.PermAll))
	if err != nil && err != zk.ErrNodeExists {
		logger.Output(1, fmt.Sprintf("path:%v , %v", z.groupPath+"/offsets", err))
		return err
	}

	_, err = z.zkClient.zkConn.Create(z.groupPath+"/owners", make([]byte, 0), 0, zk.WorldACL(zk.PermAll))
	if err != nil && err != zk.ErrNodeExists {
		logger.Output(1, fmt.Sprintf("path:%v , %v", z.groupPath+"/owners", err))
		return err
	}

	return
}
开发者ID:shiaho,项目名称:go-kafka,代码行数:26,代码来源:coordinator.go

示例11: setUpFakeZk

func setUpFakeZk(t *testing.T) {
	conn = fakezk.NewConn()
	conn.Create("/zk", nil, 0, zookeeper.WorldACL(zookeeper.PermAll))
	conn.Create("/zk/fake", nil, 0, zookeeper.WorldACL(zookeeper.PermAll))
	conn.Create("/zk/fake/customrules", nil, 0, zookeeper.WorldACL(zookeeper.PermAll))
	conn.Create("/zk/fake/customrules/testrules", []byte("customrule1"), 0, zookeeper.WorldACL(zookeeper.PermAll))
	conn.Set("/zk/fake/customrules/testrules", []byte(customRule1), -1)
}
开发者ID:erzel,项目名称:vitess,代码行数:8,代码来源:zkcustomrule_test.go

示例12: AtomicPut

// AtomicPut put a value at "key" if the key has not been
// modified in the meantime, throws an error if this is the case
func (s *Zookeeper) AtomicPut(key string, value []byte, previous *store.KVPair, _ *store.WriteOptions) (bool, *store.KVPair, error) {
	var lastIndex uint64

	if previous != nil {
		meta, err := s.client.Set(s.normalize(key), value, int32(previous.LastIndex))
		if err != nil {
			// Compare Failed
			if err == zk.ErrBadVersion {
				return false, nil, store.ErrKeyModified
			}
			return false, nil, err
		}
		lastIndex = uint64(meta.Version)
	} else {
		// Interpret previous == nil as create operation.
		_, err := s.client.Create(s.normalize(key), value, 0, zk.WorldACL(zk.PermAll))
		if err != nil {
			// Directory does not exist
			if err == zk.ErrNoNode {

				// Create the directory
				parts := store.SplitKey(strings.TrimSuffix(key, "/"))
				parts = parts[:len(parts)-1]
				if err = s.createFullPath(parts, false); err != nil {
					// Failed to create the directory.
					return false, nil, err
				}

				// Create the node
				if _, err := s.client.Create(s.normalize(key), value, 0, zk.WorldACL(zk.PermAll)); err != nil {
					// Node exist error (when previous nil)
					if err == zk.ErrNodeExists {
						return false, nil, store.ErrKeyExists
					}
					return false, nil, err
				}

			} else {
				// Node Exists error (when previous nil)
				if err == zk.ErrNodeExists {
					return false, nil, store.ErrKeyExists
				}

				// Unhandled error
				return false, nil, err
			}
		}
		lastIndex = 0 // Newly created nodes have version 0.
	}

	pair := &store.KVPair{
		Key:       key,
		Value:     value,
		LastIndex: lastIndex,
	}

	return true, pair, nil
}
开发者ID:Chandra-TechPassionate,项目名称:docker,代码行数:60,代码来源:zookeeper.go

示例13: Create

func Create(node string, data string, temp bool) (string, error) {
	ZKConn.Lock()
	defer ZKConn.Unlock()

	if temp {
		return ZKConn.Conn.Create(node, []byte(data), zk.FlagEphemeral, zk.WorldACL(zk.PermAll))
	} else {
		return ZKConn.Conn.Create(node, []byte(data), 0, zk.WorldACL(zk.PermAll))
	}
}
开发者ID:424626154,项目名称:MultServer,代码行数:10,代码来源:zkm.go

示例14: UpdateShardReplicationFields

// UpdateShardReplicationFields is part of the topo.Server interface
func (zkts *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspace, shard string, update func(*topodatapb.ShardReplication) error) error {
	// create the parent directory to be sure it's here
	zkDir := path.Join("/zk", cell, "vt", "replication", keyspace)
	if _, err := zk.CreateRecursive(zkts.zconn, zkDir, nil, 0, zookeeper.WorldACL(zookeeper.PermAll)); err != nil && err != zookeeper.ErrNodeExists {
		return convertError(err)
	}

	// now update the data
	zkPath := shardReplicationPath(cell, keyspace, shard)
	for {
		data, stat, err := zkts.zconn.Get(zkPath)
		var version int32 = -1
		sr := &topodatapb.ShardReplication{}
		switch err {
		case zookeeper.ErrNoNode:
			// empty node, version is 0
		case nil:
			version = stat.Version
			if len(data) > 0 {
				if err = json.Unmarshal(data, sr); err != nil {
					return fmt.Errorf("bad ShardReplication data %v", err)
				}
			}
		default:
			return convertError(err)
		}

		err = update(sr)
		switch err {
		case topo.ErrNoUpdateNeeded:
			return nil
		case nil:
			// keep going
		default:
			return err
		}

		// marshall and save
		d, err := json.MarshalIndent(sr, "", "  ")
		if err != nil {
			return err
		}
		if version == -1 {
			_, err = zkts.zconn.Create(zkPath, d, 0, zookeeper.WorldACL(zookeeper.PermAll))
			if err != zookeeper.ErrNodeExists {
				return convertError(err)
			}
		} else {
			_, err = zkts.zconn.Set(zkPath, d, version)
			if err != zookeeper.ErrBadVersion {
				return convertError(err)
			}
		}
	}
}
开发者ID:erzel,项目名称:vitess,代码行数:56,代码来源:replication_graph.go

示例15: CreateOrUpdate

func CreateOrUpdate(zconn zookeeper.Conn, zkPath, value string, flags int, aclv []zookeeper.ACL, recursive bool) (pathCreated string, err error) {
	if recursive {
		pathCreated, err = CreateRecursive(zconn, zkPath, value, 0, zookeeper.WorldACL(zookeeper.PermAll))
	} else {
		pathCreated, err = zconn.Create(zkPath, []byte(value), 0, zookeeper.WorldACL(zookeeper.PermAll))
	}
	if err != nil && ZkErrorEqual(err, zookeeper.ErrNodeExists) {
		pathCreated = ""
		_, err = zconn.Set(zkPath, []byte(value), -1)
	}
	return
}
开发者ID:jackwanger,项目名称:tyrant,代码行数:12,代码来源:zk.go


注:本文中的github.com/samuel/go-zookeeper/zk.WorldACL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。