From 0a4cf2fc5b2c81ddf98bc4ab65461c9dccaa1f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Fri, 22 Mar 2024 16:04:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9Edag?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E8=B0=83argo=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ImageServiceImpl.java | 2 +- .../service/impl/WorkflowServiceImpl.java | 66 ++++++++++++++----- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java index 7f3cf1aa..cd256a58 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageServiceImpl.java @@ -252,7 +252,7 @@ public class ImageServiceImpl implements ImageService { throw new Exception("解析镜像压缩包失败,请检查镜像文件"); } }else { - throw new Exception("解析镜像压缩包失败,请检查镜像文件"); + throw new Exception("解析镜像压缩包失败,请检查镜像文件"); } } 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 7b3c3c3d..c4c7992a 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 @@ -6,8 +6,12 @@ import com.ruoyi.platform.domain.Workflow; import com.ruoyi.platform.mapper.WorkflowDao; import com.ruoyi.platform.service.ExperimentService; 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 org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -15,7 +19,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * DAG workflow(Workflow)表服务实现类 @@ -31,6 +37,18 @@ public class WorkflowServiceImpl implements WorkflowService { @Resource 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查询单条数据 * @@ -142,28 +160,40 @@ public class WorkflowServiceImpl implements WorkflowService { //先去查找数据库中存在的数据 Workflow workflow = this.queryById(id); 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 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 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; + } -// @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; -// -// } + }