Compare commits

...

13 Commits

Author SHA1 Message Date
e6e1bee8df Cache的类型转换的更改优化 2025-07-01 12:07:00 +08:00
d3c81412b9 Cache的类型转换的更改优化 2025-07-01 09:27:28 +08:00
808d285888 GPU和服务发布和算法部分代码优化 2025-06-30 20:35:29 +08:00
lpz
a0680450e6 Merge pull request '模型部署+Gpu资源增删改查日志' (#19) from dc-feature into main
Reviewed-on: #19
2025-06-23 15:36:45 +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' (#17) from xiaohucoding into main
Reviewed-on: #17
2025-06-18 13:23:04 +08:00
09424cf223 算法和数据集的后端完善 2025-06-16 14:08:23 +08:00
d11aaccb1e [提交]:提交工作日报 2025-06-06 21:36:03 +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
Lpz
b926506ede 禁用 RabbitMQ 健康检查并排除其自动配置 2025-06-05 12:36:13 +08:00
47 changed files with 1119 additions and 273 deletions

View File

@ -105,4 +105,74 @@
### 📅 明日计划 ### 📅 明日计划
- 模型信息管理前端页面开发 - 模型信息管理前端页面开发
## 2025年5月26日
### ✅ 今日完成
- 模型信息管理前端页面开发与后端联调
### 🚧 进行中
- 模型信息管理前端页面开发与后端联调
### 📅 明日计划
- 模型信息管理前端页面开发与后端联调
## 2025年5月27日
### ✅ 今日完成
- 模型信息管理前端页面开发与后端联调
### 🚧 进行中
- 模型信息管理前端页面开发与后端联调
### 📅 明日计划
- 模型信息管理前端页面开发与后端联调
## 2025年5月28日
### ✅ 今日完成
- 模型信息管理前端页面开发与后端联调
### 🚧 进行中
- 模型信息管理前端页面开发与后端联调
### 📅 明日计划
- 模型信息管理前端页面开发与后端联调
## 2025年5月29日
### ✅ 今日完成
- 模型信息管理前端页面开发与后端联调
### 🚧 进行中
- 模型信息管理前端页面开发与后端联调
### 📅 明日计划
- 模型信息管理前端页面开发与后端联调
## 2025年5月30日
### ✅ 今日完成
- 增加了查询数据集列表和生命周期列表接口
### 🚧 进行中
- 模型信息管理前端页面开发与后端联调
### 📅 明日计划
- 模型信息管理前端页面开发与后端联调

View File

@ -0,0 +1,60 @@
# 工作日报 - 2025年5月
## 2025年6月3日
### ✅ 今日完成
- 优化模型构建表单
### 🚧 进行中
- 优化模型构建表单
### 📅 明日计划
- 优化模型构建表单
## 2025年6月4日
### ✅ 今日完成
* 阿里云OSS文件上传后端接口开发
### 🚧 进行中
* 阿里云OSS文件上传后端接口开发存在问题
* 模型管理前端页面开发
### ⚠️ 问题/障碍
- Spring MVC依赖被注释和gateway冲突了已经发现了问题
### 📅 明日计划
* 继续完善阿里云OSS文件上传后端接口开发保证接口测试成功
* 模型管理前端页面开发
## 2025年6月5日
### ✅ 今日完成
- 阿里云OSS文件上传后端接口开发调试成功
- 基本完成了创建模型和修改模型的前后端联调
### 🚧 进行中
- 模型管理前端页面开发
### 📅 明日计划
- 模型管理前端页面开发
## 2025年6月6日
### ✅ 今日完成
- 基本完成了版本构建、修改生命周期、上下线、模型评估和详情功能
- 修改了模型评估和生命周期更新的一些细节,便于和前端接口协调
### 🚧 进行中
- 模型管理页面前端细节优化
### 📅 明日计划
- 模型管理页面前端细节优化

50
pom.xml
View File

@ -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,30 @@
<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>
</dependencies> </dependencies>
<build> <build>
@ -182,19 +202,17 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.38</version> <version>1.18.38</version>
</path> </path>
</annotationProcessorPaths> <path>
</configuration> <groupId>org.mapstruct</groupId>
</plugin> <artifactId>mapstruct-processor</artifactId>
<plugin> <version>1.5.5.Final</version>
<groupId>org.springframework.boot</groupId> </path>
<artifactId>spring-boot-maven-plugin</artifactId> <path>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok-mapstruct-binding</artifactId>
</exclude> <version>0.2.0</version>
</excludes> </path>
</annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -1,10 +1,12 @@
package com.bipt.intelligentapplicationorchestrationservice; package com.bipt.intelligentapplicationorchestrationservice;
import com.bipt.intelligentapplicationorchestrationservice.config.IpConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@ -12,6 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableConfigurationProperties(IpConfig.class)
//@Slf4j //@Slf4j
public class IntelligentApplicationOrchestrationServiceApplication { public class IntelligentApplicationOrchestrationServiceApplication {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class); private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentApplicationOrchestrationServiceApplication.class);

View File

@ -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(","));
}
}

