Skip to content

Commit

Permalink
feat: implement DeleteSeedPeer api in manager (#2591)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Aug 3, 2023
1 parent b723181 commit 733b938
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module d7y.io/dragonfly/v2
go 1.20

require (
d7y.io/api/v2 v2.0.13
d7y.io/api/v2 v2.0.16
github.com/MysteriousPotato/go-lockable v1.0.0
github.com/RichardKnop/machinery v1.10.6
github.com/Showmax/go-fqdn v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
d7y.io/api/v2 v2.0.13 h1:J0YKbLxRBXrlFAwhGWSkfa56e4+8L2upDl5TYW6ZqFk=
d7y.io/api/v2 v2.0.13/go.mod h1:lwCvFjtRVsyTKsiXfh2W0Jdv+5tQGR/vFj+TknwnusY=
d7y.io/api/v2 v2.0.16 h1:68PPLq452PvlIFfAk4Rc/XyNkcJG8pdOnXSDj4sJG3w=
d7y.io/api/v2 v2.0.16/go.mod h1:lwCvFjtRVsyTKsiXfh2W0Jdv+5tQGR/vFj+TknwnusY=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
Expand Down
17 changes: 17 additions & 0 deletions manager/rpcserver/manager_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ func (s *managerServerV2) createSeedPeer(ctx context.Context, req *managerv2.Upd
}, nil
}

// Delete SeedPeer configuration.
func (s *managerServerV2) DeleteSeedPeer(ctx context.Context, req *managerv2.DeleteSeedPeerRequest) (*emptypb.Empty, error) {
if err := s.db.WithContext(ctx).Unscoped().Delete(&models.SeedPeer{}, models.SeedPeer{
Hostname: req.Hostname,
IP: req.Ip,
SeedPeerClusterID: uint(req.SeedPeerClusterId),
}).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}

return nil, status.Error(codes.Internal, err.Error())
}

return new(emptypb.Empty), nil
}

// Get Scheduler and Scheduler cluster configuration.
func (s *managerServerV2) GetScheduler(ctx context.Context, req *managerv2.GetSchedulerRequest) (*managerv2.Scheduler, error) {
log := logger.WithHostnameAndIP(req.Hostname, req.Ip)
Expand Down
12 changes: 12 additions & 0 deletions pkg/rpc/manager/client/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ type V2 interface {
// Update Seed peer configuration.
UpdateSeedPeer(context.Context, *managerv2.UpdateSeedPeerRequest, ...grpc.CallOption) (*managerv2.SeedPeer, error)

// Delete Seed peer configuration.
DeleteSeedPeer(context.Context, *managerv2.DeleteSeedPeerRequest, ...grpc.CallOption) error

// Get Scheduler and Scheduler cluster configuration.
GetScheduler(context.Context, *managerv2.GetSchedulerRequest, ...grpc.CallOption) (*managerv2.Scheduler, error)

Expand Down Expand Up @@ -134,6 +137,15 @@ func (v *v2) UpdateSeedPeer(ctx context.Context, req *managerv2.UpdateSeedPeerRe
return v.ManagerClient.UpdateSeedPeer(ctx, req, opts...)
}

// Delete SeedPeer configuration.
func (v *v2) DeleteSeedPeer(ctx context.Context, req *managerv2.DeleteSeedPeerRequest, opts ...grpc.CallOption) error {
ctx, cancel := context.WithTimeout(ctx, contextTimeout)
defer cancel()

_, err := v.ManagerClient.DeleteSeedPeer(ctx, req, opts...)
return err
}

// Get Scheduler and Scheduler cluster configuration.
func (v *v2) GetScheduler(ctx context.Context, req *managerv2.GetSchedulerRequest, opts ...grpc.CallOption) (*managerv2.Scheduler, error) {
ctx, cancel := context.WithTimeout(ctx, contextTimeout)
Expand Down
19 changes: 19 additions & 0 deletions pkg/rpc/manager/client/mocks/client_v2_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 733b938

Please sign in to comment.