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
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2022-12-30 14:48:50 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
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) {
|
2023-04-13 12:51:36 +00:00
|
|
|
s.log.Debug(logs.ServingRequest,
|
2022-10-20 09:50:02 +00:00
|
|
|
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
|
|
|
|
}
|