View File

@ -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());
}
}

View File

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

View File

@ -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= "文件为空";
} }

View File

@ -3,23 +3,31 @@ 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.List; import java.util.List;
@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 +71,51 @@ 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 {
return OptResult.success("算法创建成功"); AlgorithmInfo algorithmInfo = objectMapper.readValue(algorithmJson, AlgorithmInfo.class);
log.info("新增算法: {}, 文件: {}", algorithmInfo, (file != null ? file.getOriginalFilename() : "无文件"));
algorithmInfoService.save(algorithmInfo, file);
return OptResult.success("算法创建成功");
} catch (IOException e) {
log.error("JSON转换失败", e);
return OptResult.error("新增算法失败: " + e.getMessage());
} catch (Exception e) {
log.error("新增算法失败", e);
return OptResult.error("新增算法失败: " + e.getMessage());
}
}
/**
* 根据算法名称模糊查询算法信息
* @param keyword 模糊查询关键词
* @return 符合条件的算法信息列表
*/
@GetMapping("/search")
public ResponseEntity<List<AlgorithmInfo>> searchByName(@RequestParam String keyword) {
List<AlgorithmInfo> algorithmInfos = algorithmInfoService.getByNameLike(keyword);
return ResponseEntity.ok(algorithmInfos);
}
/**
* 算法运行
*/
@PostMapping("/run/{id}")
@Operation(summary = "运行")
public OptResult run(@PathVariable Long id,@RequestBody String param){
log.info("运行",id);
String result = algorithmInfoService.run(id,param);
return OptResult.success("运行成功"+result);
}
/**
* 前端列表返回算法名称
*/
@GetMapping("/names")
@Operation(summary = "列表返回算法名称")
public List<String> getNames(){
return algorithmInfoService.getAllNames();
} }
} }

View File

@ -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);
}
}
}

View File

