2020-10-08 13:13:28 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/netmap"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
|
|
|
|
netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap/grpc"
|
2020-10-08 13:13:28 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Server wraps FrostFS API Netmap service and
|
2020-10-08 13:13:28 +00:00
|
|
|
// provides gRPC Netmap service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv netmapsvc.Server
|
2020-10-08 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2021-03-15 10:53:08 +00:00
|
|
|
func New(c netmapsvc.Server) *Server {
|
2020-10-08 13:13:28 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocalNodeInfo converts gRPC request message and passes it to internal netmap service.
|
|
|
|
func (s *Server) LocalNodeInfo(
|
|
|
|
ctx context.Context,
|
2023-10-31 11:56:55 +00:00
|
|
|
req *netmapGRPC.LocalNodeInfoRequest,
|
|
|
|
) (*netmapGRPC.LocalNodeInfoResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
nodeInfoReq := new(netmap.LocalNodeInfoRequest)
|
|
|
|
if err := nodeInfoReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.LocalNodeInfo(ctx, nodeInfoReq)
|
2020-10-08 13:13:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*netmapGRPC.LocalNodeInfoResponse), nil
|
2020-10-08 13:13:28 +00:00
|
|
|
}
|
2021-02-19 08:01:37 +00:00
|
|
|
|
|
|
|
// NetworkInfo converts gRPC request message and passes it to internal netmap service.
|
|
|
|
func (s *Server) NetworkInfo(ctx context.Context, req *netmapGRPC.NetworkInfoRequest) (*netmapGRPC.NetworkInfoResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
netInfoReq := new(netmap.NetworkInfoRequest)
|
|
|
|
if err := netInfoReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.NetworkInfo(ctx, netInfoReq)
|
2021-02-19 08:01:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*netmapGRPC.NetworkInfoResponse), nil
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|
2022-09-17 12:37:01 +00:00
|
|
|
|
|
|
|
// NetmapSnapshot converts gRPC request message and passes it to internal netmap service.
|
|
|
|
func (s *Server) NetmapSnapshot(ctx context.Context, req *netmapGRPC.NetmapSnapshotRequest) (*netmapGRPC.NetmapSnapshotResponse, error) {
|
|
|
|
snapshotReq := new(netmap.SnapshotRequest)
|
|
|
|
if err := snapshotReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Snapshot(ctx, snapshotReq)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.ToGRPCMessage().(*netmapGRPC.NetmapSnapshotResponse), nil
|
|
|
|
}
|