forked from TrueCloudLab/frostfs-node
[#922] control: Extend api with ListOverrideDefinedTargets
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
95e15f499f
commit
9916598dfb
6 changed files with 113 additions and 18 deletions
|
@ -8,23 +8,24 @@ import (
|
||||||
const serviceName = "control.ControlService"
|
const serviceName = "control.ControlService"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rpcHealthCheck = "HealthCheck"
|
rpcHealthCheck = "HealthCheck"
|
||||||
rpcSetNetmapStatus = "SetNetmapStatus"
|
rpcSetNetmapStatus = "SetNetmapStatus"
|
||||||
rpcDropObjects = "DropObjects"
|
rpcDropObjects = "DropObjects"
|
||||||
rpcListShards = "ListShards"
|
rpcListShards = "ListShards"
|
||||||
rpcSetShardMode = "SetShardMode"
|
rpcSetShardMode = "SetShardMode"
|
||||||
rpcSynchronizeTree = "SynchronizeTree"
|
rpcSynchronizeTree = "SynchronizeTree"
|
||||||
rpcEvacuateShard = "EvacuateShard"
|
rpcEvacuateShard = "EvacuateShard"
|
||||||
rpcStartShardEvacuation = "StartShardEvacuation"
|
rpcStartShardEvacuation = "StartShardEvacuation"
|
||||||
rpcGetShardEvacuationStatus = "GetShardEvacuationStatus"
|
rpcGetShardEvacuationStatus = "GetShardEvacuationStatus"
|
||||||
rpcStopShardEvacuation = "StopShardEvacuation"
|
rpcStopShardEvacuation = "StopShardEvacuation"
|
||||||
rpcFlushCache = "FlushCache"
|
rpcFlushCache = "FlushCache"
|
||||||
rpcDoctor = "Doctor"
|
rpcDoctor = "Doctor"
|
||||||
rpcAddChainLocalOverride = "AddChainLocalOverride"
|
rpcAddChainLocalOverride = "AddChainLocalOverride"
|
||||||
rpcGetChainLocalOverride = "GetChainLocalOverride"
|
rpcGetChainLocalOverride = "GetChainLocalOverride"
|
||||||
rpcListChainLocalOverrides = "ListChainLocalOverrides"
|
rpcListChainLocalOverrides = "ListChainLocalOverrides"
|
||||||
rpcRemoveChainLocalOverride = "RemoveChainLocalOverride"
|
rpcRemoveChainLocalOverride = "RemoveChainLocalOverride"
|
||||||
rpcSealWriteCache = "SealWriteCache"
|
rpcSealWriteCache = "SealWriteCache"
|
||||||
|
rpcListTargetsLocalOverrides = "ListTargetsLocalOverrides"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HealthCheck executes ControlService.HealthCheck RPC.
|
// HealthCheck executes ControlService.HealthCheck RPC.
|
||||||
|
@ -240,6 +241,19 @@ func ListChainLocalOverrides(cli *client.Client, req *ListChainLocalOverridesReq
|
||||||
return wResp.message, nil
|
return wResp.message, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListTargetsLocalOverrides executes ControlService.ListTargetsLocalOverrides RPC.
|
||||||
|
func ListTargetsLocalOverrides(cli *client.Client, req *ListTargetsLocalOverridesRequest, opts ...client.CallOption) (*ListTargetsLocalOverridesResponse, error) {
|
||||||
|
wResp := newResponseWrapper[ListTargetsLocalOverridesResponse]()
|
||||||
|
wReq := &requestWrapper{m: req}
|
||||||
|
|
||||||
|
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcListTargetsLocalOverrides), wReq, wResp, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return wResp.message, nil
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveChainLocalOverride executes ControlService.RemoveChainLocalOverride RPC.
|
// RemoveChainLocalOverride executes ControlService.RemoveChainLocalOverride RPC.
|
||||||
func GetChainLocalOverride(cli *client.Client, req *GetChainLocalOverrideRequest, opts ...client.CallOption) (*GetChainLocalOverrideResponse, error) {
|
func GetChainLocalOverride(cli *client.Client, req *GetChainLocalOverrideRequest, opts ...client.CallOption) (*GetChainLocalOverrideResponse, error) {
|
||||||
wResp := newResponseWrapper[GetChainLocalOverrideResponse]()
|
wResp := newResponseWrapper[GetChainLocalOverrideResponse]()
|
||||||
|
|
|
@ -25,6 +25,29 @@ func apeTarget(chainTarget *control.ChainTarget) (engine.Target, error) {
|
||||||
fmt.Errorf("target type is not supported: %s", chainTarget.GetType().String()).Error())
|
fmt.Errorf("target type is not supported: %s", chainTarget.GetType().String()).Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func controlTarget(chainTarget *engine.Target) (control.ChainTarget, error) {
|
||||||
|
switch chainTarget.Type {
|
||||||
|
case engine.Container:
|
||||||
|
return control.ChainTarget{
|
||||||
|
Name: chainTarget.Name,
|
||||||
|
Type: control.ChainTarget_CONTAINER,
|
||||||
|
}, nil
|
||||||
|
case engine.Namespace:
|
||||||
|
// If namespace is empty, we take it for root namespace.
|
||||||
|
nm := chainTarget.Name
|
||||||
|
if nm == "root" {
|
||||||
|
nm = ""
|
||||||
|
}
|
||||||
|
return control.ChainTarget{
|
||||||
|
Name: nm,
|
||||||
|
Type: control.ChainTarget_NAMESPACE,
|
||||||
|
}, nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return control.ChainTarget{}, status.Error(codes.InvalidArgument,
|
||||||
|
fmt.Errorf("target type is not supported: %c", chainTarget.Type).Error())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) AddChainLocalOverride(_ context.Context, req *control.AddChainLocalOverrideRequest) (*control.AddChainLocalOverrideResponse, error) {
|
func (s *Server) AddChainLocalOverride(_ context.Context, req *control.AddChainLocalOverrideRequest) (*control.AddChainLocalOverrideResponse, error) {
|
||||||
if err := s.isValidRequest(req); err != nil {
|
if err := s.isValidRequest(req); err != nil {
|
||||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||||
|
@ -157,6 +180,37 @@ func (s *Server) RemoveChainLocalOverride(_ context.Context, req *control.Remove
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) ListTargetsLocalOverrides(_ context.Context, req *control.ListTargetsLocalOverridesRequest) (*control.ListTargetsLocalOverridesResponse, error) {
|
||||||
|
if err := s.isValidRequest(req); err != nil {
|
||||||
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
apeChainName := apechain.Name(req.GetBody().GetChainName())
|
||||||
|
apeTargets, err := s.localOverrideStorage.LocalStorage().ListOverrideDefinedTargets(apeChainName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(getCodeByLocalStorageErr(err), err.Error())
|
||||||
|
}
|
||||||
|
targets := make([]*control.ChainTarget, 0, len(apeTargets))
|
||||||
|
for i := range apeTargets {
|
||||||
|
target, err := controlTarget(&apeTargets[i])
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
targets = append(targets, &target)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := &control.ListTargetsLocalOverridesResponse{
|
||||||
|
Body: &control.ListTargetsLocalOverridesResponse_Body{
|
||||||
|
Targets: targets,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = SignMessage(s.key, resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getCodeByLocalStorageErr(err error) codes.Code {
|
func getCodeByLocalStorageErr(err error) codes.Code {
|
||||||
if errors.Is(err, engine.ErrChainNotFound) || errors.Is(err, engine.ErrChainNameNotFound) {
|
if errors.Is(err, engine.ErrChainNotFound) || errors.Is(err, engine.ErrChainNameNotFound) {
|
||||||
return codes.NotFound
|
return codes.NotFound
|
||||||
|
|
BIN
pkg/services/control/service.pb.go
generated
BIN
pkg/services/control/service.pb.go
generated
Binary file not shown.
|
@ -57,6 +57,9 @@ service ControlService {
|
||||||
// Remove local access policy engine overrides stored in the node by chaind id.
|
// Remove local access policy engine overrides stored in the node by chaind id.
|
||||||
rpc RemoveChainLocalOverride (RemoveChainLocalOverrideRequest) returns (RemoveChainLocalOverrideResponse);
|
rpc RemoveChainLocalOverride (RemoveChainLocalOverrideRequest) returns (RemoveChainLocalOverrideResponse);
|
||||||
|
|
||||||
|
// List targets of the local APE overrides stored in the node.
|
||||||
|
rpc ListTargetsLocalOverrides (ListTargetsLocalOverridesRequest) returns (ListTargetsLocalOverridesResponse);
|
||||||
|
|
||||||
// Flush objects from write-cache and move it to degraded read only mode.
|
// Flush objects from write-cache and move it to degraded read only mode.
|
||||||
rpc SealWriteCache(SealWriteCacheRequest) returns (SealWriteCacheResponse);
|
rpc SealWriteCache(SealWriteCacheRequest) returns (SealWriteCacheResponse);
|
||||||
}
|
}
|
||||||
|
@ -505,6 +508,30 @@ message ListChainLocalOverridesResponse {
|
||||||
Signature signature = 2;
|
Signature signature = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListTargetsLocalOverrides request.
|
||||||
|
message ListTargetsLocalOverridesRequest {
|
||||||
|
message Body {
|
||||||
|
// Target for which the overrides are applied.
|
||||||
|
string chainName = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Body body = 1;
|
||||||
|
|
||||||
|
Signature signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTargetsLocalOverrides response.
|
||||||
|
message ListTargetsLocalOverridesResponse {
|
||||||
|
message Body {
|
||||||
|
// The list of chain targets.
|
||||||
|
repeated ChainTarget targets = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Body body = 1;
|
||||||
|
|
||||||
|
Signature signature = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message RemoveChainLocalOverrideRequest {
|
message RemoveChainLocalOverrideRequest {
|
||||||
message Body {
|
message Body {
|
||||||
// Target for which the overrides are applied.
|
// Target for which the overrides are applied.
|
||||||
|
|
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