mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix(region,host): sync status check block jobs
This commit is contained in:
@@ -205,6 +205,8 @@ type PerformStatusInput struct {
|
||||
// 更改的目标状态值
|
||||
// required:true
|
||||
Status string `json:"status"`
|
||||
// swagger:ignore
|
||||
BlockJobsCount int `json:"block_jobs_count"`
|
||||
|
||||
// 更改状态的原因描述
|
||||
// required:false
|
||||
|
||||
@@ -2723,7 +2723,7 @@ func (self *SGuest) PerformStatus(ctx context.Context, userCred mcclient.TokenCr
|
||||
}
|
||||
|
||||
status := input.Status
|
||||
if len(self.BackupHostId) > 0 && status == api.VM_RUNNING {
|
||||
if len(self.BackupHostId) > 0 && status == api.VM_RUNNING && input.BlockJobsCount > 0 {
|
||||
self.SetMetadata(ctx, api.MIRROR_JOB, api.MIRROR_JOB_READY, userCred)
|
||||
} else if ispId := self.GetMetadata(api.BASE_INSTANCE_SNAPSHOT_ID, userCred); len(ispId) > 0 {
|
||||
ispM, err := InstanceSnapshotManager.FetchById(ispId)
|
||||
|
||||
@@ -4782,7 +4782,7 @@ func (self *SGuestManager) switchBackupGuests(ctx context.Context, userCred mccl
|
||||
log.Errorf("ReconcileBackupGuests failed fetch guests %s", err)
|
||||
return
|
||||
}
|
||||
log.Infof("Guests count %d need reconcile with switch bakcup", len(guests))
|
||||
log.Debugf("Guests count %d need reconcile with switch backup", len(guests))
|
||||
for i := 0; i < len(guests); i++ {
|
||||
val := guests[i].GetMetadataJson("switch_backup", userCred)
|
||||
t, err := val.GetTime()
|
||||
|
||||
@@ -68,8 +68,13 @@ func (self *GuestSyncstatusTask) OnGetStatusSucc(ctx context.Context, guest *mod
|
||||
default:
|
||||
statusStr = api.VM_UNKNOWN
|
||||
}
|
||||
blockJobsCount, err := body.Int("block_jobs_count")
|
||||
if err != nil {
|
||||
blockJobsCount = -1
|
||||
}
|
||||
input := apis.PerformStatusInput{
|
||||
Status: statusStr,
|
||||
Status: statusStr,
|
||||
BlockJobsCount: int(blockJobsCount),
|
||||
}
|
||||
guest.PerformStatus(ctx, self.UserCred, nil, input)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
|
||||
@@ -109,8 +109,12 @@ func guestActions(f actionFunc) appsrv.FilterHandler {
|
||||
|
||||
func getStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
params, _, _ := appsrv.FetchEnv(ctx, w, r)
|
||||
var status = guestman.GetGuestManager().Status(params["<sid>"])
|
||||
appsrv.SendStruct(w, strDict{"status": status})
|
||||
var status, blockJobsCount = guestman.GetGuestManager().StatusWithBlockJobsCount(params["<sid>"])
|
||||
res := map[string]interface{}{
|
||||
"status": status,
|
||||
"block_jobs_count": blockJobsCount,
|
||||
}
|
||||
appsrv.SendStruct(w, res)
|
||||
}
|
||||
|
||||
func cpusetBalance(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -627,6 +627,19 @@ func (m *SGuestManager) Status(sid string) string {
|
||||
return status
|
||||
}
|
||||
|
||||
func (m *SGuestManager) StatusWithBlockJobsCount(sid string) (string, int) {
|
||||
status := m.GetStatus(sid)
|
||||
blockJobsCount := 0
|
||||
if status == GUEST_RUNNING {
|
||||
guest, _ := m.GetServer(sid)
|
||||
if guest.Monitor == nil && !guest.IsStopping() {
|
||||
guest.StartMonitor(context.Background())
|
||||
}
|
||||
blockJobsCount = guest.BlockJobsCount()
|
||||
}
|
||||
return status, blockJobsCount
|
||||
}
|
||||
|
||||
func (m *SGuestManager) GetStatus(sid string) string {
|
||||
if guest, ok := m.GetServer(sid); ok {
|
||||
if guest.IsRunning() && guest.Monitor != nil && guest.IsMaster() {
|
||||
|
||||
Reference in New Issue
Block a user