/
api.go
57 lines (50 loc) · 1.67 KB
/
api.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
package rpc
import (
"context"
api "github.com/mohitkumar/orchy/api/v1"
"github.com/mohitkumar/orchy/model"
"github.com/mohitkumar/orchy/persistence"
)
var _ api.ActionServiceServer = (*grpcServer)(nil)
func (srv *grpcServer) SaveActionDefinition(ctx context.Context, req *api.ActionDefinition) (*api.ActionDefinitionSaveResponse, error) {
action := &model.ActionDefinition{
Name: req.Name,
RetryCount: int(req.RetryCount),
RetryAfterSeconds: int(req.RetryAfterSeconds),
RetryPolicy: model.RetryPolicy(req.RetryPolicy),
TimeoutSeconds: int(req.TimeoutSeconds),
}
err := srv.ActionDefinitionService.SaveActionDefinition(*action)
if err != nil {
return &api.ActionDefinitionSaveResponse{
Status: false,
}, err
}
return &api.ActionDefinitionSaveResponse{Status: true}, nil
}
func (srv *grpcServer) Poll(ctx context.Context, req *api.ActionPollRequest) (*api.Actions, error) {
action, err := srv.ActionService.Poll(req.ActionType, int(req.BatchSize))
if err != nil {
switch err.(type) {
case persistence.StorageLayerError:
return nil, &api.StorageLayerError{}
}
}
return action, nil
}
func (srv *grpcServer) Push(ctx context.Context, req *api.ActionResult) (*api.ActionResultPushResponse, error) {
err := srv.ActionService.Push(req)
if err != nil {
return &api.ActionResultPushResponse{
Status: false,
}, err
}
return &api.ActionResultPushResponse{Status: true}, nil
}
func (s *grpcServer) GetServers(ctx context.Context, req *api.GetServersRequest) (*api.GetServersResponse, error) {
servers, err := s.GetServerer.GetServers()
if err != nil {
return nil, err
}
return &api.GetServersResponse{Servers: servers}, nil
}