2020-08-22 10:18:50 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-08-22 10:18:50 +00:00
|
|
|
"io"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
objectGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2020-08-22 10:18:50 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Server wraps FrostFS API Object service and
|
2020-08-22 10:18:50 +00:00
|
|
|
// provides gRPC Object service server interface.
|
|
|
|
type Server struct {
|
2020-12-02 23:45:25 +00:00
|
|
|
srv objectSvc.ServiceServer
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2020-12-02 23:45:25 +00:00
|
|
|
func New(c objectSvc.ServiceServer) *Server {
|
2020-08-22 10:18:50 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put opens internal Object service Put stream and overtakes data from gRPC stream to it.
|
|
|
|
func (s *Server) Put(gStream objectGRPC.ObjectService_PutServer) error {
|
2023-04-03 11:23:53 +00:00
|
|
|
stream, err := s.srv.Put()
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
req, err := gStream.Recv()
|
2020-08-25 15:42:57 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
if errors.Is(err, io.EOF) {
|
2023-04-03 11:23:53 +00:00
|
|
|
resp, err := stream.CloseAndRecv(gStream.Context())
|
2020-08-25 15:42:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-22 10:18:50 +00:00
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return gStream.SendAndClose(resp.ToGRPCMessage().(*objectGRPC.PutResponse))
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 15:42:57 +00:00
|
|
|
return err
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
putReq := new(object.PutRequest)
|
|
|
|
if err := putReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-03 11:23:53 +00:00
|
|
|
if err := stream.Send(gStream.Context(), putReq); err != nil {
|
2021-11-06 11:13:04 +00:00
|
|
|
if errors.Is(err, util.ErrAbortStream) {
|
2023-04-03 11:23:53 +00:00
|
|
|
resp, err := stream.CloseAndRecv(gStream.Context())
|
2021-11-06 11:13:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return gStream.SendAndClose(resp.ToGRPCMessage().(*objectGRPC.PutResponse))
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:42:57 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete converts gRPC DeleteRequest message and passes it to internal Object service.
|
|
|
|
func (s *Server) Delete(ctx context.Context, req *objectGRPC.DeleteRequest) (*objectGRPC.DeleteResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
delReq := new(object.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().(*objectGRPC.DeleteResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Head converts gRPC HeadRequest message and passes it to internal Object service.
|
|
|
|
func (s *Server) Head(ctx context.Context, req *objectGRPC.HeadRequest) (*objectGRPC.HeadResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
searchReq := new(object.HeadRequest)
|
|
|
|
if err := searchReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Head(ctx, searchReq)
|
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().(*objectGRPC.HeadResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRangeHash converts gRPC GetRangeHashRequest message and passes it to internal Object service.
|
|
|
|
func (s *Server) GetRangeHash(ctx context.Context, req *objectGRPC.GetRangeHashRequest) (*objectGRPC.GetRangeHashResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
hashRngReq := new(object.GetRangeHashRequest)
|
|
|
|
if err := hashRngReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.GetRangeHash(ctx, hashRngReq)
|
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().(*objectGRPC.GetRangeHashResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
2023-07-03 08:36:20 +00:00
|
|
|
|
|
|
|
func (s *Server) PutSingle(ctx context.Context, req *objectGRPC.PutSingleRequest) (*objectGRPC.PutSingleResponse, error) {
|
|
|
|
putSingleReq := &object.PutSingleRequest{}
|
|
|
|
if err := putSingleReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.PutSingle(ctx, putSingleReq)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.ToGRPCMessage().(*objectGRPC.PutSingleResponse), nil
|
|
|
|
}
|