@ -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) {
return OptResult.success(); log.info("新增数据集: {}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
try {
datasetService.save(datasetDTO, file);
return OptResult.success();
} catch (Exception e) {
log.error("新增数据集失败", e);
return OptResult.error("新增数据集失败: " + e.getMessage());
}
} }
/** /**
@ -43,17 +59,17 @@ public class DatasetController {
return OptResult.success(pageResult); 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);
}
}
} }

View File

@ -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

View File

@ -9,11 +9,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping @RequestMapping("/gpu")
@CrossOrigin(origins = "http://localhost:3000")
public class GpuResourceController { public class GpuResourceController {
@Autowired @Autowired
private GpuManageService gpuManageService; private GpuManageService gpuManageService;
@PostMapping @PostMapping(value = "/add", produces = "application/json")
public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){ public ResponseVO addGpu(@Valid @RequestBody GpuCreateDTO dto){
return gpuManageService.createGpuResource(dto); return gpuManageService.createGpuResource(dto);
} }

View File

@ -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("更新生命周期");
modelService.updateLifeCycle(id,lifeCycle); try {
return OptResult.success(); modelService.updateLifeCycle(id,lifeCycle);
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 = "查询生命周期列表")

View File

@ -1,11 +1,16 @@
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.mapper.ModelMapper;
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 +22,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 +31,35 @@ public class PublishController {
@Autowired @Autowired
private NacosServiceUtil nacosServiceUtil; private NacosServiceUtil nacosServiceUtil;
@Autowired
private ModelMapper modelMapper;
@Autowired
private IpConfig ipConfig;
@Autowired
private ModelDeployer modelDeployer;
@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);
publishService.save(servicePublishDTO); publishService.save(servicePublishDTO);
//todo 调用模型部署 //调用模型部署
DeployRequest request = new DeployRequest();
Long modelId = servicePublishDTO.getModelId();
ModelVersion modelVersion = modelMapper.selectById(modelId);
String modelConfig = modelVersion.getModelConfig();
//假设modelConfig只存GPU数据
request.setModelId(String.valueOf(modelId));
request.setRequiredMemory(Integer.parseInt(modelConfig));
modelDeployer.deploy(request);
// 获取前端传来的IP字符串 // 获取前端传来的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 +80,31 @@ public class PublishController {
log.error("Nacos服务注册失败", e); log.error("Nacos服务注册失败", e);
return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误 return OptResult.error("Nacos服务注册失败"); // 根据业务需求返回错误
} }
return OptResult.success(); return OptResult.success();
} }
/**
* 获取已发布的服务列表
* @return
*/
@GetMapping("/list")
@Operation(summary ="获取已发布服务列表")
public OptResult<List<ServicePublishVO>> listPublishedServices() {
log.info("获取已发布服务列表接口被调用");
List<ServicePublishVO> services = publishService.listPublishedServices();
log.info("返回的数据: {}", services);
return OptResult.success(services);
}
/**
* 获取IP列表
* @return
*/
@GetMapping("/config/ips")
@Operation(summary = "获取可用IP地址列表")
public OptResult<List<String>> getAvailableIps() {
List<String> ips = ipConfig.getIps();
log.info("返回列表;{}",ips);
return OptResult.success(ips);
}
} }

View File

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

View File

@ -1,52 +1,21 @@
package com.bipt.intelligentapplicationorchestrationservice.entity; package com.bipt.intelligentapplicationorchestrationservice.entity;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.*;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Setter
@Data @Data
@AllArgsConstructor
@Setter
@Getter
public class GpuResource { public class GpuResource {
@Getter
@TableField("GPUId") @TableField("GPUId")
private Long GPUId; private Long GPUId;
@Getter
@TableField("GPUModel") @TableField("GPUModel")
private String GPUModel; private String GPUModel;
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
public Long getGPUId() {
return GPUId;
}
public String getGPUModel() {
return GPUModel;
}
public String getIp() {
return Ip;
}
public LocalDateTime getCreateTime() {
return CreateTime;
}
public LocalDateTime getUpdateTime() {
return UpdateTime;
}
public Integer getGPUMaxMemory() {
return GPUMaxMemory;
}
@Getter
@TableField("GPUMemorySize") @TableField("GPUMemorySize")
private Integer GPUMemorySize; private Integer GPUMemorySize;
@ -56,15 +25,12 @@ public class GpuResource {
@TableField("Ip") @TableField("Ip")
private String Ip; private String Ip;
@Getter @TableField("created_time")
@TableField("CreatedTime") private LocalDateTime createTime;
private LocalDateTime CreateTime;
@Getter
@TableField("update_time") @TableField("update_time")
private LocalDateTime UpdateTime; private LocalDateTime UpdateTime;
@Getter
@TableField("GPUMaxMemory") @TableField("GPUMaxMemory")
private Integer GPUMaxMemory; private Integer GPUMaxMemory;
@ -83,16 +49,40 @@ public class GpuResource {
public GpuResource(Long Id, String Model, Integer MemorySize, String ip, LocalDateTime create_time) { public GpuResource(Long Id, String GPUModel, Integer GPUMemorySize, String ip, LocalDateTime create_time) {
this.GPUId = Id; this.GPUId = Id;
this.GPUModel = Model; this.GPUModel = GPUModel;
this.GPUMemorySize = MemorySize; this.GPUMemorySize = GPUMemorySize;
this.Ip = ip; this.Ip = ip;
this.CreateTime = create_time; this.createTime = create_time;
} }
public GpuResource() {} public GpuResource() {}
public Integer getGPUMemorySize() {
return GPUMemorySize;
}
public Long getGPUId() {
return GPUId;
}
public String getGPUModel() {
return GPUModel;
}
public String getIp() {
return Ip;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public Integer getGPUMaxMemory() {
return GPUMaxMemory;
}
public void setGPUId(Long GPUId) { public void setGPUId(Long GPUId) {
this.GPUId = GPUId; this.GPUId = GPUId;
} }
@ -114,11 +104,7 @@ public class GpuResource {
} }
public void setCreateTime(LocalDateTime createTime) { public void setCreateTime(LocalDateTime createTime) {
CreateTime = createTime; this.createTime = createTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
UpdateTime = updateTime;
} }

View File

@ -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);
}

View File

@ -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);

View File

@ -6,6 +6,8 @@ import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper @Mapper
public interface PublishMapper { public interface PublishMapper {
@ -15,5 +17,6 @@ public interface PublishMapper {
Long getByApiUrl(String apiUrl); Long getByApiUrl(String apiUrl);
@Select("SELECT model_id,api_url,ip FROM service_publish")
List<ServicePublishVO> listPublishedServices();
} }

View File

@ -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;

View File

@ -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;*/
} }

