mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
scheduler: fix prefer avoid score
This commit is contained in:
@@ -110,16 +110,14 @@ func (p *AggregatePredicate) exec(h *PredicateHelper) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func SetCandidateScoreBySchedtag(u *core.Unit, c core.Candidater, aggCountMap map[string]int, postiveScore bool) {
|
||||
func SetCandidateScoreBySchedtag(u *core.Unit, c core.Candidater, aggCountMap map[string]int, prefer bool) {
|
||||
stepScore := core.PriorityStep
|
||||
if !postiveScore {
|
||||
stepScore = -stepScore
|
||||
doSet := u.SetPreferScore
|
||||
if !prefer {
|
||||
doSet = u.SetAvoidScore
|
||||
}
|
||||
for n, count := range aggCountMap {
|
||||
u.SetFrontScore(
|
||||
c.IndexKey(),
|
||||
score.NewScore(score.TScore(count*stepScore), n),
|
||||
)
|
||||
doSet(c.IndexKey(), score.NewScore(score.TScore(count*stepScore), n))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,18 +83,25 @@ func (p *SchedtagPredicate) Check(candidate ISchedtagCandidate) error {
|
||||
func GetSchedtagCount(inTags []computeapi.SchedtagConfig, objTags []models.SSchedtag, strategy string) (countMap map[string]int) {
|
||||
countMap = make(map[string]int)
|
||||
|
||||
in := func(objTag models.SSchedtag, inTags []computeapi.SchedtagConfig) bool {
|
||||
in := func(objTag models.SSchedtag, inTags []computeapi.SchedtagConfig) (bool, int) {
|
||||
for _, tag := range inTags {
|
||||
if tag.Id == objTag.Id || tag.Id == objTag.Name {
|
||||
return true
|
||||
return true, tag.Weight
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false, 0
|
||||
}
|
||||
|
||||
for _, objTag := range objTags {
|
||||
if in(objTag, inTags) {
|
||||
countMap[fmt.Sprintf("%s:%s:%s", objTag.Id, objTag.Name, strategy)]++
|
||||
if ok, weight := in(objTag, inTags); ok {
|
||||
key := fmt.Sprintf("%s:%s:%s", objTag.Id, objTag.Name, strategy)
|
||||
score, ok := countMap[key]
|
||||
if ok {
|
||||
score += weight
|
||||
} else {
|
||||
score = weight
|
||||
}
|
||||
countMap[key] = score
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -116,7 +123,10 @@ func GetRequestSchedtags(reqTags []*computeapi.SchedtagConfig, allTags []models.
|
||||
|
||||
appendedTagIds := make(map[string]int)
|
||||
|
||||
appendTagByStrategy := func(tag *computeapi.SchedtagConfig) {
|
||||
appendTagByStrategy := func(tag *computeapi.SchedtagConfig, defaultWeight int) {
|
||||
if tag.Weight <= 0 {
|
||||
tag.Weight = defaultWeight
|
||||
}
|
||||
switch tag.Strategy {
|
||||
case models.STRATEGY_REQUIRE:
|
||||
requireTags = append(requireTags, *tag)
|
||||
@@ -130,7 +140,7 @@ func GetRequestSchedtags(reqTags []*computeapi.SchedtagConfig, allTags []models.
|
||||
}
|
||||
|
||||
for _, tag := range reqTags {
|
||||
appendTagByStrategy(tag)
|
||||
appendTagByStrategy(tag, 10)
|
||||
|
||||
appendedTagIds[tag.Id] = 1
|
||||
}
|
||||
@@ -141,7 +151,7 @@ func GetRequestSchedtags(reqTags []*computeapi.SchedtagConfig, allTags []models.
|
||||
|
||||
if !(nameOk || idOk) {
|
||||
apiTag := &computeapi.SchedtagConfig{Id: tag.Id, Strategy: tag.DefaultStrategy}
|
||||
appendTagByStrategy(apiTag)
|
||||
appendTagByStrategy(apiTag, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user