示例#1
0
// AddUpdate implements zzk.SyncHandler
func (l *ServiceSynchronizer) AddUpdate(id string, node zzk.Node) (string, error) {
	if snode, ok := node.(*ServiceNode); !ok {
		glog.Errorf("Could not extract service node data for %s", id)
		return "", zzk.ErrInvalidType
	} else if svc := snode.Service; svc == nil {
		glog.Errorf("Service is nil for %s", id)
		return "", zzk.ErrInvalidType
	} else if err := l.handler.AddUpdateService(svc); err != nil {
		return "", err
	}
	return node.GetID(), nil
}
示例#2
0
// AddUpdate implements zzk.SyncHandler
func (l *HostSynchronizer) AddUpdate(id string, node zzk.Node) (string, error) {
	if hnode, ok := node.(*HostNode); !ok {
		glog.Errorf("Could not extract host node data for %s", id)
		return "", zzk.ErrInvalidType
	} else if host := hnode.Host; host == nil {
		glog.Errorf("Host is nil for %s", id)
		return "", zzk.ErrInvalidType
	} else if err := l.handler.AddUpdateHost(host); err != nil {
		return "", err
	}

	return node.GetID(), nil
}
示例#3
0
// AddUpdate implements zzk.SyncHandler
func (l *PoolSynchronizer) AddUpdate(id string, node zzk.Node) (string, error) {
	if pnode, ok := node.(*PoolNode); !ok {
		glog.Errorf("Could not extract pool node data for %s", id)
		return "", zzk.ErrInvalidType
	} else if pool := pnode.ResourcePool; pool == nil {
		glog.Errorf("Pool is nil for %s", id)
		return "", zzk.ErrInvalidType
	} else if err := l.handler.AddUpdateResourcePool(pool); err != nil {
		return "", err
	}

	return node.GetID(), nil
}
示例#4
0
// AddUpdate implements zzk.SyncHandler
func (l *KeySynchronizer) AddUpdate(_ string, node zzk.Node) (string, error) {
	exists, err := zzk.PathExists(l.conn, l.registry.getPath(node.GetID()))

	if err != nil {
		return "", err
	}

	if exists {
		err = l.updatekey(node.GetID())
	} else {
		err = l.addkey(node.GetID())
	}

	if err != nil {
		return "", err
	}

	return node.GetID(), nil
}