# Conflicts:
#	modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/pipeline/PipelineUpdateReq.java
#	modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/process/dataObject/pipeline/PipPipeline.java
This commit is contained in:
HopeLi 2025-05-16 16:14:49 +08:00
commit 734f44dfd3
40 changed files with 694 additions and 179 deletions

View File

@ -41,4 +41,6 @@ public interface GlobalErrorCodeConstants {
ErrorCode ID_DUPLICATION = new ErrorCode(1000, "ID重复");
ErrorCode PIPELINE_ERROR = new ErrorCode(1001,"流水线执行错误");
}

View File

@ -26,7 +26,7 @@ public class ModelUpdate {
private String name;
@Schema(title = "更新人", required = true)
private String updateUserId;
private Long updateUserId;
@Schema(title = "更新结果信息", required = false)
private String updateResultMessage;

View File

@ -30,7 +30,7 @@ public class PipelineQueryReq extends PageParam {
/**
* 创建人用户id
*/
private String createUserId;
private Long createUserId;
/**

View File

@ -16,9 +16,18 @@ public class PipelineUpdateReq {
private String name;
private Long createUserId;
private Long updateUserId;
private String envId;
private String groupId;
private LocalDateTime createTime;
private LocalDateTime updateTime;
/**
* @pi.name:type
* @pi.dataType:Integer
@ -65,7 +74,7 @@ public class PipelineUpdateReq {
private String pipelineTag;
private String projectId;
private String resourceId;
private String remark;
@ -84,4 +93,57 @@ public class PipelineUpdateReq {
private String pipelineTriggerMode;
private String executeStatus;
// // 以下为统计信息
//
//
// /**
// * @pi.model:execUser
// * @pi.desc:用户(执行人)
// */
// private User execUser;
//
// /**
// * @pi.name:number
// * @pi.dataType:Integer
// * @pi.desc:执行次数
// * @pi.value:2
// */
// private Integer number;
//
// /**
// * @pi.name:instanceId
// * @pi.dataType:string
// * @pi.desc:实例id
// * @pi.value:instanceId
// */
// private String instanceId;
//
//
// /**
// * @pi.name:buildStatus
// * @pi.dataType:string
// * @pi.desc:最近构建状态
// * @pi.value:buildStatus
// */
// private String buildStatus;
//
//
// /**
// * @pi.name:lastBuildTime
// * @pi.dataType:string
// * @pi.desc:最近构建时间
// * @pi.value:lastBuildTime
// */
// private String lastBuildTime;
//
//
// /**
// * @pi.name:isExec
// * @pi.dataType:boolean
// * @pi.desc:是否可以执行
// * @pi.value:true
// */
// private Boolean isExec;
}

View File

@ -114,9 +114,9 @@ public class ResourceQueryReq {
/**
* 创建人用户id
*/
private String createUserId;
private Long createUserId;
private String updateUserId;
private Long updateUserId;
/**
* 创建时间

View File

@ -114,9 +114,9 @@ public class ResourceReq {
/**
* 创建人用户id
*/
private String createUserId;
private Long createUserId;
private String updateUserId;
private Long updateUserId;
/**
* 创建时间

View File

@ -1,55 +0,0 @@
package cd.casic.ci.common.pipeline.req.stage;
import cd.casic.ci.common.pipeline.req.task.TasksReq;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class StageReq {
//@ApiProperty(name = "stageId",desc="id")
private String stageId;
//@ApiProperty(name = "stageName",desc="名称")
private String stageName;
//@ApiProperty(name = "createTime",desc="创建时间")
private LocalDateTime createTime;
//@ApiProperty(name="pipelineId",desc="流水线id")
private String pipelineId;
//@ApiProperty(name="stageSort",desc="阶段顺序")
private int stageSort;
//@ApiProperty(name = "parentId",desc="主阶段")
private String parentId;
//@ApiProperty(name = "code",desc="是否是源码")
private boolean code = false;
//@ApiProperty(name = "taskValues",desc="阶段任务")
private List<TasksReq> taskValues;
//@ApiProperty(name = "stageList",desc="阶段")
private List<StageReq> stageList;
//@ApiProperty(name = "taskType",desc="任务类型")
private String taskType;
//@ApiProperty(name = "taskId",desc="任务id")
private String taskId;
//@ApiProperty(name = "values",desc="更新内容")
private Object values;
//@ApiProperty(name = "taskSort",desc="任务顺序")
private int taskSort;
//@ApiProperty(name = "parallelName",desc="并行阶段名称")
private String parallelName;
// 执行实例id
private String instanceId;
}

View File

@ -8,6 +8,6 @@ public class StageUpdateReq {
private String stageName;
// 更新sort
private Integer stageSort;
private String stageId;
private String id;
private String pipelineId;
}

View File

@ -8,7 +8,7 @@ import java.time.LocalDateTime;
@Data
public class TasksReq {
//@ApiProperty(name="taskId",desc="配置id")
private String taskId;
private String id;
//@ApiProperty(name="createTime",desc="创建时间")
private LocalDateTime createTime;

View File

@ -20,13 +20,13 @@ public class PipelineFindResp {
private String name;
//创建人id
private String createUserId;
private Long createUserId;
//创建人姓名
private String createUserName;
//最后修改人id
private String updateUserId;
private Long updateUserId;
//最后修改人姓名
private String updateUserName;

View File

@ -114,9 +114,9 @@ public class ResourceResp {
/**
* 创建人用户id
*/
private String createUserId;
private Long createUserId;
private String updateUserId;
private Long updateUserId;
/**
* 创建时间

View File

@ -0,0 +1,10 @@
package cd.casic.ci.process.engine.dispatcher;
import cd.casic.ci.process.engine.runContext.BaseRunContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import java.util.List;
public interface BaseDispatcher {
void dispatch();
}

View File

@ -0,0 +1,26 @@
package cd.casic.ci.process.engine.dispatcher.impl;
import cd.casic.ci.process.engine.dispatcher.BaseDispatcher;
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.stage.PipStage;
import java.util.List;
public class ParallelDispatcher implements BaseDispatcher {
private List<PipStage> firstStageList;
private Integer stageIndex;
private PipelineRunContext context;
public ParallelDispatcher(List<PipStage> firstStageList, PipelineRunContext context) {
this.firstStageList = firstStageList;
this.context = context;
this.stageIndex = 0;
}
@Override
public void dispatch() {
}
}

View File

@ -0,0 +1,17 @@
package cd.casic.ci.process.engine.dispatcher.impl;
import cd.casic.ci.process.engine.dispatcher.BaseDispatcher;
import cd.casic.ci.process.engine.runContext.StageRunContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import java.util.List;
public class SerialDispatcher implements BaseDispatcher {
private StageRunContext stageRunContext;
private List<PipTask> itemList;
@Override
public void dispatch() {
}
}

View File

@ -0,0 +1,70 @@
package cd.casic.ci.process.engine.enums;
import lombok.Getter;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@Getter
public enum ContextStateEnum {
INIT(0,"初始化", new HashSet<>(){
{
add(READY);
add(SUSPEND);
add(STOP);
}
}),
READY(1,"就绪", new HashSet<>(){
{
add(RUNNING);
add(SUSPEND);
add(STOP);
}
}),
RUNNING(2,"运行", new HashSet<>(){
{
add(SUSPEND);
add(STOP);
add(HAPPY_ENDING);
add(BAD_ENDING);
}
}),
SUSPEND(3,"挂起", new HashSet<>(){
{
add(INIT);
add(READY);
add(RUNNING);
}
}),
STOP(-1,"停止", new HashSet<>()),
HAPPY_ENDING(4,"执行成功", new HashSet<>()),
BAD_ENDING(5,"执行失败", new HashSet<>())
;
private Integer code;
private String msg;
/**
* 包含当前所有合法的下一个状态
* */
private Set<ContextStateEnum> nextStep;
ContextStateEnum(Integer code, String msg, Set<ContextStateEnum> nextStep) {
this.code = code;
this.msg = msg;
this.nextStep = nextStep;
}
public static Boolean canGoto(ContextStateEnum from,ContextStateEnum to){
if (Objects.isNull(from) || Objects.isNull(to)) {
return false;
}
return from.nextStep.contains(to);
}
public static ContextStateEnum getByCode(Integer code){
for (ContextStateEnum value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}
}

View File

@ -0,0 +1,7 @@
package cd.casic.ci.process.engine.executor;
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
public interface PipelineExecutor {
PipelineRunContext execute(String pipelineId);
}

View File

@ -0,0 +1,45 @@
package cd.casic.ci.process.engine.executor.impl;
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
import cd.casic.ci.process.engine.dispatcher.impl.ParallelDispatcher;
import cd.casic.ci.process.engine.enums.ContextStateEnum;
import cd.casic.ci.process.engine.executor.PipelineExecutor;
import cd.casic.ci.process.engine.manager.RunContextManager;
import cd.casic.ci.process.engine.runContext.PipelineRunContext;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.ci.process.process.dataObject.stage.PipStage;
import cd.casic.ci.process.process.service.pipeline.PipelineService;
import cd.casic.ci.process.process.service.stage.StageService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@Component
public class DefaultPipelineExecutor implements PipelineExecutor {
@Resource
private PipelineService pipelineService;
@Resource
private StageService stageService;
@Resource
private RunContextManager runContextManager;
@Override
public PipelineRunContext execute(String pipelineId) {
PipPipeline pipeline = pipelineService.getById(pipelineId);
// TODO 判断状态不能重复运行
Integer state = pipeline.getState();
// TODO 判断资源是否申请成功是否处于可运行状态
String resourceId = pipeline.getResourceId();
String executeStatus = pipeline.getExecuteStatus();
// TODO 如果判断成功则查询所有的阶段信息
List<PipStage> mainStage = stageService.findAllFirstStagesAndChild(pipelineId);
PipelineRunContext pipelineRunContext = new PipelineRunContext(null,pipeline,new ConcurrentHashMap<>(),new ConcurrentHashMap<>());
runContextManager.contextRegister(pipelineRunContext);
// ParallelDispatcher parallelDispatcher = new ParallelDispatcher();
return null;
}
}

View File

@ -0,0 +1,31 @@
package cd.casic.ci.process.engine.manager;
import cd.casic.ci.process.engine.runContext.BaseRunContext;
public interface RunContextManager {
/**
* 停止流水线运行-预留
* */
Boolean stopPipeline(String pipelineId);
/**
* 恢复流水线运行-预留
* */
Boolean notifyPipeline(String pipelineId);
/**
* 挂起流水线-预留
* */
Boolean suspendPipeline(String pipelineId);
/**
* 恢复子阶段运行-预留
* */
Boolean notifyStage(String pipelineId,String stageId);
/**
* 挂起子阶段-预留
* */
Boolean suspendStage(String pipelineId,String stageId);
/**
* 判断相应的context类型放入注册Map中
* */
void contextRegister(BaseRunContext context);
BaseRunContext getContext(String key);
}

View File

@ -0,0 +1,4 @@
package cd.casic.ci.process.engine.manager;
public interface WorkerManager {
}

View File

@ -0,0 +1,43 @@
package cd.casic.ci.process.engine.manager.impl;
import cd.casic.ci.process.engine.manager.RunContextManager;
import cd.casic.ci.process.engine.runContext.BaseRunContext;
import org.springframework.stereotype.Component;
@Component
public class DefaultRunContextManager implements RunContextManager {
@Override
public Boolean stopPipeline(String pipelineId) {
return null;
}
@Override
public Boolean notifyPipeline(String pipelineId) {
return null;
}
@Override
public Boolean suspendPipeline(String pipelineId) {
return null;
}
@Override
public Boolean notifyStage(String pipelineId, String stageId) {
return null;
}
@Override
public Boolean suspendStage(String pipelineId, String stageId) {
return null;
}
@Override
public void contextRegister(BaseRunContext context) {
}
@Override
public BaseRunContext getContext(String key) {
return null;
}
}

View File

@ -0,0 +1,97 @@
package cd.casic.ci.process.engine.runContext;
import cd.casic.ci.process.engine.enums.ContextStateEnum;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@Data
public abstract class BaseRunContext {
/**
* 当前上下文的定义
* */
private PipBaseElement contextDef;
private BaseRunContext parentContext;
/**
* 运行状态
* */
private AtomicInteger state;
/**
* 启动时间
* */
private LocalDateTime startTime;
/**
* 结束时间
* */
private LocalDateTime endTime;
private String resourceId;
private String targetId;
private String targetType;
/**
* 整个流水线全局的变量
* */
private Map<String,Object> globalVariables;
/**
* 当前上下文局部变量
* */
private Map<String,Object> localVariables;
private Map<String,BaseRunContext> childContext;
public BaseRunContext(PipBaseElement contextDef,BaseRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables, Map<String, BaseRunContext> childContext) {
this.contextDef = contextDef;
this.parentContext = parentContext;
this.state = new AtomicInteger(ContextStateEnum.INIT.getCode());
this.startTime = startTime;
this.resourceId = resourceId;
this.targetId = targetId;
this.targetType = targetType;
this.globalVariables = globalVariables;
this.localVariables = localVariables;
this.childContext = childContext;
}
/**
* 获取当前或者子上下文
* */
public abstract BaseRunContext getChildRunContext(String key);
public abstract void putChildRunContext(String key,BaseRunContext context);
public void callParentChange(ContextStateEnum state){
if (ContextStateEnum.HAPPY_ENDING.equals(state)||ContextStateEnum.BAD_ENDING.equals(state)) {
checkChildEnd();
}
}
/**
* 查找子类是否全部完成如果子类全部完成则父类也全部完成
* */
public void checkChildEnd() throws ServiceException{
int result = ContextStateEnum.HAPPY_ENDING.getCode();
for (Map.Entry<String, BaseRunContext> entry : childContext.entrySet()) {
BaseRunContext child = entry.getValue();
int state = child.getState().get();
if (!ContextStateEnum.HAPPY_ENDING.getCode().equals(state)&&!ContextStateEnum.BAD_ENDING.getCode().equals(state)) {
return;
}
result&=state;
}
boolean end = false;
if (ContextStateEnum.HAPPY_ENDING.getCode()==result) {
if (ContextStateEnum.canGoto(ContextStateEnum.getByCode(state.get()),ContextStateEnum.HAPPY_ENDING)) {
this.state.compareAndExchange(state.get(),ContextStateEnum.HAPPY_ENDING.getCode());
end = true;
}
} else {
if (ContextStateEnum.canGoto(ContextStateEnum.getByCode(state.get()),ContextStateEnum.BAD_ENDING)) {
this.state.compareAndExchange(state.get(),ContextStateEnum.BAD_ENDING.getCode());
end = true;
}
}
if (!end) {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"状态有误");
}
}
}

View File

@ -0,0 +1,22 @@
package cd.casic.ci.process.engine.runContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import java.time.LocalDateTime;
import java.util.Map;
public class MainStageContext extends BaseRunContext{
public MainStageContext(PipBaseElement contextDef, BaseRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables, Map<String, BaseRunContext> childContext) {
super(contextDef, parentContext, startTime, resourceId, targetId, targetType, globalVariables, localVariables, childContext);
}
@Override
public BaseRunContext getChildRunContext(String key) {
return null;
}
@Override
public void putChildRunContext(String key, BaseRunContext context) {
}
}

View File

@ -0,0 +1,59 @@
package cd.casic.ci.process.engine.runContext;
import cd.casic.ci.process.api.process.pojo.Pipeline;
import cd.casic.ci.process.engine.enums.ContextStateEnum;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class PipelineRunContext extends BaseRunContext{
public PipelineRunContext(BaseRunContext parentContext,PipPipeline pipeline,Map<String, Object> globalVariables,Map<String, Object> localVariables) {
this(pipeline,parentContext,LocalDateTime.now(),pipeline.getResourceId(),pipeline.getTargetId(),pipeline.getTargetType(),globalVariables,localVariables,new ConcurrentHashMap<>());
}
private PipelineRunContext(PipBaseElement contextDef, BaseRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables, Map<String, BaseRunContext> childContext) {
super( contextDef
,parentContext
,startTime
, resourceId
, targetId
, targetType
, globalVariables
, localVariables
, childContext);
}
/**
* pipeline 底下有多个阶段多个阶段包含多个task 不保存第二级context
* */
@Override
public BaseRunContext getChildRunContext(String stageId) {
Map<String, BaseRunContext> childContext = getChildContext();
for (Map.Entry<String, BaseRunContext> entry : childContext.entrySet()) {
BaseRunContext childRunContext = entry.getValue().getChildRunContext(stageId);
if (childRunContext!=null) {
return childRunContext;
}
}
return null;
}
@Override
public void putChildRunContext(String key, BaseRunContext context) {
Map<String, BaseRunContext> childContext = getChildContext();
if (context instanceof StageRunContext) {
childContext.put(key,context);
} else {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"不支持类型");
}
}
}

