服务发布
This commit is contained in:
@ -9,11 +9,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Tag(name ="服务发布相关接口")
|
@Tag(name ="服务发布相关接口")
|
||||||
@ -34,29 +32,81 @@ public class publishController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary ="新增发布请求")
|
@Operation(summary ="新增发布请求")
|
||||||
@Transactional
|
@Transactional
|
||||||
public OptResult<ServicePublishVO> save(@RequestBody ServicePublishDTO servicePublishDTO){
|
public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) {
|
||||||
log.info("模型发布请求:{}", servicePublishDTO);
|
log.info("模型发布请求:{}", servicePublishDTO);
|
||||||
publishService.save(servicePublishDTO);
|
publishService.save(servicePublishDTO);
|
||||||
Long modelId = servicePublishDTO.getModelId();
|
Long modelId = servicePublishDTO.getModelId();
|
||||||
String key="Model_" + modelId;
|
String key = "Model_" + modelId;
|
||||||
//查询redis是否存在GPU相关资源数据
|
//查询redis是否存在GPU相关资源数据
|
||||||
ServicePublishVO servicePublishVO = (ServicePublishVO) redisTemplate.opsForValue().get(key);
|
List<ServicePublishVO> list;
|
||||||
|
list = (List<ServicePublishVO>) redisTemplate.opsForValue().get(key);
|
||||||
//如果存在,直接返回,无须查询数据库
|
//如果存在,直接返回,无须查询数据库
|
||||||
if (servicePublishVO != null){
|
if (list != null) {
|
||||||
return OptResult.success(servicePublishVO);
|
return OptResult.success(list);
|
||||||
|
}else {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
String modelConfig = publishService.getByModelId(modelId);
|
||||||
|
if (modelConfig == null) {
|
||||||
|
log.error("模型配置为空,modelId={}", modelId);
|
||||||
|
}
|
||||||
|
String[] keyValuePairs = modelConfig.split("\\|");
|
||||||
|
String GPUMemorySize = null;
|
||||||
|
String GPUModel = null;
|
||||||
|
for (String pair : keyValuePairs) {
|
||||||
|
pair = pair.trim();
|
||||||
|
if (pair.startsWith("GPU")) {
|
||||||
|
GPUModel = pair.split(";", 2)[1];
|
||||||
|
} else if (pair.startsWith("Memory:")) {
|
||||||
|
GPUMemorySize = pair.split(":", 2)[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServicePublishVO servicePublishVO = new ServicePublishVO();
|
||||||
|
servicePublishVO.setIp(servicePublishDTO.getIp());
|
||||||
|
servicePublishVO.setModelId(servicePublishDTO.getModelId());
|
||||||
|
servicePublishVO.setGPUMemorySize(GPUMemorySize);
|
||||||
|
servicePublishVO.setGPUModel(GPUModel);
|
||||||
|
//todo 调用模型部署,传递信息
|
||||||
|
|
||||||
|
servicePublishVO.setApiUrl(servicePublishDTO.getApiUrl());
|
||||||
|
list.add(servicePublishVO);
|
||||||
|
redisTemplate.opsForValue().set(key,list);
|
||||||
|
//一个ip上有多个机器
|
||||||
|
// 假设从 Redis 获取的列表元素是 MachineInfo 类型
|
||||||
|
String ip = servicePublishVO.getIp();
|
||||||
|
String key1 = ip;
|
||||||
|
List<MachineInfo> machineList = (List<MachineInfo>) redisTemplate.opsForValue().get(key1);
|
||||||
|
|
||||||
|
|
||||||
|
// 模型所需的 GPU 资源
|
||||||
|
String requiredGPUModel = servicePublishVO.getGPUModel();
|
||||||
|
Integer requiredGPUMemory = Integer.valueOf(servicePublishVO.getGPUMemorySize());
|
||||||
|
|
||||||
|
if (machineList != null) {
|
||||||
|
for (MachineInfo machine : machineList) {
|
||||||
|
// 获取机器的 GPU 资源
|
||||||
|
String machineGPUModel = machine.getGPUModel();
|
||||||
|
Integer machineGPUMemory = machine.getGPUMemorySize();
|
||||||
|
|
||||||
|
// 判断机器是否满足模型需求
|
||||||
|
if (requiredGPUModel.equals(machineGPUModel) &&
|
||||||
|
machineGPUMemory >= requiredGPUMemory) {
|
||||||
|
return OptResult.success(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String key3 = "wait_queue";
|
||||||
|
redisTemplate.opsForValue().set(key3,list);
|
||||||
|
//todo资源释放时候优先分配等待队列中任务
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String modelConfig = publishService.getByModelId(modelId);
|
return OptResult.success(list);
|
||||||
//todo 序列化结果提出来
|
|
||||||
|
|
||||||
ServicePublish servicePublish = new ServicePublish();
|
|
||||||
String ip = servicePublishDTO.getIp();
|
|
||||||
servicePublish.setIp(ip);
|
|
||||||
|
|
||||||
return OptResult.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机器信息实体类
|
||||||
|
* @author hky
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MachineInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String id; // 机器唯一标识
|
||||||
|
private String ip; // IP 地址
|
||||||
|
private String hostname; // 主机名
|
||||||
|
private Integer cpuCoreNum; // CPU 核心数
|
||||||
|
private Long memoryTotal; // 总内存 (MB)
|
||||||
|
private Long memoryUsed; // 已用内存 (MB)
|
||||||
|
private String GPUModel; // GPU 型号
|
||||||
|
private Integer GPUMemorySize; // GPU 显存大小 (GB)
|
||||||
|
private Integer GPUCount; // GPU 数量
|
||||||
|
private Integer status; // 机器状态 (0: 离线, 1: 在线, 2: 繁忙)
|
||||||
|
private String os; // 操作系统
|
||||||
|
private String region; // 所属区域
|
||||||
|
private String zone; // 可用区
|
||||||
|
private Date createTime; // 创建时间
|
||||||
|
private Date updateTime; // 更新时间
|
||||||
|
private Map<String, String> labels; // 自定义标签
|
||||||
|
}
|
@ -20,6 +20,7 @@ public class ServicePublishVO implements Serializable {
|
|||||||
private String GPUModel;
|
private String GPUModel;
|
||||||
private String ip;
|
private String ip;
|
||||||
private String GPUMemorySize;
|
private String GPUMemorySize;
|
||||||
|
private String apiUrl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user