2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-20 11:28:21 +00:00
|
|
|
"fmt"
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
v2netmap "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
|
|
|
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
|
|
|
v2session "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/signature"
|
2023-03-07 11:20:03 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
2021-11-09 08:07:49 +00:00
|
|
|
)
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmEndpointInfo groups parameters of EndpointInfo operation.
|
2022-03-03 11:04:53 +00:00
|
|
|
type PrmEndpointInfo struct {
|
2023-09-04 16:55:23 +00:00
|
|
|
XHeaders []string
|
2022-03-03 11:04:53 +00:00
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
2023-04-14 13:32:22 +00:00
|
|
|
func (x *PrmEndpointInfo) buildRequest(c *Client) (*v2netmap.LocalNodeInfoRequest, error) {
|
|
|
|
meta := new(v2session.RequestMetaHeader)
|
2023-09-04 16:55:23 +00:00
|
|
|
writeXHeadersToMeta(x.XHeaders, meta)
|
2023-04-14 13:32:22 +00:00
|
|
|
|
|
|
|
req := new(v2netmap.LocalNodeInfoRequest)
|
|
|
|
req.SetBody(new(v2netmap.LocalNodeInfoRequestBody))
|
|
|
|
c.prepareRequest(req, meta)
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResEndpointInfo group resulting values of EndpointInfo operation.
|
|
|
|
type ResEndpointInfo struct {
|
2021-12-02 12:21:54 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
version version.Version
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
ni netmap.NodeInfo
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// LatestVersion returns latest FrostFS API protocol's version in use.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResEndpointInfo) LatestVersion() version.Version {
|
2021-12-02 12:21:54 +00:00
|
|
|
return x.version
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// NodeInfo returns information about the FrostFS node served on the remote endpoint.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResEndpointInfo) NodeInfo() netmap.NodeInfo {
|
2021-12-02 12:21:54 +00:00
|
|
|
return x.ni
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// EndpointInfo requests information about the storage node served on the remote endpoint.
|
|
|
|
//
|
|
|
|
// Method can be used as a health check to see if node is alive and responds to requests.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2023-09-15 15:52:08 +00:00
|
|
|
// If PrmInit.DisableFrostFSFailuresResolution has been called, unsuccessful
|
2023-09-12 15:57:04 +00:00
|
|
|
// FrostFS status codes are included in the returned result structure,
|
|
|
|
// otherwise, are also returned as `error`.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmEndpointInfo docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResEndpointInfo.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
|
2023-04-14 13:32:22 +00:00
|
|
|
req, err := prm.buildRequest(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 12:18:07 +00:00
|
|
|
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
|
2023-04-14 13:32:22 +00:00
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.LocalNodeInfo(&c.c, req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2023-04-14 13:32:22 +00:00
|
|
|
|
|
|
|
var res ResEndpointInfo
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
|
|
|
return &res, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 13:32:22 +00:00
|
|
|
body := resp.GetBody()
|
|
|
|
|
|
|
|
const fieldVersion = "version"
|
|
|
|
|
|
|
|
verV2 := body.GetVersion()
|
|
|
|
if verV2 == nil {
|
|
|
|
return nil, newErrMissingResponseField(fieldVersion)
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2023-04-14 13:32:22 +00:00
|
|
|
if err := res.version.ReadFromV2(*verV2); err != nil {
|
|
|
|
return nil, newErrInvalidResponseField(fieldVersion, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
const fieldNodeInfo = "node info"
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2023-04-14 13:32:22 +00:00
|
|
|
nodeInfoV2 := body.GetNodeInfo()
|
|
|
|
if nodeInfoV2 == nil {
|
|
|
|
return nil, newErrMissingResponseField(fieldNodeInfo)
|
|
|
|
}
|
|
|
|
if err := res.ni.ReadFromV2(*nodeInfoV2); err != nil {
|
|
|
|
return nil, newErrInvalidResponseField(fieldNodeInfo, err)
|
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmNetworkInfo groups parameters of NetworkInfo operation.
|
2022-03-03 11:04:53 +00:00
|
|
|
type PrmNetworkInfo struct {
|
2023-09-04 16:55:23 +00:00
|
|
|
XHeaders []string
|
2022-03-03 11:04:53 +00:00
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
2023-04-14 12:56:40 +00:00
|
|
|
func (x PrmNetworkInfo) buildRequest(c *Client) (*v2netmap.NetworkInfoRequest, error) {
|
|
|
|
meta := new(v2session.RequestMetaHeader)
|
2023-09-04 16:55:23 +00:00
|
|
|
writeXHeadersToMeta(x.XHeaders, meta)
|
2023-04-14 12:56:40 +00:00
|
|
|
|
|
|
|
var req v2netmap.NetworkInfoRequest
|
|
|
|
req.SetBody(new(v2netmap.NetworkInfoRequestBody))
|
|
|
|
c.prepareRequest(&req, meta)
|
|
|
|
return &req, nil
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResNetworkInfo groups resulting values of NetworkInfo operation.
|
|
|
|
type ResNetworkInfo struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
info netmap.NetworkInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// Info returns structured information about the FrostFS network.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResNetworkInfo) Info() netmap.NetworkInfo {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.info
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// NetworkInfo requests information about the FrostFS network of which the remote server is a part.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2023-09-15 15:52:08 +00:00
|
|
|
// If PrmInit.DisableFrostFSFailuresResolution has been called, unsuccessful
|
2023-09-12 15:57:04 +00:00
|
|
|
// FrostFS status codes are included in the returned result structure,
|
|
|
|
// otherwise, are also returned as `error`.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmNetworkInfo docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResNetworkInfo.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
|
2023-04-14 12:56:40 +00:00
|
|
|
req, err := prm.buildRequest(c)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2023-11-13 12:18:07 +00:00
|
|
|
if err := signature.SignServiceMessage(&c.prm.Key, req); err != nil {
|
2023-04-14 12:56:40 +00:00
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2023-04-14 12:56:40 +00:00
|
|
|
resp, err := rpcapi.NetworkInfo(&c.c, req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2023-04-14 12:56:40 +00:00
|
|
|
var res ResNetworkInfo
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
|
|
|
return &res, err
|
|
|
|
}
|
2022-08-05 07:56:49 +00:00
|
|
|
|
2023-04-14 12:56:40 +00:00
|
|
|
const fieldNetInfo = "network info"
|
2022-06-07 08:25:34 +00:00
|
|
|
|
2023-04-14 12:56:40 +00:00
|
|
|
netInfoV2 := resp.GetBody().GetNetworkInfo()
|
|
|
|
if netInfoV2 == nil {
|
|
|
|
return nil, newErrMissingResponseField(fieldNetInfo)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
2023-04-14 12:56:40 +00:00
|
|
|
if err := res.info.ReadFromV2(*netInfoV2); err != nil {
|
|
|
|
return nil, newErrInvalidResponseField(fieldNetInfo, err)
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
|
|
|
// PrmNetMapSnapshot groups parameters of NetMapSnapshot operation.
|
2023-11-21 09:57:35 +00:00
|
|
|
type PrmNetMapSnapshot struct{}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
|
|
|
// ResNetMapSnapshot groups resulting values of NetMapSnapshot operation.
|
|
|
|
type ResNetMapSnapshot struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
netMap netmap.NetMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMap returns current server's local network map.
|
|
|
|
func (x ResNetMapSnapshot) NetMap() netmap.NetMap {
|
|
|
|
return x.netMap
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMapSnapshot requests current network view of the remote server.
|
|
|
|
//
|
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2023-09-15 15:52:08 +00:00
|
|
|
// If PrmInit.DisableFrostFSFailuresResolution has been called, unsuccessful
|
2023-09-12 15:57:04 +00:00
|
|
|
// FrostFS status codes are included in the returned result structure,
|
|
|
|
// otherwise, are also returned as `error`.
|
2022-09-17 10:07:56 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly.
|
2022-09-17 10:07:56 +00:00
|
|
|
// Context is required and MUST NOT be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResNetMapSnapshot.
|
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2022-09-20 11:28:21 +00:00
|
|
|
func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResNetMapSnapshot, error) {
|
|
|
|
// form request body
|
|
|
|
var body v2netmap.SnapshotRequestBody
|
|
|
|
|
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
|
|
|
|
2022-09-17 10:07:56 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.SnapshotRequest
|
2022-09-20 11:28:21 +00:00
|
|
|
req.SetBody(&body)
|
|
|
|
c.prepareRequest(&req, &meta)
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2023-11-13 12:18:07 +00:00
|
|
|
err := signature.SignServiceMessage(&c.prm.Key, &req)
|
2022-09-20 11:28:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 13:06:14 +00:00
|
|
|
resp, err := c.server.netMapSnapshot(ctx, req)
|
2022-09-20 11:28:21 +00:00
|
|
|
if err != nil {
|
2022-09-20 13:06:14 +00:00
|
|
|
return nil, err
|
2022-09-20 11:28:21 +00:00
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
var res ResNetMapSnapshot
|
|
|
|
res.st, err = c.processResponse(resp)
|
2024-09-24 13:31:56 +00:00
|
|
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
|
|
|
return &res, err
|
2022-09-20 11:28:21 +00:00
|
|
|
}
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
const fieldNetMap = "network map"
|
2022-09-17 10:07:56 +00:00
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
netMapV2 := resp.GetBody().NetMap()
|
|
|
|
if netMapV2 == nil {
|
|
|
|
return nil, newErrMissingResponseField(fieldNetMap)
|
2022-09-17 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 11:28:21 +00:00
|
|
|
err = res.netMap.ReadFromV2(*netMapV2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, newErrInvalidResponseField(fieldNetMap, err)
|
2022-09-17 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|