GPU和服务发布和算法部分代码优化
This commit is contained in:
26
pom.xml
26
pom.xml
@ -92,7 +92,6 @@
|
|||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) -->
|
<!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
@ -103,7 +102,6 @@
|
|||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 测试依赖 -->
|
<!-- 测试依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -137,8 +135,6 @@
|
|||||||
<artifactId>mapstruct</artifactId>
|
<artifactId>mapstruct</artifactId>
|
||||||
<version>1.5.5.Final</version> <!-- 确保版本 ≥1.2.0 -->
|
<version>1.5.5.Final</version> <!-- 确保版本 ≥1.2.0 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
@ -206,19 +202,17 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.38</version>
|
<version>1.18.38</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
<path>
|
||||||
</configuration>
|
<groupId>org.mapstruct</groupId>
|
||||||
</plugin>
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
<plugin>
|
<version>1.5.5.Final</version>
|
||||||
<groupId>org.springframework.boot</groupId>
|
</path>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<path>
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||||
</exclude>
|
<version>0.2.0</version>
|
||||||
</excludes>
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice;
|
package com.bipt.intelligentapplicationorchestrationservice;
|
||||||
|
|
||||||
|
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
|
@EnableConfigurationProperties(IpConfig.class)
|
||||||
//@Slf4j
|
//@Slf4j
|
||||||
public class IntelligentApplicationOrchestrationServiceApplication {
|
public class IntelligentApplicationOrchestrationServiceApplication {
|
||||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class);
|
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;
|
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||||
|
|
||||||
import ch.qos.logback.classic.Logger;
|
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.ClientOptions;
|
||||||
import io.lettuce.core.SocketOptions;
|
import io.lettuce.core.SocketOptions;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -60,38 +63,41 @@ public class RedisConfig {
|
|||||||
.clientOptions(clientOptions) // 注入 ClientOptions
|
.clientOptions(clientOptions) // 注入 ClientOptions
|
||||||
.commandTimeout(Duration.ofSeconds(30)) // 全局命令超时
|
.commandTimeout(Duration.ofSeconds(30)) // 全局命令超时
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
||||||
config.setHostName(redisHost);
|
config.setHostName(redisHost);
|
||||||
config.setPort(redisPort);
|
config.setPort(redisPort);
|
||||||
config.setUsername(redisUsername); // Redis 6.0+ 支持用户名
|
config.setUsername(redisUsername); // Redis 6.0+ 支持用户名
|
||||||
config.setPassword(RedisPassword.of(redisPassword));
|
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);
|
return new LettuceConnectionFactory(config, clientConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Bean
|
|
||||||
// public RedisConnectionFactory redisConnectionFactory() {
|
|
||||||
// RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
|
||||||
// config.setPassword("");
|
|
||||||
// return new LettuceConnectionFactory(config);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate() {
|
public RedisTemplate<String, Object> redisTemplate() {
|
||||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||||
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
|
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
|
||||||
log.info("开始创建redis模板对象...");
|
log.info("开始创建redis模板对象...");
|
||||||
template.setConnectionFactory(redisConnectionFactory());
|
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.setKeySerializer(new StringRedisSerializer());
|
||||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
template.setValueSerializer(jsonSerializer);
|
||||||
|
template.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
template.setHashValueSerializer(jsonSerializer);
|
||||||
|
|
||||||
|
template.afterPropertiesSet();
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,11 +9,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping
|
@RequestMapping("/gpu")
|
||||||
|
@CrossOrigin(origins = "http://localhost:3000")
|
||||||
public class GpuResourceController {
|
public class GpuResourceController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private GpuManageService gpuManageService;
|
private GpuManageService gpuManageService;
|
||||||
@PostMapping
|
@PostMapping(value = "/add", produces = "application/json")
|
||||||
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
|
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
|
||||||
return gpuManageService.createGpuResource(dto);
|
return gpuManageService.createGpuResource(dto);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||||
|
|
||||||
|
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
|
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
|
||||||
@ -17,6 +18,8 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/publish")
|
@RequestMapping("/publish")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
|
||||||
|
|
||||||
public class PublishController {
|
public class PublishController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PublishService publishService;
|
private PublishService publishService;
|
||||||
@ -24,6 +27,9 @@ public class PublishController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NacosServiceUtil nacosServiceUtil;
|
private NacosServiceUtil nacosServiceUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IpConfig ipConfig;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary ="新增发布请求")
|
@Operation(summary ="新增发布请求")
|
||||||
@Transactional
|
@Transactional
|
||||||
@ -38,7 +44,6 @@ public class PublishController {
|
|||||||
log.warn("IP列表为空,不进行Nacos注册");
|
log.warn("IP列表为空,不进行Nacos注册");
|
||||||
return OptResult.success();
|
return OptResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 使用逗号分割IP字符串
|
// 使用逗号分割IP字符串
|
||||||
String[] ipArray = ipListStr.split(",");
|
String[] ipArray = ipListStr.split(",");
|
||||||
@ -59,15 +64,31 @@ public class PublishController {
|
|||||||
log.error("Nacos服务注册失败", e);
|
log.error("Nacos服务注册失败", e);
|
||||||
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
|
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return OptResult.success();
|
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.GpuCreateDTO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.MappingConstants;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface GpuMapper {
|
public interface GpuMapper {
|
||||||
GpuResource toEntity(GpuCreateDTO dto);
|
GpuResource toEntity(GpuCreateDTO dto);
|
@ -1,52 +1,21 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import lombok.Data;
|
import lombok.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Setter
|
|
||||||
@Data
|
@Data
|
||||||
public class GpuResource {
|
@AllArgsConstructor
|
||||||
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
|
public class GpuResource {
|
||||||
@TableField("GPUId")
|
@TableField("GPUId")
|
||||||
private Long GPUId;
|
private Long GPUId;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@TableField("GPUModel")
|
@TableField("GPUModel")
|
||||||
private String 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")
|
@TableField("GPUMemorySize")
|
||||||
private Integer GPUMemorySize;
|
private Integer GPUMemorySize;
|
||||||
|
|
||||||
@ -56,15 +25,12 @@ public class GpuResource {
|
|||||||
@TableField("Ip")
|
@TableField("Ip")
|
||||||
private String Ip;
|
private String Ip;
|
||||||
|
|
||||||
@Getter
|
@TableField("created_time")
|
||||||
@TableField("CreatedTime")
|
private LocalDateTime createTime;
|
||||||
private LocalDateTime CreateTime;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@TableField("update_time")
|
@TableField("update_time")
|
||||||
private LocalDateTime UpdateTime;
|
private LocalDateTime UpdateTime;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@TableField("GPUMaxMemory")
|
@TableField("GPUMaxMemory")
|
||||||
private Integer 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.GPUId = Id;
|
||||||
this.GPUModel = Model;
|
this.GPUModel = GPUModel;
|
||||||
this.GPUMemorySize = MemorySize;
|
this.GPUMemorySize = GPUMemorySize;
|
||||||
this.Ip = ip;
|
this.Ip = ip;
|
||||||
this.CreateTime = create_time;
|
this.createTime = create_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GpuResource() {}
|
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) {
|
public void setGPUId(Long GPUId) {
|
||||||
this.GPUId = GPUId;
|
this.GPUId = GPUId;
|
||||||
}
|
}
|
||||||
@ -114,11 +104,7 @@ public class GpuResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateTime(LocalDateTime createTime) {
|
public void setCreateTime(LocalDateTime createTime) {
|
||||||
CreateTime = createTime;
|
this.createTime = createTime;
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdateTime(LocalDateTime updateTime) {
|
|
||||||
UpdateTime = updateTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
public interface GpuResourceDao {
|
public interface GpuResourceDao {
|
||||||
//---------------------- 基础CRUD ------------------------
|
//---------------------- 基础CRUD ------------------------
|
||||||
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
|
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
|
||||||
"VALUES (#{model}, #{memory}, #{ip})")
|
"VALUES (#{GPUModel}, #{GPUMemorySize}, #{Ip})")
|
||||||
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
||||||
Integer insert(GpuResource entity);
|
Integer insert(GpuResource entity);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public interface GpuResourceDao {
|
|||||||
Integer isDeleted(@Param("gpuId") Long gpuId);
|
Integer isDeleted(@Param("gpuId") Long gpuId);
|
||||||
|
|
||||||
@Update("UPDATE Ipz.public.gpu_resource " +
|
@Update("UPDATE Ipz.public.gpu_resource " +
|
||||||
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " +
|
"SET GPUModel = #{GPUModel}, GPUMemorySize = #{GPUMemorySize}, Ip = #{Ip} " +
|
||||||
"WHERE GPUId = #{GPUId}")
|
"WHERE GPUId = #{GPUId}")
|
||||||
Integer updateById(GpuResource entity);
|
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.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PublishMapper {
|
public interface PublishMapper {
|
||||||
|
|
||||||
@ -15,5 +17,6 @@ public interface PublishMapper {
|
|||||||
|
|
||||||
Long getByApiUrl(String apiUrl);
|
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;
|
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Pattern;
|
import jakarta.validation.constraints.Pattern;
|
||||||
@ -14,14 +15,17 @@ public class GpuCreateDTO {
|
|||||||
@NotBlank(message = "GPU型号不能为空")
|
@NotBlank(message = "GPU型号不能为空")
|
||||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||||
|
@JsonProperty("GPUModel") // 显示指定JSON映射名称
|
||||||
private String GPUModel;
|
private String GPUModel;
|
||||||
|
|
||||||
@NotNull(message = "显存容量不能为空")
|
@NotNull(message = "显存容量不能为空")
|
||||||
|
@JsonProperty("GPUMemorySize")
|
||||||
private Integer GPUMemorySize;
|
private Integer GPUMemorySize;
|
||||||
|
|
||||||
@NotBlank(message = "IP地址不能为空")
|
@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地址格式无效")
|
message = "IP地址格式无效")
|
||||||
|
@JsonProperty("Ip") // 显示指定JSON映射名称
|
||||||
private String Ip;
|
private String Ip;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,30 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
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 lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class GpuResponseDTO {
|
public class GpuResponseDTO {
|
||||||
private Long id;
|
@JsonView
|
||||||
|
private Long GPUId;
|
||||||
private String GPUModel;
|
private String GPUModel;
|
||||||
private Integer GPUMemorySize;
|
private Integer GPUMemorySize;
|
||||||
private String Ip;
|
private String Ip;
|
||||||
|
|
||||||
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
// Builder类
|
// Builder类
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String model;
|
private String model;
|
||||||
private Integer memory;
|
private Integer memory;
|
||||||
private String ip;
|
private String ip;
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createTime = LocalDateTime.now(); // 统一命名为createTime
|
||||||
|
|
||||||
public Builder id(Long id) {
|
public Builder id(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -39,19 +46,29 @@ public class GpuResponseDTO {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder createdTime(LocalDateTime createdTime) {
|
public Builder createTime(LocalDateTime createTime) {
|
||||||
this.createdTime = createdTime;
|
this.createTime = createTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GpuResponseDTO build() {
|
public GpuResponseDTO build() {
|
||||||
// 必填字段校验(如网页2的推荐)
|
// 必填字段校验
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new IllegalArgumentException("GPU ID必须填写");
|
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() {
|
public String getCreateTimeStr() {
|
||||||
return "GPU创建时间:" + createTime.toString();
|
return "GPU创建时间:" + (createTime != null ? createTime.toString() : "未设置");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Pattern;
|
import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
@ -7,14 +8,36 @@ import lombok.*;
|
|||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
//@Setter
|
@Setter
|
||||||
//@Getter
|
@Getter
|
||||||
public class GpuUpdateDTO {
|
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;
|
this.GPUId = GPUId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,18 +50,15 @@ public class GpuUpdateDTO {
|
|||||||
message = "IP地址格式无效") String ip) {
|
message = "IP地址格式无效") String ip) {
|
||||||
Ip = ip;
|
Ip = ip;
|
||||||
}
|
}
|
||||||
|
public Long getGPUId() {
|
||||||
@NotNull(message = "GPU ID cannot be null")
|
return GPUId;
|
||||||
private Long GPUId;
|
}
|
||||||
|
|
||||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
public Integer getGPUMemorySize() {
|
||||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
return GPUMemorySize;
|
||||||
private String GPUModel;
|
}
|
||||||
|
|
||||||
@Setter
|
public void setGPUMemorySize(Integer GPUMemorySize) {
|
||||||
private Integer GPUMemorySize;
|
this.GPUMemorySize = GPUMemorySize;
|
||||||
|
}
|
||||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
|
||||||
message = "IP地址格式无效")
|
|
||||||
private String Ip;
|
|
||||||
}
|
}
|
||||||
|
@ -35,4 +35,28 @@ public class ResponseVO<T> implements Serializable {
|
|||||||
public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) {
|
public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) {
|
||||||
return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null);
|
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
|
@AllArgsConstructor
|
||||||
public class ServicePublishVO implements Serializable {
|
public class ServicePublishVO implements Serializable {
|
||||||
private Long modelId;
|
private Long modelId;
|
||||||
private String GPUModel;
|
/*private String GPUModel;*/
|
||||||
private String ip;
|
private String ip;
|
||||||
private String GPUMemorySize;
|
/* private String GPUMemorySize;*/
|
||||||
private String apiUrl;
|
private String apiUrl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String run(Long id, String param) {
|
public String run(Long id, String param) {
|
||||||
|
//todo从分布式存储中拿到文件(以下是示例)
|
||||||
String file = algorithmInfoMapper.getFileById(id);
|
String file = algorithmInfoMapper.getFileById(id);
|
||||||
StringBuilder result = new StringBuilder(); // 用于存储结果
|
StringBuilder result = new StringBuilder(); // 用于存储结果
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
|||||||
|
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
|
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
||||||
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hky
|
* @author hky
|
||||||
*/
|
*/
|
||||||
@ -35,6 +38,10 @@ public class PublishServiceImpl implements PublishService {
|
|||||||
publishMapper.insert(servicePublishDTO);
|
publishMapper.insert(servicePublishDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ServicePublishVO> listPublishedServices() {
|
||||||
|
return publishMapper.listPublishedServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||||
|
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
|
||||||
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PublishService {
|
public interface PublishService {
|
||||||
|
|
||||||
void save(ServicePublishDTO servicePublishDTO);
|
void save(ServicePublishDTO servicePublishDTO);
|
||||||
|
|
||||||
|
|
||||||
|
List<ServicePublishVO> listPublishedServices();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
|
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
|
||||||
|
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
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.GpuCreateDTO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||||
|
@ -57,4 +57,6 @@ spring.servlet.multipart.max-request-size=100MB
|
|||||||
# 激活开发环境!告诉 Spring:加载 application-dev.properties 里的配置
|
# 激活开发环境!告诉 Spring:加载 application-dev.properties 里的配置
|
||||||
spring.profiles.active=dev
|
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"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao">
|
<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"
|
<select id="selectByFields"
|
||||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
resultMap="gpuResourceMap">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM Ipz.public.gpu_resource
|
FROM Ipz.public.gpu_resource
|
||||||
<where>
|
<where>
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper">
|
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper">
|
||||||
<insert id="insert">
|
<insert id="insert">
|
||||||
INSERT INTO service_publish
|
INSERT INTO service_publish
|
||||||
(id,model_id,api_url,create_time)
|
(id,model_id,api_url,create_time,ip)
|
||||||
values (#{id}, #{modelId}, #{apiUrl}, #{createTime})
|
values (#{id}, #{modelId}, #{apiUrl}, #{createTime},#{ip})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="getByApiUrl" resultType="java.lang.Long">
|
<select id="getByApiUrl" resultType="java.lang.Long">
|
||||||
|
Reference in New Issue
Block a user