修改:hpc求解文件分片上传;文件按照用户id区分;求解器文件路径空格问题;输出文件out绑定jobId;comsol结果文件处理;abaqus求解文件处理
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
package com.sdm.common.config;
|
||||
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.handler.timeout.WriteTimeoutHandler;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.netty.resources.ConnectionProvider;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
public class WebClientConfig {
|
||||
|
||||
@Value("${webClient.maxConnections:50}")
|
||||
private int maxConnections;
|
||||
|
||||
@Value("${webClient.pendingAcquireMaxCount:200}")
|
||||
private int pendingAcquireMaxCount;
|
||||
|
||||
@Value("${webClient.pendingAcquireTimeout:30}")
|
||||
private int pendingAcquireTimeout;
|
||||
|
||||
@Value("${webClient.maxIdleTime:60}")
|
||||
private int maxIdleTime;
|
||||
|
||||
@Value("${webClient.maxLifeTime:5}")
|
||||
private int maxLifeTime;
|
||||
|
||||
@Value("${webClient.responseTimeoutMinutes:30}")
|
||||
private int responseTimeoutMinutes;
|
||||
|
||||
@Value("${webClient.readTimeoutMinutes:30}")
|
||||
private int readTimeoutMinutes;
|
||||
|
||||
@Value("${webClient.writeTimeoutMinutes:30}")
|
||||
private int writeTimeoutMinutes;
|
||||
|
||||
@Value("${webClient.maxInMemorySize:16384}")
|
||||
private int maxInMemorySize;
|
||||
|
||||
@Value("${webClient.connectTimeout:10000}")
|
||||
private int connectTimeout;
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public WebClient webClient() {
|
||||
|
||||
// 1. 连接池配置
|
||||
ConnectionProvider connectionProvider = ConnectionProvider.builder("webclient-pool")
|
||||
.maxConnections(maxConnections) // 最大连接
|
||||
.pendingAcquireMaxCount(pendingAcquireMaxCount) // 等待队列
|
||||
.pendingAcquireTimeout(Duration.ofSeconds(pendingAcquireTimeout))
|
||||
.maxIdleTime(Duration.ofSeconds(maxIdleTime)) // 空闲连接
|
||||
.maxLifeTime(Duration.ofMinutes(maxLifeTime)) // 连接最大生命周期
|
||||
.build();
|
||||
|
||||
// 2. HttpClient 配置
|
||||
HttpClient httpClient = HttpClient.create(connectionProvider)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout)
|
||||
.responseTimeout(Duration.ofMinutes(responseTimeoutMinutes)) // 可能是大文件下载
|
||||
.doOnConnected(conn ->
|
||||
conn.addHandlerLast(new ReadTimeoutHandler(readTimeoutMinutes, TimeUnit.MINUTES))
|
||||
.addHandlerLast(new WriteTimeoutHandler(writeTimeoutMinutes, TimeUnit.MINUTES))
|
||||
)
|
||||
.compress(true); // gzip
|
||||
|
||||
// 3. WebClient 构建
|
||||
return WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||
// 禁用大内存聚合(否则大文件会 OOM)
|
||||
.exchangeStrategies(ExchangeStrategies.builder()
|
||||
.codecs(configurer ->
|
||||
configurer.defaultCodecs()
|
||||
.maxInMemorySize(maxInMemorySize) // 16KB
|
||||
)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,8 +58,7 @@ public class HpcCommandExcuteUtil {
|
||||
@Autowired
|
||||
private HttpClientUtil httpClientUtil;
|
||||
|
||||
@Autowired
|
||||
private WebClient webClient;
|
||||
|
||||
|
||||
public String excuteCmd(String command) {
|
||||
if(Objects.equals(hpcExcuteWay,"remote")){
|
||||
@@ -144,7 +143,7 @@ public class HpcCommandExcuteUtil {
|
||||
return nodeInfos;
|
||||
}
|
||||
|
||||
public ResponseEntity<StreamingResponseBody> hpcDownloadFile(String path, Long fileSize) {
|
||||
public ResponseEntity<StreamingResponseBody> hpcDownloadFile(String path, Long fileSize,WebClient pbsWebClient) {
|
||||
String fileName = extractFileName(path);
|
||||
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
|
||||
@@ -154,7 +153,7 @@ public class HpcCommandExcuteUtil {
|
||||
|
||||
// 调用 B 服务并流式写出
|
||||
DataBufferUtils.write(
|
||||
webClient.get()
|
||||
pbsWebClient.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.bodyToFlux(DataBuffer.class),
|
||||
@@ -209,7 +208,7 @@ public class HpcCommandExcuteUtil {
|
||||
}
|
||||
|
||||
// 调用工具上传hpc文件
|
||||
public String uploaHpcFile(MultipartFile file, String subDir) {
|
||||
public String uploaHpcFile(MultipartFile file, String subDir,WebClient pbsWebClient) {
|
||||
try {
|
||||
// 3. Multipart body 构建
|
||||
MultipartBodyBuilder builder = new MultipartBodyBuilder();
|
||||
@@ -221,7 +220,7 @@ public class HpcCommandExcuteUtil {
|
||||
});
|
||||
builder.part("subDir", subDir);
|
||||
// 4. 调用 B 服务上传接口
|
||||
String uploadResult = webClient.post()
|
||||
String uploadResult = pbsWebClient.post()
|
||||
.uri(remoteUploadFileUrl)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.body(BodyInserters.fromMultipartData(builder.build()))
|
||||
@@ -230,7 +229,7 @@ public class HpcCommandExcuteUtil {
|
||||
.block();
|
||||
return uploadResult;
|
||||
} catch (Exception e) {
|
||||
System.out.println("上传失败");
|
||||
log.error("Hpc求解文件上传失败:{}",e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user