Merge pull request #1770 from Zexi/feature/scheduler-resource-matched

scheduler: schedtag predicate match resources then do filter
This commit is contained in:
yunion-ci-robot
2019-07-17 13:47:58 +08:00
committed by GitHub
3 changed files with 38 additions and 1 deletions
@@ -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() {
@@ -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)
@@ -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 {