本文整理汇总了Golang中launchpad/net/gozk/zookeeper.WorldACL函数的典型用法代码示例。如果您正苦于以下问题:Golang WorldACL函数的具体用法?Golang WorldACL怎么用?Golang WorldACL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WorldACL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateTablet
func (zkts *Server) CreateTablet(tablet *topo.Tablet) error {
zkTabletPath := TabletPathForAlias(tablet.Alias())
// Create /zk/<cell>/vt/tablets/<uid>
_, err := zk.CreateRecursive(zkts.zconn, zkTabletPath, tablet.Json(), 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
err = topo.ErrNodeExists
}
return err
}
// Create /zk/<cell>/vt/tablets/<uid>/action
tap := path.Join(zkTabletPath, "action")
_, err = zkts.zconn.Create(tap, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
return err
}
// Create /zk/<cell>/vt/tablets/<uid>/actionlog
talp := path.Join(zkTabletPath, "actionlog")
_, err = zkts.zconn.Create(talp, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
return err
}
return nil
}
示例2: TestRetryChangeSetting
func (s *S) TestRetryChangeSetting(c *C) {
conn, _ := s.init(c)
_, err := conn.Create("/test", "old", zk.EPHEMERAL, zk.WorldACL(zk.PERM_ALL))
c.Assert(err, IsNil)
err = conn.RetryChange("/test", zk.EPHEMERAL, []zk.ACL{},
func(data string, stat *zk.Stat) (string, error) {
c.Assert(data, Equals, "old")
c.Assert(stat, NotNil)
c.Assert(stat.Version(), Equals, 0)
return "brand new", nil
})
c.Assert(err, IsNil)
data, stat, err := conn.Get("/test")
c.Assert(err, IsNil)
c.Assert(stat, NotNil)
c.Assert(stat.Version(), Equals, 1)
c.Assert(data, Equals, "brand new")
// ACL was unchanged by RetryChange().
acl, _, err := conn.ACL("/test")
c.Assert(err, IsNil)
c.Assert(acl, DeepEquals, zk.WorldACL(zk.PERM_ALL))
}
示例3: 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", &topo.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
actionLogPath := path.Join(globalKeyspacesPath, "test_keyspace", "actionlog")
zkts := ts.Server.(*Server)
if _, err := zk.CreateRecursive(zkts.zconn, actionLogPath+"/0", "first", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(stale): %v", err)
}
if _, err := zk.CreateRecursive(zkts.zconn, actionLogPath+"/1", "second", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); 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.zconn.Children(actionLogPath)
if err != nil || len(actionLogs) != 1 || actionLogs[0] != "1" {
t.Errorf("PruneActionLogs kept the wrong things: %v %v", err, actionLogs)
}
}
示例4: create
// Create the persistence node in zookeeper
func (zk *ZK) create() error {
// create zk root path
tpath := ""
for _, str := range strings.Split(Conf.ZookeeperPath, "/")[1:] {
tpath += "/" + str
Log.Debug("create zookeeper path:%s", tpath)
_, err := zk.conn.Create(tpath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
Log.Warn("zk.create(\"%s\") exists", tpath)
} else {
Log.Error("zk.create(\"%s\") error(%v)", tpath, err)
return err
}
}
}
// create node path
fpath := fmt.Sprintf("%s/%s", Conf.ZookeeperPath, Conf.ZookeeperNode)
Log.Debug("create zookeeper path:%s", fpath)
_, err := zk.conn.Create(fpath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
Log.Warn("zk.Create(\"%s\") exists", fpath)
} else {
Log.Error("zk.Create(\"%s\") error(%v)", fpath, err)
return err
}
}
return nil
}
示例5: TestPurgeActions
// TestPurgeActions is a ZK specific unit test
func TestPurgeActions(t *testing.T) {
ctx := context.Background()
ts := NewTestServer(t, []string{"test"})
defer ts.Close()
if err := ts.CreateKeyspace(ctx, "test_keyspace", &topo.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
actionPath := path.Join(globalKeyspacesPath, "test_keyspace", "action")
zkts := ts.Server.(*Server)
if _, err := zk.CreateRecursive(zkts.zconn, actionPath+"/topurge", "purgeme", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(topurge): %v", err)
}
if _, err := zk.CreateRecursive(zkts.zconn, actionPath+"/tokeep", "keepme", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("CreateRecursive(tokeep): %v", err)
}
if err := zkts.PurgeActions(actionPath, func(data string) bool {
return data == "purgeme"
}); err != nil {
t.Fatalf("PurgeActions(tokeep): %v", err)
}
actions, _, err := zkts.zconn.Children(actionPath)
if err != nil || len(actions) != 1 || actions[0] != "tokeep" {
t.Errorf("PurgeActions kept the wrong things: %v %v", err, actions)
}
}
示例6: 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, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil && !zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
return convertError(err)
}
// now update the data
zkPath := shardReplicationPath(cell, keyspace, shard)
f := func(oldValue string, oldStat zk.Stat) (string, error) {
sr := &topodatapb.ShardReplication{}
if oldValue != "" {
if err := json.Unmarshal([]byte(oldValue), sr); err != nil {
return "", err
}
}
if err := update(sr); err != nil {
return "", err
}
data, err := json.MarshalIndent(sr, "", " ")
if err != nil {
return "", err
}
return string(data), nil
}
err := zkts.zconn.RetryChange(zkPath, 0, zookeeper.WorldACL(zookeeper.PERM_ALL), f)
if err != nil {
return convertError(err)
}
return nil
}
示例7: Create
// Create the persistence node in zookeeper
func (zk *ZK) Create(path string, node string) error {
// create zk root path
tpath := ""
for _, str := range strings.Split(path, "/")[1:] {
tpath += "/" + str
Log.Debug("create zookeeper path:%s", tpath)
_, err := zk.conn.Create(tpath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
Log.Warn("zk.Create(\"%s\") exists", tpath)
} else {
Log.Error("zk.Create(\"%s\") failed (%s)", tpath, err.Error())
return err
}
}
}
// create node path
fpath := path + "/" + node
Log.Debug("create zookeeper path:%s", fpath)
_, err := zk.conn.Create(fpath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
Log.Warn("zk.Create(\"%s\") exists", fpath)
} else {
Log.Error("zk.Create(\"%s\") failed (%s)", fpath, err.Error())
return err
}
}
return nil
}
示例8: TestRetryChangeConflictOnCreate
func (s *S) TestRetryChangeConflictOnCreate(c *C) {
conn, _ := s.init(c)
changeFunc := func(data string, stat *zk.Stat) (string, error) {
switch data {
case "":
c.Assert(stat, IsNil)
_, err := conn.Create("/test", "conflict", zk.EPHEMERAL,
zk.WorldACL(zk.PERM_ALL))
c.Assert(err, IsNil)
return "<none> => conflict", nil
case "conflict":
c.Assert(stat, NotNil)
c.Assert(stat.Version(), Equals, 0)
return "conflict => new", nil
default:
c.Fatal("Unexpected node data: " + data)
}
return "can't happen", nil
}
err := conn.RetryChange("/test", zk.EPHEMERAL, zk.WorldACL(zk.PERM_ALL), changeFunc)
c.Assert(err, IsNil)
data, stat, err := conn.Get("/test")
c.Assert(err, IsNil)
c.Assert(data, Equals, "conflict => new")
c.Assert(stat, NotNil)
c.Assert(stat.Version(), Equals, 1)
}
示例9: UpdateEndPoints
// UpdateEndPoints is part of the topo.Server interface
func (zkts *Server) UpdateEndPoints(ctx context.Context, cell, keyspace, shard string, tabletType topodatapb.TabletType, addrs *topodatapb.EndPoints, existingVersion int64) error {
path := zkPathForVtName(cell, keyspace, shard, tabletType)
data, err := json.MarshalIndent(addrs, "", " ")
if err != nil {
return err
}
if existingVersion == -1 {
// Update or create unconditionally.
_, err := zk.CreateRecursive(zkts.zconn, path, string(data), 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil {
if zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
// Node already exists - just stomp away. Multiple writers shouldn't be here.
// We use RetryChange here because it won't update the node unnecessarily.
f := func(oldValue string, oldStat zk.Stat) (string, error) {
return string(data), nil
}
err = zkts.zconn.RetryChange(path, 0, zookeeper.WorldACL(zookeeper.PERM_ALL), f)
}
}
return err
}
// Compare And Set
if _, err = zkts.zconn.Set(path, string(data), int(existingVersion)); err != nil {
if zookeeper.IsError(err, zookeeper.ZBADVERSION) {
err = topo.ErrBadVersion
} else if zookeeper.IsError(err, zookeeper.ZNONODE) {
err = topo.ErrNoNode
}
}
return err
}
示例10: setUpFakeZk
func setUpFakeZk(t *testing.T) {
conn = fakezk.NewConn()
conn.Create("/zk", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
conn.Create("/zk/fake", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
conn.Create("/zk/fake/customrules", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
conn.Create("/zk/fake/customrules/testrules", "customrule1", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
conn.Set("/zk/fake/customrules/testrules", customRule1, -1)
}
示例11: init
func (zkd *Zkd) init(preserveData bool) error {
log.Infof("zkd.Init")
for _, path := range zkd.config.DirectoryList() {
if err := os.MkdirAll(path, 0775); err != nil {
log.Errorf(err.Error())
return err
}
// FIXME(msolomon) validate permissions?
}
configData, err := zkd.makeCfg()
if err == nil {
err = ioutil.WriteFile(zkd.config.ConfigFile(), []byte(configData), 0664)
}
if err != nil {
log.Errorf("failed creating %v: %v", zkd.config.ConfigFile(), err)
return err
}
err = zkd.config.WriteMyid()
if err != nil {
log.Errorf("failed creating %v: %v", zkd.config.MyidFile(), err)
return err
}
if err = zkd.Start(); err != nil {
log.Errorf("failed starting, check %v", zkd.config.LogDir())
return err
}
zkAddr := fmt.Sprintf("localhost:%v", zkd.config.ClientPort)
zk, session, err := zookeeper.Dial(zkAddr, StartWaitTime*time.Second)
if err != nil {
return err
}
event := <-session
if event.State != zookeeper.STATE_CONNECTED {
return err
}
defer zk.Close()
if !preserveData {
_, err = zk.Create("/zk", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil && !zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
return err
}
if zkd.config.Global {
_, err = zk.Create("/zk/global", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
if err != nil && !zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
return err
}
}
}
return nil
}
示例12: createPaths
func (c *Coordinator) createPaths() {
c.basePath = path.Join("/", c.config.JobId)
c.lockPath = path.Join(c.basePath, LockPath)
c.workersPath = path.Join(c.basePath, WorkersPath)
c.barriersPath = path.Join(c.basePath, BarriersPath)
c.zk.Create(c.basePath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
c.zk.Create(c.workersPath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
c.zk.Create(c.barriersPath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
}
示例13: CreateOrUpdate
func CreateOrUpdate(zconn 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.PERM_ALL))
} else {
pathCreated, err = zconn.Create(zkPath, value, 0, zookeeper.WorldACL(zookeeper.PERM_ALL))
}
if err != nil && zookeeper.IsError(err, zookeeper.ZNODEEXISTS) {
pathCreated = ""
_, err = zconn.Set(zkPath, value, -1)
}
return
}
示例14: TestChildrenAndWatch
func (s *S) TestChildrenAndWatch(c *C) {
c.Check(zk.CountPendingWatches(), Equals, 0)
conn, _ := s.init(c)
c.Check(zk.CountPendingWatches(), Equals, 1)
children, stat, watch, err := conn.ChildrenW("/")
c.Assert(err, IsNil)
c.Assert(children, DeepEquals, []string{"zookeeper"})
c.Assert(stat.NumChildren(), Equals, 1)
select {
case <-watch:
c.Fatal("Watch fired")
default:
}
c.Check(zk.CountPendingWatches(), Equals, 2)
_, err = conn.Create("/test1", "", zk.EPHEMERAL, zk.WorldACL(zk.PERM_ALL))
c.Assert(err, IsNil)
event := <-watch
c.Assert(event.Type, Equals, zk.EVENT_CHILD)
c.Assert(event.Path, Equals, "/")
c.Check(zk.CountPendingWatches(), Equals, 1)
children, stat, watch, err = conn.ChildrenW("/")
c.Assert(err, IsNil)
c.Assert(stat.NumChildren(), Equals, 2)
// The ordering is most likely unstable, so this test must be fixed.
c.Assert(children, DeepEquals, []string{"test1", "zookeeper"})
select {
case <-watch:
c.Fatal("Watch fired")
default:
}
c.Check(zk.CountPendingWatches(), Equals, 2)
_, err = conn.Create("/test2", "", zk.EPHEMERAL, zk.WorldACL(zk.PERM_ALL))
c.Assert(err, IsNil)
event = <-watch
c.Assert(event.Type, Equals, zk.EVENT_CHILD)
c.Check(zk.CountPendingWatches(), Equals, 1)
}
示例15: NewTestServer
func NewTestServer(t *testing.T, cells []string) *TestServer {
zconn := fakezk.NewConn()
// create the toplevel zk paths
if _, err := zk.CreateRecursive(zconn, "/zk/global/vt", "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
for _, cell := range cells {
if _, err := zk.CreateRecursive(zconn, fmt.Sprintf("/zk/%v/vt", cell), "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err != nil {
t.Fatalf("cannot init ZooKeeper: %v", err)
}
}
return &TestServer{Server: NewServer(zconn), localCells: cells}
}