2023-04-13 05:15:20 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-13 05:52:14 +00:00
|
|
|
"fmt"
|
2023-04-13 05:15:20 +00:00
|
|
|
|
|
|
|
v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
|
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
2023-04-13 05:52:14 +00:00
|
|
|
v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature"
|
2023-04-13 05:15:20 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrmAnnounceSpace groups parameters of ContainerAnnounceUsedSpace operation.
|
|
|
|
type PrmAnnounceSpace struct {
|
2023-09-04 16:53:34 +00:00
|
|
|
XHeaders []string
|
2023-04-13 05:15:20 +00:00
|
|
|
|
2023-09-04 16:53:34 +00:00
|
|
|
Announcements []container.SizeEstimation
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetValues sets values describing volume of space that is used for the container objects.
|
|
|
|
// Required parameter. Must not be empty.
|
|
|
|
//
|
|
|
|
// Must not be mutated before the end of the operation.
|
2023-09-04 16:53:34 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmAnnounceSpace.Announcements instead.
|
2023-04-13 05:15:20 +00:00
|
|
|
func (x *PrmAnnounceSpace) SetValues(vs []container.SizeEstimation) {
|
2023-09-04 16:53:34 +00:00
|
|
|
x.Announcements = vs
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 07:31:07 +00:00
|
|
|
func (x *PrmAnnounceSpace) buildRequest(c *Client) (*v2container.AnnounceUsedSpaceRequest, error) {
|
2023-09-04 16:53:34 +00:00
|
|
|
if len(x.Announcements) == 0 {
|
2023-04-13 05:33:17 +00:00
|
|
|
return nil, errorMissingAnnouncements
|
|
|
|
}
|
|
|
|
|
2023-09-04 16:53:34 +00:00
|
|
|
v2announce := make([]v2container.UsedSpaceAnnouncement, len(x.Announcements))
|
|
|
|
for i := range x.Announcements {
|
|
|
|
x.Announcements[i].WriteToV2(&v2announce[i])
|
2023-04-13 05:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.AnnounceUsedSpaceRequestBody)
|
|
|
|
reqBody.SetAnnouncements(v2announce)
|
|
|
|
|
|
|
|
var req v2container.AnnounceUsedSpaceRequest
|
|
|
|
req.SetBody(reqBody)
|
2023-04-13 05:52:14 +00:00
|
|
|
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
2023-04-13 05:33:17 +00:00
|
|
|
return &req, nil
|
|
|
|
}
|
|
|
|
|
2023-04-13 05:15:20 +00:00
|
|
|
// ResAnnounceSpace groups resulting values of ContainerAnnounceUsedSpace operation.
|
|
|
|
type ResAnnounceSpace struct {
|
|
|
|
statusRes
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerAnnounceUsedSpace sends request to announce volume of the space used for the container objects.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2023-09-12 15:57:04 +00:00
|
|
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are included in the returned result structure,
|
|
|
|
// otherwise, are also returned as `error`.
|
2023-04-13 05:15:20 +00:00
|
|
|
//
|
|
|
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// At this moment success can not be checked.
|
|
|
|
//
|
|
|
|
// Returns an error if parameters are set incorrectly (see PrmAnnounceSpace docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
|
|
|
func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) (*ResAnnounceSpace, error) {
|
2023-04-17 07:31:07 +00:00
|
|
|
req, err := prm.buildRequest(c)
|
2023-04-13 05:33:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 05:52:14 +00:00
|
|
|
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
|
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 05:52:14 +00:00
|
|
|
resp, err := rpcapi.AnnounceUsedSpace(&c.c, req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 05:52:14 +00:00
|
|
|
var res ResAnnounceSpace
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
return &res, err
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|