Merge pull request #8437 from rainzm/fix/snapshotpolicylist

SnapshotPolicy Display and Sync
This commit is contained in:
yunion-ci-robot
2020-10-22 20:07:18 +08:00
committed by GitHub
4 changed files with 36 additions and 7 deletions
+4 -4
View File
@@ -21,10 +21,10 @@ type SnapshotPolicyDetails struct {
SSnapshotPolicy
RetentionDays int `json:"retention_days"`
RepeatWeekdays []int `json:"repeat_weekdays"`
TimePoints []int `json:"time_points"`
IsActivated *bool `json:"is_activated,omitempty"`
RetentionDays int `json:"retention_days"`
RepeatWeekdaysDisplay []int `json:"repeat_weekdays_display"`
TimePointsDisplay []int `json:"time_points_display"`
IsActivated *bool `json:"is_activated,omitempty"`
BindingDiskCount int `json:"binding_disk_count"`
}
+20 -1
View File
@@ -2458,6 +2458,12 @@ func (self *SDisk) UpdataSnapshotsBackingDisk(backingDiskId string) error {
func (manager *SDiskManager) AutoSyncExtDiskSnapshot(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
now := time.Now()
week := now.Weekday()
if week == 0 {
week += 7
}
timePoint := now.Hour()
q := SnapshotPolicyDiskManager.Query().LE("next_sync_time", now)
spds := make([]SSnapshotPolicyDisk, 0)
err := db.FetchModelObjects(SnapshotPolicyDiskManager, q, &spds)
@@ -2487,7 +2493,11 @@ func (manager *SDiskManager) AutoSyncExtDiskSnapshot(ctx context.Context, userCr
db.OpsLog.LogEvent(disk, db.ACT_DISK_AUTO_SYNC_SNAPSHOT_FAIL, syncResult.Result(), userCred)
continue
}
if syncResult.AddCnt == 0 {
sp := spMap[spd.GetId()]
repeatWeekdays := SnapshotPolicyManager.RepeatWeekdaysToIntArray(sp.RepeatWeekdays)
timePoints := SnapshotPolicyManager.TimePointsToIntArray(sp.TimePoints)
if isInInts(int(week), repeatWeekdays) && isInInts(timePoint, timePoints) && syncResult.AddCnt == 0 {
// should add one
continue
}
db.OpsLog.LogEvent(disk, db.ACT_DISK_AUTO_SYNC_SNAPSHOT, "disk auto sync snapshot successfully", userCred)
@@ -2501,6 +2511,15 @@ func (manager *SDiskManager) AutoSyncExtDiskSnapshot(ctx context.Context, userCr
}
}
func isInInts(a int, array []int) bool {
for _, i := range array {
if i == a {
return true
}
}
return false
}
func (self *SDisk) syncSnapshots(ctx context.Context, userCred mcclient.TokenCredential) compare.SyncResult {
syncResult := compare.SyncResult{}
+2 -2
View File
@@ -370,8 +370,8 @@ func (sp *SSnapshotPolicy) GetExtraDetails(
}
func (sp *SSnapshotPolicy) getMoreDetails(out api.SnapshotPolicyDetails) api.SnapshotPolicyDetails {
out.RepeatWeekdays = SnapshotPolicyManager.RepeatWeekdaysToIntArray(sp.RepeatWeekdays)
out.TimePoints = SnapshotPolicyManager.TimePointsToIntArray(sp.TimePoints)
out.RepeatWeekdaysDisplay = SnapshotPolicyManager.RepeatWeekdaysToIntArray(sp.RepeatWeekdays)
out.TimePointsDisplay = SnapshotPolicyManager.TimePointsToIntArray(sp.TimePoints)
out.BindingDiskCount, _ = SnapshotPolicyDiskManager.FetchDiskCountBySPID(sp.Id)
return out
}
+10
View File
@@ -494,6 +494,16 @@ func (self *SSnapshotPolicyDiskManager) ValidateCreateData(ctx context.Context,
return data, nil
}
func (sd *SSnapshotPolicyDisk) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
sp, err := SnapshotPolicyManager.FetchSnapshotPolicyById(sd.SnapshotpolicyId)
if err != nil {
return err
}
now := time.Now()
sd.NextSyncTime = sp.ComputeNextSyncTime(now, now)
return nil
}
func (sd *SSnapshotPolicyDisk) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.
IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {