2024-01-30 15:18:58 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr"
|
|
|
|
"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"
|
2024-01-30 15:18:58 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2024-10-21 08:56:38 +00:00
|
|
|
func (s *Server) DetachShards(ctx context.Context, req *control.DetachShardsRequest) (*control.DetachShardsResponse, error) {
|
2024-01-30 15:18:58 +00:00
|
|
|
err := s.isValidRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
shardIDs := s.getShardIDList(req.GetBody().GetShard_ID())
|
|
|
|
|
2024-10-21 08:56:38 +00:00
|
|
|
if err := s.s.DetachShards(ctx, shardIDs); err != nil {
|
2024-01-30 15:18:58 +00:00
|
|
|
if errors.As(err, new(logicerr.Logical)) {
|
|
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
|
|
}
|
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &control.DetachShardsResponse{
|
|
|
|
Body: &control.DetachShardsResponse_Body{},
|
|
|
|
}
|
|
|
|
|
2024-05-16 09:11:57 +00:00
|
|
|
if err = ctrlmessage.Sign(s.key, resp); err != nil {
|
2024-01-30 15:18:58 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|