Compare commits
40 Commits
12a9355bb8
...
dc-feature
Author | SHA1 | Date | |
---|---|---|---|
ddf44f9d2c | |||
12f602dc45 | |||
86a64f205f | |||
0aff6e71ff | |||
94bfc4cc70 | |||
1cf3944744 | |||
64d21a574d | |||
05eb83d68d | |||
cc0b69362c | |||
43641b7d02 | |||
22547031cf | |||
caeb280396 | |||
158fdca6e0 | |||
0fe404b717 | |||
ee8e4709a6 | |||
92b470e001 | |||
49851384c8 | |||
0619c7d184 | |||
5dd1cfcf9e | |||
77a4b86cb4 | |||
df4ae86ea3 | |||
b218335558 | |||
987e5c30fe | |||
cae2a7786e | |||
9eef82b642 | |||
789108aaa3 | |||
3fb10b1e2f | |||
4a1e6013b3 | |||
c24d640de4 | |||
2aaf3d96f0 | |||
77fb43e95d | |||
bcf44161b5 | |||
5692cca3e7 | |||
60a71a121c | |||
9f348280ea | |||
999fd82ccc | |||
28b5ca1dfc | |||
c01e985256 | |||
73388da706 | |||
6943f38d1b |
13
doc/WorkReport/2025-05-15-杜冲.md
Normal file
13
doc/WorkReport/2025-05-15-杜冲.md
Normal file
@ -0,0 +1,13 @@
|
||||
# 工作日报 - 2025年5月
|
||||
## 2025年5月15日
|
||||
### ✅ 今日完成
|
||||
- 完成删除和查询功能
|
||||
|
||||
_### 🚧 进行中
|
||||
- 设计触发服务API请求调度缓存更新类
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
- KingBase8数据库方言配置出错
|
||||
|
||||
### 📅 明日计划
|
||||
- 完成触发API请求调度缓存更新类
|
@ -77,7 +77,7 @@ redis的服务器配置
|
||||
### 📅 明日计划
|
||||
完成服务发布的开发
|
||||
|
||||
## 2025年5月22日
|
||||
## 2025年5月23日
|
||||
### ✅ 今日完成
|
||||
服务发布,拦截器部分功能
|
||||
|
||||
@ -90,4 +90,17 @@ redis的服务器配置
|
||||
### 📅 明日计划
|
||||
完成拦截器功能
|
||||
|
||||
## 2025年5月25日
|
||||
### ✅ 今日完成
|
||||
服务发布可注册到nacos上
|
||||
|
||||
### 🚧 进行中
|
||||
拦截器开发
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
模型api请求不知道是什么
|
||||
|
||||
### 📅 明日计划
|
||||
开发拦截器功能
|
||||
|
||||
|
||||
|
139
pom.xml
139
pom.xml
@ -2,34 +2,51 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<version>3.1.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.bipt</groupId>
|
||||
<artifactId>intelligent-application-orchestration-service</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>intelligent-application-orchestration-service</name>
|
||||
<description>intelligent-application-orchestration-service</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<java.version>17</java.version>
|
||||
<!-- 添加 Spring Cloud 版本控制 -->
|
||||
<spring-cloud.version>2022.0.4</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖管理:统一控制 Spring Cloud 和 Alibaba 版本 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- Spring Cloud 依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- Spring Cloud Alibaba 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2022.0.0.0-RC2</version> <!-- 适配 Spring Boot 3.1.x 的正确版本 -->
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot 基础依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
@ -38,42 +55,60 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库驱动 -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.kingbase8</groupId>
|
||||
<artifactId>kingbase8</artifactId>
|
||||
<version>9.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!-- 工具类依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!--分页查询-->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
<!--swagger相关依赖,生成接口文档-->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.3.0</version> <!-- 最新稳定版 -->
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--KingbaseES V8/V9 数据库 JDBC 驱动-->
|
||||
<!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) -->
|
||||
<dependency>
|
||||
<groupId>com.kingbase8</groupId>
|
||||
<artifactId>kingbase8</artifactId>
|
||||
<version>9.0.0</version>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- Spring Boot 3.x 必须的 Bootstrap 依赖(无需版本号) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.15.3</version>
|
||||
</dependency>
|
||||
<!-- 测试依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@ -90,6 +125,50 @@
|
||||
<version>3.0.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<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>
|
||||
<exclusions>
|
||||
<!-- 排除 RabbitMQ 自动配置 -->
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -98,12 +177,25 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- 显式指定 Java 21 编译 -->
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.5.5.Final</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@ -121,5 +213,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -2,16 +2,19 @@ package com.bipt.intelligentapplicationorchestrationservice;
|
||||
|
||||
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.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@MapperScan("com.bipt.intelligentapplicationorchestrationservice.mapper")//指定扫描Mapper接口的包
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement
|
||||
@Slf4j
|
||||
@EnableDiscoveryClient
|
||||
//@Slf4j
|
||||
public class IntelligentApplicationOrchestrationServiceApplication {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class);
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(IntelligentApplicationOrchestrationServiceApplication.class, args);
|
||||
log.info("server started");
|
||||
|
37
src/main/java/com/bipt/intelligentapplicationorchestrationservice/cache/CacheInitTask.java
vendored
Normal file
37
src/main/java/com/bipt/intelligentapplicationorchestrationservice/cache/CacheInitTask.java
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.cache;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CacheInitTask {
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
@Value("${cache.init-batch-size:500}")
|
||||
private int batchSize;
|
||||
|
||||
@Autowired
|
||||
public CacheInitTask(CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用启动后执行全量缓存加载
|
||||
* 使用@EventListener替代@PostConstruct确保数据库连接就绪
|
||||
*/
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void initCacheOnStartup() {
|
||||
try {
|
||||
cacheManager.loadFullCache(batchSize);
|
||||
System.out.println("✅ 缓存全量初始化完成 | Total loaded: " + cacheManager.getCacheCount());
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 缓存初始化失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
63
src/main/java/com/bipt/intelligentapplicationorchestrationservice/cache/CacheSyncTask.java
vendored
Normal file
63
src/main/java/com/bipt/intelligentapplicationorchestrationservice/cache/CacheSyncTask.java
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.cache;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
//@Slf4j
|
||||
@Component
|
||||
public class CacheSyncTask {
|
||||
private final GpuResourceDao gpuResourceDao;
|
||||
private final CacheManager cacheManager;
|
||||
private LocalDateTime lastSyncTime = LocalDateTime.MIN;
|
||||
private static final Logger log = LoggerFactory.getLogger(CacheSyncTask.class);
|
||||
|
||||
@Autowired
|
||||
public CacheSyncTask(GpuResourceDao gpuResourceDao, CacheManager cacheManager) {
|
||||
this.gpuResourceDao = gpuResourceDao;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时同步缓存(默认每10分钟)
|
||||
*/
|
||||
@Scheduled(fixedDelayString = "${cache.sync-interval:600000}")
|
||||
public void syncCache() {
|
||||
try {
|
||||
LocalDateTime currentSyncTime = LocalDateTime.now();
|
||||
log.info("🔄 开始缓存同步 | 时间范围: {} - {}", lastSyncTime, currentSyncTime);
|
||||
|
||||
// 1. 查询增量数据
|
||||
List<GpuResource> modifiedGpus = gpuResourceDao.findModifiedSince(lastSyncTime);
|
||||
if (modifiedGpus.isEmpty()) {
|
||||
log.info("✅ 无数据变更,跳过本次同步");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 处理数据变更
|
||||
modifiedGpus.forEach(gpu -> {
|
||||
if (gpu.getIsDeleted()) {
|
||||
cacheManager.evictCache(gpu.getGPUId());
|
||||
log.debug("🗑️ 删除缓存 | GPU ID: {}", gpu.getGPUId());
|
||||
} else {
|
||||
cacheManager.refreshCache(gpu.getGPUId());
|
||||
log.debug("🔄 更新缓存 | GPU ID: {}", gpu.getGPUId());
|
||||
}
|
||||
});
|
||||
|
||||
// 3. 更新同步时间戳
|
||||
lastSyncTime = currentSyncTime;
|
||||
log.info("✅ 缓存同步完成 | 共处理 {} 条记录", modifiedGpus.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("❌ 缓存同步失败: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class CacheAopConfig {
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
public CacheAopConfig(CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
// 定义写操作切点
|
||||
@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional) && " +
|
||||
"execution(* com.bipt.intelligentapplicationorchestrationservice.service..*.*(..))")
|
||||
public void writeOperation() {}
|
||||
|
||||
// 事务提交后操作
|
||||
@AfterReturning(pointcut = "writeOperation()", returning = "result")
|
||||
public void afterWriteCommit(JoinPoint joinPoint, Object result) {
|
||||
TransactionSynchronizationManager.registerSynchronization(
|
||||
new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
processCacheUpdate(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void processCacheUpdate(Object result) {
|
||||
if (result instanceof GpuResource) {
|
||||
GpuResource gpu = (GpuResource) result;
|
||||
cacheManager.refreshCache(gpu.getGPUId());
|
||||
} else if (result instanceof Long) { // 处理删除操作返回ID的情况
|
||||
cacheManager.evictCache((Long) result);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisPassword;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Value("${spring.data.redis.host}")
|
||||
private String redisHost;
|
||||
|
||||
@Value("${spring.data.redis.port}")
|
||||
private int redisPort;
|
||||
|
||||
@Value("${spring.data.redis.username}")
|
||||
private String redisUsername;
|
||||
|
||||
@Value("${spring.data.redis.password}")
|
||||
private String redisPassword;
|
||||
|
||||
@Value("${spring.data.redis.ssl:false}")
|
||||
private boolean useSsl;
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory redisConnectionFactory() {
|
||||
// 1. 创建 SocketOptions
|
||||
SocketOptions socketOptions = SocketOptions.builder()
|
||||
.connectTimeout(Duration.ofSeconds(15)) // 连接超时
|
||||
.keepAlive(true) // 启用 TCP Keep-Alive
|
||||
.build();
|
||||
|
||||
// 2. 构建 ClientOptions
|
||||
ClientOptions clientOptions = ClientOptions.builder()
|
||||
.socketOptions(socketOptions)
|
||||
.autoReconnect(true) // 启用自动重连
|
||||
.build();
|
||||
|
||||
// 3. 集成到 Lettuce 配置
|
||||
LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
|
||||
.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(){
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
|
||||
log.info("开始创建redis模板对象...");
|
||||
template.setConnectionFactory(redisConnectionFactory());
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
return template;
|
||||
}
|
||||
}
|
@ -4,20 +4,18 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置类,注册web层相关组件
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class WebMvcConfiguration{
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 配置OpenAPI信息
|
||||
@ -36,12 +34,4 @@ public class WebMvcConfiguration{
|
||||
.servers(servers);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 设置静态资源映射(Springdoc不需要特殊配置,保留可能的其他资源映射)
|
||||
// */
|
||||
// @Override
|
||||
// protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
// // 保留其他静态资源映射(如果有)
|
||||
// // registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
|
||||
// }
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.constant;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConfigConstants {
|
||||
@Value("${model.deploy.port:8080}")
|
||||
public int MODEL_PORT;
|
||||
|
||||
@Value("${model.deploy.url-template:http://%s:%d/model/%s/%s}")
|
||||
public String URL_TEMPLATE;
|
||||
|
||||
@Value("${model.deploy.script-timeout:300}")
|
||||
public int SCRIPT_TIMEOUT_SECONDS;
|
||||
}
|
@ -3,4 +3,12 @@ package com.bipt.intelligentapplicationorchestrationservice.constant;
|
||||
public class MessageConstant {
|
||||
public static final String UNKNOWN_ERROR = "未知错误";
|
||||
public static final String ALREADY_EXISTS = "已存在";
|
||||
|
||||
//生命周期相关常量
|
||||
public static final String LifeCycle_No_Exist = "生命周期不存在";
|
||||
public static final String LifeCycle_Undefined = "生命周期未定义";
|
||||
public static final String ERROR_DEPLOYED_TO_DESIGNING = "已部署的模型不能直接调整成设计,需先下线再设计";
|
||||
public static final String ERROR_ABANDONED_CANNOT_UPDATE = "已废弃的模型只能查看信息,不能更新生命周期";
|
||||
public static final String ERROR_TRAINING_INVALID_TRANSITION = "训练中的模型只能调整成设计和评估";
|
||||
public static final String UPDATE_FAILURE = "更新模型生命周期失败";
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name ="算法创建相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/algorithm")
|
||||
@Slf4j
|
||||
public class AlgorithmInfoController {
|
||||
|
||||
@Autowired
|
||||
@ -57,4 +62,16 @@ public class AlgorithmInfoController {
|
||||
ResponseEntity.ok("Delete successful") :
|
||||
ResponseEntity.badRequest().body("Delete failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* 算法创建
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary ="算法创建")
|
||||
public OptResult save(@RequestBody AlgorithmInfo algorithmInfo){
|
||||
log.info("新增算法",algorithmInfo);
|
||||
algorithmInfoService.save(algorithmInfo);
|
||||
return OptResult.success("算法创建成功");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class GpuResourceController {
|
||||
@Autowired
|
||||
private GpuManageService gpuManageService;
|
||||
@PostMapping(value = "/add", produces = "application/json")
|
||||
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
|
||||
return gpuManageService.createGpuResource(dto);
|
||||
}
|
||||
@DeleteMapping("/{gpuId}")
|
||||
public ResponseVO removeGpu(@PathVariable("gpuId") Long gpuId){
|
||||
return gpuManageService.deleteGpuResource(gpuId);
|
||||
}
|
||||
@PutMapping(value = "/update/{gpuId}", produces = "application/json")
|
||||
public void updateGpuResource(
|
||||
@PathVariable("gpuId") Long gpuId,
|
||||
@Valid @RequestBody GpuUpdateDTO dto){
|
||||
if (gpuId == null) {
|
||||
throw new IllegalArgumentException("GPU ID cannot be null");
|
||||
}
|
||||
dto.setGPUId(gpuId);
|
||||
gpuManageService.updateGpuResource(dto);
|
||||
}
|
||||
@GetMapping("/search")
|
||||
public ResponseVO<List<GpuResponseDTO>> searchGpuResources(
|
||||
@RequestParam(required = false) String model,
|
||||
@RequestParam(required = false) Integer memorySize,
|
||||
@RequestParam(required = false) String ip){
|
||||
List<GpuResponseDTO> resources = gpuManageService.searchByCriteria(model, memorySize,ip);
|
||||
return ResponseVO.success(resources);
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/model")
|
||||
@Tag(name = "模型部分相关接口")
|
||||
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
|
||||
public class ModelController {
|
||||
@Autowired
|
||||
private ModelService modelService;
|
||||
@Operation(summary = "创建模型")
|
||||
@PostMapping("/createModel")
|
||||
public OptResult creatModel(@RequestBody ModelDTO dto){
|
||||
log.info("创建模型");
|
||||
modelService.createModel(dto);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "新增模型版本")
|
||||
@PostMapping("/createModelVersion")
|
||||
public OptResult createModelVersion(@RequestBody ModelDTO dto){
|
||||
log.info("新增模型版本");
|
||||
modelService.createModelVersion(dto);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询模型列表")
|
||||
@GetMapping("list")
|
||||
public OptResult list(){
|
||||
log.info("查询模型列表");
|
||||
List<ModelVO> modelVOList = modelService.list();
|
||||
return OptResult.success(modelVOList);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询模型详情")
|
||||
@GetMapping("detail")
|
||||
public OptResult detail(Long id){
|
||||
log.info("查询模型详情");
|
||||
ModelVersion modelVersion = modelService.detail(id);
|
||||
return OptResult.success(modelVersion);
|
||||
}
|
||||
|
||||
@Operation(summary = "模型更新")
|
||||
@PutMapping("/updateModel")
|
||||
public OptResult updateModel(@RequestBody ModelVersionDTO dto){
|
||||
log.info("模型更新");
|
||||
modelService.updateModel(dto);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "模型版本删除")
|
||||
@DeleteMapping("/deleteModelVersion")
|
||||
public OptResult deleteModelVersion(Long id){
|
||||
log.info("模型版本删除");
|
||||
modelService.deleteModelVersion(id);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "更新生命周期")
|
||||
@PutMapping("/updateLifeCycle")
|
||||
public OptResult updateLifeCycle(Long id,String lifeCycle){
|
||||
log.info("更新生命周期");
|
||||
modelService.updateLifeCycle(id,lifeCycle);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询生命周期列表")
|
||||
@GetMapping("/listLifeCycle")
|
||||
public OptResult listLifeCycle(){
|
||||
log.info("查询生命周期列表");
|
||||
List<Map<String, String>> lifeCycleList = modelService.listLifeCycle();
|
||||
return OptResult.success(lifeCycleList);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询数据集列表")
|
||||
@GetMapping("/listDataset")
|
||||
public OptResult listDataset(){
|
||||
List<DatasetEntity> datasetList = modelService.listDataset();
|
||||
return OptResult.success(datasetList);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
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.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name ="服务发布相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/publish")
|
||||
@Slf4j
|
||||
public class PublishController {
|
||||
@Autowired
|
||||
private PublishService publishService;
|
||||
|
||||
@Autowired
|
||||
private NacosServiceUtil nacosServiceUtil;
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary ="新增发布请求")
|
||||
@Transactional
|
||||
public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) {
|
||||
log.info("模型发布请求:{}", servicePublishDTO);
|
||||
publishService.save(servicePublishDTO);
|
||||
//todo 调用模型部署
|
||||
|
||||
// 获取前端传来的IP字符串
|
||||
String ipListStr = servicePublishDTO.getIp();
|
||||
if (ipListStr == null || ipListStr.trim().isEmpty()) {
|
||||
log.warn("IP列表为空,不进行Nacos注册");
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用逗号分割IP字符串
|
||||
String[] ipArray = ipListStr.split(",");
|
||||
// 循环注册每个IP到Nacos
|
||||
for (String ip : ipArray) {
|
||||
String trimmedIp = ip.trim();
|
||||
if (!trimmedIp.isEmpty()) {
|
||||
nacosServiceUtil.registerService(
|
||||
servicePublishDTO.getModelId().toString(),
|
||||
trimmedIp,
|
||||
8080,
|
||||
servicePublishDTO.getApiUrl()
|
||||
);
|
||||
log.info("Nacos服务注册成功: {}", trimmedIp);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Nacos服务注册失败", e);
|
||||
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
|
||||
}
|
||||
|
||||
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.ServiceAPIService;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Tag(name ="服务API相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/API")
|
||||
@Slf4j
|
||||
public class ServiceAPIController {
|
||||
|
||||
@Autowired
|
||||
private ServiceAPIService serviceAPIService;
|
||||
|
||||
@Autowired
|
||||
private NacosServiceUtil nacosServiceUtil;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@PostMapping("/release")
|
||||
@Operation(summary = "结束访问")
|
||||
@Transactional
|
||||
public OptResult releaseResource(@PathVariable Long modelId) {
|
||||
String key = "modelId:" + modelId;
|
||||
String modelConfig = (String) redisTemplate.opsForValue().get(key);
|
||||
int userMemorySize = parseGpuMemorySize(modelConfig);
|
||||
List<String> instanceIps;
|
||||
try {
|
||||
instanceIps = nacosServiceUtil.getServiceInstances(modelId.toString());
|
||||
} catch (Exception e) {
|
||||
log.error("获取Nacos实例失败", e);
|
||||
return OptResult.error("获取实例失败");
|
||||
}
|
||||
int memorySize;
|
||||
for (String ip : instanceIps) {
|
||||
String ipKey = "ip:" + ip;
|
||||
Integer nowMemorySizeOBJ = (Integer) redisTemplate.opsForValue().get(ipKey);
|
||||
int nowMemorySize = nowMemorySizeOBJ;
|
||||
memorySize = nowMemorySize + userMemorySize;
|
||||
// 更新IP对应的资源值
|
||||
redisTemplate.opsForValue().set(ipKey, memorySize);
|
||||
// 设置缓存过期时间(3600秒)
|
||||
redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// 处理等待队列(先来先服务)
|
||||
String waitQueueKey = "waitQueue:" + modelId;
|
||||
// 取出队列头部的任务(最早加入的)
|
||||
Long waitModelId = (Long) redisTemplate.opsForList().leftPop(waitQueueKey);
|
||||
if (waitModelId != null) {
|
||||
log.info("检测到等待队列任务,尝试调度模型ID: {}", waitModelId);
|
||||
return schedule(waitModelId); // 重新调度最早的任务
|
||||
} else {
|
||||
log.info("等待队列为空,无任务需要处理");
|
||||
}
|
||||
|
||||
return OptResult.success("资源释放成功");
|
||||
}
|
||||
|
||||
@PostMapping("/request/{modelId}")
|
||||
@Operation(summary = "请求调度")
|
||||
@Transactional
|
||||
public OptResult schedule(@PathVariable Long modelId) {
|
||||
// 1. 存储modelConfig到缓存
|
||||
String modelConfig = serviceAPIService.getByModelId(modelId);
|
||||
int requestMemorySize = parseGpuMemorySize(modelConfig);
|
||||
if (requestMemorySize == -1){
|
||||
return OptResult.error("解析配置失败,请检查模型:" + modelId +"是否存在");
|
||||
}
|
||||
String modelConfigKey = "modelConfig:" + modelId;
|
||||
redisTemplate.opsForValue().set(modelConfigKey, modelConfig);
|
||||
// 2. 获取Nacos实例IP列表
|
||||
List<String> instanceIps;
|
||||
try {
|
||||
instanceIps = nacosServiceUtil.getServiceInstances(modelId.toString());
|
||||
} catch (Exception e) {
|
||||
log.error("获取Nacos实例失败", e);
|
||||
return OptResult.error("获取实例失败");
|
||||
}
|
||||
Set<String> gpuKeys = redisTemplate.keys("gpu:*");
|
||||
//根据IP列表查找资源
|
||||
for (String instanceIp : instanceIps) {
|
||||
for (String gpuKey : gpuKeys) {
|
||||
String GPUConfig = (String) redisTemplate.opsForValue().get(gpuKey);
|
||||
if (GPUConfig != null) {
|
||||
// 分割键值对
|
||||
String[] pairs = GPUConfig.split(",");
|
||||
String ip = null;
|
||||
int memorySize = 0;
|
||||
for (String pair : pairs) {
|
||||
String[] keyValue = pair.split(":", 2);
|
||||
if (keyValue.length == 2) {
|
||||
String key = keyValue[0].trim();
|
||||
String value = keyValue[1].trim();
|
||||
if ("IP".equalsIgnoreCase(key)) {
|
||||
ip = value;
|
||||
} else if ("GPUMemorySize".equalsIgnoreCase(key)) {
|
||||
memorySize = Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 检查解析出的 IP 是否在 Nacos 实例列表中
|
||||
if (instanceIp.equals(ip)) {
|
||||
log.info("找到 IP {} 对应的 GPU 内存: {} ", ip, memorySize);
|
||||
if (memorySize>=requestMemorySize){
|
||||
int newMemorySize = memorySize - requestMemorySize;
|
||||
String ipKey = "ip:" + ip;
|
||||
redisTemplate.opsForValue().set(ipKey,newMemorySize);
|
||||
//访问请求最大时间为3600s
|
||||
redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS);
|
||||
}
|
||||
return OptResult.success("资源分配成功,使用ip:" + ip);
|
||||
}else {
|
||||
log.info("资源不足");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 所有实例检查完毕未找到足够资源
|
||||
String waitQueueKey = "waitQueue:" + modelId;
|
||||
// 改为右插入,保证队列顺序为FIFO(最早的任务在列表头部)
|
||||
redisTemplate.opsForList().rightPush(waitQueueKey, modelId);
|
||||
log.info("未找到足够资源,任务 {} 加入等待队列", modelId);
|
||||
return OptResult.error("资源不足,等待中");
|
||||
}
|
||||
/**
|
||||
* 从模型配置字符串中解析GPU内存需求
|
||||
* @param modelConfig 模型配置字符串,格式如 "GPUMemorySize:8000,version:1"
|
||||
* @return 解析到的GPU内存大小(MB),若解析失败返回-1
|
||||
*/
|
||||
private int parseGpuMemorySize(String modelConfig) {
|
||||
if (modelConfig == null || modelConfig.isEmpty()) {
|
||||
log.error("模型配置为空,无法解析GPU内存需求");
|
||||
return -1;
|
||||
}
|
||||
int requestMemorySize = 0;
|
||||
String[] config = modelConfig.split(",");
|
||||
for (String pair : config) {
|
||||
// 按冒号分割键值对
|
||||
String[] keyValue = pair.split(":", 2);
|
||||
if (keyValue.length == 2) {
|
||||
String key = keyValue[0].trim();
|
||||
String value = keyValue[1].trim();
|
||||
// 匹配 GPUMemorySize 字段(忽略大小写)
|
||||
if ("GPUMemorySize".equalsIgnoreCase(key)) {
|
||||
try {
|
||||
requestMemorySize = Integer.parseInt(value);
|
||||
log.info("模型GPU内存: {} MB", requestMemorySize);
|
||||
break; // 找到后即可退出循环
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("解析GPUMemorySize失败,值: {}", value, e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requestMemorySize <= 0) {
|
||||
log.error("模型需求GPU内存未配置或无效");
|
||||
return -1;
|
||||
}
|
||||
return requestMemorySize;
|
||||
}
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.config.RedisConfiguration;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name ="服务发布相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/publish")
|
||||
@Slf4j
|
||||
public class publishController {
|
||||
@Autowired
|
||||
private PublishService publishService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
/**
|
||||
* 新增请求发布
|
||||
* @param servicePublishDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary ="新增发布请求")
|
||||
@Transactional
|
||||
public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) {
|
||||
log.info("模型发布请求:{}", servicePublishDTO);
|
||||
publishService.save(servicePublishDTO);
|
||||
Long modelId = servicePublishDTO.getModelId();
|
||||
String key = "Model_" + modelId;
|
||||
//查询redis是否存在GPU相关资源数据
|
||||
List<ServicePublishVO> list;
|
||||
list = (List<ServicePublishVO>) redisTemplate.opsForValue().get(key);
|
||||
//如果存在,直接返回,无须查询数据库
|
||||
if (list != null) {
|
||||
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资源释放时候优先分配等待队列中任务
|
||||
|
||||
}
|
||||
|
||||
return OptResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.deploy.entity;
|
||||
|
||||
public class DeployRequest {
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DeployRequest {
|
||||
private String modelId;
|
||||
private int requiredMemory;
|
||||
private DeployType deployType;
|
||||
private ModelInfo modelInfo;
|
||||
|
||||
// 部署类型枚举
|
||||
public enum DeployType {
|
||||
NORMAL,
|
||||
GRAY
|
||||
}
|
||||
// 默认构造函数
|
||||
public DeployRequest() {
|
||||
}
|
||||
|
||||
public DeployRequest(String modelId, int requiredMemory, DeployType deployType, ModelInfo modelInfo) {
|
||||
this.modelId = modelId;
|
||||
this.requiredMemory = requiredMemory;
|
||||
this.deployType = deployType;
|
||||
this.modelInfo = modelInfo;
|
||||
}
|
||||
|
||||
// Getter & Setter 方法
|
||||
public String getModelId() {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
public void setModelId(String modelId) {
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
public int getRequiredMemory() {
|
||||
return requiredMemory;
|
||||
}
|
||||
|
||||
public void setRequiredMemory(int requiredMemory) {
|
||||
this.requiredMemory = requiredMemory;
|
||||
}
|
||||
|
||||
public DeployType getDeployType() {
|
||||
return deployType;
|
||||
}
|
||||
|
||||
public void setDeployType(DeployType deployType) {
|
||||
this.deployType = deployType;
|
||||
}
|
||||
|
||||
public ModelInfo getModelInfo() {
|
||||
return modelInfo;
|
||||
}
|
||||
|
||||
public void setModelInfo(ModelInfo modelInfo) {
|
||||
this.modelInfo = modelInfo;
|
||||
}
|
||||
|
||||
// Equals 和 HashCode 方法
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DeployRequest that = (DeployRequest) o;
|
||||
return requiredMemory == that.requiredMemory &&
|
||||
Objects.equals(modelId, that.modelId) &&
|
||||
deployType == that.deployType &&
|
||||
Objects.equals(modelInfo, that.modelInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(modelId, requiredMemory, deployType, modelInfo);
|
||||
}
|
||||
|
||||
// toString 方法
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeployRequest{" +
|
||||
"modelId='" + modelId + '\'' +
|
||||
", requiredMemory=" + requiredMemory +
|
||||
", deployType=" + deployType +
|
||||
", modelInfo=" + modelInfo +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
public class DeployResponse<T> {
|
||||
private boolean isSuccess;
|
||||
private String errorInfo;
|
||||
private int status;
|
||||
private T data;
|
||||
|
||||
public DeployResponse(boolean b, String s, int i, T data) {
|
||||
isSuccess = b;
|
||||
errorInfo = s;
|
||||
status = i;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
// 成功响应
|
||||
public static <T> DeployResponse<T> success(T data) {
|
||||
return new DeployResponse<>(true, "", 200, data);
|
||||
}
|
||||
|
||||
// 失败响应
|
||||
public static <T> DeployResponse<T> fail(int status, String error) {
|
||||
return new DeployResponse<>(false, error, status, null);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
//@AllArgsConstructor
|
||||
public class DeploymentResource {
|
||||
private final GpuResource gpu;
|
||||
private final String url;
|
||||
|
||||
public DeploymentResource(GpuResource gpu, String url) {
|
||||
this.gpu = gpu;
|
||||
this.url = url;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface GpuEntityTransfer {
|
||||
GpuResource toEntity(GpuCreateDTO dto);
|
||||
GpuResource toEntity(GpuUpdateDTO dto);
|
||||
GpuResource toEntity(GpuResponseDTO dto);
|
||||
GpuResponseDTO toDTO(GpuResource entity);
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Data
|
||||
public class GpuResource {
|
||||
@TableField("GPUId")
|
||||
private Long GPUId;
|
||||
|
||||
@TableField("GPUModel")
|
||||
private String GPUModel;
|
||||
|
||||
@TableField("GPUMemorySize")
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@TableField("is_deleted")
|
||||
private Integer isDeleted = 0;
|
||||
|
||||
@TableField("Ip")
|
||||
private String Ip;
|
||||
|
||||
@TableField("created_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime UpdateTime;
|
||||
|
||||
@TableField("GPUMaxMemory")
|
||||
private Integer GPUMaxMemory;
|
||||
|
||||
public GpuResource(long l, String s, boolean b) {
|
||||
this.GPUId = l;
|
||||
this.GPUModel = s;
|
||||
this.isDeleted = b ? 1 : 0;
|
||||
}
|
||||
// public @Pattern(regexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$") String getIp() {
|
||||
// return Ip;
|
||||
// }
|
||||
|
||||
public Boolean getIsDeleted() {
|
||||
return isDeleted != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GpuResource(Long Id, String Model, Integer MemorySize, String ip, LocalDateTime create_time) {
|
||||
this.GPUId = Id;
|
||||
this.GPUModel = Model;
|
||||
this.GPUMemorySize = MemorySize;
|
||||
this.Ip = ip;
|
||||
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;
|
||||
}
|
||||
|
||||
public void setGPUModel(String GPUModel) {
|
||||
this.GPUModel = GPUModel;
|
||||
}
|
||||
|
||||
public void setGPUMemorySize(Integer GPUMemorySize) {
|
||||
this.GPUMemorySize = GPUMemorySize;
|
||||
}
|
||||
|
||||
public void setIsDeleted(Integer isDeleted) {
|
||||
this.isDeleted = isDeleted;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
Ip = ip;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.RedisCacheService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Repository
|
||||
public class GpuResourceRepository {
|
||||
// Redis键定义
|
||||
// Redis键模式定义
|
||||
private static final String GPU_KEY_PREFIX = "gpu:";
|
||||
|
||||
private final RedisCacheService redisCacheService;
|
||||
|
||||
@Autowired
|
||||
public GpuResourceRepository(RedisCacheService redisCacheService) {
|
||||
this.redisCacheService = redisCacheService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存或更新GPU资源
|
||||
* @param resource GPU资源对象
|
||||
*/
|
||||
public void save(GpuResource resource) {
|
||||
redisCacheService.put(resource.getGPUId().toString(), resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按ID查询GPU资源
|
||||
* @param id GPU资源ID
|
||||
* @return GPU资源对象(可能为null)
|
||||
*/
|
||||
public GpuResource findById(Long id) {
|
||||
return redisCacheService.get(id.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
public List<GpuResource> findByStatus(Status status) {
|
||||
// 由于Redis存储结构不支持直接按属性查询,需要通过keys + 过滤方式实现
|
||||
// 注意:生产环境中应考虑使用RedisSCAN替代KEYS(此处为简写)
|
||||
Set<String> keys = redisCacheService.scanKeys(GPU_KEY_PREFIX + "*");
|
||||
|
||||
List<GpuResource> result = new ArrayList<>();
|
||||
keys.forEach(key -> {
|
||||
String gpuId = key.substring(GPU_KEY_PREFIX.length());
|
||||
GpuResource resource = redisCacheService.get(gpuId);
|
||||
if (resource != null && resource.getStatus() == status) {
|
||||
result.add(resource);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateStatus(Long gpuId, Status newStatus) {
|
||||
GpuResource resource = findById(gpuId);
|
||||
if (resource != null) {
|
||||
resource.setStatus(newStatus);
|
||||
save(resource);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public List<GpuResource> findAll() {
|
||||
Set<String> keys = redisCacheService.scanKeys("gpu:*");
|
||||
return keys.stream()
|
||||
.map(key -> {
|
||||
String gpuId = key.substring(4); // 去除"gpu:"前缀
|
||||
return redisCacheService.get(gpuId);
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ModelInfo {
|
||||
private String modelId;
|
||||
private String modelName;
|
||||
private String modelType;
|
||||
private String preprocessScript;
|
||||
private String modelFilePath;
|
||||
private String storageLocation;
|
||||
|
||||
public String getModelId() {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
public void setModelId(String modelId) {
|
||||
this.modelId = modelId;
|
||||
}
|
||||
|
||||
// Getter & Setter 方法
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
public String getModelType() {
|
||||
return modelType;
|
||||
}
|
||||
|
||||
public void setModelType(String modelType) {
|
||||
this.modelType = modelType;
|
||||
}
|
||||
|
||||
public String getPreprocessScript() {
|
||||
return preprocessScript;
|
||||
}
|
||||
|
||||
public void setPreprocessScript(String preprocessScript) {
|
||||
this.preprocessScript = preprocessScript;
|
||||
}
|
||||
|
||||
public String getModelFilePath() {
|
||||
return modelFilePath;
|
||||
}
|
||||
|
||||
public void setModelFilePath(String modelFilePath) {
|
||||
this.modelFilePath = modelFilePath;
|
||||
}
|
||||
|
||||
public void setStorageLocation(String storageLocation) {
|
||||
// 验证路径格式
|
||||
if (storageLocation != null && !isValidStoragePath(storageLocation)) {
|
||||
throw new IllegalArgumentException("无效的存储路径: " + storageLocation);
|
||||
}
|
||||
this.storageLocation = storageLocation;
|
||||
}
|
||||
|
||||
private boolean isValidStoragePath(String path) {
|
||||
// 1. 基本非空检查
|
||||
if (path == null || path.trim().isEmpty()) return false;
|
||||
|
||||
// 2. 防止路径遍历攻击
|
||||
if (path.contains("..")) return false;
|
||||
|
||||
// 3. 仅允许合法路径格式
|
||||
return path.startsWith("/") ||
|
||||
path.startsWith("s3://") ||
|
||||
path.matches("[a-zA-Z]:\\\\"); // Windows 路径
|
||||
}
|
||||
|
||||
// Equals 和 HashCode 方法
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ModelInfo modelInfo = (ModelInfo) o;
|
||||
return Objects.equals(modelName, modelInfo.modelName) &&
|
||||
Objects.equals(modelType, modelInfo.modelType) &&
|
||||
Objects.equals(preprocessScript, modelInfo.preprocessScript) &&
|
||||
Objects.equals(modelFilePath, modelInfo.modelFilePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(modelName, modelType, preprocessScript, modelFilePath);
|
||||
}
|
||||
|
||||
// toString 方法
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ModelInfo{" +
|
||||
"modelName='" + modelName + '\'' +
|
||||
", modelType='" + modelType + '\'' +
|
||||
", preprocessScript='" + preprocessScript + '\'' +
|
||||
", modelFilePath='" + modelFilePath + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.enumeration;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum ErrorCodeEnum {
|
||||
SUCCESS(200, "操作成功"),
|
||||
SYSTEM_ERROR(500, "系统错误"),
|
||||
|
||||
PARAM_INVALID(400, "参数无效"),
|
||||
PARAM_MISSING(401, "缺少参数"),
|
||||
IP_FORMAT_ERROR(402, "IP地址格式错误"),
|
||||
GPU_MODEL_ERROR(403, "GPU型号格式应为[厂商]-[型号]"),
|
||||
|
||||
PERMISSION_DENIED(501, "无操作权限"),
|
||||
|
||||
GPU_NOT_FOUND(601, "GPU资源不存在"),
|
||||
|
||||
DB_CONNECTION_FAILED(701, "数据库连接错误"),
|
||||
VALIDATION_ERROR(801,"参数校验异常" ),
|
||||
|
||||
CACHE_INIT_ERROR(901, "缓存初始化失败"),
|
||||
INTERNAL_SERVER_ERROR(201,"内部服务出错" );
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
ErrorCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ErrorCodeEnum{" +
|
||||
"code=" + code +
|
||||
", message='" + message + '\''+
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.enumeration;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
|
||||
|
||||
/**
|
||||
* 模型生命周期状态枚举
|
||||
*/
|
||||
public enum ModelLifecycle {
|
||||
DESIGNING("设计中"),
|
||||
TRAINING("训练中"),
|
||||
EVALUATING("评估中"),
|
||||
DEPLOYED("已部署"),
|
||||
OFFLINE("已下线"),
|
||||
ABANDONED("已废弃");
|
||||
|
||||
private final String description;
|
||||
|
||||
private ModelLifecycle(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
// 将枚举名称转换成数据库存储的字符串
|
||||
public String getDbValue() {
|
||||
return name();
|
||||
}
|
||||
|
||||
// 将数据库存储的字符串转换为枚举实例
|
||||
public static ModelLifecycle getDbValueFromDb(String dbValue) {
|
||||
if(dbValue == null) return null;
|
||||
try {
|
||||
return ModelLifecycle.valueOf(dbValue);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(MessageConstant.LifeCycle_No_Exist + ":" + dbValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 从前端传的中文描述 -> 转换为枚举
|
||||
public static ModelLifecycle fromDescription(String description) {
|
||||
for (ModelLifecycle lifecycle : ModelLifecycle.values()) {
|
||||
if (lifecycle.getDescription().equals(description)) {
|
||||
return lifecycle;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("生命周期描述非法: " + description);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
public class CacheInitException extends RuntimeException{
|
||||
public CacheInitException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public CacheInitException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
public class DeployException extends RuntimeException{
|
||||
// 错误代码
|
||||
private int errorCode = 500;
|
||||
|
||||
public DeployException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DeployException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DeployException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DeployException(String message, int errorCode) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
public class EvaluationFailedException extends DeployException{
|
||||
public EvaluationFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public EvaluationFailedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public EvaluationFailedException() {
|
||||
super("模型评估未通过,无法部署");
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GpuGlobalException {
|
||||
@ExceptionHandler(DataAccessResourceFailureException.class)
|
||||
public ResponseVO handleDBConnectionError() {
|
||||
return ResponseVO.error(ErrorCodeEnum.DB_CONNECTION_FAILED);
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public ResponseVO handleValidationError(MethodArgumentNotValidException e) {
|
||||
return ResponseVO.error(ErrorCodeEnum.VALIDATION_ERROR);
|
||||
}
|
||||
|
||||
@ExceptionHandler(PermissionDeniedException.class)
|
||||
public ResponseVO handlePermissionDenied(PermissionDeniedException ex) {
|
||||
return ResponseVO.error(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(CacheInitException.class)
|
||||
public ResponseVO<?> handleCacheInitException(CacheInitException ex) {
|
||||
return ResponseVO.error(
|
||||
ErrorCodeEnum.CACHE_INIT_ERROR.getCode(),
|
||||
"缓存初始化失败: " + ex.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class PermissionDeniedException extends RuntimeException {
|
||||
private final Integer code;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
private final String message;
|
||||
|
||||
public PermissionDeniedException(ErrorCodeEnum errorCode) {
|
||||
super(errorCode.getMessage());
|
||||
this.code = errorCode.getCode();
|
||||
this.message = errorCode.getMessage();
|
||||
}
|
||||
|
||||
public PermissionDeniedException(ErrorCodeEnum errorCode, String appendMessage) {
|
||||
super(errorCode.getMessage()+": "+appendMessage);
|
||||
this.code = errorCode.getCode();
|
||||
this.message = errorCode.getMessage()+": "+appendMessage;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.filter;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Component
|
||||
public class ApiRequestGlobalFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
// 检查请求路径和方法
|
||||
if (request.getURI().getPath().equals("/request/{id}") &&
|
||||
request.getMethod() == HttpMethod.POST) {
|
||||
// 在此处添加拦截逻辑
|
||||
System.out.println("拦截到POST /request请求");
|
||||
}
|
||||
// 继续处理请求
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 1; // 过滤器执行顺序,数值越小越先执行
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface GpuResourceDao {
|
||||
//---------------------- 基础CRUD ------------------------
|
||||
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip, created_time) " +
|
||||
"VALUES (#{GPUModel}, #{GPUMemorySize}, #{Ip}, NOW())")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "GPUId")
|
||||
Integer insert(GpuResource entity);
|
||||
|
||||
//物理删除
|
||||
@Delete("DELETE FROM Ipz.public.gpu_resource WHERE GPUId = #{gpuId}")
|
||||
Integer deleteById(@Param("gpuId") Long gpuId);
|
||||
|
||||
// 逻辑删除
|
||||
@Update("UPDATE Ipz.public.gpu_resource" +
|
||||
" SET is_deleted = 1, update_time = NOW() " +
|
||||
" WHERE GPUId = #{gpuId}")
|
||||
Integer isDeleted(@Param("gpuId") Long gpuId);
|
||||
|
||||
@Update("UPDATE Ipz.public.gpu_resource " +
|
||||
"SET GPUModel = #{GPUModel}, GPUMemorySize = #{GPUMemorySize}, Ip = #{Ip} " +
|
||||
"WHERE GPUId = #{GPUId}")
|
||||
Integer updateById(GpuResource entity);
|
||||
|
||||
@Select("SELECT * FROM Ipz.public.gpu_resource WHERE GPUId = #{gpuId} AND is_deleted = 0")
|
||||
GpuResource selectById(@Param("gpuId") Long gpuId);
|
||||
|
||||
//---------------------- 缓存相关扩展 ------------------------
|
||||
|
||||
/**
|
||||
* 分页全量查询(缓存初始化用)
|
||||
* @param offset 起始位置
|
||||
* @param limit 每页数量
|
||||
*/
|
||||
// @Select("SELECT * FROM ipz.gpu_resource " +
|
||||
// "ORDER BY GPUId ASC LIMIT #{limit} OFFSET #{offset}")
|
||||
List<GpuResource> findByPage(@Param("offset") int offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 增量数据查询(缓存同步用)
|
||||
* @param since 起始时间
|
||||
*/
|
||||
// @Select("SELECT *, is_deleted FROM ipz.gpu_resource " +
|
||||
// "WHERE update_time > #{since} " +
|
||||
// "ORDER BY update_time ASC")
|
||||
List<GpuResource> findModifiedSince(@Param("since") LocalDateTime since);
|
||||
|
||||
/**
|
||||
* 带锁查询(防缓存击穿)
|
||||
*/
|
||||
// @Select("SELECT * FROM ipz.gpu_resource " +
|
||||
// "WHERE GPUId = #{gpuId} FOR UPDATE NOWAIT")
|
||||
GpuResource selectByIdWithLock(@Param("gpuId") Long gpuId);
|
||||
|
||||
/**
|
||||
* 动态条件查询(管理界面筛选用)
|
||||
*/
|
||||
// @SelectProvider(type = GpuSqlBuilder.class, method = "buildDynamicQuery")
|
||||
List<GpuResource> selectByFields(@Param("params") Map<String, Object> params);
|
||||
}
|
||||
|
||||
// 动态SQL构造器
|
||||
class GpuSqlBuilder {
|
||||
public static String buildDynamicQuery(Map<String, Object> params) {
|
||||
return new SQL() {{
|
||||
SELECT("*");
|
||||
FROM("Ipz.public.gpu_resource");
|
||||
if (params.containsKey("model")) {
|
||||
WHERE("GPUModel LIKE #{params.model}");
|
||||
}
|
||||
if (params.containsKey("memoryMin")) {
|
||||
WHERE("GPUMemorySize >= #{params.memoryMin}");
|
||||
}
|
||||
if (params.containsKey("ip")) {
|
||||
WHERE("Ip = #{params.ip}");
|
||||
}
|
||||
if (params.containsKey("isDeleted")) {
|
||||
WHERE("is_deleted = #{params.isDeleted}");
|
||||
}
|
||||
}}.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModelMapper {
|
||||
|
||||
/**
|
||||
* 插入模型基本信息
|
||||
* @param modelInfo
|
||||
*/
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id") //能够拿到主键值,并设置给modelInfo对象
|
||||
@Insert("insert into model_info(model_name) values(#{modelName})")
|
||||
void insertModelInfo(ModelInfo modelInfo);
|
||||
|
||||
/**
|
||||
* 插入模型版本信息
|
||||
* @param modelVersion
|
||||
*/
|
||||
void insertModelVersion(ModelVersion modelVersion);
|
||||
|
||||
/*
|
||||
* 查询模型列表
|
||||
*/
|
||||
List<ModelVO> list();
|
||||
|
||||
/**
|
||||
* 根据id查询模型详情
|
||||
* @param id 版本表id
|
||||
* @return
|
||||
*/
|
||||
ModelVersion selectById(Long id);
|
||||
|
||||
/**
|
||||
* 更新模型信息
|
||||
* @param dto
|
||||
*/
|
||||
void update(ModelVersionDTO dto);
|
||||
|
||||
/**
|
||||
* 删除模型版本
|
||||
* @param id 版本表id
|
||||
*/
|
||||
@Delete("delete from model_version where id=#{id}")
|
||||
void deleteModelVersion(Long id);
|
||||
|
||||
/**
|
||||
* 删除模型
|
||||
* @param id 模型id
|
||||
*/
|
||||
@Delete("delete from model_info where id= #{id}")
|
||||
void deleteModel(Long id);
|
||||
|
||||
/**
|
||||
* 查询模型生命周期
|
||||
* @param id 模型版本表id
|
||||
* 返回模型生命周期
|
||||
*/
|
||||
@Select("select life_cycle from model_version where id=#{id}")
|
||||
String selectLifeCycleById(Long id);
|
||||
|
||||
/**
|
||||
* 更新模型生命周期
|
||||
* @param id 模型版本表id
|
||||
* @param dbValue 数据库中存储的生命周期
|
||||
* @return
|
||||
*/
|
||||
@Update("update model_version set life_cycle=#{dbValue} where id=#{id}")
|
||||
int updateLifeCycleById(Long id, String dbValue);
|
||||
|
||||
/**
|
||||
* 查询数据集列表
|
||||
* @return
|
||||
*/
|
||||
@Select("select dataset_id,dataset_name from dataset")
|
||||
List<DatasetEntity> listDataset();
|
||||
}
|
@ -14,7 +14,6 @@ public interface PublishMapper {
|
||||
void insert(ServicePublishDTO servicePublishDTO);
|
||||
|
||||
Long getByApiUrl(String apiUrl);
|
||||
@Select("select model_config from model_version where model_id=#{modelId} and status = 1")
|
||||
String getById(Long modelId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@Mapper
|
||||
public interface ServiceAPIMapper {
|
||||
@Select("select model_config from model_version where model_id=#{modelId} and status = 1")
|
||||
String getById(Long modelId);
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AlgorithmInfo {
|
||||
private Long id;
|
||||
private String algorithmName;
|
||||
|
@ -0,0 +1,31 @@
|
||||
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;
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
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}\\.){3}\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
@JsonProperty("Ip") // 显示指定JSON映射名称
|
||||
private String Ip;
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
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 {
|
||||
@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 createTime = LocalDateTime.now(); // 统一命名为createTime
|
||||
|
||||
public Builder id(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder model(String model) {
|
||||
this.model = model;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder memory(Integer memory) {
|
||||
this.memory = memory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ip(String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder createTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GpuResponseDTO build() {
|
||||
// 必填字段校验
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("GPU ID必须填写");
|
||||
}
|
||||
|
||||
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 != null ? createTime.toString() : "未设置");
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
//@Setter
|
||||
//@Getter
|
||||
public class GpuUpdateDTO {
|
||||
|
||||
private Long GPUId;
|
||||
|
||||
public @Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") String getGPUModel() {
|
||||
return GPUModel;
|
||||
}
|
||||
|
||||
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")
|
||||
private String GPUModel;
|
||||
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
private String Ip;
|
||||
|
||||
public void setGPUId(Long GPUId) {
|
||||
this.GPUId = GPUId;
|
||||
}
|
||||
|
||||
public void setGPUModel(@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") String GPUModel) {
|
||||
this.GPUModel = GPUModel;
|
||||
}
|
||||
|
||||
public void setIp(@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效") String ip) {
|
||||
Ip = ip;
|
||||
}
|
||||
public Long getGPUId() {
|
||||
return GPUId;
|
||||
}
|
||||
|
||||
public Integer getGPUMemorySize() {
|
||||
return GPUMemorySize;
|
||||
}
|
||||
|
||||
public void setGPUMemorySize(Integer GPUMemorySize) {
|
||||
this.GPUMemorySize = GPUMemorySize;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ModelDTO {
|
||||
private Long id; // 模型id
|
||||
private String modelName; // 模型名称
|
||||
private String version; // 模型版本
|
||||
private Integer datasetId; // 数据集id
|
||||
private String modelConfig; // 模型配置信息
|
||||
private String modelPath; // 模型存储路径
|
||||
private Integer status; // 模型状态(1代表上线,0代表不上线)D
|
||||
private Integer modelSize; // 模型大小
|
||||
private String dataPreHandleFile; // 数据预处理文件存储路径
|
||||
private String modelSuperArgs; // 模型超参数
|
||||
private String modelArgsSize; // 模型参数量
|
||||
private String modelSourceCodeUrl; // 模型源代码路径
|
||||
private String modelFile; // 模型文件存储路径
|
||||
private String modelDesignDocument; // 模型设计文档存储路径
|
||||
private String lifeCycle; // 模型生命周期
|
||||
private String operateUser; // 操作人
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ModelVO {
|
||||
private Long id; // 模型id
|
||||
private Long versionId; // 用于保证react的map中key的唯一性
|
||||
private String modelName; // 模型名称
|
||||
private String version; // 模型版本
|
||||
private String dataPreHandleFile; // 数据预处理文件存储路径
|
||||
private String operateUser; // 操作人
|
||||
private LocalDateTime updateTime; // 修改时间
|
||||
private Integer status; // 模型状态(1代表上线,0代表不上线)
|
||||
|
||||
}
|
@ -24,5 +24,23 @@ public class ModelVersion implements Serializable {
|
||||
private String modelPath; // 模型存储路径
|
||||
private Integer status; // 模型状态(1代表上线,0代表不上线)
|
||||
private LocalDateTime createTime; // 创建时间
|
||||
//补充更新时间字段
|
||||
private LocalDateTime updateTime; // 更新时间
|
||||
//创建模型部分补充的字段
|
||||
private Integer modelSize; // 模型大小
|
||||
private String dataPreHandleFile; // 数据预处理文件存储路径
|
||||
//模型信息管理部分补充的字段
|
||||
private String modelSuperArgs; // 模型超参数
|
||||
private String modelArgsSize; // 模型参数量
|
||||
private String modelSourceCodeUrl; // 模型源代码路径
|
||||
private String modelFile; // 模型文件存储路径
|
||||
private String modelDesignDocument; // 模型设计文档存储路径
|
||||
|
||||
private String lifeCycle; // 模型生命周期
|
||||
|
||||
private String operateUser; // 操作人
|
||||
|
||||
private String modelName; //模型名称
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ModelVersionDTO {
|
||||
private Long id; // 模型id
|
||||
private String version; // 模型版本
|
||||
private Integer datasetId; // 数据集id
|
||||
private String modelConfig; // 模型配置信息
|
||||
private String modelPath; // 模型存储路径
|
||||
private Integer status; // 模型状态(1代表上线,0代表不上线)
|
||||
private LocalDateTime createTime; // 创建时间
|
||||
private LocalDateTime updateTime; // 更新时间
|
||||
private Integer modelSize; // 模型大小
|
||||
private String dataPreHandleFile; // 数据预处理文件存储路径
|
||||
private String modelSuperArgs; // 模型超参数
|
||||
private String modelArgsSize; // 模型参数量
|
||||
private String modelSourceCodeUrl; // 模型源代码路径
|
||||
private String modelFile; // 模型文件存储路径
|
||||
private String modelDesignDocument; // 模型设计文档存储路径
|
||||
private String lifeCycle; // 模型生命周期
|
||||
private String operateUser; // 操作人
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ResponseVO<T> implements Serializable {
|
||||
private Integer code; //状态码
|
||||
private String message; //描述信息
|
||||
private T data; //业务数据
|
||||
|
||||
|
||||
//私有构造方法
|
||||
private ResponseVO(Integer code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
//静态工厂方法
|
||||
//成功响应(无数据)
|
||||
public static <T> ResponseVO<T> success() {
|
||||
return new ResponseVO<>(200, "OK", null);
|
||||
}
|
||||
//成功响应(有数据)
|
||||
public static <T> ResponseVO<T> success(T data) {
|
||||
return new ResponseVO<>(200, "OK", data);
|
||||
}
|
||||
//失败响应(自定义错误码和消息)
|
||||
public static <T> ResponseVO<T> error(Integer code, String message) {
|
||||
return new ResponseVO<>(code, message, null);
|
||||
}
|
||||
//失败响应(基于预定义错误枚举)
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -18,6 +19,7 @@ public class ServicePublishDTO implements Serializable {
|
||||
private Long id;
|
||||
private Long modelId;
|
||||
private String apiUrl;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
private String ip;
|
||||
}
|
||||
|
@ -11,4 +11,7 @@ public interface AlgorithmInfoService {
|
||||
boolean update(AlgorithmInfo algorithmInfo);
|
||||
boolean delete(Long id);
|
||||
boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo);
|
||||
|
||||
void save(AlgorithmInfo algorithmInfo);
|
||||
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.CacheInitException;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Transactional // 添加类级别事务管理
|
||||
@Component
|
||||
public class CacheManager {
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private GpuResourceDao gpuResourceDao;
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@Value("${cache.redis-key-prefix:gpu:}")
|
||||
private String keyPrefix;
|
||||
|
||||
@Value("${cache.ttl-base:7200}")
|
||||
private int ttlBase;
|
||||
|
||||
@Value("${cache.init-batch-size:500}")
|
||||
private int initBatchSize;
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(CacheManager.class);
|
||||
// 全量加载(带分页和分布式锁)
|
||||
@Transactional(propagation = Propagation.REQUIRED) // 方法级别覆盖
|
||||
@PostConstruct
|
||||
public void loadFullCache() {
|
||||
if (tryLock()) {
|
||||
try {
|
||||
int page = 0;
|
||||
while (true) {
|
||||
List<GpuResource> batch = gpuResourceDao.findByPage(page * initBatchSize, initBatchSize);
|
||||
if (batch.isEmpty()) break;
|
||||
|
||||
batch.forEach(this::setCacheWithTTL);
|
||||
page++;
|
||||
}
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 单条缓存刷新(带版本控制)
|
||||
public void refreshCache(Long gpuId) {
|
||||
GpuResource latest = gpuResourceDao.selectByIdWithLock(gpuId);
|
||||
if (latest != null) {
|
||||
setCacheWithTTL(latest);
|
||||
}
|
||||
}
|
||||
|
||||
// 批量增量同步
|
||||
public void syncCache(LocalDateTime lastSyncTime) {
|
||||
List<GpuResource> updates = gpuResourceDao.findModifiedSince(lastSyncTime);
|
||||
updates.forEach(entity -> {
|
||||
if (entity.getIsDeleted()) {
|
||||
redisTemplate.delete(buildKey(entity.getGPUId().toString()));
|
||||
} else {
|
||||
setCacheWithTTL(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 带随机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防止雪崩
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
// 构建缓存键
|
||||
private String buildKey(String gpuId) {
|
||||
return keyPrefix + gpuId;
|
||||
}
|
||||
|
||||
// 分布式锁操作
|
||||
private boolean tryLock() {
|
||||
try {
|
||||
return lock.tryLock(30, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void unlock() {
|
||||
lock.unlock();
|
||||
}
|
||||
// 分页加载入口
|
||||
public void loadFullCache(int batchSize) {
|
||||
int page = 0;
|
||||
while (true) {
|
||||
List<GpuResource> batch = gpuResourceDao.findByPage(page * batchSize, batchSize);
|
||||
if (batch.isEmpty()) break;
|
||||
|
||||
batch.forEach(this::refreshWithRetry); // 带重试的刷新逻辑
|
||||
page++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 带重试机制的缓存刷新
|
||||
public void refreshWithRetry(GpuResource entity) {
|
||||
try {
|
||||
setCacheWithTTL(entity);
|
||||
} catch (RedisConnectionFailureException ex) {
|
||||
// 3次重试逻辑
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
log.info("重试第 {} 次", i + 1); // 添加日志
|
||||
Thread.sleep(1000);
|
||||
setCacheWithTTL(entity);
|
||||
return;
|
||||
} catch (InterruptedException e) {
|
||||
if (i == 2) {
|
||||
throw new CacheInitException("缓存刷新失败: " + entity.getGPUId().toString());
|
||||
}
|
||||
|
||||
log.error("重试失败", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前缓存数量(调试用)
|
||||
public long getCacheCount() {
|
||||
return redisTemplate.keys(keyPrefix + "*").size();
|
||||
}
|
||||
|
||||
public void evictCache(Long gpuId) {
|
||||
String key = buildKey(gpuId.toString());
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
public GpuResource getFromCache(String gpuId) {
|
||||
return (GpuResource) redisTemplate.opsForValue().get("gpu:" + gpuId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GpuManageService {
|
||||
public ResponseVO createGpuResource(GpuCreateDTO dto);
|
||||
public ResponseVO deleteGpuResource(Long gpuId);
|
||||
public void updateGpuResource(GpuUpdateDTO entity);
|
||||
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip);
|
||||
|
||||
@Transactional
|
||||
ResponseVO createGpuResourceWithTrace(GpuCreateDTO dto);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResourceRepository;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class GpuResourceService {
|
||||
@Autowired
|
||||
private GpuResourceRepository repository;
|
||||
|
||||
@Cacheable(value = "availableGpus")
|
||||
public List<GpuResource> getAvailableResources() {
|
||||
// 获取所有未删除的资源
|
||||
return repository.findAll().stream()
|
||||
.filter(gpu -> gpu.getIsDeleted() == null || !gpu.getIsDeleted())
|
||||
.collect(Collectors.toList()); }
|
||||
|
||||
public void markAsAllocated(Long gpuId, int allocatedMemory) {
|
||||
GpuResource gpu = repository.findById(gpuId);
|
||||
if (gpu != null) {
|
||||
// 更新已使用内存
|
||||
int currentMemory = gpu.getGPUMemorySize() != null ? gpu.getGPUMemorySize() : 0;
|
||||
gpu.setGPUMemorySize(currentMemory + allocatedMemory);
|
||||
repository.save(gpu);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.EvaluationFailedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class GrayDeployService {
|
||||
@Autowired
|
||||
private ModelEvaluator modelEvaluator;
|
||||
|
||||
@Autowired
|
||||
private ResourceAllocator resourceAllocator;
|
||||
|
||||
@Autowired
|
||||
private GpuResourceService gpuService;
|
||||
|
||||
// @Autowired
|
||||
// private MQSender mqSender;
|
||||
|
||||
public DeployResponse process(DeployRequest request) {
|
||||
// 检查评估状态
|
||||
if (!modelEvaluator.isEvaluationPassed(request.getModelId())) {
|
||||
throw new EvaluationFailedException("模型评估未通过");
|
||||
}
|
||||
|
||||
// 分配资源并获取URL
|
||||
DeploymentResource resource = resourceAllocator.allocate(
|
||||
gpuService.getAvailableResources(),
|
||||
request.getRequiredMemory(),
|
||||
request.getModelId(),
|
||||
true
|
||||
);
|
||||
|
||||
// // 发送MQ灰度通知
|
||||
// mqSender.sendGrayDeployNotification(
|
||||
// resource.getUrl(),
|
||||
// request.getModelId(),
|
||||
// resource.getGpu().getGPUId()
|
||||
// );
|
||||
// 标记资源已分配(更新内存使用量)
|
||||
gpuService.markAsAllocated(
|
||||
resource.getGpu().getGPUId(),
|
||||
request.getRequiredMemory()
|
||||
);
|
||||
return DeployResponse.success(resource.getUrl());
|
||||
|
||||
}
|
||||
}
|
@ -60,4 +60,23 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 算法创建
|
||||
* @param algorithmInfo
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(AlgorithmInfo algorithmInfo) {
|
||||
String algorithmName = algorithmInfo.getAlgorithmName();
|
||||
//查找表里是否有重复的算法,如果有则报错
|
||||
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
|
||||
if (duplicateName != null){
|
||||
throw new RuntimeException("算法已存在");
|
||||
}
|
||||
//todo 算法文件分布式存入分布式存储中
|
||||
|
||||
|
||||
algorithmInfoMapper.insert(algorithmInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ModelLifecycle;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ModelServiceImpl implements ModelService {
|
||||
@Autowired
|
||||
private ModelMapper modelMapper;
|
||||
/**
|
||||
* 创建模型
|
||||
* @param dto
|
||||
*/
|
||||
@Transactional //事务注解
|
||||
@Override
|
||||
public void createModel(ModelDTO dto) {
|
||||
log.info("创建模型");
|
||||
//1.插入模型基本信息
|
||||
ModelInfo modelInfo = new ModelInfo();
|
||||
BeanUtils.copyProperties(dto, modelInfo, "id");
|
||||
modelMapper.insertModelInfo(modelInfo);
|
||||
log.info("模型id: {}", modelInfo.getId());
|
||||
//2.插入模型版本信息
|
||||
ModelVersion modelVersion = new ModelVersion();
|
||||
//使用工具类将dto属性复制给modelVersion
|
||||
BeanUtils.copyProperties(dto, modelVersion, "id");
|
||||
modelVersion.setModelId(modelInfo.getId());
|
||||
modelVersion.setCreateTime(LocalDateTime.now());
|
||||
modelVersion.setUpdateTime(LocalDateTime.now());
|
||||
modelVersion.setOperateUser("zs");
|
||||
modelMapper.insertModelVersion(modelVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增模型版本
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public void createModelVersion(ModelDTO dto) {
|
||||
log.info("新增模型版本");
|
||||
ModelVersion modelVersion = new ModelVersion();
|
||||
BeanUtils.copyProperties(dto, modelVersion, "id");
|
||||
modelVersion.setModelId(dto.getId());
|
||||
modelVersion.setCreateTime(LocalDateTime.now());
|
||||
modelVersion.setUpdateTime(LocalDateTime.now());
|
||||
modelVersion.setOperateUser("zs");
|
||||
modelMapper.insertModelVersion(modelVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询模型列表
|
||||
*/
|
||||
@Override
|
||||
public List<ModelVO> list() {
|
||||
log.info("查询模型列表");
|
||||
List<ModelVO> modelVOList = modelMapper.list();
|
||||
return modelVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelVersion detail(Long id) {
|
||||
log.info("查询模型详情");
|
||||
ModelVersion modelVersion = modelMapper.selectById(id);
|
||||
return modelVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateModel(ModelVersionDTO dto) {
|
||||
log.info("更新模型");
|
||||
modelMapper.update(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteModelVersion(Long id) {
|
||||
log.info("删除模型版本");
|
||||
modelMapper.deleteModelVersion(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新模型生命周期
|
||||
* @param id 版本表id
|
||||
* @param
|
||||
*/
|
||||
@Override
|
||||
public void updateLifeCycle(Long id, String lifeCycleDescription) {
|
||||
log.info("更新模型生命周期");
|
||||
|
||||
// 1. 查询当前生命周期并转为枚举
|
||||
String currentLifeCycleStr = modelMapper.selectLifeCycleById(id);
|
||||
if (currentLifeCycleStr == null) {
|
||||
log.error("未找到对应模型信息,无法更新生命周期");
|
||||
throw new IllegalArgumentException(MessageConstant.LifeCycle_No_Exist);
|
||||
}
|
||||
|
||||
ModelLifecycle currentLifeCycle;
|
||||
ModelLifecycle targetLifeCycle;
|
||||
try {
|
||||
currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文
|
||||
targetLifeCycle = ModelLifecycle.fromDescription((lifeCycleDescription).trim()); // 前端传中文
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error(MessageConstant.LifeCycle_Undefined + ":{}", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 2. 业务逻辑校验
|
||||
switch (currentLifeCycle) {
|
||||
case DEPLOYED:
|
||||
if (targetLifeCycle == ModelLifecycle.DESIGNING) {
|
||||
log.error("已部署的模型不能直接调整成设计,需先下线再设计");
|
||||
throw new IllegalArgumentException(MessageConstant.ERROR_DEPLOYED_TO_DESIGNING);
|
||||
}
|
||||
break;
|
||||
case ABANDONED:
|
||||
log.error("已废弃的模型只能查看信息,不能更新生命周期");
|
||||
throw new IllegalArgumentException(MessageConstant.ERROR_ABANDONED_CANNOT_UPDATE);
|
||||
case TRAINING:
|
||||
if (targetLifeCycle != ModelLifecycle.DESIGNING && targetLifeCycle != ModelLifecycle.EVALUATING) {
|
||||
log.error("训练中的模型只能调整成设计和评估");
|
||||
throw new IllegalArgumentException(MessageConstant.ERROR_TRAINING_INVALID_TRANSITION);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 3. 执行更新
|
||||
int affectedRows = modelMapper.updateLifeCycleById(id, targetLifeCycle.getDbValue());
|
||||
if (affectedRows == 0) {
|
||||
log.error("更新模型生命周期失败");
|
||||
throw new RuntimeException(MessageConstant.UPDATE_FAILURE);
|
||||
}
|
||||
|
||||
log.info("模型生命周期更新成功,新状态为: {}", targetLifeCycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> listLifeCycle() {
|
||||
return Arrays.stream(ModelLifecycle.values())
|
||||
.map(lifecycle -> Map.of(
|
||||
"code", lifecycle.name(), // 枚举名称(如 "DESIGNING")
|
||||
"description", lifecycle.getDescription() // 中文描述(如 "设计中")
|
||||
))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DatasetEntity> listDataset() {
|
||||
List<DatasetEntity> datasetEntityList = modelMapper.listDataset();
|
||||
return datasetEntityList;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -29,18 +29,12 @@ public class PublishServiceImpl implements PublishService {
|
||||
if (id != null){
|
||||
throw new IllegalArgumentException("请求已存在: " + apiUrl);
|
||||
}
|
||||
|
||||
//todo调用服务部署
|
||||
|
||||
publishMapper.insert(servicePublishDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查找配置信息
|
||||
* @param modelId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getByModelId(Long modelId) {
|
||||
return publishMapper.getById(modelId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.ServiceAPIMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.ServiceAPIService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ServiceAPIImpl implements ServiceAPIService {
|
||||
@Autowired
|
||||
private ServiceAPIMapper serviceAPIMapper;
|
||||
/**
|
||||
* 根据id查找配置信息
|
||||
* @param modelId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getByModelId(Long modelId) {
|
||||
return serviceAPIMapper.getById(modelId);
|
||||
};
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.DeployException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class ModelDeployer {
|
||||
|
||||
@Autowired
|
||||
private ModelRepositoryClient modelRepositoryClient;
|
||||
|
||||
@Autowired
|
||||
private ModelEvaluator modelEvaluationService;
|
||||
|
||||
@Autowired
|
||||
private NormalDeployService normalDeployService;
|
||||
|
||||
@Autowired
|
||||
private GrayDeployService grayDeployService;
|
||||
|
||||
@Autowired
|
||||
private ResourceAllocator resourceAllocator;
|
||||
|
||||
@Autowired
|
||||
private GpuResourceService gpuResourceService;
|
||||
|
||||
public DeployResponse deploy(DeployRequest request) {
|
||||
try {
|
||||
// 1. 获取完整模型信息
|
||||
ModelInfo modelInfo = getModelInfo(request.getModelId());
|
||||
|
||||
// 2. 更新请求中的模型信息
|
||||
request.setModelInfo(modelInfo);
|
||||
|
||||
// 3. 添加模型评估检查
|
||||
if (!isEvaluationPassed(modelInfo)) {
|
||||
return DeployResponse.fail(403,
|
||||
"模型[" + modelInfo.getModelName() + "]评估未通过,无法部署");
|
||||
}
|
||||
List<GpuResource> availableResources = gpuResourceService.getAvailableResources();
|
||||
int requiredMemory = request.getRequiredMemory();
|
||||
String modelId = request.getModelId();
|
||||
|
||||
if (!resourceAllocator.checkResourceQuota(availableResources, requiredMemory, modelId)){
|
||||
return DeployResponse.fail(507, "资源配额不足。需要内存: " + requiredMemory + "MB\n");
|
||||
}
|
||||
|
||||
// 4. 根据部署类型路由
|
||||
if (request.getDeployType() == DeployRequest.DeployType.NORMAL) {
|
||||
return normalDeployService.process(request);
|
||||
} else {
|
||||
return grayDeployService.process(request);
|
||||
}
|
||||
} catch (DeployException e) {
|
||||
return DeployResponse.fail(404, "获取模型信息失败: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return DeployResponse.fail(500, "部署失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从模型仓库获取模型详细信息
|
||||
*/
|
||||
private ModelInfo getModelInfo(String modelId) {
|
||||
// 添加缓存和重试机制
|
||||
ModelInfo modelInfo = modelRepositoryClient.getModelInfo(modelId);
|
||||
|
||||
// 验证关键字段
|
||||
if (modelInfo.getModelFilePath() == null) {
|
||||
throw new DeployException("模型文件路径未定义");
|
||||
}
|
||||
|
||||
// 获取额外信息
|
||||
modelInfo.setStorageLocation(
|
||||
modelRepositoryClient.getModelStorageLocation(modelId)
|
||||
);
|
||||
|
||||
return modelInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模型评估状态
|
||||
*/
|
||||
private boolean isEvaluationPassed(ModelInfo modelInfo) {
|
||||
return modelEvaluationService.isEvaluationPassed(
|
||||
modelInfo.getModelId()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ModelEvaluator {
|
||||
@Value("${model.evaluation.service-url}")
|
||||
private String evaluationServiceUrl;
|
||||
|
||||
@Value("${model.evaluation.api-timeout:3000}")
|
||||
private int apiTimeout;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
/**
|
||||
* 检查模型评估是否通过
|
||||
* @param modelId 模型ID
|
||||
* @return 评估是否通过
|
||||
*/
|
||||
public boolean isEvaluationPassed(String modelId) {
|
||||
return isEvaluationPassed(modelId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查模型评估是否通过(带版本号)
|
||||
* @param modelId 模型ID
|
||||
* @param version 模型版本
|
||||
* @return 评估是否通过
|
||||
*/
|
||||
public boolean isEvaluationPassed(String modelId, String version) {
|
||||
// 1. 构建API调用参数
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("modelId", modelId);
|
||||
if (version != null) {
|
||||
params.put("version", version);
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 设置请求头和超时
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("X-Request-ID", generateRequestId(modelId));
|
||||
|
||||
// 3. 调用评估API
|
||||
ResponseEntity<EvaluationResponse> response = restTemplate.exchange(
|
||||
buildEvaluationUrl(modelId, version),
|
||||
HttpMethod.GET,
|
||||
new HttpEntity<>(headers),
|
||||
EvaluationResponse.class
|
||||
);
|
||||
|
||||
// 4. 处理响应
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
||||
return response.getBody().isPassed();
|
||||
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
logEvaluationWarning(modelId, "模型未找到");
|
||||
} else {
|
||||
logEvaluationError(modelId, "评估服务返回非200状态: " + response.getStatusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logEvaluationError(modelId, "评估服务调用失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
// 5. 默认返回失败
|
||||
return false;
|
||||
}
|
||||
|
||||
// ================= 辅助方法 =================
|
||||
|
||||
/**
|
||||
* 构建评估API URL
|
||||
*/
|
||||
private String buildEvaluationUrl(String modelId, String version) {
|
||||
String baseUrl = evaluationServiceUrl + "/models/" + modelId + "/evaluation";
|
||||
return version != null ? baseUrl + "?version=" + version : baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求ID(用于日志追踪)
|
||||
*/
|
||||
private String generateRequestId(String modelId) {
|
||||
return "eval-" + modelId + "-" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录评估错误日志
|
||||
*/
|
||||
private void logEvaluationError(String modelId, String message) {
|
||||
// 实际实现应使用日志框架(如SLF4J)
|
||||
System.err.println("[" + modelId + "] 评估错误: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录评估警告日志
|
||||
*/
|
||||
private void logEvaluationWarning(String modelId, String message) {
|
||||
// 实际实现应使用日志框架
|
||||
System.out.println("[" + modelId + "] 评估警告: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评估响应内部类
|
||||
*/
|
||||
private static class EvaluationResponse {
|
||||
private boolean passed;
|
||||
private String reason;
|
||||
private String evaluatedAt;
|
||||
|
||||
// 需要默认构造方法用于JSON反序列化
|
||||
public EvaluationResponse() {}
|
||||
|
||||
public boolean isPassed() {
|
||||
return passed;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String getEvaluatedAt() {
|
||||
return evaluatedAt;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.DeployException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
@Component
|
||||
public class ModelRepositoryClient {
|
||||
|
||||
@Value("${model.repository.url}")
|
||||
private String repositoryBaseUrl;
|
||||
|
||||
@Value("${model.repository.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
/**
|
||||
* 从模型仓库获取模型信息
|
||||
*
|
||||
* @param modelId 模型唯一标识
|
||||
* @return 完整的模型信息对象
|
||||
*/
|
||||
public ModelInfo getModelInfo(String modelId) {
|
||||
// 1. 构建请求URL
|
||||
String url = repositoryBaseUrl + "/models/" + modelId + "/info";
|
||||
|
||||
// 2. 设置认证头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("X-API-KEY", apiKey);
|
||||
headers.set("Model-Id", modelId);
|
||||
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
|
||||
try {
|
||||
// 3. 发送请求到模型仓库服务
|
||||
ResponseEntity<ModelInfo> response = restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
ModelInfo.class
|
||||
);
|
||||
|
||||
// 4. 处理响应
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
||||
return response.getBody();
|
||||
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
throw new DeployException("模型未找到: " + modelId);
|
||||
} else {
|
||||
throw new DeployException("获取模型信息失败,状态码: " + response.getStatusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DeployException("访问模型仓库失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
public String getModelStorageLocation(String modelId) {
|
||||
// 1. 构建请求URL
|
||||
String url = repositoryBaseUrl + "/models/" + modelId + "/storage-location";
|
||||
|
||||
// 2. 设置认证头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("X-API-KEY", apiKey);
|
||||
headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
|
||||
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
|
||||
try {
|
||||
// 3. 发送请求到模型仓库服务
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
String.class
|
||||
);
|
||||
|
||||
// 4. 处理响应
|
||||
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
||||
return response.getBody();
|
||||
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||||
throw new DeployException("模型存储位置未找到: " + modelId);
|
||||
} else {
|
||||
throw new DeployException("获取存储位置失败,状态码: " + response.getStatusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DeployException("访问模型仓库失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ModelService {
|
||||
void createModel(ModelDTO dto);
|
||||
|
||||
void createModelVersion(ModelDTO dto);
|
||||
|
||||
List<ModelVO> list();
|
||||
|
||||
ModelVersion detail(Long id);
|
||||
|
||||
void updateModel(ModelVersionDTO dto);
|
||||
|
||||
void deleteModelVersion(Long id);
|
||||
|
||||
void updateLifeCycle(Long id, String lifeCycle);
|
||||
|
||||
List<Map<String, String>> listLifeCycle();
|
||||
|
||||
List<DatasetEntity> listDataset();
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.exception.EvaluationFailedException;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.util.TemplateParser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@Service
|
||||
public class NormalDeployService {
|
||||
@Autowired
|
||||
private ModelEvaluator modelEvaluator;
|
||||
|
||||
@Autowired
|
||||
private ResourceAllocator resourceAllocator;
|
||||
|
||||
@Autowired
|
||||
private GpuResourceService gpuService;
|
||||
|
||||
@Autowired
|
||||
private TemplateParser templateParser; // 使用模板解析器
|
||||
|
||||
@Value("${model.deploy.script-directory:/opt/deploy_scripts}")
|
||||
private String scriptDirectory;
|
||||
|
||||
@Value("${model.deploy.script-timeout:300}")
|
||||
private int scriptTimeout;
|
||||
|
||||
public DeployResponse process(DeployRequest request) {
|
||||
try {
|
||||
// 1. 检查模型评估状态(使用ModelInfo包含的模型ID)
|
||||
ModelInfo modelInfo = request.getModelInfo();
|
||||
if (!modelEvaluator.isEvaluationPassed(modelInfo != null ? modelInfo.getModelName() : "")) {
|
||||
throw new EvaluationFailedException("模型评估未通过");
|
||||
}
|
||||
|
||||
// 2. 分配资源并获取URL
|
||||
DeploymentResource resource = resourceAllocator.allocate(
|
||||
gpuService.getAvailableResources(),
|
||||
request.getRequiredMemory(),
|
||||
modelInfo != null ? modelInfo.getModelName() : "unknown",
|
||||
false
|
||||
);
|
||||
|
||||
// 3. 使用ModelInfo生成部署脚本内容
|
||||
String scriptContent = templateParser.generateDeploymentScript(
|
||||
request.getModelInfo(),
|
||||
resource.getUrl()
|
||||
);
|
||||
|
||||
// 4. 执行部署脚本
|
||||
executeDeploymentScript(scriptContent);
|
||||
|
||||
// 5. 标记资源已分配
|
||||
gpuService.markAsAllocated(
|
||||
resource.getGpu().getGPUId(),
|
||||
request.getRequiredMemory()
|
||||
);
|
||||
|
||||
return DeployResponse.success(resource.getUrl());
|
||||
|
||||
} catch (EvaluationFailedException e) {
|
||||
return DeployResponse.fail(403, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return DeployResponse.fail(500, "部署失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行部署脚本
|
||||
*/
|
||||
private void executeDeploymentScript(String scriptContent) throws Exception {
|
||||
// 创建脚本文件
|
||||
Path scriptPath = Paths.get(scriptDirectory, "deploy_" + System.currentTimeMillis() + ".sh");
|
||||
Files.write(scriptPath, scriptContent.getBytes());
|
||||
|
||||
// 设置执行权限 (754)
|
||||
Set<PosixFilePermission> permissions = Set.of(
|
||||
PosixFilePermission.OWNER_READ,
|
||||
PosixFilePermission.OWNER_WRITE,
|
||||
PosixFilePermission.OWNER_EXECUTE,
|
||||
PosixFilePermission.GROUP_READ,
|
||||
PosixFilePermission.GROUP_EXECUTE,
|
||||
PosixFilePermission.OTHERS_READ
|
||||
);
|
||||
Files.setPosixFilePermissions(scriptPath, permissions);
|
||||
|
||||
// 执行脚本
|
||||
Process process = new ProcessBuilder(scriptPath.toString())
|
||||
.directory(Paths.get(scriptDirectory).toFile())
|
||||
.start();
|
||||
|
||||
// 带超时等待
|
||||
boolean completed = process.waitFor(scriptTimeout, TimeUnit.SECONDS);
|
||||
if (!completed) {
|
||||
process.destroyForcibly();
|
||||
throw new RuntimeException("脚本执行超时(限制: " + scriptTimeout + "秒)");
|
||||
}
|
||||
|
||||
// 检查退出码
|
||||
if (process.exitValue() != 0) {
|
||||
throw new RuntimeException("脚本执行失败,退出码: " + process.exitValue());
|
||||
}
|
||||
|
||||
// 清理脚本文件
|
||||
Files.deleteIfExists(scriptPath);
|
||||
}
|
||||
}
|
@ -9,5 +9,4 @@ public interface PublishService {
|
||||
|
||||
|
||||
|
||||
String getByModelId(Long modelId);
|
||||
}
|
||||
|
@ -0,0 +1,152 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import org.apache.ibatis.cache.CacheException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class RedisCacheService {
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Value("${cache.redis-key-prefix:gpu:}")
|
||||
private String keyPrefix;
|
||||
|
||||
@Value("${cache.ttl-base:7200}")
|
||||
private int baseTTL;
|
||||
private final RedisSerializer<Object> valueSerializer;
|
||||
|
||||
// @Autowired
|
||||
// public RedisCacheService(RedisTemplate<String, Object> redisTemplate) {
|
||||
// this.redisTemplate = redisTemplate;
|
||||
// }
|
||||
|
||||
// 核心方法 ------------------------------------------------------------
|
||||
@Autowired
|
||||
public RedisCacheService(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.valueSerializer = (RedisSerializer<Object>) redisTemplate.getValueSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入GPU资源数据(带管道优化)
|
||||
* @param resources GPU资源列表
|
||||
*/
|
||||
public void batchPut(List<GpuResource> resources) {
|
||||
redisTemplate.executePipelined((RedisCallback<Object>) connection -> {
|
||||
resources.forEach(resource -> {
|
||||
String key = buildKey(resource.getGPUId().toString());
|
||||
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] valueBytes = valueSerializer.serialize(resource);
|
||||
connection.stringCommands().setEx(
|
||||
keyBytes,
|
||||
calculateTTL(),
|
||||
valueBytes
|
||||
);
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单条缓存(含随机TTL防雪崩)
|
||||
* @param gpuId 资源ID
|
||||
* @param resource 资源对象
|
||||
*/
|
||||
public void put(String gpuId, GpuResource resource) {
|
||||
String key = buildKey(gpuId);
|
||||
redisTemplate.opsForValue().set(
|
||||
key,
|
||||
resource,
|
||||
calculateTTL(),
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个缓存项
|
||||
* @param gpuId 资源ID
|
||||
* @return 缓存对象或null
|
||||
*/
|
||||
public GpuResource get(String gpuId) {
|
||||
return (GpuResource) redisTemplate.opsForValue().get(buildKey(gpuId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定缓存
|
||||
* @param gpuId 资源ID
|
||||
*/
|
||||
public void delete(Long gpuId) {
|
||||
redisTemplate.delete(buildKey(gpuId.toString()));
|
||||
}
|
||||
|
||||
// 辅助方法 ------------------------------------------------------------
|
||||
|
||||
private String buildKey(String gpuId) {
|
||||
return keyPrefix + gpuId;
|
||||
}
|
||||
|
||||
private long calculateTTL() {
|
||||
return baseTTL + (long)(Math.random() * 600); // 7200-7800秒随机值
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除缓存(事务处理)
|
||||
* @param gpuIds 资源ID列表
|
||||
*/
|
||||
public void batchDelete(List<String> gpuIds) {
|
||||
redisTemplate.execute((RedisCallback<Object>) connection -> {
|
||||
connection.multi();
|
||||
gpuIds.forEach(id -> connection.del(buildKey(id).getBytes()));
|
||||
connection.exec();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存健康检查
|
||||
* @return 是否连通
|
||||
*/
|
||||
public boolean healthCheck() {
|
||||
try {
|
||||
return "PONG".equals(Objects.requireNonNull(redisTemplate.getConnectionFactory())
|
||||
.getConnection().ping());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Set<String> scanKeys(String pattern) {
|
||||
try (RedisConnection connection = Objects.requireNonNull(
|
||||
redisTemplate.getConnectionFactory()).getConnection()) {
|
||||
|
||||
ScanOptions options = ScanOptions.scanOptions()
|
||||
.match(pattern)
|
||||
.count(100) // 批量扫描数量
|
||||
.build();
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
Cursor<byte[]> cursor = connection.scan(options);
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
keys.add(new String(cursor.next(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
return keys;
|
||||
} catch (Exception e) {
|
||||
throw new CacheException("Keys scan failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.constant.ConfigConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ResourceAllocator {
|
||||
|
||||
@Autowired
|
||||
private ConfigConstants config;
|
||||
|
||||
// 检查资源配额
|
||||
public boolean checkResourceQuota(List<GpuResource> resources, int requiredMemory, String modelId) {
|
||||
// 1. 检查全局资源是否充足
|
||||
long totalFreeMemory = resources.stream()
|
||||
.mapToInt(this::getRemainingMemory)
|
||||
.sum();
|
||||
|
||||
// 全局内存不足
|
||||
if (totalFreeMemory < requiredMemory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 检查单个GPU是否能满足需求
|
||||
boolean canAllocate = resources.stream()
|
||||
.anyMatch(gpu -> getRemainingMemory(gpu) >= requiredMemory);
|
||||
|
||||
if (!canAllocate) {
|
||||
// 检查碎片化分配
|
||||
return checkFragmentationAllocation(resources, requiredMemory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查碎片化分配可能性
|
||||
private boolean checkFragmentationAllocation(List<GpuResource> resources, int requiredMemory) {
|
||||
// 按碎片率排序(碎片小的优先)
|
||||
resources.sort(Comparator.comparingDouble(
|
||||
r -> (double)getRemainingMemory(r) / r.getGPUMaxMemory()
|
||||
));
|
||||
|
||||
// 检查碎片整合后是否可能满足需求
|
||||
int accumulatedMemory = 0;
|
||||
for (GpuResource gpu : resources) {
|
||||
int fragment = getRemainingMemory(gpu);
|
||||
// 如果单个碎片就足够,直接返回成功
|
||||
if (fragment >= requiredMemory) return true;
|
||||
|
||||
// 累积碎片
|
||||
accumulatedMemory += fragment;
|
||||
if (accumulatedMemory >= requiredMemory) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取剩余内存
|
||||
private int getRemainingMemory(GpuResource resource){
|
||||
return resource.getGPUMaxMemory()-resource.getGPUMemorySize();
|
||||
}
|
||||
|
||||
public DeploymentResource allocate(
|
||||
List<GpuResource> resources,
|
||||
int requiredMemory,
|
||||
String modelId,
|
||||
boolean isGray
|
||||
){
|
||||
resources.sort(Comparator.comparingInt(GpuResource::getGPUMemorySize));
|
||||
|
||||
//第一轮分配
|
||||
for(GpuResource resource:resources){
|
||||
if(getRemainingMemory(resource) >= requiredMemory) {
|
||||
return createResource(resource, modelId, isGray);
|
||||
}
|
||||
}
|
||||
|
||||
//第二轮分配
|
||||
return defragmentation(resources,requiredMemory, modelId, isGray);
|
||||
}
|
||||
|
||||
|
||||
private DeploymentResource defragmentation(
|
||||
List<GpuResource> resources,
|
||||
int requiredMemory,
|
||||
String modelId,
|
||||
boolean isGray
|
||||
){
|
||||
//按内存碎片大小排序(最小碎片优先)
|
||||
resources.sort(Comparator.comparingDouble(
|
||||
r -> (double)getRemainingMemory(r) / r.getGPUMaxMemory()));
|
||||
|
||||
for(GpuResource resource:resources){
|
||||
if(getRemainingMemory(resource) >= requiredMemory){
|
||||
return createResource(resource, modelId, isGray);
|
||||
}
|
||||
}
|
||||
throw new ResourceAccessException("GPU资源不足");
|
||||
}
|
||||
|
||||
private DeploymentResource createResource(GpuResource gpu, String modelId, boolean isGray){
|
||||
String urlType = isGray ? "gray":"prod";
|
||||
String url = String.format(
|
||||
config.URL_TEMPLATE,
|
||||
gpu.getIp(),
|
||||
config.MODEL_PORT,
|
||||
modelId,
|
||||
urlType
|
||||
);
|
||||
return new DeploymentResource(gpu, url);
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
public interface ServiceAPIService {
|
||||
String getByModelId(Long modelId);
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuEntityTransfer;
|
||||
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 com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class GpuManageServiceImpl implements GpuManageService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(GpuManageServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private GpuResourceDao gpuDao;
|
||||
|
||||
@Autowired
|
||||
private GpuEntityTransfer gpuEntityTransfer;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResponseVO createGpuResource(GpuCreateDTO dto) {
|
||||
try {
|
||||
logger.info("创建GPU资源请求: {}", dto);
|
||||
|
||||
GpuResource entity = gpuEntityTransfer.toEntity(dto);
|
||||
gpuDao.insert(entity);
|
||||
|
||||
logger.info("创建GPU资源成功, ID: {}", entity.getGPUId());
|
||||
return ResponseVO.success(entity);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("创建GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
|
||||
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResponseVO deleteGpuResource(Long gpuId) {
|
||||
logger.info("删除GPU资源请求, ID: {}", gpuId);
|
||||
|
||||
try {
|
||||
GpuResource entity = gpuDao.selectById(gpuId);
|
||||
if (entity == null) {
|
||||
logger.warn("GPU资源不存在, ID: {}", gpuId);
|
||||
return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND);
|
||||
}
|
||||
|
||||
gpuDao.isDeleted(gpuId);
|
||||
logger.info("逻辑删除GPU资源成功, ID: {}", gpuId);
|
||||
return ResponseVO.success();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("删除GPU资源失败, ID: {}, 错误: {}", gpuId, e.getMessage(), e);
|
||||
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateGpuResource(GpuUpdateDTO dto) {
|
||||
logger.info("更新GPU资源请求: {}", dto);
|
||||
|
||||
try {
|
||||
GpuResource entity = gpuEntityTransfer.toEntity(dto);
|
||||
gpuDao.updateById(entity);
|
||||
logger.info("更新GPU资源成功, ID: {}", entity.getGPUId());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("更新GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
|
||||
throw new RuntimeException("更新GPU资源失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if(model != null) params.put("model", "%" + model + "%");
|
||||
if(memorySize != null) params.put("memorySize", memorySize);
|
||||
if(ip != null) params.put("ip", ip);
|
||||
|
||||
logger.info("查询GPU资源条件: {}", params);
|
||||
|
||||
try {
|
||||
List<GpuResource> entities = gpuDao.selectByFields(params);
|
||||
logger.info("查询到 {} 条GPU资源", entities.size());
|
||||
|
||||
return entities.stream()
|
||||
.map(gpuEntityTransfer::toDTO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("查询GPU资源失败, 条件: {}, 错误: {}", params, e.getMessage(), e);
|
||||
throw new RuntimeException("查询GPU资源失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 新增的日志追踪方法 ==========
|
||||
|
||||
private void logOperation(String methodName, Object... details) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
StringBuilder logBuilder = new StringBuilder(methodName);
|
||||
for (Object detail : details) {
|
||||
logBuilder.append(" | ").append(detail);
|
||||
}
|
||||
logger.debug(logBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void logDuration(String methodName, long startTime, boolean success) {
|
||||
long duration = System.currentTimeMillis() - startTime;
|
||||
String status = success ? "成功" : "失败";
|
||||
logger.info("方法 {} 执行{} | 耗时: {}ms", methodName, status, duration);
|
||||
}
|
||||
|
||||
// ========== 增强的日志版本 ==========
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public ResponseVO createGpuResourceWithTrace(GpuCreateDTO dto) {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
logOperation("createGpuResource", "请求参数", dto);
|
||||
|
||||
ResponseVO result = createGpuResource(dto);
|
||||
|
||||
logDuration("createGpuResource", start, true);
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
logDuration("createGpuResource", start, false);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.util;
|
||||
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class NacosServiceUtil {
|
||||
|
||||
@Value("${spring.cloud.nacos.discovery.server-addr}")
|
||||
private String nacosServerAddr;
|
||||
|
||||
public void registerService(String serviceName, String ip, int port, String url) throws Exception { // 新增url参数
|
||||
NamingService naming = NamingFactory.createNamingService(nacosServerAddr);
|
||||
Instance instance = new Instance();
|
||||
instance.setIp(ip);
|
||||
instance.setPort(port);
|
||||
// 添加元数据存储URL
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("url", url); // 将URL存入元数据
|
||||
instance.setMetadata(metadata);
|
||||
naming.registerInstance(serviceName, instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务所有实例IP
|
||||
*/
|
||||
public List<String> getServiceInstances(String serviceName) throws Exception {
|
||||
NamingService naming = NamingFactory.createNamingService(nacosServerAddr);
|
||||
List<Instance> instances = naming.getAllInstances(serviceName);
|
||||
return instances.stream()
|
||||
.map(Instance::getIp)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.util;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class TemplateParser {
|
||||
// 使用静态模板避免硬编码(可根据需要扩展为读取外部配置文件)
|
||||
private static final Map<String, String> DEPLOYMENT_TEMPLATES = new HashMap<>() {{
|
||||
put("tensorflow", "#!/bin/bash\n"
|
||||
+ "# TensorFlow Serving Deployment\n"
|
||||
+ "docker run -d --name {0}-service \\\n"
|
||||
+ " -p {1} \\\n"
|
||||
+ " -v {2}:/models/{0} \\\n"
|
||||
+ " -e MODEL_NAME={0} \\\n"
|
||||
+ " tensorflow/serving:latest\n"
|
||||
+ "# Preprocessing\n"
|
||||
+ "{3} $1");
|
||||
|
||||
put("pytorch", "#!/bin/bash\n"
|
||||
+ "# TorchServe Deployment\n"
|
||||
+ "torch-model-archiver --model-name {0} \\\n"
|
||||
+ " --version 1.0 \\\n"
|
||||
+ " --serialized-file {2} \\\n"
|
||||
+ " --handler {3} \\\n"
|
||||
+ " --export-path model_store\n"
|
||||
+ "torchserve --start \\\n"
|
||||
+ " --model-store model_store \\\n"
|
||||
+ " --models {0}.mar \\\n"
|
||||
+ " --ncs \\\n"
|
||||
+ " --ts-config config.properties");
|
||||
}};
|
||||
|
||||
public String generateDeploymentScript(ModelInfo modelInfo, String endpointUrl) {
|
||||
// 提取URL端口号 (假设URL格式为 http://host:port)
|
||||
String port = extractPortFromUrl(endpointUrl);
|
||||
|
||||
// 获取基础模板
|
||||
String template = DEPLOYMENT_TEMPLATES.getOrDefault(
|
||||
modelInfo.getModelType().toLowerCase(),
|
||||
getDefaultTemplate()
|
||||
);
|
||||
|
||||
// 安全处理空值
|
||||
String safeModelName = modelInfo.getModelName() != null ? modelInfo.getModelName() : "unnamed";
|
||||
String safeFilePath = modelInfo.getModelFilePath() != null ? modelInfo.getModelFilePath() : "";
|
||||
String safeScript = modelInfo.getPreprocessScript() != null ? modelInfo.getPreprocessScript() : "echo 'No preprocessing'";
|
||||
|
||||
// 填充模板参数
|
||||
return MessageFormat.format(template,
|
||||
safeModelName,
|
||||
port,
|
||||
safeFilePath,
|
||||
safeScript
|
||||
);
|
||||
}
|
||||
private String extractPortFromUrl(String url) {
|
||||
if (url == null) return "8080"; // 默认端口
|
||||
try {
|
||||
return url.split(":")[2].replaceAll("[^0-9]", "");
|
||||
} catch (Exception e) {
|
||||
return "8080";
|
||||
}
|
||||
}
|
||||
|
||||
private String getDefaultTemplate() {
|
||||
return "#!/bin/bash\n"
|
||||
+ "# Universal Deployment Template\n"
|
||||
+ "echo \"Deploying model: {0} at endpoint {1}\"\n"
|
||||
+ "echo \"Model path: {2}\"\n"
|
||||
+ "echo \"Running preprocessing: {3}\"\n"
|
||||
+ "# Add custom deployment logic here";
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
spring.application.name=intelligent-application-orchestration-service
|
||||
|
||||
|
||||
# 数据库配置
|
||||
# ?????
|
||||
spring.datasource.url=jdbc:kingbase8://116.205.121.200:54321/Ipz
|
||||
spring.datasource.username=system
|
||||
spring.datasource.password=root
|
||||
@ -9,21 +9,40 @@ spring.datasource.driver-class-name=com.kingbase8.Driver
|
||||
spring.datasource.hikari.maximum-pool-size=10
|
||||
spring.datasource.hikari.minimum-idle=5
|
||||
spring.datasource.hikari.connection-timeout=30000
|
||||
spring.mvc.contentnegotiation.default-content-type=application/json
|
||||
|
||||
# SQL映射文件路径配置
|
||||
# MyBatis??
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
# 配置实体类别名所在包
|
||||
mybatis.type-aliases-package=com.bipt.intelligentapplicationorchestrationservice.pojo
|
||||
# 开启驼峰命名转换
|
||||
mybatis.configuration.map-underscore-to-camel-case=true
|
||||
|
||||
# Redis服务器地址
|
||||
# Redis??
|
||||
#spring.data.redis.host=127.0.0.1
|
||||
#spring.data.redis.port=6379
|
||||
spring.data.redis.host=116.205.121.200
|
||||
# Redis服务器端口
|
||||
spring.data.redis.port=6379
|
||||
# Redis密码(如果有)
|
||||
spring.data.redis.username=default
|
||||
spring.data.redis.password=Jbjhhzstsl97@
|
||||
# Redis数据库索引(默认为0)
|
||||
spring.data.redis.database = 0
|
||||
# 连接超时时间(毫秒)
|
||||
spring.data.redis.timeout = 3000
|
||||
spring.data.redis.database=0
|
||||
spring.data.redis.timeout=3000
|
||||
spring.data.redis.ssl.enabled=false
|
||||
|
||||
# ??????
|
||||
spring.cloud.gateway.routes[0].id=request-service-route
|
||||
spring.cloud.gateway.routes[0].uri=lb://intelligent-application-orchestration-service
|
||||
spring.cloud.gateway.routes[0].predicates[0]=Path=/request
|
||||
|
||||
|
||||
logging.level.org.springframework.web=DEBUG
|
||||
|
||||
# ????????
|
||||
model.evaluation.service-url=http://evaluation-service:8080/api/v1
|
||||
model.evaluation.api-timeout=3000
|
||||
# ????????
|
||||
model.repository.url=https://model-repo.example.com/api/v1
|
||||
model.repository.api-key=SECURE_API_KEY_12345
|
||||
model.repository.timeout=5000
|
||||
|
||||
#SQL ????????
|
||||
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
10
src/main/resources/bootstrap.properties
Normal file
10
src/main/resources/bootstrap.properties
Normal file
@ -0,0 +1,10 @@
|
||||
# 应用名称(必须与Nacos配置的dataId前缀一致)
|
||||
spring.application.name=intelligent-application-orchestration-service
|
||||
|
||||
# Nacos配置中心地址(引导阶段加载配置)
|
||||
spring.cloud.nacos.config.server-addr=113.44.217.169:8848
|
||||
spring.cloud.nacos.config.data-id=${spring.application.name}.properties
|
||||
spring.cloud.nacos.config.group=DEFAULT_GROUP
|
||||
|
||||
# Nacos服务注册地址(引导阶段注册服务)
|
||||
spring.cloud.nacos.discovery.server-addr=113.44.217.169:8848
|
@ -2,7 +2,7 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.EvaluationMapper">
|
||||
<!--查询模型日志详细信息-->
|
||||
<select id="selectLogDetail" resultType="modelLogVO">
|
||||
<select id="selectLogDetail" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelLogVO">
|
||||
select m1.*,
|
||||
m2.model_name,
|
||||
m3.model_config, m3.version
|
||||
|
66
src/main/resources/mapper/GpuResourceMapper.xml
Normal file
66
src/main/resources/mapper/GpuResourceMapper.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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"
|
||||
resultMap="gpuResourceMap">
|
||||
SELECT *
|
||||
FROM Ipz.public.gpu_resource
|
||||
<where>
|
||||
is_deleted = 0
|
||||
<if test="params.model != null and params.model != ''">
|
||||
AND GPUModel LIKE CONCAT('%', #{params.model}, '%')
|
||||
</if>
|
||||
<if test="params.memoryMin != null">
|
||||
AND GPUMemorySize >= #{params.memoryMin}
|
||||
</if>
|
||||
<if test="params.ip != null and params.ip != ''">
|
||||
AND Ip = #{params.ip}
|
||||
</if>
|
||||
<if test="params.startTime != null and params.endTime != null">
|
||||
AND update_time BETWEEN #{params.startTime} AND #{params.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY GPUId DESC
|
||||
</select>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="findByPage"
|
||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
||||
SELECT *
|
||||
FROM gpu_resource
|
||||
WHERE is_deleted = 0
|
||||
ORDER BY GPUId ASC
|
||||
LIMIT #{limit} OFFSET #{offset}
|
||||
</select>
|
||||
|
||||
<!-- 增量同步查询 -->
|
||||
<select id="findModifiedSince"
|
||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
||||
SELECT *, is_deleted
|
||||
FROM gpu_resource
|
||||
WHERE update_time > #{since}
|
||||
ORDER BY update_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 带锁查询 -->
|
||||
<select id="selectByIdWithLock"
|
||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
|
||||
SELECT *
|
||||
FROM gpu_resource
|
||||
WHERE GPUId = #{gpuId}
|
||||
FOR UPDATE NOWAIT
|
||||
</select>
|
||||
|
||||
</mapper>
|
59
src/main/resources/mapper/ModelMapper.xml
Normal file
59
src/main/resources/mapper/ModelMapper.xml
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper">
|
||||
|
||||
<!--(新增新的模型)插入模型版本信息-->
|
||||
<insert id="insertModelVersion">
|
||||
insert into model_version (
|
||||
model_id, version, dataset_id, model_config,
|
||||
model_path, status, create_time, update_time, model_size,
|
||||
data_pre_handle_file, model_super_args, model_args_size, model_source_code_url, model_file,
|
||||
model_design_document, life_cycle, operate_user
|
||||
)
|
||||
values (
|
||||
#{modelId}, #{version}, #{datasetId}, #{modelConfig},
|
||||
#{modelPath}, #{status}, #{createTime}, #{updateTime}, #{modelSize},
|
||||
#{dataPreHandleFile}, #{modelSuperArgs}, #{modelArgsSize}, #{modelSourceCodeUrl}, #{modelFile},
|
||||
#{modelDesignDocument}, #{lifeCycle}, #{operateUser}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!--查询模型列表-->
|
||||
<select id="list" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO">
|
||||
select t1.*,
|
||||
t2.id as versionId,t2.version, t2.version, t2.data_pre_handle_file, t2.operate_user, t2.update_time,
|
||||
t2.status
|
||||
from model_info t1
|
||||
left join model_version t2 on t1.id = t2.model_id
|
||||
order by t2.update_time desc
|
||||
</select>
|
||||
|
||||
<!--查询模型详细信息-->
|
||||
<select id="selectById" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion">
|
||||
SELECT
|
||||
t1.model_name,
|
||||
t2.version, t2.dataset_id, t2.model_config,
|
||||
t2.model_path, t2.status, t2.create_time, t2.update_time, t2.model_size,
|
||||
t2.data_pre_handle_file, t2.model_super_args, t2.model_args_size, t2.model_source_code_url, t2.model_file,
|
||||
t2.model_design_document, t2.life_cycle, t2.operate_user
|
||||
FROM model_info t1 JOIN model_version t2 ON t1.id = t2.model_id
|
||||
where t2.id = #{id}
|
||||
</select>
|
||||
|
||||
<!--更新模型信息-->
|
||||
<update id="update">
|
||||
UPDATE model_version
|
||||
<set>
|
||||
<if test="modelSize != null">
|
||||
model_size = #{modelSize},
|
||||
</if>
|
||||
<if test="modelSuperArgs != null">
|
||||
model_super_args = #{modelSuperArgs},
|
||||
</if>
|
||||
<if test="modelArgsSize != null">
|
||||
model_args_size = #{modelArgsSize},
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id
|
||||
</update>
|
||||
</mapper>
|
Reference in New Issue
Block a user