fix: update the replication API handler (#18197)

1. Check execution before stop replication execution.
2. Check execution before list replication tasks.

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
Chlins Zhang 2023-02-14 13:11:27 +08:00 committed by GitHub
parent cece65ccf7
commit 47137605c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -163,6 +163,12 @@ func (c *controller) markError(ctx context.Context, executionID int64, err error
}
func (c *controller) Stop(ctx context.Context, id int64) error {
// check whether the replication execution existed
_, err := c.GetExecution(ctx, id)
if err != nil {
return err
}
return c.execMgr.Stop(ctx, id)
}

View File

@ -105,6 +105,21 @@ func (r *replicationTestSuite) TestStart() {
}
func (r *replicationTestSuite) TestStop() {
r.execMgr.On("List", mock.Anything, mock.Anything).Return([]*task.Execution{
{
ID: 1,
VendorType: job.Replication,
VendorID: 1,
Status: job.RunningStatus.String(),
Metrics: &dao.Metrics{
TaskCount: 1,
RunningTaskCount: 1,
},
Trigger: task.ExecutionTriggerManual,
StartTime: time.Time{},
EndTime: time.Time{},
},
}, nil)
r.execMgr.On("Stop", mock.Anything, mock.Anything).Return(nil)
err := r.ctl.Stop(nil, 1)
r.Require().Nil(err)

View File

@ -350,6 +350,12 @@ func (r *replicationAPI) ListReplicationTasks(ctx context.Context, params operat
if err := r.RequireSystemAccess(ctx, rbac.ActionList, rbac.ResourceReplication); err != nil {
return r.SendError(ctx, err)
}
// check the existence of the replication execution
_, err := r.ctl.GetExecution(ctx, params.ID)
if err != nil {
return r.SendError(ctx, err)
}
query, err := r.BuildQuery(ctx, nil, params.Sort, params.Page, params.PageSize)
if err != nil {
return r.SendError(ctx, err)