forked from aerospike/aerospike-management-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.go
76 lines (63 loc) · 1.66 KB
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package deployment
import (
"fmt"
"github.com/go-logr/logr"
aero "github.com/aerospike/aerospike-client-go/v7"
"github.com/tanmayja/aerospike-management-lib/info"
)
// host is a system on which the aerospike server is running. It provides aerospike
// specific capabilities on the system.
type host struct {
log logr.Logger
asConnInfo *asConnInfo
id string // host UUID string
}
type asConnInfo struct {
// aerospike specific details
aerospikePolicy *aero.ClientPolicy
asInfo *info.AsInfo
aerospikeHostName string
aerospikePort int
}
// newHost creates an aerospike host.
func newHost(
id string, aerospikePolicy *aero.ClientPolicy, asConn *ASConn,
) (*host, error) {
nd := host{
id: id,
}
if asConn != nil {
nd.log = asConn.Log
nd.asConnInfo = newASConnInfo(aerospikePolicy, asConn)
}
return &nd, nil
}
func newASConnInfo(aerospikePolicy *aero.ClientPolicy, asConn *ASConn) *asConnInfo {
h := aero.Host{
Name: asConn.AerospikeHostName,
Port: asConn.AerospikePort,
TLSName: asConn.AerospikeTLSName,
}
asInfo := info.NewAsInfo(asConn.Log, &h, aerospikePolicy)
return &asConnInfo{
aerospikeHostName: asConn.AerospikeHostName,
aerospikePort: asConn.AerospikePort,
aerospikePolicy: aerospikePolicy,
asInfo: asInfo,
}
}
func (n *host) String() string {
return n.id
}
// Close closes all the open connections of the host.
func (n *host) Close() error {
if n.asConnInfo.asInfo != nil {
if err := n.asConnInfo.asInfo.Close(); err != nil {
return fmt.Errorf(
"failed to close asinfo/system connection for host %s: %v",
n.asConnInfo.aerospikeHostName, err,
)
}
}
return nil
}