Fix #7579: cannot stop the execution during the initialization stage (#7721)

Fix #7579: cannot stop the execution during the initialization stage

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2019-05-08 19:11:18 +08:00 committed by Wang Yan
parent f2abfcb598
commit 6e07a62fe1
4 changed files with 45 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 {

View File

@ -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