xiaohucoding #16
3
pom.xml
3
pom.xml
@ -38,7 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2022.0.0.0</version> <!-- 适配 Spring Boot 3.1.x 的正确版本 -->
|
||||
<version>2022.0.0.0-RC2</version> <!-- 适配 Spring Boot 3.1.x 的正确版本 -->
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@ -55,6 +55,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
|
@ -1,15 +1,20 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.controller;
|
||||
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
|
||||
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name ="算法创建相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/algorithm")
|
||||
@Slf4j
|
||||
public class AlgorithmInfoController {
|
||||
|
||||
@Autowired
|
||||
@ -57,4 +62,16 @@ public class AlgorithmInfoController {
|
||||
ResponseEntity.ok("Delete successful") :
|
||||
ResponseEntity.badRequest().body("Delete failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* 算法创建
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary ="算法创建")
|
||||
public OptResult save(@RequestBody AlgorithmInfo algorithmInfo){
|
||||
log.info("新增算法",algorithmInfo);
|
||||
algorithmInfoService.save(algorithmInfo);
|
||||
return OptResult.success("算法创建成功");
|
||||
}
|
||||
|
||||
}
|
@ -21,8 +21,6 @@ public class PublishController {
|
||||
@Autowired
|
||||
private PublishService publishService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private NacosServiceUtil nacosServiceUtil;
|
||||
|
||||
|
@ -74,13 +74,16 @@ public class ServiceAPIController {
|
||||
return OptResult.success("资源释放成功");
|
||||
}
|
||||
|
||||
@PostMapping("/request")
|
||||
@PostMapping("/request/{modelId}")
|
||||
@Operation(summary = "请求调度")
|
||||
@Transactional
|
||||
public OptResult schedule(@PathVariable Long modelId) {
|
||||
// 1. 存储modelConfig到缓存
|
||||
String modelConfig = serviceAPIService.getByModelId(modelId);
|
||||
int requestMemorySize = parseGpuMemorySize(modelConfig);
|
||||
if (requestMemorySize == -1){
|
||||
return OptResult.error("解析配置失败,请检查模型:" + modelId +"是否存在");
|
||||
}
|
||||
String modelConfigKey = "modelConfig:" + modelId;
|
||||
redisTemplate.opsForValue().set(modelConfigKey, modelConfig);
|
||||
// 2. 获取Nacos实例IP列表
|
||||
|
@ -15,16 +15,12 @@ public class ApiRequestGlobalFilter implements GlobalFilter, Ordered {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
|
||||
// 检查请求路径和方法
|
||||
if (request.getURI().getPath().equals("/request") &&
|
||||
if (request.getURI().getPath().equals("/request/{id}") &&
|
||||
request.getMethod() == HttpMethod.POST) {
|
||||
|
||||
// 在此处添加拦截逻辑
|
||||
System.out.println("拦截到POST /request请求");
|
||||
|
||||
}
|
||||
|
||||
// 继续处理请求
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
@ -1,7 +1,16 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AlgorithmInfo {
|
||||
private Long id;
|
||||
private String algorithmName;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -18,6 +19,7 @@ public class ServicePublishDTO implements Serializable {
|
||||
private Long id;
|
||||
private Long modelId;
|
||||
private String apiUrl;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
private String ip;
|
||||
}
|
||||
|
@ -11,4 +11,7 @@ public interface AlgorithmInfoService {
|
||||
boolean update(AlgorithmInfo algorithmInfo);
|
||||
boolean delete(Long id);
|
||||
boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo);
|
||||
}
|
||||
|
||||
void save(AlgorithmInfo algorithmInfo);
|
||||
|
||||
}
|
@ -60,4 +60,23 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 算法创建
|
||||
* @param algorithmInfo
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(AlgorithmInfo algorithmInfo) {
|
||||
String algorithmName = algorithmInfo.getAlgorithmName();
|
||||
//查找表里是否有重复的算法,如果有则报错
|
||||
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
|
||||
if (duplicateName != null){
|
||||
throw new RuntimeException("算法已存在");
|
||||
}
|
||||
//todo 算法文件分布式存入分布式存储中
|
||||
|
||||
|
||||
algorithmInfoMapper.insert(algorithmInfo);
|
||||
}
|
||||
}
|
@ -29,6 +29,13 @@ spring.cloud.gateway.routes[0].predicates[0]=Path=/request
|
||||
|
||||
|
||||
|
||||
logging.level.org.springframework.web=DEBUG
|
||||
|
||||
#SQL 语句日志输出配置
|
||||
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
|
||||
# 服务路由配置
|
||||
spring.cloud.gateway.routes[0].id=request-service-route
|
||||
spring.cloud.gateway.routes[0].uri=lb://intelligent-application-orchestration-service
|
||||
spring.cloud.gateway.routes[0].predicates[0]=Path=/request
|
||||
|
@ -2,9 +2,9 @@
|
||||
spring.application.name=intelligent-application-orchestration-service
|
||||
|
||||
# Nacos配置中心地址(引导阶段加载配置)
|
||||
spring.cloud.nacos.config.server-addr=192.168.100.1:8848
|
||||
spring.cloud.nacos.config.server-addr=113.44.217.169:8848
|
||||
spring.cloud.nacos.config.data-id=${spring.application.name}.properties
|
||||
spring.cloud.nacos.config.group=DEFAULT_GROUP
|
||||
|
||||
# Nacos服务注册地址(引导阶段注册服务)
|
||||
spring.cloud.nacos.discovery.server-addr=192.168.100.1:8848
|
||||
spring.cloud.nacos.discovery.server-addr=113.44.217.169:8848
|
Reference in New Issue
Block a user