陈博文 6 days ago
commit 9f31d22472

@ -124,6 +124,7 @@ message NodeReply {
string architecture = 20; string architecture = 20;
string creation_timestamp = 21; string creation_timestamp = 21;
int64 disk_size = 22; int64 disk_size = 22;
repeated string resource_pools = 23;
} }

@ -149,6 +149,37 @@ func QueryDistinctNodes() ([]*Nodes, error) {
return nodes, nil return nodes, nil
} }
func QueryResourceNamesByIp(nodeIp string) ([]string, error) {
// 执行查询
rows, err := db.Query("select pool_name from resource_pool where id in (select distinct pool_id from nodes where node_ip=?)", nodeIp)
if err != nil {
log.Infof("Query failed: %v", err)
return nil, err
}
defer rows.Close()
// 存放结果的切片
resourcePoolNames := make([]string, 0)
// 遍历每一行
for rows.Next() {
var name string
err := rows.Scan(&name)
if err != nil {
log.Infof("Scan failed: %v", err)
return nil, err
}
resourcePoolNames = append(resourcePoolNames, name)
}
// 检查 rows 是否遍历中出错
if err := rows.Err(); err != nil {
return nil, err
}
return resourcePoolNames, nil
}
func InsertResourcePool(poolName string) (int64, error) { func InsertResourcePool(poolName string) (int64, error) {
querySql := "INSERT INTO resource_pool(pool_name) VALUES (?)" querySql := "INSERT INTO resource_pool(pool_name) VALUES (?)"

@ -6,6 +6,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"vgpu/internal/biz" "vgpu/internal/biz"
"vgpu/internal/database"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
@ -49,12 +50,18 @@ func (s *NodeService) GetAllNodes(ctx context.Context, req *pb.GetAllNodesReq) (
return nil, err return nil, err
} }
coreTotal, memoryTotal, err := s.queryNodeMetrics(ctx, node.Name) resourcePoolNames, err := database.QueryResourceNamesByIp(node.IP)
if err == nil { if err != nil {
nodeReply.CoreTotal = int64(coreTotal) return nil, err
nodeReply.MemoryTotal = int64(memoryTotal)
} }
nodeReply.ResourcePools = resourcePoolNames
//coreTotal, memoryTotal, err := s.queryNodeMetrics(ctx, node.Name)
//if err == nil {
// nodeReply.CoreTotal = int64(coreTotal)
// nodeReply.MemoryTotal = int64(memoryTotal)
//}
if filters.Ip != "" && filters.Ip != nodeReply.Ip { if filters.Ip != "" && filters.Ip != nodeReply.Ip {
continue continue
} }

@ -300,6 +300,10 @@ components:
type: string type: string
diskSize: diskSize:
type: string type: string
resourcePools:
type: array
items:
type: string
NodesReply: NodesReply:
type: object type: object
properties: properties:

Loading…
Cancel
Save