mirror of https://github.com/goharbor/harbor.git
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:
parent
cece65ccf7
commit
47137605c9
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue