2021-12-17 15:55:59 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-05-16 09:11:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
2021-12-17 15:55:59 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) ListShards(_ context.Context, req *control.ListShardsRequest) (*control.ListShardsResponse, error) {
|
|
|
|
// verify request
|
|
|
|
if err := s.isValidRequest(req); err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// create and fill response
|
|
|
|
resp := new(control.ListShardsResponse)
|
|
|
|
|
|
|
|
body := new(control.ListShardsResponse_Body)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
info := s.s.DumpInfo()
|
|
|
|
|
2024-08-29 12:45:33 +00:00
|
|
|
shardInfos := make([]control.ShardInfo, 0, len(info.Shards))
|
2021-12-17 15:55:59 +00:00
|
|
|
|
2021-12-27 18:08:01 +00:00
|
|
|
for _, sh := range info.Shards {
|
2021-12-17 15:55:59 +00:00
|
|
|
si := new(control.ShardInfo)
|
|
|
|
|
2024-08-19 15:28:53 +00:00
|
|
|
si.SetShard_ID(*sh.ID)
|
2021-12-27 18:08:01 +00:00
|
|
|
si.SetMetabasePath(sh.MetaBaseInfo.Path)
|
2022-10-05 12:41:36 +00:00
|
|
|
si.Blobstor = blobstorInfoToProto(sh.BlobStorInfo)
|
2024-08-19 15:28:53 +00:00
|
|
|
si.SetWritecachePath(sh.WriteCacheInfo.Path)
|
2022-05-16 13:23:09 +00:00
|
|
|
si.SetPiloramaPath(sh.PiloramaInfo.Path)
|
2021-12-17 15:55:59 +00:00
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
var m control.ShardMode
|
2021-12-27 18:08:01 +00:00
|
|
|
|
|
|
|
switch sh.Mode {
|
2022-06-28 14:05:08 +00:00
|
|
|
case mode.ReadWrite:
|
|
|
|
m = control.ShardMode_READ_WRITE
|
|
|
|
case mode.ReadOnly:
|
|
|
|
m = control.ShardMode_READ_ONLY
|
|
|
|
case mode.Degraded:
|
|
|
|
m = control.ShardMode_DEGRADED
|
2022-07-18 11:44:29 +00:00
|
|
|
case mode.DegradedReadOnly:
|
|
|
|
m = control.ShardMode_DEGRADED_READ_ONLY
|
2021-12-27 18:08:01 +00:00
|
|
|
default:
|
2022-06-28 14:05:08 +00:00
|
|
|
m = control.ShardMode_SHARD_MODE_UNDEFINED
|
2021-12-27 18:08:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
si.SetMode(m)
|
2022-01-31 15:23:19 +00:00
|
|
|
si.SetErrorCount(sh.ErrorCount)
|
2024-09-03 09:18:10 +00:00
|
|
|
si.SetEvacuationInProgress(sh.EvacuationInProgress)
|
2021-12-17 15:55:59 +00:00
|
|
|
|
2024-08-29 12:45:33 +00:00
|
|
|
shardInfos = append(shardInfos, *si)
|
2021-12-17 15:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body.SetShards(shardInfos)
|
|
|
|
|
|
|
|
// sign the response
|
2024-05-16 09:11:57 +00:00
|
|
|
if err := ctrlmessage.Sign(s.key, resp); err != nil {
|
2021-12-17 15:55:59 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-05 12:41:36 +00:00
|
|
|
|
2024-08-29 12:45:33 +00:00
|
|
|
func blobstorInfoToProto(info blobstor.Info) []control.BlobstorInfo {
|
|
|
|
res := make([]control.BlobstorInfo, len(info.SubStorages))
|
2022-10-05 12:41:36 +00:00
|
|
|
for i := range info.SubStorages {
|
2024-08-29 12:45:33 +00:00
|
|
|
res[i] = control.BlobstorInfo{
|
2022-10-05 12:41:36 +00:00
|
|
|
Path: info.SubStorages[i].Path,
|
|
|
|
Type: info.SubStorages[i].Type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|