frostfs-node/pkg/network/transport/apemanager/grpc/service.go
Airat Arifullin 542d3adcb2 [#1105] apemanager: Implement apemanager service
* Introduce grpc server for apemanager service and
  its implementation in `pkg/services/apemanager`.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-27 09:34:21 +00:00

63 lines
1.7 KiB
Go

package apemanager
import (
"context"
apemanager_v2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
apemanager_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc"
apemanager_svc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/apemanager"
)
type Server struct {
srv apemanager_svc.Server
}
var _ apemanager_grpc.APEManagerServiceServer = (*Server)(nil)
func New(c apemanager_svc.Server) *Server {
return &Server{
srv: c,
}
}
func (s *Server) AddChain(ctx context.Context, req *apemanager_grpc.AddChainRequest) (*apemanager_grpc.AddChainResponse, error) {
v2req := new(apemanager_v2.AddChainRequest)
if err := v2req.FromGRPCMessage(req); err != nil {
return nil, err
}
resp, err := s.srv.AddChain(ctx, v2req)
if err != nil {
return nil, err
}
return resp.ToGRPCMessage().(*apemanager_grpc.AddChainResponse), nil
}
func (s *Server) RemoveChain(ctx context.Context, req *apemanager_grpc.RemoveChainRequest) (*apemanager_grpc.RemoveChainResponse, error) {
v2req := new(apemanager_v2.RemoveChainRequest)
if err := v2req.FromGRPCMessage(req); err != nil {
return nil, err
}
resp, err := s.srv.RemoveChain(ctx, v2req)
if err != nil {
return nil, err
}
return resp.ToGRPCMessage().(*apemanager_grpc.RemoveChainResponse), nil
}
func (s *Server) ListChains(ctx context.Context, req *apemanager_grpc.ListChainsRequest) (*apemanager_grpc.ListChainsResponse, error) {
v2req := new(apemanager_v2.ListChainsRequest)
if err := v2req.FromGRPCMessage(req); err != nil {
return nil, err
}
resp, err := s.srv.ListChains(ctx, v2req)
if err != nil {
return nil, err
}
return resp.ToGRPCMessage().(*apemanager_grpc.ListChainsResponse), nil
}