mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 06:38:19 +01:00
Fix #7579: cannot stop the execution during the initialization stage Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
f2abfcb598
commit
6e07a62fe1
@ -125,6 +125,29 @@ func (c *controller) StopReplication(executionID int64) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// no tasks, just set its status to "stopped"
|
||||
if len(tasks) == 0 {
|
||||
execution, err := c.executionMgr.Get(executionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if execution == nil {
|
||||
return fmt.Errorf("the execution %d not found", executionID)
|
||||
}
|
||||
if execution.Status != models.ExecutionStatusInProgress {
|
||||
log.Debugf("the execution %d isn't in progress, no need to stop", executionID)
|
||||
return nil
|
||||
}
|
||||
if err = c.executionMgr.Update(&models.Execution{
|
||||
ID: executionID,
|
||||
Status: models.ExecutionStatusStopped,
|
||||
EndTime: time.Now(),
|
||||
}, models.ExecutionPropsName.Status, models.ExecutionPropsName.EndTime); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debugf("the status of execution %d is set to stopped", executionID)
|
||||
}
|
||||
// got tasks, stopping the tasks one by one
|
||||
for _, task := range tasks {
|
||||
if !isTaskRunning(task) {
|
||||
log.Debugf("the task %d(job ID: %s) isn't running, its status is %s, skip", task.ID, task.JobID, task.Status)
|
||||
|
@ -61,6 +61,15 @@ func (c *copyFlow) Run(interface{}) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
isStopped, err := isExecutionStopped(c.executionMgr, c.executionID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if isStopped {
|
||||
log.Debugf("the execution %d is stopped, stop the flow", c.executionID)
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(srcResources) == 0 {
|
||||
markExecutionSuccess(c.executionMgr, c.executionID, "no resources need to be replicated")
|
||||
log.Infof("no resources need to be replicated for the execution %d, skip", c.executionID)
|
||||
|
@ -309,6 +309,18 @@ func schedule(scheduler scheduler.Scheduler, executionMgr execution.Manager, ite
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// check whether the execution is stopped
|
||||
func isExecutionStopped(mgr execution.Manager, id int64) (bool, error) {
|
||||
execution, err := mgr.Get(id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if execution == nil {
|
||||
return false, fmt.Errorf("execution %d not found", id)
|
||||
}
|
||||
return execution.Status == models.ExecutionStatusStopped, nil
|
||||
}
|
||||
|
||||
// return the name with format "res_name" or "res_name:[vtag1,vtag2,vtag3]"
|
||||
// if the resource has vtags
|
||||
func getResourceName(res *model.Resource) string {
|
||||
|
@ -151,7 +151,7 @@ func (f *fakedExecutionManager) List(...*models.ExecutionQuery) (int64, []*model
|
||||
return 0, nil, nil
|
||||
}
|
||||
func (f *fakedExecutionManager) Get(int64) (*models.Execution, error) {
|
||||
return nil, nil
|
||||
return &models.Execution{}, nil
|
||||
}
|
||||
func (f *fakedExecutionManager) Update(*models.Execution, ...string) error {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user