mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #15761 from wanyaoqi/automated-cherry-pick-of-#15760-upstream-master
Automated cherry pick of #15760: Automated cherry pick of #15759: fix(region): auto switch to backup on host down
This commit is contained in:
+3
-2
@@ -227,8 +227,9 @@ type PerformStatusInput struct {
|
||||
BlockJobsCount int `json:"block_jobs_count"`
|
||||
// 电源状态
|
||||
PowerStates string `json:"power_states"`
|
||||
// is call from slave guest
|
||||
IsSlave bool `json:"is_slave"`
|
||||
// call from host id
|
||||
HostId string `json:"host_id"`
|
||||
|
||||
// 更改状态的原因描述
|
||||
// required:false
|
||||
Reason string `json:"reason"`
|
||||
|
||||
@@ -2859,7 +2859,7 @@ func (self *SGuest) SetBackupGuestStatus(userCred mcclient.TokenCredential, stat
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformStatusInput) (jsonutils.JSONObject, error) {
|
||||
if input.IsSlave { // perform status called from slave guest
|
||||
if input.HostId != "" && self.BackupHostId != "" && input.HostId == self.BackupHostId { // perform status called from slave guest
|
||||
return nil, self.SetBackupGuestStatus(userCred, input.Status, input.Reason)
|
||||
}
|
||||
if input.PowerStates != "" {
|
||||
|
||||
@@ -68,7 +68,7 @@ func (h *SHostHealthChecker) load(hostname string) chan struct{} {
|
||||
}
|
||||
|
||||
func (h *SHostHealthChecker) startHealthCheck(ctx context.Context) error {
|
||||
q := HostManager.Query().IsTrue("enabled").IsTrue("enable_health_check").Equals("host_type", api.HOST_TYPE_HYPERVISOR)
|
||||
q := HostManager.Query().IsTrue("enabled").Equals("host_type", api.HOST_TYPE_HYPERVISOR)
|
||||
rows, err := q.Rows()
|
||||
if err != nil {
|
||||
log.Errorf("HostHealth check Query hosts %s", err)
|
||||
|
||||
@@ -5738,23 +5738,6 @@ func (host *SHost) switchWithBackup(ctx context.Context, userCred mcclient.Token
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
guests2 := host.GetGuestsBackupOnThisHost()
|
||||
for i := 0; i < len(guests2); i++ {
|
||||
data := jsonutils.NewDict()
|
||||
data.Set("purge", jsonutils.JSONTrue)
|
||||
data.Set("create", jsonutils.JSONTrue)
|
||||
_, err := guests2[i].PerformDeleteBackup(ctx, userCred, nil, data)
|
||||
if err != nil {
|
||||
db.OpsLog.LogEvent(
|
||||
&guests2[i], db.ACT_DELETE_BACKUP_FAILED, fmt.Sprintf("PerformDeleteBackup on host down: %s", err), userCred,
|
||||
)
|
||||
logclient.AddSimpleActionLog(
|
||||
&guests2[i], logclient.ACT_DELETE_BACKUP,
|
||||
fmt.Sprintf("PerformDeleteBackup on host down: %s", err), userCred, false,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (host *SHost) migrateOnHostDown(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
|
||||
@@ -151,6 +151,15 @@ func (self *GuestStartAndSyncToBackupTask) checkTemplete(ctx context.Context, gu
|
||||
func (self *GuestStartAndSyncToBackupTask) OnCheckTemplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.SetStage("OnStartBackupGuest", nil)
|
||||
host := models.HostManager.FetchHostById(guest.BackupHostId)
|
||||
|
||||
if !guest.IsGuestBackupMirrorJobReady(ctx, self.UserCred) {
|
||||
hostMaster := models.HostManager.FetchHostById(guest.HostId)
|
||||
self.Params.Set("block_ready", jsonutils.JSONFalse)
|
||||
diskUri := fmt.Sprintf("%s/disks", hostMaster.GetFetchUrl(true))
|
||||
self.Params.Set("disk_uri", jsonutils.NewString(diskUri))
|
||||
} else {
|
||||
self.Params.Set("block_ready", jsonutils.JSONTrue)
|
||||
}
|
||||
err := guest.GetDriver().RequestStartOnHost(ctx, guest, host, self.UserCred, self)
|
||||
if err != nil {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
|
||||
@@ -1362,8 +1362,8 @@ func (s *SKVMGuestInstance) SyncStatus(reason string) {
|
||||
statusInput := &apis.PerformStatusInput{
|
||||
Status: status,
|
||||
Reason: reason,
|
||||
IsSlave: s.IsSlave(),
|
||||
PowerStates: s.GetPowerStates(),
|
||||
HostId: hostinfo.Instance().HostId,
|
||||
}
|
||||
|
||||
if _, err := hostutils.UpdateServerStatus(context.Background(), s.Id, statusInput); err != nil {
|
||||
@@ -1390,7 +1390,7 @@ func (s *SKVMGuestInstance) CheckBlockOrRunning(jobs int) {
|
||||
Status: status,
|
||||
BlockJobsCount: jobs,
|
||||
PowerStates: s.GetPowerStates(),
|
||||
IsSlave: s.IsSlave(),
|
||||
HostId: hostinfo.Instance().HostId,
|
||||
}
|
||||
_, err := hostutils.UpdateServerStatus(context.Background(), s.Id, statusInput)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user