From 8dbd8d74f5d3406e1606d482a040e63f8b20464b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Mon, 25 Mar 2024 17:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9Ejson=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../experiment/ExperimentInsController.java | 25 +++++++++--- .../service/ExperimentInsService.java | 4 +- .../impl/ExperimentInsServiceImpl.java | 38 +++++++++++++++---- .../service/impl/WorkflowServiceImpl.java | 5 --- 4 files changed, 54 insertions(+), 18 deletions(-) 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 678e6de5..c3ab7134 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 @@ -121,7 +121,7 @@ public class ExperimentInsController { * @return 运行日志 */ - @GetMapping(("/log")) + @GetMapping("/log") @ApiOperation("查询实例日志") public AjaxResult showExperimentInsLog(@RequestParam("id") Integer id, @RequestParam("component_id") String componentId){ @@ -129,25 +129,40 @@ public class ExperimentInsController { } /** - * 查询实验实时日志 + * 查询pods实时日志 * * @return 运行日志 */ - @PostMapping(("/realTimeLog")) - @ApiOperation("查询实例实时日志") + @GetMapping("/pods/log") + @ApiOperation("获取pod实时日志请求") + public AjaxResult getRealtimePodLog(@RequestParam("pod_name") String podName, + @RequestParam("start_time") String startTime){ + return AjaxResult.success(this.experimentInsService.getRealtimePodLog(podName,startTime)); + } + + /** + * 查询实验实例实时日志 + * + * @return 运行日志 + */ + + @PostMapping("/realTimeLog") + @ApiOperation("查询实验实例实时日志") public AjaxResult getRealtimeWorkflowLog(@RequestBody LogRequestVo logRequest){ return AjaxResult.success(this.experimentInsService.getRealtimeWorkflowLog(logRequest)); } + + /** * 查询实验节点结果 * * @return 运行日志 */ - @GetMapping(("/nodeResult")) + @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)); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java index b6848de2..96552f83 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java @@ -7,6 +7,7 @@ import org.springframework.data.domain.PageRequest; import java.io.IOException; import java.util.List; +import java.util.Map; /** * (ExperimentIns)表服务接口 @@ -90,6 +91,7 @@ public interface ExperimentInsService { List getNodeResult(Integer id, String nodeId) throws Exception; - String getRealtimeWorkflowLog(LogRequestVo logRequest); + Map getRealtimeWorkflowLog(LogRequestVo logRequest); + Map getRealtimePodLog(String podName, String startTime); } 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 299a1c59..2636c671 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 @@ -1,6 +1,5 @@ package com.ruoyi.platform.service.impl; -import com.fasterxml.jackson.core.JsonProcessingException; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.ExperimentIns; @@ -8,10 +7,7 @@ import com.ruoyi.platform.mapper.ExperimentDao; import com.ruoyi.platform.mapper.ExperimentInsDao; import com.ruoyi.platform.service.ExperimentInsService; import com.ruoyi.platform.service.WorkflowService; -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.platform.utils.*; import com.ruoyi.platform.vo.LogRequestVo; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.StringUtils; @@ -53,6 +49,8 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { private String argoWorkflowLog; @Value("${argo.workflowRealTimeLog}") private String argoWorkflowRealTimeLog; + @Value("${argo.workflowPodLog}") + private String argoWorkflowPodLog; private final MinioUtil minioUtil; public ExperimentInsServiceImpl(MinioUtil minioUtil) { @@ -457,7 +455,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { } @Override - public String getRealtimeWorkflowLog(LogRequestVo logRequest) { + public Map getRealtimeWorkflowLog(LogRequestVo logRequest) { String componentId = logRequest.getComponentId(); String nameSpace = logRequest.getNamespace(); @@ -482,7 +480,10 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { if (StringUtils.isEmpty(req)) { throw new RuntimeException("响应内容为空"); } - return req; + // 使用JacksonUtil将响应字符串转换为Map + Map tempMap = JacksonUtil.parseJSONStr2Map(req); + //去掉中间多余的data层 + return (Map) tempMap.get("data"); } catch (Exception e) { throw new RuntimeException("查询实验日志失败: " + e.getMessage(), e); @@ -490,6 +491,29 @@ public class ExperimentInsServiceImpl implements ExperimentInsService { } + @Override + public Map getRealtimePodLog(String podName, String startTime) { + Map requestData = new HashMap<>(); + requestData.put("pod_name",podName); + requestData.put("start_time",startTime); + try { + // 将Map转换为JSON字符串 + String req = HttpUtils.sendPost(argoUrl + argoWorkflowPodLog, JsonUtils.mapToJson(requestData)); + // 检查响应是否为空或无内容 + if (StringUtils.isEmpty(req)) { + throw new RuntimeException("响应内容为空"); + } + // 使用JacksonUtil将响应字符串转换为Map + Map tempMap = JacksonUtil.parseJSONStr2Map(req); + //去掉中间多余的data层 + return (Map) tempMap.get("data"); + + } catch (Exception e) { + throw new RuntimeException("查询pod实时日志失败: " + e.getMessage(), e); + } + + } + private boolean isTerminatedState(ExperimentIns ins) throws IOException { // 定义终止态的列表,例如 "Succeeded", "Failed" 等 String status = ins.getStatus(); 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 c4c7992a..023e1a98 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 @@ -154,8 +154,6 @@ public class WorkflowServiceImpl implements WorkflowService { } @Override - - public Workflow duplicateWorkflow(Long id) { //先去查找数据库中存在的数据 Workflow workflow = this.queryById(id); @@ -187,13 +185,10 @@ public class WorkflowServiceImpl implements WorkflowService { throw new RuntimeException("复制流水线失败: " + e.getMessage(), e); } - } return null; } - - }