[REV] sort response by used memory (next cpu)

This commit is contained in:
bay1ts 2017-12-06 15:54:37 +08:00
parent 5c284f9581
commit 5987a7eacd
3 changed files with 57 additions and 15 deletions

View File

@ -40,6 +40,7 @@ import (
httputil "github.com/goodrain/rainbond/pkg/util/http"
"github.com/Sirupsen/logrus"
"sort"
)
//V2Routes v2Routes
@ -174,8 +175,9 @@ func (t *TenantStruct) TenantsWithResource(w http.ResponseWriter, r *http.Reques
res.UsedMEM=usedResInfo.MEM
result=append(result,&res)
}
httputil.ReturnSuccess(r, w, result)
pList := api_model.TenantResList(result)
sort.Sort(pList)
httputil.ReturnSuccess(r, w, pList)
return
}

View File

@ -26,19 +26,6 @@ import (
)
//TenantResource path参数
//swagger:parameters getVolumes getDepVolumes
type TenantResource struct {
AllocatedCPU int `json:"alloc_cpu"`
AllocatedMEM int `json:"alloc_memory"`
UsedCPU int `json:"used_cpu"`
UsedMEM int `json:"used_memory"`
Name string `json:"name"`
UUID string `json:"uuid"`
EID string `json:"eid"`
}
//ServiceGetCommon path参数
//swagger:parameters getVolumes getDepVolumes

View File

@ -0,0 +1,53 @@
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package model
type TenantResList []*TenantResource
//TenantResource path参数
//swagger:parameters getVolumes getDepVolumes
type TenantResource struct {
AllocatedCPU int `json:"alloc_cpu"`
AllocatedMEM int `json:"alloc_memory"`
UsedCPU int `json:"used_cpu"`
UsedMEM int `json:"used_memory"`
Name string `json:"name"`
UUID string `json:"uuid"`
EID string `json:"eid"`
}
func (list TenantResList) Len() int {
return len(list)
}
func (list TenantResList) Less(i, j int) bool {
if list[i].UsedMEM < list[j].UsedMEM {
return true
} else if list[i].UsedMEM > list[j].UsedMEM {
return false
} else {
return list[i].UsedCPU < list[j].UsedCPU
}
}
func (list TenantResList) Swap(i, j int) {
var temp *TenantResource = list[i]
list[i] = list[j]
list[j] = temp
}