cluster.go 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package cluster // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver/cluster"
  4. import (
  5. as "github.com/aerospike/aerospike-client-go/v6"
  6. )
  7. // asclient interface is for mocking
  8. type asclient interface {
  9. GetNodes() []*as.Node
  10. Close()
  11. }
  12. // wrap aerospike Cluster so we can return node interfaces
  13. type Cluster struct {
  14. conn asclient
  15. }
  16. func NewCluster(policy *as.ClientPolicy, hosts []*as.Host) (*Cluster, error) {
  17. c, err := as.NewClientWithPolicyAndHost(policy, hosts...)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return &Cluster{c}, err
  22. }
  23. func (c *Cluster) GetNodes() []Node {
  24. asNodes := c.conn.GetNodes()
  25. nodes := make([]Node, len(asNodes))
  26. for i, n := range asNodes {
  27. nodes[i] = n
  28. }
  29. return nodes
  30. }
  31. func (c *Cluster) Close() {
  32. c.conn.Close()
  33. }