fix(region): Fix problems about Auto Scaling

1. Alarm 的创建统一使用 AdminSession
2. ScalingTimer 的更新有些问题
3. 创建的主机名称不应该包含大写字母
4. ScalingTimer 的描述有些问题
5. 绑定LB的时候少传递了一个参数
This commit is contained in:
Rain
2020-04-08 21:38:49 +08:00
parent 3860e635e6
commit 09797e3abe
5 changed files with 13 additions and 7 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ type SScalingActivity struct {
ActionDesc string `width:"256" charset:"ascii" get:"user" list:"user"`
StartTime time.Time `list:"user" get:"user"`
EndTime time.Time `list:"user" get:"user"`
Reason string `width:"256" charset:"ascii" get:"user" list:"user"`
Reason string `width:"1024" charset:"ascii" get:"user" list:"user"`
}
var ScalingActivityManager *SScalingActivityManager
+4 -1
View File
@@ -401,8 +401,11 @@ func (sg *SScalingGroup) ScalingPolicyNumber() (int, error) {
func (sg *SScalingGroup) ScalingGroupGuests(guestIds []string) ([]SScalingGroupGuest, error) {
q := ScalingGroupGuestManager.Query().Equals("scaling_group_id", sg.GetId())
if len(guestIds) == 0 {
return nil, nil
}
if len(guestIds) == 1 {
q = q.Equals("guest_id", guestIds[1])
q = q.Equals("guest_id", guestIds[0])
}
if len(guestIds) > 1 {
q = q.In("guest_id", guestIds)
+5 -3
View File
@@ -209,7 +209,7 @@ func (st *SScalingTimer) Update(now time.Time) {
if now.Before(st.StartTime) {
now = st.StartTime
}
if now.Before(st.NextTime) {
if !st.NextTime.Before(now) {
return
}
@@ -349,11 +349,13 @@ func (st *SScalingTimer) TriggerId() string {
return st.GetId()
}
var cstSh, _ = time.LoadLocation("Asia/Shanghai")
func (st *SScalingTimer) TriggerDescription() string {
var detail string
switch st.Type {
case api.TIMER_TYPE_ONCE:
detail = st.EndTime.String()
detail = st.EndTime.In(cstSh).Format("2006-01-02 15:04:05")
case api.TIMER_TYPE_DAY:
detail = fmt.Sprintf("%d:%d every day", st.Hour, st.Minute)
case api.TIMER_TYPE_WEEK:
@@ -430,7 +432,7 @@ func (sa *SScalingAlarm) Register(ctx context.Context, userCred mcclient.TokenCr
if err != nil {
return err
}
session := auth.GetSession(ctx, userCred, "", "")
session := auth.GetAdminSession(ctx, "", "")
notificationID, err := ScalingPolicyManager.NotificationID(session)
if err != nil {
return errors.Wrap(err, "ScalingPolicyManager.NotificationID")
+2 -1
View File
@@ -637,6 +637,7 @@ func (asc *SASController) actionAfterCreate(
params.Set("backend_type", jsonutils.NewString("guest"))
params.Set("port", jsonutils.NewInt(int64(sg.LoadbalancerBackendPort)))
params.Set("weight", jsonutils.NewInt(int64(sg.LoadbalancerBackendWeight)))
params.Set("backend_group", jsonutils.NewString(sg.BackendGroupId))
_, err := modules.LoadbalancerBackends.Create(session, params)
if err != nil {
rollback(fmt.Sprintf("bind instance '%s' to loadbalancer backend gropu '%s' failed: %s", ret.Id, sg.BackendGroupId, err.Error()))
@@ -655,7 +656,7 @@ func (asc *SASController) actionAfterCreate(
}
func (asc *SASController) randStringRunes(n int) string {
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
+1 -1
View File
@@ -67,7 +67,7 @@ func (asc *SASController) Timer(ctx context.Context, userCred mcclient.TokenCred
// For unknown reasons, the scalingTimer did not execute at the specified time
scalingTimer.Update(timeScope.Start)
// scalingTimer should not exec for now.
if scalingTimer.NextTime.After(timeScope.End) {
if scalingTimer.NextTime.After(timeScope.End) || scalingTimer.IsExpired {
err = models.ScalingTimerManager.TableSpec().InsertOrUpdate(&scalingTimer)
if err != nil {
log.Errorf("update ScalingTimer whose ScalingPolicyId is %s error: %s",