forked from aerospike/aerospike-management-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.go
99 lines (82 loc) · 2.43 KB
/
deployment.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package deployment
import (
"fmt"
"net"
"strconv"
"github.com/go-logr/logr"
aero "github.com/aerospike/aerospike-client-go/v7"
"github.com/tanmayja/aerospike-management-lib/info"
)
// HostConn has all parameters to connect to an aerospike host and the machine.
type HostConn struct {
Log logr.Logger
ASConn *ASConn
ID string // host UUID string
}
type ASConnInterface interface {
RunInfo(*aero.ClientPolicy, ...string) (map[string]string, error)
}
type ASConn struct {
Log logr.Logger
AerospikeHostName string // host name of the machine to connect through aerospike
AerospikeTLSName string // tls name of the aerospike connection
AerospikePort int // aerospike port to connect to
}
// NewHostConn returns a new HostConn
func NewHostConn(log logr.Logger, id string, asConn *ASConn) *HostConn {
return &HostConn{
Log: log,
ID: id,
ASConn: asConn,
}
}
// RunInfo runs info command on given host
func (asc *ASConn) RunInfo(
aerospikePolicy *aero.ClientPolicy, command ...string,
) (map[string]string, error) {
h := aero.Host{
Name: asc.AerospikeHostName,
Port: asc.AerospikePort,
TLSName: asc.AerospikeTLSName,
}
asinfo := info.NewAsInfo(asc.Log, &h, aerospikePolicy)
return asinfo.RequestInfo(command...)
}
// AlumniReset runs services alumni reset
func (asc *ASConn) AlumniReset(aerospikePolicy *aero.ClientPolicy) error {
res, err := asc.RunInfo(aerospikePolicy, "services-alumni-reset")
asc.Log.Info("AlumniReset", "res", res)
return err
}
// TipClearHostname runs tip clear
func (asc *ASConn) TipClearHostname(
aerospikePolicy *aero.ClientPolicy, address string, heartbeatPort int,
) error {
res, err := asc.RunInfo(
aerospikePolicy,
fmt.Sprintf("tip-clear:host-port-list=%s:%d", address, heartbeatPort),
)
asc.Log.Info("TipClearHostname", "res", res)
return err
}
// TipHostname runs tip clear
func (asc *ASConn) TipHostname(
aerospikePolicy *aero.ClientPolicy, address string, heartbeatPort int,
) error {
res, err := asc.RunInfo(
aerospikePolicy,
fmt.Sprintf("tip:host=%s;port=%d", address, heartbeatPort),
)
asc.Log.Info("TipHostname", "res", res)
return err
}
// ToHost returns a host object
func (n *HostConn) toHost(policy *aero.ClientPolicy) (*host, error) {
return newHost(n.ID, policy, n.ASConn)
}
// Implements stringer interface
func (n *HostConn) String() string {
return net.JoinHostPort(
n.ASConn.AerospikeHostName, strconv.Itoa(n.ASConn.AerospikePort),
)
}