本文整理汇总了Golang中github.com/control-center/serviced/coordinator/client.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Current
// Current returns the currect elected leader and deserializes it in to node.
// It will return ErrNoLeaderFound if no leader has been elected.
func (l *Leader) Current(node client.Node) (err error) {
children, _, err := l.c.conn.Children(l.path)
if err != nil {
return xlateError(err)
}
var lowestSeq uint64
lowestSeq = math.MaxUint64
path := ""
for _, p := range children {
s, err := parseSeq(p)
if err != nil {
return xlateError(err)
}
if s < lowestSeq {
lowestSeq = s
path = p
}
}
if lowestSeq == math.MaxUint64 {
return ErrNoLeaderFound
}
path = fmt.Sprintf("%s/%s", l.path, path)
data, stat, err := l.c.conn.Get(path)
err = json.Unmarshal(data, node)
node.SetVersion(stat)
return xlateError(err)
}
示例2: setItem
//Set node to the key in registry. Returns the path of the node in the registry
func (r *registryType) setItem(conn client.Connection, key string, nodeID string, node client.Node) (string, error) {
if err := r.ensureKey(conn, key); err != nil {
return "", err
}
//TODO: make ephemeral
path := r.getPath(key, nodeID)
exists, err := zzk.PathExists(conn, path)
if err != nil {
return "", err
}
if exists {
glog.V(3).Infof("Set to %s: %#v", path, node)
epn := EndpointNode{}
if err := conn.Get(path, &epn); err != nil {
return "", err
}
node.SetVersion(epn.Version())
if err := conn.Set(path, node); err != nil {
return "", err
}
} else {
if addPath, err := r.addItem(conn, key, nodeID, node); err != nil {
return "", err
} else {
path = addPath
}
glog.V(3).Infof("Add to %s: %#v", path, node)
}
return path, nil
}
示例3: CreateEphemeral
func (c *Connection) CreateEphemeral(path string, node client.Node) (string, error) {
if c.conn == nil {
return "", client.ErrConnectionClosed
}
p := join(c.basePath, path)
bytes, err := json.Marshal(node)
if err != nil {
return "", client.ErrSerialization
}
path, err = c.conn.CreateProtectedEphemeralSequential(p, bytes, zklib.WorldACL(zklib.PermAll))
if err == zklib.ErrNoNode {
// Create parent node.
parts := strings.Split(p, "/")
pth := ""
if len(parts) > 1 {
for _, p := range parts[1 : len(parts)-1] {
pth += "/" + p
_, err = c.conn.Create(pth, []byte{}, 0, zklib.WorldACL(zklib.PermAll))
if err != nil && err != zklib.ErrNodeExists {
return "", xlateError(err)
}
}
path, err = c.conn.CreateProtectedEphemeralSequential(p, bytes, zklib.WorldACL(zklib.PermAll))
}
}
if err == nil {
node.SetVersion(&zklib.Stat{})
}
return path, xlateError(err)
}
示例4: Create
// Create places data at the node at the given path.
func (c *Connection) Create(path string, node client.Node) error {
if c.conn == nil {
return client.ErrConnectionClosed
}
p := join(c.basePath, path)
bytes, err := json.Marshal(node)
if err != nil {
return client.ErrSerialization
}
_, err = c.conn.Create(p, bytes, 0, zklib.WorldACL(zklib.PermAll))
if err == zklib.ErrNoNode {
// Create parent node.
parts := strings.Split(p, "/")
pth := ""
for _, p := range parts[1:] {
pth += "/" + p
_, err = c.conn.Create(pth, []byte{}, 0, zklib.WorldACL(zklib.PermAll))
if err != nil && err != zklib.ErrNodeExists {
return xlateError(err)
}
}
}
if err == nil {
node.SetVersion(&zklib.Stat{})
}
return xlateError(err)
}
示例5: get
func (c *Connection) get(path string, node client.Node) (err error) {
data, stat, err := c.conn.Get(path)
if err != nil {
return xlateError(err)
}
if len(data) > 0 {
glog.V(11).Infof("got data %s", string(data))
err = json.Unmarshal(data, node)
} else {
err = client.ErrEmptyNode
}
node.SetVersion(stat)
return xlateError(err)
}
示例6: Set
// Set serializes the given node and places it at the given path.
func (c *Connection) Set(path string, node client.Node) error {
if c.conn == nil {
return client.ErrConnectionClosed
}
data, err := json.Marshal(node)
if err != nil {
return xlateError(err)
}
stat := &zklib.Stat{}
if node.Version() != nil {
zstat, ok := node.Version().(*zklib.Stat)
if !ok {
return client.ErrInvalidVersionObj
}
*stat = *zstat
}
_, err = c.conn.Set(join(c.basePath, path), data, stat.Version)
return xlateError(err)
}