2020-08-24 14:56:39 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-24 14:56:39 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/session"
|
2022-12-30 14:48:50 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2022-10-20 09:50:02 +00:00
|
|
|
"go.uber.org/zap"
|
2020-08-24 14:56:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceExecutor interface {
|
|
|
|
Create(context.Context, *session.CreateRequestBody) (*session.CreateResponseBody, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type executorSvc struct {
|
|
|
|
exec ServiceExecutor
|
2022-10-20 09:50:02 +00:00
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
respSvc *response.Service
|
|
|
|
|
2022-10-20 09:50:02 +00:00
|
|
|
log *logger.Logger
|
2020-08-24 14:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
|
2022-12-30 14:48:50 +00:00
|
|
|
func NewExecutionService(exec ServiceExecutor, respSvc *response.Service, l *logger.Logger) Server {
|
2020-08-24 14:56:39 +00:00
|
|
|
return &executorSvc{
|
2022-12-30 14:48:50 +00:00
|
|
|
exec: exec,
|
|
|
|
log: l,
|
|
|
|
respSvc: respSvc,
|
2020-08-24 14:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *executorSvc) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
2022-10-20 09:50:02 +00:00
|
|
|
s.log.Debug("serving request...",
|
|
|
|
zap.String("component", "SessionService"),
|
|
|
|
zap.String("request", "Create"),
|
|
|
|
)
|
|
|
|
|
2020-08-24 14:56:39 +00:00
|
|
|
respBody, err := s.exec.Create(ctx, req.GetBody())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute Create request: %w", err)
|
2020-08-24 14:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(session.CreateResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-24 14:56:39 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|