From 47808327f629038516383b055ff52ac36295e95d Mon Sep 17 00:00:00 2001 From: youys <1272586223@qq.com> Date: Thu, 7 Aug 2025 11:20:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B5=84=E6=BA=90=E6=B1=A0=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/container.proto | 2 + server/api/v1/resource_pool.proto | 1 + server/config/config.yaml | 3 +- server/config/db.sql | 1 + server/internal/biz/pod.go | 28 ++++++------ server/internal/data/pod.go | 25 ++++++----- server/internal/service/card.go | 46 ++++++++++++++++---- server/internal/service/container.go | 55 ++++++++++++++++++++---- server/internal/service/resource_pool.go | 4 ++ server/openapi.yaml | 5 +++ 10 files changed, 128 insertions(+), 42 deletions(-) diff --git a/server/api/v1/container.proto b/server/api/v1/container.proto index b9756f6..c190d35 100644 --- a/server/api/v1/container.proto +++ b/server/api/v1/container.proto @@ -71,6 +71,8 @@ message ContainerReply { string shixun_name = 21; string role = 22; string username = 23; + float requested_cpu_cores = 24; + int64 requested_memory = 25; } message ContainersReply { diff --git a/server/api/v1/resource_pool.proto b/server/api/v1/resource_pool.proto index f7576c9..990b51f 100644 --- a/server/api/v1/resource_pool.proto +++ b/server/api/v1/resource_pool.proto @@ -151,6 +151,7 @@ message ResourcePoolListData{ int64 total_memory = 7; // kb int64 disk_size = 8; repeated Nodes node_list = 9; + string link_url = 10; } message ResourcePoolListRequest { diff --git a/server/config/config.yaml b/server/config/config.yaml index 3d57573..fe8b267 100644 --- a/server/config/config.yaml +++ b/server/config/config.yaml @@ -17,4 +17,5 @@ database: driver: mysql dataSourceName: testeducoder:TEST@123@tcp(testeducoder-public.mysql.polardb.rds.aliyuncs.com:3306)/hami?parseTime=true&loc=Local web_domain: http://172.16.100.14 -big_model_resource_pool_name: "大模型资源池" \ No newline at end of file +big_model_resource_pool_name: "大模型资源池" +big_model_resource_pool_link_url: "https://www.baidu.com" \ No newline at end of file diff --git a/server/config/db.sql b/server/config/db.sql index 86d07c4..20b5801 100644 --- a/server/config/db.sql +++ b/server/config/db.sql @@ -17,3 +17,4 @@ create table nodes( update_time timestamp default current_timestamp on update current_timestamp ); +INSERT INTO hami.resource_pool (pool_name) VALUES ('大模型资源池'); diff --git a/server/internal/biz/pod.go b/server/internal/biz/pod.go index e5bbb67..cc8b41b 100644 --- a/server/internal/biz/pod.go +++ b/server/internal/biz/pod.go @@ -9,19 +9,21 @@ import ( ) type Container struct { - Name string - UUID string - ContainerIdx int - NodeName string - PodUID string - PodName string - ContainerDevices ContainerDevices - Status string - CreateTime time.Time - Priority string - NodeUID string - Namespace string - TpiID string + Name string + UUID string + ContainerIdx int + NodeName string + PodUID string + PodName string + ContainerDevices ContainerDevices + Status string + CreateTime time.Time + Priority string + NodeUID string + Namespace string + TpiID string + RequestedCpuCores float32 + RequestedMemory int64 } type PodInfo struct { diff --git a/server/internal/data/pod.go b/server/internal/data/pod.go index 8c05c96..96c30c9 100644 --- a/server/internal/data/pod.go +++ b/server/internal/data/pod.go @@ -93,6 +93,7 @@ func (r *podRepo) addPod(pod *corev1.Pod, nodeID string, devices biz.PodDevices) r.mutex.Lock() defer r.mutex.Unlock() ctrs := r.fetchContainerInfo(pod) + pi := &biz.PodInfo{Name: pod.Name, UID: pod.UID, Namespace: pod.Namespace, NodeID: nodeID, Devices: devices, Ctrs: ctrs, Labels: pod.Labels} r.pods[pod.UID] = pi r.allPods = append(r.allPods, pi) @@ -137,17 +138,19 @@ func (r *podRepo) fetchContainerInfo(pod *corev1.Pod) []*biz.Container { for i, ctr := range pod.Spec.Containers { c := &biz.Container{ - Name: ctr.Name, - UUID: ctrIdMaps[ctr.Name], - ContainerIdx: i, - NodeName: pod.Spec.NodeName, - PodName: pod.Name, - PodUID: string(pod.UID), - Status: containerStat[ctr.Name], - NodeUID: r.GetNodeUUID(pod), - Namespace: pod.Namespace, - CreateTime: r.GetCreateTime(pod), - ContainerDevices: bizContainerDevices[i], + Name: ctr.Name, + UUID: ctrIdMaps[ctr.Name], + ContainerIdx: i, + NodeName: pod.Spec.NodeName, + PodName: pod.Name, + PodUID: string(pod.UID), + Status: containerStat[ctr.Name], + NodeUID: r.GetNodeUUID(pod), + Namespace: pod.Namespace, + CreateTime: r.GetCreateTime(pod), + ContainerDevices: bizContainerDevices[i], + RequestedCpuCores: float32(ctr.Resources.Requests.Cpu().MilliValue()) / 1000, + RequestedMemory: ctr.Resources.Requests.Memory().Value(), } if len(bizContainerDevices[i]) > 0 { c.Priority = bizContainerDevices[i][0].Priority diff --git a/server/internal/service/card.go b/server/internal/service/card.go index da96b05..b11914d 100644 --- a/server/internal/service/card.go +++ b/server/internal/service/card.go @@ -3,6 +3,8 @@ package service import ( "context" "fmt" + "github.com/go-kratos/kratos/v2/log" + "slices" "sort" "strings" pb "vgpu/api/v1" @@ -31,17 +33,43 @@ func (s *CardService) GetAllGPUs(ctx context.Context, req *pb.GetAllGpusReq) (*p var res = &pb.GPUsReply{List: []*pb.GPUReply{}} for _, device := range deviceInfos { gpu := &pb.GPUReply{} - nodeName := strings.Trim(filters.NodeName, " ") - if nodeName != "" && nodeName != device.NodeName { - continue + //nodeName := strings.Trim(filters.NodeName, " ") + //if nodeName != "" && nodeName != device.NodeName { + // continue + //} + //deviceType := strings.Trim(filters.Type, " ") + //if deviceType != "" && deviceType != device.Type { + // continue + //} + //deviceUid := strings.Trim(filters.Uid, " ") + //if deviceUid != "" && deviceUid != device.Id { + // continue + //} + + nodeNames := strings.Trim(filters.NodeName, " ") + if nodeNames != "" { + names := strings.Split(nodeNames, "|") + log.Info("GetAllGPUs names: ", names) + if !slices.Contains(names, device.NodeName) { + continue + } } - deviceType := strings.Trim(filters.Type, " ") - if deviceType != "" && deviceType != device.Type { - continue + + deviceTypes := strings.Trim(filters.Type, " ") + if deviceTypes != "" { + types := strings.Split(deviceTypes, "|") + log.Info("GetAllGPUs types: ", types) + if !slices.Contains(types, device.Type) { + continue + } } - deviceUid := strings.Trim(filters.Uid, " ") - if deviceUid != "" && deviceUid != device.Id { - continue + deviceUids := strings.Trim(filters.Uid, " ") + if deviceUids != "" { + uids := strings.Split(deviceUids, "|") + log.Info("GetAllGPUs uids: ", uids) + if !slices.Contains(uids, device.NodeUid) { + continue + } } gpu.Uuid = device.Id gpu.NodeName = device.NodeName diff --git a/server/internal/service/container.go b/server/internal/service/container.go index 296c4e3..ccba6f4 100644 --- a/server/internal/service/container.go +++ b/server/internal/service/container.go @@ -40,18 +40,55 @@ func (s *ContainerService) GetAllContainers(ctx context.Context, req *pb.GetAllC } var res = &pb.ContainersReply{Items: []*pb.ContainerReply{}} for _, container := range containers { - if filters.Name != "" && !strings.Contains(container.Name, filters.Name) { - continue + //if filters.Name != "" && !strings.Contains(container.Name, filters.Name) { + // continue + //} + //if filters.NodeName != "" && filters.NodeName != container.NodeName { + // continue + //} + //if filters.Status != "" && filters.Status != container.Status { + // continue + //} + //if filters.NodeUid != "" && filters.NodeUid != container.NodeUID { + // continue + //} + + names := strings.Trim(filters.Name, " ") + if names != "" { + nameList := strings.Split(names, "|") + log.Info("GetAllContainers names: ", nameList) + if !slices.Contains(nameList, container.Name) { + continue + } } - if filters.NodeName != "" && filters.NodeName != container.NodeName { - continue + + nodeNames := strings.Trim(filters.NodeName, " ") + if nodeNames != "" { + names := strings.Split(nodeNames, "|") + log.Info("GetAllContainers node names: ", names) + if !slices.Contains(names, container.NodeName) { + continue + } } - if filters.Status != "" && filters.Status != container.Status { - continue + + statuses := strings.Trim(filters.Status, " ") + if statuses != "" { + statusList := strings.Split(statuses, "|") + log.Info("GetAllContainers statuses: ", statusList) + if !slices.Contains(statusList, container.Status) { + continue + } } - if filters.NodeUid != "" && filters.NodeUid != container.NodeUID { - continue + + nodeUids := strings.Trim(filters.NodeUid, " ") + if nodeUids != "" { + uids := strings.Split(nodeUids, "|") + log.Info("GetAllContainers node UIDs: ", uids) + if !slices.Contains(uids, container.NodeUID) { + continue + } } + priority := strings.Trim(filters.Priority, " ") if priority != "" { if (priority == "0" && container.Priority == "1") || @@ -140,6 +177,8 @@ func (s *ContainerService) GetContainer(ctx context.Context, req *pb.GetContaine ctrReply.NodeUid = container.NodeUID ctrReply.Namespace = container.Namespace ctrReply.Priority = container.Priority + ctrReply.RequestedCpuCores = container.RequestedCpuCores + ctrReply.RequestedMemory = container.RequestedMemory for _, containerDevice := range container.ContainerDevices { if req.DeviceId != "" && req.DeviceId != containerDevice.UUID { continue diff --git a/server/internal/service/resource_pool.go b/server/internal/service/resource_pool.go index 027c9fc..eb95ce6 100644 --- a/server/internal/service/resource_pool.go +++ b/server/internal/service/resource_pool.go @@ -155,6 +155,10 @@ func (s *ResourcePoolService) List(ctx context.Context, req *pb.ResourcePoolList } data = append(data, &poolData) } + + listData := data[0] + linkUrl, _ := database.Get("big_model_resource_pool_link_url") + listData.LinkUrl = linkUrl.(string) return &pb.ResourcePoolListResponse{Data: data}, nil } diff --git a/server/openapi.yaml b/server/openapi.yaml index fbfd7a2..c1755ea 100644 --- a/server/openapi.yaml +++ b/server/openapi.yaml @@ -119,6 +119,11 @@ components: type: string username: type: string + requestedCpuCores: + type: number + format: float + requestedMemory: + type: string ContainersReply: type: object properties: