From 89a67ac48ecdde2189a499aa9869df6357550148 Mon Sep 17 00:00:00 2001 From: chenpeng0206 <123@qq.com> Date: Tue, 10 Mar 2026 18:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=97=E6=8E=A5=E5=85=A5abacus=20ap?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/bootstrap.yml | 6 +- .../platform/scheduling/AppScheduleTask.java | 31 +++++- .../platform/service/CSCollectService.java | 4 +- .../service/impl/CSCollectServiceImpl.java | 26 ++--- .../impl/CSServiceVersionServiceImpl.java | 4 +- .../com/ruoyi/platform/utils/MinioUtil.java | 104 ++++++++---------- .../src/main/resources/bootstrap.yml | 8 +- 7 files changed, 99 insertions(+), 84 deletions(-) diff --git a/ruoyi-gateway/src/main/resources/bootstrap.yml b/ruoyi-gateway/src/main/resources/bootstrap.yml index bcfd24d8..4a095eb1 100644 --- a/ruoyi-gateway/src/main/resources/bootstrap.yml +++ b/ruoyi-gateway/src/main/resources/bootstrap.yml @@ -14,16 +14,17 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: nacos-ci4s.argo.svc:8848 + server-addr: 172.20.32.121:31203 username: nacos password: h1n2x3j4y5@ retry: enabled: true + namespace: f4dffebe-4a37-4244-bff5-614bfbe98df7 config: username: nacos password: h1n2x3j4y5@ # 配置中心地址 - server-addr: nacos-ci4s.argo.svc:8848 + server-addr: 172.20.32.121:31203 # 配置文件格式 file-extension: yml # 共享配置 @@ -34,6 +35,7 @@ spring: - data-id: ${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} group: DEFAULT_GROUP refresh: true + namespace: f4dffebe-4a37-4244-bff5-614bfbe98df7 sentinel: # 取消控制台懒加载 eager: true diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AppScheduleTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AppScheduleTask.java index d1c36fa8..d3f07dff 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AppScheduleTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AppScheduleTask.java @@ -2,6 +2,7 @@ package com.ruoyi.platform.scheduling; import cn.hutool.core.lang.UUID; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -203,10 +204,8 @@ public class AppScheduleTask { String zipFileName = "batch_download_" + taskId + ".zip"; String zipFilePath = savePath + "/" + zipFileName; - HashMap upload = MapUtil.newHashMap(); - upload.put("input", (String) taskInfo.getByPath("input_file.direct_url")); - upload.put("output", saveFilePath); - csCollectService.allFileUpload(upload, savePath + "/" + zipFileName); + List inputFilePaths = readInputFilePath(taskInfo); + csCollectService.allFileUpload(inputFilePaths, saveFilePath, zipFilePath); HashMap batch_download = MapUtil.newHashMap(); batch_download.put("direct_url", zipFilePath); batch_download.put("filename", zipFileName); @@ -228,4 +227,28 @@ public class AppScheduleTask { // trainingTaskDao.update(trainingTask); // } //} + + /** + * 获取输入路径 + * + * @param taskInfo + * @return + */ + private List readInputFilePath(JSONObject taskInfo) { + List empty = new ArrayList<>();; + taskInfo.forEach((key, value) -> { + if (value instanceof JSONObject) { + JSONObject valueObj = (JSONObject) value; + if (valueObj.containsKey("direct_url")) { + + String directUrl = valueObj.getStr("direct_url"); + String filename = valueObj.getStr("filename"); + + String suffix = StrUtil.removeSuffix(directUrl, filename); + empty.add(suffix); + } + } + }); + return empty; + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/CSCollectService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/CSCollectService.java index aef41d8b..7a6aa599 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/CSCollectService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/CSCollectService.java @@ -5,7 +5,7 @@ import cn.hutool.json.JSONObject; import com.ruoyi.platform.domain.TrainingTask; import org.springframework.web.multipart.MultipartFile; -import java.util.HashMap; +import java.util.List; public interface CSCollectService { @@ -23,5 +23,5 @@ public interface CSCollectService { JSONObject singleFileDownload(Integer objectId, String savePath,String fileName) throws Exception; - void allFileUpload(HashMap upload, String zipFilePath) throws Exception; + void allFileUpload(List inputs, String output, String zipFilePath) throws Exception; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSCollectServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSCollectServiceImpl.java index 7556d4c4..b7e339ed 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSCollectServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSCollectServiceImpl.java @@ -101,8 +101,7 @@ public class CSCollectServiceImpl implements CSCollectService { .contentType("application/json") .execute() .body(); - JSONObject resData = returnResDataWithOK(res); - return (Integer) getByPath(resData, "object.objectID"); + return packageId; } /** @@ -123,7 +122,6 @@ public class CSCollectServiceImpl implements CSCollectService { CSAuthInfo csAuthInfo = getZSAuthInfoFromRedis(); List> hpcBindingFiles = buildHpcBindingFiles(taskParam, taskInfo); JSONObject params = convertToJobRequest(trainingTask.getTaskName(),clusterId, jobName, hpcBindingFiles, csAuthInfo.getUserId(), ntasks, nodes); - String url = csUrl + "/jsm/v2/jobs/submit"; String res = HttpUtils.sendBodyPostWithToken(url, params, csAuthInfo.getToken()); JSONObject resData = returnResDataWithOK(res); @@ -191,12 +189,13 @@ public class CSCollectServiceImpl implements CSCollectService { if (fileValue instanceof JSONObject) { JSONObject fileObj = (JSONObject) fileValue; // 提取 file_id 和 filename - Integer objectId = fileObj.getInt("file_id"); + Integer packageId = fileObj.getInt("file_id"); + String filename = fileObj.getStr("filename"); // 构建 binding 元素 Map binding = new HashMap<>(); - binding.put("paramName", fieldName); - binding.put("objectID", objectId); + binding.put("filename", filename); + binding.put("packageID", packageId); bindingFiles.add(binding); } } @@ -246,11 +245,12 @@ public class CSCollectServiceImpl implements CSCollectService { if (hpcBindingFiles != null) { for (Map fileInfo : hpcBindingFiles) { JSONObject binding = new JSONObject(); - binding.set("paramName", fileInfo.get("paramName")); + binding.set("paramName", "inputFile"); JSONObject resource = new JSONObject(); - resource.set("type", "object"); - resource.set("objectID", fileInfo.get("objectID")); + resource.set("type", "path"); + resource.set("path", "/"+fileInfo.get("filename")); + resource.set("packageID", fileInfo.get("packageID")); binding.set("resource", resource); bindingArray.set(binding); @@ -419,16 +419,17 @@ public class CSCollectServiceImpl implements CSCollectService { /** * 所有文件打包上传 * - * @param upload + * @param inputs + * @param output * @param zipFilePath * @throws Exception */ @Override - public void allFileUpload(HashMap upload, String zipFilePath) throws Exception { + public void allFileUpload(List inputs, String output, String zipFilePath) throws Exception { // 异步提交任务 CompletableFuture future = CompletableFuture.supplyAsync(() -> { try { - minioUtil.createZipFromDirectory(bucketName, upload, zipFilePath); + minioUtil.createZipFromDirectory(bucketName, inputs,output, zipFilePath); return "执行成功"; } catch (Exception e) { throw new RuntimeException("异步提交任务失败", e); @@ -436,7 +437,6 @@ public class CSCollectServiceImpl implements CSCollectService { }); // 处理异步结果 future.thenAcceptAsync(result -> { - log.info("所有文件打包上传成功,result: {}", result); }).exceptionally(ex -> { log.error("异步处理任务失败", ex); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSServiceVersionServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSServiceVersionServiceImpl.java index ef1056c1..a06189af 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSServiceVersionServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/CSServiceVersionServiceImpl.java @@ -187,11 +187,11 @@ public class CSServiceVersionServiceImpl implements ServiceVersionService { ServiceVersion serviceVersion = csServiceDao.getServiceVersionById(serviceVersionId); com.ruoyi.platform.domain.service.Service service = serviceDao.getServiceById(serviceVersion.getServiceId()); ServiceTemp serviceTemp = serviceTempService.getServiceTemp(service.getServiceTempId()); - Integer objectID = csCollectService.uploadFile(serviceTemp.getName(), file); + Integer packageId = csCollectService.uploadFile(serviceTemp.getName(), file); String savePath = "/mini-model-platform-data/cs-data/upload/"+serviceVersionId+ "/" + UUID.fastUUID()+"/"+file.getOriginalFilename(); minioService.uploadFile(bucketName, savePath, file); HashMap result = MapUtil.newHashMap(); - result.put("file_id", objectID); + result.put("file_id", packageId); result.put("direct_url", savePath); result.put("filename", file.getOriginalFilename()); return result; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java index 757a118f..99dae844 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java @@ -1,8 +1,9 @@ package com.ruoyi.platform.utils; +import com.ruoyi.common.core.utils.StringUtils; import io.minio.*; -import io.minio.errors.MinioException; +import io.minio.errors.*; import io.minio.http.Method; import io.minio.messages.DeleteObject; import io.minio.messages.Item; @@ -16,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; @@ -516,43 +518,69 @@ public class MinioUtil { /** * 创建目录的压缩包 */ - public void createZipFromDirectory(String bucket, Map dirMap, String zipPath) + public void createZipFromDirectory(String bucket, List inputs,String output, String zipPath) throws Exception { - // 创建内存中的ZIP流 - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Path tempFile = Files.createTempFile("zip-", ".tmp"); + try { + // 写入临时文件 + try (FileOutputStream fos = new FileOutputStream(tempFile.toFile()); + ZipOutputStream zos = new ZipOutputStream(fos)) { - try (ZipOutputStream zos = new ZipOutputStream(baos)) { + for (String input : inputs) { + if (StringUtils.isNotBlank(input)) { + writeBuffer("input", input, bucket, zos); + } + } + writeBuffer("output", output, bucket, zos); + } - // 遍历每个目录映射 - for (Map.Entry entry : dirMap.entrySet()) { - String folderName = entry.getKey(); // 压缩包内的文件夹名 - String sourcePath = entry.getValue(); // MinIO中的路径 + // 上传临时文件 + try (InputStream is = Files.newInputStream(tempFile)) { + minioClient.putObject( + PutObjectArgs.builder() + .bucket(bucket) + .object(zipPath) + .stream(is, Files.size(tempFile), -1) + .contentType("application/zip") + .build() + ); + } + } finally { + // 清理临时文件 + Files.deleteIfExists(tempFile); + } + } - // 1. 自动提取目录路径(去除文件名) - String sourceDir = extractDirectoryPath(sourcePath); + /** + * + * @param folderName 压缩包内的文件夹名 + * @param sourcePath MinIO中的路径 + */ + private void writeBuffer(String folderName,String sourcePath,String bucket,ZipOutputStream zos) { + try { - // 2. 规范化文件夹名 + // 1. 规范化文件夹名 if (!folderName.endsWith("/")) { folderName = folderName + "/"; } - // 3. 获取目录下的所有文件 + // 2. 获取目录下的所有文件 Iterable> items = minioClient.listObjects( ListObjectsArgs.builder() .bucket(bucket) - .prefix(sourceDir) + .prefix(sourcePath) .recursive(true) .build() ); - // 4. 添加文件到ZIP + // 3. 添加文件到ZIP for (Result result : items) { Item item = result.get(); if (item.isDir()) continue; String objectName = item.objectName(); - String relativePath = objectName.substring(sourceDir.length()-1); + String relativePath = objectName.substring(sourcePath.length() - 1); // 使用自定义的文件夹名 String zipEntryName = folderName + relativePath; @@ -576,48 +604,8 @@ public class MinioUtil { zos.closeEntry(); } - } - - zos.finish(); - } - - // 上传压缩包到MinIO - byte[] zipBytes = baos.toByteArray(); - - try (ByteArrayInputStream bais = new ByteArrayInputStream(zipBytes)) { - minioClient.putObject( - PutObjectArgs.builder() - .bucket(bucket) - .object(zipPath) - .stream(bais, zipBytes.length, -1) - .contentType("application/zip") - .build() - ); - } - } - - private String extractDirectoryPath(String path) { - path = path.trim(); - - // 如果路径包含点号且不以斜杠结尾,可能是文件 - if (path.contains(".") && !path.endsWith("/")) { - int lastSlash = path.lastIndexOf("/"); - if (lastSlash > 0) { - // 返回目录部分 - return path.substring(0, lastSlash + 1); + }catch (Exception e){ + e.printStackTrace(); } } - - // 如果不是文件路径,直接返回 - if (!path.endsWith("/")) { - return path + "/"; - } - return path; - } - - public static void main(String[] args) { - String objectName = "mini-model-platform-data/cs-data/98/28bbb298-6e21-4361-b00a-ba8dc1643f65/file/log.lammps"; - String relativePath = objectName.substring("/mini-model-platform-data/cs-data/98/28bbb298-6e21-4361-b00a-ba8dc1643f65/file/".length()-1); - System.out.println(relativePath); //输出og.lammps - } } \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml index 6490b42d..7b1b4db7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml @@ -14,14 +14,15 @@ spring: nacos: discovery: # 服务注册地址 - server-addr: nacos-ci4s.argo.svc:8848 + server-addr: 172.20.32.121:31203 username: nacos password: h1n2x3j4y5@ + namespace: f4dffebe-4a37-4244-bff5-614bfbe98df7 config: username: nacos password: h1n2x3j4y5@ # 配置中心地址 - server-addr: nacos-ci4s.argo.svc:8848 + server-addr: 172.20.32.121:31203 # 配置文件格式 file-extension: yml # 共享配置 @@ -31,4 +32,5 @@ spring: refresh: true - data-id: ruoyi-system-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} group: DEFAULT_GROUP - refresh: true \ No newline at end of file + refresh: true + namespace: f4dffebe-4a37-4244-bff5-614bfbe98df7 \ No newline at end of file