View File

@ -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;

View File

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

View File

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

View File

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

View File

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

View File

@ -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;
}
} }

View File

@ -17,9 +17,9 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
public class ServicePublishVO implements Serializable { public class ServicePublishVO implements Serializable {
private Long modelId; private Long modelId;
private String GPUModel; /*private String GPUModel;*/
private String ip; private String ip;
private String GPUMemorySize; /* private String GPUMemorySize;*/
private String apiUrl; private String apiUrl;

View File

@ -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;
}

View File

@ -1,6 +1,7 @@
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.util.List; import java.util.List;
@ -12,6 +13,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(Long id, String param);
List<String> getAllNames();
List<AlgorithmInfo> getByNameLike(String keyword);
} }

View File

@ -3,8 +3,10 @@ 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.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;
}
}
}

View File

@ -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);
} }

View File

@ -3,19 +3,28 @@ 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 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.BufferedReader;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@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:/tmp/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);
@ -61,22 +70,81 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
return true; return true;
} }
/**
* 算法创建
* @param algorithmInfo
*/
@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()) {
log.info("已接收文件: {}", file.getOriginalFilename());
log.info("文件大小: {} 字节", file.getSize());
log.info("文件类型: {}", file.getContentType());
// 临时设置一个空路径(避免数据库保存空值)
//todo 保存到分布式存储
algorithmInfo.setAlgorithmFile("");
}
algorithmInfo.setCreateTime(LocalDateTime.now());
// 保存算法信息到数据库注意此时algorithmFile字段为空
algorithmInfoMapper.insert(algorithmInfo); algorithmInfoMapper.insert(algorithmInfo);
} }
@Override
public String run(Long id, String param) {
//todo从分布式存储中拿到文件以下是示例
String file = algorithmInfoMapper.getFileById(id);
StringBuilder result = new StringBuilder(); // 用于存储结果
try {
// 构建命令,将 param 作为参数传递给 Python 脚本
ProcessBuilder pb = new ProcessBuilder("python", file, param);
Process process = pb.start();
// 读取标准输出(脚本执行结果)
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
result.append(line).append("\n");
}
// 读取错误输出
BufferedReader errorReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
String errorLine;
while ((errorLine = errorReader.readLine()) != null) {
result.append("Error: ").append(errorLine).append("\n");
}
int exitCode = process.waitFor();
result.append("Exit Code: ").append(exitCode);
} catch (Exception e) {
result.append("执行异常: ").append(e.getMessage());
e.printStackTrace();
}
return result.toString(); // 返回完整结果
}
@Override
public List<String> getAllNames() {
return algorithmInfoMapper.getAllNames();
}
/**
* 模糊查询
* @param keyword
* @return
*/
@Override
public List<AlgorithmInfo> getByNameLike(String keyword) {
return algorithmInfoMapper.selectByNameLike(keyword);
}
} }

