Compare commits

..

25 Commits

Author SHA1 Message Date
lpz
44b18c3689 Merge pull request 'xiaohucoding' () from xiaohucoding into main
Reviewed-on: 
2025-07-31 12:08:37 +08:00
28ef203b90 整体需求完善 2025-07-30 12:15:30 +08:00
c254e2f94c 整体需求完善 2025-07-30 10:56:56 +08:00
lpz
c7505179bb Merge pull request '服务发布回显模型名称和版本' () from xiaohucoding into main
Reviewed-on: 
2025-07-16 15:27:00 +08:00
19e8d21620 服务发布回显模型名称和版本 2025-07-14 16:00:04 +08:00
lpz
671dc90b61 Merge pull request 'nh' () from nh into main
Reviewed-on: 
2025-07-07 11:21:12 +08:00
0ccef5f290 [提交]:数据库存档文件 2025-07-04 11:05:53 +08:00
ae97005a7c 优化了模型创建、版本构建、模型修改和模型更新的部分功能异常 2025-07-04 10:59:34 +08:00
fb2ee66b5b Merge remote-tracking branch 'origin/main' 2025-07-04 10:58:11 +08:00
lpz
5ef521438a Merge pull request 'xiaohucoding' () from xiaohucoding into main
Reviewed-on: 
2025-07-01 18:10:46 +08:00
e6e1bee8df Cache的类型转换的更改优化 2025-07-01 12:07:00 +08:00
d3c81412b9 Cache的类型转换的更改优化 2025-07-01 09:27:28 +08:00
lpz
ed4cd0643a Merge pull request 'GPU和服务发布和算法部分代码优化' () from xiaohucoding into main
Reviewed-on: 
2025-06-30 20:58:43 +08:00
808d285888 GPU和服务发布和算法部分代码优化 2025-06-30 20:35:29 +08:00
02538ef4f4 Merge remote-tracking branch 'origin/main' 2025-06-30 20:00:16 +08:00
lpz
a0680450e6 Merge pull request '模型部署+Gpu资源增删改查日志' () from dc-feature into main
Reviewed-on: 
2025-06-23 15:36:45 +08:00
d219fbc92a 配置文件 2025-06-22 17:43:47 +08:00
dc
86a64f205f 模型部署+Gpu资源增删改查日志 2025-06-20 15:06:20 +08:00
Lpz
9d25661743 Merge branch 'nh'
# Conflicts:
#	src/main/resources/application.properties
2025-06-19 10:20:06 +08:00
lpz
957c5bc3e1 Merge pull request 'xiaohucoding' () from xiaohucoding into main
Reviewed-on: 
2025-06-18 13:23:04 +08:00
09424cf223 算法和数据集的后端完善 2025-06-16 14:08:23 +08:00
f18c4e4159 [修改]:修改了模型评估和生命周期更新的一些细节,便于和前端接口协调 2025-06-06 21:07:16 +08:00
cf2eb689ca [提交]:增加了上传文件到阿里云oss接口
# Conflicts:
#	src/main/resources/application.properties
2025-06-05 15:04:40 +08:00
46331fcade 算法创建 2025-06-05 12:40:19 +08:00
99c291ca09 算法创建 2025-06-05 12:40:14 +08:00
87 changed files with 3626 additions and 475 deletions
algorithm_files
lib
pom.xml
src
main
java
com
bipt
intelligentapplicationorchestrationservice
IntelligentApplicationOrchestrationServiceApplication.java
cache
config
constant
controller
deploy
entity
enumeration
exception
mapper
pojo
properties
service
util
resources
test
java
com
bipt
intelligentapplicationorchestrationservice

@ -0,0 +1,57 @@
import random
import sys
def quick_sort(arr):
"""
快速排序主函数,支持空数组处理
"""
if len(arr) <= 1:
return arr
def partition(low, high):
pivot_index = random.randint(low, high) # 随机选择基准
arr[pivot_index], arr[high] = arr[high], arr[pivot_index]
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i+1], arr[high] = arr[high], arr[i+1]
return i + 1
def recur_sort(low, high):
if low < high:
pi = partition(low, high)
recur_sort(low, pi - 1)
recur_sort(pi + 1, high)
recur_sort(0, len(arr) - 1)
return arr
if __name__ == "__main__":
# 从命令行参数读取数据
if len(sys.argv) > 1:
try:
# 处理多种输入格式:逗号分隔、空格分隔或混合分隔
input_str = " ".join(sys.argv[1:])
input_data = [float(x) if '.' in x else int(x)
for x in input_str.replace(',', ' ').split()]
print("原始输入:", sys.argv[1:])
print("解析数据:", input_data)
sorted_arr = quick_sort(input_data.copy())
print("排序结果:", sorted_arr)
except ValueError:
print("错误:输入数据包含非数字字符,请确保只输入数字")
print("用法: python script.py [数字1 数字2 ...]")
print("示例: python script.py 3 0 8 7 2 1 9 4")
else:
print("未提供输入数据,使用默认测试用例")
test_case = [3, 0, 8, 7, 2, 1, 9, 4]
print("测试数据:", test_case)
print("排序结果:", quick_sort(test_case.copy()))

@ -0,0 +1,57 @@
import random
import sys
def quick_sort(arr):
"""
快速排序主函数,支持空数组处理
"""
if len(arr) <= 1:
return arr
def partition(low, high):
pivot_index = random.randint(low, high) # 随机选择基准
arr[pivot_index], arr[high] = arr[high], arr[pivot_index]
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i]
arr[i+1], arr[high] = arr[high], arr[i+1]
return i + 1
def recur_sort(low, high):
if low < high:
pi = partition(low, high)
recur_sort(low, pi - 1)
recur_sort(pi + 1, high)
recur_sort(0, len(arr) - 1)
return arr
if __name__ == "__main__":
# 从命令行参数读取数据
if len(sys.argv) > 1:
try:
# 处理多种输入格式:逗号分隔、空格分隔或混合分隔
input_str = " ".join(sys.argv[1:])
input_data = [float(x) if '.' in x else int(x)
for x in input_str.replace(',', ' ').split()]
print("原始输入:", sys.argv[1:])
print("解析数据:", input_data)
sorted_arr = quick_sort(input_data.copy())
print("排序结果:", sorted_arr)
except ValueError:
print("错误:输入数据包含非数字字符,请确保只输入数字")
print("用法: python script.py [数字1 数字2 ...]")
print("示例: python script.py 3 0 8 7 2 1 9 4")
else:
print("未提供输入数据,使用默认测试用例")
test_case = [3, 0, 8, 7, 2, 1, 9, 4]
print("测试数据:", test_case)
print("排序结果:", quick_sort(test_case.copy()))

