fix: cpu和内存字段重新定义

main
youys 4 days ago
parent 435a03fa71
commit 351b95503c

@ -109,9 +109,9 @@ message NodeReply {
int32 vgpu_used = 5; int32 vgpu_used = 5;
int32 vgpu_total = 6; int32 vgpu_total = 6;
int32 core_used = 7; int32 core_used = 7;
int64 core_total = 8; int32 core_total = 8;
int32 memory_used = 9; int32 memory_used = 9;
int64 memory_total = 10; int32 memory_total = 10;
string uid = 11; string uid = 11;
string name = 12; string name = 12;
int32 card_cnt = 13; int32 card_cnt = 13;
@ -125,6 +125,8 @@ message NodeReply {
string creation_timestamp = 21; string creation_timestamp = 21;
int64 disk_size = 22; int64 disk_size = 22;
repeated string resource_pools = 23; repeated string resource_pools = 23;
int64 cpu_cores = 24;
int64 total_memory = 25;
} }

@ -115,9 +115,9 @@ message PoolNodeReply {
int32 vgpu_used = 5; int32 vgpu_used = 5;
int32 vgpu_total = 6; int32 vgpu_total = 6;
int32 core_used = 7; int32 core_used = 7;
int64 core_total = 8; int32 core_total = 8;
int64 memory_used = 9; int32 memory_used = 9;
int64 memory_total = 10; int32 memory_total = 10;
string uid = 11; string uid = 11;
string name = 12; string name = 12;
int32 card_cnt = 13; int32 card_cnt = 13;
@ -131,6 +131,8 @@ message PoolNodeReply {
string creation_timestamp = 21; string creation_timestamp = 21;
int64 disk_size = 22; int64 disk_size = 22;
int64 node_id = 23; int64 node_id = 23;
int64 cpu_cores = 24;
int64 total_memory = 25;
} }
message ResourcePoolDetailRequest { message ResourcePoolDetailRequest {

@ -150,16 +150,16 @@ func (s *NodeService) buildNodeReply(ctx context.Context, node *biz.Node) (*pb.N
KubeProxyVersion: node.KubeProxyVersion, KubeProxyVersion: node.KubeProxyVersion,
Architecture: node.Architecture, Architecture: node.Architecture,
CreationTimestamp: node.CreationTimestamp, CreationTimestamp: node.CreationTimestamp,
CoreTotal: node.CPUCores,
MemoryTotal: node.TotalMemory,
DiskSize: node.DiskTotal, DiskSize: node.DiskTotal,
CpuCores: node.CPUCores,
TotalMemory: node.TotalMemory,
} }
for _, device := range node.Devices { for _, device := range node.Devices {
nodeReply.Type = append(nodeReply.Type, device.Type) nodeReply.Type = append(nodeReply.Type, device.Type)
nodeReply.VgpuTotal += device.Count nodeReply.VgpuTotal += device.Count
nodeReply.CoreTotal += int64(device.Devcore) nodeReply.CoreTotal += device.Devcore
nodeReply.MemoryTotal += int64(device.Devmem) nodeReply.MemoryTotal += device.Devmem
vGPU, core, memory, err := s.pod.StatisticsByDeviceId(ctx, device.AliasId) vGPU, core, memory, err := s.pod.StatisticsByDeviceId(ctx, device.AliasId)
if err == nil { if err == nil {
nodeReply.VgpuUsed += vGPU nodeReply.VgpuUsed += vGPU

@ -2,7 +2,6 @@ package service
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
@ -176,8 +175,6 @@ func (s *ResourcePoolService) GetDetail(ctx context.Context, req *pb.ResourcePoo
nodes, err := s.uc.ListAllNodesV2(ctx) nodes, err := s.uc.ListAllNodesV2(ctx)
for _, poolNode := range poolNodes { for _, poolNode := range poolNodes {
b1, _ := json.MarshalIndent(poolNode, "", " ")
log.Info(string(b1))
node := s.filterNode(poolNode.NodeIp, nodes) node := s.filterNode(poolNode.NodeIp, nodes)
if node == nil { if node == nil {
continue continue
@ -253,8 +250,6 @@ func (s *ResourcePoolService) simpleQuery(ctx context.Context, query string) int
func (s *ResourcePoolService) filterNode(nodeIp string, nodes []*biz.Node) *biz.Node { func (s *ResourcePoolService) filterNode(nodeIp string, nodes []*biz.Node) *biz.Node {
for _, node := range nodes { for _, node := range nodes {
b, _ := json.MarshalIndent(node, "", " ")
log.Info(string(b))
if node.IP == nodeIp { if node.IP == nodeIp {
return node return node
} }
@ -278,21 +273,21 @@ func (s *ResourcePoolService) buildNodeReply(ctx context.Context, node *biz.Node
KubeProxyVersion: node.KubeProxyVersion, KubeProxyVersion: node.KubeProxyVersion,
Architecture: node.Architecture, Architecture: node.Architecture,
CreationTimestamp: node.CreationTimestamp, CreationTimestamp: node.CreationTimestamp,
CoreTotal: node.CPUCores, CpuCores: node.CPUCores,
MemoryTotal: node.TotalMemory, TotalMemory: node.TotalMemory,
DiskSize: node.DiskTotal, DiskSize: node.DiskTotal,
} }
for _, device := range node.Devices { for _, device := range node.Devices {
nodeReply.Type = append(nodeReply.Type, device.Type) nodeReply.Type = append(nodeReply.Type, device.Type)
nodeReply.VgpuTotal += device.Count nodeReply.VgpuTotal += device.Count
nodeReply.CoreTotal += int64(device.Devcore) nodeReply.CoreTotal += device.Devcore
nodeReply.MemoryTotal += int64(device.Devmem) nodeReply.MemoryTotal += device.Devmem
vGPU, core, memory, err := s.pod.StatisticsByDeviceId(ctx, device.AliasId) vGPU, core, memory, err := s.pod.StatisticsByDeviceId(ctx, device.AliasId)
if err == nil { if err == nil {
nodeReply.VgpuUsed += vGPU nodeReply.VgpuUsed += vGPU
nodeReply.CoreUsed += core nodeReply.CoreUsed += core
nodeReply.MemoryUsed += int64(memory) nodeReply.MemoryUsed += memory
} }
} }

@ -3,50 +3,151 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: Container API title: ResourcePool API
version: 0.0.1 version: 0.0.1
paths: paths:
/v1/container: /v1/available/nodes:
get: get:
tags: tags:
- Container - ResourcePool
operationId: Container_GetContainer operationId: ResourcePool_GetAvailableNodes
parameters: responses:
- name: name "200":
in: query description: OK
content:
application/json:
schema: schema:
type: string $ref: '#/components/schemas/AvailableNodesResponse'
- name: podUid default:
in: query description: Default error response
content:
application/json:
schema: schema:
type: string $ref: '#/components/schemas/Status'
- name: deviceId /v1/resource/pool/create:
in: query post:
tags:
- ResourcePool
operationId: ResourcePool_Create
requestBody:
content:
application/json:
schema: schema:
type: string $ref: '#/components/schemas/ResourcePoolCreateRequest'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/BaseResponse'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
/v1/resource/pool/delete:
post:
tags:
- ResourcePool
operationId: ResourcePool_Delete
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ResourcePoolDeleteRequest'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/BaseResponse'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
/v1/resource/pool/detail:
post:
tags:
- ResourcePool
operationId: ResourcePool_GetDetail
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ResourcePoolDetailRequest'
required: true
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ResourcePoolDetailResponse'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
/v1/resource/pool/list:
get:
tags:
- ResourcePool
operationId: ResourcePool_List
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ResourcePoolListResponse'
default:
description: Default error response
content:
application/json:
schema:
$ref: '#/components/schemas/Status'
/v1/resource/pool/removeNode:
post:
tags:
- ResourcePool
operationId: ResourcePool_RemoveNode
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RemoveNodeRequest'
required: true
responses: responses:
"200": "200":
description: OK description: OK
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ContainerReply' $ref: '#/components/schemas/BaseResponse'
default: default:
description: Default error response description: Default error response
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/Status' $ref: '#/components/schemas/Status'
/v1/containers: /v1/resource/pool/update:
post: post:
tags: tags:
- Container - ResourcePool
operationId: Container_GetAllContainers operationId: ResourcePool_Update
requestBody: requestBody:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/GetAllContainersReq' $ref: '#/components/schemas/ResourcePoolUpdateRequest'
required: true required: true
responses: responses:
"200": "200":
@ -54,7 +155,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ContainersReply' $ref: '#/components/schemas/BaseResponse'
default: default:
description: Default error response description: Default error response
content: content:
@ -63,119 +164,191 @@ paths:
$ref: '#/components/schemas/Status' $ref: '#/components/schemas/Status'
components: components:
schemas: schemas:
ContainerReply: AvailableNodesInfo:
type: object type: object
properties: properties:
name: nodeName:
type: string
cpuCores:
type: string
gpuNum:
type: string
gpuMemory:
type: string
totalMemory:
type: string
diskSize:
type: string
nodeIp:
type: string
AvailableNodesResponse:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/AvailableNodesInfo'
BaseResponse:
type: object
properties:
code:
type: integer
format: int32
message:
type: string type: string
status: data:
type: object
GoogleProtobufAny:
type: object
properties:
'@type':
type: string type: string
appName: description: The type of the serialized message.
additionalProperties: true
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
Nodes:
type: object
properties:
nodeIp:
type: string type: string
nodeName: nodeName:
type: string type: string
allocatedDevices: PoolNodeReply:
type: object
properties:
ip:
type: string
isSchedulable:
type: boolean
isReady:
type: boolean
type:
type: array
items:
type: string
vgpuUsed:
type: integer type: integer
format: int32 format: int32
allocatedCores: vgpuTotal:
type: integer type: integer
format: int32 format: int32
allocatedMem: coreUsed:
type: integer type: integer
format: int32 format: int32
type: coreTotal:
type: string type: integer
createTime: format: int32
type: string memoryUsed:
startTime: type: integer
format: int32
memoryTotal:
type: integer
format: int32
uid:
type: string type: string
endTime: name:
type: string type: string
podUid: cardCnt:
type: integer
format: int32
osImage:
type: string type: string
nodeUid: operatingSystem:
type: string type: string
resourcePools: kernelVersion:
type: array
items:
type: string type: string
flavor: containerRuntimeVersion:
type: string type: string
priority: kubeletVersion:
type: string type: string
namespace: kubeProxyVersion:
type: string type: string
deviceIds: architecture:
type: array
items:
type: string type: string
podName: creationTimestamp:
type: string type: string
taskType: diskSize:
type: string type: string
shixunName: nodeId:
type: string type: string
role: cpuCores:
type: string type: string
username: totalMemory:
type: string type: string
requestedCpuCores: RemoveNodeRequest:
type: number type: object
format: float properties:
requestedMemory: nodeId:
type: string type: string
ContainersReply: ResourcePoolCreateRequest:
type: object type: object
properties: properties:
items: poolName:
type: string
nodes:
type: array type: array
items: items:
$ref: '#/components/schemas/ContainerReply' $ref: '#/components/schemas/Nodes'
GetAllContainersReq: ResourcePoolDeleteRequest:
type: object type: object
properties: properties:
filters: poolId:
$ref: '#/components/schemas/GetAllContainersReq_Filters' type: string
pageSize: ResourcePoolDetailRequest:
$ref: '#/components/schemas/GetAllContainersReq_PageSize'
GetAllContainersReq_Filters:
type: object type: object
properties: properties:
name: poolId:
type: string type: string
nodeName: ResourcePoolDetailResponse:
type: object
properties:
list:
type: array
items:
$ref: '#/components/schemas/PoolNodeReply'
ResourcePoolListData:
type: object
properties:
poolId:
type: string type: string
status: poolName:
type: string type: string
deviceId: cpuCores:
type: string type: string
nodeUid: nodeNum:
type: string type: string
resourceGroup: gpuNum:
type: string type: string
priority: availableMemory:
type: string type: string
GetAllContainersReq_PageSize: totalMemory:
type: object
properties:
pageSize:
type: integer
format: int32
pageNo:
type: integer
format: int32
sort:
type: string type: string
sortField: diskSize:
type: string type: string
GoogleProtobufAny: nodeList:
type: array
items:
$ref: '#/components/schemas/Nodes'
linkUrl:
type: string
ResourcePoolListResponse:
type: object type: object
properties: properties:
'@type': data:
type: array
items:
$ref: '#/components/schemas/ResourcePoolListData'
ResourcePoolUpdateRequest:
type: object
properties:
poolId:
type: string type: string
description: The type of the serialized message. poolName:
additionalProperties: true type: string
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message. nodes:
type: array
items:
$ref: '#/components/schemas/Nodes'
Status: Status:
type: object type: object
properties: properties:
@ -193,4 +366,4 @@ components:
description: A list of messages that carry the error details. There is a common set of message types for APIs to use. description: A list of messages that carry the error details. There is a common set of message types for APIs to use.
description: 'The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).' description: 'The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).'
tags: tags:
- name: Container - name: ResourcePool

Loading…
Cancel
Save