diff --git a/cmd/frostfs-node/netmap.go b/cmd/frostfs-node/netmap.go index 6aff8ddf..2d424eec 100644 --- a/cmd/frostfs-node/netmap.go +++ b/cmd/frostfs-node/netmap.go @@ -374,6 +374,15 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { return c.updateNetMapState(func(*nmClient.UpdatePeerPrm) {}) } +func (c *cfg) GetNetmapStatus() (control.NetmapStatus, uint64, error) { + epoch, err := c.netMapSource.Epoch() + if err != nil { + return control.NetmapStatus_STATUS_UNDEFINED, 0, fmt.Errorf("failed to get current epoch: %w", err) + } + st := c.NetmapStatus() + return st, epoch, nil +} + func (c *cfg) ForceMaintenance() error { return c.setMaintenanceStatus(true) } diff --git a/pkg/services/control/rpc.go b/pkg/services/control/rpc.go index f9397c12..a90e58a6 100644 --- a/pkg/services/control/rpc.go +++ b/pkg/services/control/rpc.go @@ -10,6 +10,7 @@ const serviceName = "control.ControlService" const ( rpcHealthCheck = "HealthCheck" rpcSetNetmapStatus = "SetNetmapStatus" + rpcGetNetmapStatus = "GetNetmapStatus" rpcDropObjects = "DropObjects" rpcListShards = "ListShards" rpcSetShardMode = "SetShardMode" @@ -70,6 +71,26 @@ func SetNetmapStatus( return wResp.message, nil } +// GetNetmapStatus executes ControlService.GetNetmapStatus RPC. +func GetNetmapStatus( + cli *client.Client, + req *GetNetmapStatusRequest, + opts ...client.CallOption, +) (*GetNetmapStatusResponse, error) { + wResp := newResponseWrapper[GetNetmapStatusResponse]() + + wReq := &requestWrapper{ + m: req, + } + + err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcGetNetmapStatus), wReq, wResp, opts...) + if err != nil { + return nil, err + } + + return wResp.message, nil +} + // DropObjects executes ControlService.DropObjects RPC. func DropObjects( cli *client.Client, diff --git a/pkg/services/control/server/audit.go b/pkg/services/control/server/audit.go index 16c04a8c..6443ea37 100644 --- a/pkg/services/control/server/audit.go +++ b/pkg/services/control/server/audit.go @@ -242,6 +242,17 @@ func (a *auditService) SetNetmapStatus(ctx context.Context, req *ctl.SetNetmapSt return res, err } +// GetNetmapStatus implements control.ControlServiceServer. +func (a *auditService) GetNetmapStatus(ctx context.Context, req *ctl.GetNetmapStatusRequest) (*ctl.GetNetmapStatusResponse, error) { + res, err := a.next.GetNetmapStatus(ctx, req) + if !a.enabled.Load() { + return res, err + } + audit.LogRequestWithKey(a.log, ctl.ControlService_GetNetmapStatus_FullMethodName, req.GetSignature().GetKey(), + nil, err == nil) + return res, err +} + // SetShardMode implements control.ControlServiceServer. func (a *auditService) SetShardMode(ctx context.Context, req *ctl.SetShardModeRequest) (*ctl.SetShardModeResponse, error) { res, err := a.next.SetShardMode(ctx, req) diff --git a/pkg/services/control/server/get_netmap_status.go b/pkg/services/control/server/get_netmap_status.go new file mode 100644 index 00000000..1c038253 --- /dev/null +++ b/pkg/services/control/server/get_netmap_status.go @@ -0,0 +1,35 @@ +package control + +import ( + "context" + + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetNetmapStatus gets node status in FrostFS network. +func (s *Server) GetNetmapStatus(_ context.Context, req *control.GetNetmapStatusRequest) (*control.GetNetmapStatusResponse, error) { + if err := s.isValidRequest(req); err != nil { + return nil, status.Error(codes.PermissionDenied, err.Error()) + } + + st, epoch, err := s.nodeState.GetNetmapStatus() + if err != nil { + return nil, err + } + + resp := &control.GetNetmapStatusResponse{ + Body: &control.GetNetmapStatusResponse_Body{ + Status: st, + Epoch: epoch, + }, + } + + if err := ctrlmessage.Sign(s.key, resp); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return resp, nil +} diff --git a/pkg/services/control/server/server.go b/pkg/services/control/server/server.go index 7cfa93f0..f3fe56a4 100644 --- a/pkg/services/control/server/server.go +++ b/pkg/services/control/server/server.go @@ -50,6 +50,8 @@ type NodeState interface { // ForceMaintenance works like SetNetmapStatus(control.NetmapStatus_MAINTENANCE) // but starts local maintenance regardless of the network settings. ForceMaintenance() error + + GetNetmapStatus() (control.NetmapStatus, uint64, error) } // LocalOverrideStorageDecorator interface provides methods to decorate LocalOverrideEngine diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index 9c597bee..727dd121 100644 Binary files a/pkg/services/control/service.pb.go and b/pkg/services/control/service.pb.go differ diff --git a/pkg/services/control/service.proto b/pkg/services/control/service.proto index 94032b34..2cd8434f 100644 --- a/pkg/services/control/service.proto +++ b/pkg/services/control/service.proto @@ -15,6 +15,9 @@ service ControlService { // Sets status of the storage node in FrostFS network map. rpc SetNetmapStatus(SetNetmapStatusRequest) returns (SetNetmapStatusResponse); + // Gets status of the storage node in FrostFS network map. + rpc GetNetmapStatus(GetNetmapStatusRequest) returns (GetNetmapStatusResponse); + // Mark objects to be removed from node's local object storage. rpc DropObjects(DropObjectsRequest) returns (DropObjectsResponse); @@ -156,6 +159,34 @@ message SetNetmapStatusResponse { Signature signature = 2; } +// Get netmap status request. +message GetNetmapStatusRequest { + message Body {} + + // Body of set netmap status request message. + Body body = 1; + + // Body signature. + Signature signature = 2; +} + +// Get netmap status response. +message GetNetmapStatusResponse { + message Body { + // Storage node status in FrostFS network map. + NetmapStatus status = 1; + + // Network map epoch. + uint64 epoch = 2; + } + + // Body of get netmap status response message. + Body body = 1; + + // Body signature. + Signature signature = 2; +} + // Request to drop the objects. message DropObjectsRequest { // Request body structure. diff --git a/pkg/services/control/service_frostfs.pb.go b/pkg/services/control/service_frostfs.pb.go index 9d8d6376..a287606f 100644 Binary files a/pkg/services/control/service_frostfs.pb.go and b/pkg/services/control/service_frostfs.pb.go differ diff --git a/pkg/services/control/service_grpc.pb.go b/pkg/services/control/service_grpc.pb.go index feeee000..fa9de974 100644 Binary files a/pkg/services/control/service_grpc.pb.go and b/pkg/services/control/service_grpc.pb.go differ