Merge remote-tracking branch 'origin/main'
This commit is contained in:
26
pom.xml
26
pom.xml
@ -92,7 +92,6 @@
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
@ -103,7 +102,6 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 测试依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -137,8 +135,6 @@
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>1.5.5.Final</version> <!-- 确保版本 ≥1.2.0 -->
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
@ -206,19 +202,17 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@ -12,6 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement
|
||||
@EnableDiscoveryClient
|
||||
@EnableConfigurationProperties(IpConfig.class)
|
||||
//@Slf4j
|
||||
public class IntelligentApplicationOrchestrationServiceApplication {
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class);
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "available")
|
||||
public class IpConfig {
|
||||
private List<String> ips;
|
||||
|
||||
public List<String> getIps() {
|
||||
return ips;
|
||||
}
|
||||
|
||||
public void setIps(String ips) {
|
||||
this.ips = Arrays.asList(ips.split(","));
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import io.lettuce.core.ClientOptions;
|
||||
import io.lettuce.core.SocketOptions;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -60,38 +63,41 @@ public class RedisConfig {
|
||||
.clientOptions(clientOptions) // 注入 ClientOptions
|
||||
.commandTimeout(Duration.ofSeconds(30)) // 全局命令超时
|
||||
.build();
|
||||
|
||||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
||||
config.setHostName(redisHost);
|
||||
config.setPort(redisPort);
|
||||
config.setUsername(redisUsername); // Redis 6.0+ 支持用户名
|
||||
config.setPassword(RedisPassword.of(redisPassword));
|
||||
|
||||
// LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
|
||||
// .commandTimeout(Duration.ofSeconds(30)) // 增加命令超时
|
||||
// .socketOptions(SocketOptions.builder()
|
||||
// .connectTimeout(Duration.ofSeconds(15)) // TCP连接超时
|
||||
// .build())
|
||||
// .build();
|
||||
|
||||
return new LettuceConnectionFactory(config, clientConfig);
|
||||
}
|
||||
|
||||
|
||||
// @Bean
|
||||
// public RedisConnectionFactory redisConnectionFactory() {
|
||||
// RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
||||
// config.setPassword("");
|
||||
// return new LettuceConnectionFactory(config);
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(){
|
||||
public RedisTemplate<String, Object> redisTemplate() {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
|
||||
log.info("开始创建redis模板对象...");
|
||||
template.setConnectionFactory(redisConnectionFactory());
|
||||
|
||||
// 创建自定义的ObjectMapper并注册JavaTimeModule
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
// 禁用将日期序列化为时间戳
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 注册Java 8日期时间模块
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
// 使用自定义的ObjectMapper创建JSON序列化器
|
||||
GenericJackson2JsonRedisSerializer jsonSerializer =
|
||||
new GenericJackson2JsonRedisSerializer(mapper);
|
||||
|
||||
// 设置键和值的序列化方式
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
template.setValueSerializer(jsonSerializer);
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(jsonSerializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,11 +9,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping
|
||||
@RequestMapping("/gpu")
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class GpuResourceController {
|
||||
@Autowired
|
||||
private GpuManageService gpuManageService;
|
||||
@PostMapping
|
||||
@PostMapping(value = "/add", produces = "application/json")
|
||||
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
|
||||
return gpuManageService.createGpuResource(dto);
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.ModelDeployer;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -17,6 +22,8 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/publish")
|
||||
@Slf4j
|
||||
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
|
||||
|
||||
public class PublishController {
|
||||
@Autowired
|
||||
private PublishService publishService;
|
||||
@ -24,21 +31,35 @@ public class PublishController {
|
||||
@Autowired
|
||||
private NacosServiceUtil nacosServiceUtil;
|
||||
|
||||
@Autowired
|
||||
private ModelMapper modelMapper;
|
||||
@Autowired
|
||||
private IpConfig ipConfig;
|
||||
|
||||
@Autowired
|
||||
private ModelDeployer modelDeployer;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary ="新增发布请求")
|
||||
@Transactional
|
||||
public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) {
|
||||
log.info("模型发布请求:{}", servicePublishDTO);
|
||||
publishService.save(servicePublishDTO);
|
||||
//todo 调用模型部署
|
||||
|
||||
//调用模型部署
|
||||
DeployRequest request = new DeployRequest();
|
||||
Long modelId = servicePublishDTO.getModelId();
|
||||
ModelVersion modelVersion = modelMapper.selectById(modelId);
|
||||
String modelConfig = modelVersion.getModelConfig();
|
||||
//假设modelConfig只存GPU数据
|
||||
request.setModelId(String.valueOf(modelId));
|
||||
request.setRequiredMemory(Integer.parseInt(modelConfig));
|
||||
modelDeployer.deploy(request);
|
||||
// 获取前端传来的IP字符串
|
||||
String ipListStr = servicePublishDTO.getIp();
|
||||
if (ipListStr == null || ipListStr.trim().isEmpty()) {
|
||||
log.warn("IP列表为空,不进行Nacos注册");
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用逗号分割IP字符串
|
||||
String[] ipArray = ipListStr.split(",");
|
||||
@ -59,15 +80,31 @@ public class PublishController {
|
||||
log.error("Nacos服务注册失败", e);
|
||||
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
|
||||
}
|
||||
|
||||
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已发布的服务列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Operation(summary ="获取已发布服务列表")
|
||||
public OptResult<List<ServicePublishVO>> listPublishedServices() {
|
||||
log.info("获取已发布服务列表接口被调用");
|
||||
List<ServicePublishVO> services = publishService.listPublishedServices();
|
||||
log.info("返回的数据: {}", services);
|
||||
return OptResult.success(services);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取IP列表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/config/ips")
|
||||
@Operation(summary = "获取可用IP地址列表")
|
||||
public OptResult<List<String>> getAvailableIps() {
|
||||
List<String> ips = ipConfig.getIps();
|
||||
log.info("返回列表;{}",ips);
|
||||
return OptResult.success(ips);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface GpuMapper {
|
||||
GpuResource toEntity(GpuCreateDTO dto);
|
@ -1,52 +1,21 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
public class GpuResource {
|
||||
@Getter
|
||||
@TableField("GPUId")
|
||||
private Long GPUId;
|
||||
|
||||
@Getter
|
||||
@TableField("GPUModel")
|
||||
private String GPUModel;
|
||||
|
||||
public Integer getGPUMemorySize() {
|
||||
return GPUMemorySize;
|
||||
}
|
||||
|
||||
public Long getGPUId() {
|
||||
return GPUId;
|
||||
}
|
||||
|
||||
public String getGPUModel() {
|
||||
return GPUModel;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return Ip;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return CreateTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return UpdateTime;
|
||||
}
|
||||
|
||||
public Integer getGPUMaxMemory() {
|
||||
return GPUMaxMemory;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@TableField("GPUMemorySize")
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@ -56,15 +25,12 @@ public class GpuResource {
|
||||
@TableField("Ip")
|
||||
private String Ip;
|
||||
|
||||
@Getter
|
||||
@TableField("CreatedTime")
|
||||
private LocalDateTime CreateTime;
|
||||
@TableField("created_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Getter
|
||||
@TableField("update_time")
|
||||
private LocalDateTime UpdateTime;
|
||||
|
||||
@Getter
|
||||
@TableField("GPUMaxMemory")
|
||||
private Integer GPUMaxMemory;
|
||||
|
||||
@ -83,16 +49,40 @@ public class GpuResource {
|
||||
|
||||
|
||||
|
||||
public GpuResource(Long Id, String Model, Integer MemorySize, String ip, LocalDateTime create_time) {
|
||||
public GpuResource(Long Id, String GPUModel, Integer GPUMemorySize, String ip, LocalDateTime create_time) {
|
||||
this.GPUId = Id;
|
||||
this.GPUModel = Model;
|
||||
this.GPUMemorySize = MemorySize;
|
||||
this.GPUModel = GPUModel;
|
||||
this.GPUMemorySize = GPUMemorySize;
|
||||
this.Ip = ip;
|
||||
this.CreateTime = create_time;
|
||||
this.createTime = create_time;
|
||||
}
|
||||
|
||||
public GpuResource() {}
|
||||
|
||||
public Integer getGPUMemorySize() {
|
||||
return GPUMemorySize;
|
||||
}
|
||||
|
||||
public Long getGPUId() {
|
||||
return GPUId;
|
||||
}
|
||||
|
||||
public String getGPUModel() {
|
||||
return GPUModel;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return Ip;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public Integer getGPUMaxMemory() {
|
||||
return GPUMaxMemory;
|
||||
}
|
||||
|
||||
public void setGPUId(Long GPUId) {
|
||||
this.GPUId = GPUId;
|
||||
}
|
||||
@ -114,11 +104,7 @@ public class GpuResource {
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
CreateTime = createTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
UpdateTime = updateTime;
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ import java.util.Map;
|
||||
public interface GpuResourceDao {
|
||||
//---------------------- 基础CRUD ------------------------
|
||||
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
|
||||
"VALUES (#{model}, #{memory}, #{ip})")
|
||||
"VALUES (#{GPUModel}, #{GPUMemorySize}, #{Ip})")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
||||
Integer insert(GpuResource entity);
|
||||
|
||||
@ -27,7 +27,7 @@ public interface GpuResourceDao {
|
||||
Integer isDeleted(@Param("gpuId") Long gpuId);
|
||||
|
||||
@Update("UPDATE Ipz.public.gpu_resource " +
|
||||
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " +
|
||||
"SET GPUModel = #{GPUModel}, GPUMemorySize = #{GPUMemorySize}, Ip = #{Ip} " +
|
||||
"WHERE GPUId = #{GPUId}")
|
||||
Integer updateById(GpuResource entity);
|
||||
|
||||
|
@ -6,6 +6,8 @@ import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PublishMapper {
|
||||
|
||||
@ -15,5 +17,6 @@ public interface PublishMapper {
|
||||
|
||||
Long getByApiUrl(String apiUrl);
|
||||
|
||||
|
||||
@Select("SELECT model_id,api_url,ip FROM service_publish")
|
||||
List<ServicePublishVO> listPublishedServices();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
@ -14,14 +15,17 @@ public class GpuCreateDTO {
|
||||
@NotBlank(message = "GPU型号不能为空")
|
||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||
@JsonProperty("GPUModel") // 显示指定JSON映射名称
|
||||
private String GPUModel;
|
||||
|
||||
@NotNull(message = "显存容量不能为空")
|
||||
@JsonProperty("GPUMemorySize")
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@NotBlank(message = "IP地址不能为空")
|
||||
@Pattern(regexp = "^\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}$",
|
||||
@Pattern(regexp = "^(\\d{1,3}\\.){3}\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
@JsonProperty("Ip") // 显示指定JSON映射名称
|
||||
private String Ip;
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,30 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class GpuResponseDTO {
|
||||
private Long id;
|
||||
@JsonView
|
||||
private Long GPUId;
|
||||
private String GPUModel;
|
||||
private Integer GPUMemorySize;
|
||||
private String Ip;
|
||||
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
// Builder类
|
||||
public static class Builder {
|
||||
private Long id;
|
||||
private String model;
|
||||
private Integer memory;
|
||||
private String ip;
|
||||
private LocalDateTime createdTime;
|
||||
private LocalDateTime createTime = LocalDateTime.now(); // 统一命名为createTime
|
||||
|
||||
public Builder id(Long id) {
|
||||
this.id = id;
|
||||
@ -39,19 +46,29 @@ public class GpuResponseDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder createdTime(LocalDateTime createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
public Builder createTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GpuResponseDTO build() {
|
||||
// 必填字段校验(如网页2的推荐)
|
||||
// 必填字段校验
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("GPU ID必须填写");
|
||||
}
|
||||
return new GpuResponseDTO();
|
||||
|
||||
GpuResponseDTO dto = new GpuResponseDTO();
|
||||
dto.setGPUId(id);
|
||||
dto.setGPUModel(model);
|
||||
dto.setGPUMemorySize(memory);
|
||||
dto.setIp(ip);
|
||||
dto.setCreateTime(createTime); // 正确赋值createTime
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
public String getCreateTimeStr(){
|
||||
return "GPU创建时间:" + createTime.toString();
|
||||
|
||||
public String getCreateTimeStr() {
|
||||
return "GPU创建时间:" + (createTime != null ? createTime.toString() : "未设置");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.*;
|
||||
@ -7,14 +8,36 @@ import lombok.*;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
//@Setter
|
||||
//@Getter
|
||||
@Setter
|
||||
@Getter
|
||||
public class GpuUpdateDTO {
|
||||
public @NotNull(message = "GPU ID cannot be null") Long getGPUId() {
|
||||
return GPUId;
|
||||
|
||||
private Long GPUId;
|
||||
|
||||
public @Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") String getGPUModel() {
|
||||
return GPUModel;
|
||||
}
|
||||
|
||||
public void setGPUId(@NotNull(message = "GPU ID cannot be null") Long GPUId) {
|
||||
public @Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效") String getIp() {
|
||||
return Ip;
|
||||
}
|
||||
|
||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||
@JsonProperty("GPUModel") // 显示指定JSON映射名称
|
||||
private String GPUModel;
|
||||
|
||||
@JsonProperty("GPUMemorySize") // 显示指定JSON映射名称
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
@JsonProperty("Ip") // 显示指定JSON映射名称
|
||||
private String Ip;
|
||||
|
||||
public void setGPUId(Long GPUId) {
|
||||
this.GPUId = GPUId;
|
||||
}
|
||||
|
||||
@ -27,18 +50,15 @@ public class GpuUpdateDTO {
|
||||
message = "IP地址格式无效") String ip) {
|
||||
Ip = ip;
|
||||
}
|
||||
public Long getGPUId() {
|
||||
return GPUId;
|
||||
}
|
||||
|
||||
@NotNull(message = "GPU ID cannot be null")
|
||||
private Long GPUId;
|
||||
public Integer getGPUMemorySize() {
|
||||
return GPUMemorySize;
|
||||
}
|
||||
|
||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||
private String GPUModel;
|
||||
|
||||
@Setter
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
private String Ip;
|
||||
public void setGPUMemorySize(Integer GPUMemorySize) {
|
||||
this.GPUMemorySize = GPUMemorySize;
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,28 @@ public class ResponseVO<T> implements Serializable {
|
||||
public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) {
|
||||
return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null);
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
public class ServicePublishVO implements Serializable {
|
||||
private Long modelId;
|
||||
private String GPUModel;
|
||||
/*private String GPUModel;*/
|
||||
private String ip;
|
||||
private String GPUMemorySize;
|
||||
/* private String GPUMemorySize;*/
|
||||
private String apiUrl;
|
||||
|
||||
|
||||
|
@ -3,8 +3,10 @@ package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.CacheInitException;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
@ -18,7 +20,6 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Transactional // 添加类级别事务管理
|
||||
@Component
|
||||
public class CacheManager {
|
||||
@Autowired
|
||||
@ -27,6 +28,9 @@ public class CacheManager {
|
||||
@Autowired
|
||||
private GpuResourceDao gpuResourceDao;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper; // 注入ObjectMapper用于类型转换
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@Value("${cache.redis-key-prefix:gpu:}")
|
||||
@ -38,9 +42,9 @@ public class CacheManager {
|
||||
@Value("${cache.init-batch-size:500}")
|
||||
private int initBatchSize;
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(CacheManager.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(CacheManager.class);
|
||||
|
||||
// 全量加载(带分页和分布式锁)
|
||||
@Transactional(propagation = Propagation.REQUIRED) // 方法级别覆盖
|
||||
@PostConstruct
|
||||
public void loadFullCache() {
|
||||
if (tryLock()) {
|
||||
@ -82,16 +86,12 @@ public class CacheManager {
|
||||
// 带随机TTL的缓存设置
|
||||
private void setCacheWithTTL(GpuResource entity) {
|
||||
String key = buildKey(entity.getGPUId().toString());
|
||||
GpuResource cached = (GpuResource) redisTemplate.opsForValue().get(key);
|
||||
|
||||
// 保留原有内存字段值
|
||||
if (cached != null && cached.getGPUMemorySize() != null) {
|
||||
entity.setGPUMemorySize(cached.getGPUMemorySize());
|
||||
}
|
||||
// 直接存储实体对象,确保类型一致性
|
||||
redisTemplate.opsForValue().set(
|
||||
key,
|
||||
entity,
|
||||
ttlBase + (int)(Math.random() * 600), // 随机TTL防止雪崩
|
||||
ttlBase + (int)(Math.random() * 600),
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
@ -114,6 +114,7 @@ public class CacheManager {
|
||||
private void unlock() {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
// 分页加载入口
|
||||
public void loadFullCache(int batchSize) {
|
||||
int page = 0;
|
||||
@ -121,12 +122,11 @@ public class CacheManager {
|
||||
List<GpuResource> batch = gpuResourceDao.findByPage(page * batchSize, batchSize);
|
||||
if (batch.isEmpty()) break;
|
||||
|
||||
batch.forEach(this::refreshWithRetry); // 带重试的刷新逻辑
|
||||
batch.forEach(this::refreshWithRetry);
|
||||
page++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 带重试机制的缓存刷新
|
||||
public void refreshWithRetry(GpuResource entity) {
|
||||
try {
|
||||
@ -135,7 +135,7 @@ public class CacheManager {
|
||||
// 3次重试逻辑
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
log.info("重试第 {} 次", i + 1); // 添加日志
|
||||
log.info("重试第 {} 次", i + 1);
|
||||
Thread.sleep(1000);
|
||||
setCacheWithTTL(entity);
|
||||
return;
|
||||
@ -148,7 +148,6 @@ public class CacheManager {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,8 +161,35 @@ public class CacheManager {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
// 修改获取缓存的方法,增加类型安全处理
|
||||
@SuppressWarnings("unchecked")
|
||||
public GpuResource getFromCache(String gpuId) {
|
||||
return (GpuResource) redisTemplate.opsForValue().get("gpu:" + gpuId);
|
||||
}
|
||||
String key = buildKey(gpuId);
|
||||
Object value = redisTemplate.opsForValue().get(key);
|
||||
|
||||
}
|
||||
// 处理可能的类型不匹配问题
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先尝试直接转换
|
||||
if (value instanceof GpuResource) {
|
||||
return (GpuResource) value;
|
||||
}
|
||||
// 如果是LinkedHashMap,使用ObjectMapper转换
|
||||
else if (value instanceof java.util.LinkedHashMap) {
|
||||
return objectMapper.convertValue(value, GpuResource.class);
|
||||
}
|
||||
// 其他情况尝试序列化后反序列化(适用于JSON存储场景)
|
||||
else {
|
||||
// 先序列化为JSON字符串,再反序列化为对象
|
||||
String json = objectMapper.writeValueAsString(value);
|
||||
return objectMapper.readValue(json, GpuResource.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取缓存时类型转换失败,key: {}, valueType: {}", key, value.getClass().getName(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -97,6 +97,7 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
|
||||
@Override
|
||||
public String run(Long id, String param) {
|
||||
//todo从分布式存储中拿到文件(以下是示例)
|
||||
String file = algorithmInfoMapper.getFileById(id);
|
||||
StringBuilder result = new StringBuilder(); // 用于存储结果
|
||||
|
||||
|
@ -2,12 +2,15 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hky
|
||||
*/
|
||||
@ -35,6 +38,10 @@ public class PublishServiceImpl implements PublishService {
|
||||
publishMapper.insert(servicePublishDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServicePublishVO> listPublishedServices() {
|
||||
return publishMapper.listPublishedServices();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PublishService {
|
||||
|
||||
void save(ServicePublishDTO servicePublishDTO);
|
||||
|
||||
|
||||
|
||||
|
||||
List<ServicePublishVO> listPublishedServices();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||
|
@ -57,4 +57,6 @@ spring.servlet.multipart.max-request-size=100MB
|
||||
# 激活开发环境!告诉 Spring:加载 application-dev.properties 里的配置
|
||||
spring.profiles.active=dev
|
||||
|
||||
#配置IP列表(后续根据需求修改ip数据,以下仅为测试用例)
|
||||
available.ips=192.168.1.100,192.168.1.101,192.168.1.102
|
||||
|
||||
|
@ -2,10 +2,19 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao">
|
||||
|
||||
<resultMap id="gpuResourceMap" type="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
||||
<id property="GPUId" column="GPUId" /> <!-- 强制映射 -->
|
||||
<result property="createTime" column="created_time"/>
|
||||
<result property="UpdateTime" column="update_time"/>
|
||||
<result property="GPUModel" column="GPUModel"/>
|
||||
<result property="GPUMemorySize" column="GPUMemorySize"/>
|
||||
<result property="Ip" column="Ip"/>
|
||||
<result property="isDeleted" column="is_deleted"/>
|
||||
<result property="GPUMaxMemory" column="GPUMaxMemory"/>
|
||||
</resultMap>
|
||||
<!-- 动态条件查询 -->
|
||||
<select id="selectByFields"
|
||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
||||
resultMap="gpuResourceMap">
|
||||
SELECT *
|
||||
FROM Ipz.public.gpu_resource
|
||||
<where>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper">
|
||||
<insert id="insert">
|
||||
INSERT INTO service_publish
|
||||
(id,model_id,api_url,create_time)
|
||||
values (#{id}, #{modelId}, #{apiUrl}, #{createTime})
|
||||
(id,model_id,api_url,create_time,ip)
|
||||
values (#{id}, #{modelId}, #{apiUrl}, #{createTime},#{ip})
|
||||
</insert>
|
||||
|
||||
<select id="getByApiUrl" resultType="java.lang.Long">
|
||||
|
Reference in New Issue
Block a user