Ejemplo n.º 1
0
//Add node to the key in registry.  Returns the path of the node in the registry
func (r *registryType) addItem(conn client.Connection, key string, nodeID string, node client.Node) (string, error) {
	if err := r.ensureKey(conn, key); err != nil {
		glog.Errorf("error with addItem.ensureKey(%s): %+v", r.getPath(key), err)
		return "", err
	}

	//TODO: make ephemeral
	path := r.getPath(key, nodeID)
	glog.V(3).Infof("Adding to %s: %#v", path, node)
	if r.ephemeral {
		var err error
		if path, err = conn.CreateEphemeral(path, node); err != nil {
			glog.Errorf("error with addItem.CreateEphemeral(%s) %+v", path, err)
			return "", err
		}
	} else {
		if err := conn.Create(path, node); err != nil {
			glog.Errorf("error with addItem.Create(%s) %+v", path, err)
			return "", err
		}
	}
	return path, nil
}