scheduler: fix disk allocated not balanced

This commit is contained in:
Zexi Li
2020-03-14 16:51:45 +08:00
parent 2f50aae082
commit 8031105ea2
8 changed files with 141 additions and 21 deletions
@@ -17,7 +17,6 @@ package predicates
import (
"fmt"
"yunion.io/x/log"
"yunion.io/x/pkg/utils"
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
@@ -28,6 +27,7 @@ import (
type DiskSchedtagPredicate struct {
*BaseSchedtagPredicate
storageUsed map[string]int64
}
func (p *DiskSchedtagPredicate) Name() string {
@@ -37,6 +37,7 @@ func (p *DiskSchedtagPredicate) Name() string {
func (p *DiskSchedtagPredicate) Clone() core.FitPredicate {
return &DiskSchedtagPredicate{
BaseSchedtagPredicate: NewBaseSchedtagPredicate(),
storageUsed: make(map[string]int64),
}
}
@@ -145,19 +146,24 @@ func (p *DiskSchedtagPredicate) DoSelect(
}
func (p *DiskSchedtagPredicate) GetCandidateResourceSortScore(selectRes ISchedtagCandidateResource) int64 {
return selectRes.(*api.CandidateStorage).GetFreeCapacity()
s := selectRes.(*api.CandidateStorage)
return s.GetFreeCapacity()
}
func (p *DiskSchedtagPredicate) AddSelectResult(index int, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource) {
storageIds := []string{}
func (p *DiskSchedtagPredicate) AddSelectResult(index int, input ISchedtagCustomer, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource) {
storages := []*schedapi.CandidateStorage{}
for _, res := range selectRes {
storageIds = append(storageIds, res.GetId())
cs := res.(*api.CandidateStorage)
storages = append(storages, &schedapi.CandidateStorage{
Id: cs.GetId(),
Name: cs.GetName(),
FreeCapacity: cs.GetFreeCapacity(),
})
}
ret := &schedapi.CandidateDisk{
Index: index,
StorageIds: storageIds,
ret := &schedapi.CandidateDiskV2{
Index: index,
Storages: storages,
}
log.Debugf("Suggestion storages %v for disk%d", storageIds, index)
output.Disks = append(output.Disks, ret)
}
@@ -266,7 +266,7 @@ func (p *NetworkSchedtagPredicate) DoSelect(
return sNets.Results()
}
func (p *NetworkSchedtagPredicate) AddSelectResult(index int, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource) {
func (p *NetworkSchedtagPredicate) AddSelectResult(index int, input ISchedtagCustomer, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource) {
networkIds := []string{}
for _, res := range selectRes {
networkIds = append(networkIds, res.GetId())
@@ -256,7 +256,7 @@ type ISchedtagPredicateInstance interface {
IsResourceFitInput(unit *core.Unit, c core.Candidater, res ISchedtagCandidateResource, input ISchedtagCustomer) core.PredicateFailureReason
DoSelect(c core.Candidater, input ISchedtagCustomer, res []ISchedtagCandidateResource) []ISchedtagCandidateResource
AddSelectResult(index int, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource)
AddSelectResult(index int, input ISchedtagCustomer, selectRes []ISchedtagCandidateResource, output *core.AllocatedResource)
GetCandidateResourceSortScore(candidate ISchedtagCandidateResource) int64
}
@@ -478,7 +478,7 @@ func (p *BaseSchedtagPredicate) OnSelectEnd(sp ISchedtagPredicateInstance, u *co
sortRes := newSortCandidateResource(sp, selRes)
sort.Sort(sortRes)
//log.Debugf("sort result: %s", sortRes.DebugString())
sp.AddSelectResult(idx, sortRes.res, output)
sp.AddSelectResult(idx, inputs[idx], sortRes.res, output)
}
}