From f9fcb5e73fbe45cacf8f5168c80ea05fc7067e90 Mon Sep 17 00:00:00 2001 From: Rain Date: Mon, 27 Apr 2020 16:09:46 +0800 Subject: [PATCH 1/2] fix/autoscaling: Chang the format of CoolingTime --- pkg/compute/models/scaling_group.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/scaling_group.go b/pkg/compute/models/scaling_group.go index 8f5958d7a0..46a7ef0ef1 100644 --- a/pkg/compute/models/scaling_group.go +++ b/pkg/compute/models/scaling_group.go @@ -493,6 +493,8 @@ func (sg *SScalingGroup) exec(ctx context.Context, action IScalingAction) (ret s return } +var CoolingTimeLocation, _ = time.LoadLocation("Asia/Shanghai") + // Scale will modify SScalingGroup.DesireInstanceNumber and generate SScalingActivity based on the trigger and its // corresponding SScalingPolicy. func (sg *SScalingGroup) Scale(ctx context.Context, triggerDesc IScalingTriggerDesc, action IScalingAction, @@ -514,7 +516,8 @@ func (sg *SScalingGroup) Scale(ctx context.Context, triggerDesc IScalingTriggerD } if action.CheckCoolTime() && !sg.AllowScale() { err = scalingActivity.SetReject("", - fmt.Sprintf("The Cooling Time limit the execution time of the policy to at least: %s", sg.AllowScaleTime.Format("2006-01-02 15:04:05"))) + fmt.Sprintf("The Cooling Time limit the execution time of the policy to at least: %s", + sg.AllowScaleTime.In(CoolingTimeLocation).Format("2006-01-02 15:04:05 -0700"))) return nil } From 76788bfa9df726836c593e8c5545ef5e857332a2 Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 28 Apr 2020 11:13:59 +0800 Subject: [PATCH 2/2] fix/as: Set ScalingPolicy's project as its ScalingGroup's project --- pkg/compute/models/scaling_policy.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/compute/models/scaling_policy.go b/pkg/compute/models/scaling_policy.go index f91de52650..2fc9cb9f51 100644 --- a/pkg/compute/models/scaling_policy.go +++ b/pkg/compute/models/scaling_policy.go @@ -239,6 +239,17 @@ func (spm *SScalingPolicyManager) ValidateCreateData(ctx context.Context, userCr return input, err } +func (sp *SScalingPolicy) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, + ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error { + // sp.Project must be same with sp.ScalingGroup + sg, err := sp.ScalingGroup() + if err != nil { + return err + } + ownerId = sg.GetOwnerId() + return sp.SVirtualResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data) +} + func (sp *SScalingPolicy) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { // do nothing sp.SetStatus(userCred, api.SP_STATUS_DELETING, "")