Browse Source

优化主动学习实例详情

dev-active_learn
chenzhihang 11 months ago
parent
commit
724fb6d9ad
5 changed files with 88 additions and 5 deletions
  1. +9
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java
  2. +46
    -3
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java
  3. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java
  4. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java
  5. +31
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java

+ 9
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/ActiveLearnIns.java View File

@@ -1,11 +1,14 @@
package com.ruoyi.platform.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@@ -36,4 +39,10 @@ public class ActiveLearnIns {
private String nodeStatus;

private String nodeResult;

@TableField(exist = false)
private Map<String, Object> dataMap;

@TableField(exist = false)
private List<Map<String, Object>> trialList;
}

+ 46
- 3
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnInsServiceImpl.java View File

@@ -6,11 +6,11 @@ import com.ruoyi.platform.mapper.ActiveLearnDao;
import com.ruoyi.platform.mapper.ActiveLearnInsDao;
import com.ruoyi.platform.service.ActiveLearnInsService;
import com.ruoyi.platform.service.ResourceOccupyService;
import com.ruoyi.platform.utils.DateUtils;
import com.ruoyi.platform.utils.HttpUtils;
import com.ruoyi.platform.utils.JsonUtils;
import com.ruoyi.platform.utils.*;
import com.ruoyi.system.api.constant.Constant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
@@ -24,12 +24,16 @@ import java.util.*;

@Service
public class ActiveLearnInsServiceImpl implements ActiveLearnInsService {
private static final Logger logger = LoggerFactory.getLogger(ActiveLearnInsServiceImpl.class);

@Value("${argo.url}")
private String argoUrl;
@Value("${argo.workflowStatus}")
private String argoWorkflowStatus;
@Value("${argo.workflowTermination}")
private String argoWorkflowTermination;
@Value("${minio.endpointIp}")
String endpoint;

@Resource
private ActiveLearnInsDao activeLearnInsDao;
@@ -37,6 +41,8 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService {
private ActiveLearnDao activeLearnDao;
@Resource
private ResourceOccupyService resourceOccupyService;
@Resource
private MinioUtil minioUtil;

@Override
public Page<ActiveLearnIns> queryByPage(Long activeLearnId, PageRequest pageRequest) throws IOException {
@@ -168,6 +174,7 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService {
if (Constant.Running.equals(activeLearnIns.getStatus()) || Constant.Pending.equals(activeLearnIns.getStatus())) {
activeLearnIns = queryStatusFromArgo(activeLearnIns);
}
getTrialList(activeLearnIns);
return activeLearnIns;
}

@@ -260,4 +267,40 @@ public class ActiveLearnInsServiceImpl implements ActiveLearnInsService {
public List<ActiveLearnIns> queryActiveLearnInsIsNotTerminated() {
return activeLearnInsDao.queryActiveLearnInsIsNotTerminated();
}

public void getTrialList(ActiveLearnIns ins) {
String directoryPath = ins.getResultPath();

ins.setResultPath(endpoint + "/" + directoryPath);
try {
String bucketName = directoryPath.substring(0, directoryPath.indexOf("/"));
String prefix = directoryPath.substring(directoryPath.indexOf("/") + 1, directoryPath.length()) + "/";
List<Map> fileMaps = minioUtil.listALFilesInDirectory(bucketName, prefix);

if (!fileMaps.isEmpty()) {
String trialJson = minioUtil.readObjectAsString(bucketName, prefix + "trial.json");
List<Map<String, Object>> trialList = JacksonUtil.parseJSONStr2MapList(trialJson);
ins.setTrialList(trialList);

String dataJson = minioUtil.readObjectAsString(bucketName, prefix + "data.json");
Map<String, Object> dataMap = JacksonUtil.parseJSONStr2Map(dataJson);
ins.setDataMap(dataMap);

for (Map<String, Object> trial : trialList) {
Integer trialId = (Integer) trial.get("trial_id");
for (Map fileMap : fileMaps) {
String[] split = fileMap.get("name").toString().split("_");
if (split.length > 2) {
String idx = fileMap.get("name").toString().split("_")[2];
if (idx.equals(String.valueOf(trialId))) {
trial.put("file", fileMap);
}
}
}
}
}
} catch (Exception e) {
logger.error("未找到结果文件");
}
}
}

+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java View File

@@ -186,7 +186,7 @@ public class ActiveLearnServiceImpl implements ActiveLearnService {
Map<String, Object> param_output = (Map<String, Object>) output.get("param_output");
List output1 = (ArrayList) param_output.values().toArray()[0];
Map<String, String> output2 = (Map<String, String>) output1.get(0);
String outputPath = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/hpo";
String outputPath = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name"));
activeLearnIns.setResultPath(outputPath);
activeLearnInsDao.insert(activeLearnIns);
activeLearnInsService.updateActiveLearnStatus(id);


+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayInsServiceImpl.java View File

@@ -361,7 +361,7 @@ public class RayInsServiceImpl implements RayInsService {
}
}
} catch (Exception e) {
logger.error("未找到结果文件:result.txt");
logger.error("未找到结果文件");
}
}



+ 31
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/MinioUtil.java View File

@@ -359,7 +359,38 @@ public class MinioUtil {
map.put("url", bucketName + "/" + fullPath);
fileInfoList.add(map);
}
return fileInfoList;
}

public List<Map> listALFilesInDirectory(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);

if (fileName.endsWith("checkpoint") && fileSize == 0) {
map.put("isDirectory", true);
map.put("children", listALFilesInDirectory(bucketName, fullPath));
} else {
map.put("isFile", true);
}
map.put("url", bucketName + "/" + fullPath);
fileInfoList.add(map);
}
return fileInfoList;
}



Loading…
Cancel
Save