mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 23:00:25 +08:00
节点列表增加下行流量,节点列表可以按CPU、内存、下行流量排序
This commit is contained in:
@@ -204,12 +204,20 @@ func (this *NodeDAO) CountAllEnabledNodes(tx *dbs.Tx) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListEnabledNodesMatch 列出单页节点
|
// ListEnabledNodesMatch 列出单页节点
|
||||||
func (this *NodeDAO) ListEnabledNodesMatch(tx *dbs.Tx, offset int64, size int64, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64, regionId int64) (result []*Node, err error) {
|
func (this *NodeDAO) ListEnabledNodesMatch(tx *dbs.Tx,
|
||||||
|
clusterId int64,
|
||||||
|
installState configutils.BoolState,
|
||||||
|
activeState configutils.BoolState,
|
||||||
|
keyword string,
|
||||||
|
groupId int64,
|
||||||
|
regionId int64,
|
||||||
|
order string,
|
||||||
|
offset int64,
|
||||||
|
size int64) (result []*Node, err error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Limit(size).
|
Limit(size).
|
||||||
DescPk().
|
|
||||||
Slice(&result)
|
Slice(&result)
|
||||||
|
|
||||||
// 集群
|
// 集群
|
||||||
@@ -253,6 +261,27 @@ func (this *NodeDAO) ListEnabledNodesMatch(tx *dbs.Tx, offset int64, size int64,
|
|||||||
query.Attr("regionId", regionId)
|
query.Attr("regionId", regionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
switch order {
|
||||||
|
case "cpuAsc":
|
||||||
|
query.Asc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.cpuUsage'), 0), 0)")
|
||||||
|
case "cpuDesc":
|
||||||
|
query.Desc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.cpuUsage'), 0), 0)")
|
||||||
|
case "memoryAsc":
|
||||||
|
query.Asc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.memoryUsage'), 0), 0)")
|
||||||
|
case "memoryDesc":
|
||||||
|
query.Desc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.memoryUsage'), 0), 0)")
|
||||||
|
case "trafficInAsc":
|
||||||
|
query.Asc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.trafficInBytes'), 0), 0)")
|
||||||
|
case "trafficInDesc":
|
||||||
|
query.Desc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.trafficInBytes'), 0), 0)")
|
||||||
|
case "trafficOutAsc":
|
||||||
|
query.Asc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.trafficOutBytes'), 0), 0)")
|
||||||
|
case "trafficOutDesc":
|
||||||
|
query.Desc("IF(JSON_EXTRACT(status, '$.updatedAt')>UNIX_TIMESTAMP()-120, IFNULL(JSON_EXTRACT(status, '$.trafficOutBytes'), 0), 0)")
|
||||||
|
}
|
||||||
|
query.DescPk()
|
||||||
|
|
||||||
_, err = query.FindAll()
|
_, err = query.FindAll()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -345,7 +374,13 @@ func (this *NodeDAO) FindAllInactiveNodesWithClusterId(tx *dbs.Tx, clusterId int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountAllEnabledNodesMatch 计算节点数量
|
// CountAllEnabledNodesMatch 计算节点数量
|
||||||
func (this *NodeDAO) CountAllEnabledNodesMatch(tx *dbs.Tx, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, groupId int64, regionId int64) (int64, error) {
|
func (this *NodeDAO) CountAllEnabledNodesMatch(tx *dbs.Tx,
|
||||||
|
clusterId int64,
|
||||||
|
installState configutils.BoolState,
|
||||||
|
activeState configutils.BoolState,
|
||||||
|
keyword string,
|
||||||
|
groupId int64,
|
||||||
|
regionId int64) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
query.State(NodeStateEnabled)
|
query.State(NodeStateEnabled)
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,27 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(tx, req.Offset, req.Size, req.NodeClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.NodeGroupId, req.NodeRegionId)
|
// 排序
|
||||||
|
var order = ""
|
||||||
|
if req.CpuAsc {
|
||||||
|
order = "cpuAsc"
|
||||||
|
} else if req.CpuDesc {
|
||||||
|
order = "cpuDesc"
|
||||||
|
} else if req.MemoryAsc {
|
||||||
|
order = "memoryAsc"
|
||||||
|
} else if req.MemoryDesc {
|
||||||
|
order = "memoryDesc"
|
||||||
|
} else if req.TrafficInAsc {
|
||||||
|
order = "trafficInAsc"
|
||||||
|
} else if req.TrafficInDesc {
|
||||||
|
order = "trafficInDesc"
|
||||||
|
} else if req.TrafficOutAsc {
|
||||||
|
order = "trafficOutAsc"
|
||||||
|
} else if req.TrafficOutDesc {
|
||||||
|
order = "trafficOutDesc"
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes, err := models.SharedNodeDAO.ListEnabledNodesMatch(tx, req.NodeClusterId, configutils.ToBoolState(req.InstallState), configutils.ToBoolState(req.ActiveState), req.Keyword, req.NodeGroupId, req.NodeRegionId, order, req.Offset, req.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user