forked from control-center/serviced
/
lbClient.go
48 lines (40 loc) · 1.61 KB
/
lbClient.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
package serviced
import (
"github.com/zenoss/glog"
"github.com/zenoss/serviced/dao"
"net/rpc"
)
// A LBClient implementation.
type LBClient struct {
addr string
rpcClient *rpc.Client
}
// assert that this implemenents the Agent interface
var _ LoadBalancer = &LBClient{}
// Create a new AgentClient.
func NewLBClient(addr string) (s *LBClient, err error) {
s = new(LBClient)
s.addr = addr
rpcClient, err := rpc.DialHTTP("tcp", s.addr)
s.rpcClient = rpcClient
return s, err
}
func (a *LBClient) Close() error {
return a.rpcClient.Close()
}
// GetServiceEndpoints returns a list of endpoints for the given service endpoint request.
func (a *LBClient) GetServiceEndpoints(serviceId string, endpoints *map[string][]*dao.ApplicationEndpoint) error {
glog.V(4).Infof("ControlPlaneAgent.GetServiceEndpoints()")
return a.rpcClient.Call("ControlPlaneAgent.GetServiceEndpoints", serviceId, endpoints)
}
// GetProxySnapshotQuiece blocks until there is a snapshot request to the service
func (a *LBClient) GetProxySnapshotQuiece(serviceId string, snapshotId *string) error {
glog.V(4).Infof("ControlPlaneAgent.GetServiceEndpoints()")
return a.rpcClient.Call("ControlPlaneAgent.GetServiceEndpoints", serviceId, snapshotId)
}
// AckProxySnapshotQuiece is called by clients when the snapshot command has
// shown the service is quieced; the agent returns a response when the snapshot is complete
func (a *LBClient) AckProxySnapshotQuiece(snapshotId string, unused *interface{}) error {
glog.V(4).Infof("ControlPlaneAgent.AckProxySnapshotQuiece()")
return a.rpcClient.Call("ControlPlaneAgent.AckProxySnapshotQuiece", snapshotId, unused)
}