change tenant list sort

This commit is contained in:
barnettZQG 2020-08-16 11:55:29 +08:00
parent 5069f4cdf8
commit 07fb7e406d
2 changed files with 28 additions and 11 deletions

View File

@ -95,15 +95,21 @@ func (list TenantList) Less(i, j int) bool {
if list[i].MemoryRequest > list[j].MemoryRequest {
return true
}
if list[i].CPURequest > list[j].CPURequest {
return true
}
if list[i].RunningAppNum > list[j].RunningAppNum {
return true
}
// Minimum priority
if list[i].Tenants.LimitMemory > list[j].Tenants.LimitMemory {
return true
if list[i].MemoryRequest == list[j].MemoryRequest {
if list[i].CPURequest > list[j].CPURequest {
return true
}
if list[i].CPURequest == list[j].CPURequest {
if list[i].RunningAppNum > list[j].RunningAppNum {
return true
}
if list[i].RunningAppNum == list[j].RunningAppNum {
// Minimum priority
if list[i].Tenants.LimitMemory > list[j].Tenants.LimitMemory {
return true
}
}
}
}
return false
}

View File

@ -38,12 +38,23 @@ func TestTenantList(t *testing.T) {
tenants.Add(t2)
t3 := &TenantAndResource{
MemoryRequest: 80,
MemoryRequest: 0,
}
t3.LimitMemory = 60
t4 := &TenantAndResource{
MemoryRequest: 0,
}
t4.LimitMemory = 70
t5 := &TenantAndResource{
RunningAppNum: 10,
}
t5.LimitMemory = 0
tenants.Add(t3)
sort.Sort(sort.Reverse(tenants))
tenants.Add(t4)
tenants.Add(t5)
sort.Sort(tenants)
for _, ten := range tenants {
t.Logf("%+v", ten)
}