forked from TrueCloudLab/frostfs-http-gw
[#232] Use contract to get container info
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
parent
dbb1bcad00
commit
96a22d98f2
13 changed files with 229 additions and 44 deletions
|
@ -167,12 +167,18 @@ type ContainerResolver interface {
|
|||
Resolve(ctx context.Context, zone, name string) (*cid.ID, error)
|
||||
}
|
||||
|
||||
type ContainerContract interface {
|
||||
// GetContainerByID reads a container from contract by ID.
|
||||
GetContainerByID(cid.ID) (*container.Container, error)
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
log *zap.Logger
|
||||
frostfs FrostFS
|
||||
ownerID *user.ID
|
||||
config Config
|
||||
containerResolver ContainerResolver
|
||||
cnrContract ContainerContract
|
||||
tree *tree.Tree
|
||||
cache *cache.BucketCache
|
||||
workerPool *ants.Pool
|
||||
|
@ -190,7 +196,7 @@ type AppParams struct {
|
|||
CORSCache *cache.CORSCache
|
||||
}
|
||||
|
||||
func New(params *AppParams, config Config, tree *tree.Tree, workerPool *ants.Pool) *Handler {
|
||||
func New(params *AppParams, config Config, tree *tree.Tree, rpcCli ContainerContract, workerPool *ants.Pool) *Handler {
|
||||
return &Handler{
|
||||
log: params.Logger,
|
||||
frostfs: params.FrostFS,
|
||||
|
@ -202,6 +208,7 @@ func New(params *AppParams, config Config, tree *tree.Tree, workerPool *ants.Poo
|
|||
workerPool: workerPool,
|
||||
corsCnrID: params.CORSCnrID,
|
||||
corsCache: params.CORSCache,
|
||||
cnrContract: rpcCli,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,43 +315,7 @@ func (h *Handler) getBucketInfo(ctx context.Context, containerName string) (*dat
|
|||
return nil, fmt.Errorf("resolve container: %w", err)
|
||||
}
|
||||
|
||||
bktInfo, err := h.readContainer(ctx, *cnrID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read container: %w", err)
|
||||
}
|
||||
|
||||
if err = h.cache.Put(bktInfo); err != nil {
|
||||
h.reqLogger(ctx).Warn(logs.CouldntPutBucketIntoCache,
|
||||
zap.String("bucket name", bktInfo.Name),
|
||||
zap.Stringer("bucket cid", bktInfo.CID),
|
||||
zap.Error(err),
|
||||
logs.TagField(logs.TagDatapath))
|
||||
}
|
||||
|
||||
return bktInfo, nil
|
||||
}
|
||||
|
||||
func (h *Handler) readContainer(ctx context.Context, cnrID cid.ID) (*data.BucketInfo, error) {
|
||||
prm := PrmContainer{ContainerID: cnrID}
|
||||
res, err := h.frostfs.Container(ctx, prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get frostfs container '%s': %w", cnrID.String(), err)
|
||||
}
|
||||
|
||||
bktInfo := &data.BucketInfo{
|
||||
CID: cnrID,
|
||||
Name: cnrID.EncodeToString(),
|
||||
}
|
||||
|
||||
if domain := container.ReadDomain(*res); domain.Name() != "" {
|
||||
bktInfo.Name = domain.Name()
|
||||
bktInfo.Zone = domain.Zone()
|
||||
}
|
||||
|
||||
bktInfo.HomomorphicHashDisabled = container.IsHomomorphicHashingDisabled(*res)
|
||||
bktInfo.PlacementPolicy = res.PlacementPolicy()
|
||||
|
||||
return bktInfo, err
|
||||
return h.containerInfo(ctx, *cnrID)
|
||||
}
|
||||
|
||||
type ListFunc func(ctx context.Context, bucketInfo *data.BucketInfo, prefix string) (*GetObjectsResponse, error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue