2022-10-14 09:35:19 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-10-14 09:35:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NodeState is storage node state processed by Object service.
|
|
|
|
type NodeState interface {
|
|
|
|
// IsMaintenance checks if node is under maintenance. Node MUST NOT serve
|
|
|
|
// local object operations. Node MUST respond with apistatus.NodeUnderMaintenance
|
|
|
|
// error if IsMaintenance returns true.
|
|
|
|
IsMaintenance() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Common is an Object API ServiceServer which encapsulates logic spread to all
|
|
|
|
// object operations.
|
|
|
|
//
|
|
|
|
// If underlying NodeState.IsMaintenance returns true, all operations are
|
|
|
|
// immediately failed with apistatus.NodeUnderMaintenance.
|
|
|
|
type Common struct {
|
|
|
|
state NodeState
|
|
|
|
|
|
|
|
nextHandler ServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initializes the Common instance.
|
|
|
|
func (x *Common) Init(state NodeState, nextHandler ServiceServer) {
|
|
|
|
x.state = state
|
|
|
|
x.nextHandler = nextHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Common) Get(req *objectV2.GetRequest, stream GetObjectStream) error {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.Get(req, stream)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (x *Common) Put(ctx context.Context) (PutObjectStream, error) {
|
2022-10-14 09:35:19 +00:00
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
return x.nextHandler.Put(ctx)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func (x *Common) Patch(ctx context.Context) (PatchObjectStream, error) {
|
2024-08-12 10:01:57 +00:00
|
|
|
if x.state.IsMaintenance() {
|
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
return x.nextHandler.Patch(ctx)
|
2024-08-12 10:01:57 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 09:35:19 +00:00
|
|
|
func (x *Common) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.Head(ctx, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Common) Search(req *objectV2.SearchRequest, stream SearchStream) error {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.Search(req, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Common) Delete(ctx context.Context, req *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.Delete(ctx, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Common) GetRange(req *objectV2.GetRangeRequest, stream GetObjectRangeStream) error {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.GetRange(req, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *Common) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
2022-10-14 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.GetRangeHash(ctx, req)
|
|
|
|
}
|
2023-07-03 08:36:20 +00:00
|
|
|
|
|
|
|
func (x *Common) PutSingle(ctx context.Context, req *objectV2.PutSingleRequest) (*objectV2.PutSingleResponse, error) {
|
|
|
|
if x.state.IsMaintenance() {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.NodeUnderMaintenance)
|
2023-07-03 08:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x.nextHandler.PutSingle(ctx, req)
|
|
|
|
}
|