-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
109 lines (91 loc) · 3.11 KB
/
api.go
File metadata and controls
109 lines (91 loc) · 3.11 KB
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
100
101
102
103
104
105
106
107
108
109
package pistachio
import (
"github.com/dedis/pistachio/gentree"
"github.com/dedis/pistachio/service"
redisSvc "github.com/dedis/pistachio/service"
"gopkg.in/dedis/cothority.v2"
"gopkg.in/dedis/onet.v2"
"gopkg.in/dedis/onet.v2/log"
"gopkg.in/dedis/onet.v2/network"
)
// Client is a structure to communicate with the nyle service.
type Client struct {
*onet.Client
}
// NewClient instantiates a new nyle.Client.
func NewClient() *Client {
return &Client{Client: onet.NewClient(cothority.Suite, service.Name)}
}
// InitRequest ...
func (c *Client) InitRequest(dst *network.ServerIdentity, Nodes []*gentree.LocalityNode,
ServerIdentityToName map[*network.ServerIdentity]string, nrOps int, nrLevels int, jurisdictionsAndRoot string, limixMode bool) (*service.InitResponse, error) {
serviceReq := &service.InitRequest{
Nodes: Nodes,
ServerIdentityToName: ServerIdentityToName,
NrOps: nrOps,
NrLevels: nrLevels,
JurisdictionsAndRoot: jurisdictionsAndRoot,
LimixMode: limixMode,
}
log.LLvl1("Sending INIT to", ServerIdentityToName[dst], "req=", *serviceReq)
reply := &service.InitResponse{}
err := c.SendProtobuf(dst, serviceReq, reply)
if err != nil {
log.LLvl1("We have an error when sending to", dst.String(), "readable name", ServerIdentityToName[dst], "error is", err)
//panic(err)
return nil, err
}
log.Lvl1("Done INIT", ServerIdentityToName[dst])
return reply, nil
}
func (c *Client) ExecReq(dst *network.ServerIdentity, rootName string, commandName string, params []string, reqId int, op redisSvc.COMMAND_TYPE, nrKeys int) (*service.ExecRedisReply, error) {
req := service.ExecRedisReq{
CommandName: commandName,
Params: params,
ReqId: reqId,
Command: op,
NrKeys: nrKeys,
}
log.Lvl2("Client sending exp req to", dst.String(), req)
var resp service.ExecRedisReply
err := c.SendProtobuf(dst, &req, &resp)
//log.LLvl1("Client done with exp ", dst.String(), reqId)
if err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) LoadGeoPartitioning(roster *onet.Roster, regions, partitionMapping, externDir string) error {
if regions == "" || partitionMapping == "" || externDir == "" {
panic("empty geo partition config")
}
for _, dst := range roster.List {
err := c.SendProtobuf(dst,
&redisSvc.LoadGeoPartitioning{regions, partitionMapping, externDir},
&redisSvc.LoadGeoPartitioningReply{})
if err != nil {
return err
}
}
return nil
}
// StartCoSi ...
func (c *Client) StartStopRedis(dst *network.ServerIdentity, roster *onet.Roster, reqId int, reqType service.REQ_TYPE, op service.COMMAND_TYPE, minNodesPerZone int, jurisdictions string, privateCloud bool) (*service.StartStopDSResp, error) {
req := service.StartStopDSReq{
Roster: *roster,
ReqId: reqId,
ReqType: reqType,
OpType: op,
MinNodesPerZone: minNodesPerZone,
JurisdictionsAndCenter: jurisdictions,
PrivateCloud: privateCloud,
}
log.LLvl1("Client sending req to", dst.String(), reqId)
var resp service.StartStopDSResp
err := c.SendProtobuf(dst, &req, &resp)
log.LLvl1("Client done with ", dst.String(), reqId)
if err != nil {
return nil, err
}
return &resp, nil
}