View File

@ -0,0 +1,36 @@
package cd.casic.ci.process.engine.runContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import java.time.LocalDateTime;
import java.util.Map;
public class StageRunContext extends BaseRunContext{
public StageRunContext(PipBaseElement contextDef, BaseRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables, Map<String, BaseRunContext> childContext) {
super(contextDef, parentContext, startTime, resourceId, targetId, targetType, globalVariables, localVariables, childContext);
}
@Override
public BaseRunContext getChildRunContext(String taskId) {
Map<String, BaseRunContext> childContext = getChildContext();
for (Map.Entry<String, BaseRunContext> entry : childContext.entrySet()) {
BaseRunContext childRunContext = entry.getValue().getChildRunContext(taskId);
if (childRunContext!=null) {
return childRunContext;
}
}
return null;
}
@Override
public void putChildRunContext(String key, BaseRunContext context) {
Map<String, BaseRunContext> childContext = getChildContext();
if (context instanceof TaskRunContext) {
childContext.put(key,context);
} else {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"不支持类型");
}
}
}

View File

@ -0,0 +1,40 @@
package cd.casic.ci.process.engine.runContext;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.framework.commons.exception.ServiceException;
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
public class TaskRunContext extends BaseRunContext{
public TaskRunContext(PipTask contextDef, StageRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables) {
super(contextDef, parentContext, startTime, resourceId, targetId, targetType, globalVariables, localVariables, new HashMap<>());
}
private TaskRunContext(PipBaseElement contextDef, BaseRunContext parentContext, LocalDateTime startTime, String resourceId, String targetId, String targetType, Map<String, Object> globalVariables, Map<String, Object> localVariables, Map<String, BaseRunContext> childContext) {
super(contextDef, parentContext, startTime, resourceId, targetId, targetType, globalVariables, localVariables, childContext);
}
/**
* task是最后一层没有下一级所以如果id相同直接返回它自己
* */
@Override
public BaseRunContext getChildRunContext(String id) {
if (!StringUtils.isEmpty(id)||!id.equals(this.getContextDef().getId())) {
return null;
}
return this;
}
@Override
public void putChildRunContext(String key, BaseRunContext context) {
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"task没有子阶段");
}
}

