2020-08-24 14:07:08 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
2022-12-30 14:48:50 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
2020-08-24 14:07:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceExecutor interface {
|
2022-03-30 14:19:14 +00:00
|
|
|
Put(context.Context, *session.Token, *container.PutRequestBody) (*container.PutResponseBody, error)
|
|
|
|
Delete(context.Context, *session.Token, *container.DeleteRequestBody) (*container.DeleteResponseBody, error)
|
2020-08-24 14:07:08 +00:00
|
|
|
Get(context.Context, *container.GetRequestBody) (*container.GetResponseBody, error)
|
|
|
|
List(context.Context, *container.ListRequestBody) (*container.ListResponseBody, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type executorSvc struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
Server
|
2021-02-01 12:43:09 +00:00
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
exec ServiceExecutor
|
2022-12-30 14:48:50 +00:00
|
|
|
|
|
|
|
respSvc *response.Service
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Container Service interface.
|
2022-12-30 14:48:50 +00:00
|
|
|
func NewExecutionService(exec ServiceExecutor, respSvc *response.Service) Server {
|
2020-08-24 14:07:08 +00:00
|
|
|
return &executorSvc{
|
2022-12-30 14:48:50 +00:00
|
|
|
exec: exec,
|
|
|
|
respSvc: respSvc,
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 16:23:11 +00:00
|
|
|
func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
2022-05-31 14:13:34 +00:00
|
|
|
meta := req.GetMetaHeader()
|
|
|
|
for origin := meta.GetOrigin(); origin != nil; origin = meta.GetOrigin() {
|
|
|
|
meta = origin
|
|
|
|
}
|
|
|
|
|
|
|
|
respBody, err := s.exec.Put(ctx, meta.GetSessionToken(), req.GetBody())
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute Put request: %w", err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(container.PutResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-24 14:07:08 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *executorSvc) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
2022-05-31 14:13:34 +00:00
|
|
|
meta := req.GetMetaHeader()
|
|
|
|
for origin := meta.GetOrigin(); origin != nil; origin = meta.GetOrigin() {
|
|
|
|
meta = origin
|
|
|
|
}
|
|
|
|
|
|
|
|
respBody, err := s.exec.Delete(ctx, meta.GetSessionToken(), req.GetBody())
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute Delete request: %w", err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(container.DeleteResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-24 14:07:08 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *executorSvc) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
|
|
|
respBody, err := s.exec.Get(ctx, req.GetBody())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute Get request: %w", err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(container.GetResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-24 14:07:08 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *executorSvc) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
|
|
|
respBody, err := s.exec.List(ctx, req.GetBody())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute List request: %w", err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(container.ListResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-24 14:07:08 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|