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"
|
|
|
|
"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
|
|
|
|
|
|
|
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) {
|
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)
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|