From 76ce3d1e2ec8a0cc0a7cdb8b1b0b6a437a04e7d2 Mon Sep 17 00:00:00 2001 From: "mian-bin@hotmail.com" Date: Fri, 28 Mar 2025 14:22:05 +0800 Subject: [PATCH] =?UTF-8?q?v4.1=20=E6=8F=90=E4=BA=A4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=EF=BC=8C=E4=BD=86=E6=98=AF=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E8=BF=90=E8=A1=8C=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E8=A6=81=E8=BF=90=E8=A1=8C=EF=BC=8C=E6=8A=8Aci-process?= =?UTF-8?q?=E5=8D=B8=E8=BD=BDpom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ci/common/pipeline/IModelTemplate.java | 5 + .../common/pipeline/container/Container.java | 42 +++--- .../pipeline/container/NormalContainer.java | 137 ++++-------------- .../pipeline/container/TriggerContainer.java | 25 +++- .../pipeline/container/VMBuildContainer.java | 23 ++- 5 files changed, 97 insertions(+), 135 deletions(-) diff --git a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/IModelTemplate.java b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/IModelTemplate.java index 0a9b66f..87d97ce 100644 --- a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/IModelTemplate.java +++ b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/IModelTemplate.java @@ -25,6 +25,11 @@ public interface IModelTemplate { @Schema(title = "变量", required = true) Map getVariables(); + void setTemplate(String template); + + void setRef(String ref); + + void setVariables(Map variables); /** * 判读是否来自于模板 diff --git a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/Container.java b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/Container.java index d78966b..6b62921 100644 --- a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/Container.java +++ b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/Container.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import java.util.List; @@ -34,28 +35,29 @@ import java.util.Map; @JsonSubTypes.Type(value = VMBuildContainer.class, name = VMBuildContainer.classType) }) @Getter +@NoArgsConstructor @AllArgsConstructor public abstract class Container implements IModelTemplate { - private String id; - private String name; - private List elements; - private String status; - @Deprecated - private Long startEpoch; - @Deprecated - private Long systemElapsed; - @Deprecated - private Long elementElapsed; - private Boolean canRetry; - private String containerId; - private String containerHashId; - private String startVMStatus; - private Integer executeCount; - private String jobId; - private Boolean containPostTaskFlag; - private Boolean matrixGroupFlag; - private BuildRecordTimeCost timeCost; - private Integer startVMTaskSeq; + protected String id; // seq id + protected String name; + protected List elements; + protected String status; + @Deprecated(since = "即将被timeCost代替") + protected Long startEpoch; + @Deprecated(since = "即将被timeCost代替") + protected Long systemElapsed; // 系统耗时(开机时间) + @Deprecated(since = "即将被timeCost代替") + protected Long elementElapsed; // 插件执行耗时 + protected Boolean canRetry; // 当前job是否能重试 + protected String containerId; // container 流水线唯一ID,同seq id + protected String containerHashId; // container 全局唯一ID + protected String startVMStatus; + protected Integer executeCount; + protected String jobId; // 用户自定义id + protected Boolean containPostTaskFlag; // 是否包含post任务 + protected Boolean matrixGroupFlag; // 是否为构建矩阵组 + protected BuildRecordTimeCost timeCost; // 耗时结果 + protected Integer startVMTaskSeq; // 开机任务序号 public void resetBuildOption(int executeCount) { this.status = null; diff --git a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/NormalContainer.java b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/NormalContainer.java index 1f83ca9..0fcfed5 100644 --- a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/NormalContainer.java +++ b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/NormalContainer.java @@ -3,104 +3,51 @@ package cd.casic.ci.common.pipeline.container; import cd.casic.ci.common.pipeline.NameAndValue; import cd.casic.ci.common.pipeline.option.JobControlOption; import cd.casic.ci.common.pipeline.option.MatrixControlOption; -import cd.casic.ci.common.pipeline.pojo.element.Element; -import cd.casic.ci.common.pipeline.pojo.time.BuildRecordTimeCost; import io.swagger.v3.oas.annotations.media.Schema; +import kotlin.ReplaceWith; import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.EqualsAndHashCode; -import java.util.ArrayList; import java.util.List; import java.util.Map; -/** - * @Author:mianbin - * @Package:cd.casic.ci.common.pipeline.container - * @Project:ops-pro - * @name:NormalContainer - * @Date:2025/03/25 16:54 - * @Filename:NormalContainer - * @description:Todo - */ @Data -@NoArgsConstructor +@EqualsAndHashCode(callSuper = false) @Schema(title = "流水线模型-普通任务容器") -public class NormalContainer implements Container { - public static final String classType = "normal"; +public class NormalContainer extends Container { + public static final String CLASS_TYPE = "normal"; + + private Boolean enableSkip = false; - @Schema(title = "构建容器序号id", required = false, readOnly = true) - private String id; - @Schema(title = "容器名称", required = true) - private String name; - @Schema(title = "任务集合", required = true) - private List elements; - @Schema(title = "容器状态", required = false, readOnly = true) - private String status; - @Schema(title = "系统运行时间", required = false, readOnly = true) - @Deprecated - private Long startEpoch; - @Schema(title = "系统耗时(开机时间)", required = false, readOnly = true) - @Deprecated - private Long systemElapsed; - @Schema(title = "插件执行耗时", required = false, readOnly = true) - @Deprecated - private Long elementElapsed; - @Schema(title = "允许可跳过", required = false) - @Deprecated - private Boolean enableSkip; - @Schema(title = "触发条件", required = false) - @Deprecated private List conditions; - @Schema(title = "是否可重试-仅限于构建详情展示重试,目前未作为编排的选项,暂设置为null不存储", required = false, readOnly = true) - private Boolean canRetry; - @Schema(title = "构建容器顺序ID(同id值)", required = false, readOnly = true) - private String containerId; - @Schema(title = "容器唯一ID", required = false, readOnly = true) - private String containerHashId; - @Schema(title = "无构建环境-等待运行环境启动的排队最长时间(分钟)", required = false) - @Deprecated + private Integer maxQueueMinutes = 60; - @Schema(title = "无构建环境-运行最长时间(分钟)", required = false) - @Deprecated + private Integer maxRunningMinutes = 1440; - @Schema(title = "流程控制选项", required = true) - private JobControlOption jobControlOption; - @Schema(title = "互斥组", required = false) - private MutexGroup mutexGroup; - @Schema(title = "构建环境启动状态", required = false, readOnly = true) - private String startVMStatus; - @Schema(title = "容器运行次数", required = false, readOnly = true) - private Integer executeCount; - @Schema(title = "用户自定义ID", required = false, hidden = false) - private String jobId; - @Schema(title = "是否包含post任务标识", required = false, readOnly = true) - private Boolean containPostTaskFlag; - @Schema(title = "是否为构建矩阵", required = false, readOnly = true) - private Boolean matrixGroupFlag; - @Schema(title = "各项耗时", required = true) - private BuildRecordTimeCost timeCost; - @Schema(title = "开机任务序号", required = false, readOnly = true) - private Integer startVMTaskSeq; - @Schema(title = "构建矩阵配置项", required = false) + + private JobControlOption jobControlOption; // 为了兼容旧数据,所以定义为可空以及var + private MutexGroup mutexGroup; // 为了兼容旧数据,所以定义为可空以及var private MatrixControlOption matrixControlOption; - @Schema(title = "所在构建矩阵组的containerHashId(分裂后的子容器特有字段)", required = false) private String matrixGroupId; - @Schema(title = "当前矩阵子容器的上下文组合(分裂后的子容器特有字段)", required = false) private Map matrixContext; - @Schema(title = "分裂后的容器集合(分裂后的父容器特有字段)", required = false) private List groupContainers; @Override public String getClassType() { - return classType; + return CLASS_TYPE; } @Override public Container getContainerById(String vmSeqId) { - if (id.equals(vmSeqId) || containerId.equals(vmSeqId)) return this; - if (groupContainers != null) { - for (Container container : groupContainers) { - if (container.getId().equals(vmSeqId) || container.getContainerId().equals(vmSeqId)) return container; + if (vmSeqId.equals(id) || vmSeqId.equals(containerId)) { + return this; + } + List containers = fetchGroupContainers(); + if (containers != null) { + for (Container container : containers) { + if (vmSeqId.equals(container.getId()) || vmSeqId.equals(container.getContainerId())) { + return container; + } } } return null; @@ -108,7 +55,7 @@ public class NormalContainer implements Container { @Override public void retryFreshMatrixOption() { - groupContainers = new ArrayList<>(); + groupContainers = null; if (matrixControlOption != null) { matrixControlOption.setFinishCount(null); matrixControlOption.setTotalCount(null); @@ -117,7 +64,7 @@ public class NormalContainer implements Container { @Override public List fetchGroupContainers() { - return groupContainers != null ? new ArrayList<>(groupContainers) : null; + return groupContainers != null ? List.copyOf(groupContainers) : null; } @Override @@ -126,47 +73,23 @@ public class NormalContainer implements Container { } @Override - public Boolean containerEnabled() { - return jobControlOption != null ? jobControlOption.getEnable() : true; + public boolean containerEnabled() { + return jobControlOption == null || jobControlOption.getEnable(); } @Override - public void setContainerEnable(Boolean enable) { + public void setContainerEnable(boolean enable) { jobControlOption = jobControlOption != null ? jobControlOption.copy(enable) : new JobControlOption(enable); } - @Override - public void resetBuildOption(int executeCount) { - - } - @Override public void transformCompatibility() { - if (jobControlOption != null && jobControlOption.getTimeoutVar() == null || jobControlOption.getTimeoutVar().isBlank()) { + if (jobControlOption != null && (jobControlOption.getTimeoutVar() == null || jobControlOption.getTimeoutVar().isEmpty())) { jobControlOption.setTimeoutVar(String.valueOf(jobControlOption.getTimeout())); } - if (mutexGroup != null && (mutexGroup.getTimeoutVar() == null || mutexGroup.getTimeoutVar().isBlank())) { + if (mutexGroup != null && (mutexGroup.getTimeoutVar() == null || mutexGroup.getTimeoutVar().isEmpty())) { mutexGroup.setTimeoutVar(String.valueOf(mutexGroup.getTimeout())); } - } - - @Override - public Map genTaskParams() { - return null; - } - - @Override - public String getTemplate() { - return null; - } - - @Override - public String getRef() { - return null; - } - - @Override - public Map getVariables() { - return null; + super.transformCompatibility(); } } diff --git a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/TriggerContainer.java b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/TriggerContainer.java index efa42d2..1381280 100644 --- a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/TriggerContainer.java +++ b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/TriggerContainer.java @@ -2,6 +2,8 @@ package cd.casic.ci.common.pipeline.container; import cd.casic.ci.common.pipeline.pojo.BuildFormProperty; import cd.casic.ci.common.pipeline.pojo.BuildNo; +import cd.casic.ci.common.pipeline.pojo.element.Element; +import cd.casic.ci.common.pipeline.pojo.time.BuildRecordTimeCost; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.NoArgsConstructor; @@ -21,7 +23,7 @@ import java.util.Map; @Data @NoArgsConstructor @Schema(title = "流水线模型-构建触发容器") -public class TriggerContainer implements Container { +public class TriggerContainer extends Container { public static final String classType = "trigger"; @Schema(title = "构建容器序号id", required = false, readOnly = true) @@ -94,17 +96,32 @@ public class TriggerContainer implements Container { } @Override - public Boolean containerEnabled() { + public boolean containerEnabled() { return true; } @Override - public void setContainerEnable(Boolean enable) { - // No operation needed + public void setContainerEnable(boolean enable) { + } @Override public void transformCompatibility() { // No compatibility transformation needed } + + @Override + public String getTemplate() { + return null; + } + + @Override + public String getRef() { + return null; + } + + @Override + public Map getVariables() { + return null; + } } diff --git a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/VMBuildContainer.java b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/VMBuildContainer.java index 3f4589b..95670b6 100644 --- a/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/VMBuildContainer.java +++ b/modules/ci-commons/common-pipeline/src/main/java/cd/casic/ci/common/pipeline/container/VMBuildContainer.java @@ -28,7 +28,7 @@ import java.util.Set; @Data @NoArgsConstructor @Schema(title = "流水线模型-虚拟机构建容器") -public class VMBuildContainer implements Container { +public class VMBuildContainer extends Container { public static final String classType = "vmBuild"; @Schema(title = "构建容器序号id", required = false, readOnly = true) @@ -155,13 +155,13 @@ public class VMBuildContainer implements Container { } @Override - public Boolean containerEnabled() { + public boolean containerEnabled() { return jobControlOption != null ? jobControlOption.getEnable() : true; } @Override - public void setContainerEnable(Boolean enable) { - jobControlOption = jobControlOption != null ? jobControlOption.setEnable(enable) : new JobControlOption(enable); + public void setContainerEnable(boolean enable) { + } @Override @@ -173,4 +173,19 @@ public class VMBuildContainer implements Container { mutexGroup.setTimeoutVar(String.valueOf(mutexGroup.getTimeout())); } } + + @Override + public String getTemplate() { + return null; + } + + @Override + public String getRef() { + return null; + } + + @Override + public Map getVariables() { + return null; + } }