[#245] v2/container: Add AnnounceUsedSpace method

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-01-21 17:57:04 +03:00 committed by Alex Vanin
parent 5d9ef5feec
commit d2ee6b469a
11 changed files with 1351 additions and 185 deletions

View file

@ -23,6 +23,8 @@ type Client struct {
cSetEACL *setEACLClient
cGetEACL *getEACLClient
cAnnounce *announceUsedSpaceClient
}
// Option represents Client option.
@ -94,6 +96,14 @@ type getEACLClient struct {
responseConverter func(interface{}) *GetExtendedACLResponse
}
type announceUsedSpaceClient struct {
requestConverter func(request *AnnounceUsedSpaceRequest) interface{}
caller func(context.Context, interface{}) (interface{}, error)
responseConverter func(interface{}) *AnnounceUsedSpaceResponse
}
// Put sends PutRequest over the network and returns PutResponse.
//
// It returns any error encountered during the call.
@ -166,6 +176,19 @@ func (c *Client) GetExtendedACL(ctx context.Context, req *GetExtendedACLRequest)
return c.cGetEACL.responseConverter(resp), nil
}
// AnnounceUsedSpace sends AnnounceUsedSpaceRequest over the network and returns
// AnnounceUsedSpaceResponse.
//
// It returns any error encountered during the call.
func (c *Client) AnnounceUsedSpace(ctx context.Context, req *AnnounceUsedSpaceRequest) (*AnnounceUsedSpaceResponse, error) {
resp, err := c.cAnnounce.caller(ctx, c.cAnnounce.requestConverter(req))
if err != nil {
return nil, errors.Wrap(err, "could not send announce used space request")
}
return c.cAnnounce.responseConverter(resp), nil
}
func defaultCfg() *cfg {
return &cfg{
proto: client.ProtoGRPC,
@ -255,6 +278,17 @@ func NewClient(opts ...Option) (*Client, error) {
return GetExtendedACLResponseFromGRPCMessage(resp.(*container.GetExtendedACLResponse))
},
},
cAnnounce: &announceUsedSpaceClient{
requestConverter: func(req *AnnounceUsedSpaceRequest) interface{} {
return AnnounceUsedSpaceRequestToGRPCMessage(req)
},
caller: func(ctx context.Context, req interface{}) (interface{}, error) {
return c.AnnounceUsedSpace(ctx, req.(*container.AnnounceUsedSpaceRequest))
},
responseConverter: func(resp interface{}) *AnnounceUsedSpaceResponse {
return AnnounceUsedSpaceResponseFromGRPCMessage(resp.(*container.AnnounceUsedSpaceResponse))
},
},
}, nil
default:
err = client.ErrProtoUnsupported