View File

@ -0,0 +1,21 @@
package cd.casic.ci.process.process.dataObject.base;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class PipBaseElement {
/**
* 主键id
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
//@ApiProperty(name = "createTime",desc="创建时间")
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Long createUserId;
private Long updateUserId;
}

View File

@ -6,39 +6,16 @@ import lombok.Data;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
@Data
public class PipPipeline {
/**
* 主键id
*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
public class PipPipeline extends PipBaseElement {
/**
* 流水线名称
*/
private String name;
/**
* 创建人用户id
*/
private String createUserId;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 最后修改人用户id
*/
private String updateUserId;
/**
* 最后修改时间
*/
private LocalDateTime updateTime;
/**
* 流水线类型 1.多任务 2.多阶段
*/

View File

@ -117,9 +117,9 @@ public class PipResource {
/**
* 创建人用户id
*/
private String createUserId;
private Long createUserId;
private String updateUserId;
private Long updateUserId;
/**
* 创建时间

View File

@ -1,24 +1,23 @@
package cd.casic.ci.process.process.dataObject.stage;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@Data
public class PipStage {
public class PipStage extends PipBaseElement {
//@ApiProperty(name = "stageId",desc="id")
@TableId(type = IdType.ASSIGN_ID)
private String stageId;
//@ApiProperty(name = "stageName",desc="名称")
private String stageName;
//@ApiProperty(name = "createTime",desc="创建时间")
private LocalDateTime createTime;
//@ApiProperty(name="pipelineId",desc="流水线id")
private String pipelineId;
@ -42,7 +41,5 @@ public class PipStage {
// 执行实例id
@TableField(exist = false)
private String instanceId;
private LocalDateTime updateTime;
private Long createUserId;
private Long updateUserId;
}

View File

@ -1,21 +1,18 @@
package cd.casic.ci.process.process.dataObject.task;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.json.JSONObject;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
@Data
public class PipTask {
//@ApiProperty(name="taskId",desc="配置id")
@TableId(type = IdType.ASSIGN_ID)
private String taskId;
//@ApiProperty(name="createTime",desc="创建时间")
private LocalDateTime createTime;
public class PipTask extends PipBaseElement {
//@ApiProperty(name="taskType",desc= "类型1-10:源码,10-20:测试,20-30:构建,30-40:部署,40-50:代码扫描,50-60:推送制品")
private String taskType;
@ -40,7 +37,5 @@ public class PipTask {
// 执行实例id
@TableField(exist = false)
private String instanceId;
private LocalDateTime updateTime;
private Long updateUserId;
private Long createUserId;
}

View File

@ -82,8 +82,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
pipeline.setCreateTime(LocalDateTime.now());
if (Objects.isNull(pipeline.getCreateUserId())){
String loginUserId = String.valueOf(WebFrameworkUtils.getLoginUserId());
pipeline.setCreateUserId(loginUserId);
pipeline.setCreateUserId(WebFrameworkUtils.getLoginUserId());
}
pipeline.setState(1);
@ -124,7 +123,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childStage1.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childStage1.setStageSort(1);
childStage1.setCode(false);
childStage1.setParentId(stageReq1.getStageId());
childStage1.setParentId(stageReq1.getId());
stageService.save(childStage1);
//新增第二个阶段包含串行和并行任务
@ -146,7 +145,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childStage21.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childStage21.setStageSort(1);
childStage21.setCode(false);
childStage21.setParentId(stageReq2.getStageId());
childStage21.setParentId(stageReq2.getId());
stageService.save(childStage21);
//新增串行阶段
@ -157,7 +156,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childTask21.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childTask21.setTaskType("test");
childTask21.setTaskSort(1);
childTask21.setStageId(childStage21.getStageId());
childTask21.setStageId(childStage21.getId());
taskService.save(childTask21);
//------------------------------------------------------------------
@ -168,7 +167,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childStage22.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childStage22.setStageSort(2);
childStage22.setCode(false);
childStage22.setParentId(stageReq2.getStageId());
childStage22.setParentId(stageReq2.getId());
stageService.save(childStage22);
PipTask childTask22 = new PipTask();
@ -178,7 +177,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childTask22.setPipelineId(pipeline.getId());
childTask22.setTaskType("test");
childTask22.setTaskSort(2);
childTask22.setStageId(childStage22.getStageId());
childTask22.setStageId(childStage22.getId());
taskService.save(childTask22);
//创建第三个阶段
@ -199,7 +198,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childStage31.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childStage31.setStageSort(1);
childStage31.setCode(false);
childStage31.setParentId(stageReq3.getStageId());
childStage31.setParentId(stageReq3.getId());
stageService.save(childStage31);
PipTask childTask31 = new PipTask();
@ -209,7 +208,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childTask31.setPipelineId(pipeline.getId());
childTask31.setTaskType("test");
childTask31.setTaskSort(1);
childTask31.setStageId(childStage31.getStageId());
childTask31.setStageId(childStage31.getId());
taskService.save(childTask31);
//创建第四个阶段
@ -230,7 +229,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childStage41.setCreateUserId(WebFrameworkUtils.getLoginUserId());
childStage41.setStageSort(1);
childStage41.setCode(false);
childStage41.setParentId(stageReq4.getStageId());
childStage41.setParentId(stageReq4.getId());
stageService.save(childStage41);
PipTask childTask41 = new PipTask();
@ -240,7 +239,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
childTask41.setPipelineId(pipeline.getId());
childTask41.setTaskType("test");
childTask41.setTaskSort(1);
childTask41.setStageId(childStage41.getStageId());
childTask41.setStageId(childStage41.getId());
taskService.save(childTask41);
//TODO 创建对应的鉴权关系
@ -313,7 +312,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
pipStage.setPipelineId(pipelineId);
List<PipStage> pipStageList = stageService.getPipStageList(pipStage);
if (!CollectionUtils.isEmpty(pipStageList)){
List<String> list = pipStageList.stream().map(PipStage::getStageId).toList();
List<String> list = pipStageList.stream().map(PipStage::getId).toList();
pipStageDao.deleteByIds(list);
}
@ -321,7 +320,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
pipTask.setPipelineId(pipelineId);
List<PipTask> task = taskService.getTask(pipTask);
if (!CollectionUtils.isEmpty(task)){
List<String> list = task.stream().map(PipTask::getTaskId).toList();
List<String> list = task.stream().map(PipTask::getId).toList();
pipTaskDao.deleteByIds(list);
}
@ -340,7 +339,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
PipPipeline pipPipeline = new PipPipeline();
BeanUtils.copyProperties(pipeline,pipPipeline);
pipPipeline.setUpdateTime(LocalDateTime.now());
pipPipeline.setUpdateUserId(String.valueOf(WebFrameworkUtils.getLoginUserId()));
pipPipeline.setUpdateUserId(WebFrameworkUtils.getLoginUserId());
pipelineDao.updateById(pipPipeline);
}
@ -397,7 +396,7 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
pipeline.setId(null);
pipeline.setName(pipelineName);
pipeline.setCreateTime(LocalDateTime.now());
pipeline.setCreateUserId(String.valueOf(WebFrameworkUtils.getLoginUserId()));
pipeline.setCreateUserId(WebFrameworkUtils.getLoginUserId());
this.save(pipeline);
//复制stage
@ -413,11 +412,11 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
//根据阶段id查询下游并行节点
PipStage childStage = new PipStage();
childStage.setPipelineId(pipelineId);
childStage.setParentId(o.getStageId());
childStage.setParentId(o.getId());
List<PipStage> pipStageChildList = stageService.getPipStageList(pipStage);
//对查询结束的stage进行复制
o.setStageId(null);
o.setId(null);
o.setPipelineId(pipeline.getId());
o.setCreateTime(LocalDateTime.now());
o.setCreateUserId(WebFrameworkUtils.getLoginUserId());
@ -429,12 +428,12 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
//根据stageId查询串行节点
PipTask pipTask = new PipTask();
pipTask.setPipelineId(pipelineId);
pipTask.setStageId(j.getStageId());
pipTask.setStageId(j.getId());
List<PipTask> taskList = taskService.getTask(pipTask);
//对查询结束的并行节点进行复制
j.setStageId(null);
j.setParentId(o.getStageId());
j.setId(null);
j.setParentId(o.getId());
j.setPipelineId(pipeline.getId());
j.setCreateTime(LocalDateTime.now());
j.setCreateUserId(WebFrameworkUtils.getLoginUserId());
@ -442,8 +441,8 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
if (!CollectionUtils.isEmpty(taskList)){
taskList.forEach(k->{
k.setTaskId(null);
k.setStageId(j.getStageId());
k.setId(null);
k.setStageId(j.getId());
k.setPipelineId(pipeline.getId());
k.setCreateTime(LocalDateTime.now());
k.setCreateUserId(WebFrameworkUtils.getLoginUserId());

View File

@ -1,14 +1,11 @@
package cd.casic.ci.process.process.service.stage;
import cd.casic.ci.common.pipeline.req.stage.StageCreateReq;
import cd.casic.ci.common.pipeline.req.stage.StageReq;
import cd.casic.ci.common.pipeline.req.stage.StageUpdateReq;
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
import cd.casic.ci.process.process.dataObject.stage.PipStage;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
@ -27,6 +24,7 @@ public interface StageService extends IService<PipStage> {
* @return 任务
*/
List<StageResp> findAllStagesTask(String pipelineId);
List<PipStage> findAllFirstStagesAndChild(String pipelineId);
/**
* 删除阶段及任务

View File

@ -78,7 +78,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
save(firstStage);
} else {
PipStage stageQuery = new PipStage();
stageQuery.setStageId(firstStageId);
stageQuery.setId(firstStageId);
List<PipStage> pipStageList = getPipStageList(stageQuery);
if (!CollectionUtils.isEmpty(pipStageList)) {
firstStage = pipStageList.get(0);
@ -108,7 +108,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
secondStage.setUpdateUserId(loginUserId);
save(secondStage);
taskSort=1;
secondStageId = secondStage.getStageId();
secondStageId = secondStage.getId();
} else {
secondStage = getById(secondStageId);
}
@ -128,7 +128,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
pipTask.setCreateUserId(loginUserId);
pipTask.setUpdateUserId(loginUserId);
taskService.save(pipTask);
return pipTask.getTaskId();
return pipTask.getId();
}
@Override
@ -140,9 +140,9 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
}
List<StageResp> list = new ArrayList<>();
for (PipStage stage : stageMainStage) {
String stagesId = stage.getStageId();
String stagesId = stage.getId();
//获取从节点
List<PipStage> allStageStage = findOtherStageNoTask(stagesId);
List<PipStage> allStageStage = findSecondStageAndTask(stagesId);
List<StageResp> stageRespList = allStageStage.stream().map(it -> {
StageResp stageResp = new StageResp();
BeanUtils.copyProperties(it, stageResp);
@ -157,10 +157,27 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
return list;
}
@Override
public List<PipStage> findAllFirstStagesAndChild(String pipelineId) {
//获取流水线主节点
List<PipStage> stageMainStage = findAllMainStage(pipelineId);
if (stageMainStage.isEmpty()){
return Collections.emptyList();
}
for (PipStage stage : stageMainStage) {
String stagesId = stage.getId();
//获取从节点
List<PipStage> allStageStage = findSecondStageAndTask(stagesId);
stage.setStageList(allStageStage);
}
stageMainStage.sort(Comparator.comparing(PipStage::getStageSort));
return stageMainStage;
}
@Override
public void deleteStagesOrTask(String taskId) {
PipTask taskQuery = new PipTask();
taskQuery.setTaskId(taskId);
taskQuery.setId(taskId);
List<PipTask> taskList = taskService.getTask(taskQuery);
if (CollectionUtils.isEmpty(taskList)) {
return;
@ -170,7 +187,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
// 查询上一级stage下有无其他task 没有则连着stage删除
String stageId = task.getStageId();
String pipelineId = task.getPipelineId();
taskQuery.setTaskId("");
taskQuery.setId("");
taskQuery.setStageId(stageId);
List<PipTask> otherTask = taskService.getTask(task);
if (CollectionUtils.isEmpty(otherTask)) {
@ -186,7 +203,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
deleteStages(stageId);
String parentId = currStage.getParentId();
stageQuery.setParentId(parentId);
stageQuery.setStageId(null);
stageQuery.setId(null);
// 查询同阶段其他二级stage如果不存在其他stage则删除阶段stage并整理sort值
List<PipStage> otherStageList = getPipStageList(stageQuery);
if (CollectionUtils.isEmpty(otherStageList)) {
@ -216,7 +233,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
public List<PipStage> getPipStageList(PipStage pipStage){
LambdaQueryWrapper<PipStage> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(StringUtils.isNotEmpty(pipStage.getStageId()),PipStage::getStageId,pipStage.getStageId());
wrapper.eq(StringUtils.isNotEmpty(pipStage.getId()),PipStage::getId,pipStage.getId());
wrapper.eq(StringUtils.isNotEmpty(pipStage.getPipelineId()),PipStage::getPipelineId,pipStage.getPipelineId());
wrapper.eq(StringUtils.isNotEmpty(pipStage.getParentId()),PipStage::getParentId,pipStage.getParentId());
return stageDao.selectList(wrapper);
@ -232,11 +249,11 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
@Transactional(rollbackFor = Exception.class)
@Override
public void updateStagesTask(StageUpdateReq stage) {
String stageId = stage.getStageId();
String id = stage.getId();
String stageName = stage.getStageName();
Integer currStageSort = stage.getStageSort();
Long loginUserId = WebFrameworkUtils.getLoginUserId();
PipStage updateStage = getById(stageId);
PipStage updateStage = getById(id);
if (updateStage==null) {
return;
}
@ -258,7 +275,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
if (oldStageSort<currStageSort) {
// 往右移动
for (PipStage pipStage : stageList) {
if (!pipStage.getStageId().equals(updateStage.getStageId())) {
if (!pipStage.getId().equals(updateStage.getId())) {
if (pipStage.getStageSort()>oldStageSort&&pipStage.getStageSort()<=currStageSort) {
pipStage.setStageSort(pipStage.getStageSort()-1);
}
@ -267,7 +284,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
} else {
// 往左移动
for (PipStage pipStage : stageList) {
if (!pipStage.getStageId().equals(updateStage.getStageId())) {
if (!pipStage.getId().equals(updateStage.getId())) {
if (pipStage.getStageSort()<oldStageSort&&pipStage.getStageSort()>=currStageSort) {
pipStage.setStageSort(pipStage.getStageSort()+1);
}
@ -311,14 +328,14 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
}
}
// 保存复制后的阶段除了id和sort其他都一样
firstStage.setStageId(null);
firstStage.setId(null);
firstStage.setStageSort(firstStage.getStageSort()+1);
save(firstStage);
updateBatchById(updateStageList);
// 查询阶段下所有分支
List<PipStage> secondStageList = findSecondStage(stageId);
if (!CollectionUtils.isEmpty(secondStageList)) {
List<String> stageIdList = secondStageList.stream().map(PipStage::getStageId).toList();
List<String> stageIdList = secondStageList.stream().map(PipStage::getId).toList();
List<PipTask> taskList = taskService.listByIds(stageIdList);
Map<String, List<PipTask>> stageIdMap = taskList.stream().collect(Collectors.groupingBy(PipTask::getStageId));
for (PipStage secondStage : secondStageList) {
@ -326,14 +343,14 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
secondStage.setCreateTime(LocalDateTime.now());
secondStage.setUpdateTime(LocalDateTime.now());
secondStage.setUpdateUserId(loginUserId);
secondStage.setParentId(firstStage.getStageId());
String secondStageId = secondStage.getStageId();
secondStage.setParentId(firstStage.getId());
String secondStageId = secondStage.getId();
List<PipTask> childTask = stageIdMap.get(secondStageId);
secondStage.setStageId(null);
secondStage.setId(null);
save(secondStage);
for (PipTask pipTask : childTask) {
pipTask.setStageId(secondStage.getStageId());
pipTask.setTaskId(null);
pipTask.setStageId(secondStage.getId());
pipTask.setId(null);
pipTask.setCreateUserId(loginUserId);
pipTask.setCreateTime(LocalDateTime.now());
pipTask.setUpdateTime(LocalDateTime.now());
@ -345,14 +362,14 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
}
public List<PipStage> findOtherStageNoTask(String stagesId){
public List<PipStage> findSecondStageAndTask(String stagesId){
List<PipStage> otherStage = findSecondStage(stagesId);
List<PipStage> list = new ArrayList<>();
List<String> stageIdList = otherStage.stream().map(PipStage::getStageId).toList();
List<String> stageIdList = otherStage.stream().map(PipStage::getId).toList();
Map<String, List<PipTask>> stageIdTaskMap = taskService.listByIds(stageIdList).stream().collect(Collectors.groupingBy(PipTask::getStageId));
for (PipStage stage : otherStage) {
//获取阶段配置及任务
String otherId = stage.getStageId();
String otherId = stage.getId();
List<PipTask> allStageTask = stageIdTaskMap.get(otherId);
stage.setTaskValues(allStageTask);
list.add(stage);

View File

@ -56,7 +56,7 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
@Override
public List<PipTask> getTask(PipTask task) {
LambdaQueryWrapper<PipTask> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(StringUtils.isNotEmpty(task.getTaskId()),PipTask::getTaskId,task.getTaskId());
wrapper.eq(StringUtils.isNotEmpty(task.getId()),PipTask::getId,task.getId());
wrapper.eq(StringUtils.isNotEmpty(task.getPipelineId()),PipTask::getPipelineId,task.getPipelineId());
wrapper.eq(StringUtils.isNotEmpty(task.getStageId()),PipTask::getStageId,task.getStageId());
return taskDao.selectList(wrapper);
@ -64,7 +64,7 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
@Override
public TasksResp getRespById(String taskId){
PipTask pipTask = new PipTask();
pipTask.setTaskId(taskId);
pipTask.setId(taskId);
List<PipTask> taskList = getTask(pipTask);
if (!CollectionUtils.isEmpty(taskList)) {
return null;
@ -90,7 +90,7 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
}
List<PipTask> updateList = new ArrayList<>(sameLevelTaskList.size());
for (PipTask pipTask : sameLevelTaskList) {
if (!pipTask.getTaskId().equals(sourceTask.getTaskId())) {
if (!pipTask.getId().equals(sourceTask.getId())) {
if (pipTask.getTaskSort()>sourceTask.getTaskSort()) {
pipTask.setTaskSort(pipTask.getTaskSort()+1);
updateList.add(pipTask);
@ -98,7 +98,7 @@ public class TaskServiceImpl extends ServiceImpl<PipTaskDao, PipTask> implements
}
}
sourceTask.setTaskSort(sourceTask.getTaskSort()+1);
sourceTask.setTaskId(null);
sourceTask.setId(null);
save(sourceTask);
if (!CollectionUtils.isEmpty(updateList)) {
updateBatchById(updateList);

View File

@ -15,7 +15,7 @@ import java.util.List;
public class ProjectCreateUserInfo {
@Schema(title = "操作人")
private String createUserId;
private Long createUserId;
@Schema(title = "待分配的角色名称")
private String roleName;

View File

@ -19,10 +19,10 @@ public interface ConfigConvert {
List<ConfigRespVO> convertList(List<ConfigDO> list);
@Mapping(source = "configKey", target = "key")
// @Mapping(source = "configKey", target = "key")
ConfigRespVO convert(ConfigDO bean);
@Mapping(source = "key", target = "configKey")
// @Mapping(source = "key", target = "configKey")
ConfigDO convert(ConfigSaveReqVO bean);
}

View File

@ -11,12 +11,12 @@ import org.mapstruct.factory.Mappers;
*
* @author mianbin modified from yudao
*/
@Mapper
//@Mapper
public interface FileConfigConvert {
FileConfigConvert INSTANCE = Mappers.getMapper(FileConfigConvert.class);
@Mapping(target = "config", ignore = true)
// @Mapping(target = "config", ignore = true)
FileConfigDO convert(FileConfigSaveReqVO bean);
}

View File

@ -9,7 +9,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
//@Mapper
public interface DictDataConvert {
DictDataConvert INSTANCE = Mappers.getMapper(DictDataConvert.class);

View File

@ -9,7 +9,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
//@Mapper
public interface DictTypeConvert {
DictTypeConvert INSTANCE = Mappers.getMapper(DictTypeConvert.class);

View File

@ -1,13 +1,10 @@
package cd.casic.server.controller;
import cd.casic.ci.common.pipeline.req.stage.StageCreateReq;
import cd.casic.ci.common.pipeline.req.stage.StageReq;
import cd.casic.ci.common.pipeline.req.stage.StageUpdateReq;
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
import cd.casic.ci.process.process.service.stage.StageService;
import cd.casic.framework.commons.pojo.CommonResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
@ -18,8 +15,6 @@ import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**