From d874b52b0c96c92ce2310724f2e7026a115cb57a Mon Sep 17 00:00:00 2001 From: zhaoxiangchun Date: Thu, 30 Apr 2020 15:59:11 +0800 Subject: [PATCH 1/2] bugfix mem paginate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过totoal和offset 与limit比较确定最后返回数据 --- pkg/cloudcommon/db/db_dispatcher.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/cloudcommon/db/db_dispatcher.go b/pkg/cloudcommon/db/db_dispatcher.go index 839c60567c..6b459e0b5a 100644 --- a/pkg/cloudcommon/db/db_dispatcher.go +++ b/pkg/cloudcommon/db/db_dispatcher.go @@ -741,6 +741,8 @@ func calculateListResult(data []jsonutils.JSONObject, total, limit, offset int64 // do limit if limit > 0 && total-offset > limit { data = data[:limit] + } else { + data = data[:total-offset] } } From cb13b2241c022c5de3bd5f9d3158b545082f6d22 Mon Sep 17 00:00:00 2001 From: zhaoxiangchun Date: Thu, 30 Apr 2020 20:09:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=A6=81=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/monitor/models/suggestsysrule.go | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/monitor/models/suggestsysrule.go b/pkg/monitor/models/suggestsysrule.go index 7049914d31..02481fba8b 100644 --- a/pkg/monitor/models/suggestsysrule.go +++ b/pkg/monitor/models/suggestsysrule.go @@ -214,18 +214,17 @@ func (self *SSuggestSysRule) GetExtraDetails( //after create, update Cronjob's info func (self *SSuggestSysRule) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { self.SVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data) - cronman.GetCronJobManager().Remove(self.Type) - if self.Enabled.Bool() { - dur, _ := time.ParseDuration(self.Period) - cronman.GetCronJobManager().AddJobAtIntervalsWithStartRun(self.Type, dur, - suggestSysRuleDrivers[self.Type].DoSuggestSysRule, true) - } + self.updateCronjob() } //after update, update Cronjob's info func (self *SSuggestSysRule) PostUpdate( ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { + self.updateCronjob() +} + +func (self *SSuggestSysRule) updateCronjob() { cronman.GetCronJobManager().Remove(self.Type) if self.Enabled.Bool() { dur, _ := time.ParseDuration(self.Period) @@ -246,7 +245,23 @@ func (self *SSuggestSysRule) PerformEnable(ctx context.Context, userCred mcclien return nil }) db.OpsLog.LogEvent(self, db.ACT_ENABLE, "", userCred) - self.PostUpdate(ctx, userCred, query, data) + self.updateCronjob() + } + return nil, nil +} + +func (self *SSuggestSysRule) AllowPerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return db.IsAdminAllowPerform(userCred, self, "disable") +} + +func (self *SSuggestSysRule) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { + if self.Enabled.IsTrue() { + db.Update(self, func() error { + self.Enabled = tristate.False + return nil + }) + db.OpsLog.LogEvent(self, db.ACT_DISABLE, "", userCred) + self.updateCronjob() } return nil, nil }