2020-08-22 10:18:50 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
|
|
containerGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
|
|
|
|
containersvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/container"
|
2020-08-22 10:18:50 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Server wraps FrostFS API Container service and
|
2020-08-22 10:18:50 +00:00
|
|
|
// provides gRPC Container service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv containersvc.Server
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2021-03-15 10:53:08 +00:00
|
|
|
func New(c containersvc.Server) *Server {
|
2020-08-22 10:18:50 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put converts gRPC PutRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Put(ctx context.Context, req *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
putReq := new(container.PutRequest)
|
|
|
|
if err := putReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Put(ctx, putReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.PutResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete converts gRPC DeleteRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Delete(ctx context.Context, req *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
delReq := new(container.DeleteRequest)
|
|
|
|
if err := delReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Delete(ctx, delReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.DeleteResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get converts gRPC GetRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Get(ctx context.Context, req *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
getReq := new(container.GetRequest)
|
|
|
|
if err := getReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Get(ctx, getReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.GetResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// List converts gRPC ListRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) List(ctx context.Context, req *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
listReq := new(container.ListRequest)
|
|
|
|
if err := listReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.List(ctx, listReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.ListResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|