Compare commits

9 Commits

Author SHA1 Message Date
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
64 changed files with 932 additions and 1351 deletions

View File

@ -106,3 +106,73 @@
### 📅 明日计划
- 模型信息管理前端页面开发
## 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日
### ✅ 今日完成
- 基本完成了版本构建、修改生命周期、上下线、模型评估和详情功能
- 修改了模型评估和生命周期更新的一些细节,便于和前端接口协调
### 🚧 进行中
- 模型管理页面前端细节优化
### 📅 明日计划
- 模型管理页面前端细节优化

26
pom.xml
View File

@ -18,7 +18,7 @@
<url/>
<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<!-- 添加 Spring Cloud 版本控制 -->
<spring-cloud.version>2022.0.4</spring-cloud.version>
</properties>
@ -165,6 +165,30 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</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>
<build>

View File

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

View File

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

View File

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

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

@ -15,7 +15,6 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.client.RestTemplate;
import java.time.Duration;
@ -36,11 +35,6 @@ public class RedisConfig {
@Value("${spring.data.redis.ssl:false}")
private boolean useSsl;
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
public RedisConnectionFactory redisConnectionFactory() {
// 1. 创建 SocketOptions
@ -89,6 +83,12 @@ public class RedisConfig {
RedisTemplate<String, Object> template = new RedisTemplate<>();
Logger log = (Logger) LoggerFactory.getLogger(RedisConfig.class);
log.info("开始创建redis模板对象...");
//RedisTemplate redisTemplate = new RedisTemplate();
//设置redis的连接工厂对象
//redisTemplate.setConnectionFactory(redisConnectionFactory);
//设置redis key的序列化器
//redisTemplate.setKeySerializer(new StringRedisSerializer());
//RedisTemplate<String, GpuResource> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());

View File

@ -10,5 +10,10 @@ public class MessageConstant {
public static final String ERROR_DEPLOYED_TO_DESIGNING = "已部署的模型不能直接调整成设计,需先下线再设计";
public static final String ERROR_ABANDONED_CANNOT_UPDATE = "已废弃的模型只能查看信息,不能更新生命周期";
public static final String ERROR_TRAINING_INVALID_TRANSITION = "训练中的模型只能调整成设计和评估";
public static final String UPDATE_FAILURE = "更新模型生命周期失败";
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.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
@Tag(name ="算法创建相关接口")
@RestController
@RequestMapping("/api/algorithm")
@Slf4j
@CrossOrigin(origins = "http://localhost:3000")
public class AlgorithmInfoController {
@Autowired
private AlgorithmInfoService algorithmInfoService;
@Autowired
private ObjectMapper objectMapper;
@GetMapping("/{id}")
public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
@ -63,15 +71,51 @@ public class AlgorithmInfoController {
ResponseEntity.badRequest().body("Delete failed");
}
/**
* 算法创建
*/
@PostMapping
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary ="算法创建")
public OptResult save(@RequestBody AlgorithmInfo algorithmInfo){
log.info("新增算法",algorithmInfo);
algorithmInfoService.save(algorithmInfo);
return OptResult.success("算法创建成功");
public OptResult save(@RequestParam("algorithm") String algorithmJson,
@RequestPart(value = "algorithmFile") MultipartFile file) {
try {
AlgorithmInfo algorithmInfo = objectMapper.readValue(algorithmJson, AlgorithmInfo.class);
log.info("新增算法: {}, 文件: {}", algorithmInfo, (file != null ? file.getOriginalFilename() : "无文件"));
algorithmInfoService.save(algorithmInfo, file);
return OptResult.success("算法创建成功");
} catch (IOException e) {
log.error("JSON转换失败", e);
return OptResult.error("新增算法失败: " + e.getMessage());
} catch (Exception e) {
log.error("新增算法失败", e);
return OptResult.error("新增算法失败: " + e.getMessage());
}
}
/**
* 根据算法名称模糊查询算法信息
* @param keyword 模糊查询关键词
* @return 符合条件的算法信息列表
*/
@GetMapping("/search")
public ResponseEntity<List<AlgorithmInfo>> searchByName(@RequestParam String keyword) {
List<AlgorithmInfo> algorithmInfos = algorithmInfoService.getByNameLike(keyword);
return ResponseEntity.ok(algorithmInfos);
}
/**
* 算法运行
*/
@PostMapping("/run/{id}")
@Operation(summary = "运行")
public OptResult run(@PathVariable Long id,@RequestBody String param){
log.info("运行",id);
String result = algorithmInfoService.run(id,param);
return OptResult.success("运行成功"+result);
}
/**
* 前端列表返回算法名称
*/
@GetMapping("/names")
@Operation(summary = "列表返回算法名称")
public List<String> getNames(){
return algorithmInfoService.getAllNames();
}
}

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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@Tag(name ="数据集相关接口")
@RestController
@RequestMapping("/dataset")
@Slf4j
@CrossOrigin(origins = "http://localhost:3000")
public class DatasetController {
@Autowired
private DatasetService datasetService;
/**
* 新增数据集
* 新增数据集(整合文件上传)
* @param datasetDTO
* @param file
* @return
*/
@Operation(summary ="新增数据集")
@PostMapping
public OptResult save(@RequestBody DatasetDTO datasetDTO) {
log.info("新增数据集:{}", datasetDTO);
datasetService.save(datasetDTO);
return OptResult.success();
@Operation(summary = "新增数据集")
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public OptResult save(
@ModelAttribute("dataset") DatasetDTO datasetDTO,
@RequestPart(value = "file", required = false) MultipartFile file) {
log.info("新增数据集: {}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
try {
datasetService.save(datasetDTO, file);
return OptResult.success();
} catch (Exception e) {
log.error("新增数据集失败", e);
return OptResult.error("新增数据集失败: " + e.getMessage());
}
}
/**
@ -43,17 +59,17 @@ public class DatasetController {
return OptResult.success(pageResult);
}
/**
* 修改数据集
* @param datasetDTO
* @return
*/
@Operation(summary ="修改数据集")
@PutMapping
public OptResult update(@RequestBody DatasetDTO datasetDTO){
log.info("修改数据集",datasetDTO);
datasetService.update(datasetDTO);
@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public OptResult update(@ModelAttribute("dataset") DatasetDTO datasetDTO,
@RequestPart(value = "file", required = false) MultipartFile file){
log.info("修改数据集{}, 文件: {}", datasetDTO, (file != null ? file.getOriginalFilename() : "无文件"));
datasetService.update(datasetDTO,file);
return OptResult.success();
}
@ -72,4 +88,34 @@ public class DatasetController {
return OptResult.success("批量删除成功");
}
/**
* 下载数据集
* @param datasetId 数据集ID
* @return 数据集文件
*/
@Operation(summary = "下载数据集")
@GetMapping("/download/{datasetId}")
public ResponseEntity<byte[]> downloadDataset(@PathVariable Long datasetId) {
log.info("下载数据集ID{}", datasetId);
try {
// TODO: 调用分布式存储系统的接口获取数据集文件的输入流
InputStream inputStream = datasetService.downloadDataset(datasetId);
if (inputStream == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
byte[] fileBytes = inputStream.readAllBytes();
inputStream.close();
// 设置响应头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", "dataset_" + datasetId + ".zip");
return new ResponseEntity<>(fileBytes, headers, HttpStatus.OK);
} catch (IOException e) {
log.error("下载数据集失败", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -7,12 +7,10 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@Tag(name = "模型评估相关接口")
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/evaluation")
@Slf4j

View File

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

View File

@ -1,5 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import io.swagger.v3.oas.annotations.Operation;
@ -52,14 +53,16 @@ public class ModelController {
}
@Operation(summary = "模型更新")
@PutMapping("/updateModel")
public OptResult updateModel(@RequestBody ModelVersionDTO dto){
log.info("模型更新");
@PutMapping("/updateModel/{id}")
public OptResult updateModel(@PathVariable("id") Long id, @RequestBody ModelVersionDTO dto) {
log.info("模型更新id: {}", id);
dto.setId(id);
modelService.updateModel(dto);
return OptResult.success();
}
@Operation(summary = "模型版本删除")
@DeleteMapping("/deleteModelVersion")
public OptResult deleteModelVersion(Long id){
@ -70,10 +73,18 @@ public class ModelController {
@Operation(summary = "更新生命周期")
@PutMapping("/updateLifeCycle")
public OptResult updateLifeCycle(Long id,String lifeCycle){
public OptResult updateLifeCycle(@RequestParam Long id, @RequestParam String lifeCycle){
log.info("更新生命周期");
modelService.updateLifeCycle(id,lifeCycle);
return OptResult.success();
try {
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 = "查询生命周期列表")

View File

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

View File

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

View File

@ -0,0 +1,12 @@
package com.bipt.intelligentapplicationorchestrationservice.deploy.entity;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class DeploymentResource {
private final GpuResource gpu;
private final String url;
}

View File

@ -1,87 +0,0 @@
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 +
'}';
}
}

View File

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

View File

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

View File

@ -1,102 +0,0 @@
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 + '\'' +
'}';
}
}

View File

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

View File

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
package com.bipt.intelligentapplicationorchestrationservice.entity.dto;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

View File

@ -1,4 +1,4 @@
package com.bipt.intelligentapplicationorchestrationservice.entity;
package com.bipt.intelligentapplicationorchestrationservice.entity.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
@ -18,34 +18,6 @@ public class GpuResource {
@TableField("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")
private Integer GPUMemorySize;
@ -93,33 +65,32 @@ public class GpuResource {
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;
}
// 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;
// }
}

View File

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

View File

@ -1,6 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
package com.bipt.intelligentapplicationorchestrationservice.entity.vo;
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum;
import java.io.Serializable;

View File

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

View File

@ -1,13 +0,0 @@
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("模型评估未通过,无法部署");
}
}

View File

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

View File

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

View File

@ -29,4 +29,12 @@ public interface AlgorithmInfoMapper {
@Delete("DELETE FROM algorithm_info WHERE id = #{id}")
int deleteById(Long id);
@Select("select description from algorithm_info where id = #{id}")
String getDescriptionById(Long id);
@Select("select algorithm_file from algorithm_info where id = #{id}")
String getFileById(Long id);
@Select("select algorithm_name from algorithm_info")
List<String> getAllNames();
List<AlgorithmInfo> selectByNameLike(String keyword);
}

View File

@ -1,13 +1,13 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.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 = "spring")
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface GpuMapper {
GpuResource toEntity(GpuCreateDTO dto);
GpuResource toEntity(GpuUpdateDTO dto);

View File

@ -1,6 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

View File

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

View File

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

View File

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

View File

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

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;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@ -12,6 +13,11 @@ public interface AlgorithmInfoService {
boolean delete(Long id);
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

@ -2,7 +2,7 @@ package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.exception.CacheInitException;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

View File

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

View File

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

View File

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

View File

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

View File

@ -3,19 +3,28 @@ package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.List;
@Service
@Slf4j
public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
@Autowired
private AlgorithmInfoMapper algorithmInfoMapper;
@Value("${algorithm.upload.dir:/tmp/algorithm-files/}") // 默认上传目录
private String uploadDir;
@Override
public AlgorithmInfo getById(Long id) {
return algorithmInfoMapper.selectById(id);
@ -61,22 +70,80 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
return true;
}
/**
* 算法创建
* @param algorithmInfo
*/
@Override
@Transactional
public void save(AlgorithmInfo algorithmInfo) {
public void save(AlgorithmInfo algorithmInfo, MultipartFile file) {
String algorithmName = algorithmInfo.getAlgorithmName();
//查找表里是否有重复的算法,如果有则报错
// 检查同名算法
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
if (duplicateName != null){
throw new RuntimeException("算法已存在");
if (duplicateName != null) {
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);
}
@Override
public String run(Long id, String param) {
String file = algorithmInfoMapper.getFileById(id);
StringBuilder result = new StringBuilder(); // 用于存储结果
try {
// 构建命令,将 param 作为参数传递给 Python 脚本
ProcessBuilder pb = new ProcessBuilder("python", file, param);
Process process = pb.start();
// 读取标准输出(脚本执行结果)
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
result.append(line).append("\n");
}
// 读取错误输出
BufferedReader errorReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()));
String errorLine;
while ((errorLine = errorReader.readLine()) != null) {
result.append("Error: ").append(errorLine).append("\n");
}
int exitCode = process.waitFor();
result.append("Exit Code: ").append(exitCode);
} catch (Exception e) {
result.append("执行异常: ").append(e.getMessage());
e.printStackTrace();
}
return result.toString(); // 返回完整结果
}
@Override
public List<String> getAllNames() {
return algorithmInfoMapper.getAllNames();
}
/**
* 模糊查询
* @param keyword
* @return
*/
@Override
public List<AlgorithmInfo> getByNameLike(String keyword) {
return algorithmInfoMapper.selectByNameLike(keyword);
}
}

View File

@ -12,12 +12,17 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.FROM_DATABASE;
import static com.bipt.intelligentapplicationorchestrationservice.enumeration.DatasetType.UPLOAD;
@Service
@Slf4j
@ -25,63 +30,65 @@ public class DatasetServiceImpl implements DatasetService {
@Autowired
private DatasetMapper datasetMapper;
/**
* 新增数据集
* @param datasetDTO
*/
@Override
@Transactional
public void save(DatasetDTO datasetDTO) {
//判断数据集类型,如果是本地上传则保存,若用调用数据仓库进入下一步
// 获取数据集类型
public void save(DatasetDTO datasetDTO, MultipartFile file) {
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
// 根据类型处理数据
switch (datasetType) {
case UPLOAD:
//TODO 保存到分布式文件系统
break;
case FROM_DATABASE:
String args = datasetDTO.getArgs();
//TODO 根据筛选条件调用数据仓库中的数据
if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
try {
//todo存入分布式文件系统
//TODO 调用数据仓库保存到分布式文件系统
break;
default:
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType);
// 生成文件名(建议使用 UUID 避免重复)
String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
// 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
String filePath = "/your/storage/path/" + fileName;
// 保存文件到磁盘(示例代码,需处理 IO 异常)
file.transferTo(new File(filePath));
// 更新数据集路径
datasetDTO.setDsPath(filePath); // 取消注释,并确保 datasetDTO 有 setDsPath 方法
} catch (IOException e) {
throw new RuntimeException("文件上传失败: " + e.getMessage());
}
} else if (datasetType == FROM_DATABASE){
//todo 从数据仓库中查询 并选择筛选条件
}
// 保存数据集实体
DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);
datasetEntity.setDatasetStatus(StatusConstant.ENABLE);
BeanUtils.copyProperties(datasetDTO, datasetEntity);
datasetEntity.setCreateTime(LocalDateTime.now());
datasetEntity.setUpdateTime(LocalDateTime.now());
datasetMapper.insert(datasetEntity);
}
/**
* 修改数据集
*
* @param datasetDTO
* @param file
*/
@Override
@Transactional
public void update(DatasetDTO datasetDTO) {
/*DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);*/
public void update(DatasetDTO datasetDTO, MultipartFile file) {
DatasetType datasetType = DatasetType.fromCode(datasetDTO.getDatasetType());
// 根据类型处理数据
switch (datasetType) {
case UPLOAD:
//TODO 覆盖保存到分布式文件系统中
break;
case FROM_DATABASE:
//TODO 覆盖数据文件
break;
default:
throw new IllegalArgumentException("不支持的数据集类型: " + datasetType);
if (datasetType == UPLOAD && file != null && !file.isEmpty()) {
try {
// 生成文件名(建议使用 UUID 避免重复)
String fileName = UUID.randomUUID() + "-" + file.getOriginalFilename();
// 假设使用本地存储(实际需对接分布式文件系统,如 MinIO、OSS 等)
String filePath = "/your/storage/path/" + fileName;
// 保存文件到磁盘(示例代码,需处理 IO 异常)
file.transferTo(new File(filePath));
// 更新数据集路径
datasetDTO.setDsPath(filePath); // 取消注释,并确保 datasetDTO 有 setDsPath 方法
} catch (IOException e) {
throw new RuntimeException("文件上传失败: " + e.getMessage());
}
} else if (datasetType == FROM_DATABASE){
//todo 从数据仓库中查询 并选择筛选条件
}
DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);
datasetEntity.setUpdateTime(LocalDateTime.now());
@ -112,4 +119,14 @@ public class DatasetServiceImpl implements DatasetService {
datasetMapper.deleteBatch(datasetIds);
}
/**
* 下载
* @param datasetId
* @return
*/
@Override
public InputStream downloadDataset(Long datasetId) {
// TODO: 调用分布式存储系统的接口获取数据集文件的输入流
return null;
}
}

View File

@ -42,7 +42,7 @@ public class ModelServiceImpl implements ModelService {
modelVersion.setModelId(modelInfo.getId());
modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
modelVersion.setOperateUser("zs"); //这里的写死的后续需要修改应该是当前登录用户的id
modelMapper.insertModelVersion(modelVersion);
}
@ -81,6 +81,7 @@ public class ModelServiceImpl implements ModelService {
@Override
public void updateModel(ModelVersionDTO dto) {
// 更新模型还需要更新操作人和时间
log.info("更新模型");
modelMapper.update(dto);
}
@ -110,14 +111,14 @@ public class ModelServiceImpl implements ModelService {
ModelLifecycle currentLifeCycle;
ModelLifecycle targetLifeCycle;
try {
currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文
targetLifeCycle = ModelLifecycle.fromDescription((lifeCycleDescription).trim()); // 前端传中文
currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文
targetLifeCycle = ModelLifecycle.valueOf(lifeCycleDescription.trim()); // 前端传英文代码,直接转换
} catch (IllegalArgumentException e) {
log.error(MessageConstant.LifeCycle_Undefined + ":{}", e.getMessage());
throw e;
}
// 2. 业务逻辑校验
// 2. 业务逻辑校验(保持不变)
switch (currentLifeCycle) {
case DEPLOYED:
if (targetLifeCycle == ModelLifecycle.DESIGNING) {
@ -142,7 +143,7 @@ public class ModelServiceImpl implements ModelService {
int affectedRows = modelMapper.updateLifeCycleById(id, targetLifeCycle.getDbValue());
if (affectedRows == 0) {
log.error("更新模型生命周期失败");
throw new RuntimeException(MessageConstant.UPDATE_FAILURE);
throw new RuntimeException(MessageConstant.LIFECYCLE_UPDATE_FAILURE);
}
log.info("模型生命周期更新成功,新状态为: {}", targetLifeCycle);

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,16 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import org.apache.ibatis.cache.CacheException;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Service
@ -127,26 +124,4 @@ public class RedisCacheService {
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);
}
}
}

View File

@ -1,16 +1,14 @@
package com.bipt.intelligentapplicationorchestrationservice.service.impl;
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuResourceDao;
import com.bipt.intelligentapplicationorchestrationservice.mapper.GpuMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ErrorCodeEnum;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ResponseVO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuCreateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuResponseDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.dto.GpuUpdateDTO;
import com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource;
import com.bipt.intelligentapplicationorchestrationservice.entity.enums.ErrorCodeEnum;
import com.bipt.intelligentapplicationorchestrationservice.entity.vo.ResponseVO;
import com.bipt.intelligentapplicationorchestrationservice.service.GpuManageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -22,128 +20,53 @@ import java.util.stream.Collectors;
@Service
public class GpuManageServiceImpl implements GpuManageService {
private static final Logger logger = LoggerFactory.getLogger(GpuManageServiceImpl.class);
@Autowired
private GpuResourceDao gpuDao;
@Autowired
private GpuMapper gpuMapper;
@Autowired
private GpuResourceDao gpuResourceDao;
@Transactional
@Override
//创建GPU资源
public ResponseVO createGpuResource(GpuCreateDTO dto) {
try {
logger.info("创建GPU资源请求: {}", dto);
GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.insert(entity);
logger.info("创建GPU资源成功, ID: {}", entity.getGPUId());
return ResponseVO.success(entity);
} catch (Exception e) {
logger.error("创建GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
}
GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.insert(entity);
return ResponseVO.success(entity);
}
@Transactional
@Override
//删除GPU资源逻辑删除
public ResponseVO deleteGpuResource(Long gpuId) {
logger.info("删除GPU资源请求, ID: {}", gpuId);
try {
GpuResource entity = gpuDao.selectById(gpuId);
if (entity == null) {
logger.warn("GPU资源不存在, ID: {}", gpuId);
return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND);
}
gpuDao.isDeleted(gpuId);
logger.info("逻辑删除GPU资源成功, ID: {}", gpuId);
return ResponseVO.success();
} catch (Exception e) {
logger.error("删除GPU资源失败, ID: {}, 错误: {}", gpuId, e.getMessage(), e);
return ResponseVO.error(ErrorCodeEnum.INTERNAL_SERVER_ERROR);
GpuResource entity = gpuDao.selectById(gpuId);
if (entity == null) {
return ResponseVO.error(ErrorCodeEnum.GPU_NOT_FOUND);
}
gpuDao.isDeleted(gpuId);
return ResponseVO.success();
}
@Transactional
@Override
//更新GPU资源
public void updateGpuResource(GpuUpdateDTO dto) {
logger.info("更新GPU资源请求: {}", dto);
try {
GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.updateById(entity);
logger.info("更新GPU资源成功, ID: {}", entity.getGPUId());
} catch (Exception e) {
logger.error("更新GPU资源失败: {}, 参数: {}", e.getMessage(), dto, e);
throw new RuntimeException("更新GPU资源失败", e);
}
GpuResource entity = gpuMapper.toEntity(dto);
gpuDao.updateById(entity);
}
@Override
//模糊匹配查询
public List<GpuResponseDTO> searchByCriteria(String model, Integer memorySize, String ip) {
// PermissionCheckUtil.checkTenantAccess();
Map<String, Object> params = new HashMap<>();
if(model != null) params.put("model", "%" + model + "%");
if(memorySize != null) params.put("memorySize", memorySize);
if(ip != null) params.put("ip", ip);
if(model != null) params.put("model","%" + model + "%");
if(memorySize!=null) params.put("memorySize", memorySize);
if(ip!=null) params.put("ip", ip);
logger.info("查询GPU资源条件: {}", params);
List<GpuResource> entities = gpuResourceDao.selectByFields(params);
try {
List<GpuResource> entities = gpuDao.selectByFields(params);
logger.info("查询到 {} 条GPU资源", entities.size());
return entities.stream().map(gpuMapper::toDTO).collect(Collectors.toList());
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;
}
}
}

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

@ -1,78 +0,0 @@
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";
}
}

View File

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

View File

@ -32,16 +32,23 @@ spring.cloud.gateway.routes[0].uri=lb://intelligent-application-orchestration-se
spring.cloud.gateway.routes[0].predicates[0]=Path=/request
logging.level.org.springframework.web=DEBUG
# ????????
model.evaluation.service-url=http://evaluation-service:8080/api/v1
model.evaluation.api-timeout=3000
# ????????
model.repository.url=https://model-repo.example.com/api/v1
model.repository.api-key=SECURE_API_KEY_12345
model.repository.timeout=5000
#SQL ????????
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
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

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!=''">
dataset_name LIKE CONCAT('%', #{datasetName}, '%')
</if>
<if test="datasetType != null">
and dataset_type=#{datasetType}
</if>
<if test="datasetStatus != null">
and dataset_status=#{datasetStatus}
</if>
<if test="dsPath != null">
and ds_path=#{dsPath}
</if>
<if test="args != null">
and args=#{args}
</if>
<if test="createTime != null">
and create_time=#{createTime}
</if>
<if test="updateTime != null">
and update_time=#{updateTime}
</if>
</where>
</select>
</mapper>

View File

@ -18,6 +18,6 @@
<if test="status != null">
status=#{status}
</if>
where model_id=#{id}
where id=#{id}
</update>
</mapper>

View File

@ -5,7 +5,7 @@
<!-- 动态条件查询 -->
<select id="selectByFields"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource">
SELECT *
FROM Ipz.public.gpu_resource
<where>
@ -28,7 +28,7 @@
<!-- 分页查询 -->
<select id="findByPage"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource">
SELECT *
FROM gpu_resource
WHERE is_deleted = 0
@ -38,7 +38,7 @@
<!-- 增量同步查询 -->
<select id="findModifiedSince"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource">
SELECT *, is_deleted
FROM gpu_resource
WHERE update_time &gt; #{since}
@ -47,7 +47,7 @@
<!-- 带锁查询 -->
<select id="selectByIdWithLock"
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.GpuResource">
resultType="com.bipt.intelligentapplicationorchestrationservice.entity.entity.GpuResource">
SELECT *
FROM gpu_resource
WHERE GPUId = #{gpuId}

View File

@ -44,16 +44,22 @@
<update id="update">
UPDATE model_version
<set>
<if test="modelSize != null">
model_size = #{modelSize},
</if>
<if test="modelSuperArgs != null">
model_super_args = #{modelSuperArgs},
</if>
<if test="modelArgsSize != null">
model_args_size = #{modelArgsSize},
</if>
<if test="datasetId != null">dataset_id = #{datasetId},</if>
<if test="modelConfig != null">model_config = #{modelConfig},</if>
<if test="modelPath != null">model_path = #{modelPath},</if>
<if test="status != null">status = #{status},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="modelSize != null">model_size = #{modelSize},</if>
<if test="dataPreHandleFile != null">data_pre_handle_file = #{dataPreHandleFile},</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>
WHERE id = #{id
WHERE id = #{id}
</update>
</mapper>