代码提交,(不可运行)
This commit is contained in:
parent
a30646253d
commit
19f9ad32a9
@ -0,0 +1,220 @@
|
||||
package cd.casic.ci.process.constant;
|
||||
|
||||
public class PipelineFinalConstant {
|
||||
|
||||
/**
|
||||
* 项目名称
|
||||
*/
|
||||
public static final String appName = "arbess";
|
||||
|
||||
/**
|
||||
* DEFAULT
|
||||
*/
|
||||
public static final String DEFAULT = "default";
|
||||
|
||||
/**
|
||||
* 流水线文件系统
|
||||
*/
|
||||
public static final String MATFLOW_WORKSPACE = "/source";
|
||||
|
||||
public static final String MATFLOW_LOGS = "/artifact";
|
||||
|
||||
|
||||
/**
|
||||
* 流水线运行状态
|
||||
*/
|
||||
//流水线运行状态
|
||||
public static final String RUN_SUCCESS = "success";
|
||||
|
||||
public static final String RUN_ERROR = "error";
|
||||
|
||||
public static final String RUN_WAIT = "wait";
|
||||
|
||||
public static final String RUN_HALT = "halt";
|
||||
|
||||
public static final String RUN_RUN = "run";
|
||||
|
||||
public static final String RUN_SUSPEND = "suspend";
|
||||
|
||||
|
||||
/**
|
||||
* 系统编码
|
||||
*/
|
||||
//字节编码
|
||||
public static final String UTF_8 = "UTF-8";
|
||||
|
||||
public static final String GBK = "GBK";
|
||||
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
//消息发送类型
|
||||
public static final String MES_PIPELINE_RUN = "PIPELINE_RUN";
|
||||
|
||||
//消息发送方式
|
||||
public static final String MES_SEND_SITE = "site";
|
||||
public static final String MES_SEND_EMAIL = "email";
|
||||
public static final String MES_SEND_DINGDING = "dingding";
|
||||
public static final String MES_SEND_WECHAT = "qywechat";
|
||||
public static final String MES_SEND_SMS = "sms";
|
||||
|
||||
//消息通知方案
|
||||
public static final String MES_UPDATE = "MF_MES_TYPE_UPDATE";
|
||||
public static final String MES_DELETE = "MF_MES_TYPE_DELETE";
|
||||
public static final String MES_CREATE = "MF_MES_TYPE_CREATE";
|
||||
public static final String MES_RUN = "MF_MES_TYPE_RUN";
|
||||
|
||||
|
||||
// 日志类型
|
||||
public static final String LOG_TYPE_CREATE = "MF_LOG_TYPE_CREATE";
|
||||
|
||||
public static final String LOG_TYPE_DELETE = "MF_LOG_TYPE_DELETE";
|
||||
|
||||
public static final String LOG_TYPE_UPDATE = "MF_LOG_TYPE_UPDATE";
|
||||
|
||||
public static final String LOG_TYPE_RUN = "MF_LOG_TYPE_RUN";
|
||||
|
||||
|
||||
public static final String CREATE_LINK = "/pipeline/${pipelineId}/config";
|
||||
|
||||
public static final String DELETE_LINK = "/pipeline/${pipelineId}/delete";
|
||||
|
||||
public static final String UPDATE_LINK = "/pipeline/${pipelineId}/set/info";
|
||||
|
||||
public static final String RUN_LINK = "/pipeline/${pipelineId}/history/${instanceId}";
|
||||
|
||||
|
||||
/**
|
||||
* 构建产物信息
|
||||
*/
|
||||
// 默认制品地址
|
||||
public static final String PROJECT_DEFAULT_ADDRESS = "${PROJECT_DEFAULT_ADDRESS}";
|
||||
|
||||
public static final String DEFAULT_ARTIFACT_ADDRESS = "DEFAULT_ARTIFACT_ADDRESS";
|
||||
|
||||
// 默认制品
|
||||
public static final String DEFAULT_ARTIFACT_NAME = "DEFAULT_ARTIFACT_NAME";
|
||||
|
||||
// Docker制品
|
||||
public static final String DEFAULT_ARTIFACT_DOCKER = "DEFAULT_ARTIFACT_DOCKER";
|
||||
|
||||
// Docker名称
|
||||
public static final String DEFAULT_ARTIFACT_DOCKER_NAME = "DEFAULT_ARTIFACT_DOCKER_NAME";
|
||||
|
||||
|
||||
// 默认源码位置
|
||||
public static final String DEFAULT_CODE_ADDRESS = "${DEFAULT_CODE_ADDRESS}";
|
||||
|
||||
public static final String DEFAULT_TYPE = "string";
|
||||
|
||||
/**
|
||||
* 默认命令
|
||||
*/
|
||||
public static final String TEST_DEFAULT_ORDER = "mvn test";
|
||||
public static final String MAVEN_DEFAULT_ORDER = "mvn clean package";
|
||||
public static final String NODE_DEFAULT_ORDER = "npm install";
|
||||
public static final String DOCKER_DEFAULT_ORDER = "docker image build -t default .";
|
||||
|
||||
/**
|
||||
* 文件信息
|
||||
*/
|
||||
public static final String FILE_TEMP_PREFIX = "temp";
|
||||
public static final String FILE_TYPE_TXT = ".txt";
|
||||
public static final String FILE_TYPE_SH = ".sh";
|
||||
public static final String FILE_TYPE_BAT = ".bat";
|
||||
|
||||
/**
|
||||
* 系统任务类型
|
||||
*/
|
||||
|
||||
// 源码应用类型
|
||||
public static final String TASK_TYPE_CODE = "code";
|
||||
public static final String TASK_CODE_GIT = "git";
|
||||
public static final String TASK_CODE_GITLAB = "gitlab";
|
||||
public static final String TASK_CODE_GITHUB = "github";
|
||||
public static final String TASK_CODE_GITEE = "gitee";
|
||||
public static final String TASK_CODE_SVN = "svn";
|
||||
public static final String TASK_CODE_XCODE = "gitpuk";
|
||||
public static final String TASK_CODE_DEFAULT_BRANCH = "master";
|
||||
|
||||
|
||||
// 构建应用类型
|
||||
public static final String TASK_TYPE_BUILD = "build";
|
||||
public static final String TASK_BUILD_MAVEN = "maven";
|
||||
public static final String TASK_BUILD_NODEJS = "nodejs";
|
||||
|
||||
public static final String TASK_BUILD_DOCKER = "build_docker";
|
||||
|
||||
|
||||
// 测试应用类型
|
||||
public static final String TASK_TYPE_TEST = "test";
|
||||
public static final String TASK_TEST_MAVENTEST = "maventest";
|
||||
public static final String TASK_TEST_TESTON = "testhubo";
|
||||
|
||||
|
||||
// 部署应用类型
|
||||
public static final String TASK_TYPE_DEPLOY = "deploy";
|
||||
public static final String TASK_DEPLOY_LINUX = "liunx";
|
||||
public static final String TASK_DEPLOY_DOCKER = "docker";
|
||||
public static final String TASK_DEPLOY_K8S = "k8s";
|
||||
|
||||
|
||||
// 推送制品应用类型
|
||||
public static final String TASK_TYPE_ARTIFACT = "artifact";
|
||||
public static final String TASK_ARTIFACT_MAVEN = "artifact_maven";
|
||||
public static final String TASK_ARTIFACT_NODEJS = "artifact_nodejs";
|
||||
public static final String TASK_ARTIFACT_DOCKER = "artifact_docker";
|
||||
|
||||
|
||||
// 制品拉取应用类型
|
||||
public static final String TASK_TYPE_PULL = "pull";
|
||||
public static final String TASK_PULL_MAVEN = "pull_maven";
|
||||
public static final String TASK_PULL_NODEJS = "pull_nodejs";
|
||||
public static final String TASK_PULL_DOCKER = "pull_docker";
|
||||
|
||||
// 制品推送应用方式
|
||||
public static final String TASK_ARTIFACT_XPACK = "hadess";
|
||||
public static final String TASK_ARTIFACT_SSH = "ssh";
|
||||
public static final String TASK_ARTIFACT_NEXUS = "nexus";
|
||||
|
||||
// 代码扫描应用类型
|
||||
public static final String TASK_TYPE_CODESCAN = "codescan";
|
||||
public static final String TASK_CODESCAN_SONAR = "sonar";
|
||||
public static final String TASK_CODESCAN_SPOTBUGS = "spotbugs";
|
||||
|
||||
// 消息应用类型
|
||||
public static final String TASK_TYPE_MESSAGE = "message";
|
||||
public static final String TASK_MESSAGE_MSG = "message";
|
||||
|
||||
// 脚本应用类型
|
||||
public static final String TASK_TYPE_SCRIPT = "script";
|
||||
public static final String TASK_SCRIPT_SHELL = "shell";
|
||||
public static final String TASK_SCRIPT_BAT = "bat";
|
||||
|
||||
|
||||
//触发器
|
||||
public static final String TRIGGER_SCHEDULED = "scheduled";
|
||||
|
||||
|
||||
public static final String SIZE_TYPE_MB = "MB";
|
||||
|
||||
public static final int DEFAULT_SIZE = 2;
|
||||
|
||||
|
||||
public static final String SIZE_TYPE_GB = "GB";
|
||||
|
||||
|
||||
public static final Integer DEFAULT_CLEAN_CACHE_DAY = 7;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package cd.casic.ci.process.process.dal.pipeline;
|
||||
|
||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||
|
||||
public interface PipStageDao extends BaseMapperX<PipStage> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package cd.casic.ci.process.process.dal.pipeline;
|
||||
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||
|
||||
public interface PipTaskDao extends BaseMapperX<PipTask> {
|
||||
}
|
@ -2,6 +2,7 @@ package cd.casic.ci.process.process.service.stage;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -65,14 +66,14 @@ public interface StageService {
|
||||
* @param pipelineId 流水线id
|
||||
* @return 主分支
|
||||
*/
|
||||
List<StageResp> findAllMainStage(String pipelineId);
|
||||
List<PipStage> findAllMainStage(String pipelineId);
|
||||
|
||||
/**
|
||||
* 根据根节点查询从节点
|
||||
* @param stagesId 根节点id
|
||||
* @return 从节点列表
|
||||
*/
|
||||
List<StageResp> findOtherStage(String stagesId);
|
||||
List<PipStage> findOtherStage(String stagesId);
|
||||
|
||||
/**
|
||||
* 更新阶段任务
|
||||
@ -93,13 +94,13 @@ public interface StageService {
|
||||
* @param stage 阶段信息
|
||||
* @return 阶段id
|
||||
*/
|
||||
String createStages(StageReq stage);
|
||||
String createStages(PipStage stage);
|
||||
|
||||
/**
|
||||
* 更新阶段
|
||||
* @param stage 阶段信息
|
||||
*/
|
||||
void updateStages(StageReq stage);
|
||||
void updateStages(PipStage stage);
|
||||
|
||||
/**
|
||||
* 删除阶段
|
||||
|
@ -5,12 +5,15 @@ import cd.casic.ci.common.pipeline.container.Stage;
|
||||
import cd.casic.ci.common.pipeline.req.stage.StageReq;
|
||||
import cd.casic.ci.common.pipeline.resp.stage.StageResp;
|
||||
import cd.casic.ci.common.pipeline.utils.PipelineDateUtil;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipStageDao;
|
||||
import cd.casic.ci.process.process.dataObject.stage.PipStage;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import cd.casic.ci.process.process.service.stage.StageService;
|
||||
import cd.casic.ci.process.process.service.task.TaskService;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.util.object.BeanUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.task.VirtualThreadTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -20,9 +23,13 @@ import java.util.List;
|
||||
public class StageServiceImpl implements StageService {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
@Resource
|
||||
private PipStageDao stageDao;
|
||||
|
||||
@Override
|
||||
public String createStagesOrTask(StageReq stage) {
|
||||
public String createStagesOrTask(StageReq stageReq) {
|
||||
PipStage stage = new PipStage();
|
||||
BeanUtils.copyProperties(stageReq,stage);
|
||||
String stagesId = stage.getStageId();
|
||||
String pipelineId = stage.getPipelineId();
|
||||
|
||||
@ -36,73 +43,92 @@ public class StageServiceImpl implements StageService {
|
||||
tasks.setTaskSort(1);
|
||||
// TODO 查询是否为已知worker
|
||||
taskService.taskTypeExist(taskType);
|
||||
return null;
|
||||
// //是否为源码
|
||||
// if (taskType.equals(PipelineFinal.TASK_TYPE_CODE)){
|
||||
// //判断是否存在代码源(目标)节点
|
||||
// findTargetTasks(pipelineId);
|
||||
//
|
||||
// //创建根节点
|
||||
// int initStage = initStage(pipelineId,1);
|
||||
// stage.setCode(true);
|
||||
// stage.setStageSort(1);
|
||||
// stage.setPipelineId(pipelineId);
|
||||
// stage.setStageName("阶段-"+initStage);
|
||||
// String id = createStages(stage);
|
||||
//
|
||||
// //从节点
|
||||
// Stage stages = new Stage();
|
||||
// stages.setStageSort(1);
|
||||
// stages.setParentId(id);
|
||||
// stages.setStageName("源码");
|
||||
// stagesId = createStages(stages);
|
||||
// tasks.setStageId(stagesId);
|
||||
//
|
||||
// return tasksService.createTasksOrTask(tasks);
|
||||
// }
|
||||
//
|
||||
// //新任务
|
||||
// if (!PipelineUtil.isNoNull(stagesId) && stageSort != 0){
|
||||
// //创建主节点
|
||||
// int initStage = initStage(pipelineId, stageSort);
|
||||
// stage.setStageSort(initStage);
|
||||
// stage.setPipelineId(pipelineId);
|
||||
// stage.setStageName("阶段-" + initStage);
|
||||
// String id = createStages(stage);
|
||||
//
|
||||
// //创建从节点
|
||||
// Stage stages = new Stage();
|
||||
// stages.setParentId(id);
|
||||
// stages.setStageSort(1);
|
||||
// stages.setStageName("并行阶段-"+initStage+"-" + 1);
|
||||
// stagesId = createStages(stages);
|
||||
// tasks.setStageId(stagesId);
|
||||
// return tasksService.createTasksOrTask(tasks);
|
||||
// }
|
||||
//
|
||||
// //并行任务
|
||||
// if (PipelineUtil.isNoNull(stagesId) && stageSort == 0){
|
||||
// List<Stage> otherStage = findOtherStage(stagesId);
|
||||
// Stage oneStages = findOneStages(stagesId);
|
||||
// Stage stages = new Stage();
|
||||
// stages.setParentId(stagesId);
|
||||
// stages.setStageSort(otherStage.size() + 1);
|
||||
// stages.setStageName("并行阶段-"+oneStages.getStageSort()+"-"+(otherStage.size()+1));
|
||||
// stagesId = createStages(stages);
|
||||
// tasks.setStageId(stagesId);
|
||||
// return tasksService.createTasksOrTask(tasks);
|
||||
// }
|
||||
//
|
||||
// //串行任务
|
||||
// int sort = stage.getTaskSort();
|
||||
// if (sort != 0){
|
||||
// tasks.setTaskSort(sort);
|
||||
// tasks.setStageId(stagesId);
|
||||
// return tasksService.createTasksOrTask(tasks);
|
||||
// }
|
||||
// throw new ApplicationException(50001,"未知的操作类型");
|
||||
}
|
||||
//是否为源码
|
||||
if (taskType.equals(PipelineFinal.TASK_TYPE_CODE)){
|
||||
//判断是否存在代码源(目标)节点
|
||||
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);
|
||||
}
|
||||
|
||||
//新任务
|
||||
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 = findOtherStage(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 tasksService.createTasksOrTask(tasks);
|
||||
}
|
||||
throw new ApplicationException(50001,"未知的操作类型");
|
||||
}
|
||||
/**
|
||||
* 更新主节点阶段顺序
|
||||
* @param pipelineId 流水线id
|
||||
* @param taskSort 顺序
|
||||
* @return 顺序
|
||||
*/
|
||||
private Integer initStage(String pipelineId,int taskSort){
|
||||
List<PipStage> allMainStage = findAllMainStage(pipelineId);
|
||||
if (allMainStage.isEmpty()){
|
||||
return 1;
|
||||
}
|
||||
for (PipStage stages : allMainStage) {
|
||||
int stage = stages.getStageSort();
|
||||
if (stage < taskSort){
|
||||
continue;
|
||||
}
|
||||
stages.setStageSort(stage+1);
|
||||
updateStages(stages);
|
||||
}
|
||||
return taskSort;
|
||||
}
|
||||
@Override
|
||||
public void createStageTemplate(String pipelineId, String[] template) {
|
||||
|
||||
@ -139,12 +165,12 @@ public class StageServiceImpl implements StageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StageResp> findAllMainStage(String pipelineId) {
|
||||
public List<PipStage> findAllMainStage(String pipelineId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StageResp> findOtherStage(String stagesId) {
|
||||
public List<PipStage> findOtherStage(String stagesId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -159,13 +185,13 @@ public class StageServiceImpl implements StageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createStages(StageReq stage) {
|
||||
public String createStages(PipStage stage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStages(StageReq stage) {
|
||||
|
||||
public void updateStages(PipStage stage) {
|
||||
stageDao.updateById(stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,13 @@
|
||||
package cd.casic.ci.process.process.service.task;
|
||||
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public interface TaskService {
|
||||
/**
|
||||
* 查询taskType是否存在(原项目的各种worker)
|
||||
* */
|
||||
public void taskTypeExist(String taskType);
|
||||
public String createTasksOrTask(PipTask tasks);
|
||||
}
|
||||
|
@ -1,19 +1,34 @@
|
||||
package cd.casic.ci.process.process.service.task.impl;
|
||||
|
||||
import cd.casic.ci.common.pipeline.annotation.Plugin;
|
||||
import cd.casic.ci.common.pipeline.constant.PipelineDateUtilConstant;
|
||||
import cd.casic.ci.common.pipeline.utils.PipelineDateUtil;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipTaskDao;
|
||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||
import cd.casic.ci.process.process.service.task.TaskService;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.util.util.WebFrameworkUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static cd.casic.ci.process.constant.PipelineFinalConstant.TASK_TYPE_CODE;
|
||||
|
||||
@Service
|
||||
public class TaskServiceImpl implements TaskService {
|
||||
private static final String basePackage = "cd.casic.ci.process.process.service";
|
||||
private Set<BeanDefinition> candidates;
|
||||
@Resource
|
||||
private PipTaskDao taskDao;
|
||||
|
||||
public TaskServiceImpl() {
|
||||
System.out.println("");
|
||||
@ -30,4 +45,137 @@ public class TaskServiceImpl implements TaskService {
|
||||
public void taskTypeExist(String taskType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTasksOrTask(PipTask tasks) {
|
||||
|
||||
int sort = 0;
|
||||
int taskSort = tasks.getTaskSort();
|
||||
String taskType = tasks.getTaskType();
|
||||
|
||||
//判断多任务是否存在代码源
|
||||
boolean b = TASK_TYPE_CODE.equals(taskType);
|
||||
if (tasks.getPipelineId() != null && (b) ){
|
||||
findCode(tasks.getPipelineId());
|
||||
}
|
||||
|
||||
//流水线任务
|
||||
String pipelineId = tasks.getPipelineId();
|
||||
if (pipelineId != null) {
|
||||
sort = initSort(tasks.getPipelineId(), taskSort, taskType,1);
|
||||
}
|
||||
|
||||
//阶段任务
|
||||
String stageId = tasks.getStageId();
|
||||
if (stageId != null){
|
||||
sort = initSort(stageId, taskSort, taskType,2);
|
||||
}
|
||||
|
||||
//后置任务
|
||||
String postprocessId = tasks.getPostprocessId();
|
||||
if (postprocessId != null){
|
||||
sort = initSort(postprocessId, taskSort, taskType,3);
|
||||
}
|
||||
|
||||
tasks.setTaskSort(sort);
|
||||
// 初始化名称
|
||||
if (Objects.isNull(tasks.getTaskName())){
|
||||
// String taskName = initDifferentTaskName(taskType);
|
||||
String taskName = "未命名";
|
||||
tasks.setTaskName(taskName);
|
||||
}
|
||||
|
||||
tasks.setCreateTime(PipelineDateUtil.nowDateString(PipelineDateUtilConstant.yyyy_MM_dd_HH_mm_ss));
|
||||
|
||||
String tasksId = createTasks(tasks);
|
||||
//创建任务
|
||||
createDifferentTask(tasksId,taskType,tasks.getValues());
|
||||
return tasksId;
|
||||
}
|
||||
void createDifferentTask(String taskId,String taskType,Object values){
|
||||
// TODO
|
||||
}
|
||||
/**
|
||||
* 查找目标节点是否存在
|
||||
* */
|
||||
private void findCode(String pipelineId){
|
||||
List<PipTask> tasks = finAllPipelineTask(pipelineId);
|
||||
if (tasks == null){
|
||||
return;
|
||||
}
|
||||
for (PipTask task : tasks) {
|
||||
String taskType = task.getTaskType();
|
||||
if (TASK_TYPE_CODE.equals(taskType)){
|
||||
throw new ServiceException(50001,"代码源已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<PipTask> finAllPipelineTask(String pipelineId) {
|
||||
LambdaQueryWrapper<PipTask> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PipTask::getPipelineId,pipelineId);
|
||||
return taskDao.selectList(wrapper);
|
||||
}
|
||||
/**
|
||||
* 初始化配置顺序
|
||||
* @param id id
|
||||
* @param taskSort 插入顺序
|
||||
* @param taskType 任务类型
|
||||
* @param type 1.流水线id 2.阶段id
|
||||
* @return 顺序
|
||||
*/
|
||||
private Integer initSort(String id, int taskSort,String taskType,int type){
|
||||
List<PipTask> list = new ArrayList<>();
|
||||
if (type == 1){
|
||||
list = finAllPipelineTask(id);
|
||||
}
|
||||
if (type == 2){
|
||||
list = finAllStageTask(id);
|
||||
}
|
||||
if (type == 3){
|
||||
PipTask postTask = findOnePostTask(id);
|
||||
if (postTask!= null){
|
||||
list.add(postTask);
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean b = TASK_TYPE_CODE.equals(taskType);
|
||||
|
||||
//插入的为代码源
|
||||
if (b){
|
||||
for (PipTask tasks : list) {
|
||||
tasks.setTaskSort(tasks.getTaskSort()+1);
|
||||
updateTasks(tasks);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//更新顺序
|
||||
for (PipTask tasks : list) {
|
||||
if (tasks.getTaskSort() < taskSort ){
|
||||
continue;
|
||||
}
|
||||
tasks.setTaskSort(tasks.getTaskSort()+1);
|
||||
updateTasks(tasks);
|
||||
}
|
||||
return taskSort;
|
||||
|
||||
}
|
||||
|
||||
private void updateTasks(PipTask tasks){
|
||||
taskDao.updateById(tasks);
|
||||
}
|
||||
/**
|
||||
* 创建任务
|
||||
* @param tasks 任务模型
|
||||
* @return 任务id
|
||||
*/
|
||||
private String createTasks(PipTask tasks){
|
||||
taskDao.insert(tasks);
|
||||
return tasks.getTaskId();
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,7 @@ public class StageController {
|
||||
*/
|
||||
@RequestMapping(path="/createStage",method = RequestMethod.POST)
|
||||
public CommonResult<String> createStagesOrTask(@RequestBody @Valid @NotNull StageReq stage){
|
||||
// String taskId = stageService.createStagesOrTask(stage);
|
||||
String taskId = "";
|
||||
String taskId = stageService.createStagesOrTask(stage);
|
||||
return CommonResult.success(taskId);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user