创建节点逻辑修改
This commit is contained in:
parent
ad63181c33
commit
81b7533da5
@ -5,13 +5,9 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StageCreateReq {
|
||||
//@ApiProperty(name = "stageId",desc="id")
|
||||
// 阶段stageId
|
||||
private String stageId;
|
||||
//@ApiProperty(name="pipelineId",desc="流水线id")
|
||||
private String pipelineId;
|
||||
//@ApiProperty(name="stageSort",desc="阶段顺序")
|
||||
private int stageSort;
|
||||
//@ApiProperty(name = "parentId",desc="主阶段")
|
||||
private String parentId;
|
||||
// 如果需要新增阶段则传这个
|
||||
private Integer stageSort;
|
||||
private TaskCreateReq task;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import lombok.Data;
|
||||
import org.json.JSONObject;
|
||||
@Data
|
||||
public class TaskCreateReq {
|
||||
// 第二级stageId,如果没有值则新建第二级stage
|
||||
private String stageId;
|
||||
private String taskName;
|
||||
private String pipelineId;
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cd.casic.ci.process.process.dataObject.stage;
|
||||
|
||||
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 java.time.LocalDateTime;
|
||||
@ -8,6 +11,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class PipStage {
|
||||
//@ApiProperty(name = "stageId",desc="id")
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String stageId;
|
||||
|
||||
//@ApiProperty(name = "stageName",desc="名称")
|
||||
@ -29,26 +33,12 @@ public class PipStage {
|
||||
private boolean code = false;
|
||||
|
||||
//@ApiProperty(name = "taskValues",desc="阶段任务")
|
||||
@TableField(exist = false)
|
||||
private List<PipTask> taskValues;
|
||||
|
||||
//@ApiProperty(name = "stageList",desc="阶段")
|
||||
@TableField(exist = false)
|
||||
private List<PipStage> 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;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.resp.stage.StageResp;
|
||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||
@ -15,7 +16,7 @@ public interface StageService extends IService<PipStage> {
|
||||
* @param stage 阶段信息
|
||||
* @return 阶段id
|
||||
*/
|
||||
String createStagesOrTask(StageReq stage);
|
||||
String createStagesOrTask(StageCreateReq stage);
|
||||
|
||||
|
||||
/**
|
||||
@ -128,6 +129,6 @@ public interface StageService extends IService<PipStage> {
|
||||
List<StageResp> findAllStagesList(List<String> idList);
|
||||
|
||||
|
||||
void createStagesOrTaskList(@Valid @NotNull List<StageReq> stageList);
|
||||
void createStagesOrTaskList(@Valid @NotNull List<StageCreateReq> stageList);
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cd.casic.ci.process.process.service.stage.impl;
|
||||
|
||||
|
||||
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.task.TaskCreateReq;
|
||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipStageDao;
|
||||
@ -18,6 +20,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@ -38,86 +41,34 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
private PipStageDao stageDao;
|
||||
|
||||
@Override
|
||||
public String createStagesOrTask(StageReq stageReq) {
|
||||
PipStage stage = new PipStage();
|
||||
BeanUtils.copyProperties(stageReq,stage);
|
||||
String stagesId = stage.getStageId();
|
||||
String pipelineId = stage.getPipelineId();
|
||||
|
||||
String taskType = stage.getTaskType();
|
||||
int stageSort = stage.getStageSort();
|
||||
|
||||
stage.setCreateTime(LocalDateTime.now());
|
||||
|
||||
PipTask tasks = new PipTask();
|
||||
tasks.setTaskType(taskType);
|
||||
tasks.setTaskSort(1);
|
||||
// TODO 查询是否为已知worker
|
||||
taskService.taskTypeExist(taskType);
|
||||
//是否为源码
|
||||
if (TASK_TYPE_CODE.equals(taskType)){
|
||||
//判断是否存在代码源(目标)节点
|
||||
findTargetTasks(pipelineId);
|
||||
|
||||
//创建根节点
|
||||
int initStage = initStage(pipelineId,1);
|
||||
stage.setCode(true);
|
||||
stage.setStageSort(1);
|
||||
stage.setPipelineId(pipelineId);
|
||||
stage.setStageName("阶段-"+initStage);
|
||||
String id = createStages(stage);
|
||||
|
||||
//从节点
|
||||
PipStage stages = new PipStage();
|
||||
stages.setStageSort(1);
|
||||
stages.setParentId(id);
|
||||
stages.setStageName("源码");
|
||||
stagesId = createStages(stages);
|
||||
tasks.setStageId(stagesId);
|
||||
|
||||
return taskService.createTasksOrTask(tasks);
|
||||
public String createStagesOrTask(StageCreateReq stageReq) {
|
||||
String firstStageId = stageReq.getStageId();
|
||||
Integer stageSort = stageReq.getStageSort();
|
||||
TaskCreateReq task = stageReq.getTask();
|
||||
String taskName = task.getTaskName();
|
||||
String secondStageId = task.getStageId();
|
||||
JSONObject taskProperties = task.getTaskProperties();
|
||||
String taskType = task.getTaskType();
|
||||
String taskSort = task.getTaskSort();
|
||||
String pipelineId = task.getPipelineId();
|
||||
PipStage firstStage = null;
|
||||
// 判断是否需要新建阶段,如果没有传第一级tageId而传了sort就是需要创建阶段
|
||||
if (StringUtils.isEmpty(firstStageId)) {
|
||||
// 新建stage
|
||||
firstStage = new PipStage();
|
||||
firstStage.setStageName("阶段-"+stageSort);
|
||||
if (stageSort == null) {
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"参数有误");
|
||||
}
|
||||
firstStage.setStageSort(stageSort);
|
||||
firstStage.setCreateTime(LocalDateTime.now());
|
||||
firstStage.setParentId("-1");
|
||||
firstStage.setPipelineId(pipelineId);
|
||||
// firstStage
|
||||
} else {
|
||||
|
||||
//新任务
|
||||
if (!StringUtils.isNotEmpty(stagesId) && stageSort != 0){
|
||||
//创建主节点
|
||||
int initStage = initStage(pipelineId, stageSort);
|
||||
stage.setStageSort(initStage);
|
||||
stage.setPipelineId(pipelineId);
|
||||
stage.setStageName("阶段-" + initStage);
|
||||
String id = createStages(stage);
|
||||
|
||||
//创建从节点
|
||||
PipStage stages = new PipStage();
|
||||
stages.setParentId(id);
|
||||
stages.setStageSort(1);
|
||||
stages.setStageName("并行阶段-"+initStage+"-" + 1);
|
||||
stagesId = createStages(stages);
|
||||
tasks.setStageId(stagesId);
|
||||
return taskService.createTasksOrTask(tasks);
|
||||
}
|
||||
|
||||
//并行任务
|
||||
if (StringUtils.isNotEmpty(stagesId)&& stageSort == 0){
|
||||
List<PipStage> otherStage = findSecondStage(stagesId);
|
||||
PipStage oneStages = findOneStages(stagesId);
|
||||
PipStage stages = new PipStage();
|
||||
stages.setParentId(stagesId);
|
||||
stages.setStageSort(otherStage.size() + 1);
|
||||
stages.setStageName("并行阶段-"+oneStages.getStageSort()+"-"+(otherStage.size()+1));
|
||||
stagesId = createStages(stages);
|
||||
tasks.setStageId(stagesId);
|
||||
return taskService.createTasksOrTask(tasks);
|
||||
}
|
||||
|
||||
//串行任务
|
||||
int sort = stage.getTaskSort();
|
||||
if (sort != 0){
|
||||
tasks.setTaskSort(sort);
|
||||
tasks.setStageId(stagesId);
|
||||
return taskService.createTasksOrTask(tasks);
|
||||
}
|
||||
throw new ServiceException(50001,"未知的操作类型");
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 更新主节点阶段顺序
|
||||
@ -307,11 +258,9 @@ public class StageServiceImpl extends ServiceImpl<PipStageDao, PipStage> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createStagesOrTaskList(List<StageReq> stageList) {
|
||||
public void createStagesOrTaskList(List<StageCreateReq> stageList) {
|
||||
if (!ObjectUtils.isEmpty(stageList)){
|
||||
stageList.forEach(o->{
|
||||
this.createStagesOrTask(o);
|
||||
});
|
||||
stageList.forEach(this::createStagesOrTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.resp.stage.StageResp;
|
||||
import cd.casic.ci.process.process.service.stage.StageService;
|
||||
@ -41,14 +42,14 @@ public class StageController {
|
||||
* @pi.param: model=stage
|
||||
*/
|
||||
@RequestMapping(path="/createStage",method = RequestMethod.POST)
|
||||
public CommonResult<String> createStagesOrTask(@RequestBody @Valid @NotNull StageReq stage){
|
||||
public CommonResult<String> createStagesOrTask(@RequestBody @Valid @NotNull StageCreateReq stage){
|
||||
String taskId = stageService.createStagesOrTask(stage);
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(path="/createStageList",method = RequestMethod.POST)
|
||||
public CommonResult<String> createStagesOrTaskList(@RequestBody @Valid @NotNull List<StageReq> stageList){
|
||||
public CommonResult<String> createStagesOrTaskList(@RequestBody @Valid @NotNull List<StageCreateReq> stageList){
|
||||
stageService.createStagesOrTaskList(stageList);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user