forked from goodrain/rainbond
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tenantsResource.go
42 lines (34 loc) · 1.27 KB
/
tenantsResource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package handler
import (
"github.com/Sirupsen/logrus"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/pkg/errors"
)
// CheckTenantResource check tenant's resource is support action or not
func CheckTenantResource(tenant *dbmodel.Tenants, needMemory int) error {
ts, err := GetServiceManager().GetTenantRes(tenant.UUID)
if err != nil {
return err
}
logrus.Debugf("tenant limitMemory: %v, usedMemory: %v", tenant.LimitMemory, ts.UsedMEM)
if tenant.LimitMemory != 0 {
//tenant.LimitMemory: 租户的总资源 ts.UsedMEM: 租户使用的资源
avaiMemory := tenant.LimitMemory - ts.UsedMEM
if needMemory > avaiMemory {
logrus.Error("超出租户可用资源")
return errors.New("tenant_lack_of_memory")
}
}
clusterInfo, err := GetTenantManager().GetAllocatableResources() //节点可用资源
if err != nil {
return err
}
logrus.Debugf("cluster allocatedMemory: %v, tenantsUsedMemory; %v", clusterInfo.AllMemory, clusterInfo.RequestMemory)
// clusterInfo.AllMemory: 集群总资源 clusterInfo.RequestMemory: 集群已使用资源
clusterAvailMemory := clusterInfo.AllMemory - clusterInfo.RequestMemory
if int64(needMemory) > clusterAvailMemory {
logrus.Error("超出集群可用资源")
return errors.New("cluster_lack_of_memory")
}
return nil
}