mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
scheduler: make schedtag prefer and avoid strategy work
This commit is contained in:
@@ -3,14 +3,17 @@ package guest
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/plugin"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core/score"
|
||||
)
|
||||
|
||||
// GroupPredicate filter the packet based on the label information,
|
||||
// the same group of guests should avoid schedule on same host.
|
||||
type GroupPredicate struct {
|
||||
predicates.BasePredicate
|
||||
plugin.BasePlugin
|
||||
|
||||
ExcludeGroups []string
|
||||
RequireGroups []string
|
||||
@@ -47,33 +50,6 @@ func (p *GroupPredicate) PreExecute(u *core.Unit, cs []core.Candidater) (bool, e
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (p *GroupPredicate) OnSelect(u *core.Unit, c core.Candidater) bool {
|
||||
if len(p.ExcludeGroups) > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(p.RequireGroups) > 0 {
|
||||
// TODO: what?
|
||||
}
|
||||
|
||||
if len(p.AvoidGroups) > 0 {
|
||||
u.IncreaseScore(c.IndexKey(),
|
||||
p.Name()+":avoid", -core.PriorityStep*len(p.AvoidGroups),
|
||||
)
|
||||
}
|
||||
|
||||
if len(p.PreferGroups) > 0 {
|
||||
u.IncreaseScore(c.IndexKey(),
|
||||
p.Name()+":prefer", core.PriorityStep*len(p.PreferGroups),
|
||||
)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *GroupPredicate) OnSelectEnd(u *core.Unit, c core.Candidater, count int64) {
|
||||
}
|
||||
|
||||
func (p *GroupPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) {
|
||||
|
||||
h := predicates.NewPredicateHelper(p, u, c)
|
||||
@@ -101,3 +77,23 @@ func (p *GroupPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []core.
|
||||
|
||||
return h.GetResult()
|
||||
}
|
||||
|
||||
func (p *GroupPredicate) OnPriorityEnd(u *core.Unit, c core.Candidater) {
|
||||
if len(p.AvoidGroups) > 0 {
|
||||
u.SetFrontScore(
|
||||
c.IndexKey(),
|
||||
score.NewScore(
|
||||
score.TScore(-core.PriorityStep*len(p.AvoidGroups)),
|
||||
p.Name()+":avoid",
|
||||
))
|
||||
}
|
||||
|
||||
if len(p.PreferGroups) > 0 {
|
||||
u.SetFrontScore(
|
||||
c.IndexKey(),
|
||||
score.NewScore(
|
||||
score.TScore(core.PriorityStep*len(p.PreferGroups)),
|
||||
p.Name()+":prefer",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,14 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/plugin"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/algorithm/predicates"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/api"
|
||||
"yunion.io/x/onecloud/pkg/scheduler/core"
|
||||
networks "yunion.io/x/onecloud/pkg/scheduler/db/models"
|
||||
"yunion.io/x/pkg/util/sets"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
// NetworkPredicate will filter the current network information with
|
||||
@@ -18,6 +20,7 @@ import (
|
||||
// randomly match the available network resources.
|
||||
type NetworkPredicate struct {
|
||||
predicates.BasePredicate
|
||||
plugin.BasePlugin
|
||||
SelectedNetworks sync.Map
|
||||
}
|
||||
|
||||
@@ -105,10 +108,6 @@ func (p *NetworkPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []cor
|
||||
p.SelectedNetworks.Store(n.ID, counter.GetCount())
|
||||
counters.Add(counter)
|
||||
found = true
|
||||
|
||||
if counters.GetCount() >= d.Count {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
fullErrMsgs = append(fullErrMsgs,
|
||||
fmt.Sprintf("%s: %s", n.ID, strings.Join(errMsgs, ",")),
|
||||
@@ -202,11 +201,3 @@ func (p *NetworkPredicate) Execute(u *core.Unit, c core.Candidater) (bool, []cor
|
||||
|
||||
return h.GetResult()
|
||||
}
|
||||
|
||||
func (p *NetworkPredicate) OnSelect(u *core.Unit, c core.Candidater) bool {
|
||||
u.SetFiltedData(c.IndexKey(), "networks", &p.SelectedNetworks)
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *NetworkPredicate) OnSelectEnd(u *core.Unit, c core.Candidater, count int64) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user