[#45] api-go: Add Object.PutSingle implementation

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-06-30 13:25:01 +03:00
parent 3add88d435
commit b17995a238
4 changed files with 713 additions and 220 deletions

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,7 @@ const (
ObjectService_Search_FullMethodName = "/neo.fs.v2.object.ObjectService/Search"
ObjectService_GetRange_FullMethodName = "/neo.fs.v2.object.ObjectService/GetRange"
ObjectService_GetRangeHash_FullMethodName = "/neo.fs.v2.object.ObjectService/GetRangeHash"
ObjectService_PutSingle_FullMethodName = "/neo.fs.v2.object.ObjectService/PutSingle"
)
// ObjectServiceClient is the client API for ObjectService service.
@ -243,6 +244,40 @@ type ObjectServiceClient interface {
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
GetRangeHash(ctx context.Context, in *GetRangeHashRequest, opts ...grpc.CallOption) (*GetRangeHashResponse, error)
// Put the prepared object into container.
// `ContainerID`, `ObjectID` and `OwnerID` of an object
// MUST be set. Session token MUST be obtained before `PUT SINGLE` operation (see
// session package).
//
// Extended headers can change `Put` behaviour:
// - [ __SYSTEM__NETMAP_EPOCH \
// (`__NEOFS__NETMAP_EPOCH` is deprecated) \
// Will use the requested version of Network Map for object placement
// calculation.
//
// Please refer to detailed `XHeader` description.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS): \
// object has been successfully saved in the container;
// - Common failures (SECTION_FAILURE_COMMON);
// - **ACCESS_DENIED** (2048, SECTION_OBJECT): \
// write access to the container is denied;
// - **LOCKED** (2050, SECTION_OBJECT): \
// placement of an object of type TOMBSTONE that includes at least one locked
// object is prohibited;
// - **LOCK_NON_REGULAR_OBJECT** (2051, SECTION_OBJECT): \
// placement of an object of type LOCK that includes at least one object of
// type other than REGULAR is prohibited;
// - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \
// object storage container not found;
// - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \
// (for trusted object preparation) session private key does not exist or has
//
// been deleted;
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
PutSingle(ctx context.Context, in *PutSingleRequest, opts ...grpc.CallOption) (*PutSingleResponse, error)
}
type objectServiceClient struct {
@ -410,6 +445,15 @@ func (c *objectServiceClient) GetRangeHash(ctx context.Context, in *GetRangeHash
return out, nil
}
func (c *objectServiceClient) PutSingle(ctx context.Context, in *PutSingleRequest, opts ...grpc.CallOption) (*PutSingleResponse, error) {
out := new(PutSingleResponse)
err := c.cc.Invoke(ctx, ObjectService_PutSingle_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ObjectServiceServer is the server API for ObjectService service.
// All implementations should embed UnimplementedObjectServiceServer
// for forward compatibility
@ -625,6 +669,40 @@ type ObjectServiceServer interface {
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
GetRangeHash(context.Context, *GetRangeHashRequest) (*GetRangeHashResponse, error)
// Put the prepared object into container.
// `ContainerID`, `ObjectID` and `OwnerID` of an object
// MUST be set. Session token MUST be obtained before `PUT SINGLE` operation (see
// session package).
//
// Extended headers can change `Put` behaviour:
// - [ __SYSTEM__NETMAP_EPOCH \
// (`__NEOFS__NETMAP_EPOCH` is deprecated) \
// Will use the requested version of Network Map for object placement
// calculation.
//
// Please refer to detailed `XHeader` description.
//
// Statuses:
// - **OK** (0, SECTION_SUCCESS): \
// object has been successfully saved in the container;
// - Common failures (SECTION_FAILURE_COMMON);
// - **ACCESS_DENIED** (2048, SECTION_OBJECT): \
// write access to the container is denied;
// - **LOCKED** (2050, SECTION_OBJECT): \
// placement of an object of type TOMBSTONE that includes at least one locked
// object is prohibited;
// - **LOCK_NON_REGULAR_OBJECT** (2051, SECTION_OBJECT): \
// placement of an object of type LOCK that includes at least one object of
// type other than REGULAR is prohibited;
// - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \
// object storage container not found;
// - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \
// (for trusted object preparation) session private key does not exist or has
//
// been deleted;
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
// provided session token has expired.
PutSingle(context.Context, *PutSingleRequest) (*PutSingleResponse, error)
}
// UnimplementedObjectServiceServer should be embedded to have forward compatible implementations.
@ -652,6 +730,9 @@ func (UnimplementedObjectServiceServer) GetRange(*GetRangeRequest, ObjectService
func (UnimplementedObjectServiceServer) GetRangeHash(context.Context, *GetRangeHashRequest) (*GetRangeHashResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetRangeHash not implemented")
}
func (UnimplementedObjectServiceServer) PutSingle(context.Context, *PutSingleRequest) (*PutSingleResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method PutSingle not implemented")
}
// UnsafeObjectServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to ObjectServiceServer will
@ -807,6 +888,24 @@ func _ObjectService_GetRangeHash_Handler(srv interface{}, ctx context.Context, d
return interceptor(ctx, in, info, handler)
}
func _ObjectService_PutSingle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PutSingleRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ObjectServiceServer).PutSingle(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ObjectService_PutSingle_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ObjectServiceServer).PutSingle(ctx, req.(*PutSingleRequest))
}
return interceptor(ctx, in, info, handler)
}
// ObjectService_ServiceDesc is the grpc.ServiceDesc for ObjectService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -826,6 +925,10 @@ var ObjectService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetRangeHash",
Handler: _ObjectService_GetRangeHash_Handler,
},
{
MethodName: "PutSingle",
Handler: _ObjectService_PutSingle_Handler,
},
},
Streams: []grpc.StreamDesc{
{

View file

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc-gen-go v1.30.0
// protoc v3.21.9
// source: object/grpc/types.proto

View file

@ -301,6 +301,17 @@ type GetRangeHashResponse struct {
session.ResponseHeaders
}
type PutSingleRequestBody struct {
object *Object
copyNum []uint32
}
type PutSingleRequest struct {
body *PutSingleRequestBody
session.RequestHeaders
}
const (
TypeRegular Type = iota
TypeTombstone
@ -1405,3 +1416,37 @@ func (r *GetRangeHashResponse) GetBody() *GetRangeHashResponseBody {
func (r *GetRangeHashResponse) SetBody(v *GetRangeHashResponseBody) {
r.body = v
}
func (r *PutSingleRequest) GetBody() *PutSingleRequestBody {
if r != nil {
return r.body
}
return nil
}
func (r *PutSingleRequest) SetBody(v *PutSingleRequestBody) {
r.body = v
}
func (b *PutSingleRequestBody) GetObject() *Object {
if b == nil {
return nil
}
return b.object
}
func (b *PutSingleRequestBody) SetObject(o *Object) {
b.object = o
}
func (b *PutSingleRequestBody) GetCopiesNumber() []uint32 {
if b == nil {
return nil
}
return b.copyNum
}
func (b *PutSingleRequestBody) SetCopiesNumber(v []uint32) {
b.copyNum = v
}