| @@ -128,5 +128,18 @@ public class ExperimentInsController { | |||||
| /** | |||||
| * 查询实验节点结果 | |||||
| * | |||||
| * @return 运行日志 | |||||
| */ | |||||
| @GetMapping(("/nodeResult")) | |||||
| @ApiOperation("查询实例节点结果") | |||||
| public AjaxResult getNodeResult(@RequestParam("id") Integer id,@RequestParam("node_id") String nodeId) throws Exception { | |||||
| return AjaxResult.success(this.experimentInsService.getNodeResult(id,nodeId)); | |||||
| } | |||||
| } | } | ||||
| @@ -6,7 +6,6 @@ import org.springframework.data.domain.PageRequest; | |||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * (ExperimentIns)表服务接口 | * (ExperimentIns)表服务接口 | ||||
| @@ -88,4 +87,5 @@ public interface ExperimentInsService { | |||||
| */ | */ | ||||
| String showExperimentInsLog(Integer id, String componentId); | String showExperimentInsLog(Integer id, String componentId); | ||||
| List getNodeResult(Integer id, String nodeId) throws Exception; | |||||
| } | } | ||||
| @@ -10,6 +10,7 @@ import com.ruoyi.platform.service.WorkflowService; | |||||
| import com.ruoyi.platform.utils.DateUtils; | import com.ruoyi.platform.utils.DateUtils; | ||||
| import com.ruoyi.platform.utils.HttpUtils; | import com.ruoyi.platform.utils.HttpUtils; | ||||
| import com.ruoyi.platform.utils.JsonUtils; | import com.ruoyi.platform.utils.JsonUtils; | ||||
| import com.ruoyi.platform.utils.MinioUtil; | |||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| @@ -20,7 +21,6 @@ import org.springframework.stereotype.Service; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.*; | import java.util.*; | ||||
| /** | /** | ||||
| @@ -49,6 +49,11 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { | |||||
| private String argoWorkflowTermination; | private String argoWorkflowTermination; | ||||
| @Value("${argo.workflowLog}") | @Value("${argo.workflowLog}") | ||||
| private String argoWorkflowLog; | private String argoWorkflowLog; | ||||
| private final MinioUtil minioUtil; | |||||
| public ExperimentInsServiceImpl(MinioUtil minioUtil) { | |||||
| this.minioUtil = minioUtil; | |||||
| } | |||||
| /** | /** | ||||
| * 通过ID查询单条数据 | * 通过ID查询单条数据 | ||||
| @@ -412,6 +417,41 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { | |||||
| } | } | ||||
| } | } | ||||
| @Override | |||||
| public List getNodeResult(Integer id, String nodeId) throws Exception { | |||||
| List<Map> results = new ArrayList<Map>(); | |||||
| //查询 实例 | |||||
| ExperimentIns experimentIns = this.experimentInsDao.queryById(id); | |||||
| if (experimentIns == null) { | |||||
| throw new Exception("实验实例未查询到,id:" + id); | |||||
| } | |||||
| //找到 节点 节点结果 | |||||
| String nodesResultString = experimentIns.getNodesResult(); | |||||
| if (StringUtils.isEmpty(nodesResultString)) { | |||||
| throw new Exception("实验实例未查询到节点结果,id:" + id); | |||||
| } | |||||
| Map<String, Object> nodesResult = JsonUtils.jsonToMap(nodesResultString); | |||||
| List<Map<String,Object>> nodeList = (List<Map<String,Object>>) nodesResult.get(nodeId); | |||||
| //遍历 查询minio | |||||
| for (int i = 0; i < nodeList.size(); i++) { | |||||
| Map<String, Object> map = nodeList.get(i); | |||||
| String path = (String) map.get("path"); | |||||
| String bucketName = path.substring(0, path.indexOf("/")); | |||||
| String prefix = path.substring(path.indexOf("/")+1,path.length())+"/"; | |||||
| if (StringUtils.equals( (String)map.get("type"),"file")){ | |||||
| List<Map> fileInfo = minioUtil.listFilesInDirectory(bucketName, prefix); | |||||
| map.put("value",fileInfo); | |||||
| }else if (StringUtils.equals( (String)map.get("type"),"string")){ | |||||
| String resultInfo = minioUtil.readObjectAsString(bucketName, prefix); | |||||
| map.put("value",resultInfo); | |||||
| } | |||||
| results.add(map); | |||||
| //组装 | |||||
| } | |||||
| return results; | |||||
| } | |||||
| private boolean isTerminatedState(ExperimentIns ins) throws IOException { | private boolean isTerminatedState(ExperimentIns ins) throws IOException { | ||||
| // 定义终止态的列表,例如 "Succeeded", "Failed" 等 | // 定义终止态的列表,例如 "Succeeded", "Failed" 等 | ||||
| String status = ins.getStatus(); | String status = ins.getStatus(); | ||||
| @@ -32,11 +32,15 @@ public class JupyterServiceImpl implements JupyterService { | |||||
| @Value("${k8s.storageClassName}") | @Value("${k8s.storageClassName}") | ||||
| private String storageClassName; | private String storageClassName; | ||||
| @Resource | |||||
| private MinioUtil minioUtil; | |||||
| private final MinioUtil minioUtil; | |||||
| @Resource | @Resource | ||||
| private MlflowUtil mlflowUtil; | private MlflowUtil mlflowUtil; | ||||
| public JupyterServiceImpl(MinioUtil minioUtil) { | |||||
| this.minioUtil = minioUtil; | |||||
| } | |||||
| @Override | @Override | ||||
| public String getJupyterServiceUrl() { | public String getJupyterServiceUrl() { | ||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| @@ -0,0 +1,24 @@ | |||||
| package com.ruoyi.platform.utils; | |||||
| public class FileUtil { | |||||
| public static String formatFileSize(long sizeInBytes) { | |||||
| if (sizeInBytes < 0) { | |||||
| throw new IllegalArgumentException("File size cannot be negative."); | |||||
| } | |||||
| if (sizeInBytes < 1024) { | |||||
| return sizeInBytes + " B"; | |||||
| } else if (sizeInBytes < 1024 * 1024) { | |||||
| double sizeInKB = sizeInBytes / 1024.0; | |||||
| return String.format("%.2f KB", sizeInKB); | |||||
| } else if (sizeInBytes < 1024 * 1024 * 1024) { | |||||
| double sizeInMB = sizeInBytes / (1024.0 * 1024); | |||||
| return String.format("%.2f MB", sizeInMB); | |||||
| } else { | |||||
| double sizeInGB = sizeInBytes / (1024.0 * 1024 * 1024); | |||||
| return String.format("%.2f GB", sizeInGB); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -2,11 +2,19 @@ package com.ruoyi.platform.utils; | |||||
| import io.minio.*; | import io.minio.*; | ||||
| import io.minio.messages.Item; | |||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.io.OutputStream; | import java.io.OutputStream; | ||||
| import java.nio.charset.StandardCharsets; | |||||
| import java.nio.file.Path; | |||||
| import java.nio.file.Paths; | |||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @Component | @Component | ||||
| public class MinioUtil { | public class MinioUtil { | ||||
| @@ -57,4 +65,48 @@ public class MinioUtil { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| public List<Map> listFilesInDirectory(String bucketName, String prefix) throws Exception { | |||||
| List<Map> fileInfoList = new ArrayList<>(); | |||||
| Iterable<Result<Item>> results = minioClient.listObjects( | |||||
| ListObjectsArgs.builder() | |||||
| .prefix(prefix) | |||||
| .bucket(bucketName) | |||||
| .build()); | |||||
| for (Result<Item> result : results) { | |||||
| Item item = result.get(); | |||||
| String fullPath = item.objectName(); | |||||
| Path path = Paths.get(fullPath); | |||||
| String fileName = path.getFileName().toString(); | |||||
| long fileSize = item.size(); | |||||
| String formattedSize = FileUtil.formatFileSize(fileSize); // 格式化文件大小 | |||||
| Map map = new HashMap<>(); | |||||
| map.put("name", fileName); | |||||
| map.put("size", formattedSize); | |||||
| fileInfoList.add(map); | |||||
| } | |||||
| return fileInfoList; | |||||
| } | |||||
| public String readObjectAsString(String bucketName, String objectName) throws Exception { | |||||
| try (InputStream inputStream = minioClient.getObject( | |||||
| GetObjectArgs.builder() | |||||
| .bucket(bucketName) | |||||
| .object(objectName) | |||||
| .build())) { | |||||
| byte[] buffer = new byte[1024]; | |||||
| int bytesRead; | |||||
| StringBuilder content = new StringBuilder(); | |||||
| while ((bytesRead = inputStream.read(buffer)) != -1) { | |||||
| content.append(new String(buffer, 0, bytesRead, StandardCharsets.UTF_8)); | |||||
| } | |||||
| return content.toString(); | |||||
| } | |||||
| } | |||||
| } | } | ||||