From c40815f71d5b1eb3d98e5ca740db4900fc991f7c Mon Sep 17 00:00:00 2001 From: Zexi Date: Wed, 17 Jul 2019 13:18:43 +0800 Subject: [PATCH] scheduler: schedtag predicate match resources then do filter --- .../predicates/disk_schedtag_predicate.go | 8 ++++++++ .../predicates/network_schedtag_predicate.go | 15 +++++++++++++++ pkg/scheduler/algorithm/predicates/predicates.go | 16 +++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/algorithm/predicates/disk_schedtag_predicate.go b/pkg/scheduler/algorithm/predicates/disk_schedtag_predicate.go index 97eab818df..37cadf94ad 100644 --- a/pkg/scheduler/algorithm/predicates/disk_schedtag_predicate.go +++ b/pkg/scheduler/algorithm/predicates/disk_schedtag_predicate.go @@ -52,6 +52,10 @@ func (d diskW) Keyword() string { return "disk" } +func (d diskW) ResourceKeyword() string { + return "storage" +} + func (d diskW) GetSchedtags() []*computeapi.SchedtagConfig { return d.DiskConfig.Schedtags } @@ -72,6 +76,10 @@ func (p *DiskSchedtagPredicate) GetResources(c core.Candidater) []ISchedtagCandi return ret } +func (p *DiskSchedtagPredicate) IsResourceMatchInput(input ISchedtagCustomer, res ISchedtagCandidateResource) bool { + return true +} + func (p *DiskSchedtagPredicate) IsResourceFitInput(u *core.Unit, c core.Candidater, res ISchedtagCandidateResource, input ISchedtagCustomer) core.PredicateFailureReason { storage := res.(*api.CandidateStorage) if storage.Status == computeapi.STORAGE_OFFLINE || storage.Enabled.IsFalse() { diff --git a/pkg/scheduler/algorithm/predicates/network_schedtag_predicate.go b/pkg/scheduler/algorithm/predicates/network_schedtag_predicate.go index 4119d55d9f..9d47d14780 100644 --- a/pkg/scheduler/algorithm/predicates/network_schedtag_predicate.go +++ b/pkg/scheduler/algorithm/predicates/network_schedtag_predicate.go @@ -55,6 +55,10 @@ func (n netW) Keyword() string { return "net" } +func (n netW) ResourceKeyword() string { + return "network" +} + func (n netW) GetSchedtags() []*computeapi.SchedtagConfig { return n.NetworkConfig.Schedtags } @@ -75,6 +79,17 @@ func (p *NetworkSchedtagPredicate) GetResources(c core.Candidater) []ISchedtagCa return ret } +func (p *NetworkSchedtagPredicate) IsResourceMatchInput(input ISchedtagCustomer, res ISchedtagCandidateResource) bool { + net := input.(*netW) + network := res.(*api.CandidateNetwork) + if net.Network != "" { + if !(network.Id == net.Network || network.Name == net.Network) { + return false + } + } + return true +} + func (p *NetworkSchedtagPredicate) IsResourceFitInput(u *core.Unit, c core.Candidater, res ISchedtagCandidateResource, input ISchedtagCustomer) core.PredicateFailureReason { network := res.(*api.CandidateNetwork) net := input.(*netW) diff --git a/pkg/scheduler/algorithm/predicates/predicates.go b/pkg/scheduler/algorithm/predicates/predicates.go index ffd01130f1..29a6a9a0ca 100644 --- a/pkg/scheduler/algorithm/predicates/predicates.go +++ b/pkg/scheduler/algorithm/predicates/predicates.go @@ -230,6 +230,7 @@ type ISchedtagPredicateInstance interface { GetInputs(u *core.Unit) []ISchedtagCustomer GetResources(c core.Candidater) []ISchedtagCandidateResource + IsResourceMatchInput(input ISchedtagCustomer, res ISchedtagCandidateResource) bool IsResourceFitInput(unit *core.Unit, c core.Candidater, res ISchedtagCandidateResource, input ISchedtagCustomer) core.PredicateFailureReason DoSelect(c core.Candidater, input ISchedtagCustomer, res []ISchedtagCandidateResource) []ISchedtagCandidateResource @@ -268,6 +269,7 @@ type ISchedtagCustomer interface { JSON(interface{}) *jsonutils.JSONDict Keyword() string GetSchedtags() []*computeapi.SchedtagConfig + ResourceKeyword() string } type SchedtagResourceW struct { @@ -384,7 +386,19 @@ func (p *BaseSchedtagPredicate) Execute( for idx, input := range inputs { fitResources := make([]ISchedtagCandidateResource, 0) errs := make([]core.PredicateFailureReason, 0) - for _, res := range resources { + matchedRes := make([]ISchedtagCandidateResource, 0) + for _, r := range resources { + if sp.IsResourceMatchInput(input, r) { + matchedRes = append(matchedRes, r) + } + } + if len(matchedRes) == 0 { + errs = append(errs, &FailReason{ + Reason: fmt.Sprintf("Not found matched %s, candidate: %s, %s: %s", input.ResourceKeyword(), c.Getter().Name(), input.Keyword(), input.JSON(input).String()), + Type: fmt.Sprintf("%s_match", input.ResourceKeyword()), + }) + } + for _, res := range matchedRes { if err := sp.IsResourceFitInput(u, c, res, input); err == nil { fitResources = append(fitResources, res) } else {