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-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/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
|
|
|
|
|
|
|
log *logger.Logger
|
2020-08-24 14:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
|
2022-10-20 09:50:02 +00:00
|
|
|
func NewExecutionService(exec ServiceExecutor, l *logger.Logger) Server {
|
2020-08-24 14:56:39 +00:00
|
|
|
return &executorSvc{
|
2020-10-22 11:12:35 +00:00
|
|
|
exec: exec,
|
2022-10-20 09:50:02 +00:00
|
|
|
log: l,
|
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)
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|