forked from TrueCloudLab/frostfs-node
[#60] control: Add GetNetmapStatus method
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
9ac74efc41
commit
a83eeddb1d
9 changed files with 109 additions and 0 deletions
|
@ -374,6 +374,15 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
|
||||||
return c.updateNetMapState(func(*nmClient.UpdatePeerPrm) {})
|
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 {
|
func (c *cfg) ForceMaintenance() error {
|
||||||
return c.setMaintenanceStatus(true)
|
return c.setMaintenanceStatus(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ const serviceName = "control.ControlService"
|
||||||
const (
|
const (
|
||||||
rpcHealthCheck = "HealthCheck"
|
rpcHealthCheck = "HealthCheck"
|
||||||
rpcSetNetmapStatus = "SetNetmapStatus"
|
rpcSetNetmapStatus = "SetNetmapStatus"
|
||||||
|
rpcGetNetmapStatus = "GetNetmapStatus"
|
||||||
rpcDropObjects = "DropObjects"
|
rpcDropObjects = "DropObjects"
|
||||||
rpcListShards = "ListShards"
|
rpcListShards = "ListShards"
|
||||||
rpcSetShardMode = "SetShardMode"
|
rpcSetShardMode = "SetShardMode"
|
||||||
|
@ -70,6 +71,26 @@ func SetNetmapStatus(
|
||||||
return wResp.message, nil
|
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.
|
// DropObjects executes ControlService.DropObjects RPC.
|
||||||
func DropObjects(
|
func DropObjects(
|
||||||
cli *client.Client,
|
cli *client.Client,
|
||||||
|
|
|
@ -242,6 +242,17 @@ func (a *auditService) SetNetmapStatus(ctx context.Context, req *ctl.SetNetmapSt
|
||||||
return res, err
|
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.
|
// SetShardMode implements control.ControlServiceServer.
|
||||||
func (a *auditService) SetShardMode(ctx context.Context, req *ctl.SetShardModeRequest) (*ctl.SetShardModeResponse, error) {
|
func (a *auditService) SetShardMode(ctx context.Context, req *ctl.SetShardModeRequest) (*ctl.SetShardModeResponse, error) {
|
||||||
res, err := a.next.SetShardMode(ctx, req)
|
res, err := a.next.SetShardMode(ctx, req)
|
||||||
|
|
35
pkg/services/control/server/get_netmap_status.go
Normal file
35
pkg/services/control/server/get_netmap_status.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -50,6 +50,8 @@ type NodeState interface {
|
||||||
// ForceMaintenance works like SetNetmapStatus(control.NetmapStatus_MAINTENANCE)
|
// ForceMaintenance works like SetNetmapStatus(control.NetmapStatus_MAINTENANCE)
|
||||||
// but starts local maintenance regardless of the network settings.
|
// but starts local maintenance regardless of the network settings.
|
||||||
ForceMaintenance() error
|
ForceMaintenance() error
|
||||||
|
|
||||||
|
GetNetmapStatus() (control.NetmapStatus, uint64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalOverrideStorageDecorator interface provides methods to decorate LocalOverrideEngine
|
// LocalOverrideStorageDecorator interface provides methods to decorate LocalOverrideEngine
|
||||||
|
|
BIN
pkg/services/control/service.pb.go
generated
BIN
pkg/services/control/service.pb.go
generated
Binary file not shown.
|
@ -15,6 +15,9 @@ service ControlService {
|
||||||
// Sets status of the storage node in FrostFS network map.
|
// Sets status of the storage node in FrostFS network map.
|
||||||
rpc SetNetmapStatus(SetNetmapStatusRequest) returns (SetNetmapStatusResponse);
|
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.
|
// Mark objects to be removed from node's local object storage.
|
||||||
rpc DropObjects(DropObjectsRequest) returns (DropObjectsResponse);
|
rpc DropObjects(DropObjectsRequest) returns (DropObjectsResponse);
|
||||||
|
|
||||||
|
@ -156,6 +159,34 @@ message SetNetmapStatusResponse {
|
||||||
Signature signature = 2;
|
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.
|
// Request to drop the objects.
|
||||||
message DropObjectsRequest {
|
message DropObjectsRequest {
|
||||||
// Request body structure.
|
// Request body structure.
|
||||||
|
|
BIN
pkg/services/control/service_frostfs.pb.go
generated
BIN
pkg/services/control/service_frostfs.pb.go
generated
Binary file not shown.
BIN
pkg/services/control/service_grpc.pb.go
generated
BIN
pkg/services/control/service_grpc.pb.go
generated
Binary file not shown.
Loading…
Reference in a new issue