From 4a6e0347b216ff730481f1372bc4c9dd6904edc7 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 9 May 2025 16:44:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activeLearn/ActiveLearnInsController.java | 4 +- .../experiment/ExperimentInsController.java | 43 ++++++------ .../labelStudio/labelStudioController.java | 10 +-- .../platform/domain/MachineLearnIns.java | 4 ++ .../scheduling/ActiveLearnInsStatusTask.java | 2 +- .../scheduling/AutoMlInsStatusTask.java | 2 +- .../ExperimentInstanceStatusTask.java | 2 +- .../platform/scheduling/MLStatusTask.java | 2 +- .../platform/scheduling/RayInsStatusTask.java | 2 +- .../service/impl/ActiveLearnServiceImpl.java | 2 +- .../service/impl/AutoMlServiceImpl.java | 2 +- .../impl/ExperimentInsServiceImpl.java | 70 +++++++++++-------- .../impl/MachineLearnInsServiceImpl.java | 30 ++++++++ .../service/impl/MachineLearnServiceImpl.java | 17 +++-- .../platform/service/impl/RayServiceImpl.java | 2 +- .../impl/ResourceOccupyServiceImpl.java | 9 ++- .../service/impl/WorkflowServiceImpl.java | 2 +- .../com/ruoyi/platform/utils/MinioUtil.java | 2 +- .../managementPlatform/ResourceOccupy.xml | 8 ++- 19 files changed, 132 insertions(+), 83 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java index 282506b1..cd2c953e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/activeLearn/ActiveLearnInsController.java @@ -59,10 +59,10 @@ public class ActiveLearnInsController extends BaseController { return genericsSuccess(this.activeLearnInsService.getDetailById(id)); } - @GetMapping("/getExpMetrics") + @PostMapping("/getExpMetrics") @ApiOperation("获取当前实验的指标对比地址") @ApiResponse - public GenericsAjaxResult getExpMetrics(@RequestParam(value = "experiment_ins_id") String experimentInsId) throws Exception { + public GenericsAjaxResult getExpMetrics(@RequestBody String experimentInsId) throws Exception { return genericsSuccess(activeLearnInsService.getExpMetrics(experimentInsId)); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java index 32ad25ce..e95aa2fe 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; +import java.util.Date; import java.util.List; import java.util.Map; @@ -42,8 +43,8 @@ public class ExperimentInsController extends BaseController { @GetMapping @ApiOperation("分页查询") public GenericsAjaxResult> queryByPage(ExperimentIns experimentIns, int page, int size) throws IOException { - PageRequest pageRequest = PageRequest.of(page,size); - return genericsSuccess(this.experimentInsService.queryByPage(experimentIns, pageRequest)); + PageRequest pageRequest = PageRequest.of(page, size); + return genericsSuccess(this.experimentInsService.queryByPage(experimentIns, pageRequest)); } /** @@ -55,7 +56,7 @@ public class ExperimentInsController extends BaseController { @GetMapping("{id}") @ApiOperation("通过id查询实验实例") public GenericsAjaxResult queryById(@PathVariable("id") Integer id) throws IOException { - return genericsSuccess(this.experimentInsService.queryById(id)); + return genericsSuccess(this.experimentInsService.queryById(id)); } /** @@ -67,7 +68,7 @@ public class ExperimentInsController extends BaseController { @GetMapping("/queryByExperimentId/{Experiment_id}") @ApiOperation("通过实验id查询查询实验实例列表") public GenericsAjaxResult> queryByExperimentId(@PathVariable("Experiment_id") Integer experimentId) throws IOException { - return genericsSuccess(this.experimentInsService.getByExperimentId(experimentId)); + return genericsSuccess(this.experimentInsService.getByExperimentId(experimentId)); } /** @@ -79,7 +80,7 @@ public class ExperimentInsController extends BaseController { @PostMapping @ApiOperation("新增实验实例") public GenericsAjaxResult add(@RequestBody ExperimentIns experimentIns) { - return genericsSuccess(this.experimentInsService.insert(experimentIns)); + return genericsSuccess(this.experimentInsService.insert(experimentIns)); } /** @@ -91,7 +92,7 @@ public class ExperimentInsController extends BaseController { @PutMapping @ApiOperation("编辑实验实例") public GenericsAjaxResult edit(@RequestBody ExperimentIns experimentIns) throws IOException { - return genericsSuccess(this.experimentInsService.update(experimentIns)); + return genericsSuccess(this.experimentInsService.update(experimentIns)); } /** @@ -102,14 +103,14 @@ public class ExperimentInsController extends BaseController { */ @DeleteMapping("{id}") @ApiOperation("删除实验实例") - public GenericsAjaxResult deleteById( @PathVariable("id") Integer id) { - return genericsSuccess(this.experimentInsService.removeById(id)); + public GenericsAjaxResult deleteById(@PathVariable("id") Integer id) { + return genericsSuccess(this.experimentInsService.removeById(id)); } @DeleteMapping("batchDelete") @ApiOperation("批量删除实验实例") - public GenericsAjaxResult batchDelete(@RequestBody List ids) throws Exception{ - return genericsSuccess(this.experimentInsService.batchDelete(ids)); + public GenericsAjaxResult batchDelete(@RequestBody List ids) throws Exception { + return genericsSuccess(this.experimentInsService.batchDelete(ids)); } /** @@ -133,8 +134,8 @@ public class ExperimentInsController extends BaseController { @GetMapping("/log") @ApiOperation("查询实例日志") public GenericsAjaxResult showExperimentInsLog(@RequestParam("id") Integer id, - @RequestParam("component_id") String componentId){ - return genericsSuccess(this.experimentInsService.showExperimentInsLog(id,componentId)); + @RequestParam("component_id") String componentId) { + return genericsSuccess(this.experimentInsService.showExperimentInsLog(id, componentId)); } /** @@ -146,14 +147,14 @@ public class ExperimentInsController extends BaseController { @GetMapping("/pods/log") @ApiOperation("获取pod实时日志请求") public GenericsAjaxResult> getRealtimePodLog(@RequestParam("pod_name") String podName, - @RequestParam("start_time") String startTime){ - return genericsSuccess(this.experimentInsService.getRealtimePodLog(podName,startTime)); + @RequestParam("start_time") String startTime) { + return genericsSuccess(this.experimentInsService.getRealtimePodLog(podName, startTime)); } @PostMapping("/pods/realTimeLog") @ApiOperation("获取pod实时日志请求") - public GenericsAjaxResult getRealtimePodLogFromPod(@RequestBody PodLogVo podLogVo){ + public GenericsAjaxResult getRealtimePodLogFromPod(@RequestBody PodLogVo podLogVo) { return genericsSuccess(this.experimentInsService.getRealtimePodLogFromPod(podLogVo)); } @@ -166,14 +167,11 @@ public class ExperimentInsController extends BaseController { @PostMapping("/realTimeLog") @ApiOperation("查询实验实例实时日志") - public GenericsAjaxResult> getRealtimeWorkflowLog(@RequestBody LogRequestVo logRequest){ + public GenericsAjaxResult> getRealtimeWorkflowLog(@RequestBody LogRequestVo logRequest) { return genericsSuccess(this.experimentInsService.getRealtimeWorkflowLog(logRequest)); } - - - /** * 查询实验节点结果 * @@ -184,8 +182,13 @@ public class ExperimentInsController extends BaseController { public GenericsAjaxResult getNodeResult(@RequestBody Map map) throws Exception { Integer id = Integer.parseInt((String) map.get("id")); String nodeId = (String) map.get("node_id"); - return genericsSuccess(this.experimentInsService.getNodeResult(id,nodeId)); + return genericsSuccess(this.experimentInsService.getNodeResult(id, nodeId)); } + @GetMapping("/time") + @ApiOperation("获取当前时间") + public GenericsAjaxResult getTime() { + return genericsSuccess(new Date()); + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/labelStudio/labelStudioController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/labelStudio/labelStudioController.java index deda8542..290b6bc1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/labelStudio/labelStudioController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/labelStudio/labelStudioController.java @@ -1,9 +1,7 @@ package com.ruoyi.platform.controller.labelStudio; import com.ruoyi.common.core.web.controller.BaseController; -import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult; -import com.ruoyi.platform.service.JupyterService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Value; @@ -11,12 +9,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - @RestController @RequestMapping("/labelStudio") @Api("labelStudio service") @@ -25,7 +17,7 @@ public class labelStudioController extends BaseController { private String url; @GetMapping(value = "/getURL") @ApiOperation("得到访问地址") - public GenericsAjaxResult getURL() throws IOException { + public GenericsAjaxResult getURL() { return genericsSuccess(url); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/MachineLearnIns.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/MachineLearnIns.java index 120cf68d..c53d2d7b 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/MachineLearnIns.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/MachineLearnIns.java @@ -7,6 +7,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; +import java.util.List; +import java.util.Map; @Data @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) @@ -48,4 +50,6 @@ public class MachineLearnIns { private Date updateTime; private Date finishTime; + + private Map fileMap; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java index c08d6512..0bd1150e 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ActiveLearnInsStatusTask.java @@ -33,7 +33,7 @@ public class ActiveLearnInsStatusTask { private List activeLearnIds = new ArrayList<>(); - @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + @Scheduled(cron = "0/10 * * * * ?") // 每10S执行一次 public void executeActiveLearnInsStatus() { List activeLearnInsList = activeLearnInsService.queryActiveLearnInsIsNotTerminated(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java index c59d67fc..44822fa8 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/AutoMlInsStatusTask.java @@ -29,7 +29,7 @@ public class AutoMlInsStatusTask { private List autoMlIds = new ArrayList<>(); - @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + @Scheduled(cron = "0/10 * * * * ?") // 每10S执行一次 public void executeAutoMlInsStatus() { // 首先查到所有非终止态的实验实例 List autoMlInsList = autoMlInsService.queryByAutoMlInsIsNotTerminated(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java index f1cf303a..3b97cd22 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/ExperimentInstanceStatusTask.java @@ -36,7 +36,7 @@ public class ExperimentInstanceStatusTask { private List experimentIds = new ArrayList<>(); - @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + @Scheduled(cron = "0/10 * * * * ?") // 每10S执行一次 public void executeExperimentInsStatus() throws Exception { // 首先查到所有非终止态的实验实例 List experimentInsList = experimentInsService.queryByExperimentIsNotTerminated(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/MLStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/MLStatusTask.java index 905f6d2a..88980ba6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/MLStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/MLStatusTask.java @@ -31,7 +31,7 @@ public class MLStatusTask { private List machineLearnIds = new ArrayList<>(); - @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + @Scheduled(cron = "0/10 * * * * ?") // 每10S执行一次 public void executeMachineLearnInsStatus() { // 首先查到所有非终止态的实验实例 List insList = machineLearnInsService.queryNotTerminated(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java index f5b0b759..cbf65ed4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/scheduling/RayInsStatusTask.java @@ -33,7 +33,7 @@ public class RayInsStatusTask { private List rayIds = new ArrayList<>(); - @Scheduled(cron = "0/30 * * * * ?") // 每30S执行一次 + @Scheduled(cron = "0/10 * * * * ?") // 每10S执行一次 public void executeRayInsStatus() { List rayInsList = rayInsService.queryByRayInsIsNotTerminated(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java index bf3d607d..1a00356a 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ActiveLearnServiceImpl.java @@ -57,7 +57,7 @@ public class ActiveLearnServiceImpl implements ActiveLearnService { @Override public ActiveLearn save(ActiveLearnVo activeLearnVo) throws Exception { - if (activeLearnVo.getName().length() >= 64) { + if (activeLearnVo.getName().length() > 64) { throw new RuntimeException("实验名称大于最大长度"); } ActiveLearn activeLearnByName = activeLearnDao.getActiveLearnByName(activeLearnVo.getName()); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java index 99354424..07887883 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/AutoMlServiceImpl.java @@ -66,7 +66,7 @@ public class AutoMlServiceImpl implements AutoMlService { @Override public AutoMl save(AutoMlVo autoMlVo) throws Exception { - if (autoMlVo.getMlName().length() >= 64) { + if (autoMlVo.getMlName().length() > 64) { throw new RuntimeException("实验名称大于最大长度"); } AutoMl autoMlByName = autoMlDao.getAutoMlByName(autoMlVo.getMlName()); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java index b58e449b..9a6ab793 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java @@ -18,6 +18,8 @@ import com.ruoyi.platform.vo.PodLogVo; import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; 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; @@ -37,6 +39,8 @@ import java.util.*; */ @Service("experimentInsService") public class ExperimentInsServiceImpl implements ExperimentInsService { + private static final Logger logger = LoggerFactory.getLogger(ExperimentInsServiceImpl.class); + @Resource private ExperimentInsDao experimentInsDao; @Resource @@ -362,7 +366,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { } // 只有状态是"Running"时才能终止实例 - if (!currentStatus.equalsIgnoreCase("Running")) { + if (!currentStatus.equalsIgnoreCase(Constant.Running)) { throw new Exception("终止错误,只有运行状态的实例才能终止"); // 如果不是"Running"状态,则不执行终止操作 } @@ -430,40 +434,44 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { } - void deleteExportVersion(ExperimentIns experimentIns) throws Exception { - LoginUser loginUser = SecurityUtils.getLoginUser(); - String ci4sUsername = loginUser.getUsername(); - - String nodesResult = experimentIns.getNodesResult(); - - if (StringUtils.isNotEmpty(nodesResult)) { - Map nodesResultMap = JsonUtils.jsonToMap(nodesResult); - Map paramOutput = (Map) nodesResultMap.get("param_output"); - - for (String key : paramOutput.keySet()) { - //删除导出模型版本 - if (key.contains("model-export")) { - HashMap queryMap = new HashMap(); - queryMap.put("insId", experimentIns.getId()); - ModelDependency1 modelDependency1 = modelDependency1Dao.queryByInsId(JSON.toJSONString(queryMap)); - if (modelDependency1 != null) { - if (StringUtils.isNotEmpty(modelDependency1.getVersion())) { - String relativePath = ci4sUsername + "/model/" + modelDependency1.getRepoId() + "/" + modelDependency1.getIdentifier() + "/" + modelDependency1.getVersion() + "/model"; - modelsService.deleteVersion(modelDependency1.getRepoId(), modelDependency1.getIdentifier(), modelDependency1.getOwner(), modelDependency1.getVersion(), relativePath); - } else { - modelDependency1Dao.deleteModelById(modelDependency1.getId()); + void deleteExportVersion(ExperimentIns experimentIns) { + try { + LoginUser loginUser = SecurityUtils.getLoginUser(); + String ci4sUsername = loginUser.getUsername(); + + String nodesResult = experimentIns.getNodesResult(); + + if (StringUtils.isNotEmpty(nodesResult)) { + Map nodesResultMap = JsonUtils.jsonToMap(nodesResult); + Map paramOutput = (Map) nodesResultMap.get("param_output"); + + for (String key : paramOutput.keySet()) { + //删除导出模型版本 + if (key.contains("model-export")) { + HashMap queryMap = new HashMap(); + queryMap.put("insId", experimentIns.getId()); + ModelDependency1 modelDependency1 = modelDependency1Dao.queryByInsId(JSON.toJSONString(queryMap)); + if (modelDependency1 != null) { + if (StringUtils.isNotEmpty(modelDependency1.getVersion())) { + String relativePath = ci4sUsername + "/model/" + modelDependency1.getRepoId() + "/" + modelDependency1.getIdentifier() + "/" + modelDependency1.getVersion() + "/model"; + modelsService.deleteVersion(modelDependency1.getRepoId(), modelDependency1.getIdentifier(), modelDependency1.getOwner(), modelDependency1.getVersion(), relativePath); + } else { + modelDependency1Dao.deleteModelById(modelDependency1.getId()); + } } } - } - //删除导出数据集版本 - if (key.contains("dataset-export")) { - HashMap queryMap = new HashMap(); - queryMap.put("ins_id", experimentIns.getId()); - DatasetTempStorage datasetTempStorage = datasetTempStorageDao.queryByInsId(JSON.toJSONString(queryMap)); - String relativePath = ci4sUsername + "/datasets/" + datasetTempStorage.getRepoId() + "/" + datasetTempStorage.getName() + "/" + datasetTempStorage.getVersion() + "/dataset"; - newDatasetService.deleteDatasetVersionNew(datasetTempStorage.getRepoId(), datasetTempStorage.getName(), datasetTempStorage.getCreateBy(), datasetTempStorage.getVersion(), relativePath); + //删除导出数据集版本 + if (key.contains("dataset-export")) { + HashMap queryMap = new HashMap(); + queryMap.put("ins_id", experimentIns.getId()); + DatasetTempStorage datasetTempStorage = datasetTempStorageDao.queryByInsId(JSON.toJSONString(queryMap)); + String relativePath = ci4sUsername + "/datasets/" + datasetTempStorage.getRepoId() + "/" + datasetTempStorage.getName() + "/" + datasetTempStorage.getVersion() + "/dataset"; + newDatasetService.deleteDatasetVersionNew(datasetTempStorage.getRepoId(), datasetTempStorage.getName(), datasetTempStorage.getCreateBy(), datasetTempStorage.getVersion(), relativePath); + } } } + } catch (Exception e) { + logger.error(e.getMessage()); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnInsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnInsServiceImpl.java index 2e353807..6311fc74 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnInsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnInsServiceImpl.java @@ -9,8 +9,11 @@ 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.MinioUtil; 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.stereotype.Service; import org.springframework.data.domain.Page; @@ -23,6 +26,8 @@ import java.util.*; @Service public class MachineLearnInsServiceImpl implements MachineLearnInsService { + private static final Logger logger = LoggerFactory.getLogger(MachineLearnInsServiceImpl.class); + @Value("${argo.url}") private String argoUrl; @Value("${argo.workflowStatus}") @@ -36,6 +41,8 @@ public class MachineLearnInsServiceImpl implements MachineLearnInsService { private MachineLearnDao machineLearnDao; @Resource private ResourceOccupyService resourceOccupyService; + @Resource + private MinioUtil minioUtil; @Override public Page queryByPage(Long machineLearnId, PageRequest pageRequest) { @@ -237,6 +244,9 @@ public class MachineLearnInsServiceImpl implements MachineLearnInsService { if (Constant.Running.equals(machineLearnIns.getStatus()) || Constant.Pending.equals(machineLearnIns.getStatus())) { machineLearnIns = queryStatusFromArgo(machineLearnIns); } + if (Constant.ML_VideoClassification.equals(machineLearnIns.getType())) { + getFileList(machineLearnIns); + } return machineLearnIns; } @@ -256,4 +266,24 @@ public class MachineLearnInsServiceImpl implements MachineLearnInsService { machineLearnDao.edit(machineLearn); } } + + public void getFileList(MachineLearnIns ins) { + String directoryPath = ins.getResultPath(); + + try { + String bucketName = directoryPath.substring(0, directoryPath.indexOf("/")); + String prefix = directoryPath.substring(directoryPath.indexOf("/") + 1, directoryPath.length()) + "/"; + List fileMaps = minioUtil.listRayFilesInDirectory(bucketName, prefix); + Map fileMap = new HashMap<>(); + fileMap.put("children", fileMaps); + fileMap.put("url", directoryPath); + fileMap.put("isDirectory", true); + fileMap.put("size", "0 B"); + fileMap.put("name", "result file"); + ins.setFileMap(fileMap); + } catch (Exception e) { + logger.error("未找到结果文件"); + } + + } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnServiceImpl.java index f61847ef..dc803c63 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/MachineLearnServiceImpl.java @@ -63,7 +63,7 @@ public class MachineLearnServiceImpl implements MachineLearnService { @Override public MachineLearn add(MachineLearn machineLearn) { - if (machineLearn.getName().length() >= 64) { + if (machineLearn.getName().length() > 64) { throw new RuntimeException("实验名称大于最大长度"); } MachineLearn machineLearnByName = machineLearnDao.getMachineLearnByName(machineLearn.getName()); @@ -105,6 +105,12 @@ public class MachineLearnServiceImpl implements MachineLearnService { if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createBy))) { throw new RuntimeException("无权限删除该实验"); } + + List insList = machineLearnInsDao.getByMachineLearnId(machineLearn.getId()); + if (!insList.isEmpty()) { + throw new RuntimeException("该实验存在实例,无法删除"); + } + machineLearn.setUpdateBy(SecurityUtils.getLoginUser().getUsername()); machineLearn.setState(Constant.State_invalid); resourceOccupyService.deleteTaskState(Constant.TaskType_ML, id, null); @@ -191,7 +197,8 @@ public class MachineLearnServiceImpl implements MachineLearnService { Map param_output = (Map) output.get("param_output"); List output1 = (ArrayList) param_output.values().toArray()[0]; Map output2 = (Map) output1.get(0); - String outputPath = minioEndpoint + "/" + output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")) + "/"; + String outputStr = output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")); + String outputPath = minioEndpoint + "/" + outputStr + "/"; switch (machineLearn.getType()) { case Constant.ML_CSV: { @@ -208,13 +215,13 @@ public class MachineLearnServiceImpl implements MachineLearnService { } case Constant.ML_TextClassification: { machineLearnIns.setModelPath(outputPath + "saved_dict/" + modelType + ".ckpt"); - machineLearnIns.setRunHistoryPath(output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")).substring("data/".length()) + "/log/" + modelType); + machineLearnIns.setRunHistoryPath(outputStr.substring("data/".length()) + "/log/" + modelType); machineLearnIns.setResultPath(outputPath + "log/" + modelType + "/result.txt"); break; } case Constant.ML_VideoClassification: { - machineLearnIns.setResultPath(outputPath); - machineLearnIns.setRunHistoryPath(output2.get("path").replace("{{workflow.name}}", (String) metadata.get("name")).substring("data/".length()) + "/log"); + machineLearnIns.setResultPath(outputStr); + machineLearnIns.setRunHistoryPath(outputStr.substring("data/".length()) + "/log"); break; } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java index 1a9c9770..e40acbe0 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/RayServiceImpl.java @@ -63,7 +63,7 @@ public class RayServiceImpl implements RayService { @Override public Ray save(RayVo rayVo) throws Exception { - if (rayVo.getName().length() >= 64) { + if (rayVo.getName().length() > 64) { throw new RuntimeException("实验名称大于最大长度"); } Ray rayByName = rayDao.getRayByName(rayVo.getName()); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java index 3b63eb43..a3ee78e9 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ResourceOccupyServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -113,9 +114,11 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { } Double hours = (double) timeDifferenceMillis / (1000 * 60 * 60); Double deduceCredit = resourceOccupy.getCreditPerHour() * hours; - resourceOccupyDao.deduceCredit(deduceCredit, resourceOccupy.getUserId()); + double deduceCreditTrun = new BigDecimal(deduceCredit).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + deduceCreditTrun = deduceCreditTrun > 0 ? deduceCreditTrun : 0.01; + resourceOccupyDao.deduceCredit(deduceCreditTrun, resourceOccupy.getUserId()); - resourceOccupy.setDeduceCredit(resourceOccupy.getDeduceCredit() + deduceCredit); + resourceOccupy.setDeduceCredit(resourceOccupy.getDeduceCredit() + deduceCreditTrun); resourceOccupy.setDeduceLastTime(now); resourceOccupy.setState(Constant.State_valid); resourceOccupyDao.edit(resourceOccupy); @@ -171,6 +174,6 @@ public class ResourceOccupyServiceImpl implements ResourceOccupyService { @Override public void deleteTaskState(String taskType, Long taskId, Long taskInsId) { - resourceOccupyDao.deleteTaskState(taskType,taskId,taskInsId); + resourceOccupyDao.deleteTaskState(taskType, taskId, taskInsId); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java index fbeb54a5..ccefc30f 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java @@ -180,7 +180,7 @@ public class WorkflowServiceImpl implements WorkflowService { Workflow workflow = this.queryById(id); if (workflow != null) { try { - if (workflow.getName().length() >= 64) { + if (workflow.getName().length() > 64) { throw new RuntimeException("流水线名称大于最大长度"); } 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 606fcb46..103aedf4 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 @@ -350,7 +350,7 @@ public class MinioUtil { map.put("name", fileName); map.put("size", formattedSize); - if ((fileName.startsWith("run") || fileName.startsWith("checkpoint")) && fileSize == 0) { + if ((fileName.startsWith("run") || fileName.startsWith("checkpoint") || fileName.equals("log")) && fileSize == 0) { map.put("isDirectory", true); map.put("children", listRayFilesInDirectory(bucketName, fullPath)); } else { diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml index 3587a9cb..c4916ea2 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ResourceOccupy.xml @@ -104,7 +104,7 @@ user_id, description, credit_per_hour, - TRUNCATE(deduce_credit, 1) as deduce_credit, + deduce_credit, start_time, task_type, task_id, @@ -119,13 +119,15 @@