當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.Node類代碼示例

本文整理匯總了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)
}
開發者ID:eval01-tts,項目名稱:serviced,代碼行數:31,代碼來源:leader.go

示例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
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:34,代碼來源:registry.go

示例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)
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:33,代碼來源:connection.go

示例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)
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:31,代碼來源:connection.go

示例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)
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:14,代碼來源:connection.go

示例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)
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:21,代碼來源:connection.go


注:本文中的github.com/control-center/serviced/coordinator/client.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。