执行引擎部分代码(开了个头),stage,task主键字段改为id
This commit is contained in:
parent
b5c7584135
commit
969def7fc3
@ -41,4 +41,6 @@ public interface GlobalErrorCodeConstants {
|
|||||||
|
|
||||||
ErrorCode ID_DUPLICATION = new ErrorCode(1000, "ID重复");
|
ErrorCode ID_DUPLICATION = new ErrorCode(1000, "ID重复");
|
||||||
|
|
||||||
|
ErrorCode PIPELINE_ERROR = new ErrorCode(1001,"流水线执行错误");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -8,6 +8,6 @@ public class StageUpdateReq {
|
|||||||
private String stageName;
|
private String stageName;
|
||||||
// 更新sort
|
// 更新sort
|
||||||
private Integer stageSort;
|
private Integer stageSort;
|
||||||
private String stageId;
|
private String id;
|
||||||
private String pipelineId;
|
private String pipelineId;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
public class TasksReq {
|
public class TasksReq {
|
||||||
//@ApiProperty(name="taskId",desc="配置id")
|
//@ApiProperty(name="taskId",desc="配置id")
|
||||||
private String taskId;
|
private String id;
|
||||||
|
|
||||||
//@ApiProperty(name="createTime",desc="创建时间")
|
//@ApiProperty(name="createTime",desc="创建时间")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
@ -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();
|
||||||
|
}
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package cd.casic.ci.process.engine.manager;
|
||||||
|
|
||||||
|
public interface WorkerManager {
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package cd.casic.ci.process.engine.manager.impl;
|
||||||
|
|
||||||
|
public class DefaultRunContextManager {
|
||||||
|
}
|
@ -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(),"状态有误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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(),"不支持类型");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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(),"不支持类型");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package cd.casic.ci.process.engine.runContext;
|
||||||
|
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class TaskRunContext extends BaseRunContext{
|
||||||
|
private String taskId;
|
||||||
|
private String taskType;
|
||||||
|
/**
|
||||||
|
* task是最后一层没有下一级所以如果id相同直接返回它自己
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public BaseRunContext getChildRunContext(String id) {
|
||||||
|
if (!StringUtils.isEmpty(id)||!id.equals(taskId)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putChildRunContext(String key, BaseRunContext context) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"task没有子阶段");
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -1,38 +1,23 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.pipeline;
|
package cd.casic.ci.process.process.dataObject.pipeline;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class PipPipeline {
|
public class PipPipeline extends PipBaseElement {
|
||||||
/**
|
|
||||||
* 主键id
|
|
||||||
*/
|
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流水线名称
|
* 流水线名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人用户id
|
|
||||||
*/
|
|
||||||
private String createUserId;
|
|
||||||
|
|
||||||
private String updateUserId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
private LocalDateTime updateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流水线类型 1.多任务 2.多阶段
|
* 流水线类型 1.多任务 2.多阶段
|
||||||
*/
|
*/
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.stage;
|
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 cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class PipStage {
|
public class PipStage extends PipBaseElement {
|
||||||
//@ApiProperty(name = "stageId",desc="id")
|
//@ApiProperty(name = "stageId",desc="id")
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private String stageId;
|
private String stageId;
|
||||||
@ -17,8 +20,7 @@ public class PipStage {
|
|||||||
//@ApiProperty(name = "stageName",desc="名称")
|
//@ApiProperty(name = "stageName",desc="名称")
|
||||||
private String stageName;
|
private String stageName;
|
||||||
|
|
||||||
//@ApiProperty(name = "createTime",desc="创建时间")
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
//@ApiProperty(name="pipelineId",desc="流水线id")
|
//@ApiProperty(name="pipelineId",desc="流水线id")
|
||||||
private String pipelineId;
|
private String pipelineId;
|
||||||
@ -42,7 +44,5 @@ public class PipStage {
|
|||||||
// 执行实例id
|
// 执行实例id
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
private LocalDateTime updateTime;
|
|
||||||
private Long createUserId;
|
|
||||||
private Long updateUserId;
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.task;
|
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.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class PipTask {
|
public class PipTask extends PipBaseElement {
|
||||||
//@ApiProperty(name="taskId",desc="配置id")
|
//@ApiProperty(name="taskId",desc="配置id")
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
//@ApiProperty(name="createTime",desc="创建时间")
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
//@ApiProperty(name="taskType",desc= "类型1-10:源码,10-20:测试,20-30:构建,30-40:部署,40-50:代码扫描,50-60:推送制品")
|
//@ApiProperty(name="taskType",desc= "类型1-10:源码,10-20:测试,20-30:构建,30-40:部署,40-50:代码扫描,50-60:推送制品")
|
||||||
private String taskType;
|
private String taskType;
|
||||||
|
|
||||||
@ -40,7 +40,5 @@ public class PipTask {
|
|||||||
// 执行实例id
|
// 执行实例id
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
private LocalDateTime updateTime;
|
|
||||||
private Long updateUserId;
|
|
||||||
private Long createUserId;
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
package cd.casic.ci.process.process.service.stage;
|
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.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.req.stage.StageUpdateReq;
|
||||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -27,6 +24,7 @@ public interface StageService extends IService<PipStage> {
|
|||||||
* @return 任务
|
* @return 任务
|
||||||
*/
|
*/
|
||||||
List<StageResp> findAllStagesTask(String pipelineId);
|
List<StageResp> findAllStagesTask(String pipelineId);
|
||||||
|
List<PipStage> findAllFirstStagesAndChild(String pipelineId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除阶段及任务
|
* 删除阶段及任务
|
||||||
|
@ -142,7 +142,7 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|||||||
for (PipStage stage : stageMainStage) {
|
for (PipStage stage : stageMainStage) {
|
||||||
String stagesId = stage.getStageId();
|
String stagesId = stage.getStageId();
|
||||||
//获取从节点
|
//获取从节点
|
||||||
List<PipStage> allStageStage = findOtherStageNoTask(stagesId);
|
List<PipStage> allStageStage = findSecondStageAndTask(stagesId);
|
||||||
List<StageResp> stageRespList = allStageStage.stream().map(it -> {
|
List<StageResp> stageRespList = allStageStage.stream().map(it -> {
|
||||||
StageResp stageResp = new StageResp();
|
StageResp stageResp = new StageResp();
|
||||||
BeanUtils.copyProperties(it, stageResp);
|
BeanUtils.copyProperties(it, stageResp);
|
||||||
@ -157,6 +157,23 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
|||||||
return list;
|
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.getStageId();
|
||||||
|
//获取从节点
|
||||||
|
List<PipStage> allStageStage = findSecondStageAndTask(stagesId);
|
||||||
|
stage.setStageList(allStageStage);
|
||||||
|
}
|
||||||
|
stageMainStage.sort(Comparator.comparing(PipStage::getStageSort));
|
||||||
|
return stageMainStage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteStagesOrTask(String taskId) {
|
public void deleteStagesOrTask(String taskId) {
|
||||||
PipTask taskQuery = new PipTask();
|
PipTask taskQuery = new PipTask();
|
||||||
@ -345,7 +362,7 @@ 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> otherStage = findSecondStage(stagesId);
|
||||||
List<PipStage> list = new ArrayList<>();
|
List<PipStage> list = new ArrayList<>();
|
||||||
List<String> stageIdList = otherStage.stream().map(PipStage::getStageId).toList();
|
List<String> stageIdList = otherStage.stream().map(PipStage::getStageId).toList();
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package cd.casic.server.controller;
|
package cd.casic.server.controller;
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.req.stage.StageCreateReq;
|
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.req.stage.StageUpdateReq;
|
||||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||||
import cd.casic.ci.process.process.service.stage.StageService;
|
import cd.casic.ci.process.process.service.stage.StageService;
|
||||||
import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
@ -18,8 +15,6 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user