Compare commits
39 Commits
c24d640de4
...
main
Author | SHA1 | Date | |
---|---|---|---|
957c5bc3e1 | |||
09424cf223 | |||
d11aaccb1e | |||
46331fcade | |||
99c291ca09 | |||
b926506ede | |||
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 | |||
2aaf3d96f0 | |||
77fb43e95d | |||
5692cca3e7 | |||
60a71a121c | |||
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请求调度缓存更新类
|
@ -90,17 +90,17 @@ redis的服务器配置
|
||||
### 📅 明日计划
|
||||
完成拦截器功能
|
||||
|
||||
## 2025年5月26日
|
||||
## 2025年5月25日
|
||||
### ✅ 今日完成
|
||||
服务调度
|
||||
服务发布可注册到nacos上
|
||||
|
||||
### 🚧 进行中
|
||||
无
|
||||
拦截器开发
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
暂无
|
||||
模型api请求不知道是什么
|
||||
|
||||
### 📅 明日计划
|
||||
已完成
|
||||
开发拦截器功能
|
||||
|
||||
|
||||
|
@ -105,4 +105,74 @@
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发
|
||||
- 模型信息管理前端页面开发
|
||||
|
||||
## 2025年5月26日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
## 2025年5月27日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
## 2025年5月28日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
## 2025年5月29日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
## 2025年5月30日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 增加了查询数据集列表和生命周期列表接口
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型信息管理前端页面开发与后端联调
|
60
doc/WorkReport/2025-06-nh .md
Normal file
60
doc/WorkReport/2025-06-nh .md
Normal file
@ -0,0 +1,60 @@
|
||||
# 工作日报 - 2025年5月
|
||||
## 2025年6月3日
|
||||
### ✅ 今日完成
|
||||
- 优化模型构建表单
|
||||
|
||||
### 🚧 进行中
|
||||
- 优化模型构建表单
|
||||
|
||||
### 📅 明日计划
|
||||
- 优化模型构建表单
|
||||
|
||||
## 2025年6月4日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
* 阿里云OSS文件上传后端接口开发
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
* 阿里云OSS文件上传后端接口开发(存在问题)
|
||||
* 模型管理前端页面开发
|
||||
|
||||
### ⚠️ 问题/障碍
|
||||
|
||||
- Spring MVC依赖被注释,和gateway冲突了,已经发现了问题
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
* 继续完善阿里云OSS文件上传后端接口开发,保证接口测试成功
|
||||
* 模型管理前端页面开发
|
||||
|
||||
## 2025年6月5日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 阿里云OSS文件上传后端接口开发调试成功
|
||||
- 基本完成了创建模型和修改模型的前后端联调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型管理前端页面开发
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型管理前端页面开发
|
||||
|
||||
## 2025年6月6日
|
||||
|
||||
### ✅ 今日完成
|
||||
|
||||
- 基本完成了版本构建、修改生命周期、上下线、模型评估和详情功能
|
||||
- 修改了模型评估和生命周期更新的一些细节,便于和前端接口协调
|
||||
|
||||
### 🚧 进行中
|
||||
|
||||
- 模型管理页面前端细节优化
|
||||
|
||||
### 📅 明日计划
|
||||
|
||||
- 模型管理页面前端细节优化
|
125
pom.xml
125
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>
|
||||
<!-- 添加 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,56 @@
|
||||
<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>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@ -90,6 +121,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,6 +173,9 @@
|
||||
<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>
|
||||
@ -121,5 +199,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
@ -4,11 +4,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
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
|
||||
@EnableDiscoveryClient
|
||||
@Slf4j
|
||||
public class IntelligentApplicationOrchestrationServiceApplication {
|
||||
|
||||
|
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.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.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,97 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.config;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
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 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 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(){
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
|
||||
log.info("开始创建redis模板对象...");
|
||||
//RedisTemplate redisTemplate = new RedisTemplate();
|
||||
//设置redis的连接工厂对象
|
||||
//redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
//设置redis key的序列化器
|
||||
//redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
//RedisTemplate<String, GpuResource> template = new RedisTemplate<>();
|
||||
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/");
|
||||
// }
|
||||
}
|
@ -1,20 +1,33 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name ="算法创建相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/algorithm")
|
||||
@Slf4j
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class AlgorithmInfoController {
|
||||
|
||||
@Autowired
|
||||
private AlgorithmInfoService algorithmInfoService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) {
|
||||
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
|
||||
@ -57,4 +70,52 @@ public class AlgorithmInfoController {
|
||||
ResponseEntity.ok("Delete successful") :
|
||||
ResponseEntity.badRequest().body("Delete failed");
|
||||
}
|
||||
|
||||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary ="算法创建")
|
||||
public OptResult save(@RequestParam("algorithm") String algorithmJson,
|
||||
@RequestPart(value = "algorithmFile") MultipartFile file) {
|
||||
try {
|
||||
AlgorithmInfo algorithmInfo = objectMapper.readValue(algorithmJson, AlgorithmInfo.class);
|
||||
log.info("新增算法: {}, 文件: {}", algorithmInfo, (file != null ? file.getOriginalFilename() : "无文件"));
|
||||
algorithmInfoService.save(algorithmInfo, file);
|
||||
return OptResult.success("算法创建成功");
|
||||
} catch (IOException e) {
|
||||
log.error("JSON转换失败", e);
|
||||
return OptResult.error("新增算法失败: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("新增算法失败", e);
|
||||
return OptResult.error("新增算法失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据算法名称模糊查询算法信息
|
||||
* @param keyword 模糊查询关键词
|
||||
* @return 符合条件的算法信息列表
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<AlgorithmInfo>> searchByName(@RequestParam String keyword) {
|
||||
List<AlgorithmInfo> algorithmInfos = algorithmInfoService.getByNameLike(keyword);
|
||||
return ResponseEntity.ok(algorithmInfos);
|
||||
}
|
||||
/**
|
||||
* 算法运行
|
||||
*/
|
||||
@PostMapping("/run/{id}")
|
||||
@Operation(summary = "运行")
|
||||
public OptResult run(@PathVariable Long id,@RequestBody String param){
|
||||
log.info("运行",id);
|
||||
String result = algorithmInfoService.run(id,param);
|
||||
return OptResult.success("运行成功"+result);
|
||||
}
|
||||
/**
|
||||
* 前端列表返回算法名称
|
||||
*/
|
||||
@GetMapping("/names")
|
||||
@Operation(summary = "列表返回算法名称")
|
||||
public List<String> getNames(){
|
||||
return algorithmInfoService.getAllNames();
|
||||
}
|
||||
|
||||
}
|
@ -6,28 +6,44 @@ 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.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
@Tag(name ="数据集相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/dataset")
|
||||
@Slf4j
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class DatasetController {
|
||||
@Autowired
|
||||
private DatasetService datasetService;
|
||||
|
||||
/**
|
||||
* 新增数据集
|
||||
* 新增数据集(整合文件上传)
|
||||
* @param datasetDTO
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary ="新增数据集")
|
||||
@PostMapping
|
||||
public OptResult save(@RequestBody DatasetDTO datasetDTO) {
|
||||
log.info("新增数据集:{}", datasetDTO);
|
||||
datasetService.save(datasetDTO);
|
||||
return OptResult.success();
|
||||
@Operation(summary = "新增数据集")
|
||||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public OptResult save(
|
||||
@ModelAttribute("dataset") DatasetDTO datasetDTO,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file) {
|
||||
log.info("新增数据集: {}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
|
||||
try {
|
||||
datasetService.save(datasetDTO, file);
|
||||
return OptResult.success();
|
||||
} catch (Exception e) {
|
||||
log.error("新增数据集失败", e);
|
||||
return OptResult.error("新增数据集失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,17 +59,17 @@ public class DatasetController {
|
||||
return OptResult.success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改数据集
|
||||
* @param datasetDTO
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary ="修改数据集")
|
||||
@PutMapping
|
||||
public OptResult update(@RequestBody DatasetDTO datasetDTO){
|
||||
log.info("修改数据集",datasetDTO);
|
||||
datasetService.update(datasetDTO);
|
||||
@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public OptResult update(@ModelAttribute("dataset") DatasetDTO datasetDTO,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file){
|
||||
log.info("修改数据集{}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
|
||||
datasetService.update(datasetDTO,file);
|
||||
return OptResult.success();
|
||||
}
|
||||
|
||||
@ -72,4 +88,34 @@ public class DatasetController {
|
||||
return OptResult.success("批量删除成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载数据集
|
||||
* @param datasetId 数据集ID
|
||||
* @return 数据集文件
|
||||
*/
|
||||
@Operation(summary = "下载数据集")
|
||||
@GetMapping("/download/{datasetId}")
|
||||
public ResponseEntity<byte[]> downloadDataset(@PathVariable Long datasetId) {
|
||||
log.info("下载数据集,ID:{}", datasetId);
|
||||
try {
|
||||
// TODO: 调用分布式存储系统的接口获取数据集文件的输入流
|
||||
InputStream inputStream = datasetService.downloadDataset(datasetId);
|
||||
if (inputStream == null) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
byte[] fileBytes = inputStream.readAllBytes();
|
||||
inputStream.close();
|
||||
|
||||
// 设置响应头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
headers.setContentDispositionFormData("attachment", "dataset_" + datasetId + ".zip");
|
||||
|
||||
return new ResponseEntity<>(fileBytes, headers, HttpStatus.OK);
|
||||
} catch (IOException e) {
|
||||
log.error("下载数据集失败", e);
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.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
|
||||
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("/{gpuId}")
|
||||
public void updateGpuResource(
|
||||
@PathVariable Long gpuId,
|
||||
@Valid @RequestBody GpuUpdateDTO dto){
|
||||
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);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@ -75,5 +76,20 @@ public class ModelController {
|
||||
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,73 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.deploy.deployment;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.deploy.entity.DeploymentResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.utils.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;
|
||||
|
||||
//获取剩余内存
|
||||
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,4 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.deploy.entity;
|
||||
|
||||
public class DeployRequest {
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.deploy.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,12 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.deploy.entity;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class DeploymentResource {
|
||||
private final GpuResource gpu;
|
||||
private final String url;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
|
||||
|
||||
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")
|
||||
private String GPUModel;
|
||||
|
||||
@NotNull(message = "显存容量不能为空")
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@NotBlank(message = "IP地址不能为空")
|
||||
@Pattern(regexp = "^\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
private String Ip;
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class GpuResponseDTO {
|
||||
private Long id;
|
||||
private String GPUModel;
|
||||
private Integer GPUMemorySize;
|
||||
private String Ip;
|
||||
private LocalDateTime createTime;
|
||||
// Builder类
|
||||
public static class Builder {
|
||||
private Long id;
|
||||
private String model;
|
||||
private Integer memory;
|
||||
private String ip;
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
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 createdTime(LocalDateTime createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
return this;
|
||||
}
|
||||
public GpuResponseDTO build() {
|
||||
// 必填字段校验(如网页2的推荐)
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("GPU ID必须填写");
|
||||
}
|
||||
return new GpuResponseDTO();
|
||||
}
|
||||
}
|
||||
public String getCreateTimeStr(){
|
||||
return "GPU创建时间:" + createTime.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.*;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
//@Setter
|
||||
//@Getter
|
||||
public class GpuUpdateDTO {
|
||||
public @NotNull(message = "GPU ID cannot be null") Long getGPUId() {
|
||||
return GPUId;
|
||||
}
|
||||
|
||||
public void setGPUId(@NotNull(message = "GPU ID cannot be null") 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;
|
||||
}
|
||||
|
||||
@NotNull(message = "GPU ID cannot be null")
|
||||
private Long GPUId;
|
||||
|
||||
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
|
||||
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
|
||||
private String GPUModel;
|
||||
|
||||
@Setter
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
|
||||
message = "IP地址格式无效")
|
||||
private String Ip;
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Setter
|
||||
@Data
|
||||
public class GpuResource {
|
||||
@Getter
|
||||
@TableField("GPUId")
|
||||
private Long GPUId;
|
||||
|
||||
@Getter
|
||||
@TableField("GPUModel")
|
||||
private String GPUModel;
|
||||
|
||||
@Getter
|
||||
@TableField("GPUMemorySize")
|
||||
private Integer GPUMemorySize;
|
||||
|
||||
@TableField("is_deleted")
|
||||
private Integer isDeleted = 0;
|
||||
|
||||
@TableField("Ip")
|
||||
private String Ip;
|
||||
|
||||
@Getter
|
||||
@TableField("CreatedTime")
|
||||
private LocalDateTime CreateTime;
|
||||
|
||||
@Getter
|
||||
@TableField("update_time")
|
||||
private LocalDateTime UpdateTime;
|
||||
|
||||
@Getter
|
||||
@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 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) {
|
||||
// CreateTime = createTime;
|
||||
// }
|
||||
//
|
||||
// public void setUpdateTime(LocalDateTime updateTime) {
|
||||
// UpdateTime = updateTime;
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.enums;
|
||||
|
||||
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, "缓存初始化失败");
|
||||
|
||||
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,38 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.entity.vo;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.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);
|
||||
}
|
||||
}
|
@ -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,34 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.exception;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.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.entity.enums.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; // 过滤器执行顺序,数值越小越先执行
|
||||
}
|
||||
}
|
@ -29,4 +29,12 @@ public interface AlgorithmInfoMapper {
|
||||
|
||||
@Delete("DELETE FROM algorithm_info WHERE id = #{id}")
|
||||
int deleteById(Long id);
|
||||
}
|
||||
@Select("select description from algorithm_info where id = #{id}")
|
||||
String getDescriptionById(Long id);
|
||||
@Select("select algorithm_file from algorithm_info where id = #{id}")
|
||||
String getFileById(Long id);
|
||||
@Select("select algorithm_name from algorithm_info")
|
||||
List<String> getAllNames();
|
||||
|
||||
List<AlgorithmInfo> selectByNameLike(String keyword);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingConstants;
|
||||
|
||||
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface GpuMapper {
|
||||
GpuResource toEntity(GpuCreateDTO dto);
|
||||
GpuResource toEntity(GpuUpdateDTO dto);
|
||||
GpuResource toEntity(GpuResponseDTO dto);
|
||||
GpuResponseDTO toDTO(GpuResource entity);
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.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) " +
|
||||
"VALUES (#{model}, #{memory}, #{ip})")
|
||||
@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 = #{model}, GPUMemorySize = #{memory}, 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();
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.mapper;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersionDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -72,4 +69,11 @@ public interface ModelMapper {
|
||||
*/
|
||||
@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;
|
||||
|
@ -19,6 +19,7 @@ public class DatasetDTO implements Serializable {
|
||||
private Long datasetId;
|
||||
private String datasetName;
|
||||
private int datasetType;
|
||||
private int datasetStatus;
|
||||
private String dsPath;
|
||||
// private Map<String,String> args;
|
||||
private String args;
|
||||
|
@ -20,11 +20,11 @@ public class DatasetPageQueryDTO implements Serializable{
|
||||
private int page;
|
||||
private int pageSize;
|
||||
private String datasetName;
|
||||
private int datasetType;
|
||||
/* private int datasetType;
|
||||
private int datasetStatus;
|
||||
private String dsPath;
|
||||
private String args;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private LocalDateTime updateTime;*/
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.Map;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DatasetVO implements Serializable {
|
||||
private Long datasetId;
|
||||
private String datasetName;
|
||||
private Integer datasetType;
|
||||
private Integer datasetStatus;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,4 +12,12 @@ public interface AlgorithmInfoService {
|
||||
boolean update(AlgorithmInfo algorithmInfo);
|
||||
boolean delete(Long id);
|
||||
boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo);
|
||||
}
|
||||
|
||||
void save(AlgorithmInfo algorithmInfo, MultipartFile file);
|
||||
|
||||
String run(Long id, String param);
|
||||
|
||||
List<String> getAllNames();
|
||||
|
||||
List<AlgorithmInfo> getByNameLike(String keyword);
|
||||
}
|
@ -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.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);
|
||||
}
|
||||
|
||||
}
|
@ -3,18 +3,22 @@ package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetPageQueryDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.PageResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hky
|
||||
*/
|
||||
public interface DatasetService {
|
||||
void save(DatasetDTO datasetDTO);
|
||||
void save(DatasetDTO datasetDTO, MultipartFile file);
|
||||
|
||||
void update(DatasetDTO datasetDTO);
|
||||
void update(DatasetDTO datasetDTO, MultipartFile file);
|
||||
|
||||
PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO);
|
||||
|
||||
void deleteBatch(List<Long> datasetIds);
|
||||
|
||||
InputStream downloadDataset(Long datasetId);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO;
|
||||
|
||||
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);
|
||||
}
|
@ -3,19 +3,28 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
|
||||
@Autowired
|
||||
private AlgorithmInfoMapper algorithmInfoMapper;
|
||||
|
||||
@Value("${algorithm.upload.dir:/tmp/algorithm-files/}") // 默认上传目录
|
||||
private String uploadDir;
|
||||
@Override
|
||||
public AlgorithmInfo getById(Long id) {
|
||||
return algorithmInfoMapper.selectById(id);
|
||||
@ -60,4 +69,81 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(AlgorithmInfo algorithmInfo, MultipartFile file) {
|
||||
String algorithmName = algorithmInfo.getAlgorithmName();
|
||||
// 检查同名算法
|
||||
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
|
||||
if (duplicateName != null) {
|
||||
throw new RuntimeException("算法已存在,请去修改算法");
|
||||
}
|
||||
|
||||
// 只接收文件但不进行保存操作
|
||||
if (file != null && !file.isEmpty()) {
|
||||
log.info("已接收文件: {}", file.getOriginalFilename());
|
||||
log.info("文件大小: {} 字节", file.getSize());
|
||||
log.info("文件类型: {}", file.getContentType());
|
||||
// 临时设置一个空路径(避免数据库保存空值)
|
||||
//todo 保存到分布式存储
|
||||
algorithmInfo.setAlgorithmFile("");
|
||||
}
|
||||
|
||||
algorithmInfo.setCreateTime(LocalDateTime.now());
|
||||
// 保存算法信息到数据库(注意:此时algorithmFile字段为空)
|
||||
algorithmInfoMapper.insert(algorithmInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String run(Long id, String param) {
|
||||
String file = algorithmInfoMapper.getFileById(id);
|
||||
StringBuilder result = new StringBuilder(); // 用于存储结果
|
||||
|
||||
try {
|
||||
// 构建命令,将 param 作为参数传递给 Python 脚本
|
||||
ProcessBuilder pb = new ProcessBuilder("python", file, param);
|
||||
Process process = pb.start();
|
||||
|
||||
// 读取标准输出(脚本执行结果)
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
|
||||
// 读取错误输出
|
||||
BufferedReader errorReader = new BufferedReader(
|
||||
new InputStreamReader(process.getErrorStream()));
|
||||
String errorLine;
|
||||
while ((errorLine = errorReader.readLine()) != null) {
|
||||
result.append("Error: ").append(errorLine).append("\n");
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
result.append("Exit Code: ").append(exitCode);
|
||||
|
||||
} catch (Exception e) {
|
||||
result.append("执行异常: ").append(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result.toString(); // 返回完整结果
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllNames() {
|
||||
return algorithmInfoMapper.getAllNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊查询
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AlgorithmInfo> getByNameLike(String keyword) {
|
||||
return algorithmInfoMapper.selectByNameLike(keyword);
|
||||
}
|
||||
}
|
@ -12,12 +12,17 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.FROM_DATABASE;
|
||||
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.UPLOAD;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@ -25,63 +30,65 @@ public class DatasetServiceImpl implements DatasetService {
|
||||
@Autowired
|
||||
private DatasetMapper datasetMapper;
|
||||
|
||||
/**
|
||||
* 新增数据集
|
||||
* @param datasetDTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(DatasetDTO datasetDTO) {
|
||||
//判断数据集类型,如果是本地上传则保存,若用调用数据仓库进入下一步
|
||||
// 获取数据集类型
|
||||
public void save(DatasetDTO datasetDTO, MultipartFile file) {
|
||||
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
|
||||
// 根据类型处理数据
|
||||
switch (datasetType) {
|
||||
case UPLOAD:
|
||||
//TODO 保存到分布式文件系统
|
||||
break;
|
||||
case FROM_DATABASE:
|
||||
String args = datasetDTO.getArgs();
|
||||
//TODO 根据筛选条件调用数据仓库中的数据
|
||||
if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
|
||||
try {
|
||||
//todo存入分布式文件系统
|
||||
|
||||
//TODO 调用数据仓库保存到分布式文件系统
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType);
|
||||
// 生成文件名(建议使用 UUID 避免重复)
|
||||
String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
|
||||
// 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
|
||||
String filePath = "/your/storage/path/" + fileName;
|
||||
// 保存文件到磁盘(示例代码,需处理 IO 异常)
|
||||
file.transferTo(new File(filePath));
|
||||
// 更新数据集路径
|
||||
datasetDTO.setDsPath(filePath); // 取消注释,并确保 datasetDTO 有 setDsPath 方法
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
} else if (datasetType == FROM_DATABASE){
|
||||
//todo 从数据仓库中查询 并选择筛选条件
|
||||
}
|
||||
|
||||
// 保存数据集实体
|
||||
DatasetEntity datasetEntity = new DatasetEntity();
|
||||
BeanUtils.copyProperties(datasetDTO,datasetEntity);
|
||||
datasetEntity.setDatasetStatus(StatusConstant.ENABLE);
|
||||
BeanUtils.copyProperties(datasetDTO, datasetEntity);
|
||||
datasetEntity.setCreateTime(LocalDateTime.now());
|
||||
datasetEntity.setUpdateTime(LocalDateTime.now());
|
||||
datasetMapper.insert(datasetEntity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改数据集
|
||||
*
|
||||
* @param datasetDTO
|
||||
* @param file
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(DatasetDTO datasetDTO) {
|
||||
/*DatasetEntity datasetEntity = new DatasetEntity();
|
||||
BeanUtils.copyProperties(datasetDTO,datasetEntity);*/
|
||||
public void update(DatasetDTO datasetDTO, MultipartFile file) {
|
||||
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
|
||||
// 根据类型处理数据
|
||||
switch (datasetType) {
|
||||
case UPLOAD:
|
||||
//TODO 覆盖保存到分布式文件系统中
|
||||
break;
|
||||
case FROM_DATABASE:
|
||||
//TODO 覆盖数据文件
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType);
|
||||
if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
|
||||
try {
|
||||
// 生成文件名(建议使用 UUID 避免重复)
|
||||
String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
|
||||
// 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
|
||||
String filePath = "/your/storage/path/" + fileName;
|
||||
// 保存文件到磁盘(示例代码,需处理 IO 异常)
|
||||
file.transferTo(new File(filePath));
|
||||
// 更新数据集路径
|
||||
datasetDTO.setDsPath(filePath); // 取消注释,并确保 datasetDTO 有 setDsPath 方法
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage());
|
||||
}
|
||||
} else if (datasetType == FROM_DATABASE){
|
||||
//todo 从数据仓库中查询 并选择筛选条件
|
||||
}
|
||||
|
||||
DatasetEntity datasetEntity = new DatasetEntity();
|
||||
BeanUtils.copyProperties(datasetDTO,datasetEntity);
|
||||
datasetEntity.setUpdateTime(LocalDateTime.now());
|
||||
@ -112,4 +119,14 @@ public class DatasetServiceImpl implements DatasetService {
|
||||
datasetMapper.deleteBatch(datasetIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
* @param datasetId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public InputStream downloadDataset(Long datasetId) {
|
||||
// TODO: 调用分布式存储系统的接口获取数据集文件的输入流
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,10 @@ 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
|
||||
@ -145,4 +148,21 @@ public class ModelServiceImpl implements ModelService {
|
||||
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);
|
||||
};
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersionDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ModelService {
|
||||
void createModel(ModelDTO dto);
|
||||
@ -21,4 +19,8 @@ public interface ModelService {
|
||||
void deleteModelVersion(Long id);
|
||||
|
||||
void updateLifeCycle(Long id, String lifeCycle);
|
||||
|
||||
List<Map<String, String>> listLifeCycle();
|
||||
|
||||
List<DatasetEntity> listDataset();
|
||||
}
|
||||
|
@ -9,5 +9,4 @@ public interface PublishService {
|
||||
|
||||
|
||||
|
||||
String getByModelId(Long modelId);
|
||||
}
|
||||
|
@ -0,0 +1,127 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service;
|
||||
|
||||
public interface ServiceAPIService {
|
||||
String getByModelId(Long modelId);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
|
||||
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 {
|
||||
@Autowired
|
||||
private GpuResourceDao gpuDao;
|
||||
|
||||
@Autowired
|
||||
private GpuMapper gpuMapper;
|
||||
@Autowired
|
||||
private GpuResourceDao gpuResourceDao;
|
||||
|
||||
@Transactional
|
||||
//创建GPU资源
|
||||
public ResponseVO createGpuResource(GpuCreateDTO dto) {
|
||||
GpuResource entity = gpuMapper.toEntity(dto);
|
||||
gpuDao.insert(entity);
|
||||
return ResponseVO.success(entity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
//删除GPU资源(逻辑删除)
|
||||
public ResponseVO deleteGpuResource(Long gpuId) {
|
||||
GpuResource entity = gpuDao.selectById(gpuId);
|
||||
if (entity == null) {
|
||||
return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND);
|
||||
}
|
||||
gpuDao.isDeleted(gpuId);
|
||||
return ResponseVO.success();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
//更新GPU资源
|
||||
public void updateGpuResource(GpuUpdateDTO dto) {
|
||||
GpuResource entity = gpuMapper.toEntity(dto);
|
||||
gpuDao.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
//模糊匹配查询
|
||||
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip) {
|
||||
// PermissionCheckUtil.checkTenantAccess();
|
||||
|
||||
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);
|
||||
|
||||
List<GpuResource> entities = gpuResourceDao.selectByFields(params);
|
||||
|
||||
return entities.stream().map(gpuMapper::toDTO).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
}
|
@ -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,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.utils;
|
||||
|
||||
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;
|
||||
}
|
@ -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
|
||||
@ -10,25 +10,40 @@ spring.datasource.hikari.maximum-pool-size=10
|
||||
spring.datasource.hikari.minimum-idle=5
|
||||
spring.datasource.hikari.connection-timeout=30000
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
#SQL 语句日志输出配置
|
||||
|
||||
logging.level.org.springframework.web=DEBUG
|
||||
|
||||
|
||||
#SQL ????????
|
||||
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
|
||||
management.health.rabbit.enabled=false
|
||||
|
||||
# 单个文件最大大小
|
||||
spring.servlet.multipart.max-file-size=10MB
|
||||
# 单次请求最大大小(可包含多个文件)
|
||||
spring.servlet.multipart.max-request-size=15MB
|
||||
|
||||
|
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
|
8
src/main/resources/mapper/AlgorithmInfoMapper.xml
Normal file
8
src/main/resources/mapper/AlgorithmInfoMapper.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?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.AlgorithmInfoMapper">
|
||||
|
||||
<select id="selectByNameLike" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo">
|
||||
SELECT * FROM algorithm_info WHERE algorithm_name LIKE CONCAT('%', #{keyword}, '%')
|
||||
</select>
|
||||
</mapper>
|
@ -44,24 +44,6 @@
|
||||
<if test="datasetName != null and datasetName!=''">
|
||||
dataset_name LIKE CONCAT('%', #{datasetName}, '%')
|
||||
</if>
|
||||
<if test="datasetType != null">
|
||||
and dataset_type=#{datasetType}
|
||||
</if>
|
||||
<if test="datasetStatus != null">
|
||||
and dataset_status=#{datasetStatus}
|
||||
</if>
|
||||
<if test="dsPath != null">
|
||||
and ds_path=#{dsPath}
|
||||
</if>
|
||||
<if test="args != null">
|
||||
and args=#{args}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time=#{createTime}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time=#{updateTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
@ -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
|
||||
|
57
src/main/resources/mapper/GpuResourceMapper.xml
Normal file
57
src/main/resources/mapper/GpuResourceMapper.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<?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">
|
||||
|
||||
<!-- 动态条件查询 -->
|
||||
<select id="selectByFields"
|
||||
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource">
|
||||
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.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.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.entity.GpuResource">
|
||||
SELECT *
|
||||
FROM gpu_resource
|
||||
WHERE GPUId = #{gpuId}
|
||||
FOR UPDATE NOWAIT
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -19,7 +19,7 @@
|
||||
</insert>
|
||||
|
||||
<!--查询模型列表-->
|
||||
<select id="list" resultType="modelVO">
|
||||
<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
|
||||
@ -29,7 +29,7 @@
|
||||
</select>
|
||||
|
||||
<!--查询模型详细信息-->
|
||||
<select id="selectById" resultType="modelVersion">
|
||||
<select id="selectById" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion">
|
||||
SELECT
|
||||
t1.model_name,
|
||||
t2.version, t2.dataset_id, t2.model_config,
|
||||
|
Reference in New Issue
Block a user