2022-09-20 13:06:14 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
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"
|
2022-09-20 13:06:14 +00:00
|
|
|
)
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// interface of FrostFS API server. Exists for test purposes only.
|
|
|
|
type frostFSAPIServer interface {
|
2022-09-20 13:06:14 +00:00
|
|
|
netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error)
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// wrapper over real client connection which communicates over FrostFS API protocol.
|
|
|
|
// Provides frostFSAPIServer for Client instances used in real applications.
|
2022-09-20 13:06:14 +00:00
|
|
|
type coreServer client.Client
|
|
|
|
|
|
|
|
// unifies errors of all RPC.
|
|
|
|
func rpcErr(e error) error {
|
|
|
|
return fmt.Errorf("rpc failure: %w", e)
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// executes NetmapService.NetmapSnapshot RPC declared in FrostFS API protocol
|
2022-09-20 13:06:14 +00:00
|
|
|
// using underlying client.Client.
|
|
|
|
func (x *coreServer) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
|
|
|
|
resp, err := rpcapi.NetMapSnapshot((*client.Client)(x), &req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, rpcErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|