Skip to content

Commit

Permalink
misc ha guest fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Jul 15, 2020
1 parent 2b923eb commit 6540851
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
7 changes: 5 additions & 2 deletions pkg/compute/models/guest_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,11 @@ func (self *SGuest) StartInsertIsoTask(ctx context.Context, imageId string, boot
if boot {
data.Add(jsonutils.JSONTrue, "boot")
}

task, err := taskman.TaskManager.NewTask(ctx, "GuestInsertIsoTask", self, userCred, data, parentTaskId, "", nil)
taskName := "GuestInsertIsoTask"
if self.BackupHostId != "" {
taskName = "HaGuestInsertIsoTask"
}
task, err := taskman.TaskManager.NewTask(ctx, taskName, self, userCred, data, parentTaskId, "", nil)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/compute/service/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import (
"yunion.io/x/pkg/errors"

"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/util/influxdb"
)

func setInfluxdbRetentionPolicy() error {
setF := func() error {
urls, err := auth.GetServiceURLs("influxdb", options.Options.Region, "", "")
if err != nil && errors.Cause(err) == httperrors.ErrNotFound {
auth.ReAuth()
}
if err != nil {
return errors.Wrap(err, "get influxdb service urls")
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/compute/tasks/guest_insert_iso_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type GuestInsertIsoTask struct {

func init() {
taskman.RegisterTask(GuestInsertIsoTask{})
taskman.RegisterTask(HaGuestInsertIsoTask{})
}

func (self *GuestInsertIsoTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
Expand Down Expand Up @@ -91,3 +92,41 @@ func (self *GuestInsertIsoTask) OnIsoPrepareComplete(ctx context.Context, obj db
func (self *GuestInsertIsoTask) OnConfigSyncComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStageComplete(ctx, nil)
}

type HaGuestInsertIsoTask struct {
GuestInsertIsoTask
}

func (self *HaGuestInsertIsoTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.prepareIsoImage(ctx, obj)
}

func (self *HaGuestInsertIsoTask) prepareIsoImage(ctx context.Context, obj db.IStandaloneModel) {
guest := obj.(*models.SGuest)
imageId, _ := self.Params.GetString("image_id")
db.OpsLog.LogEvent(obj, db.ACT_ISO_PREPARING, imageId, self.UserCred)
disks := guest.GetDisks()
disk := disks[0].GetDisk()
storage := disk.GetBackupStorage()
storageCache := storage.GetStoragecache()
if storageCache != nil {
self.SetStage("OnBackupIsoPrepareComplete", nil)
storageCache.StartImageCacheTask(ctx, self.UserCred, imageId, "iso", false, self.GetTaskId())
} else {
guest.EjectIso(self.UserCred)
db.OpsLog.LogEvent(obj, db.ACT_ISO_PREPARE_FAIL, imageId, self.UserCred)
self.SetStageFailed(ctx, "host no local storage cache")
}
}

func (self *HaGuestInsertIsoTask) OnBackupIsoPrepareComplete(
ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject,
) {
self.GuestInsertIsoTask.prepareIsoImage(ctx, guest)
}

func (self *HaGuestInsertIsoTask) OnBackupIsoPrepareCompleteFailed(
ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject,
) {
self.OnIsoPrepareCompleteFailed(ctx, guest, data)
}
10 changes: 8 additions & 2 deletions pkg/compute/tasks/ha_guest_deploy_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ type GuestDeployBackupTask struct {
func (self *GuestDeployBackupTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
guest := obj.(*models.SGuest)
if len(guest.BackupHostId) == 0 {
self.SetStageFailed(ctx, "Guest dosen't have backup host")
self.OnDeployGuestCompleteFailed(ctx, guest, jsonutils.NewString("Guest dosen't have backup host"))
return
}
self.SetStage("OnDeployGuestComplete", nil)
self.DeployBackup(ctx, guest, nil)
host := models.HostManager.FetchHostById(guest.BackupHostId)
err := guest.GetDriver().RequestDeployGuestOnHost(ctx, guest, host, self)
if err != nil {
log.Errorf("request_deploy_guest_on_host %s", err)
self.OnDeployGuestCompleteFailed(ctx, guest, jsonutils.NewString(err.Error()))
}
}

func (self *GuestDeployBackupTask) OnDeployGuestComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/compute/tasks/snapshot_create_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (self *SnapshotCreateTask) TaskFailed(ctx context.Context, snapshot *models

func (self *SnapshotCreateTask) TaskComplete(ctx context.Context, snapshot *models.SSnapshot, data jsonutils.JSONObject) {
snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "")
db.OpsLog.LogEvent(snapshot, db.ACT_SNAPSHOT_DONE, "", self.UserCred)
logclient.AddActionLogWithStartable(self, snapshot, logclient.ACT_CREATE, "", self.UserCred, true)
db.OpsLog.LogEvent(snapshot, db.ACT_SNAPSHOT_DONE, snapshot.GetShortDesc(ctx), self.UserCred)
logclient.AddActionLogWithStartable(self, snapshot, logclient.ACT_CREATE, snapshot.GetShortDesc(ctx), self.UserCred, true)
self.SetStageComplete(ctx, nil)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/mcclient/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ func Init(info *AuthInfo, debug, insecure bool, certFile, keyFile string) {
<-done
}

func ReAuth() {
manager.reAuth()
}

func GetAdminSession(ctx context.Context, region string,
apiVersion string) *mcclient.ClientSession {
return GetSession(ctx, manager.adminCredential, region, apiVersion)
Expand Down

0 comments on commit 6540851

Please sign in to comment.