2020-10-22 11:06:25 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-10-22 11:06:25 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
2020-10-22 11:06:25 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
type ResponseService struct {
|
2020-10-22 11:06:25 +00:00
|
|
|
respSvc *response.Service
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
svc ServiceServer
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type searchStreamResponser struct {
|
2022-12-30 14:55:03 +00:00
|
|
|
SearchStream
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2022-12-30 14:55:03 +00:00
|
|
|
respSvc *response.Service
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type getStreamResponser struct {
|
2022-12-30 14:55:03 +00:00
|
|
|
GetObjectStream
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-12-30 14:55:03 +00:00
|
|
|
respSvc *response.Service
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type getRangeStreamResponser struct {
|
2022-12-30 14:55:03 +00:00
|
|
|
GetObjectRangeStream
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2022-12-30 14:55:03 +00:00
|
|
|
respSvc *response.Service
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type putStreamResponser struct {
|
2022-12-30 15:01:51 +00:00
|
|
|
stream PutObjectStream
|
|
|
|
respSvc *response.Service
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2024-08-12 10:01:57 +00:00
|
|
|
type patchStreamResponser struct {
|
2024-08-12 14:11:10 +00:00
|
|
|
stream PatchObjectStream
|
2024-08-12 10:01:57 +00:00
|
|
|
respSvc *response.Service
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:06:25 +00:00
|
|
|
// NewResponseService returns object service instance that passes internal service
|
|
|
|
// call to response service.
|
2020-12-02 23:45:25 +00:00
|
|
|
func NewResponseService(objSvc ServiceServer, respSvc *response.Service) *ResponseService {
|
|
|
|
return &ResponseService{
|
2020-10-22 11:06:25 +00:00
|
|
|
respSvc: respSvc,
|
|
|
|
svc: objSvc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *getStreamResponser) Send(resp *object.GetResponse) error {
|
2022-12-30 14:55:03 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return s.GetObjectStream.Send(resp)
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *ResponseService) Get(req *object.GetRequest, stream GetObjectStream) error {
|
|
|
|
return s.svc.Get(req, &getStreamResponser{
|
2022-12-30 14:55:03 +00:00
|
|
|
GetObjectStream: stream,
|
|
|
|
respSvc: s.respSvc,
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:23:53 +00:00
|
|
|
func (s *putStreamResponser) Send(ctx context.Context, req *object.PutRequest) error {
|
2022-12-30 15:01:51 +00:00
|
|
|
if err := s.stream.Send(ctx, req); err != nil {
|
|
|
|
return fmt.Errorf("could not send the request: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:23:53 +00:00
|
|
|
func (s *putStreamResponser) CloseAndRecv(ctx context.Context) (*object.PutResponse, error) {
|
|
|
|
r, err := s.stream.CloseAndRecv(ctx)
|
2020-10-22 11:06:25 +00:00
|
|
|
if err != nil {
|
2022-12-30 15:01:51 +00:00
|
|
|
return nil, fmt.Errorf("could not close stream and receive response: %w", err)
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 15:01:51 +00:00
|
|
|
s.respSvc.SetMeta(r)
|
|
|
|
return r, nil
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 11:23:53 +00:00
|
|
|
func (s *ResponseService) Put() (PutObjectStream, error) {
|
|
|
|
stream, err := s.svc.Put()
|
2020-10-22 11:06:25 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not create Put object streamer: %w", err)
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &putStreamResponser{
|
2022-12-30 15:01:51 +00:00
|
|
|
stream: stream,
|
|
|
|
respSvc: s.respSvc,
|
2020-10-22 11:06:25 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-08-12 10:01:57 +00:00
|
|
|
func (s *patchStreamResponser) Send(ctx context.Context, req *object.PatchRequest) error {
|
|
|
|
if err := s.stream.Send(ctx, req); err != nil {
|
|
|
|
return fmt.Errorf("could not send the request: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *patchStreamResponser) CloseAndRecv(ctx context.Context) (*object.PatchResponse, error) {
|
|
|
|
r, err := s.stream.CloseAndRecv(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not close stream and receive response: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.respSvc.SetMeta(r)
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
|
2024-08-12 14:11:10 +00:00
|
|
|
func (s *ResponseService) Patch() (PatchObjectStream, error) {
|
2024-08-12 10:01:57 +00:00
|
|
|
stream, err := s.svc.Patch()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not create Put object streamer: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &patchStreamResponser{
|
|
|
|
stream: stream,
|
|
|
|
respSvc: s.respSvc,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-07-03 08:36:20 +00:00
|
|
|
func (s *ResponseService) PutSingle(ctx context.Context, req *object.PutSingleRequest) (*object.PutSingleResponse, error) {
|
|
|
|
resp, err := s.svc.PutSingle(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *ResponseService) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
|
2022-12-30 14:48:50 +00:00
|
|
|
resp, err := s.svc.Head(ctx, req)
|
2020-10-22 11:06:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return resp, nil
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *searchStreamResponser) Send(resp *object.SearchResponse) error {
|
2022-12-30 14:55:03 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return s.SearchStream.Send(resp)
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *ResponseService) Search(req *object.SearchRequest, stream SearchStream) error {
|
|
|
|
return s.svc.Search(req, &searchStreamResponser{
|
2022-12-30 14:55:03 +00:00
|
|
|
SearchStream: stream,
|
|
|
|
respSvc: s.respSvc,
|
2020-12-10 12:26:40 +00:00
|
|
|
})
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *ResponseService) Delete(ctx context.Context, req *object.DeleteRequest) (*object.DeleteResponse, error) {
|
2022-12-30 14:48:50 +00:00
|
|
|
resp, err := s.svc.Delete(ctx, req)
|
2020-10-22 11:06:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return resp, nil
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (s *getRangeStreamResponser) Send(resp *object.GetRangeResponse) error {
|
2022-12-30 14:55:03 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return s.GetObjectRangeStream.Send(resp)
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (s *ResponseService) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error {
|
|
|
|
return s.svc.GetRange(req, &getRangeStreamResponser{
|
2022-12-30 14:55:03 +00:00
|
|
|
GetObjectRangeStream: stream,
|
|
|
|
respSvc: s.respSvc,
|
2020-12-07 17:49:47 +00:00
|
|
|
})
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *ResponseService) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
2022-12-30 14:48:50 +00:00
|
|
|
resp, err := s.svc.GetRangeHash(ctx, req)
|
2020-10-22 11:06:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
|
|
|
return resp, nil
|
2020-10-22 11:06:25 +00:00
|
|
|
}
|