fix: scheduler schedtag filters execute when candidates specified (#277)

This commit is contained in:
Zexi Li
2019-04-08 22:24:34 +08:00
committed by yunion-ci-robot
parent 6e67c0a745
commit 2393df6bda
3 changed files with 23 additions and 15 deletions
@@ -51,7 +51,7 @@ func (p *AggregatePredicate) Clone() core.FitPredicate {
func (p *AggregatePredicate) PreExecute(u *core.Unit, cs []core.Candidater) (bool, error) {
data := u.SchedData()
if len(data.Candidates) > 0 {
if !u.ShouldExecuteSchedtagFilter() {
return false, nil
}
@@ -157,30 +157,34 @@ func (w schedtagStorageW) ResourceType() string {
return models.StorageManager.KeywordPlural()
}
func (p *DiskSchedtagPredicate) check(d *computeapi.DiskConfig, s *api.CandidateStorage) (*PredicatedStorage, error) {
func (p *DiskSchedtagPredicate) check(d *computeapi.DiskConfig, s *api.CandidateStorage, u *core.Unit) (*PredicatedStorage, error) {
allTags, err := GetAllSchedtags(models.StorageManager.KeywordPlural())
if err != nil {
return nil, err
}
tagPredicate := NewSchedtagPredicate(d.Schedtags, allTags)
if err := tagPredicate.Check(
schedtagStorageW{
candidater: s,
disk: d,
},
); err != nil {
return nil, err
shouldExec := u.ShouldExecuteSchedtagFilter()
ps := newPredicatedStorage(s, nil, nil)
if shouldExec {
if err := tagPredicate.Check(
schedtagStorageW{
candidater: s,
disk: d,
},
); err != nil {
return nil, err
}
ps.PreferTags = tagPredicate.GetPreferTags()
ps.AvoidTags = tagPredicate.GetAvoidTags()
}
avoidTags := tagPredicate.GetAvoidTags()
preferTags := tagPredicate.GetPreferTags()
return newPredicatedStorage(s, preferTags, avoidTags), nil
return ps, nil
}
func (p *DiskSchedtagPredicate) checkStorages(d *computeapi.DiskConfig, storages []*api.CandidateStorage) ([]*PredicatedStorage, error) {
func (p *DiskSchedtagPredicate) checkStorages(d *computeapi.DiskConfig, storages []*api.CandidateStorage, u *core.Unit) ([]*PredicatedStorage, error) {
errs := make([]error, 0)
ret := make([]*PredicatedStorage, 0)
for _, s := range storages {
ps, err := p.check(d, s)
ps, err := p.check(d, s, u)
if err != nil {
// append err, storage not suit disk
errs = append(errs, err)
@@ -222,7 +226,7 @@ func (p *DiskSchedtagPredicate) Execute(u *core.Unit, c core.Candidater) (bool,
break
}
matchedStorages, err := p.checkStorages(d, fitStorages)
matchedStorages, err := p.checkStorages(d, fitStorages, u)
if err != nil {
h.Exclude(err.Error())
}
+4
View File
@@ -415,6 +415,10 @@ func (u *Unit) SchedData() *api.SchedInfo {
return u.SchedInfo
}
func (u *Unit) ShouldExecuteSchedtagFilter() bool {
return len(u.SchedData().Candidates) == 0
}
func (u *Unit) IsPublicCloudProvider() bool {
return u.SchedData().IsPublicCloudProvider()
}