Browse Source

日志接口返回json格式

pull/7/head
西大锐 1 year ago
parent
commit
8dbd8d74f5
4 changed files with 54 additions and 18 deletions
  1. +20
    -5
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java
  2. +3
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ExperimentInsService.java
  3. +31
    -7
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java
  4. +0
    -5
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java

+ 20
- 5
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/experiment/ExperimentInsController.java View File

@@ -121,7 +121,7 @@ public class ExperimentInsController {
* @return 运行日志 * @return 运行日志
*/ */


@GetMapping(("/log"))
@GetMapping("/log")
@ApiOperation("查询实例日志") @ApiOperation("查询实例日志")
public AjaxResult showExperimentInsLog(@RequestParam("id") Integer id, public AjaxResult showExperimentInsLog(@RequestParam("id") Integer id,
@RequestParam("component_id") String componentId){ @RequestParam("component_id") String componentId){
@@ -129,25 +129,40 @@ public class ExperimentInsController {
} }


/** /**
* 查询实验实时日志
* 查询pods实时日志
* *
* @return 运行日志 * @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){ public AjaxResult getRealtimeWorkflowLog(@RequestBody LogRequestVo logRequest){
return AjaxResult.success(this.experimentInsService.getRealtimeWorkflowLog(logRequest)); return AjaxResult.success(this.experimentInsService.getRealtimeWorkflowLog(logRequest));
} }








/** /**
* 查询实验节点结果 * 查询实验节点结果
* *
* @return 运行日志 * @return 运行日志
*/ */
@GetMapping(("/nodeResult"))
@GetMapping("/nodeResult")
@ApiOperation("查询实例节点结果") @ApiOperation("查询实例节点结果")
public AjaxResult getNodeResult(@RequestParam("id") Integer id,@RequestParam("node_id") String nodeId) throws Exception { public AjaxResult getNodeResult(@RequestParam("id") Integer id,@RequestParam("node_id") String nodeId) throws Exception {
return AjaxResult.success(this.experimentInsService.getNodeResult(id,nodeId)); return AjaxResult.success(this.experimentInsService.getNodeResult(id,nodeId));


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

@@ -7,6 +7,7 @@ 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)表服务接口
@@ -90,6 +91,7 @@ public interface ExperimentInsService {


List getNodeResult(Integer id, String nodeId) throws Exception; List getNodeResult(Integer id, String nodeId) throws Exception;


String getRealtimeWorkflowLog(LogRequestVo logRequest);
Map<String, Object> getRealtimeWorkflowLog(LogRequestVo logRequest);


Map<String, Object> getRealtimePodLog(String podName, String startTime);
} }

+ 31
- 7
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ExperimentInsServiceImpl.java View File

@@ -1,6 +1,5 @@
package com.ruoyi.platform.service.impl; package com.ruoyi.platform.service.impl;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.Experiment; import com.ruoyi.platform.domain.Experiment;
import com.ruoyi.platform.domain.ExperimentIns; 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.mapper.ExperimentInsDao;
import com.ruoyi.platform.service.ExperimentInsService; import com.ruoyi.platform.service.ExperimentInsService;
import com.ruoyi.platform.service.WorkflowService; 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.platform.vo.LogRequestVo;
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;
@@ -53,6 +49,8 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
private String argoWorkflowLog; private String argoWorkflowLog;
@Value("${argo.workflowRealTimeLog}") @Value("${argo.workflowRealTimeLog}")
private String argoWorkflowRealTimeLog; private String argoWorkflowRealTimeLog;
@Value("${argo.workflowPodLog}")
private String argoWorkflowPodLog;
private final MinioUtil minioUtil; private final MinioUtil minioUtil;


public ExperimentInsServiceImpl(MinioUtil minioUtil) { public ExperimentInsServiceImpl(MinioUtil minioUtil) {
@@ -457,7 +455,7 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
} }


@Override @Override
public String getRealtimeWorkflowLog(LogRequestVo logRequest) {
public Map<String, Object> getRealtimeWorkflowLog(LogRequestVo logRequest) {


String componentId = logRequest.getComponentId(); String componentId = logRequest.getComponentId();
String nameSpace = logRequest.getNamespace(); String nameSpace = logRequest.getNamespace();
@@ -482,7 +480,10 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {
if (StringUtils.isEmpty(req)) { if (StringUtils.isEmpty(req)) {
throw new RuntimeException("响应内容为空"); throw new RuntimeException("响应内容为空");
} }
return req;
// 使用JacksonUtil将响应字符串转换为Map
Map<String, Object> tempMap = JacksonUtil.parseJSONStr2Map(req);
//去掉中间多余的data层
return (Map<String, Object>) tempMap.get("data");


} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("查询实验日志失败: " + e.getMessage(), e); throw new RuntimeException("查询实验日志失败: " + e.getMessage(), e);
@@ -490,6 +491,29 @@ public class ExperimentInsServiceImpl implements ExperimentInsService {


} }


@Override
public Map<String, Object> getRealtimePodLog(String podName, String startTime) {
Map<String,Object> 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<String, Object> tempMap = JacksonUtil.parseJSONStr2Map(req);
//去掉中间多余的data层
return (Map<String, Object>) tempMap.get("data");

} catch (Exception e) {
throw new RuntimeException("查询pod实时日志失败: " + e.getMessage(), e);
}

}

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();


+ 0
- 5
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java View File

@@ -154,8 +154,6 @@ public class WorkflowServiceImpl implements WorkflowService {
} }


@Override @Override


public Workflow duplicateWorkflow(Long id) { public Workflow duplicateWorkflow(Long id) {
//先去查找数据库中存在的数据 //先去查找数据库中存在的数据
Workflow workflow = this.queryById(id); Workflow workflow = this.queryById(id);
@@ -187,13 +185,10 @@ public class WorkflowServiceImpl implements WorkflowService {
throw new RuntimeException("复制流水线失败: " + e.getMessage(), e); throw new RuntimeException("复制流水线失败: " + e.getMessage(), e);


} }

} }
return null; return null;


} }






} }

Loading…
Cancel
Save