@ -0,0 +1,412 @@
### 零、数据库测试表test_simple)
#### 1.基本信息
所属模块:仅供创建数据库时,测试是否连接成功
负责人:宁欢
创建时间2025-05-13
#### 2.表结构
| 序号 | 字段名 | 中文名称 | 数据类型 |
| ---- | ---------- | -------------- | ------------- |
| 1 | id | id唯一主键 | Int |
| 2 | name | 名称 | VARCHAR(255) |
| 3 | created_at | 创建时间 | LocalDateTime |
#### 3.SQL脚本
```
-- 创建极简测试表
CREATE TABLE IF NOT EXISTS `test_simple` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 插入测试数据
INSERT INTO `test_simple` (`name`) VALUES ('测试数据');
-- 查询验证
SELECT * FROM `test_simple`;
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------- |
| v1.0 | 2025-05-13 | nh | 初始创建 |
### 一、模型信息表model_info)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:宁欢
创建时间: 2025-05-14
#### 2.表结构
| 序号 | 数据表名 | 中文名称 | 数据类型 |
| ---- | ---------- | ------------------ | ------------ |
| 1 | id | 模型id唯一主键 | Long |
| 2 | model_name | 模型名称 | VARCHAR(255) |
#### 3.SQL脚本
```
CREATE TABLE model_info (
id BIGINT PRIMARY KEY COMMENT '模型id唯一主键',
model_name VARCHAR(255) COMMENT '模型名称'
);
-- 1. 删除现有主键约束
ALTER TABLE model_info DROP CONSTRAINT IF EXISTS model_info_pkey;
-- 2. 创建序列(如果不存在)
CREATE SEQUENCE IF NOT EXISTS model_info_id_seq;
-- 3. 将 id 字段设置为使用序列自增
ALTER TABLE model_info
ALTER COLUMN id SET DEFAULT nextval('model_info_id_seq');
-- 4. 重新添加主键约束
ALTER TABLE model_info ADD PRIMARY KEY (id);
-- 5. 将序列的当前值设置为表中现有最大 id 值 +1确保不自增冲突
SELECT setval('model_info_id_seq', COALESCE((SELECT MAX(id)+1 FROM model_info), 1), false);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | ---------------------- |
| v1.0 | 2025-05-13 | 宁欢 | 初始创建 |
| v1.1 | 2025-05-20 | 宁欢 | 将主键约束条件改为自增 |
### 二、日志表model_log)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:宁欢
创建时间2025-05-14
#### 2.表结构
| 序号 | 数据表名 | 中文名称 | 数据类型 |
| ---- | ---------------- | --------------------- | ------------- |
| 1 | id | 日志id唯一主键 | Long |
| 2 | model_version_id | 关联模型版本id | Long |
| 3 | log_type | 日志类型123...) | Int |
| 4 | log_path | 日志存储路径 | VARCHAR(255) |
| 5 | log_time | 日志生成时间 | LocalDateTime |
#### 3.SQL脚本
```
-- 创建model_log表
CREATE TABLE model_log (
id BIGINT PRIMARY KEY COMMENT '日志id唯一主键',
model_id BIGINT COMMENT '关联模型id',
log_type INT COMMENT '日志类型123...',
log_path VARCHAR(255) COMMENT '日志存储路径',
log_time TIMESTAMP COMMENT '日志生成时间'
);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | ------------------------------------------ |
| v1.0 | 2025-05-14 | 宁欢 | 初始创建 |
| v2.0 | 2025-06-30 | 宁欢 | 模型日志修改成绑定模型版本id而不是模型id |
### 三、模型评估记录表model_evaluation)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:宁欢
创建时间2025-05-14
#### 2.表结构
| 序号 | 数据表名 | 中文名称 | 数据类型 |
| ---- | ----------------- | ---------------------- | ------------- |
| 1 | id | 评估记录id唯一主键 | Long |
| 2 | model_id | 关联模型id | Long |
| 3 | evaluation_time | 评估时间 | LocalDateTime |
| 4 | evaluation_result | 评估结果 | VARCHAR(255) |
| 5 | operator | 评估操作人员 | VARCHAR(255) |
#### 3.SQL脚本
```
-- 创建model_evaluation表
CREATE TABLE model_evaluation (
id BIGINT PRIMARY KEY COMMENT '评估记录id唯一主键',
model_id BIGINT COMMENT '关联模型id',
evaluation_time TIMESTAMP COMMENT '评估时间',
evaluation_result VARCHAR(255) COMMENT '评估结果',
operator VARCHAR(255) COMMENT '评估操作人员'
);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------- |
| v1.0 | 2025-05-14 | 宁欢 | 初始创建 |
### 四、模型版本信息model_version)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:宁欢
创建时间2025-05-14
#### 2.表结构
| 序号 | 数据表名 | 中文名称 | 数据类型 |
| ---- | --------------------- | ---------------------------------- | ------------- |
| 1 | id | 版本信息表id唯一主键 | Long |
| 2 | model_id | 关联模型id | Long |
| 3 | version | 模型版本 | VARCHAR(255) |
| 4 | dataset_id | 数据集id | Int |
| 5 | model_config | 模型配置信息 | VARCHAR(255) |
| 6 | model_path | 模型存储路径 | VARCHAR(255) |
| 7 | status | 模型状态1代表上线0代表不上线 | Int |
| 8 | create_time | 创建时间 | LocalDateTime |
| 9 | update_time | 更新时间 | LocalDateTime |
| 10 | model_size | 模型大小 | Integer |
| 11 | data_pre_handle_file | 数据预处理文件存储路径 | VARCHAR(255) |
| 12 | model_super_args | 模型超参数 | VARCHAR(255) |
| 13 | model_args_size | 模型参数量 | VARCHAR(255) |
| 14 | model_source_code_url | 模型源代码路径 | VARCHAR(255) |
| 15 | model_file | 模型文件存储路径 | VARCHAR(255) |
| 16 | model_design_document | 模型设计文档存储路径 | VARCHAR(255) |
| 17 | life_cycle | 模型生命周期 | VARCHAR(255) |
#### 3.SQL脚本
```
-- 创建model_version表
CREATE TABLE model_version (
id BIGINT PRIMARY KEY COMMENT '版本信息表id唯一主键',
model_id BIGINT COMMENT '关联模型id',
version VARCHAR(255) COMMENT '模型版本',
dataset_id INT COMMENT '数据集id',
model_config VARCHAR(255) COMMENT '模型配置信息',
model_path VARCHAR(255) COMMENT '模型存储路径',
status INT COMMENT '模型状态1代表上线0代表不上线',
create_time TIMESTAMP COMMENT '创建时间'
);
-- 添加更新时间字段类型为TIMESTAMP与Java的LocalDateTime对应
ALTER TABLE model_version ADD COLUMN update_time TIMESTAMP COMMENT '更新时间';
-- 添加模型大小字段类型用INT与Java的Integer对应
ALTER TABLE model_version ADD COLUMN model_size INT COMMENT '模型大小';
-- 数据预处理文件存储路径用VARCHAR存储路径信息
ALTER TABLE model_version ADD COLUMN data_pre_handle_file VARCHAR(255) COMMENT '数据预处理文件存储路径';
-- 模型超参数用VARCHAR存储文本信息
ALTER TABLE model_version ADD COLUMN model_super_args VARCHAR(255) COMMENT '模型超参数';
-- 模型参数量用VARCHAR存储文本格式的数量信息
ALTER TABLE model_version ADD COLUMN model_args_size VARCHAR(255) COMMENT '模型参数量';
-- 模型源代码路径用VARCHAR存储路径信息
ALTER TABLE model_version ADD COLUMN model_source_code_url VARCHAR(255) COMMENT '模型源代码路径';
-- 模型文件存储路径用VARCHAR存储路径信息
ALTER TABLE model_version ADD COLUMN model_file VARCHAR(255) COMMENT '模型文件存储路径';
-- 模型设计文档存储路径用VARCHAR存储路径信息
ALTER TABLE model_version ADD COLUMN model_design_document VARCHAR(255) COMMENT '模型设计文档存储路径';
-- 模型生命周期用VARCHAR存储文本信息
ALTER TABLE model_version ADD COLUMN life_cycle VARCHAR(255) COMMENT '模型生命周期';
-- 1. 删除现有主键约束
ALTER TABLE model_version DROP CONSTRAINT IF EXISTS model_version_pkey;
-- 2. 创建序列(如果不存在)
CREATE SEQUENCE IF NOT EXISTS model_version_id_seq;
-- 3. 将 id 字段设置为使用序列自增
ALTER TABLE model_version
ALTER COLUMN id SET DEFAULT nextval('model_version_id_seq');
-- 4. 重新添加主键约束
ALTER TABLE model_version ADD PRIMARY KEY (id);
-- 5. 将序列的当前值设置为表中现有最大 id 值 +1确保不自增冲突
SELECT setval('model_version_id_seq', COALESCE((SELECT MAX(id)+1 FROM model_version), 1), false);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------------------------------------------------- |
| v1.0 | 2025-05-14 | 宁欢 | 初始创建 |
| v1.1 | 2025-05-20 | 宁欢 | 新增了一些字段(从update_time到life_cycle共9个字段) |
| v1.3 | 2025-05-20 | 宁欢 | 将主键约束条件改为自增 |
### 五、数据集表dataset )
#### 1.基本信息
所属模块:智能应用服务管理
负责人:胡楷沅
创建时间2025-05-13
#### 2.表结构
| 序号 | 数据表名 | 中文名称 | 数据类型 |
| ---- | -------------- | ---------------------------------------------------- | ------------ |
| 1 | dataset_id | 数据集id唯一主键 | Int |
| 2 | dataset_name | 数据集名称 | VARCHAR(255) |
| 3 | dataset_type | 数据集类型0 表示用户上传1 表示来源于数据库) | Int |
| 4 | dataset_status | 数据集状态0 表示停用1 表示启用) | Int |
| 5 | ds_path | 分布式存储路径(存入分布式文件系统的路径) | VARCHAR(255) |
| 6 | args | 过滤参数(存储为 JSON 格式对应 Map<String, String> | JSON |
| 7 | create_time | 创建时间 | TIMESTAMP |
| 8 | update_time | 更新时间 | TIMESTAMP |
#### 3.SQL脚本
```
CREATE TABLE dataset (
dataset_id INT PRIMARY KEY AUTO_INCREMENT COMMENT '数据集ID',
dataset_name VARCHAR(255) COMMENT '数据集名称',
dataset_type INT COMMENT '数据集类型0表示用户上传1表示来源于数据库',
dataset_status INT COMMENT '数据集状态0表示停用1表示启用',
ds_path VARCHAR(255) COMMENT '分布式存储路径,存入分布式文件系统的路径',
args JSON COMMENT '过滤参数存储为JSON格式对应Map<String, String>',
create_time TIMESTAMP COMMENT '创建时间',
update_time TIMESTAMP COMMENT '更新时间'
);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------- |
| v1.0 | 2025-05-13 | 胡楷沅 | 初始创建 |
### 六、GPU资源表gpu_resource)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:杜冲
创建时间2025-05-14
#### 2.表结构
| 字段名 | 数据类型 | 约束 | 字段描述 |
| :-----------: | :---------: | :--------: | :-------------------: |
| GPUId | BIGINT | 主键,自增 | GPU的ID全局唯一标识 |
| GPUModel | VARCHAR(64) | NOT NULL | GPU的型号 |
| GPUMemorySize | INT | NOT NULL | GPU内存大小 |
| Ip | VARCHAR(15) | NOT NULL | GPU所在ip |
| CreatedTime | DATETIME | NULL | GPU添加时间可为空 |
#### 3.SQL脚本
```
-- 创建gpu_resource表
CREATE TABLE gpu_resource (
GPUId BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
GPUModel VARCHAR(64) NOT NULL,
GPUMemorySize INT NOT NULL,
Ip VARCHAR(15) NOT NULL CHECK (Ip ~ '^\\d+\\.\\d+\\.\\d+\\.\\d+$'),
CreatedTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------- |
| v1.0 | 2025-05-14 | 杜冲 | 初始创建 |
### 七、算法基础信息表algorithm_info)
#### 1.基本信息
所属模块:智能应用服务管理
负责人:孙一城
创建时间2025-05-14
#### 2.表结构
| 字段名 | 类型 | 是否为空 | 默认值 | 说明 |
| -------------- | ------------ | -------- | --------------------------- | -------------- |
| id | BIGINT | NOT NULL | AUTO_INCREMENT | 算法ID |
| algorithm_name | VARCHAR(100) | NOT NULL | | 算法名称(唯一) |
| algorithm_file | VARCHAR(255) | NOT NULL | | 算法文件路径 |
| algorithm_type | VARCHAR(50) | NOT NULL | | 算法分类 |
| description | TEXT | NULL | | 算法描述 |
| created_by | VARCHAR(50) | NOT NULL | | 创建人 |
| create_time | DATETIME | NOT NULL | CURRENT_TIMESTAMP | 创建时间 |
| update_time | DATETIME | NOT NULL | CURRENT_TIMESTAMP ON UPDATE | 更新时间 |
| file_size | BIGINT | NULL | | 文件大小(字节) |
#### 3.SQL脚本
```
-- 创建算法信息表Kingbase 兼容版)
CREATE TABLE algorithm_info (
id BIGSERIAL PRIMARY KEY, -- 自增主键
algorithm_name VARCHAR(100) NOT NULL, -- 算法名称
algorithm_file VARCHAR(255) NOT NULL, -- 算法文件路径
algorithm_type VARCHAR(50) NOT NULL, -- 算法分类
description TEXT, -- 算法描述
created_by VARCHAR(50) NOT NULL, -- 创建人
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 创建时间
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 更新时间(需触发器自动更新)
file_size BIGINT -- 文件大小(字节)
);
-- 添加唯一约束
ALTER TABLE algorithm_info ADD CONSTRAINT uk_algorithm_name UNIQUE (algorithm_name);
-- 这部份没有成功运行,存在问题
-- 为 update_time 添加自动更新触发器
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.update_time = NOW(); -- 语句以分号结尾
RETURN NEW;
END;
$$ LANGUAGE plpgsql; -- 美元引号正确闭合
-- 创建触发器
CREATE TRIGGER update_algorithm_info_modtime
BEFORE UPDATE ON algorithm_info
FOR EACH ROW EXECUTE FUNCTION update_modified_column();
-- 创建索引(语法与 MySQL 相同,无需修改)
CREATE INDEX idx_algorithm_type ON algorithm_info(algorithm_type);
CREATE INDEX idx_created_by ON algorithm_info(created_by);
CREATE INDEX idx_create_time ON algorithm_info(create_time);
```
#### 4.变更记录
| 版本 | 变更时间 | 变更人 | 变更内容 |
| ---- | ---------- | ------ | -------- |
| v1.0 | 2025-05-14 | 孙一城 | 初始创建 |

57
pom.xml

@ -18,7 +18,7 @@
<url/> <url/>
<properties> <properties>
<java.version>21</java.version> <java.version>17</java.version>
<!-- 添加 Spring Cloud 版本控制 --> <!-- 添加 Spring Cloud 版本控制 -->
<spring-cloud.version>2022.0.4</spring-cloud.version> <spring-cloud.version>2022.0.4</spring-cloud.version>
</properties> </properties>
@ -92,7 +92,6 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version> <version>2.3.0</version>
</dependency> </dependency>
<!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) --> <!-- Nacos 配置依赖(移除手动版本,由上方依赖管理控制) -->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
@ -103,7 +102,6 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId> <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency> </dependency>
<!-- 测试依赖 --> <!-- 测试依赖 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -137,8 +135,6 @@
<artifactId>mapstruct</artifactId> <artifactId>mapstruct</artifactId>
<version>1.5.5.Final</version> <!-- 确保版本 ≥1.2.0 --> <version>1.5.5.Final</version> <!-- 确保版本 ≥1.2.0 -->
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
@ -165,6 +161,35 @@
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
</dependency> </dependency>
<!--阿里OSS依赖-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.15.1</version>
</dependency>
<!--如果使用的是Java 9及以上的版本则需要添加JAXB相关依赖。添加JAXB相关依赖-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- no more than 2.3.3-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version> <!-- 注意版本不超过2.3.3 -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -182,19 +207,17 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.38</version> <version>1.18.38</version>
</path> </path>
</annotationProcessorPaths> <path>
</configuration> <groupId>org.mapstruct</groupId>
</plugin> <artifactId>mapstruct-processor</artifactId>
<plugin> <version>1.5.5.Final</version>
<groupId>org.springframework.boot</groupId> </path>
<artifactId>spring-boot-maven-plugin</artifactId> <path>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok-mapstruct-binding</artifactId>
</exclude> <version>0.2.0</version>
</excludes> </path>
</annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

@ -1,9 +1,12 @@
package com.bipt.intelligentapplicationorchestrationservice; package com.bipt.intelligentapplicationorchestrationservice;
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@ -11,9 +14,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@EnableDiscoveryClient @EnableDiscoveryClient
@Slf4j @EnableConfigurationProperties(IpConfig.class)
//@Slf4j
public class IntelligentApplicationOrchestrationServiceApplication { public class IntelligentApplicationOrchestrationServiceApplication {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class);
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(IntelligentApplicationOrchestrationServiceApplication.class, args); SpringApplication.run(IntelligentApplicationOrchestrationServiceApplication.class, args);
log.info("server started"); log.info("server started");

@ -2,7 +2,7 @@ package com.bipt.intelligentapplicationorchestrationservice.cache;
import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager; import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao; import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

@ -2,7 +2,7 @@ package com.bipt.intelligentapplicationorchestrationservice.config;
import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager; import com.bipt.intelligentapplicationorchestrationservice.service.CacheManager;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;

@ -0,0 +1,21 @@
package com.bipt.intelligentapplicationorchestrationservice.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.List;
@Configuration
@ConfigurationProperties(prefix = "available")
public class IpConfig {
private List<String> ips;
public List<String> getIps() {
return ips;
}
public void setIps(String ips) {
this.ips = Arrays.asList(ips.split(","));
}
}

@ -0,0 +1,29 @@
package com.bipt.intelligentapplicationorchestrationservice.config;
import com.bipt.intelligentapplicationorchestrationservice.properties.AliOssProperties;
import com.bipt.intelligentapplicationorchestrationservice.util.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/*
* 配置类,用于创建阿里云文件上传工具类对象
*/
@Slf4j
@Configuration
public class OssConfiguration {
private final AliOssProperties aliOssProperties;
public OssConfiguration(AliOssProperties aliOssProperties) {
this.aliOssProperties = aliOssProperties;
}
@Bean
public AliOssUtil aliOssUtil(){
log.info("开始创建阿里云文件上传工具类对象...");
return new AliOssUtil(
aliOssProperties.getEndpoint(),
aliOssProperties.getAccessKeyId(),
aliOssProperties.getAccessKeySecret(),
aliOssProperties.getBucketName());
}
}

@ -1,6 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.config; package com.bipt.intelligentapplicationorchestrationservice.config;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.lettuce.core.ClientOptions; import io.lettuce.core.ClientOptions;
import io.lettuce.core.SocketOptions; import io.lettuce.core.SocketOptions;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -15,6 +18,7 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.client.RestTemplate;
import java.time.Duration; import java.time.Duration;
@ -35,6 +39,11 @@ public class RedisConfig {
@Value("${spring.data.redis.ssl:false}") @Value("${spring.data.redis.ssl:false}")
private boolean useSsl; private boolean useSsl;
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean @Bean
public RedisConnectionFactory redisConnectionFactory() { public RedisConnectionFactory redisConnectionFactory() {
// 1. 创建 SocketOptions // 1. 创建 SocketOptions
@ -54,44 +63,41 @@ public class RedisConfig {
.clientOptions(clientOptions) // 注入 ClientOptions .clientOptions(clientOptions) // 注入 ClientOptions
.commandTimeout(Duration.ofSeconds(30)) // 全局命令超时 .commandTimeout(Duration.ofSeconds(30)) // 全局命令超时
.build(); .build();
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(redisHost); config.setHostName(redisHost);
config.setPort(redisPort); config.setPort(redisPort);
config.setUsername(redisUsername); // Redis 6.0+ 支持用户名 config.setUsername(redisUsername); // Redis 6.0+ 支持用户名
config.setPassword(RedisPassword.of(redisPassword)); config.setPassword(RedisPassword.of(redisPassword));
// LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
// .commandTimeout(Duration.ofSeconds(30)) // 增加命令超时
// .socketOptions(SocketOptions.builder()
// .connectTimeout(Duration.ofSeconds(15)) // TCP连接超时
// .build())
// .build();
return new LettuceConnectionFactory(config, clientConfig); return new LettuceConnectionFactory(config, clientConfig);
} }
// @Bean
// public RedisConnectionFactory redisConnectionFactory() {
// RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
// config.setPassword("");
// return new LettuceConnectionFactory(config);
// }
@Bean @Bean
public RedisTemplate<String, Object> redisTemplate() { public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>(); RedisTemplate<String, Object> template = new RedisTemplate<>();
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class); Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
log.info("开始创建redis模板对象..."); log.info("开始创建redis模板对象...");
//RedisTemplate redisTemplate = new RedisTemplate();
//设置redis的连接工厂对象
//redisTemplate.setConnectionFactory(redisConnectionFactory);
//设置redis key的序列化器
//redisTemplate.setKeySerializer(new StringRedisSerializer());
//RedisTemplate<String, GpuResource> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory()); template.setConnectionFactory(redisConnectionFactory());
// 创建自定义的ObjectMapper并注册JavaTimeModule
ObjectMapper mapper = new ObjectMapper();
// 禁用将日期序列化为时间戳
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
// 注册Java 8日期时间模块
mapper.registerModule(new JavaTimeModule());
// 使用自定义的ObjectMapper创建JSON序列化器
GenericJackson2JsonRedisSerializer jsonSerializer =
new GenericJackson2JsonRedisSerializer(mapper);
// 设置键和值的序列化方式
template.setKeySerializer(new StringRedisSerializer()); template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); template.setValueSerializer(jsonSerializer);
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(jsonSerializer);
template.afterPropertiesSet();
return template; return template;
} }
} }

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.utils; package com.bipt.intelligentapplicationorchestrationservice.constant;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

@ -10,5 +10,10 @@ public class MessageConstant {
public static final String ERROR_DEPLOYED_TO_DESIGNING = "已部署的模型不能直接调整成设计,需先下线再设计"; public static final String ERROR_DEPLOYED_TO_DESIGNING = "已部署的模型不能直接调整成设计,需先下线再设计";
public static final String ERROR_ABANDONED_CANNOT_UPDATE = "已废弃的模型只能查看信息,不能更新生命周期"; public static final String ERROR_ABANDONED_CANNOT_UPDATE = "已废弃的模型只能查看信息,不能更新生命周期";
public static final String ERROR_TRAINING_INVALID_TRANSITION = "训练中的模型只能调整成设计和评估"; public static final String ERROR_TRAINING_INVALID_TRANSITION = "训练中的模型只能调整成设计和评估";
public static final String UPDATE_FAILURE = "更新模型生命周期失败"; public static final String LIFECYCLE_UPDATE_FAILURE = "更新模型生命周期失败";
public static final String LIFECYCLE_UPDATE_SUCCESS = "生命周期更新成功";
//文件上传常量
public static final String UPLOAD_FAILURE = "上传文件失败";
public static final String FILE_EMPTY= "文件为空";
} }

@ -3,23 +3,34 @@ package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo; import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult; import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService; 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.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Tag(name ="算法创建相关接口") @Tag(name ="算法创建相关接口")
@RestController @RestController
@RequestMapping("/api/algorithm") @RequestMapping("/api/algorithm")
@Slf4j @Slf4j
@CrossOrigin(origins = "http://localhost:3000")
public class AlgorithmInfoController { public class AlgorithmInfoController {
@Autowired @Autowired
private AlgorithmInfoService algorithmInfoService; private AlgorithmInfoService algorithmInfoService;
@Autowired
private ObjectMapper objectMapper;
@GetMapping("/{id}") @GetMapping("/{id}")
public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) { public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id); AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
@ -63,15 +74,77 @@ public class AlgorithmInfoController {
ResponseEntity.badRequest().body("Delete failed"); ResponseEntity.badRequest().body("Delete failed");
} }
/** @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
* 算法创建
*/
@PostMapping
@Operation(summary ="算法创建") @Operation(summary ="算法创建")
public OptResult save(@RequestBody AlgorithmInfo algorithmInfo){ public OptResult save(@RequestParam("algorithm") String algorithmJson,
log.info("新增算法",algorithmInfo); @RequestPart(value = "algorithmFile") MultipartFile file) {
algorithmInfoService.save(algorithmInfo); try {
AlgorithmInfo algorithmInfo = objectMapper.readValue(algorithmJson, AlgorithmInfo.class);
log.info("新增算法: {}, 文件: {}", algorithmInfo, (file != null ? file.getOriginalFilename() : "无文件"));
algorithmInfoService.save(algorithmInfo, file);
return OptResult.success("算法创建成功"); 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: {}", id);
try {
AlgorithmInfo algorithm = algorithmInfoService.getById(id);
if (algorithm == null) {
return OptResult.error("算法不存在");
}
// 1. 解析前端传入的参数JSON格式
Map<String, Object> paramMap = objectMapper.readValue(param, Map.class);
// 2. 从参数中提取实际需要传递给Python脚本的参数列表
// 示例:假设前端传入 {"args": [3, 0, 8, 7, 2, 1, 9, 4]}
List<String> args = new ArrayList<>();
if (paramMap.containsKey("args")) {
List<Object> argList = (List<Object>) paramMap.get("args");
for (Object arg : argList) {
args.add(arg.toString());
}
}
// 3. 调用Service执行Python脚本并获取结果
String result = algorithmInfoService.run(algorithm.getFilePath(), args);
// 4. 返回结构化结果
return OptResult.success("运行结果"+result);
} catch (Exception e) {
log.error("算法运行失败", e);
return OptResult.error("算法运行失败: " + e.getMessage());
}
}
/**
* 前端列表返回算法名称
*/
@GetMapping("/names")
@Operation(summary = "列表返回算法名称")
public List<String> getNames(){
return algorithmInfoService.getAllNames();
} }
} }

@ -0,0 +1,59 @@
package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.util.AliOssUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.UUID;
@Slf4j
@RestController
@RequestMapping("/common")
@Tag(name = "通用接口")
@CrossOrigin(origins = "http://localhost:3000")
public class CommonController {
@Autowired
private AliOssUtil aliOssUtil;
// 默认上传的文件夹
private static final String DEFAULT_FOLDER= "File/";
/**
* 文件上传
* @param file
* @return
*/
@Operation(summary = "文件上传")
@PostMapping("/upload")
public OptResult uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
log.info("收到上传请求");
if (file.isEmpty()){
return OptResult.error(MessageConstant.FILE_EMPTY);
}
try {
// 1.生成唯一文件名
String originalFilename = file.getOriginalFilename(); // 原始文件名
log.info("原始文件名:{}", originalFilename);
String fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(".")); // 文件后缀
log.info("文件后缀:{}", fileSuffix);
String fileName = UUID.randomUUID().toString() + fileSuffix; // 唯一文件名
log.info("唯一文件名:{}", fileName);
// 2.构建oss存储路径
String objectName = DEFAULT_FOLDER + fileName;
// 3.调用工具类上传文件
String fileUrl = aliOssUtil.upload(file.getInputStream(), objectName);
// 4.返回文件URL
return OptResult.success(fileUrl);
} catch (Exception e) {
log.error(MessageConstant.UPLOAD_FAILURE +":{}", e.getMessage(), e);
return OptResult.error(MessageConstant.UPLOAD_FAILURE);
}
}
}

@ -6,28 +6,44 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.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.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
@Tag(name ="数据集相关接口") @Tag(name ="数据集相关接口")
@RestController @RestController
@RequestMapping("/dataset") @RequestMapping("/dataset")
@Slf4j @Slf4j
@CrossOrigin(origins = "http://localhost:3000")
public class DatasetController { public class DatasetController {
@Autowired @Autowired
private DatasetService datasetService; private DatasetService datasetService;
/** /**
* 新增数据集 * 新增数据集(整合文件上传)
* @param datasetDTO * @param datasetDTO
* @param file
* @return * @return
*/ */
@Operation(summary = "新增数据集") @Operation(summary = "新增数据集")
@PostMapping @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public OptResult save(@RequestBody DatasetDTO datasetDTO) { public OptResult save(
log.info("新增数据集:{}", datasetDTO); @ModelAttribute("dataset") DatasetDTO datasetDTO,
datasetService.save(datasetDTO); @RequestPart(value = "file", required = false) MultipartFile file) {
log.info("新增数据集: {}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
try {
datasetService.save(datasetDTO, file);
return OptResult.success(); 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); return OptResult.success(pageResult);
} }
/** /**
* 修改数据集 * 修改数据集
* @param datasetDTO * @param datasetDTO
* @return * @return
*/ */
@Operation(summary ="修改数据集") @Operation(summary ="修改数据集")
@PutMapping @PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public OptResult update(@RequestBody DatasetDTO datasetDTO){ public OptResult update(@ModelAttribute("dataset") DatasetDTO datasetDTO,
log.info("修改数据集",datasetDTO); @RequestPart(value = "file", required = false) MultipartFile file){
datasetService.update(datasetDTO); log.info("修改数据集{}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
datasetService.update(datasetDTO,file);
return OptResult.success(); return OptResult.success();
} }
@ -72,4 +88,34 @@ public class DatasetController {
return OptResult.success("批量删除成功"); 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);
}
}
} }

@ -7,12 +7,10 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "模型评估相关接口") @Tag(name = "模型评估相关接口")
@CrossOrigin(origins = "http://localhost:3000")
@RestController @RestController
@RequestMapping("/evaluation") @RequestMapping("/evaluation")
@Slf4j @Slf4j

@ -1,32 +1,27 @@
package com.bipt.intelligentapplicationorchestrationservice.controller; package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO;
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService; import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping @RequestMapping("/gpu")
@CrossOrigin(origins = "http://localhost:3000")
public class GpuResourceController { public class GpuResourceController {
@Autowired @Autowired
private GpuManageService gpuManageService; private GpuManageService gpuManageService;
@PostMapping(value = "/add", produces = "application/json")
@PostMapping
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){ public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
return gpuManageService.createGpuResource(dto); return gpuManageService.createGpuResource(dto);
} }
@DeleteMapping("/{gpuId}") @DeleteMapping("/{gpuId}")
public ResponseVO removeGpu(@PathVariable("gpuId") Long gpuId){ public ResponseVO removeGpu(@PathVariable("gpuId") Long gpuId){
return gpuManageService.deleteGpuResource(gpuId); return gpuManageService.deleteGpuResource(gpuId);
} }
@PutMapping("/{gpuId}") @PutMapping("/{gpuId}")
public void updateGpuResource( public void updateGpuResource(
@PathVariable Long gpuId, @PathVariable Long gpuId,
@ -34,15 +29,12 @@ public class GpuResourceController {
dto.setGPUId(gpuId); dto.setGPUId(gpuId);
gpuManageService.updateGpuResource(dto); gpuManageService.updateGpuResource(dto);
} }
@GetMapping("/search") @GetMapping("/search")
public ResponseVO<List<GpuResponseDTO>> searchGpuResources( public ResponseVO<List<GpuResponseDTO>> searchGpuResources(
@RequestParam(required = false) String model, @RequestParam(required = false) String model,
@RequestParam(required = false) Integer memorySize, @RequestParam(required = false) Integer memorySize,
@RequestParam(required = false) String ip){ @RequestParam(required = false) String ip){
List<GpuResponseDTO> resources = gpuManageService.searchByCriteria(model, memorySize,ip); List<GpuResponseDTO> resources = gpuManageService.searchByCriteria(model, memorySize,ip);
return ResponseVO.success(resources); return ResponseVO.success(resources);
} }
} }

@ -1,5 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.controller; package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*; import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService; import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -52,14 +53,16 @@ public class ModelController {
} }
@Operation(summary = "模型更新") @Operation(summary = "模型更新")
@PutMapping("/updateModel") @PutMapping("/updateModel/{id}")
public OptResult updateModel(@RequestBody ModelVersionDTO dto){ public OptResult updateModel(@PathVariable("id") Long id, @RequestBody ModelVersionDTO dto) {
log.info("模型更新"); log.info("模型更新id: {}", id);
dto.setId(id);
modelService.updateModel(dto); modelService.updateModel(dto);
return OptResult.success(); return OptResult.success();
} }
@Operation(summary = "模型版本删除") @Operation(summary = "模型版本删除")
@DeleteMapping("/deleteModelVersion") @DeleteMapping("/deleteModelVersion")
public OptResult deleteModelVersion(Long id){ public OptResult deleteModelVersion(Long id){
@ -70,10 +73,18 @@ public class ModelController {
@Operation(summary = "更新生命周期") @Operation(summary = "更新生命周期")
@PutMapping("/updateLifeCycle") @PutMapping("/updateLifeCycle")
public OptResult updateLifeCycle(Long id,String lifeCycle){ public OptResult updateLifeCycle(@RequestParam Long id, @RequestParam String lifeCycle){
log.info("更新生命周期"); log.info("更新生命周期");
try {
modelService.updateLifeCycle(id,lifeCycle); modelService.updateLifeCycle(id,lifeCycle);
return OptResult.success(); return OptResult.success(MessageConstant.LIFECYCLE_UPDATE_SUCCESS);
} catch (IllegalArgumentException e) {
return OptResult.error(e.getMessage());
} catch (RuntimeException e) {
return OptResult.error(e.getMessage());
} catch (Exception e){
return OptResult.error(MessageConstant.UNKNOWN_ERROR);
}
} }
@Operation(summary = "查询生命周期列表") @Operation(summary = "查询生命周期列表")
@ -91,5 +102,31 @@ public class ModelController {
return OptResult.success(datasetList); return OptResult.success(datasetList);
} }
@Operation(summary = "获取模型训练信息")
@GetMapping("/getModelTrainInfo")
public OptResult getModelTrainInfo(Long id){
log.info("获取模型训练信息");
ModelTrainInfoVO modelTrainInfo = modelService.getModelTrainInfo(id);
return OptResult.success(modelTrainInfo);
}
@Operation(summary = "模型修改成训练中")
@PutMapping("/updateModelTrain")
public OptResult updateModelTrain(Long id){
log.info("模型修改成训练中");
modelService.updateModelTrain(id);
return OptResult.success();
}
@Operation(summary = "模型更新小版本")
@PutMapping("/updateModelVersionMinor")
public OptResult updateModelVersionMinor(@RequestBody ModelVersionDTO dto){
log.info("模型更新小版本");
modelService.updateModelVersionMinor(dto);
return OptResult.success();
}
} }

@ -1,11 +1,19 @@
package com.bipt.intelligentapplicationorchestrationservice.controller; package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelSelectVO;
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ServiceStatus;
import com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper;
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*; import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelDeployer;
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService; import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil; import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -17,6 +25,8 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/publish") @RequestMapping("/publish")
@Slf4j @Slf4j
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
public class PublishController { public class PublishController {
@Autowired @Autowired
private PublishService publishService; private PublishService publishService;
@ -24,21 +34,41 @@ public class PublishController {
@Autowired @Autowired
private NacosServiceUtil nacosServiceUtil; private NacosServiceUtil nacosServiceUtil;
@Autowired
private ModelMapper modelMapper;
@Autowired
private IpConfig ipConfig;
@Autowired
private ModelDeployer modelDeployer;
@Autowired
private PublishMapper publishMapper;
@PostMapping @PostMapping
@Operation(summary ="新增发布请求") @Operation(summary ="新增发布请求")
@Transactional @Transactional
public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) { public OptResult<List<ServicePublishVO>> save(@RequestBody ServicePublishDTO servicePublishDTO) {
log.info("模型发布请求:{}", servicePublishDTO); log.info("模型发布请求:{}", servicePublishDTO);
Long id = servicePublishDTO.getModelId();
Long ModelId = publishService.getModelId(id);
servicePublishDTO.setModelId(ModelId);
servicePublishDTO.setStatus(ServiceStatus.ONLINE.getCode());
publishService.save(servicePublishDTO); publishService.save(servicePublishDTO);
//todo 调用模型部署 //调用模型部署
DeployRequest request = new DeployRequest();
/* Long modelId = servicePublishDTO.getModelId();*/
ModelVersion modelVersion = publishMapper.selectByModelVersionId(id);
String modelConfig = modelVersion.getModelConfig();
//假设modelConfig只存GPU数据
request.setModelId(String.valueOf(ModelId));
request.setRequiredMemory(Integer.parseInt(modelConfig));
modelDeployer.deploy(request);
// 获取前端传来的IP字符串 // 获取前端传来的IP字符串
String ipListStr = servicePublishDTO.getIp(); String ipListStr = servicePublishDTO.getIp();
if (ipListStr == null || ipListStr.trim().isEmpty()) { if (ipListStr == null || ipListStr.trim().isEmpty()) {
log.warn("IP列表为空不进行Nacos注册"); log.warn("IP列表为空不进行Nacos注册");
return OptResult.success(); return OptResult.success();
} }
try { try {
// 使用逗号分割IP字符串 // 使用逗号分割IP字符串
String[] ipArray = ipListStr.split(","); String[] ipArray = ipListStr.split(",");
@ -59,15 +89,170 @@ public class PublishController {
log.error("Nacos服务注册失败", e); log.error("Nacos服务注册失败", e);
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误 return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
} }
return OptResult.success(); return OptResult.success();
} }
/**
* 获取已发布的服务列表
* @return
*/
@GetMapping("/list")
@Operation(summary ="获取已发布服务列表")
public OptResult<List<ServicePublishVO>> listPublishedServices() {
log.info("获取已发布服务列表接口被调用");
List<ServicePublishVO> services = publishService.listPublishedServices();
log.info("返回的数据: {}", services);
return OptResult.success(services);
}
/**
* 获取IP列表
* @return
*/
@GetMapping("/config/ips")
@Operation(summary = "获取可用IP地址列表")
public OptResult<List<String>> getAvailableIps() {
List<String> ips = ipConfig.getIps();
log.info("返回列表;{}",ips);
return OptResult.success(ips);
}
@GetMapping("/config/ids")
public OptResult<List<ModelSelectVO>> getModelNames() {
// 只获取状态为“在线”的模型列表(筛掉已下线的服务)
List<ModelSelectVO> modelSelectVOS = publishService.getOnlineModelNames();
/*List<ModelSelectVO> modelNames = publishService.getModelNames();*/
log.info("获取到在线模型列表:{}", modelSelectVOS);
return OptResult.success(modelSelectVOS);
}
@PostMapping("/online/{serviceId}")
@Operation(summary = "上线已下线的服务")
@Transactional
public OptResult<String> onlineService(@PathVariable Long serviceId) {
log.info("上线服务请求: {}", serviceId);
// 1. 从数据库获取服务信息,验证状态
ServicePublishVO service = publishService.getServiceById(serviceId);
if (service == null) {
return OptResult.error("服务不存在");
}
if (service.getStatus() == ServiceStatus.ONLINE.getCode()) {
return OptResult.error("服务已处于上线状态");
}
if (service.getStatus() != ServiceStatus.OFFLINE.getCode()) {
return OptResult.error("服务当前状态不支持上线操作");
}
// 2. 调用Nacos重新注册服务
try {
String[] ipArray = service.getIp().split(",");
for (String ip : ipArray) {
String trimmedIp = ip.trim();
if (!trimmedIp.isEmpty()) {
nacosServiceUtil.registerService(
service.getModelId().toString(),
trimmedIp,
8080,
service.getApiUrl()
);
log.info("Nacos服务重新注册成功: {}", trimmedIp);
}
}
} catch (Exception e) {
log.error("Nacos服务注册失败", e);
return OptResult.error("Nacos服务注册失败");
}
// 3. 更新数据库状态为“在线”
ServicePublishDTO updateDto = new ServicePublishDTO();
BeanUtils.copyProperties(service, updateDto);
updateDto.setStatus(ServiceStatus.ONLINE.getCode()); // 假设ONLINE状态码为1
publishService.updateServiceStatus(updateDto);
return OptResult.success("服务上线成功");
}
// 新增:服务下线接口
@DeleteMapping("/{serviceId}")
@Operation(summary = "下线已发布的服务")
@Transactional
public OptResult<String> offlineService(@PathVariable Long serviceId) {
log.info("下线服务请求: {}", serviceId);
// 1. 从数据库获取服务信息
ServicePublishVO service = publishService.getServiceById(serviceId);
if (service == null) {
return OptResult.error("服务不存在");
}
// 2. 调用 Nacos 下线服务
try {
String[] ipArray = service.getIp().split(",");
for (String ip : ipArray) {
String trimmedIp = ip.trim();
if (!trimmedIp.isEmpty()) {
nacosServiceUtil.deregisterService(
service.getModelId().toString(),
trimmedIp,
8080
);
log.info("Nacos服务下线成功: {}", trimmedIp);
}
}
} catch (Exception e) {
log.error("Nacos服务下线失败", e);
return OptResult.error("Nacos服务下线失败");
}
// 3. 修改数据库记录状态为0下线
ServicePublishDTO updateDto = new ServicePublishDTO();
BeanUtils.copyProperties(service, updateDto);
updateDto.setStatus(ServiceStatus.OFFLINE.getCode()); // 假设OFFLINE状态码为0
publishService.updateServiceStatus(updateDto);
return OptResult.success("服务下线成功");
}
// 新增:服务状态同步接口
@GetMapping("/sync")
@Operation(summary = "同步服务状态")
public OptResult<String> syncServiceStatus() {
log.info("开始同步服务状态...");
try {
// 1. 获取数据库中所有已上线的服务
List<ServicePublishVO> dbServices = publishService.listPublishedServicesByStatus(ServiceStatus.ONLINE.getCode());
// 2. 遍历每个服务,检查 Nacos 注册状态
for (ServicePublishVO service : dbServices) {
String serviceName = service.getModelId().toString();
String[] ipArray = service.getIp().split(",");
// 获取 Nacos 中注册的实例
List<String> nacosInstances = nacosServiceUtil.getServiceInstances(serviceName);
// 检查每个 IP 是否都在 Nacos 中注册
for (String ip : ipArray) {
String trimmedIp = ip.trim();
if (!trimmedIp.isEmpty() && !nacosInstances.contains(trimmedIp)) {
// 如果数据库中有但 Nacos 中没有,则重新注册
nacosServiceUtil.registerService(
serviceName,
trimmedIp,
8080,
service.getApiUrl()
);
log.info("重新注册服务到 Nacos: {}", trimmedIp);
}
}
}
log.info("服务状态同步完成");
return OptResult.success("服务状态同步完成");
} catch (Exception e) {
log.error("服务状态同步失败", e);
return OptResult.error("服务状态同步失败");
}
}
} }

@ -1,20 +1,15 @@
package com.bipt.intelligentapplicationorchestrationservice.controller; package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult; import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.service.ServiceAPIService; import com.bipt.intelligentapplicationorchestrationservice.service.ServiceAPIService;
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil; import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
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.List;
import java.util.Set; import java.util.Set;
@ -34,12 +29,18 @@ public class ServiceAPIController {
@Autowired @Autowired
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@PostMapping("/release") @PostMapping("/release")
@Operation(summary = "结束访问") @Operation(summary = "结束访问")
@Transactional @Transactional
public OptResult releaseResource(@PathVariable Long modelId) { public OptResult releaseResource(@PathVariable Long modelId) {
String key = "modelId:" + modelId; String key = "modelId:" + modelId;
String modelConfig = (String) redisTemplate.opsForValue().get(key); String modelConfig = (String) redisTemplate.opsForValue().get(key);
if (modelConfig == null) {
log.warn("尝试释放不存在的模型资源: {}", modelId);
return OptResult.error("模型资源不存在");
}
int userMemorySize = parseGpuMemorySize(modelConfig); int userMemorySize = parseGpuMemorySize(modelConfig);
List<String> instanceIps; List<String> instanceIps;
try { try {
@ -48,16 +49,31 @@ public class ServiceAPIController {
log.error("获取Nacos实例失败", e); log.error("获取Nacos实例失败", e);
return OptResult.error("获取实例失败"); return OptResult.error("获取实例失败");
} }
int memorySize;
boolean released = false;
for (String ip : instanceIps) { for (String ip : instanceIps) {
String ipKey = "ip:" + ip; String ipKey = "ip:" + ip;
Integer nowMemorySizeOBJ = (Integer) redisTemplate.opsForValue().get(ipKey); Integer nowMemorySizeOBJ = (Integer) redisTemplate.opsForValue().get(ipKey);
// 如果该IP没有记录则跳过可能资源分配记录已过期
if (nowMemorySizeOBJ == null) {
log.warn("IP {} 的资源记录不存在,可能已过期", ip);
continue;
}
int nowMemorySize = nowMemorySizeOBJ; int nowMemorySize = nowMemorySizeOBJ;
memorySize = nowMemorySize + userMemorySize; int newMemorySize = nowMemorySize + userMemorySize;
// 更新IP对应的资源值 // 更新IP对应的资源值
redisTemplate.opsForValue().set(ipKey, memorySize); redisTemplate.opsForValue().set(ipKey, newMemorySize);
// 设置缓存过期时间3600秒 // 设置缓存过期时间3600秒
redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS); redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS);
log.info("IP {} 释放 {} MB 资源,当前可用: {} MB", ip, userMemorySize, newMemorySize);
released = true;
}
if (!released) {
return OptResult.error("未找到匹配的资源记录");
} }
// 处理等待队列(先来先服务) // 处理等待队列(先来先服务)
@ -84,8 +100,10 @@ public class ServiceAPIController {
if (requestMemorySize == -1) { if (requestMemorySize == -1) {
return OptResult.error("解析配置失败,请检查模型:" + modelId +"是否存在"); return OptResult.error("解析配置失败,请检查模型:" + modelId +"是否存在");
} }
String modelConfigKey = "modelConfig:" + modelId; String modelConfigKey = "modelConfig:" + modelId;
redisTemplate.opsForValue().set(modelConfigKey, modelConfig); redisTemplate.opsForValue().set(modelConfigKey, modelConfig);
// 2. 获取Nacos实例IP列表 // 2. 获取Nacos实例IP列表
List<String> instanceIps; List<String> instanceIps;
try { try {
@ -94,7 +112,13 @@ public class ServiceAPIController {
log.error("获取Nacos实例失败", e); log.error("获取Nacos实例失败", e);
return OptResult.error("获取实例失败"); return OptResult.error("获取实例失败");
} }
Set<String> gpuKeys = redisTemplate.keys("gpu:*"); Set<String> gpuKeys = redisTemplate.keys("gpu:*");
if (gpuKeys == null || gpuKeys.isEmpty()) {
log.error("未找到可用的GPU资源");
return OptResult.error("系统无可用GPU资源");
}
// 根据IP列表查找资源 // 根据IP列表查找资源
for (String instanceIp : instanceIps) { for (String instanceIp : instanceIps) {
for (String gpuKey : gpuKeys) { for (String gpuKey : gpuKeys) {
@ -103,7 +127,7 @@ public class ServiceAPIController {
// 分割键值对 // 分割键值对
String[] pairs = GPUConfig.split(","); String[] pairs = GPUConfig.split(",");
String ip = null; String ip = null;
int memorySize = 0; int totalMemorySize = 0;
for (String pair : pairs) { for (String pair : pairs) {
String[] keyValue = pair.split(":", 2); String[] keyValue = pair.split(":", 2);
if (keyValue.length == 2) { if (keyValue.length == 2) {
@ -112,27 +136,48 @@ public class ServiceAPIController {
if ("IP".equalsIgnoreCase(key)) { if ("IP".equalsIgnoreCase(key)) {
ip = value; ip = value;
} else if ("GPUMemorySize".equalsIgnoreCase(key)) { } else if ("GPUMemorySize".equalsIgnoreCase(key)) {
memorySize = Integer.parseInt(value); totalMemorySize = Integer.parseInt(value);
} }
} }
} }
// 检查解析出的 IP 是否在 Nacos 实例列表中 // 检查解析出的 IP 是否在 Nacos 实例列表中
if (instanceIp.equals(ip)) { if (instanceIp.equals(ip)) {
log.info("找到 IP {} 对应的 GPU 内存: {} ", ip, memorySize); log.info("找到 IP {} 对应的 GPU 内存: {} MB", ip, totalMemorySize);
if (memorySize>=requestMemorySize){
int newMemorySize = memorySize - requestMemorySize; // 获取当前可用内存
String ipKey = "ip:" + ip; String ipKey = "ip:" + ip;
Integer currentAvailable = (Integer) redisTemplate.opsForValue().get(ipKey);
// 如果没有记录,则初始化为总内存
if (currentAvailable == null) {
currentAvailable = totalMemorySize;
redisTemplate.opsForValue().set(ipKey, currentAvailable);
log.info("IP {} 首次使用,初始可用内存: {} MB", ip, currentAvailable);
}
// 检查可用内存是否足够
if (currentAvailable >= requestMemorySize) {
int newMemorySize = currentAvailable - requestMemorySize;
redisTemplate.opsForValue().set(ipKey, newMemorySize); redisTemplate.opsForValue().set(ipKey, newMemorySize);
// 访问请求最大时间为3600s // 访问请求最大时间为3600s
redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS); redisTemplate.expire(ipKey, 3600, TimeUnit.SECONDS);
}
// 记录模型与IP的绑定关系
redisTemplate.opsForValue().set("modelId:" + modelId, modelConfig);
log.info("IP {} 分配成功,分配前可用: {} MB分配后可用: {} MB",
ip, currentAvailable, newMemorySize);
return OptResult.success("资源分配成功使用ip:" + ip); return OptResult.success("资源分配成功使用ip:" + ip);
} else { } else {
log.info("资源不足"); log.info("IP {} 资源不足,当前可用: {} MB请求: {} MB",
ip, currentAvailable, requestMemorySize);
} }
} }
} }
} }
}
// 所有实例检查完毕未找到足够资源 // 所有实例检查完毕未找到足够资源
String waitQueueKey = "waitQueue:" + modelId; String waitQueueKey = "waitQueue:" + modelId;
// 改为右插入保证队列顺序为FIFO最早的任务在列表头部 // 改为右插入保证队列顺序为FIFO最早的任务在列表头部
@ -140,12 +185,13 @@ public class ServiceAPIController {
log.info("未找到足够资源,任务 {} 加入等待队列", modelId); log.info("未找到足够资源,任务 {} 加入等待队列", modelId);
return OptResult.error("资源不足,等待中"); return OptResult.error("资源不足,等待中");
} }
/** /**
* 从模型配置字符串中解析GPU内存需求 * 从模型配置字符串中解析GPU内存需求
* @param modelConfig 模型配置字符串,格式如 "GPUMemorySize:8000,version:1" * @param modelConfig 模型配置字符串,格式如 "GPUMemorySize:8000,version:1"
* @return 解析到的GPU内存大小MB若解析失败返回-1 * @return 解析到的GPU内存大小MB若解析失败返回-1
*/ */
private int parseGpuMemorySize(String modelConfig) { public int parseGpuMemorySize(String modelConfig) {
if (modelConfig == null || modelConfig.isEmpty()) { if (modelConfig == null || modelConfig.isEmpty()) {
log.error("模型配置为空无法解析GPU内存需求"); log.error("模型配置为空无法解析GPU内存需求");
return -1; return -1;
@ -177,5 +223,4 @@ public class ServiceAPIController {
} }
return requestMemorySize; return requestMemorySize;
} }
} }

@ -1,12 +0,0 @@
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,87 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import java.util.Objects;
public class DeployRequest {
private String modelId;
private int requiredMemory;
private DeployType deployType;
private ModelInfo modelInfo;
// 部署类型枚举
public enum DeployType {
NORMAL,
GRAY
}
// 默认构造函数
public DeployRequest() {
}
public DeployRequest(String modelId, int requiredMemory, DeployType deployType, ModelInfo modelInfo) {
this.modelId = modelId;
this.requiredMemory = requiredMemory;
this.deployType = deployType;
this.modelInfo = modelInfo;
}
// Getter & Setter 方法
public String getModelId() {
return modelId;
}
public void setModelId(String modelId) {
this.modelId = modelId;
}
public int getRequiredMemory() {
return requiredMemory;
}
public void setRequiredMemory(int requiredMemory) {
this.requiredMemory = requiredMemory;
}
public DeployType getDeployType() {
return deployType;
}
public void setDeployType(DeployType deployType) {
this.deployType = deployType;
}
public ModelInfo getModelInfo() {
return modelInfo;
}
public void setModelInfo(ModelInfo modelInfo) {
this.modelInfo = modelInfo;
}
// Equals 和 HashCode 方法
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeployRequest that = (DeployRequest) o;
return requiredMemory == that.requiredMemory &&
Objects.equals(modelId, that.modelId) &&
deployType == that.deployType &&
Objects.equals(modelInfo, that.modelInfo);
}
@Override
public int hashCode() {
return Objects.hash(modelId, requiredMemory, deployType, modelInfo);
}
// toString 方法
@Override
public String toString() {
return "DeployRequest{" +
"modelId='" + modelId + '\'' +
", requiredMemory=" + requiredMemory +
", deployType=" + deployType +
", modelInfo=" + modelInfo +
'}';
}
}

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.deploy.entity; package com.bipt.intelligentapplicationorchestrationservice.entity;
public class DeployResponse<T> { public class DeployResponse<T> {
private boolean isSuccess; private boolean isSuccess;

@ -0,0 +1,15 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import lombok.Getter;
@Getter
//@AllArgsConstructor
public class DeploymentResource {
private final GpuResource gpu;
private final String url;
public DeploymentResource(GpuResource gpu, String url) {
this.gpu = gpu;
this.url = url;
}
}

@ -0,0 +1,16 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;
@Component
@Mapper(componentModel = "spring")
public interface GpuMapper {
GpuResource toEntity(GpuCreateDTO dto);
GpuResource toEntity(GpuUpdateDTO dto);
GpuResource toEntity(GpuResponseDTO dto);
GpuResponseDTO toDTO(GpuResource entity);
}

@ -0,0 +1,111 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.*;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@Setter
@Getter
public class GpuResource {
@TableField("GPUId")
private Long GPUId;
@TableField("GPUModel")
private String GPUModel;
@TableField("GPUMemorySize")
private Integer GPUMemorySize;
@TableField("is_deleted")
private Integer isDeleted = 0;
@TableField("Ip")
private String Ip;
@TableField("created_time")
private LocalDateTime createTime;
@TableField("update_time")
private LocalDateTime UpdateTime;
@TableField("GPUMaxMemory")
private Integer GPUMaxMemory;
public GpuResource(long l, String s, boolean b) {
this.GPUId = l;
this.GPUModel = s;
this.isDeleted = b ? 1 : 0;
}
// public @Pattern(regexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$") String getIp() {
// return Ip;
// }
public Boolean getIsDeleted() {
return isDeleted != 0;
}
public GpuResource(Long Id, String GPUModel, Integer GPUMemorySize, String ip, LocalDateTime create_time) {
this.GPUId = Id;
this.GPUModel = GPUModel;
this.GPUMemorySize = GPUMemorySize;
this.Ip = ip;
this.createTime = create_time;
}
public GpuResource() {}
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
public Long getGPUId() {
return GPUId;
}
public String getGPUModel() {
return GPUModel;
}
public String getIp() {
return Ip;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public Integer getGPUMaxMemory() {
return GPUMaxMemory;
}
public void setGPUId(Long GPUId) {
this.GPUId = GPUId;
}
public void setGPUModel(String GPUModel) {
this.GPUModel = GPUModel;
}
public void setGPUMemorySize(Integer GPUMemorySize) {
this.GPUMemorySize = GPUMemorySize;
}
public void setIsDeleted(Integer isDeleted) {
this.isDeleted = isDeleted;
}
public void setIp(String ip) {
Ip = ip;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
}

@ -0,0 +1,79 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.bipt.intelligentapplicationorchestrationservice.service.RedisCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Repository
public class GpuResourceRepository {
// Redis键定义
// Redis键模式定义
private static final String GPU_KEY_PREFIX = "gpu:";
private final RedisCacheService redisCacheService;
@Autowired
public GpuResourceRepository(RedisCacheService redisCacheService) {
this.redisCacheService = redisCacheService;
}
/**
* 保存或更新GPU资源
* @param resource GPU资源对象
*/
public void save(GpuResource resource) {
redisCacheService.put(resource.getGPUId().toString(), resource);
}
/**
* 按ID查询GPU资源
* @param id GPU资源ID
* @return GPU资源对象可能为null
*/
public GpuResource findById(Long id) {
return redisCacheService.get(id.toString());
}
/**
public List<GpuResource> findByStatus(Status status) {
// 由于Redis存储结构不支持直接按属性查询需要通过keys + 过滤方式实现
// 注意生产环境中应考虑使用RedisSCAN替代KEYS此处为简写
Set<String> keys = redisCacheService.scanKeys(GPU_KEY_PREFIX + "*");
List<GpuResource> result = new ArrayList<>();
keys.forEach(key -> {
String gpuId = key.substring(GPU_KEY_PREFIX.length());
GpuResource resource = redisCacheService.get(gpuId);
if (resource != null && resource.getStatus() == status) {
result.add(resource);
}
});
return result;
}
public void updateStatus(Long gpuId, Status newStatus) {
GpuResource resource = findById(gpuId);
if (resource != null) {
resource.setStatus(newStatus);
save(resource);
}
}
*/
public List<GpuResource> findAll() {
Set<String> keys = redisCacheService.scanKeys("gpu:*");
return keys.stream()
.map(key -> {
String gpuId = key.substring(4); // 去除"gpu:"前缀
return redisCacheService.get(gpuId);
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}

@ -0,0 +1,102 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import java.util.Objects;
public class ModelInfo {
private String modelId;
private String modelName;
private String modelType;
private String preprocessScript;
private String modelFilePath;
private String storageLocation;
public String getModelId() {
return modelId;
}
public void setModelId(String modelId) {
this.modelId = modelId;
}
// Getter & Setter 方法
public String getModelName() {
return modelName;
}
public void setModelName(String modelName) {
this.modelName = modelName;
}
public String getModelType() {
return modelType;
}
public void setModelType(String modelType) {
this.modelType = modelType;
}
public String getPreprocessScript() {
return preprocessScript;
}
public void setPreprocessScript(String preprocessScript) {
this.preprocessScript = preprocessScript;
}
public String getModelFilePath() {
return modelFilePath;
}
public void setModelFilePath(String modelFilePath) {
this.modelFilePath = modelFilePath;
}
public void setStorageLocation(String storageLocation) {
// 验证路径格式
if (storageLocation != null && !isValidStoragePath(storageLocation)) {
throw new IllegalArgumentException("无效的存储路径: " + storageLocation);
}
this.storageLocation = storageLocation;
}
private boolean isValidStoragePath(String path) {
// 1. 基本非空检查
if (path == null || path.trim().isEmpty()) return false;
// 2. 防止路径遍历攻击
if (path.contains("..")) return false;
// 3. 仅允许合法路径格式
return path.startsWith("/") ||
path.startsWith("s3://") ||
path.matches("[a-zA-Z]:\\\\"); // Windows 路径
}
// Equals 和 HashCode 方法
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ModelInfo modelInfo = (ModelInfo) o;
return Objects.equals(modelName, modelInfo.modelName) &&
Objects.equals(modelType, modelInfo.modelType) &&
Objects.equals(preprocessScript, modelInfo.preprocessScript) &&
Objects.equals(modelFilePath, modelInfo.modelFilePath);
}
@Override
public int hashCode() {
return Objects.hash(modelName, modelType, preprocessScript, modelFilePath);
}
// toString 方法
@Override
public String toString() {
return "ModelInfo{" +
"modelName='" + modelName + '\'' +
", modelType='" + modelType + '\'' +
", preprocessScript='" + preprocessScript + '\'' +
", modelFilePath='" + modelFilePath + '\'' +
'}';
}
}

@ -0,0 +1,10 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
import lombok.Data;
@Data
public class ModelSelectVO {
private Long modelId; // 模型ID即modelId对应ModelVersion的id
private String modelName; // 模型名称(如"图像识别模型"
private String version; // 版本信息(如"v1.0.0"
}

@ -1,96 +0,0 @@
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;
// }
}

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.entity.enums; package com.bipt.intelligentapplicationorchestrationservice.enumeration;
import lombok.Getter; import lombok.Getter;
@ -19,7 +19,8 @@ public enum ErrorCodeEnum {
DB_CONNECTION_FAILED(701, "数据库连接错误"), DB_CONNECTION_FAILED(701, "数据库连接错误"),
VALIDATION_ERROR(801,"参数校验异常" ), VALIDATION_ERROR(801,"参数校验异常" ),
CACHE_INIT_ERROR(901, "缓存初始化失败"); CACHE_INIT_ERROR(901, "缓存初始化失败"),
INTERNAL_SERVER_ERROR(201,"内部服务出错" );
public int getCode() { public int getCode() {
return code; return code;

@ -0,0 +1,31 @@
package com.bipt.intelligentapplicationorchestrationservice.enumeration;
public enum ServiceStatus {
OFFLINE(0, "下线"),
ONLINE(1, "上线");
private final int code;
private final String description;
ServiceStatus(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static ServiceStatus fromCode(int code) {
for (ServiceStatus status : ServiceStatus.values()) {
if (status.code == code) {
return status;
}
}
throw new IllegalArgumentException("未知的状态码: " + code);
}
}

@ -0,0 +1,27 @@
package com.bipt.intelligentapplicationorchestrationservice.exception;
public class DeployException extends RuntimeException{
// 错误代码
private int errorCode = 500;
public DeployException(String message) {
super(message);
}
public DeployException(String message, Throwable cause) {
super(message, cause);
}
public DeployException(Throwable cause) {
super(cause);
}
public DeployException(String message, int errorCode) {
super(message);
this.errorCode = errorCode;
}
public int getErrorCode() {
return errorCode;
}
}

@ -0,0 +1,13 @@
package com.bipt.intelligentapplicationorchestrationservice.exception;
public class EvaluationFailedException extends DeployException{
public EvaluationFailedException(String message) {
super(message);
}
public EvaluationFailedException(String message, Throwable cause) {
super(message, cause);
}
public EvaluationFailedException() {
super("模型评估未通过,无法部署");
}
}

@ -1,7 +1,7 @@
package com.bipt.intelligentapplicationorchestrationservice.exception; package com.bipt.intelligentapplicationorchestrationservice.exception;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum; import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;

@ -1,6 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.exception; package com.bipt.intelligentapplicationorchestrationservice.exception;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum; import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import lombok.Getter; import lombok.Getter;
@Getter @Getter

@ -29,4 +29,12 @@ public interface AlgorithmInfoMapper {
@Delete("DELETE FROM algorithm_info WHERE id = #{id}") @Delete("DELETE FROM algorithm_info WHERE id = #{id}")
int deleteById(Long 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);
} }

@ -5,14 +5,14 @@ import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelLogVO;
public interface EvaluationMapper { public interface EvaluationMapper {
/* /*
* 查询模型评估日志详情 * 查询模型评估日志详情
* @param id 模型评估日志id * @param id 模型版本id
* @return 模型评估日志详情 * @return 模型评估日志详情
*/ */
ModelLogVO selectLogDetail(Long id); ModelLogVO selectLogDetail(Long id);
/* /*
* 更新模型评估日志状态(评估通过则上线) * 更新模型评估日志状态(评估通过则上线)
* @param id 模型评估日志id * @param id 模型版本id
* @param status 模型评估日志状态 * @param status 模型评估日志状态
*/ */
void update(Long id, Integer status); void update(Long id, Integer status);

@ -1,16 +0,0 @@
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);
}

@ -1,6 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper; package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL; import org.apache.ibatis.jdbc.SQL;
@ -12,7 +12,7 @@ import java.util.Map;
public interface GpuResourceDao { public interface GpuResourceDao {
//---------------------- 基础CRUD ------------------------ //---------------------- 基础CRUD ------------------------
@Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " + @Insert("INSERT INTO Ipz.public.gpu_resource (GPUModel, GPUMemorySize, Ip) " +
"VALUES (#{model}, #{memory}, #{ip})") "VALUES (#{GPUModel}, #{GPUMemorySize}, #{Ip})")
@Options(useGeneratedKeys = true, keyProperty = "GPUId") @Options(useGeneratedKeys = true, keyProperty = "GPUId")
Integer insert(GpuResource entity); Integer insert(GpuResource entity);
@ -27,7 +27,7 @@ public interface GpuResourceDao {
Integer isDeleted(@Param("gpuId") Long gpuId); Integer isDeleted(@Param("gpuId") Long gpuId);
@Update("UPDATE Ipz.public.gpu_resource " + @Update("UPDATE Ipz.public.gpu_resource " +
"SET GPUModel = #{model}, GPUMemorySize = #{memory}, Ip = #{ip} " + "SET GPUModel = #{GPUModel}, GPUMemorySize = #{GPUMemorySize}, Ip = #{Ip} " +
"WHERE GPUId = #{GPUId}") "WHERE GPUId = #{GPUId}")
Integer updateById(GpuResource entity); Integer updateById(GpuResource entity);

@ -76,4 +76,19 @@ public interface ModelMapper {
*/ */
@Select("select dataset_id,dataset_name from dataset") @Select("select dataset_id,dataset_name from dataset")
List<DatasetEntity> listDataset(); List<DatasetEntity> listDataset();
/**
* 获取模型训练信息
* @param id 模型版本表id
* 返回模型训练信息
*/
ModelTrainInfoVO getModelTrainInfo(Long id);
/**
* 获取模型版本信息
* @param modelId
* @return
*/
ModelVersion selectByModelId(Long modelId);
} }

@ -1,10 +1,15 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper; package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelSelectVO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion; import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper @Mapper
public interface PublishMapper { public interface PublishMapper {
@ -15,5 +20,46 @@ public interface PublishMapper {
Long getByApiUrl(String apiUrl); Long getByApiUrl(String apiUrl);
@Select("SELECT * FROM service_publish")
List<ServicePublishVO> listPublishedServices();
@Select("SELECT " +
"mv.model_id AS modelId, " +
"m.model_name AS modelName, " +
"mv.version AS version " +
"FROM model_version mv " +
"LEFT JOIN model_info m ON mv.model_id = m.id")
List<ModelSelectVO> selectModelSelectList();
// 根据ID查询服务移除update_time和deleted字段
@Select("SELECT id, model_id, api_url, ip, create_time " +
"FROM service_publish WHERE id = #{serviceId}")
ServicePublishVO getServiceById(Long serviceId);
void updateStatus(Long id, int status);
List<ServicePublishVO> selectByStatus(Integer status);
@Select("SELECT " +
"mv.id AS modelId, " +
/*"mv.model_id AS modelId, " +*/
"m.model_name AS modelName, " +
"mv.version AS version " +
"FROM model_version mv " +
"LEFT JOIN model_info m ON mv.model_id = m.id " +
"WHERE mv.model_id NOT IN ( " +
" SELECT DISTINCT model_id " +
" FROM service_publish " +
" WHERE status = #{code} " +
")")
List<ModelSelectVO> selectModelNamesByStatus(int code);
@Select("select model_id from model_version where id=#{id}")
Long getByMdVersionId(Long id);
/**
* 根据modelversionId查询Modelversion信息
* @param id
* @return
*/
@Select("select * from model_version where id = #{id}")
ModelVersion selectByModelVersionId(Long id);
} }

@ -84,4 +84,8 @@ public class AlgorithmInfo {
public void setFileSize(Long fileSize) { public void setFileSize(Long fileSize) {
this.fileSize = fileSize; this.fileSize = fileSize;
} }
public String getFilePath() {
return algorithmFile;
}
} }

@ -19,6 +19,7 @@ public class DatasetDTO implements Serializable {
private Long datasetId; private Long datasetId;
private String datasetName; private String datasetName;
private int datasetType; private int datasetType;
private int datasetStatus;
private String dsPath; private String dsPath;
// private Map<String,String> args; // private Map<String,String> args;
private String args; private String args;

@ -20,11 +20,11 @@ public class DatasetPageQueryDTO implements Serializable{
private int page; private int page;
private int pageSize; private int pageSize;
private String datasetName; private String datasetName;
private int datasetType; /* private int datasetType;
private int datasetStatus; private int datasetStatus;
private String dsPath; private String dsPath;
private String args; private String args;
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;*/
} }

@ -17,6 +17,7 @@ import java.util.Map;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class DatasetVO implements Serializable { public class DatasetVO implements Serializable {
private Long datasetId;
private String datasetName; private String datasetName;
private Integer datasetType; private Integer datasetType;
private Integer datasetStatus; private Integer datasetStatus;

@ -1,5 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.entity.dto; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
@ -14,14 +15,17 @@ public class GpuCreateDTO {
@NotBlank(message = "GPU型号不能为空") @NotBlank(message = "GPU型号不能为空")
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+", @Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
@JsonProperty("GPUModel") // 显示指定JSON映射名称
private String GPUModel; private String GPUModel;
@NotNull(message = "显存容量不能为空") @NotNull(message = "显存容量不能为空")
@JsonProperty("GPUMemorySize")
private Integer GPUMemorySize; private Integer GPUMemorySize;
@NotBlank(message = "IP地址不能为空") @NotBlank(message = "IP地址不能为空")
@Pattern(regexp = "^\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}$", @Pattern(regexp = "^(\\d{1,3}\\.){3}\\d{1,3}$",
message = "IP地址格式无效") message = "IP地址格式无效")
@JsonProperty("Ip") // 显示指定JSON映射名称
private String Ip; private String Ip;
} }

@ -1,23 +1,30 @@
package com.bipt.intelligentapplicationorchestrationservice.entity.dto; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Data @Data
public class GpuResponseDTO { public class GpuResponseDTO {
private Long id; @JsonView
private Long GPUId;
private String GPUModel; private String GPUModel;
private Integer GPUMemorySize; private Integer GPUMemorySize;
private String Ip; private String Ip;
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createTime; private LocalDateTime createTime;
// Builder类 // Builder类
public static class Builder { public static class Builder {
private Long id; private Long id;
private String model; private String model;
private Integer memory; private Integer memory;
private String ip; private String ip;
private LocalDateTime createdTime; private LocalDateTime createTime = LocalDateTime.now(); // 统一命名为createTime
public Builder id(Long id) { public Builder id(Long id) {
this.id = id; this.id = id;
@ -39,19 +46,29 @@ public class GpuResponseDTO {
return this; return this;
} }
public Builder createdTime(LocalDateTime createdTime) { public Builder createTime(LocalDateTime createTime) {
this.createdTime = createdTime; this.createTime = createTime;
return this; return this;
} }
public GpuResponseDTO build() { public GpuResponseDTO build() {
// 必填字段校验如网页2的推荐 // 必填字段校验
if (id == null) { if (id == null) {
throw new IllegalArgumentException("GPU ID必须填写"); throw new IllegalArgumentException("GPU ID必须填写");
} }
return new GpuResponseDTO();
GpuResponseDTO dto = new GpuResponseDTO();
dto.setGPUId(id);
dto.setGPUModel(model);
dto.setGPUMemorySize(memory);
dto.setIp(ip);
dto.setCreateTime(createTime); // 正确赋值createTime
return dto;
} }
} }
public String getCreateTimeStr() { public String getCreateTimeStr() {
return "GPU创建时间" + createTime.toString(); return "GPU创建时间" + (createTime != null ? createTime.toString() : "未设置");
} }
} }

@ -1,5 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.entity.dto; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
import lombok.*; import lombok.*;
@ -7,14 +8,36 @@ import lombok.*;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
//@Setter @Setter
//@Getter @Getter
public class GpuUpdateDTO { public class GpuUpdateDTO {
public @NotNull(message = "GPU ID cannot be null") Long getGPUId() {
return GPUId; private Long GPUId;
public @Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") String getGPUModel() {
return GPUModel;
} }
public void setGPUId(@NotNull(message = "GPU ID cannot be null") Long GPUId) { public @Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效") String getIp() {
return Ip;
}
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+",
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU")
@JsonProperty("GPUModel") // 显示指定JSON映射名称
private String GPUModel;
@JsonProperty("GPUMemorySize") // 显示指定JSON映射名称
private Integer GPUMemorySize;
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效")
@JsonProperty("Ip") // 显示指定JSON映射名称
private String Ip;
public void setGPUId(Long GPUId) {
this.GPUId = GPUId; this.GPUId = GPUId;
} }
@ -27,18 +50,15 @@ public class GpuUpdateDTO {
message = "IP地址格式无效") String ip) { message = "IP地址格式无效") String ip) {
Ip = ip; Ip = ip;
} }
public Long getGPUId() {
@NotNull(message = "GPU ID cannot be null") return GPUId;
private Long GPUId; }
@Pattern(regexp = "^([A-Z][A-Z0-9-]+)-\\w+", public Integer getGPUMemorySize() {
message = "型号格式应为 [厂商(大写字母开头)]-[型号],如 Intel-Xe_GPU") return GPUMemorySize;
private String GPUModel; }
@Setter public void setGPUMemorySize(Integer GPUMemorySize) {
private Integer GPUMemorySize; this.GPUMemorySize = GPUMemorySize;
}
@Pattern(regexp = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$",
message = "IP地址格式无效")
private String Ip;
} }

@ -17,7 +17,7 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
public class ModelEvaluation implements Serializable { public class ModelEvaluation implements Serializable {
private Long id; // 评估记录id private Long id; // 评估记录id
private Long modelId; // 关联模型id private Long modelVersionId; // 关联模型id,后续修改成了模型版本id
private LocalDateTime evaluationTime; // 评估时间 private LocalDateTime evaluationTime; // 评估时间
private String evaluationResult; // 评估结果 private String evaluationResult; // 评估结果
private String operator; // 评估操作人员 private String operator; // 评估操作人员

@ -0,0 +1,18 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ModelTrainInfoVO {
private Long id;
private Integer datasetId; // 数据集id
private String modelConfig; // 模型配置信息
private String dsPath;// 版本信息表id
private String dataPreHandleFile; // 数据预处理文件存储路径
}

@ -11,7 +11,8 @@ import java.time.LocalDateTime;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ModelVersionDTO { public class ModelVersionDTO {
private Long id; // 模型id private Long id; // 模型版本id
private Long modelId; // 模型id
private String version; // 模型版本 private String version; // 模型版本
private Integer datasetId; // 数据集id private Integer datasetId; // 数据集id
private String modelConfig; // 模型配置信息 private String modelConfig; // 模型配置信息

@ -1,6 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.entity.vo; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum; import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import java.io.Serializable; import java.io.Serializable;
@ -35,4 +35,28 @@ public class ResponseVO<T> implements Serializable {
public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) { public static <T> ResponseVO<T> error(ErrorCodeEnum errorCode) {
return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null); return new ResponseVO<>(errorCode.getCode(), errorCode.getMessage(), null);
} }
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
} }

@ -22,4 +22,5 @@ public class ServicePublishDTO implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime; private LocalDateTime createTime;
private String ip; private String ip;
private int status;
} }

@ -16,11 +16,13 @@ import java.time.LocalDateTime;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ServicePublishVO implements Serializable { public class ServicePublishVO implements Serializable {
private Long id;
private Long modelId; private Long modelId;
private String GPUModel; /*private String GPUModel;*/
private String ip; private String ip;
private String GPUMemorySize; /* private String GPUMemorySize;*/
private String apiUrl; private String apiUrl;
private int status;
} }

@ -0,0 +1,16 @@
package com.bipt.intelligentapplicationorchestrationservice.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "aliyun.oss") // 读取以 aliyun.oss 开头的配置
public class AliOssProperties {
private String endpoint;
private String accessKeyId;
private String accessKeySecret;
private String bucketName;
}

@ -1,7 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo; import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List; import java.util.List;
public interface AlgorithmInfoService { public interface AlgorithmInfoService {
@ -12,6 +14,11 @@ public interface AlgorithmInfoService {
boolean delete(Long id); boolean delete(Long id);
boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo); boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo);
void save(AlgorithmInfo algorithmInfo); void save(AlgorithmInfo algorithmInfo, MultipartFile file);
String run(String scriptPath, List<String> args) throws IOException, InterruptedException;
List<String> getAllNames();
List<AlgorithmInfo> getByNameLike(String keyword);
} }

@ -2,9 +2,11 @@ package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao; import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.exception.CacheInitException; import com.bipt.intelligentapplicationorchestrationservice.exception.CacheInitException;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
@ -18,7 +20,6 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@Transactional // 添加类级别事务管理
@Component @Component
public class CacheManager { public class CacheManager {
@Autowired @Autowired
@ -27,6 +28,9 @@ public class CacheManager {
@Autowired @Autowired
private GpuResourceDao gpuResourceDao; private GpuResourceDao gpuResourceDao;
@Autowired
private ObjectMapper objectMapper; // 注入ObjectMapper用于类型转换
private final ReentrantLock lock = new ReentrantLock(); private final ReentrantLock lock = new ReentrantLock();
@Value("${cache.redis-key-prefix:gpu:}") @Value("${cache.redis-key-prefix:gpu:}")
@ -38,9 +42,9 @@ public class CacheManager {
@Value("${cache.init-batch-size:500}") @Value("${cache.init-batch-size:500}")
private int initBatchSize; private int initBatchSize;
private static final Logger log = org.slf4j.LoggerFactory.getLogger(CacheManager.class); private static final Logger log = LoggerFactory.getLogger(CacheManager.class);
// 全量加载(带分页和分布式锁) // 全量加载(带分页和分布式锁)
@Transactional(propagation = Propagation.REQUIRED) // 方法级别覆盖
@PostConstruct @PostConstruct
public void loadFullCache() { public void loadFullCache() {
if (tryLock()) { if (tryLock()) {
@ -82,16 +86,12 @@ public class CacheManager {
// 带随机TTL的缓存设置 // 带随机TTL的缓存设置
private void setCacheWithTTL(GpuResource entity) { private void setCacheWithTTL(GpuResource entity) {
String key = buildKey(entity.getGPUId().toString()); 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( redisTemplate.opsForValue().set(
key, key,
entity, entity,
ttlBase + (int)(Math.random() * 600), // 随机TTL防止雪崩 ttlBase + (int)(Math.random() * 600),
TimeUnit.SECONDS TimeUnit.SECONDS
); );
} }
@ -114,6 +114,7 @@ public class CacheManager {
private void unlock() { private void unlock() {
lock.unlock(); lock.unlock();
} }
// 分页加载入口 // 分页加载入口
public void loadFullCache(int batchSize) { public void loadFullCache(int batchSize) {
int page = 0; int page = 0;
@ -121,12 +122,11 @@ public class CacheManager {
List<GpuResource> batch = gpuResourceDao.findByPage(page * batchSize, batchSize); List<GpuResource> batch = gpuResourceDao.findByPage(page * batchSize, batchSize);
if (batch.isEmpty()) break; if (batch.isEmpty()) break;
batch.forEach(this::refreshWithRetry); // 带重试的刷新逻辑 batch.forEach(this::refreshWithRetry);
page++; page++;
} }
} }
// 带重试机制的缓存刷新 // 带重试机制的缓存刷新
public void refreshWithRetry(GpuResource entity) { public void refreshWithRetry(GpuResource entity) {
try { try {
@ -135,7 +135,7 @@ public class CacheManager {
// 3次重试逻辑 // 3次重试逻辑
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
try { try {
log.info("重试第 {} 次", i + 1); // 添加日志 log.info("重试第 {} 次", i + 1);
Thread.sleep(1000); Thread.sleep(1000);
setCacheWithTTL(entity); setCacheWithTTL(entity);
return; return;
@ -148,7 +148,6 @@ public class CacheManager {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
} }
} }
@ -162,8 +161,35 @@ public class CacheManager {
redisTemplate.delete(key); redisTemplate.delete(key);
} }
// 修改获取缓存的方法,增加类型安全处理
@SuppressWarnings("unchecked")
public GpuResource getFromCache(String gpuId) { public GpuResource getFromCache(String gpuId) {
return (GpuResource) redisTemplate.opsForValue().get("gpu:" + gpuId); String key = buildKey(gpuId);
Object value = redisTemplate.opsForValue().get(key);
// 处理可能的类型不匹配问题
if (value == null) {
return null;
} }
try {
// 优先尝试直接转换
if (value instanceof GpuResource) {
return (GpuResource) value;
}
// 如果是LinkedHashMap使用ObjectMapper转换
else if (value instanceof java.util.LinkedHashMap) {
return objectMapper.convertValue(value, GpuResource.class);
}
// 其他情况尝试序列化后反序列化适用于JSON存储场景
else {
// 先序列化为JSON字符串再反序列化为对象
String json = objectMapper.writeValueAsString(value);
return objectMapper.readValue(json, GpuResource.class);
}
} catch (Exception e) {
log.error("获取缓存时类型转换失败key: {}, valueType: {}", key, value.getClass().getName(), e);
return null;
}
}
} }

@ -3,18 +3,22 @@ package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetPageQueryDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetPageQueryDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.PageResult; import com.bipt.intelligentapplicationorchestrationservice.pojo.PageResult;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
* @author hky * @author hky
*/ */
public interface DatasetService { 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); PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO);
void deleteBatch(List<Long> datasetIds); void deleteBatch(List<Long> datasetIds);
InputStream downloadDataset(Long datasetId);
} }

@ -1,9 +1,10 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@ -12,4 +13,7 @@ public interface GpuManageService {
public ResponseVO deleteGpuResource(Long gpuId); public ResponseVO deleteGpuResource(Long gpuId);
public void updateGpuResource(GpuUpdateDTO entity); public void updateGpuResource(GpuUpdateDTO entity);
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip); public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip);
@Transactional
ResponseVO createGpuResourceWithTrace(GpuCreateDTO dto);
} }

@ -0,0 +1,33 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResourceRepository;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class GpuResourceService {
@Autowired
private GpuResourceRepository repository;
@Cacheable(value = "availableGpus")
public List<GpuResource> getAvailableResources() {
// 获取所有未删除的资源
return repository.findAll().stream()
.filter(gpu -> gpu.getIsDeleted() == null || !gpu.getIsDeleted())
.collect(Collectors.toList()); }
public void markAsAllocated(Long gpuId, int allocatedMemory) {
GpuResource gpu = repository.findById(gpuId);
if (gpu != null) {
// 更新已使用内存
int currentMemory = gpu.getGPUMemorySize() != null ? gpu.getGPUMemorySize() : 0;
gpu.setGPUMemorySize(currentMemory + allocatedMemory);
repository.save(gpu);
}
}
}

@ -0,0 +1,51 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
import com.bipt.intelligentapplicationorchestrationservice.exception.EvaluationFailedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GrayDeployService {
@Autowired
private ModelEvaluator modelEvaluator;
@Autowired
private ResourceAllocator resourceAllocator;
@Autowired
private GpuResourceService gpuService;
// @Autowired
// private MQSender mqSender;
public DeployResponse process(DeployRequest request) {
// 检查评估状态
if (!modelEvaluator.isEvaluationPassed(request.getModelId())) {
throw new EvaluationFailedException("模型评估未通过");
}
// 分配资源并获取URL
DeploymentResource resource = resourceAllocator.allocate(
gpuService.getAvailableResources(),
request.getRequiredMemory(),
request.getModelId(),
true
);
// // 发送MQ灰度通知
// mqSender.sendGrayDeployNotification(
// resource.getUrl(),
// request.getModelId(),
// resource.getGpu().getGPUId()
// );
// 标记资源已分配(更新内存使用量)
gpuService.markAsAllocated(
resource.getGpu().getGPUId(),
request.getRequiredMemory()
);
return DeployResponse.success(resource.getUrl());
}
}

@ -3,19 +3,36 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper; import com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo; import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService; import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
import jakarta.servlet.ServletContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
@Service @Service
@Slf4j
public class AlgorithmInfoServiceImpl implements AlgorithmInfoService { public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
@Autowired @Autowired
private AlgorithmInfoMapper algorithmInfoMapper; private AlgorithmInfoMapper algorithmInfoMapper;
// 从配置文件读取上传目录
@Value("${algorithm.upload.dir:algorithm_files}")
private String uploadDir;
@Override @Override
public AlgorithmInfo getById(Long id) { public AlgorithmInfo getById(Long id) {
return algorithmInfoMapper.selectById(id); return algorithmInfoMapper.selectById(id);
@ -62,21 +79,152 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
} }
/** /**
* 算法创建 * 新增算法
* @param algorithmInfo * @param algorithmInfo
* @param file
*/ */
@Override @Override
@Transactional @Transactional
public void save(AlgorithmInfo algorithmInfo) { public void save(AlgorithmInfo algorithmInfo, MultipartFile file) {
String algorithmName = algorithmInfo.getAlgorithmName(); String algorithmName = algorithmInfo.getAlgorithmName();
//查找表里是否有重复的算法,如果有则报错 // 检查同名算法
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName); AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
if (duplicateName != null) { if (duplicateName != null) {
throw new RuntimeException("算法已存在"); throw new RuntimeException("算法已存在,请去修改算法");
} }
//todo 算法文件分布式存入分布式存储中
if (file != null && !file.isEmpty()) {
try {
// 获取文件原始名称
String originalFilename = file.getOriginalFilename();
if (originalFilename == null || originalFilename.isEmpty()) {
throw new RuntimeException("文件名称为空");
}
// 生成唯一文件名,避免冲突
String fileName = UUID.randomUUID().toString() + "_" + originalFilename;
// 构建相对路径(相对于项目根目录)
Path relativePath = Paths.get(uploadDir, fileName);
// 获取当前应用的运行目录(兼容开发和部署环境)
Path basePath = Paths.get("").toAbsolutePath();
Path absolutePath = basePath.resolve(relativePath);
// 确保目录存在
Path parentDir = absolutePath.getParent();
if (!Files.exists(parentDir)) {
Files.createDirectories(parentDir);
log.info("已创建存储目录: {}", parentDir);
}
// 保存文件到指定路径
file.transferTo(absolutePath);
// 存储相对路径到数据库
algorithmInfo.setAlgorithmFile(relativePath.toString());
// 设置文件大小
algorithmInfo.setFileSize(Files.size(absolutePath));
log.info("文件保存成功 - 相对路径: {}, 绝对路径: {}",
relativePath, absolutePath);
} catch (Exception e) {
log.error("文件保存失败", e);
throw new RuntimeException("文件保存失败: " + e.getMessage(), e);
}
} else {
// 文件为空的处理逻辑
algorithmInfo.setAlgorithmFile(null);
algorithmInfo.setFileSize(0L);
}
algorithmInfo.setCreateTime(LocalDateTime.now());
// 保存算法信息到数据库
algorithmInfoMapper.insert(algorithmInfo); algorithmInfoMapper.insert(algorithmInfo);
} }
/**
* 执行Python算法脚本并返回结果
* @param scriptPath Python脚本路径数据库中存储的相对路径
* @param args 命令行参数列表
* @return 脚本执行结果
*/
public String run(String scriptPath, List<String> args) throws IOException, InterruptedException {
if (scriptPath == null || scriptPath.isEmpty()) {
throw new IllegalArgumentException("脚本路径不能为空");
}
// 获取当前应用的运行目录(兼容开发和部署环境)
Path basePath = Paths.get("").toAbsolutePath();
Path absoluteScriptPath = basePath.resolve(scriptPath);
// 验证文件是否存在
if (!Files.exists(absoluteScriptPath)) {
throw new FileNotFoundException("脚本文件不存在: " + absoluteScriptPath);
}
// 验证文件是否可执行针对Python脚本
if (!Files.isReadable(absoluteScriptPath)) {
throw new IOException("脚本文件不可读: " + absoluteScriptPath);
}
// 构建命令python [脚本绝对路径] [参数1] [参数2] ...
List<String> command = new ArrayList<>();
command.add("python"); // Python解释器路径可配置在application.properties中
command.add(absoluteScriptPath.toString()); // 使用绝对路径执行脚本
command.addAll(args); // 添加所有参数
// 打印完整命令(用于调试)
log.info("执行命令: {}", String.join(" ", command));
// 创建进程并执行命令
ProcessBuilder processBuilder = new ProcessBuilder(command);
// 设置工作目录为脚本所在目录
processBuilder.directory(absoluteScriptPath.getParent().toFile());
processBuilder.redirectErrorStream(true); // 将错误输出合并到标准输出
Process process = processBuilder.start();
// 读取脚本输出使用UTF-8编码避免中文乱码
StringBuilder output = new StringBuilder();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
}
// 等待进程执行完成并获取退出码
int exitCode = process.waitFor();
// 检查脚本是否成功执行
if (exitCode != 0) {
// 捕获详细的错误信息
String errorMsg = "脚本执行失败,退出码: " + exitCode +
"\n命令: " + String.join(" ", command) +
"\n输出: " + output.toString();
log.error(errorMsg);
throw new RuntimeException(errorMsg);
}
return output.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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID;
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.FROM_DATABASE; import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.FROM_DATABASE;
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.UPLOAD;
@Service @Service
@Slf4j @Slf4j
@ -25,63 +30,65 @@ public class DatasetServiceImpl implements DatasetService {
@Autowired @Autowired
private DatasetMapper datasetMapper; private DatasetMapper datasetMapper;
/**
* 新增数据集
* @param datasetDTO
*/
@Override @Override
@Transactional @Transactional
public void save(DatasetDTO datasetDTO) { public void save(DatasetDTO datasetDTO, MultipartFile file) {
//判断数据集类型,如果是本地上传则保存,若用调用数据仓库进入下一步
// 获取数据集类型
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType()); DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
// 根据类型处理数据 if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
switch (datasetType) { try {
case UPLOAD: //todo存入分布式文件系统
//TODO 保存到分布式文件系统
break;
case FROM_DATABASE:
String args = datasetDTO.getArgs();
//TODO 根据筛选条件调用数据仓库中的数据
//TODO 调用数据仓库保存到分布式文件系统 // 生成文件名(建议使用 UUID 避免重复)
break; String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
default: // 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType); 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(); DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO, datasetEntity); BeanUtils.copyProperties(datasetDTO, datasetEntity);
datasetEntity.setDatasetStatus(StatusConstant.ENABLE);
datasetEntity.setCreateTime(LocalDateTime.now()); datasetEntity.setCreateTime(LocalDateTime.now());
datasetEntity.setUpdateTime(LocalDateTime.now()); datasetEntity.setUpdateTime(LocalDateTime.now());
datasetMapper.insert(datasetEntity); datasetMapper.insert(datasetEntity);
} }
/** /**
* 修改数据集 * 修改数据集
* *
* @param datasetDTO * @param datasetDTO
* @param file
*/ */
@Override @Override
@Transactional @Transactional
public void update(DatasetDTO datasetDTO) { public void update(DatasetDTO datasetDTO, MultipartFile file) {
/*DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);*/
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType()); DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
// 根据类型处理数据 if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
switch (datasetType) { try {
case UPLOAD: // 生成文件名(建议使用 UUID 避免重复)
//TODO 覆盖保存到分布式文件系统中 String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
break; // 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
case FROM_DATABASE: String filePath = "/your/storage/path/" + fileName;
//TODO 覆盖数据文件 // 保存文件到磁盘(示例代码,需处理 IO 异常)
file.transferTo(new File(filePath));
break; // 更新数据集路径
default: datasetDTO.setDsPath(filePath); // 取消注释,并确保 datasetDTO 有 setDsPath 方法
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType); } catch (IOException e) {
throw new RuntimeException("文件上传失败: " + e.getMessage());
} }
} else if (datasetType == FROM_DATABASE){
//todo 从数据仓库中查询 并选择筛选条件
}
DatasetEntity datasetEntity = new DatasetEntity(); DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity); BeanUtils.copyProperties(datasetDTO,datasetEntity);
datasetEntity.setUpdateTime(LocalDateTime.now()); datasetEntity.setUpdateTime(LocalDateTime.now());
@ -112,4 +119,14 @@ public class DatasetServiceImpl implements DatasetService {
datasetMapper.deleteBatch(datasetIds); datasetMapper.deleteBatch(datasetIds);
} }
/**
* 下载
* @param datasetId
* @return
*/
@Override
public InputStream downloadDataset(Long datasetId) {
// TODO: 调用分布式存储系统的接口获取数据集文件的输入流
return null;
}
} }

@ -42,7 +42,7 @@ public class ModelServiceImpl implements ModelService {
modelVersion.setModelId(modelInfo.getId()); modelVersion.setModelId(modelInfo.getId());
modelVersion.setCreateTime(LocalDateTime.now()); modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now()); modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs"); modelVersion.setOperateUser("zs"); //这里的写死的后续需要修改应该是当前登录用户的id
modelMapper.insertModelVersion(modelVersion); modelMapper.insertModelVersion(modelVersion);
} }
@ -72,6 +72,10 @@ public class ModelServiceImpl implements ModelService {
return modelVOList; return modelVOList;
} }
/**
* 查询模型详情
* @param id
*/
@Override @Override
public ModelVersion detail(Long id) { public ModelVersion detail(Long id) {
log.info("查询模型详情"); log.info("查询模型详情");
@ -79,12 +83,23 @@ public class ModelServiceImpl implements ModelService {
return modelVersion; return modelVersion;
} }
/**
* 更新模型
* @param dto
*/
@Override @Override
public void updateModel(ModelVersionDTO dto) { public void updateModel(ModelVersionDTO dto) {
// TODO: 更新模型还需要更新操作人和时间
log.info("更新模型"); log.info("更新模型");
dto.setCreateTime(LocalDateTime.now());
dto.setUpdateTime(LocalDateTime.now());
modelMapper.update(dto); modelMapper.update(dto);
} }
/**
* 删除模型版本
* @param id
*/
@Override @Override
public void deleteModelVersion(Long id) { public void deleteModelVersion(Long id) {
log.info("删除模型版本"); log.info("删除模型版本");
@ -111,13 +126,13 @@ public class ModelServiceImpl implements ModelService {
ModelLifecycle targetLifeCycle; ModelLifecycle targetLifeCycle;
try { try {
currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文 currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文
targetLifeCycle = ModelLifecycle.fromDescription((lifeCycleDescription).trim()); // 前端传中文 targetLifeCycle = ModelLifecycle.valueOf(lifeCycleDescription.trim()); // 前端传英文代码,直接转换
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.error(MessageConstant.LifeCycle_Undefined + ":{}", e.getMessage()); log.error(MessageConstant.LifeCycle_Undefined + ":{}", e.getMessage());
throw e; throw e;
} }
// 2. 业务逻辑校验 // 2. 业务逻辑校验(保持不变)
switch (currentLifeCycle) { switch (currentLifeCycle) {
case DEPLOYED: case DEPLOYED:
if (targetLifeCycle == ModelLifecycle.DESIGNING) { if (targetLifeCycle == ModelLifecycle.DESIGNING) {
@ -142,12 +157,15 @@ public class ModelServiceImpl implements ModelService {
int affectedRows = modelMapper.updateLifeCycleById(id, targetLifeCycle.getDbValue()); int affectedRows = modelMapper.updateLifeCycleById(id, targetLifeCycle.getDbValue());
if (affectedRows == 0) { if (affectedRows == 0) {
log.error("更新模型生命周期失败"); log.error("更新模型生命周期失败");
throw new RuntimeException(MessageConstant.UPDATE_FAILURE); throw new RuntimeException(MessageConstant.LIFECYCLE_UPDATE_FAILURE);
} }
log.info("模型生命周期更新成功,新状态为: {}", targetLifeCycle); log.info("模型生命周期更新成功,新状态为: {}", targetLifeCycle);
} }
/**
* 获取模型生命周期列表
*/
@Override @Override
public List<Map<String, String>> listLifeCycle() { public List<Map<String, String>> listLifeCycle() {
return Arrays.stream(ModelLifecycle.values()) return Arrays.stream(ModelLifecycle.values())
@ -158,6 +176,9 @@ public class ModelServiceImpl implements ModelService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 获取模型数据集列表
*/
@Override @Override
public List<DatasetEntity> listDataset() { public List<DatasetEntity> listDataset() {
List<DatasetEntity> datasetEntityList = modelMapper.listDataset(); List<DatasetEntity> datasetEntityList = modelMapper.listDataset();
@ -165,4 +186,41 @@ public class ModelServiceImpl implements ModelService {
} }
/**
* 获取模型训练信息
* @param id
*/
@Override
public ModelTrainInfoVO getModelTrainInfo(Long id) {
ModelTrainInfoVO modelTrainInfoVO = modelMapper.getModelTrainInfo(id);
return modelTrainInfoVO;
}
/**
* 模型训练(把模型修改成训练中)
* @param id
*/
@Override
public void updateModelTrain(Long id) {
// 更新当前模型的生命周期为训练中
modelMapper.updateLifeCycleById(id, ModelLifecycle.TRAINING.getDbValue());
}
/**
* 模型小版本更新
* @param dto
*/
@Override
public void updateModelVersionMinor(ModelVersionDTO dto) {
// 更新模型小版本(其实是新增一个小版本)
ModelVersion modelVersion = new ModelVersion();
BeanUtils.copyProperties(dto, modelVersion, "id", "modelId");
modelVersion.setModelId(dto.getModelId()); // 把模型id设置成该模型版本关联的模型id
modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
// TODO: 后续可能还需要更新操作人
modelMapper.insertModelVersion(modelVersion);
}
} }

@ -1,13 +1,18 @@
package com.bipt.intelligentapplicationorchestrationservice.service.Impl; package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelSelectVO;
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ServiceStatus;
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper; import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService; import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* @author hky * @author hky
*/ */
@ -30,11 +35,43 @@ public class PublishServiceImpl implements PublishService {
throw new IllegalArgumentException("请求已存在: " + apiUrl); throw new IllegalArgumentException("请求已存在: " + apiUrl);
} }
//todo调用服务部署
publishMapper.insert(servicePublishDTO); publishMapper.insert(servicePublishDTO);
} }
@Override
public List<ServicePublishVO> listPublishedServices() {
return publishMapper.listPublishedServices();
}
@Override
public List<ModelSelectVO> getModelNames() {
return publishMapper.selectModelSelectList();
}
@Override
public ServicePublishVO getServiceById(Long serviceId) {
return publishMapper.getServiceById(serviceId);
}
@Override
public void updateServiceStatus(ServicePublishDTO servicePublishDTO) {
publishMapper.updateStatus(servicePublishDTO.getId(), servicePublishDTO.getStatus());
}
@Override
public List<ServicePublishVO> listPublishedServicesByStatus(Integer status) {
return publishMapper.selectByStatus(status);
}
@Override
public List<ModelSelectVO> getOnlineModelNames() {
// 调用Mapper查询状态为“在线”的模型ServiceStatus.ONLINE.getCode() 假设为1
return publishMapper.selectModelNamesByStatus(ServiceStatus.OFFLINE.getCode());
}
@Override
public Long getModelId(Long id) {
return publishMapper.getByMdVersionId(id);
}
} }

@ -0,0 +1,97 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.exception.DeployException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ModelDeployer {
@Autowired
private ModelRepositoryClient modelRepositoryClient;
@Autowired
private ModelEvaluator modelEvaluationService;
@Autowired
private NormalDeployService normalDeployService;
@Autowired
private GrayDeployService grayDeployService;
@Autowired
private ResourceAllocator resourceAllocator;
@Autowired
private GpuResourceService gpuResourceService;
public DeployResponse deploy(DeployRequest request) {
try {
// 1. 获取完整模型信息
ModelInfo modelInfo = getModelInfo(request.getModelId());
// 2. 更新请求中的模型信息
request.setModelInfo(modelInfo);
// 3. 添加模型评估检查
if (!isEvaluationPassed(modelInfo)) {
return DeployResponse.fail(403,
"模型[" + modelInfo.getModelName() + "]评估未通过,无法部署");
}
List<GpuResource> availableResources = gpuResourceService.getAvailableResources();
int requiredMemory = request.getRequiredMemory();
String modelId = request.getModelId();
if (!resourceAllocator.checkResourceQuota(availableResources, requiredMemory, modelId)){
return DeployResponse.fail(507, "资源配额不足。需要内存: " + requiredMemory + "MB\n");
}
// 4. 根据部署类型路由
if (request.getDeployType() == DeployRequest.DeployType.NORMAL) {
return normalDeployService.process(request);
} else {
return grayDeployService.process(request);
}
} catch (DeployException e) {
return DeployResponse.fail(404, "获取模型信息失败: " + e.getMessage());
} catch (Exception e) {
return DeployResponse.fail(500, "部署失败: " + e.getMessage());
}
}
/**
* 从模型仓库获取模型详细信息
*/
private ModelInfo getModelInfo(String modelId) {
// 添加缓存和重试机制
ModelInfo modelInfo = modelRepositoryClient.getModelInfo(modelId);
// 验证关键字段
if (modelInfo.getModelFilePath() == null) {
throw new DeployException("模型文件路径未定义");
}
// 获取额外信息
modelInfo.setStorageLocation(
modelRepositoryClient.getModelStorageLocation(modelId)
);
return modelInfo;
}
/**
* 检查模型评估状态
*/
private boolean isEvaluationPassed(ModelInfo modelInfo) {
return modelEvaluationService.isEvaluationPassed(
modelInfo.getModelId()
);
}
}

@ -0,0 +1,134 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Component
public class ModelEvaluator {
@Value("${model.evaluation.service-url}")
private String evaluationServiceUrl;
@Value("${model.evaluation.api-timeout:3000}")
private int apiTimeout;
@Autowired
private RestTemplate restTemplate;
/**
* 检查模型评估是否通过
* @param modelId 模型ID
* @return 评估是否通过
*/
public boolean isEvaluationPassed(String modelId) {
return isEvaluationPassed(modelId, null);
}
/**
* 检查模型评估是否通过(带版本号)
* @param modelId 模型ID
* @param version 模型版本
* @return 评估是否通过
*/
public boolean isEvaluationPassed(String modelId, String version) {
// 1. 构建API调用参数
Map<String, String> params = new HashMap<>();
params.put("modelId", modelId);
if (version != null) {
params.put("version", version);
}
try {
// 2. 设置请求头和超时
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("X-Request-ID", generateRequestId(modelId));
// 3. 调用评估API
ResponseEntity<EvaluationResponse> response = restTemplate.exchange(
buildEvaluationUrl(modelId, version),
HttpMethod.GET,
new HttpEntity<>(headers),
EvaluationResponse.class
);
// 4. 处理响应
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
return response.getBody().isPassed();
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
logEvaluationWarning(modelId, "模型未找到");
} else {
logEvaluationError(modelId, "评估服务返回非200状态: " + response.getStatusCode());
}
} catch (Exception e) {
logEvaluationError(modelId, "评估服务调用失败: " + e.getMessage());
}
// 5. 默认返回失败
return false;
}
// ================= 辅助方法 =================
/**
* 构建评估API URL
*/
private String buildEvaluationUrl(String modelId, String version) {
String baseUrl = evaluationServiceUrl + "/models/" + modelId + "/evaluation";
return version != null ? baseUrl + "?version=" + version : baseUrl;
}
/**
* 生成请求ID用于日志追踪
*/
private String generateRequestId(String modelId) {
return "eval-" + modelId + "-" + System.currentTimeMillis();
}
/**
* 记录评估错误日志
*/
private void logEvaluationError(String modelId, String message) {
// 实际实现应使用日志框架如SLF4J
System.err.println("[" + modelId + "] 评估错误: " + message);
}
/**
* 记录评估警告日志
*/
private void logEvaluationWarning(String modelId, String message) {
// 实际实现应使用日志框架
System.out.println("[" + modelId + "] 评估警告: " + message);
}
/**
* 评估响应内部类
*/
private static class EvaluationResponse {
private boolean passed;
private String reason;
private String evaluatedAt;
// 需要默认构造方法用于JSON反序列化
public EvaluationResponse() {}
public boolean isPassed() {
return passed;
}
public String getReason() {
return reason;
}
public String getEvaluatedAt() {
return evaluatedAt;
}
}
}

@ -0,0 +1,98 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.exception.DeployException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
@Component
public class ModelRepositoryClient {
@Value("${model.repository.url}")
private String repositoryBaseUrl;
@Value("${model.repository.api-key}")
private String apiKey;
@Autowired
private RestTemplate restTemplate;
/**
* 从模型仓库获取模型信息
*
* @param modelId 模型唯一标识
* @return 完整的模型信息对象
*/
public ModelInfo getModelInfo(String modelId) {
// 1. 构建请求URL
String url = repositoryBaseUrl + "/models/" + modelId + "/info";
// 2. 设置认证头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("X-API-KEY", apiKey);
headers.set("Model-Id", modelId);
HttpEntity<?> entity = new HttpEntity<>(headers);
try {
// 3. 发送请求到模型仓库服务
ResponseEntity<ModelInfo> response = restTemplate.exchange(
url,
HttpMethod.GET,
entity,
ModelInfo.class
);
// 4. 处理响应
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
return response.getBody();
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new DeployException("模型未找到: " + modelId);
} else {
throw new DeployException("获取模型信息失败,状态码: " + response.getStatusCode());
}
} catch (Exception e) {
throw new DeployException("访问模型仓库失败: " + e.getMessage(), e);
}
}
public String getModelStorageLocation(String modelId) {
// 1. 构建请求URL
String url = repositoryBaseUrl + "/models/" + modelId + "/storage-location";
// 2. 设置认证头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("X-API-KEY", apiKey);
headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN));
HttpEntity<?> entity = new HttpEntity<>(headers);
try {
// 3. 发送请求到模型仓库服务
ResponseEntity<String> response = restTemplate.exchange(
url,
HttpMethod.GET,
entity,
String.class
);
// 4. 处理响应
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
return response.getBody();
} else if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new DeployException("模型存储位置未找到: " + modelId);
} else {
throw new DeployException("获取存储位置失败,状态码: " + response.getStatusCode());
}
} catch (Exception e) {
throw new DeployException("访问模型仓库失败: " + e.getMessage(), e);
}
}
}

@ -23,4 +23,10 @@ public interface ModelService {
List<Map<String, String>> listLifeCycle(); List<Map<String, String>> listLifeCycle();
List<DatasetEntity> listDataset(); List<DatasetEntity> listDataset();
ModelTrainInfoVO getModelTrainInfo(Long id);
void updateModelTrain(Long id);
void updateModelVersionMinor(ModelVersionDTO dto);
} }

@ -0,0 +1,118 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployRequest;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeployResponse;
import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.exception.EvaluationFailedException;
import com.bipt.intelligentapplicationorchestrationservice.util.TemplateParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Service
public class NormalDeployService {
@Autowired
private ModelEvaluator modelEvaluator;
@Autowired
private ResourceAllocator resourceAllocator;
@Autowired
private GpuResourceService gpuService;
@Autowired
private TemplateParser templateParser; // 使用模板解析器
@Value("${model.deploy.script-directory:/opt/deploy_scripts}")
private String scriptDirectory;
@Value("${model.deploy.script-timeout:300}")
private int scriptTimeout;
public DeployResponse process(DeployRequest request) {
try {
// 1. 检查模型评估状态使用ModelInfo包含的模型ID
ModelInfo modelInfo = request.getModelInfo();
if (!modelEvaluator.isEvaluationPassed(modelInfo != null ? modelInfo.getModelName() : "")) {
throw new EvaluationFailedException("模型评估未通过");
}
// 2. 分配资源并获取URL
DeploymentResource resource = resourceAllocator.allocate(
gpuService.getAvailableResources(),
request.getRequiredMemory(),
modelInfo != null ? modelInfo.getModelName() : "unknown",
false
);
// 3. 使用ModelInfo生成部署脚本内容
String scriptContent = templateParser.generateDeploymentScript(
request.getModelInfo(),
resource.getUrl()
);
// 4. 执行部署脚本
executeDeploymentScript(scriptContent);
// 5. 标记资源已分配
gpuService.markAsAllocated(
resource.getGpu().getGPUId(),
request.getRequiredMemory()
);
return DeployResponse.success(resource.getUrl());
} catch (EvaluationFailedException e) {
return DeployResponse.fail(403, e.getMessage());
} catch (Exception e) {
return DeployResponse.fail(500, "部署失败: " + e.getMessage());
}
}
/**
* 执行部署脚本
*/
private void executeDeploymentScript(String scriptContent) throws Exception {
// 创建脚本文件
Path scriptPath = Paths.get(scriptDirectory, "deploy_" + System.currentTimeMillis() + ".sh");
Files.write(scriptPath, scriptContent.getBytes());
// 设置执行权限 (754)
Set<PosixFilePermission> permissions = Set.of(
PosixFilePermission.OWNER_READ,
PosixFilePermission.OWNER_WRITE,
PosixFilePermission.OWNER_EXECUTE,
PosixFilePermission.GROUP_READ,
PosixFilePermission.GROUP_EXECUTE,
PosixFilePermission.OTHERS_READ
);
Files.setPosixFilePermissions(scriptPath, permissions);
// 执行脚本
Process process = new ProcessBuilder(scriptPath.toString())
.directory(Paths.get(scriptDirectory).toFile())
.start();
// 带超时等待
boolean completed = process.waitFor(scriptTimeout, TimeUnit.SECONDS);
if (!completed) {
process.destroyForcibly();
throw new RuntimeException("脚本执行超时(限制: " + scriptTimeout + "秒)");
}
// 检查退出码
if (process.exitValue() != 0) {
throw new RuntimeException("脚本执行失败,退出码: " + process.exitValue());
}
// 清理脚本文件
Files.deleteIfExists(scriptPath);
}
}

@ -1,12 +1,26 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelSelectVO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
import java.util.List;
public interface PublishService { public interface PublishService {
void save(ServicePublishDTO servicePublishDTO); void save(ServicePublishDTO servicePublishDTO);
List<ServicePublishVO> listPublishedServices();
List<ModelSelectVO> getModelNames();
ServicePublishVO getServiceById(Long serviceId);
void updateServiceStatus(ServicePublishDTO updateDto);
List<ServicePublishVO> listPublishedServicesByStatus(Integer status);
List<ModelSelectVO> getOnlineModelNames();
Long getModelId(Long id);
} }

@ -1,16 +1,19 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.apache.ibatis.cache.CacheException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.*;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
@ -124,4 +127,26 @@ public class RedisCacheService {
return false; return false;
} }
} }
public Set<String> scanKeys(String pattern) {
try (RedisConnection connection = Objects.requireNonNull(
redisTemplate.getConnectionFactory()).getConnection()) {
ScanOptions options = ScanOptions.scanOptions()
.match(pattern)
.count(100) // 批量扫描数量
.build();
Set<String> keys = new HashSet<>();
Cursor<byte[]> cursor = connection.scan(options);
while (cursor.hasNext()) {
keys.add(new String(cursor.next(), StandardCharsets.UTF_8));
}
return keys;
} catch (Exception e) {
throw new CacheException("Keys scan failed", e);
}
}
} }

@ -1,8 +1,8 @@
package com.bipt.intelligentapplicationorchestrationservice.deploy.deployment; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.deploy.entity.DeploymentResource; import com.bipt.intelligentapplicationorchestrationservice.entity.DeploymentResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.utils.ConfigConstants; import com.bipt.intelligentapplicationorchestrationservice.constant.ConfigConstants;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.ResourceAccessException;
@ -16,6 +16,54 @@ public class ResourceAllocator {
@Autowired @Autowired
private ConfigConstants config; private ConfigConstants config;
// 检查资源配额
public boolean checkResourceQuota(List<GpuResource> resources, int requiredMemory, String modelId) {
// 1. 检查全局资源是否充足
long totalFreeMemory = resources.stream()
.mapToInt(this::getRemainingMemory)
.sum();
// 全局内存不足
if (totalFreeMemory < requiredMemory) {
return false;
}
// 2. 检查单个GPU是否能满足需求
boolean canAllocate = resources.stream()
.anyMatch(gpu -> getRemainingMemory(gpu) >= requiredMemory);
if (!canAllocate) {
// 检查碎片化分配
return checkFragmentationAllocation(resources, requiredMemory);
}
return true;
}
// 检查碎片化分配可能性
private boolean checkFragmentationAllocation(List<GpuResource> resources, int requiredMemory) {
// 按碎片率排序碎片小的优先
resources.sort(Comparator.comparingDouble(
r -> (double)getRemainingMemory(r) / r.getGPUMaxMemory()
));
// 检查碎片整合后是否可能满足需求
int accumulatedMemory = 0;
for (GpuResource gpu : resources) {
int fragment = getRemainingMemory(gpu);
// 如果单个碎片就足够直接返回成功
if (fragment >= requiredMemory) return true;
// 累积碎片
accumulatedMemory += fragment;
if (accumulatedMemory >= requiredMemory) {
return true;
}
}
return false;
}
//获取剩余内存 //获取剩余内存
private int getRemainingMemory(GpuResource resource){ private int getRemainingMemory(GpuResource resource){
return resource.getGPUMaxMemory()-resource.getGPUMemorySize(); return resource.getGPUMaxMemory()-resource.getGPUMemorySize();

@ -1,14 +1,16 @@
package com.bipt.intelligentapplicationorchestrationservice.service.Impl; package com.bipt.intelligentapplicationorchestrationservice.service.impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao; import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuMapper;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum; import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService; import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -20,53 +22,128 @@ import java.util.stream.Collectors;
@Service @Service
public class GpuManageServiceImpl implements GpuManageService { public class GpuManageServiceImpl implements GpuManageService {
private static final Logger logger = LoggerFactory.getLogger(GpuManageServiceImpl.class);
@Autowired @Autowired
private GpuResourceDao gpuDao; private GpuResourceDao gpuDao;
@Autowired @Autowired
private GpuMapper gpuMapper; private GpuMapper gpuMapper;
@Autowired
private GpuResourceDao gpuResourceDao;
@Transactional @Transactional
//创建GPU资源 @Override
public ResponseVO createGpuResource(GpuCreateDTO dto) { public ResponseVO createGpuResource(GpuCreateDTO dto) {
try {
logger.info("创建GPU资源请求: {}", dto);
GpuResource entity = gpuMapper.toEntity(dto); GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.insert(entity); gpuDao.insert(entity);
logger.info("创建GPU资源成功, ID: {}", entity.getGPUId());
return ResponseVO.success(entity); return ResponseVO.success(entity);
} catch (Exception e) {
logger.error("创建GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
}
} }
@Transactional @Transactional
//删除GPU资源逻辑删除 @Override
public ResponseVO deleteGpuResource(Long gpuId) { public ResponseVO deleteGpuResource(Long gpuId) {
logger.info("删除GPU资源请求, ID: {}", gpuId);
try {
GpuResource entity = gpuDao.selectById(gpuId); GpuResource entity = gpuDao.selectById(gpuId);
if (entity == null) { if (entity == null) {
logger.warn("GPU资源不存在, ID: {}", gpuId);
return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND); return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND);
} }
gpuDao.isDeleted(gpuId); gpuDao.isDeleted(gpuId);
logger.info("逻辑删除GPU资源成功, ID: {}", gpuId);
return ResponseVO.success(); return ResponseVO.success();
} catch (Exception e) {
logger.error("删除GPU资源失败, ID: {}, 错误: {}", gpuId, e.getMessage(), e);
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
}
} }
@Transactional @Transactional
//更新GPU资源 @Override
public void updateGpuResource(GpuUpdateDTO dto) { public void updateGpuResource(GpuUpdateDTO dto) {
logger.info("更新GPU资源请求: {}", dto);
try {
GpuResource entity = gpuMapper.toEntity(dto); GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.updateById(entity); gpuDao.updateById(entity);
logger.info("更新GPU资源成功, ID: {}", entity.getGPUId());
} catch (Exception e) {
logger.error("更新GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
throw new RuntimeException("更新GPU资源失败", e);
}
} }
@Override @Override
//模糊匹配查询
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip) { public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip) {
// PermissionCheckUtil.checkTenantAccess();
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
if(model != null) params.put("model", "%" + model + "%"); if(model != null) params.put("model", "%" + model + "%");
if(memorySize != null) params.put("memorySize", memorySize); if(memorySize != null) params.put("memorySize", memorySize);
if(ip != null) params.put("ip", ip); if(ip != null) params.put("ip", ip);
List<GpuResource> entities = gpuResourceDao.selectByFields(params); logger.info("查询GPU资源条件: {}", params);
return entities.stream().map(gpuMapper::toDTO).collect(Collectors.toList()); try {
List<GpuResource> entities = gpuDao.selectByFields(params);
logger.info("查询到 {} 条GPU资源", entities.size());
return entities.stream()
.map(gpuMapper::toDTO)
.collect(Collectors.toList());
} catch (Exception e) {
logger.error("查询GPU资源失败, 条件: {}, 错误: {}", params, e.getMessage(), e);
throw new RuntimeException("查询GPU资源失败", e);
}
}
// ========== 新增的日志追踪方法 ==========
private void logOperation(String methodName, Object... details) {
if (logger.isDebugEnabled()) {
StringBuilder logBuilder = new StringBuilder(methodName);
for (Object detail : details) {
logBuilder.append(" | ").append(detail);
}
logger.debug(logBuilder.toString());
}
}
private void logDuration(String methodName, long startTime, boolean success) {
long duration = System.currentTimeMillis() - startTime;
String status = success ? "成功" : "失败";
logger.info("方法 {} 执行{} | 耗时: {}ms", methodName, status, duration);
}
// ========== 增强的日志版本 ==========
@Transactional
@Override
public ResponseVO createGpuResourceWithTrace(GpuCreateDTO dto) {
long start = System.currentTimeMillis();
try {
logOperation("createGpuResource", "请求参数", dto);
ResponseVO result = createGpuResource(dto);
logDuration("createGpuResource", start, true);
return result;
} catch (Exception e) {
logDuration("createGpuResource", start, false);
throw e;
}
} }
} }

@ -0,0 +1,207 @@
package com.bipt.intelligentapplicationorchestrationservice.util;
import com.aliyun.oss.HttpMethod;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.URL;
import java.util.Date;
/**
* 阿里云OSS文件操作工具类
*/
@Data
@Slf4j
@AllArgsConstructor
public class AliOssUtil {
private final String endpoint;
private final String accessKeyId;
private final String accessKeySecret;
private final String bucketName;
/**
* 上传文件到OSS
* @param file 文件对象
* @param objectName 对象名称OSS中的路径
* @return 文件URL
*/
public String upload(File file, String objectName) {
try (InputStream inputStream = new FileInputStream(file)) {
return upload(inputStream, objectName);
} catch (Exception e) {
log.error("上传文件失败: {}", e.getMessage(), e);
throw new RuntimeException("上传文件到OSS失败", e);
}
}
/**
* 上传文件流到OSS
* @param inputStream 文件流
* @param objectName 对象名称OSS中的路径
* @return 文件URL
*/
public String upload(InputStream inputStream, String objectName) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 创建PutObject请求
PutObjectRequest request = new PutObjectRequest(bucketName, objectName, inputStream);
// 设置对象元数据
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(getContentType(objectName));
request.setMetadata(metadata);
// 上传文件
ossClient.putObject(request);
log.info("文件上传成功: {}", objectName);
// 构建文件URL
return "https://" + bucketName + "." + endpoint + "/" + objectName;
} catch (Exception e) {
log.error("上传文件失败: {}", e.getMessage(), e);
throw new RuntimeException("上传文件到OSS失败", e);
} finally {
// 关闭OSSClient
ossClient.shutdown();
}
}
/**
* 生成临时签名URL用于访问私有Bucket中的文件
* @param objectName 对象名称
* @param expirationMinutes 过期时间(分钟)
* @return 签名URL
*/
public String generatePresignedUrl(String objectName, int expirationMinutes) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 设置URL过期时间
Date expiration = new Date(System.currentTimeMillis() + expirationMinutes * 60 * 1000);
// 生成签名URL
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET);
request.setExpiration(expiration);
URL url = ossClient.generatePresignedUrl(request);
log.info("生成临时签名URL: {}", url);
return url.toString();
} catch (Exception e) {
log.error("生成签名URL失败: {}", e.getMessage(), e);
throw new RuntimeException("生成签名URL失败", e);
} finally {
// 关闭OSSClient
ossClient.shutdown();
}
}
/**
* 下载文件到本地
* @param objectName 对象名称
* @param destinationFile 目标文件
*/
public void download(String objectName, File destinationFile) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 下载OSS文件到本地文件
ossClient.getObject(new GetObjectRequest(bucketName, objectName), destinationFile);
log.info("文件下载成功: {}", objectName);
} catch (Exception e) {
log.error("下载文件失败: {}", e.getMessage(), e);
throw new RuntimeException("下载文件失败", e);
} finally {
// 关闭OSSClient
ossClient.shutdown();
}
}
/**
* 删除OSS中的文件
* @param objectName 对象名称
*/
public void delete(String objectName) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 删除文件
ossClient.deleteObject(bucketName, objectName);
log.info("文件删除成功: {}", objectName);
} catch (Exception e) {
log.error("删除文件失败: {}", e.getMessage(), e);
throw new RuntimeException("删除文件失败", e);
} finally {
// 关闭OSSClient
ossClient.shutdown();
}
}
/**
* 检查文件是否存在
* @param objectName 对象名称
* @return 文件是否存在
*/
public boolean doesObjectExist(String objectName) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
return ossClient.doesObjectExist(bucketName, objectName);
} catch (Exception e) {
log.error("检查文件存在失败: {}", e.getMessage(), e);
throw new RuntimeException("检查文件存在失败", e);
} finally {
// 关闭OSSClient
ossClient.shutdown();
}
}
/**
* 根据文件扩展名确定Content-Type
* @param fileName 文件名
* @return Content-Type
*/
private String getContentType(String fileName) {
if (fileName == null) {
return "application/octet-stream";
}
if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) {
return "image/jpeg";
} else if (fileName.endsWith(".png")) {
return "image/png";
} else if (fileName.endsWith(".gif")) {
return "image/gif";
} else if (fileName.endsWith(".txt")) {
return "text/plain";
} else if (fileName.endsWith(".pdf")) {
return "application/pdf";
} else if (fileName.endsWith(".doc")) {
return "application/msword";
} else if (fileName.endsWith(".docx")) {
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
} else if (fileName.endsWith(".xls")) {
return "application/vnd.ms-excel";
} else if (fileName.endsWith(".xlsx")) {
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
} else if (fileName.endsWith(".html") || fileName.endsWith(".htm")) {
return "text/html";
} else if (fileName.endsWith(".css")) {
return "text/css";
} else if (fileName.endsWith(".js")) {
return "application/javascript";
} else if (fileName.endsWith(".json")) {
return "application/json";
} else if (fileName.endsWith(".xml")) {
return "application/xml";
} else if (fileName.endsWith(".mp4")) {
return "video/mp4";
} else if (fileName.endsWith(".mp3")) {
return "audio/mpeg";
} else {
return "application/octet-stream";
}
}
}

@ -1,14 +1,17 @@
package com.bipt.intelligentapplicationorchestrationservice.util; package com.bipt.intelligentapplicationorchestrationservice.util;
import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@ -17,26 +20,102 @@ public class NacosServiceUtil {
@Value("${spring.cloud.nacos.discovery.server-addr}") @Value("${spring.cloud.nacos.discovery.server-addr}")
private String nacosServerAddr; private String nacosServerAddr;
public void registerService(String serviceName, String ip, int port, String url) throws Exception { // 新增url参数 private NamingService namingService;
NamingService naming = NamingFactory.createNamingService(nacosServerAddr);
/**
* 获取NamingService实例线程安全
*/
private NamingService getNamingService() throws Exception {
if (namingService == null) {
synchronized (this) {
if (namingService == null) {
namingService = NacosFactory.createNamingService(nacosServerAddr);
}
}
}
return namingService;
}
/**
* 注册服务到Nacos
*/
public void registerService(String serviceName, String ip, int port, String url) throws Exception {
NamingService naming = getNamingService();
Instance instance = new Instance(); Instance instance = new Instance();
instance.setIp(ip); instance.setIp(ip);
instance.setPort(port); instance.setPort(port);
// 添加元数据存储URL instance.setWeight(1.0);
instance.setHealthy(true);
// 添加元数据
Map<String, String> metadata = new HashMap<>(); Map<String, String> metadata = new HashMap<>();
metadata.put("url", url); // 将URL存入元数据 metadata.put("url", url);
metadata.put("registerTime", String.valueOf(System.currentTimeMillis()));
instance.setMetadata(metadata); instance.setMetadata(metadata);
naming.registerInstance(serviceName, instance); naming.registerInstance(serviceName, instance);
} }
/**
* 从Nacos注销服务
*/
public void deregisterService(String serviceName, String ip, int port) throws Exception {
NamingService naming = getNamingService();
naming.deregisterInstance(serviceName, ip, port);
}
/**
* 获取服务所有实例
*/
public List<Instance> getAllInstances(String serviceName) throws Exception {
NamingService naming = getNamingService();
return naming.getAllInstances(serviceName);
}
/** /**
* 获取服务所有实例IP * 获取服务所有实例IP
*/ */
public List<String> getServiceInstances(String serviceName) throws Exception { public List<String> getServiceInstances(String serviceName) throws Exception {
NamingService naming = NamingFactory.createNamingService(nacosServerAddr); return getAllInstances(serviceName).stream()
List<Instance> instances = naming.getAllInstances(serviceName);
return instances.stream()
.map(Instance::getIp) .map(Instance::getIp)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 获取服务信息适配Nacos 2.x
*/
public ServiceInfo getServiceInfo(String serviceName) throws Exception {
NamingService naming = getNamingService();
// 使用selectInstances替代getServiceInfo
List<Instance> instances = naming.selectInstances(serviceName, true);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(serviceName);
serviceInfo.setHosts(instances);
return serviceInfo;
}
/**
* 根据IP和端口查询实例是否存在
*/
public boolean isInstanceExists(String serviceName, String ip, int port) throws Exception {
List<Instance> instances = getAllInstances(serviceName);
return instances.stream()
.anyMatch(instance ->
Objects.equals(instance.getIp(), ip) &&
instance.getPort() == port
);
}
/**
* 更新服务实例元数据
*/
public void updateInstanceMetadata(String serviceName, String ip, int port, Map<String, String> metadata) throws Exception {
NamingService naming = getNamingService();
Instance instance = new Instance();
instance.setIp(ip);
instance.setPort(port);
instance.setMetadata(metadata);
naming.registerInstance(serviceName, instance);
}
} }

@ -0,0 +1,78 @@
package com.bipt.intelligentapplicationorchestrationservice.util;
import com.bipt.intelligentapplicationorchestrationservice.entity.ModelInfo;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@Service
public class TemplateParser {
// 使用静态模板避免硬编码(可根据需要扩展为读取外部配置文件)
private static final Map<String, String> DEPLOYMENT_TEMPLATES = new HashMap<>() {{
put("tensorflow", "#!/bin/bash\n"
+ "# TensorFlow Serving Deployment\n"
+ "docker run -d --name {0}-service \\\n"
+ " -p {1} \\\n"
+ " -v {2}:/models/{0} \\\n"
+ " -e MODEL_NAME={0} \\\n"
+ " tensorflow/serving:latest\n"
+ "# Preprocessing\n"
+ "{3} $1");
put("pytorch", "#!/bin/bash\n"
+ "# TorchServe Deployment\n"
+ "torch-model-archiver --model-name {0} \\\n"
+ " --version 1.0 \\\n"
+ " --serialized-file {2} \\\n"
+ " --handler {3} \\\n"
+ " --export-path model_store\n"
+ "torchserve --start \\\n"
+ " --model-store model_store \\\n"
+ " --models {0}.mar \\\n"
+ " --ncs \\\n"
+ " --ts-config config.properties");
}};
public String generateDeploymentScript(ModelInfo modelInfo, String endpointUrl) {
// 提取URL端口号 (假设URL格式为 http://host:port)
String port = extractPortFromUrl(endpointUrl);
// 获取基础模板
String template = DEPLOYMENT_TEMPLATES.getOrDefault(
modelInfo.getModelType().toLowerCase(),
getDefaultTemplate()
);
// 安全处理空值
String safeModelName = modelInfo.getModelName() != null ? modelInfo.getModelName() : "unnamed";
String safeFilePath = modelInfo.getModelFilePath() != null ? modelInfo.getModelFilePath() : "";
String safeScript = modelInfo.getPreprocessScript() != null ? modelInfo.getPreprocessScript() : "echo 'No preprocessing'";
// 填充模板参数
return MessageFormat.format(template,
safeModelName,
port,
safeFilePath,
safeScript
);
}
private String extractPortFromUrl(String url) {
if (url == null) return "8080"; // 默认端口
try {
return url.split(":")[2].replaceAll("[^0-9]", "");
} catch (Exception e) {
return "8080";
}
}
private String getDefaultTemplate() {
return "#!/bin/bash\n"
+ "# Universal Deployment Template\n"
+ "echo \"Deploying model: {0} at endpoint {1}\"\n"
+ "echo \"Model path: {2}\"\n"
+ "echo \"Running preprocessing: {3}\"\n"
+ "# Add custom deployment logic here";
}
}

@ -0,0 +1,5 @@
# 阿里云OSS配置
aliyun.oss.endpoint=oss-cn-beijing.aliyuncs.com
aliyun.oss.bucketName=ipz-nh
aliyun.oss.accessKeyId=LTAI5tBeto7V7BPWBcCjeP7A
aliyun.oss.accessKeySecret=bjQGt2G4J5yetxuY5cT5ZnKnIOqe4O

@ -32,12 +32,34 @@ spring.cloud.gateway.routes[0].uri=lb://intelligent-application-orchestration-se
spring.cloud.gateway.routes[0].predicates[0]=Path=/request spring.cloud.gateway.routes[0].predicates[0]=Path=/request
logging.level.org.springframework.web=DEBUG logging.level.org.springframework.web=DEBUG
# ????????
model.evaluation.service-url=http://evaluation-service:8080/api/v1
model.evaluation.api-timeout=3000
# ????????
model.repository.url=https://model-repo.example.com/api/v1
model.repository.api-key=SECURE_API_KEY_12345
model.repository.timeout=5000
#SQL ???????? #SQL ????????
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG 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 management.health.rabbit.enabled=false
# 文件上传配置
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
# 激活开发环境!告诉 Spring加载 application-dev.properties 里的配置
spring.profiles.active=dev
#配置IP列表后续根据需求修改ip数据以下仅为测试用例
available.ips=192.168.1.100,192.168.1.101,192.168.1.102
# 算法文件上传目录(相对于项目根目录)
algorithm.upload.dir=algorithm_files

@ -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!=''"> <if test="datasetName != null and datasetName!=''">
dataset_name LIKE CONCAT('%', #{datasetName}, '%') dataset_name LIKE CONCAT('%', #{datasetName}, '%')
</if> </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> </where>
</select> </select>
</mapper> </mapper>

@ -9,7 +9,7 @@
from model_log m1, from model_log m1,
model_info m2, model_info m2,
model_version m3 model_version m3
where m1.model_id=m2.id and m3.model_id=m2.id and m1.model_id = #{id} where m1.model_version_id=m3.id and m3.model_id=m2.id and m1.model_version_id = #{id}
</select> </select>
<!--更新模型信息(目前只更新模型是否上线,后续如果更多需求可优化>--> <!--更新模型信息(目前只更新模型是否上线,后续如果更多需求可优化>-->
@ -18,6 +18,6 @@
<if test="status != null"> <if test="status != null">
status=#{status} status=#{status}
</if> </if>
where model_id=#{id} where id=#{id}
</update> </update>
</mapper> </mapper>

@ -2,10 +2,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao"> <mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao">
<resultMap id="gpuResourceMap" type="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
<id property="GPUId" column="GPUId" /> <!-- 强制映射 -->
<result property="createTime" column="created_time"/>
<result property="UpdateTime" column="update_time"/>
<result property="GPUModel" column="GPUModel"/>
<result property="GPUMemorySize" column="GPUMemorySize"/>
<result property="Ip" column="Ip"/>
<result property="isDeleted" column="is_deleted"/>
<result property="GPUMaxMemory" column="GPUMaxMemory"/>
</resultMap>
<!-- 动态条件查询 --> <!-- 动态条件查询 -->
<select id="selectByFields" <select id="selectByFields"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource"> resultMap="gpuResourceMap">
SELECT * SELECT *
FROM Ipz.public.gpu_resource FROM Ipz.public.gpu_resource
<where> <where>
@ -28,7 +37,7 @@
<!-- 分页查询 --> <!-- 分页查询 -->
<select id="findByPage" <select id="findByPage"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource"> resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
SELECT * SELECT *
FROM gpu_resource FROM gpu_resource
WHERE is_deleted = 0 WHERE is_deleted = 0
@ -38,7 +47,7 @@
<!-- 增量同步查询 --> <!-- 增量同步查询 -->
<select id="findModifiedSince" <select id="findModifiedSince"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource"> resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
SELECT *, is_deleted SELECT *, is_deleted
FROM gpu_resource FROM gpu_resource
WHERE update_time &gt; #{since} WHERE update_time &gt; #{since}
@ -47,7 +56,7 @@
<!-- 带锁查询 --> <!-- 带锁查询 -->
<select id="selectByIdWithLock" <select id="selectByIdWithLock"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource"> resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
SELECT * SELECT *
FROM gpu_resource FROM gpu_resource
WHERE GPUId = #{gpuId} WHERE GPUId = #{gpuId}

@ -31,29 +31,57 @@
<!--查询模型详细信息--> <!--查询模型详细信息-->
<select id="selectById" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion"> <select id="selectById" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion">
SELECT SELECT
t1.model_name, t1.model_name, t1.id modelId,
t2.version, t2.dataset_id, t2.model_config, t2.version, t2.dataset_id, t2.model_config, t2.id,
t2.model_path, t2.status, t2.create_time, t2.update_time, t2.model_size, t2.model_path, t2.status, t2.create_time, t2.update_time, t2.model_size,
t2.data_pre_handle_file, t2.model_super_args, t2.model_args_size, t2.model_source_code_url, t2.model_file, t2.data_pre_handle_file, t2.model_super_args, t2.model_args_size, t2.model_source_code_url, t2.model_file,
t2.model_design_document, t2.life_cycle, t2.operate_user t2.model_design_document, t2.life_cycle, t2.operate_user
FROM model_info t1 JOIN model_version t2 ON t1.id = t2.model_id FROM model_info t1 JOIN model_version t2 ON t1.id = t2.model_id
where t2.id = #{id} where t2.id = #{id}
</select> </select>
<select id="selectByModelId"
resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion">
SELECT
t1.model_name,
t2.version, t2.dataset_id, t2.model_config,
t2.model_path, t2.status, t2.create_time, t2.update_time, t2.model_size,
t2.data_pre_handle_file, t2.model_super_args, t2.model_args_size, t2.model_source_code_url, t2.model_file,
t2.model_design_document, t2.life_cycle, t2.operate_user
FROM model_info t1 JOIN model_version t2 ON t1.id = t2.model_id
where t2.model_id = #{id}
</select>
<!--更新模型信息--> <!--更新模型信息-->
<update id="update"> <update id="update">
UPDATE model_version UPDATE model_version
<set> <set>
<if test="modelSize != null"> <if test="datasetId != null">dataset_id = #{datasetId},</if>
model_size = #{modelSize}, <if test="modelConfig != null">model_config = #{modelConfig},</if>
</if> <if test="modelPath != null">model_path = #{modelPath},</if>
<if test="modelSuperArgs != null"> <if test="status != null">status = #{status},</if>
model_super_args = #{modelSuperArgs}, <if test="createTime != null">create_time = #{createTime},</if>
</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="modelArgsSize != null"> <if test="modelSize != null">model_size = #{modelSize},</if>
model_args_size = #{modelArgsSize}, <if test="dataPreHandleFile != null">data_pre_handle_file = #{dataPreHandleFile},</if>
</if> <if test="modelSuperArgs != null">model_super_args = #{modelSuperArgs},</if>
<if test="modelArgsSize != null">model_args_size = #{modelArgsSize},</if>
<if test="modelSourceCodeUrl != null">model_source_code_url = #{modelSourceCodeUrl},</if>
<if test="modelFile != null">model_file = #{modelFile},</if>
<if test="modelDesignDocument != null">model_design_document = #{modelDesignDocument},</if>
<if test="lifeCycle != null">life_cycle = #{lifeCycle},</if>
<if test="operateUser != null">operate_user = #{operateUser},</if>
</set> </set>
WHERE id = #{id WHERE id = #{id}
</update> </update>
<!--获取模型训练信息-->
<select id="getModelTrainInfo" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ModelTrainInfoVO">
select m1.dataset_id,
m1.id,
m1.model_config,
d2.ds_path,
m1.data_pre_handle_file
from model_version m1,dataset d2
where m1.dataset_id=d2.dataset_id and m1.id=#{id}
</select>
</mapper> </mapper>

@ -3,9 +3,14 @@
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper"> <mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper">
<insert id="insert"> <insert id="insert">
INSERT INTO service_publish INSERT INTO service_publish
(id,model_id,api_url,create_time) (id,model_id,api_url,create_time,ip,status)
values (#{id}, #{modelId}, #{apiUrl}, #{createTime}) values (#{id}, #{modelId}, #{apiUrl}, #{createTime},#{ip},#{status})
</insert> </insert>
<update id="updateStatus">
UPDATE service_publish
SET status = #{status}
WHERE id = #{id}
</update>
<select id="getByApiUrl" resultType="java.lang.Long"> <select id="getByApiUrl" resultType="java.lang.Long">
SELECT id FROM service_publish WHERE api_url = #{apiUrl}; SELECT id FROM service_publish WHERE api_url = #{apiUrl};
@ -17,4 +22,10 @@
mv.* mv.*
from model_version mv join service_publish sp on mv.model_id = sp.model_id from model_version mv join service_publish sp on mv.model_id = sp.model_id
</select> </select>
<select id="selectByStatus"
resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO">
SELECT *
FROM service_publish
WHERE status = #{status}
</select>
</mapper> </mapper>

@ -0,0 +1,125 @@
package com.bipt.intelligentapplicationorchestrationservice;
import com.bipt.intelligentapplicationorchestrationservice.controller.ServiceAPIController;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.service.ServiceAPIService;
import com.bipt.intelligentapplicationorchestrationservice.util.NacosServiceUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@RunWith(SpringRunner.class)
public class ServiceAPIControllerTest {
@Mock
private ServiceAPIService serviceAPIService;
@Mock
private NacosServiceUtil nacosServiceUtil;
@Mock
private RedisTemplate<String, Object> redisTemplate;
@Mock
private ValueOperations<String, Object> valueOperations;
@Mock
private ListOperations<String, Object> listOperations;
@InjectMocks
private ServiceAPIController serviceAPIController;
@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
when(redisTemplate.opsForValue()).thenReturn(valueOperations);
when(redisTemplate.opsForList()).thenReturn(listOperations);
}
@Test
public void testMultiResourceAllocation() throws Exception {
System.out.println("===== 开始测试多资源分配 =====");
// 环境初始化
String ip1 = "192.168.1.1";
String ip2 = "192.168.1.2";
List<String> instanceIps = Arrays.asList(ip1, ip2);
Set<String> gpuKeys = new HashSet<>(Arrays.asList("gpu:1", "gpu:2"));
// 模拟两个GPU的总内存配置
when(valueOperations.get("gpu:1")).thenReturn("IP:" + ip1 + ",GPUMemorySize:8000");
when(valueOperations.get("gpu:2")).thenReturn("IP:" + ip2 + ",GPUMemorySize:10000");
// 第一个请求分配到IP1需要3000MB
System.out.println("\n=== 第一个请求分配到IP1 ===");
Long modelId1 = 1L;
String modelConfig1 = "GPUMemorySize:3000,version:1";
when(serviceAPIService.getByModelId(modelId1)).thenReturn(modelConfig1);
when(nacosServiceUtil.getServiceInstances(modelId1.toString())).thenReturn(instanceIps);
when(redisTemplate.keys("gpu:*")).thenReturn(gpuKeys);
// IP1首次使用无需提前设置ip:ip1默认用总内存8000
OptResult result1 = serviceAPIController.schedule(modelId1);
// 验证结果
assertTrue("第一个请求应成功", result1.isSuccess());
assertEquals("资源分配成功使用ip:" + ip1, result1.getData());
verify(valueOperations, times(1)).set("ip:" + ip1, 5000); // 8000-3000
System.out.println("IP1 可用内存=5000MB, IP2 可用内存=10000MB初始");
// 第二个请求分配到IP2需要6000MB
System.out.println("\n=== 第二个请求分配到IP2 ===");
Long modelId2 = 2L;
String modelConfig2 = "GPUMemorySize:6000,version:1";
when(serviceAPIService.getByModelId(modelId2)).thenReturn(modelConfig2);
when(nacosServiceUtil.getServiceInstances(modelId2.toString())).thenReturn(instanceIps);
when(valueOperations.get("ip:" + ip1)).thenReturn(5000); // IP1当前可用5000不足6000
// IP2首次使用无需提前设置ip:ip2默认用总内存10000
OptResult result2 = serviceAPIController.schedule(modelId2);
// 验证结果
assertTrue("第二个请求应成功", result2.isSuccess());
assertEquals("资源分配成功使用ip:" + ip2, result2.getData());
verify(valueOperations, times(1)).set("ip:" + ip2, 4000); // 10000-6000
System.out.println("IP1 可用内存=5000MB, IP2 可用内存=4000MB");
// 第三个请求(资源不足)
System.out.println("\n=== 第三个请求:资源不足 ===");
Long modelId3 = 3L;
String modelConfig3 = "GPUMemorySize:7000,version:1";
when(serviceAPIService.getByModelId(modelId3)).thenReturn(modelConfig3);
when(valueOperations.get("ip:" + ip1)).thenReturn(5000); // IP1可用5000 <7000
when(valueOperations.get("ip:" + ip2)).thenReturn(4000); // IP2可用4000 <7000
OptResult result3 = serviceAPIController.schedule(modelId3);
// 验证结果
assertFalse("第三个请求应失败", result3.isSuccess());
assertEquals("资源不足,等待中", result3.getErrorInfo());
verify(listOperations, times(1)).rightPush("waitQueue:" + modelId3, modelId3);
System.out.println("模型ID=" + modelId3 + " 加入等待队列");
System.out.println("===== 多资源分配测试完成 =====");
}
}