Skip to content

Commit

Permalink
fix(region): standardization stage name (#18299)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Oct 17, 2023
1 parent 111fc16 commit 3961c28
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 38 deletions.
38 changes: 17 additions & 21 deletions pkg/cloudcommon/db/taskman/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,36 +441,32 @@ func execITask(taskValue reflect.Value, task *STask, odata jsonutils.JSONObject,
data = jsonutils.NewDict()
}

var stageName string
stageName := task.Stage
if taskFailed {
stageName = fmt.Sprintf("%sFailed", task.Stage)
} else {
stageName = task.Stage
if strings.Contains(stageName, "_") {
stageName = fmt.Sprintf("%s_failed", task.Stage)
}
}

if strings.Contains(stageName, "_") {
stageName = utils.Kebab2Camel(stageName, "_")
}

funcValue := taskValue.MethodByName(stageName)

if !funcValue.IsValid() || funcValue.IsNil() {
log.Debugf("Stage %s not found, try kebab to camel and find again", stageName)
msg := fmt.Sprintf("Stage %s not found", stageName)
if taskFailed {
stageName = fmt.Sprintf("%s_failed", task.Stage)
}
stageName = utils.Kebab2Camel(stageName, "_")
funcValue = taskValue.MethodByName(stageName)

if !funcValue.IsValid() || funcValue.IsNil() {
msg := fmt.Sprintf("Stage %s not found", stageName)
if taskFailed {
// failed handler is optional, ignore the error
log.Warningf(msg)
msg, _ = data.GetString()
} else {
log.Errorf(msg)
}
task.SetStageFailed(ctx, jsonutils.NewString(msg))
task.SaveRequestContext(&ctxData)
return
// failed handler is optional, ignore the error
log.Warningf(msg)
msg, _ = data.GetString()
} else {
log.Errorf(msg)
}
task.SetStageFailed(ctx, jsonutils.NewString(msg))
task.SaveRequestContext(&ctxData)
return
}

objManager := db.GetModelManager(task.ObjName)
Expand Down
4 changes: 2 additions & 2 deletions pkg/compute/guestdrivers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func (drv *SBaseGuestDriver) OnGuestCreateTaskComplete(ctx context.Context, gues
}
}
if jsonutils.QueryBoolean(task.GetParams(), "auto_start", false) {
task.SetStage("on_auto_start_guest", nil)
task.SetStage("OnAutoStartGuest", nil)
return guest.StartGueststartTask(ctx, task.GetUserCred(), nil, task.GetTaskId())
} else {
task.SetStage("on_sync_status_complete", nil)
task.SetStage("OnSyncStatusComplete", nil)
return guest.StartSyncstatus(ctx, task.GetUserCred(), task.GetTaskId())
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/baremetal_convert_hypervisor_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (self *BaremetalConvertHypervisorTask) OnInit(ctx context.Context, obj db.I

baremetal.SetStatus(self.UserCred, api.BAREMETAL_CONVERTING, "")

self.SetStage("on_guest_deploy_complete", nil)
self.SetStage("OnGuestDeployComplete", nil)

guest := self.getGuest()
params, _ := self.Params.Get("server_params")
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/cloud_account_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (self *CloudAccountSyncInfoTask) OnCloudaccountSyncReady(ctx context.Contex
cloudproviders := cloudaccount.GetEnabledCloudproviders()

if len(cloudproviders) > 0 {
self.SetStage("on_cloudaccount_sync_complete", nil)
self.SetStage("OnCloudaccountSyncComplete", nil)
for i := range cloudproviders {
cloudproviders[i].StartSyncCloudProviderInfoTask(ctx, self.UserCred, &syncRange, self.GetId())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/guest_attach_disk_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (self *GuestAttachDiskTask) OnInit(ctx context.Context, obj db.IStandaloneM
return
}
disk.SetStatus(self.UserCred, api.DISK_ATTACHING, "Disk attach")
self.SetStage("on_sync_config_complete", nil)
self.SetStage("OnSyncConfigComplete", nil)
guest.GetDriver().RequestAttachDisk(ctx, guest, disk, self)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/guest_change_config_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (task *GuestChangeConfigTask) OnGuestChangeCpuMemSpecFinish(ctx context.Con
func (task *GuestChangeConfigTask) OnSyncConfigComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
guest := obj.(*models.SGuest)

task.SetStage("on_sync_status_complete", nil)
task.SetStage("OnSyncStatusComplete", nil)
err := guest.StartSyncstatus(ctx, task.UserCred, task.GetTaskId())
if err != nil {
task.markStageFailed(ctx, guest, jsonutils.NewString(fmt.Sprintf("StartSyncstatus fail %s", err)))
Expand Down
8 changes: 4 additions & 4 deletions pkg/compute/tasks/guest_create_disk_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type GuestCreateDiskTask struct {
}

func (self *GuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStage("on_disk_prepared", nil)
self.SetStage("OnDiskPrepared", nil)
guest := obj.(*models.SGuest)
err := guest.GetDriver().DoGuestCreateDisksTask(ctx, guest, self)
if err != nil {
Expand All @@ -60,7 +60,7 @@ type KVMGuestCreateDiskTask struct {
}

func (self *KVMGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStage("on_kvm_disk_prepared", nil)
self.SetStage("OnKvmDiskPrepared", nil)
self.OnKvmDiskPrepared(ctx, obj, data)
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (self *KVMGuestCreateDiskTask) OnKvmDiskPrepared(ctx context.Context, obj d
if diskReady {
guest := obj.(*models.SGuest)
if guest.Status == api.VM_RUNNING {
self.SetStage("on_config_sync_complete", nil)
self.SetStage("OnConfigSyncComplete", nil)
err := guest.StartSyncTask(ctx, self.UserCred, false, self.GetTaskId())
if err != nil {
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
Expand Down Expand Up @@ -172,7 +172,7 @@ type ManagedGuestCreateDiskTask struct {
}

func (self *ManagedGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStage("on_managed_disk_prepared", nil)
self.SetStage("OnManagedDiskPrepared", nil)
self.OnManagedDiskPrepared(ctx, obj, data)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/compute/tasks/guest_create_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
func (self *GuestCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
guest := obj.(*models.SGuest)
guest.SetStatus(self.UserCred, api.VM_CREATE_NETWORK, "")
self.SetStage("on_wait_guest_networks_ready", nil)
self.SetStage("OnWaitGuestNetworksReady", nil)
self.OnWaitGuestNetworksReady(ctx, obj, nil)
}

Expand Down Expand Up @@ -218,10 +218,10 @@ func (self *GuestCreateTask) OnDeployEipComplete(ctx context.Context, obj db.ISt
}

if jsonutils.QueryBoolean(self.GetParams(), "auto_start", false) {
self.SetStage("on_auto_start_guest", nil)
self.SetStage("OnAutoStartGuest", nil)
guest.StartGueststartTask(ctx, self.GetUserCred(), nil, self.GetTaskId())
} else {
self.SetStage("on_sync_status_complete", nil)
self.SetStage("OnSyncStatusComplete", nil)
guest.StartSyncstatus(ctx, self.GetUserCred(), self.GetTaskId())
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/guest_detach_all_disks_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
}

func (self *GuestDetachAllDisksTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStage("on_disk_delete_complete", nil)
self.SetStage("OnDiskDeleteComplete", nil)
self.OnDiskDeleteComplete(ctx, obj, data)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/guest_save_instance_image_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (self *GuestSaveGuestImageTask) OnSaveRootImageComplete(ctx context.Context
}

if restart, _ := self.GetParams().Bool("auto_start"); restart {
self.SetStage("on_start_server_complete", nil)
self.SetStage("OnStartServerComplete", nil)
guest.StartGueststartTask(ctx, self.GetUserCred(), nil, self.GetTaskId())
} else {
guest.SetStatus(self.UserCred, api.VM_READY, "")
Expand Down
4 changes: 2 additions & 2 deletions pkg/compute/tasks/guest_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (self *GuestSyncConfTask) OnSyncComplete(ctx context.Context, obj db.IStand
self.StartRestartNetworkTask(ctx, guest)
} else if data.Contains("task") {
// XXX this is only applied to KVM, which will call task_complete twice
self.SetStage("on_disk_sync_complete", nil)
self.SetStage("OnDiskSyncComplete", nil)
} else {
self.OnDiskSyncComplete(ctx, guest, data)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (self *GuestSyncConfTask) OnDiskSyncComplete(ctx context.Context, guest *mo
if jsonutils.QueryBoolean(self.Params, "without_sync_status", false) {
self.OnSyncStatusComplete(ctx, guest, nil)
} else {
self.SetStage("on_sync_status_complete", nil)
self.SetStage("OnSyncStatusComplete", nil)
guest.StartSyncstatus(ctx, self.GetUserCred(), self.GetTaskId())
}
}
Expand Down

0 comments on commit 3961c28

Please sign in to comment.