2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
|
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
2021-11-16 18:15:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-11-09 08:07:49 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
|
|
|
)
|
|
|
|
|
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 {
|
|
|
|
prmCommonMeta
|
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
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
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
version *version.Version
|
|
|
|
|
|
|
|
ni *netmap.NodeInfo
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// LatestVersion returns latest NeoFS API protocol's version in use.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2022-02-17 16:10: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-02-17 16:10:49 +00:00
|
|
|
func (x *ResEndpointInfo) setLatestVersion(ver *version.Version) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.version = ver
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// NodeInfo returns information about the NeoFS node served on the remote endpoint.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2022-02-17 16:10: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
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *ResEndpointInfo) setNodeInfo(info *netmap.NodeInfo) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.ni = info
|
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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics 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:
|
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) EndpointInfo(ctx context.Context, prm PrmEndpointInfo) (*ResEndpointInfo, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check context
|
|
|
|
if ctx == nil {
|
|
|
|
panic(panicMsgMissingContext)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.LocalNodeInfoRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResEndpointInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
|
|
|
return rpcapi.LocalNodeInfo(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2netmap.LocalNodeInfoResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
body := resp.GetBody()
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
res.setLatestVersion(version.NewFromV2(body.GetVersion()))
|
|
|
|
res.setNodeInfo(netmap.NewNodeInfoFromV2(body.GetNodeInfo()))
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
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 {
|
|
|
|
prmCommonMeta
|
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
info *netmap.NetworkInfo
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Info returns structured information about the NeoFS network.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x ResNetworkInfo) Info() *netmap.NetworkInfo {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.info
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *ResNetworkInfo) setInfo(info *netmap.NetworkInfo) {
|
2021-11-16 18:17:25 +00:00
|
|
|
x.info = info
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// NetworkInfo requests information about the NeoFS 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Immediately panics 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:
|
|
|
|
// - global (see Client docs).
|
2022-03-03 11:04:53 +00:00
|
|
|
func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetworkInfo, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check context
|
|
|
|
if ctx == nil {
|
|
|
|
panic(panicMsgMissingContext)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2netmap.NetworkInfoRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResNetworkInfo
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
|
|
|
return rpcapi.NetworkInfo(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2netmap.NetworkInfoResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
res.setInfo(netmap.NewNetworkInfoFromV2(resp.GetBody().GetNetworkInfo()))
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|