2020-07-10 14:17:51 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2020-07-24 13:54:03 +00:00
|
|
|
"errors"
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/container"
|
2020-07-24 13:54:03 +00:00
|
|
|
eacl "github.com/nspcc-dev/neofs-node/pkg/core/container/acl/extended/storage"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container/storage"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network/transport/grpc"
|
|
|
|
libgrpc "github.com/nspcc-dev/neofs-node/pkg/network/transport/grpc"
|
2020-07-10 14:17:51 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// Service is an interface of the server of Container service.
|
|
|
|
Service interface {
|
|
|
|
grpc.Service
|
|
|
|
container.ServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
// HealthChecker is an interface of node healthiness checking tool.
|
|
|
|
HealthChecker interface {
|
|
|
|
Healthy() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Params groups the parameters of Container service server's constructor.
|
|
|
|
Params struct {
|
|
|
|
Logger *zap.Logger
|
|
|
|
|
|
|
|
Healthy HealthChecker
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
Store storage.Storage
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
ExtendedACLStore eacl.Storage
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cnrService struct {
|
|
|
|
log *zap.Logger
|
|
|
|
|
|
|
|
healthy HealthChecker
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
cnrStore storage.Storage
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
aclStore eacl.Storage
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
var (
|
|
|
|
errEmptyLogger = errors.New("empty log component")
|
|
|
|
errEmptyHealthChecker = errors.New("empty healthy component")
|
2020-07-10 14:17:51 +00:00
|
|
|
)
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
var requestVerifyFunc = libgrpc.VerifyRequestWithSignatures
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
// New is an Container service server's constructor.
|
|
|
|
func New(p Params) (Service, error) {
|
|
|
|
switch {
|
|
|
|
case p.Logger == nil:
|
|
|
|
return nil, errEmptyLogger
|
|
|
|
case p.Store == nil:
|
2020-07-24 13:54:03 +00:00
|
|
|
return nil, storage.ErrNilStorage
|
2020-07-10 14:17:51 +00:00
|
|
|
case p.Healthy == nil:
|
|
|
|
return nil, errEmptyHealthChecker
|
|
|
|
case p.ExtendedACLStore == nil:
|
2020-07-24 13:54:03 +00:00
|
|
|
return nil, eacl.ErrNilStorage
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &cnrService{
|
|
|
|
log: p.Logger,
|
|
|
|
healthy: p.Healthy,
|
|
|
|
cnrStore: p.Store,
|
|
|
|
aclStore: p.ExtendedACLStore,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cnrService) Name() string { return "ContainerService" }
|
|
|
|
|
|
|
|
func (s cnrService) Register(g *grpc.Server) { container.RegisterServiceServer(g, s) }
|