View File

@ -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;
}
} }

View File

@ -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);
} }
@ -81,6 +81,7 @@ public class ModelServiceImpl implements ModelService {
@Override @Override
public void updateModel(ModelVersionDTO dto) { public void updateModel(ModelVersionDTO dto) {
// 更新模型还需要更新操作人和时间
log.info("更新模型"); log.info("更新模型");
modelMapper.update(dto); modelMapper.update(dto);
} }
@ -110,14 +111,14 @@ public class ModelServiceImpl implements ModelService {
ModelLifecycle currentLifeCycle; ModelLifecycle currentLifeCycle;
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,7 +143,7 @@ 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);

View File

@ -2,12 +2,15 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper; import com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
import com.bipt.intelligentapplicationorchestrationservice.service.PublishService; import com.bipt.intelligentapplicationorchestrationservice.service.PublishService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* @author hky * @author hky
*/ */
@ -35,6 +38,10 @@ public class PublishServiceImpl implements PublishService {
publishMapper.insert(servicePublishDTO); publishMapper.insert(servicePublishDTO);
} }
@Override
public List<ServicePublishVO> listPublishedServices() {
return publishMapper.listPublishedServices();
}
} }

View File

@ -1,12 +1,14 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ServicePublishVO;
import java.util.List;
public interface PublishService { public interface PublishService {
void save(ServicePublishDTO servicePublishDTO); void save(ServicePublishDTO servicePublishDTO);
List<ServicePublishVO> listPublishedServices();
} }

View File

@ -1,7 +1,7 @@
package com.bipt.intelligentapplicationorchestrationservice.service.impl; package com.bipt.intelligentapplicationorchestrationservice.service.impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao; import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper; import com.bipt.intelligentapplicationorchestrationservice.entity.GpuMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;

View File

@ -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";
}
}
}

View File

@ -44,4 +44,19 @@ 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
# 文件上传配置
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

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper">
<select id="selectByNameLike" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo">
SELECT * FROM algorithm_info WHERE algorithm_name LIKE CONCAT('%', #{keyword}, '%')
</select>
</mapper>

View File

@ -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>

View File

@ -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>

View File

@ -2,10 +2,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao"> <mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao">
<resultMap id="gpuResourceMap" type="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
<id property="GPUId" column="GPUId" /> <!-- 强制映射 -->
<result property="createTime" column="created_time"/>
<result property="UpdateTime" column="update_time"/>
<result property="GPUModel" column="GPUModel"/>
<result property="GPUMemorySize" column="GPUMemorySize"/>
<result property="Ip" column="Ip"/>
<result property="isDeleted" column="is_deleted"/>
<result property="GPUMaxMemory" column="GPUMaxMemory"/>
</resultMap>
<!-- 动态条件查询 --> <!-- 动态条件查询 -->
<select id="selectByFields" <select id="selectByFields"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource"> resultMap="gpuResourceMap">
SELECT * SELECT *
FROM Ipz.public.gpu_resource FROM Ipz.public.gpu_resource
<where> <where>

View File

@ -44,16 +44,22 @@
<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>
</mapper> </mapper>

View File

@ -3,8 +3,8 @@
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper"> <mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.PublishMapper">
<insert id="insert"> <insert id="insert">
INSERT INTO service_publish INSERT INTO service_publish
(id,model_id,api_url,create_time) (id,model_id,api_url,create_time,ip)
values (#{id}, #{modelId}, #{apiUrl}, #{createTime}) values (#{id}, #{modelId}, #{apiUrl}, #{createTime},#{ip})
</insert> </insert>
<select id="getByApiUrl" resultType="java.lang.Long"> <select id="getByApiUrl" resultType="java.lang.Long">