Browse Source

流水线复制接口修改新增dag逻辑,调argo接口

pull/7/head
西大锐 1 year ago
parent
commit
0a4cf2fc5b
2 changed files with 49 additions and 19 deletions
  1. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java
  2. +48
    -18
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/WorkflowServiceImpl.java

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

@@ -252,7 +252,7 @@ public class ImageServiceImpl implements ImageService {
throw new Exception("解析镜像压缩包失败,请检查镜像文件"); throw new Exception("解析镜像压缩包失败,请检查镜像文件");
} }
}else { }else {
throw new Exception("解析镜像压缩包失败,请检查镜像文件");
throw new Exception("解析镜像压缩包失败,请检查镜像文件");
} }
} }




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

@@ -6,8 +6,12 @@ import com.ruoyi.platform.domain.Workflow;
import com.ruoyi.platform.mapper.WorkflowDao; import com.ruoyi.platform.mapper.WorkflowDao;
import com.ruoyi.platform.service.ExperimentService; import com.ruoyi.platform.service.ExperimentService;
import com.ruoyi.platform.service.WorkflowService; import com.ruoyi.platform.service.WorkflowService;
import com.ruoyi.platform.utils.HttpUtils;
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.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
@@ -15,7 +19,9 @@ import org.springframework.stereotype.Service;


import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;


/** /**
* DAG workflow(Workflow)表服务实现类 * DAG workflow(Workflow)表服务实现类
@@ -31,6 +37,18 @@ public class WorkflowServiceImpl implements WorkflowService {
@Resource @Resource
private ExperimentService experimentService; private ExperimentService experimentService;


@Value("${argo.url}")
private String argoUrl;

@Value("${argo.workflowCopy}")
private String argoWorkflowCopy;

private final MinioUtil minioUtil;

public WorkflowServiceImpl(MinioUtil minioUtil) {
this.minioUtil = minioUtil;
}

/** /**
* 通过ID查询单条数据 * 通过ID查询单条数据
* *
@@ -142,28 +160,40 @@ public class WorkflowServiceImpl implements WorkflowService {
//先去查找数据库中存在的数据 //先去查找数据库中存在的数据
Workflow workflow = this.queryById(id); Workflow workflow = this.queryById(id);
if (workflow!= null) { if (workflow!= null) {
Workflow duplicateWorkflow = new Workflow();
duplicateWorkflow.setName(workflow.getName()+"-copy");
duplicateWorkflow.setDag(workflow.getDag());
duplicateWorkflow.setDescription(workflow.getDescription());
return this.insert(duplicateWorkflow);
try {
Workflow duplicateWorkflow = new Workflow();
duplicateWorkflow.setName(workflow.getName()+"-copy");
String oldDag = workflow.getDag();
// 创建请求数据的Json(map)
Map<String,Object> requestData = new HashMap<>();
requestData.put("data", oldDag);
// 发送POST请求到Argo工作流复制接口,并将请求数据转换为JSON
String req = HttpUtils.sendPost(argoUrl + argoWorkflowCopy , JsonUtils.mapToJson(requestData));
// 检查响应是否为空或无内容
if (StringUtils.isEmpty(req)) {
throw new RuntimeException("工作流复制接口响应内容为空");
}
// 将响应的JSON字符串转换为Map对象
Map<String, Object> runResMap = JsonUtils.jsonToMap(req);
// 从响应Map中获取"data"的值,也就是日志的值
String newDag = (String) runResMap.get("data");
if (newDag == null){
throw new RuntimeException("响应内容为空。");
}
duplicateWorkflow.setDag(newDag);
duplicateWorkflow.setDescription(workflow.getDescription());
return this.insert(duplicateWorkflow);
} catch (Exception e) {
throw new RuntimeException("复制流水线失败: " + e.getMessage(), e);

}

} }
return null; return null;

} }






// @Override
// public Workflow saveWorkflow(Long id) {
// Workflow workflow = this.queryById(id);
// if (workflow!= null) {
// workflow.setState(1);
//
// //todo (set DAG)
// return this.update(workflow);
// }
//
// return null;
//
// }

} }

Loading…
Cancel
Save