service
迁移
This commit is contained in:
parent
5d283c9e66
commit
c146cd3678
@ -78,6 +78,13 @@ public class Pipeline {
|
|||||||
|
|
||||||
//是否可以执行
|
//是否可以执行
|
||||||
private Boolean isExec;
|
private Boolean isExec;
|
||||||
|
/**
|
||||||
|
* @pi.name:color
|
||||||
|
* @pi.dataType:Integer
|
||||||
|
* @pi.desc:颜色 1~5随机生成
|
||||||
|
* @pi.value:2
|
||||||
|
*/
|
||||||
|
private int color;
|
||||||
|
|
||||||
public Pipeline(String pipelineId) {
|
public Pipeline(String pipelineId) {
|
||||||
this.id = pipelineId;
|
this.id = pipelineId;
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package cd.casic.module.process.message.message;
|
||||||
|
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import cd.casic.module.process.message.message.model.MessageDmNotice;
|
||||||
|
import cd.casic.module.process.message.message.model.MessageDmNoticeQuery;
|
||||||
|
import cd.casic.module.process.message.message.model.MessageNoticePatch;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MessageDmNoticeService {
|
||||||
|
void initMessageDmNotice(MessageNoticePatch var1);
|
||||||
|
|
||||||
|
String createMessageDmNotice(MessageDmNotice var1);
|
||||||
|
|
||||||
|
void addMessageDmNotice(MessageDmNotice var1);
|
||||||
|
|
||||||
|
void updateMessageDmNotice(MessageDmNotice var1);
|
||||||
|
|
||||||
|
void deleteMessageDmNotice(String var1);
|
||||||
|
|
||||||
|
MessageDmNotice findOneMessageDmNotice(String var1);
|
||||||
|
|
||||||
|
List<MessageDmNotice> findAllMessageDmNotice();
|
||||||
|
|
||||||
|
void updateMessageDmNoticeState(String var1);
|
||||||
|
|
||||||
|
List<MessageDmNotice> findMessageDmNoticeList(List<String> var1);
|
||||||
|
|
||||||
|
List<MessageDmNotice> findMessageDmNoticeList(MessageDmNoticeQuery var1);
|
||||||
|
|
||||||
|
PageResult<MessageDmNotice> findMessageDmNoticePage(MessageDmNoticeQuery var1);
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package cd.casic.module.process.message.message.model;
|
||||||
|
|
||||||
|
import cd.casic.module.process.message.model.MessageNotice;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MessageDmNotice {
|
||||||
|
private String id;
|
||||||
|
@NotNull
|
||||||
|
// @Mappings({@Mapping(
|
||||||
|
// source = "messageNotice.id",
|
||||||
|
// target = "messageNoticeId"
|
||||||
|
// )})
|
||||||
|
// @JoinQuery(
|
||||||
|
// key = "id"
|
||||||
|
// )
|
||||||
|
private MessageNotice messageNotice;
|
||||||
|
private String domainId;
|
||||||
|
private String sourceNoticeId;
|
||||||
|
private String messageSendTypeId;
|
||||||
|
private Boolean open;
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cd.casic.module.process.message.message.model;
|
||||||
|
|
||||||
|
import cd.casic.ci.commons.bean.order.Order;
|
||||||
|
import cd.casic.ci.commons.bean.order.OrderBuilders;
|
||||||
|
import cd.casic.framework.commons.pojo.PageParam;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
@Data
|
||||||
|
public class MessageDmNoticeQuery {
|
||||||
|
private String messageNoticeId;
|
||||||
|
private String domainId;
|
||||||
|
private String sourceNoticeId;
|
||||||
|
private List<Order> orderParams = OrderBuilders.instance().desc("id").get();
|
||||||
|
private PageParam pageParam = new PageParam();
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cd.casic.module.process.message.message.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
@Data
|
||||||
|
public class MessageNoticePatch {
|
||||||
|
private String messageNoticeId;
|
||||||
|
private String domainId;
|
||||||
|
private List<String> userGroupList = new ArrayList();
|
||||||
|
private List<String> orgaList = new ArrayList();
|
||||||
|
private List<String> userList = new ArrayList();
|
||||||
|
private List<String> roleList = new ArrayList();
|
||||||
|
private List<String> vRoleList = new ArrayList();
|
||||||
|
}
|
@ -0,0 +1,633 @@
|
|||||||
|
package cd.casic.module.process.pipeline.definition.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.commons.bean.process.definition.*;
|
||||||
|
import cd.casic.ci.commons.bean.process.instance.PipelineInstance;
|
||||||
|
import cd.casic.ci.commons.bean.utils.PipelineFileUtil;
|
||||||
|
import cd.casic.ci.commons.bean.utils.PipelineUtil;
|
||||||
|
import cd.casic.framework.commons.exception.ErrorCode;
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import cd.casic.module.process.engine.task.TasksCloneService;
|
||||||
|
import cd.casic.module.process.engine.task.TasksService;
|
||||||
|
import cd.casic.module.process.home.service.PipelineHomeService;
|
||||||
|
import cd.casic.module.process.message.message.MessageDmNoticeService;
|
||||||
|
import cd.casic.module.process.message.message.model.MessageNoticePatch;
|
||||||
|
import cd.casic.module.process.pipeline.definition.PipelineFollowService;
|
||||||
|
import cd.casic.module.process.pipeline.definition.PipelineOpenService;
|
||||||
|
import cd.casic.module.process.pipeline.definition.PipelineService;
|
||||||
|
import cd.casic.module.process.pipeline.definition.entity.PipelineEntity;
|
||||||
|
|
||||||
|
import cd.casic.module.process.process.definition.VariableService;
|
||||||
|
import cd.casic.module.process.process.definition.dao.PipelineDao;
|
||||||
|
import cd.casic.module.process.process.instance.PipelineInstanceService;
|
||||||
|
import cd.casic.module.process.process.stage.StageService;
|
||||||
|
import cd.casic.module.process.support.authority.service.PipelineAuthorityService;
|
||||||
|
import cd.casic.module.process.support.condition.service.ConditionService;
|
||||||
|
import cd.casic.module.process.support.postprocess.service.PostprocessService;
|
||||||
|
import cd.casic.module.process.support.trigger.service.TriggerService;
|
||||||
|
import cd.casic.module.process.support.util.PipelineUtilService;
|
||||||
|
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||||
|
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||||
|
import cd.casic.module.process.toolkit.join.JoinTemplate;
|
||||||
|
import cd.casic.module.process.user.user.User;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.security.auth.login.LoginContext;
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class PipelineServiceImpl implements PipelineService {
|
||||||
|
@Resource
|
||||||
|
JoinTemplate joinTemplate;
|
||||||
|
|
||||||
|
// @Resource
|
||||||
|
// UserService userService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineDao pipelineDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineInstanceService instanceService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineHomeService homeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineAuthorityService authorityService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
TasksService tasksService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
TasksCloneService tasksCloneService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
StageService stageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineFollowService followService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineUtilService utilService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PipelineOpenService openService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PostprocessService postprocessService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
TriggerService triggerService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
VariableService variableService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ConditionService conditionService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
MessageDmNoticeService messageDmNoticeService;
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PipelineServiceImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createPipeline(Pipeline pipeline) {
|
||||||
|
//随机颜色
|
||||||
|
Random random ;
|
||||||
|
try {
|
||||||
|
random = SecureRandom.getInstanceStrong();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new ServiceException();
|
||||||
|
}
|
||||||
|
pipeline.setColor((random.nextInt(5) + 1));
|
||||||
|
pipeline.setCreateTime(PipelineUtil.date(1));
|
||||||
|
// if (Objects.isNull(pipeline.getUser()) || StringUtils.isEmpty(pipeline.getUser().getId())){
|
||||||
|
// String loginId = LoginContext.getLoginId();
|
||||||
|
// pipeline.setUser(new User(loginId));
|
||||||
|
// }
|
||||||
|
|
||||||
|
//创建流水线
|
||||||
|
PipelineEntity pipelineEntity = BeanMapper.map(pipeline, PipelineEntity.class);
|
||||||
|
pipelineEntity.setState(1);
|
||||||
|
String pipelineId = pipelineDao.createPipeline(pipelineEntity);
|
||||||
|
joinTemplate.joinQuery(pipeline);
|
||||||
|
pipeline.setId(pipelineId);
|
||||||
|
|
||||||
|
//创建对应流水线模板
|
||||||
|
String template = pipeline.getTemplate();
|
||||||
|
String[] ints;
|
||||||
|
switch (template) {
|
||||||
|
case "2131" -> ints =
|
||||||
|
new String[]{PipelineFinal.TASK_CODE_GIT, PipelineFinal.TASK_BUILD_MAVEN, PipelineFinal.TASK_DEPLOY_LINUX};
|
||||||
|
case "112131" -> ints =
|
||||||
|
new String[]{PipelineFinal.TASK_CODE_GIT, PipelineFinal.TASK_TEST_MAVENTEST, PipelineFinal.TASK_BUILD_MAVEN, PipelineFinal.TASK_DEPLOY_LINUX};
|
||||||
|
case "2231" -> ints =
|
||||||
|
new String[]{PipelineFinal.TASK_CODE_GIT, PipelineFinal.TASK_TEST_MAVENTEST, PipelineFinal.TASK_DEPLOY_LINUX};
|
||||||
|
default -> ints = new String[]{PipelineFinal.TASK_CODE_GIT};
|
||||||
|
}
|
||||||
|
if (pipeline.getType() == 1) {
|
||||||
|
tasksService.createTaskTemplate(pipelineId , ints);
|
||||||
|
}
|
||||||
|
if (pipeline.getType() == 2) {
|
||||||
|
stageService.createStageTemplate(pipelineId , ints);
|
||||||
|
}
|
||||||
|
|
||||||
|
// String userId = pipeline.getUser().getId();
|
||||||
|
// //流水线关联角色,用户信息
|
||||||
|
// authorityService.createDmUser(pipelineId,userId,pipeline.getUserList());
|
||||||
|
|
||||||
|
// 消息通知方案
|
||||||
|
MessageNoticePatch messageNoticePatch = new MessageNoticePatch();
|
||||||
|
messageNoticePatch.setDomainId(pipelineId);
|
||||||
|
// messageNoticePatch.setUserList(List.of(userId));
|
||||||
|
messageDmNoticeService.initMessageDmNotice(messageNoticePatch);
|
||||||
|
|
||||||
|
//动态与消息
|
||||||
|
Map<String,Object> map =homeService.initMap(pipeline);
|
||||||
|
map.put("link",PipelineFinal.CREATE_LINK);
|
||||||
|
map.put("pipelineName",pipeline.getName());
|
||||||
|
homeService.log(PipelineFinal.LOG_TYPE_CREATE, map);
|
||||||
|
homeService.settingMessage(PipelineFinal.MES_CREATE, map);
|
||||||
|
|
||||||
|
return pipelineId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deletePipeline(String pipelineId) {
|
||||||
|
Pipeline pipeline = findPipelineById(pipelineId);
|
||||||
|
// joinTemplate.joinQuery(pipeline);
|
||||||
|
//删除关联信息
|
||||||
|
pipelineDao.deletePipeline(pipelineId); //删除流水线
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
authorityService.deleteDmUser(pipelineId); //删除关联用户
|
||||||
|
logger.warn("删除流水线历史信息....");
|
||||||
|
deleteOther(pipelineId); //删除历史,日志,收藏,最近打开
|
||||||
|
|
||||||
|
//删除配置信息
|
||||||
|
logger.warn("删除流水线关联配置信息....");
|
||||||
|
if (pipeline.getType() == 1){
|
||||||
|
tasksService.deleteAllTasksOrTask(pipelineId,1);
|
||||||
|
}
|
||||||
|
if (pipeline.getType() == 2){
|
||||||
|
stageService.deleteAllStagesOrTask(pipelineId);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
//动态与消息
|
||||||
|
Map<String,Object> map = homeService.initMap(pipeline);
|
||||||
|
homeService.log(PipelineFinal.LOG_TYPE_DELETE, map);
|
||||||
|
homeService.settingMessage(PipelineFinal.MES_DELETE, map);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePipeline(Pipeline pipeline) {
|
||||||
|
//更新名称
|
||||||
|
Pipeline flow = findPipelineById(pipeline.getId());
|
||||||
|
joinTemplate.joinQuery(flow);
|
||||||
|
//判断名称是否改变
|
||||||
|
if (!pipeline.getName().equals(flow.getName())){
|
||||||
|
Map<String,Object> map = homeService.initMap(pipeline);
|
||||||
|
map.put("link",PipelineFinal.UPDATE_LINK);
|
||||||
|
map.put("message", flow.getName() +"更改为:"+pipeline.getName());
|
||||||
|
map.put("lastName", flow.getName());
|
||||||
|
flow.setName(pipeline.getName());
|
||||||
|
map.put("dmMessage",true);
|
||||||
|
homeService.log(PipelineFinal.LOG_TYPE_UPDATE, map);
|
||||||
|
homeService.settingMessage(PipelineFinal.MES_UPDATE, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断权限是否改变
|
||||||
|
int pipelinePower = pipeline.getPower();
|
||||||
|
if (pipelinePower != flow.getPower() && pipelinePower != 0){
|
||||||
|
flow.setPower(pipelinePower);
|
||||||
|
}
|
||||||
|
if (pipeline.getState() !=0 ){
|
||||||
|
flow.setState(pipeline.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
flow.setEnv(pipeline.getEnv());
|
||||||
|
flow.setGroup(pipeline.getGroup());
|
||||||
|
|
||||||
|
PipelineEntity pipelineEntity = BeanMapper.map(flow, PipelineEntity.class);
|
||||||
|
pipelineDao.updatePipeline(pipelineEntity);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询
|
||||||
|
@Override
|
||||||
|
public Pipeline findPipelineById(String pipelineId) {
|
||||||
|
PipelineEntity pipelineEntity = pipelineDao.findPipelineById(pipelineId);
|
||||||
|
Pipeline pipeline = BeanMapper.map(pipelineEntity, Pipeline.class);
|
||||||
|
joinTemplate.joinQuery(pipeline);
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pipeline findPipelineByIdNoQuery(String pipelineId) {
|
||||||
|
PipelineEntity pipelineEntity = pipelineDao.findPipelineById(pipelineId);
|
||||||
|
return BeanMapper.map(pipelineEntity, Pipeline.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pipeline findOnePipeline(String pipelineId){
|
||||||
|
return findPipelineById(pipelineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pipeline findPipelineNoQuery(String pipelineId){
|
||||||
|
PipelineEntity pipelineEntity = pipelineDao.findPipelineById(pipelineId);
|
||||||
|
return BeanMapper.map(pipelineEntity, Pipeline.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询所有
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findAllPipeline() {
|
||||||
|
List<Pipeline> list = BeanMapper.mapList(pipelineDao.findAllPipeline(), Pipeline.class);
|
||||||
|
joinTemplate.joinQuery(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findAllPipelineNoQuery() {
|
||||||
|
List<Pipeline> list = BeanMapper.mapList(pipelineDao.findAllPipeline(), Pipeline.class);
|
||||||
|
joinTemplate.joinQuery(list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findAllPipelineList(List<String> idList) {
|
||||||
|
List<PipelineEntity> pipelineEntityList = pipelineDao.findAllPipelineList(idList);
|
||||||
|
return BeanMapper.mapList(pipelineEntityList, Pipeline.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findUserPipeline(PipelineQuery query){
|
||||||
|
String[] builder = authorityService.findUserPipelineIdString(query.getUserId());
|
||||||
|
query.setIdString(builder);
|
||||||
|
List<Pipeline> userPipeline = findPipelineList(query);
|
||||||
|
if (Objects.isNull(userPipeline)){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return userPipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<Pipeline> findUserPipelinePage(PipelineQuery query){
|
||||||
|
String userId = query.getUserId();
|
||||||
|
|
||||||
|
String[] builders = authorityService.findUserPipelineIdString(userId);
|
||||||
|
query.setIdString(builders);
|
||||||
|
// 用户收藏的流水线
|
||||||
|
Integer follow = query.getPipelineFollow();
|
||||||
|
if (!Objects.isNull(follow) && follow == 1){
|
||||||
|
PageResult<PipelineEntity> pipelineListQuery = pipelineDao.findPipelineListQuery(query);
|
||||||
|
List<PipelineEntity> dataList = pipelineListQuery.getList();
|
||||||
|
if (dataList.isEmpty()){
|
||||||
|
return PageResult.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Pipeline> pipelineList = BeanMapper.mapList(dataList, Pipeline.class);
|
||||||
|
// TODO 流水线关联上用户
|
||||||
|
// List<Pipeline> list = new ArrayList<>();
|
||||||
|
return new PageResult<Pipeline>(pipelineList, pipelineListQuery.getTotal());
|
||||||
|
// List<String> userIdList = new ArrayList<>();
|
||||||
|
// for (Pipeline pipeline : pipelineList) {
|
||||||
|
//// userIdList.add(pipeline.getUser().getId());
|
||||||
|
// pipeline.setCollect(1);
|
||||||
|
// Pipeline pipelineMessage = findPipelineExecMessage(pipeline);
|
||||||
|
// list.add(pipelineMessage);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 查询用户信息
|
||||||
|
// Map<String, User> pipelineUser = findPipelineUser(userIdList);
|
||||||
|
//
|
||||||
|
// List<Pipeline> pipelines = list.stream()
|
||||||
|
// .peek(pipeline -> pipeline.setUser(pipelineUser.get(pipeline.getUser().getId())))
|
||||||
|
// .toList();
|
||||||
|
|
||||||
|
// return PaginationBuilder.build(pipelineListQuery,pipelines);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询用户流水线
|
||||||
|
PipelineFollowQuery followQuery = new PipelineFollowQuery();
|
||||||
|
followQuery.setUserId(userId);
|
||||||
|
List<PipelineFollow> followPipeline = followService.findFollowQueryList(followQuery);
|
||||||
|
Map<String,String> map = new HashMap<>();
|
||||||
|
for (PipelineFollow pipelineFollow : followPipeline) {
|
||||||
|
Pipeline pipeline = pipelineFollow.getPipeline();
|
||||||
|
if (Objects.isNull(pipeline)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
map.put(pipeline.getId(),pipeline.getId());
|
||||||
|
}
|
||||||
|
PageResult<PipelineEntity> pipelinePage = pipelineDao.findPipelinePage(query);
|
||||||
|
List<PipelineEntity> dataList = pipelinePage.getList();
|
||||||
|
List<Pipeline> pipelineList = BeanMapper.mapList(dataList, Pipeline.class);
|
||||||
|
if (pipelineList.isEmpty()){
|
||||||
|
// return PaginationBuilder.build(pipelinePage, Collections.emptyList());
|
||||||
|
return PageResult.empty();
|
||||||
|
}
|
||||||
|
return new PageResult<>(pipelineList,Long.valueOf(String.valueOf(followPipeline.size())) );
|
||||||
|
// TODO 关联上用户信息
|
||||||
|
// List<Pipeline> list = new ArrayList<>();
|
||||||
|
// List<String> userIdList = new ArrayList<>();
|
||||||
|
// for (Pipeline pipeline : pipelineList) {
|
||||||
|
// // 判断是否收藏
|
||||||
|
// String s = map.get(pipeline.getId());
|
||||||
|
// pipeline.setCollect(0);
|
||||||
|
// if (!Objects.isNull(s)){
|
||||||
|
// pipeline.setCollect(1);
|
||||||
|
// }
|
||||||
|
// userIdList.add(pipeline.getUser().getId());
|
||||||
|
// list.add(findPipelineExecMessage(pipeline));
|
||||||
|
// }
|
||||||
|
// Map<String, User> pipelineUser = findPipelineUser(userIdList);
|
||||||
|
//
|
||||||
|
// List<Pipeline> pipelines = list.stream()
|
||||||
|
// .peek(pipeline -> pipeline.setUser(pipelineUser.get(pipeline.getUser().getId())))
|
||||||
|
// .toList();
|
||||||
|
//
|
||||||
|
// return PaginationBuilder.build(pipelinePage,pipelines);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findPipelineList(PipelineQuery query){
|
||||||
|
List<PipelineEntity> pipelineEntityList = pipelineDao.findPipelineList(query);
|
||||||
|
if (Objects.isNull(pipelineEntityList)){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return BeanMapper.mapList(pipelineEntityList,Pipeline.class);
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
// @Override
|
||||||
|
// public List<User> findPipelineUser(String pipelineId) {
|
||||||
|
// return authorityService.findPipelineUser(pipelineId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PipelineRecently> findPipelineRecently(String userId, int number){
|
||||||
|
|
||||||
|
// 筛选出用户拥有的流水线的历史
|
||||||
|
String[] userPipeline = authorityService.findUserPipelineIdString(userId);
|
||||||
|
if (userPipeline.length == 0){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PipelineInstance> instanceList = instanceService.findUserPipelineInstance(userId,number);
|
||||||
|
if (instanceList.isEmpty()){
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PipelineInstance> pipelineInstanceList = new ArrayList<>();
|
||||||
|
List<String> pipelineIdList = Arrays.stream(userPipeline).toList();
|
||||||
|
for (PipelineInstance instance : instanceList) {
|
||||||
|
String id = instance.getPipeline().getId();
|
||||||
|
boolean containsElement = pipelineIdList.contains(id);
|
||||||
|
if (!containsElement){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pipelineInstanceList.add(instance);
|
||||||
|
}
|
||||||
|
List<PipelineRecently> list = new ArrayList<>();
|
||||||
|
for (PipelineInstance lastInstance : pipelineInstanceList) {
|
||||||
|
String pipelineId = lastInstance.getPipeline().getId();
|
||||||
|
Pipeline pipeline = findPipelineByIdNoQuery(pipelineId);
|
||||||
|
|
||||||
|
PipelineRecently recently = new PipelineRecently();
|
||||||
|
recently.setPipelineId(pipelineId);
|
||||||
|
recently.setPipelineName(pipeline.getName());
|
||||||
|
recently.setLastRunState(lastInstance.getRunStatus());
|
||||||
|
recently.setNumber(lastInstance.getFindNumber());
|
||||||
|
String createTime = lastInstance.getCreateTime();
|
||||||
|
recently.setCreateTime(createTime);
|
||||||
|
Date date = PipelineUtil.StringChengeDate(createTime);
|
||||||
|
String dateTime = PipelineUtil.findDateTime(date, 3000);
|
||||||
|
recently.setExecTime(dateTime);
|
||||||
|
// String formatted = PipelineUtil.formatDateTime(lastInstance.getRunTime());
|
||||||
|
// recently.setLastRunTime(formatted);
|
||||||
|
// recently.setColor(pipeline.getColor());
|
||||||
|
recently.setInstanceId(lastInstance.getInstanceId());
|
||||||
|
recently.setLastRunType(lastInstance.getRunWay());
|
||||||
|
list.add(recently);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findPipelineCloneName(String pipelineId){
|
||||||
|
Pipeline pipeline = findPipelineById(pipelineId);
|
||||||
|
|
||||||
|
if (Objects.isNull(pipeline)){
|
||||||
|
logger.error("没有查询到当前流水线信息,pipelineId:{}",pipelineId);
|
||||||
|
// throw new ApplicationException("没有查询到当前流水线信息!");
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.LOCKED.getCode(),"没有查询到当前流水线信息!");
|
||||||
|
}
|
||||||
|
String name = pipeline.getName() + "_copy";
|
||||||
|
|
||||||
|
// 匹配流水线名称
|
||||||
|
int i = 1;
|
||||||
|
PipelineQuery pipelineQuery = new PipelineQuery();
|
||||||
|
pipelineQuery.setPipelineName(name);
|
||||||
|
pipelineQuery.setEqName(true);
|
||||||
|
List<Pipeline> userPipelineList = findPipelineList(pipelineQuery);
|
||||||
|
while (!userPipelineList.isEmpty() && i < 10){
|
||||||
|
name = pipeline.getName() + "_copy_"+ i ;
|
||||||
|
pipelineQuery.setPipelineName(name);
|
||||||
|
userPipelineList = findPipelineList(pipelineQuery);
|
||||||
|
i ++ ;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pipelineClone(String pipelineId,String pipelineName) {
|
||||||
|
Pipeline pipeline = findPipelineById(pipelineId);
|
||||||
|
|
||||||
|
if (Objects.isNull(pipeline)){
|
||||||
|
logger.error("没有查询到当前流水线信息,pipelineId:{}",pipelineId);
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.LOCKED.getCode(),"克隆失败,没有查询到当前流水线信息!");
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline.setName(pipelineName);
|
||||||
|
|
||||||
|
// 克隆流水线
|
||||||
|
PipelineEntity pipelineEntity = BeanMapper.map(pipeline, PipelineEntity.class);
|
||||||
|
String clonePipelineId = pipelineDao.createPipeline(pipelineEntity);
|
||||||
|
|
||||||
|
// 克隆流水线成员以及权限信息
|
||||||
|
authorityService.cloneDomainRole(pipelineId,clonePipelineId);
|
||||||
|
|
||||||
|
// 克隆任务
|
||||||
|
int type = pipeline.getType();
|
||||||
|
if (type == 1){
|
||||||
|
// 多任务
|
||||||
|
tasksCloneService.clonePipelineTasks(pipelineId,clonePipelineId);
|
||||||
|
}else {
|
||||||
|
// 多阶段
|
||||||
|
stageService.cloneStage(pipelineId, clonePipelineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 克隆后置任务
|
||||||
|
postprocessService.clonePostTask(pipelineId,clonePipelineId);
|
||||||
|
|
||||||
|
// 克隆触发器
|
||||||
|
triggerService.cloneTrigger(pipelineId,clonePipelineId);
|
||||||
|
|
||||||
|
// 克隆流水线变量
|
||||||
|
variableService.cloneVariable(pipelineId,clonePipelineId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pipeline> findRecentlyPipeline(Integer number,String pipelineId){
|
||||||
|
|
||||||
|
int i = number + 1;
|
||||||
|
List<String> userOpenList = openService.findUserOpen(i);
|
||||||
|
|
||||||
|
// String loginId = LoginContext.getLoginId();
|
||||||
|
// TODO
|
||||||
|
String loginId = "";
|
||||||
|
String[] builders = authorityService.findUserPipelineIdString(loginId);
|
||||||
|
|
||||||
|
Pipeline pipeline = findPipelineNoQuery(pipelineId);
|
||||||
|
|
||||||
|
// 过滤出当前流水线
|
||||||
|
List<String> strings = Stream.of(builders).filter(a -> !a.equals(pipelineId)).toList();
|
||||||
|
if (strings.isEmpty()){
|
||||||
|
List<Pipeline> objects = new ArrayList<>();
|
||||||
|
objects.add(pipeline);
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最近没有打开流水线
|
||||||
|
if (userOpenList.isEmpty()){
|
||||||
|
List<PipelineEntity> pipelineEntityList = pipelineDao.findAllPipelineList(strings);
|
||||||
|
if (pipelineEntityList.size() > number){
|
||||||
|
pipelineEntityList.subList(0, number);
|
||||||
|
}
|
||||||
|
List<Pipeline> pipelineList = BeanMapper.mapList(pipelineEntityList, Pipeline.class);
|
||||||
|
pipelineList.add(0,pipeline);
|
||||||
|
return pipelineList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤出当前流水线
|
||||||
|
List<String> pieplineIdList = userOpenList.stream().filter(s -> !s.equals(pipelineId))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 获取最近打开以及拥有权限的流水线
|
||||||
|
List<String> collect = strings.stream()
|
||||||
|
.filter(pieplineIdList::contains).distinct().toList();
|
||||||
|
|
||||||
|
List<String> idStrings = new ArrayList<>(collect);
|
||||||
|
|
||||||
|
// 判断是否超出数量
|
||||||
|
if (collect.size() >= number){
|
||||||
|
idStrings = idStrings.subList(0, number);
|
||||||
|
}else {
|
||||||
|
List<String> collect1 = strings.stream().filter(element -> !pieplineIdList.contains(element)).toList();
|
||||||
|
if (collect1.size() >= number - collect.size()){
|
||||||
|
idStrings.addAll(collect.size()-1,collect1.subList(0,number - collect.size()));
|
||||||
|
}else {
|
||||||
|
idStrings.addAll(collect.size()-1,collect1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (strings.isEmpty()){
|
||||||
|
// List<Pipeline> objects = new ArrayList<>();
|
||||||
|
// objects.add(pipeline);
|
||||||
|
// return objects;
|
||||||
|
// }
|
||||||
|
|
||||||
|
List<Pipeline> pipelineList = findAllPipelineList(idStrings);
|
||||||
|
pipelineList.add(0,pipeline);
|
||||||
|
|
||||||
|
return pipelineList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关联信息
|
||||||
|
* @param pipelineId 流水线Id
|
||||||
|
*/
|
||||||
|
private void deleteOther(String pipelineId){
|
||||||
|
|
||||||
|
//删除对应的历史
|
||||||
|
instanceService.deleteAllInstance(pipelineId);
|
||||||
|
|
||||||
|
//删除对应源码文件
|
||||||
|
String fileAddress = utilService.findPipelineDefaultAddress(pipelineId,1);
|
||||||
|
PipelineFileUtil.deleteFile(new File(fileAddress));
|
||||||
|
|
||||||
|
//删除对应日志
|
||||||
|
String logAddress = utilService.findPipelineDefaultAddress(pipelineId,2);
|
||||||
|
PipelineFileUtil.deleteFile(new File(logAddress));
|
||||||
|
|
||||||
|
// 删除最近打开
|
||||||
|
openService.deleteAllOpen(pipelineId);
|
||||||
|
|
||||||
|
// 删除收藏
|
||||||
|
followService.deletePipelineFollow(pipelineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加流水线执行信息
|
||||||
|
* @param pipeline 流水线
|
||||||
|
* @return 流水线
|
||||||
|
*/
|
||||||
|
public Pipeline findPipelineExecMessage(Pipeline pipeline){
|
||||||
|
PipelineInstance latelyHistory = instanceService.findLatelyInstance(pipeline.getId());
|
||||||
|
if (!Objects.isNull(latelyHistory)){
|
||||||
|
|
||||||
|
pipeline.setBuildStatus(latelyHistory.getRunStatus());
|
||||||
|
pipeline.setNumber(latelyHistory.getFindNumber());
|
||||||
|
pipeline.setInstanceId(latelyHistory.getInstanceId());
|
||||||
|
|
||||||
|
String createTime = latelyHistory.getCreateTime();
|
||||||
|
Date date = PipelineUtil.StringChengeDate(createTime);
|
||||||
|
String dateTime = PipelineUtil.findDateTime(date, 1000);
|
||||||
|
if (!Objects.isNull(dateTime)){
|
||||||
|
pipeline.setLastBuildTime(dateTime);
|
||||||
|
// pipeline.setBuildStatus(latelyHistory.getRunStatus());
|
||||||
|
// pipeline.setNumber(latelyHistory.getFindNumber());
|
||||||
|
// pipeline.setInstanceId(latelyHistory.getInstanceId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户Id查询用户
|
||||||
|
* @param userIdString 用户Id
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
// public Map<String, User> findPipelineUser(List<String> userIdString){
|
||||||
|
//
|
||||||
|
// // 使用Stream API去除重复元素
|
||||||
|
// List<String> uniqueList = userIdString.stream()
|
||||||
|
// .distinct()
|
||||||
|
// .toList();
|
||||||
|
//
|
||||||
|
// Map<String,User> map = new HashMap<>();
|
||||||
|
//
|
||||||
|
// List<User> list = userService.findList(uniqueList);
|
||||||
|
// for (User user : list) {
|
||||||
|
// if (Objects.isNull(user)){
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// map.put(user.getId(),user);
|
||||||
|
// }
|
||||||
|
// return map;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,641 @@
|
|||||||
|
//package cd.casic.module.process.pipeline.definition.impl;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import cd.casic.ci.commons.bean.engine.job.Tasks;
|
||||||
|
//import cd.casic.ci.commons.bean.process.stage.Stage;
|
||||||
|
//import cd.casic.module.process.engine.task.TasksService;
|
||||||
|
//import cd.casic.module.process.pipeline.definition.PipelineYamlService;
|
||||||
|
//import cd.casic.module.process.pipeline.definition.entity.PipelineEntity;
|
||||||
|
//import cd.casic.module.process.process.definition.dao.PipelineDao;
|
||||||
|
//import cd.casic.module.process.setting.service.AuthHostService;
|
||||||
|
//import cd.casic.module.process.setting.service.AuthService;
|
||||||
|
//import cd.casic.module.process.setting.service.AuthThirdService;
|
||||||
|
//import cd.casic.module.process.stages.service.StageService;
|
||||||
|
//import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||||
|
//import com.alibaba.fastjson.JSONObject;
|
||||||
|
//import org.slf4j.Logger;
|
||||||
|
//import org.slf4j.LoggerFactory;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.stereotype.Service;
|
||||||
|
//import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
//import org.yaml.snakeyaml.Yaml;
|
||||||
|
//
|
||||||
|
//import java.util.*;
|
||||||
|
//
|
||||||
|
//@Service
|
||||||
|
//public class PipelineYamlServiceImpl implements PipelineYamlService {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineDao pipelineDao;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// AuthHostService authHostService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// AuthThirdService authThirdService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// TaskTestOnService taskTestOnService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// TaskCodeGittokService taskCodeGittokService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// TaskArtifactXpackService taskArtifactXpackService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// AuthService authService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineYamlService pipelineYamlService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// TasksService tasksService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// StageService stageService;
|
||||||
|
//
|
||||||
|
// private static final Logger logger = LoggerFactory.getLogger(PipelineYamlService.class);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public String importPipelineYaml(String pipelineId){
|
||||||
|
//
|
||||||
|
// PipelineEntity pipeline = pipelineDao.findPipelineById(pipelineId);
|
||||||
|
//
|
||||||
|
// Map<String, Object> properties = new HashMap<>();
|
||||||
|
// properties.put("pipeline", Map.of("name", pipeline.getName()));
|
||||||
|
//
|
||||||
|
// DumperOptions options = new DumperOptions();
|
||||||
|
// options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
//
|
||||||
|
// Yaml yaml = new Yaml(options);
|
||||||
|
//
|
||||||
|
// // 将Java对象转换为YAML字符串
|
||||||
|
// String yamlString = yaml.dump(properties);
|
||||||
|
//
|
||||||
|
// return importStageYaml(yamlString,pipelineId);
|
||||||
|
//
|
||||||
|
// // int type = pipeline.getType();
|
||||||
|
// //
|
||||||
|
// // if (type == 1){
|
||||||
|
// // return importTaskYaml(yamlString,pipelineId);
|
||||||
|
// // }else {
|
||||||
|
// // return importStageYaml(yamlString,pipelineId);
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // /**
|
||||||
|
// // * 导出多任务配置为Yaml格式
|
||||||
|
// // * @param yamlString yaml
|
||||||
|
// // * @param pipelineId 流水线
|
||||||
|
// // * @return Yaml格式支付串
|
||||||
|
// // */
|
||||||
|
// // private String importTaskYaml(String yamlString,String pipelineId){
|
||||||
|
// //
|
||||||
|
// // DumperOptions options = new DumperOptions();
|
||||||
|
// // options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
// //
|
||||||
|
// // Yaml yaml = new Yaml(options);
|
||||||
|
// // Map<String, Object> data = yaml.load(yamlString);
|
||||||
|
// //
|
||||||
|
// // List<Map<String, Object>> taskList = new ArrayList<>();
|
||||||
|
// //
|
||||||
|
// // List<Tasks> tasksList = tasksService.finAllPipelineTaskOrTask(pipelineId);
|
||||||
|
// // for (Tasks tasks : tasksList) {
|
||||||
|
// // LinkedHashMap<String, Object> tasksMap = new LinkedHashMap<>();
|
||||||
|
// //
|
||||||
|
// // LinkedHashMap<String, Object> taskDetails = new LinkedHashMap<>();
|
||||||
|
// //
|
||||||
|
// // taskDetails.put("taskId",tasks.getTaskId());
|
||||||
|
// // taskDetails.put("taskName",tasks.getTaskName());
|
||||||
|
// // findTaskDetails(tasks.getTaskType(), tasks.getTask(), taskDetails);
|
||||||
|
// //
|
||||||
|
// // tasksMap.put("task",taskDetails);
|
||||||
|
// // taskList.add(tasksMap);
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // Map<String, Object> pipelineMap = (Map<String, Object>) data.get("pipeline");
|
||||||
|
// // pipelineMap.put("tasks",taskList);
|
||||||
|
// // return yaml.dump(data);
|
||||||
|
// // }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 导出多阶段配置为Yaml格式
|
||||||
|
// * @param yamlString yaml
|
||||||
|
// * @param pipelineId 流水线
|
||||||
|
// * @return Yaml格式支付串
|
||||||
|
// */
|
||||||
|
// private String importStageYaml(String yamlString,String pipelineId){
|
||||||
|
//
|
||||||
|
// DumperOptions options = new DumperOptions();
|
||||||
|
// options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
//
|
||||||
|
// Yaml yaml = new Yaml(options);
|
||||||
|
// Map<String, Object> data = yaml.load(yamlString);
|
||||||
|
//
|
||||||
|
// List<Map<String, Object>> stageMapList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// List<Stage> stageList = stageService.findAllStagesOrTask(pipelineId);
|
||||||
|
//
|
||||||
|
// for (Stage stage : stageList) {
|
||||||
|
// LinkedHashMap<String, Object> stageMap = new LinkedHashMap<>();
|
||||||
|
//
|
||||||
|
// List<Stage> parallelStageList = stage.getStageList();
|
||||||
|
//
|
||||||
|
// List<Map<String, Object>> parallelMapList = new ArrayList<>();
|
||||||
|
// LinkedHashMap<String, Object> parallelsMap = new LinkedHashMap<>();
|
||||||
|
// for (Stage parallelStage : parallelStageList) {
|
||||||
|
//
|
||||||
|
// LinkedHashMap<String, Object> parallelMap = new LinkedHashMap<>();
|
||||||
|
//
|
||||||
|
// List<Map<String, Object>> taskMapList = new ArrayList<>();
|
||||||
|
// List<Tasks> taskList = parallelStage.getTaskValues();
|
||||||
|
// LinkedHashMap<String, Object> tasksMap = new LinkedHashMap<>();
|
||||||
|
// for (Tasks tasks : taskList) {
|
||||||
|
//
|
||||||
|
// LinkedHashMap<String, Object> taskMap = new LinkedHashMap<>();
|
||||||
|
// LinkedHashMap<String, Object> taskDetails = new LinkedHashMap<>();
|
||||||
|
//
|
||||||
|
// taskDetails.put("taskId",tasks.getTaskId());
|
||||||
|
// taskDetails.put("taskName",tasks.getTaskName());
|
||||||
|
// findTaskDetails(tasks.getTaskType(), tasks.getTask(), taskDetails);
|
||||||
|
//
|
||||||
|
// taskMap.put("task",taskDetails);
|
||||||
|
// taskMapList.add(taskMap);
|
||||||
|
//
|
||||||
|
// tasksMap.put("parallelId",parallelStage.getStageId());
|
||||||
|
// tasksMap.put("parallelName",parallelStage.getStageName());
|
||||||
|
// tasksMap.put("tasks",taskMapList);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// parallelMap.put("parallel",tasksMap);
|
||||||
|
// parallelMapList.add(parallelMap);
|
||||||
|
// }
|
||||||
|
// parallelsMap.put("stageId",stage.getStageId());
|
||||||
|
// parallelsMap.put("stageName",stage.getStageName());
|
||||||
|
// parallelsMap.put("parallels",parallelMapList);
|
||||||
|
//
|
||||||
|
// stageMap.put("stage",parallelsMap);
|
||||||
|
// stageMapList.add(stageMap);
|
||||||
|
// }
|
||||||
|
// Map<String, Object> pipelineMap = (Map<String, Object>) data.get("pipeline");
|
||||||
|
// pipelineMap.put("stages",stageMapList);
|
||||||
|
//
|
||||||
|
// return yaml.dump(data);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> findTaskDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetails){
|
||||||
|
// if (Objects.isNull(object)){
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_CODE_GIT , PipelineFinal.TASK_CODE_GITEE , PipelineFinal.TASK_CODE_GITHUB ,
|
||||||
|
// PipelineFinal.TASK_CODE_GITLAB, PipelineFinal.TASK_CODE_XCODE, PipelineFinal.TASK_CODE_SVN ->{
|
||||||
|
// return taskCodeDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_BUILD_MAVEN, PipelineFinal.TASK_BUILD_NODEJS ->{
|
||||||
|
// return taskBuildDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_TEST_MAVENTEST, PipelineFinal.TASK_TEST_TESTON ->{
|
||||||
|
// return taskTestDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_DEPLOY_LINUX , PipelineFinal.TASK_DEPLOY_DOCKER ->{
|
||||||
|
// return taskDeployDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NEXUS , PipelineFinal.TASK_ARTIFACT_SSH , PipelineFinal.TASK_ARTIFACT_XPACK ->{
|
||||||
|
// return taskArtifactDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_CODESCAN_SONAR ->{
|
||||||
|
// return taskCodeScanDetails(taskType,object,taskDetails);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskCodeDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskCode taskCode = JSONObject.parseObject(string, TaskCode.class);
|
||||||
|
// if (!Objects.isNull(taskCode.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskCode.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!taskType.equals(PipelineFinal.TASK_CODE_SVN)){
|
||||||
|
// if (!Objects.isNull(taskCode.getCodeName())){
|
||||||
|
// taskDetailsMap.put("url",taskCode.getCodeName());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskCode.getCodeBranch())){
|
||||||
|
// taskDetailsMap.put("branch",taskCode.getCodeBranch());
|
||||||
|
// }else {
|
||||||
|
// taskDetailsMap.put("branch", PipelineFinal.TASK_CODE_DEFAULT_BRANCH);
|
||||||
|
// }
|
||||||
|
// }else {
|
||||||
|
// if (!Objects.isNull(taskCode.getCodeName())){
|
||||||
|
// taskDetailsMap.put("detection_url",taskCode.getCodeName());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!Objects.isNull(taskCode.getSvnFile())){
|
||||||
|
// taskDetailsMap.put("detection_file",taskCode.getSvnFile());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // switch (taskType){
|
||||||
|
// // case PipelineFinal.TASK_CODE_GIT, PipelineFinal.TASK_CODE_GITLAB ->{
|
||||||
|
// // if (!Objects.isNull(taskCode.getAuthId())){
|
||||||
|
// // taskDetailsMap.put("authId",taskCode.getAuthId());
|
||||||
|
// // }
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeName())){
|
||||||
|
// // taskDetailsMap.put("url",taskCode.getCodeName());
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeBranch())){
|
||||||
|
// // taskDetailsMap.put("branch",taskCode.getCodeBranch());
|
||||||
|
// // }else {
|
||||||
|
// // taskDetailsMap.put("branch", PipelineFinal.TASK_CODE_DEFAULT_BRANCH);
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // case PipelineFinal.TASK_CODE_GITEE, PipelineFinal.TASK_CODE_GITHUB ->{
|
||||||
|
// // if (!Objects.isNull(taskCode.getAuthId())){
|
||||||
|
// // taskDetailsMap.put("authId",taskCode.getAuthId());
|
||||||
|
// // }
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeName())){
|
||||||
|
// // taskDetailsMap.put("repository_name",taskCode.getCodeName());
|
||||||
|
// // }
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeAddress())){
|
||||||
|
// // taskDetailsMap.put("repository_url",taskCode.getCodeAddress());
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // if (!Objects.isNull(taskDetailsMap.get("authId"))){
|
||||||
|
// // String authId = (String) taskDetailsMap.get("authId");
|
||||||
|
// // String repositoryName = (String) taskDetailsMap.get("repository_name");
|
||||||
|
// // String houseUrl = codeThirdService.getHouseUrl(authId, repositoryName, taskType);
|
||||||
|
// // taskCode.setCodeAddress(houseUrl);
|
||||||
|
// // taskDetailsMap.put("repository_url",houseUrl);
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeBranch())){
|
||||||
|
// // taskDetailsMap.put("branch",taskCode.getCodeBranch());
|
||||||
|
// // }else {
|
||||||
|
// // taskDetailsMap.put("branch", PipelineFinal.TASK_CODE_DEFAULT_BRANCH);
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // case PipelineFinal.TASK_CODE_XCODE ->{
|
||||||
|
// // String authId = taskCode.getAuthId();
|
||||||
|
// // if (!Objects.isNull(authId)){
|
||||||
|
// // taskDetailsMap.put("authId",taskCode.getAuthId());
|
||||||
|
// // }
|
||||||
|
// // if (!Objects.isNull(taskCode.getRepository())){
|
||||||
|
// // String rpyId = taskCode.getRepository().getRpyId();
|
||||||
|
// // taskDetailsMap.put("repository_id",rpyId);
|
||||||
|
// // ThirdHouse thirdHouse = taskCodeGittokService.
|
||||||
|
// // findStoreHouse((String) taskDetailsMap.get("authId"), rpyId);
|
||||||
|
// // if (!Objects.isNull(thirdHouse)) {
|
||||||
|
// // // taskCode.setRepository(thirdHouse);
|
||||||
|
// // taskDetailsMap.put("repository_url",thirdHouse.getHouseWebUrl());
|
||||||
|
// // taskDetailsMap.put("repository_name",thirdHouse.getName());
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // taskDetailsMap.put("branch", PipelineFinal.TASK_CODE_DEFAULT_BRANCH);
|
||||||
|
// // if (!Objects.isNull(taskCode.getBranch())){
|
||||||
|
// // String branchId = taskCode.getBranch().getBranchId();
|
||||||
|
// // String authId1 = (String) taskDetailsMap.get("authId");
|
||||||
|
// // String rpyId1 = (String) taskDetailsMap.get("repository_id");
|
||||||
|
// // XcodeBranch xcodeBranch = taskCodeGittokService.findOneBranch(authId1, rpyId1,branchId);
|
||||||
|
// // if (!Objects.isNull(xcodeBranch)){
|
||||||
|
// // taskCode.setBranch(xcodeBranch);
|
||||||
|
// // taskDetailsMap.put("branch_name",xcodeBranch.getBranchName());
|
||||||
|
// // }
|
||||||
|
// // }else {
|
||||||
|
// // taskDetailsMap.put("branch", PipelineFinal.TASK_CODE_DEFAULT_BRANCH);
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // case PipelineFinal.TASK_CODE_SVN ->{
|
||||||
|
// // if (!Objects.isNull(taskCode.getAuthId())){
|
||||||
|
// // taskDetailsMap.put("authId",taskCode.getAuthId());
|
||||||
|
// // }
|
||||||
|
// // if (!Objects.isNull(taskCode.getCodeName())){
|
||||||
|
// // taskDetailsMap.put("detection_url",taskCode.getCodeName());
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // if (!Objects.isNull(taskCode.getSvnFile())){
|
||||||
|
// // taskDetailsMap.put("detection_file",taskCode.getSvnFile());
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskCodeScanDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskCodeScan taskCodeScan = JSONObject.parseObject(string, TaskCodeScan.class);
|
||||||
|
//
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_CODESCAN_SONAR ->{
|
||||||
|
// if (!Objects.isNull(taskCodeScan.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskCodeScan.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskCodeScan.getProjectName())){
|
||||||
|
// taskDetailsMap.put("project_name",taskCodeScan.getProjectName());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskTestDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskTest taskTest = JSONObject.parseObject(string, TaskTest.class);
|
||||||
|
//
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_TEST_MAVENTEST ->{
|
||||||
|
// if (!Objects.isNull(taskTest.getTestOrder())){
|
||||||
|
// taskDetailsMap.put("test_order",taskTest.getTestOrder());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskTest.getAddress())){
|
||||||
|
// taskDetailsMap.put("pom_address",taskTest.getAddress());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_TEST_TESTON ->{
|
||||||
|
//
|
||||||
|
// if (!Objects.isNull(taskTest.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskTest.getAuthId());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!Objects.isNull(taskTest.getWebEnv())){
|
||||||
|
// taskDetailsMap.put("webEnv",taskTest.getWebEnv().getId());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!Objects.isNull(taskTest.getApiEnv())){
|
||||||
|
// taskDetailsMap.put("apiEnv",taskTest.getApiEnv().getId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskTest.getAppEnv())){
|
||||||
|
// taskDetailsMap.put("appEnv",taskTest.getAppEnv().getId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskTest.getTestPlan())){
|
||||||
|
// taskDetailsMap.put("testPlan",taskTest.getTestPlan().getId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskTest.getTestSpace())){
|
||||||
|
// taskDetailsMap.put("testSpace",taskTest.getTestSpace().getId());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskBuildDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskBuild taskBuilder = JSONObject.parseObject(string, TaskBuild.class);
|
||||||
|
//
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_BUILD_MAVEN ->{
|
||||||
|
// if (!Objects.isNull(taskBuilder.getBuildOrder())){
|
||||||
|
// taskDetailsMap.put("mvn_order",taskBuilder.getBuildOrder());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskBuilder.getBuildAddress())){
|
||||||
|
// taskDetailsMap.put("pom_address",taskBuilder.getBuildAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskBuilder.getProductRule())){
|
||||||
|
// taskDetailsMap.put("artifact_role",taskBuilder.getProductRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_BUILD_NODEJS ->{
|
||||||
|
// if (!Objects.isNull(taskBuilder.getBuildOrder())){
|
||||||
|
// taskDetailsMap.put("npm_order",taskBuilder.getBuildOrder());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskBuilder.getBuildAddress())){
|
||||||
|
// taskDetailsMap.put("model_address",taskBuilder.getBuildAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskBuilder.getProductRule())){
|
||||||
|
// taskDetailsMap.put("artifact_role",taskBuilder.getProductRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskDeployDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskDeploy taskDeploy = JSONObject.parseObject(string, TaskDeploy.class);
|
||||||
|
//
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_DEPLOY_LINUX ->{
|
||||||
|
// if (taskDeploy.getAuthType() != 0){
|
||||||
|
// taskDetailsMap.put("deploy_type",taskDeploy.getAuthType());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (taskDeploy.getAuthType() == 1){
|
||||||
|
// if (!Objects.isNull(taskDeploy.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskDeploy.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskDeploy.getDeployAddress())){
|
||||||
|
// taskDetailsMap.put("deploy_address",taskDeploy.getDeployAddress());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskDeploy.getDeployOrder())){
|
||||||
|
// taskDetailsMap.put("deploy_order",taskDeploy.getDeployOrder());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_DEPLOY_DOCKER->{
|
||||||
|
// if (!Objects.isNull(taskDeploy.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskDeploy.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskDeploy.getDockerImage())){
|
||||||
|
// taskDetailsMap.put("image",taskDeploy.getDockerImage());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskDeploy.getDeployAddress())){
|
||||||
|
// taskDetailsMap.put("deploy_address",taskDeploy.getDeployAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskDeploy.getDeployOrder())){
|
||||||
|
// taskDetailsMap.put("deploy_order",taskDeploy.getDeployOrder());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskArtifactDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskArtifact taskArtifact = JSONObject.parseObject(string, TaskArtifact.class);
|
||||||
|
//
|
||||||
|
// String artifactType = taskArtifact.getArtifactType();
|
||||||
|
// taskDetailsMap.put("artifact_type",artifactType);
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_MAVEN ->{
|
||||||
|
// switch (artifactType){
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NEXUS ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getArtifactId())){
|
||||||
|
// taskDetailsMap.put("artifact_id",taskArtifact.getArtifactId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("auth_id",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getGroupId())){
|
||||||
|
// taskDetailsMap.put("group_id",taskArtifact.getGroupId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getVersion())){
|
||||||
|
// taskDetailsMap.put("version",taskArtifact.getVersion());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("file_address",taskArtifact.getFileAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRule())){
|
||||||
|
// taskDetailsMap.put("rule",taskArtifact.getRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_SSH ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("auth_id",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getPutAddress())){
|
||||||
|
// taskDetailsMap.put("remote_address",taskArtifact.getPutAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("fileAddress",taskArtifact.getFileAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("put_address",taskArtifact.getPutAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRule())){
|
||||||
|
// taskDetailsMap.put("rule",taskArtifact.getRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_XPACK ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getArtifactId())){
|
||||||
|
// taskDetailsMap.put("artifactId",taskArtifact.getArtifactId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getGroupId())){
|
||||||
|
// taskDetailsMap.put("groupId",taskArtifact.getGroupId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getVersion())){
|
||||||
|
// taskDetailsMap.put("version",taskArtifact.getVersion());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRepository())){
|
||||||
|
// taskDetailsMap.put("repository_id",taskArtifact.getRepository().getId());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NODEJS ->{
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_DOCKER ->{
|
||||||
|
// switch (artifactType){
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NEXUS ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getDockerImage())){
|
||||||
|
// taskDetailsMap.put("image",taskArtifact.getDockerImage());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private LinkedHashMap<String, Object> taskPullArtifactDetails(String taskType,Object object,LinkedHashMap<String, Object> taskDetailsMap){
|
||||||
|
// String string = JSONObject.toJSONString(object);
|
||||||
|
//
|
||||||
|
// TaskArtifact taskArtifact = JSONObject.parseObject(string, TaskArtifact.class);
|
||||||
|
//
|
||||||
|
// String artifactType = taskArtifact.getArtifactType();
|
||||||
|
// taskDetailsMap.put("artifact_type",artifactType);
|
||||||
|
// switch (taskType){
|
||||||
|
// case PipelineFinal.TASK_PULL_MAVEN ->{
|
||||||
|
// switch (artifactType){
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NEXUS ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getArtifactId())){
|
||||||
|
// taskDetailsMap.put("artifact_id",taskArtifact.getArtifactId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("auth_id",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getGroupId())){
|
||||||
|
// taskDetailsMap.put("group_id",taskArtifact.getGroupId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getVersion())){
|
||||||
|
// taskDetailsMap.put("version",taskArtifact.getVersion());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("file_address",taskArtifact.getFileAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRule())){
|
||||||
|
// taskDetailsMap.put("rule",taskArtifact.getRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_SSH ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("auth_id",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getPutAddress())){
|
||||||
|
// taskDetailsMap.put("remote_address",taskArtifact.getPutAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("fileAddress",taskArtifact.getFileAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getFileAddress())){
|
||||||
|
// taskDetailsMap.put("put_address",taskArtifact.getPutAddress());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRule())){
|
||||||
|
// taskDetailsMap.put("rule",taskArtifact.getRule());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_XPACK ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getArtifactId())){
|
||||||
|
// taskDetailsMap.put("artifactId",taskArtifact.getArtifactId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getGroupId())){
|
||||||
|
// taskDetailsMap.put("groupId",taskArtifact.getGroupId());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getVersion())){
|
||||||
|
// taskDetailsMap.put("version",taskArtifact.getVersion());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getRepository())){
|
||||||
|
// taskDetailsMap.put("repository_id",taskArtifact.getRepository().getId());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_PULL_NODEJS ->{
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// case PipelineFinal.TASK_PULL_DOCKER ->{
|
||||||
|
// switch (artifactType){
|
||||||
|
// case PipelineFinal.TASK_ARTIFACT_NEXUS ->{
|
||||||
|
// if (!Objects.isNull(taskArtifact.getDockerImage())){
|
||||||
|
// taskDetailsMap.put("image",taskArtifact.getDockerImage());
|
||||||
|
// }
|
||||||
|
// if (!Objects.isNull(taskArtifact.getAuthId())){
|
||||||
|
// taskDetailsMap.put("authId",taskArtifact.getAuthId());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return taskDetailsMap;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,356 @@
|
|||||||
|
//package cd.casic.module.process.pipeline.execute.service.impl;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import cd.casic.ci.commons.bean.engine.execute.PipelineRunMsg;
|
||||||
|
//import cd.casic.ci.commons.bean.process.instance.PipelineInstance;
|
||||||
|
//import cd.casic.ci.commons.bean.work.agent.model.Agent;
|
||||||
|
//import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
//import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
//import cd.casic.module.process.engine.task.TasksExecService;
|
||||||
|
//import cd.casic.module.process.pipeline.definition.PipelineService;
|
||||||
|
//import cd.casic.module.process.pipeline.execute.service.PipelineExecService;
|
||||||
|
//import cd.casic.module.process.process.definition.VariableService;
|
||||||
|
//import cd.casic.module.process.process.instance.PipelineInstanceService;
|
||||||
|
//import cd.casic.module.process.setting.service.ResourcesService;
|
||||||
|
//import cd.casic.module.process.setting.service.ScmService;
|
||||||
|
//import cd.casic.module.process.stages.service.StageExecService;
|
||||||
|
//import cd.casic.module.process.stages.service.StageService;
|
||||||
|
//import cd.casic.module.process.support.agent.service.AgentService;
|
||||||
|
//import cd.casic.module.process.support.disk.service.DiskService;
|
||||||
|
//import cd.casic.module.process.support.home.PipelineVersionService;
|
||||||
|
//import cd.casic.module.process.support.postprocess.service.PostprocessExecService;
|
||||||
|
//import cd.casic.module.process.support.util.PipelineUtilService;
|
||||||
|
//import cd.casic.module.process.toolkit.join.JoinTemplate;
|
||||||
|
//import org.apache.commons.lang3.StringUtils;
|
||||||
|
//import org.slf4j.Logger;
|
||||||
|
//import org.slf4j.LoggerFactory;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.stereotype.Service;
|
||||||
|
////import org.springframework.web.socket.WebSocketSession;
|
||||||
|
//
|
||||||
|
//import java.util.HashMap;
|
||||||
|
//import java.util.List;
|
||||||
|
//import java.util.Map;
|
||||||
|
//import java.util.Objects;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 流水线运行服务
|
||||||
|
// */
|
||||||
|
//@Service
|
||||||
|
////@Exporter
|
||||||
|
//public class PipelineExecServiceImpl implements PipelineExecService {
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineService pipelineService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PostprocessExecService postExecService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineInstanceService pipelineInstanceService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// TasksExecService tasksExecService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// StageExecService stageExecService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// ResourcesService resourcesService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineVersionService versionService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// PipelineUtilService utilService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// DiskService diskService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// StageService stageService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// JoinTemplate joinTemplate;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// ScmService scmService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// VariableService variableService;
|
||||||
|
//
|
||||||
|
// @Autowired
|
||||||
|
// AgentService agentService;
|
||||||
|
//
|
||||||
|
// public final Logger logger = LoggerFactory.getLogger(PipelineExecServiceImpl.class);
|
||||||
|
//
|
||||||
|
// //流水线id:流水线实例id
|
||||||
|
// public static final Map<String,String> pipelineIdOrInstanceId = new HashMap<>();
|
||||||
|
//
|
||||||
|
// //流水线id:agent
|
||||||
|
// public static final Map<String , Agent> pipelineIdOrAgentId = new HashMap<>();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 流水线开始运行
|
||||||
|
// * @param runMsg 流水线id
|
||||||
|
// * @return 是否正在运行
|
||||||
|
// */
|
||||||
|
// @Override
|
||||||
|
// public PipelineInstance start(PipelineRunMsg runMsg) {
|
||||||
|
// Agent agent;
|
||||||
|
// if (StringUtils.isEmpty(runMsg.getAgentId())){
|
||||||
|
// agent = agentService.findDefaultAgent();
|
||||||
|
// }else {
|
||||||
|
// agent = agentService.findAgent(runMsg.getAgentId());
|
||||||
|
// }
|
||||||
|
// if (Objects.isNull(agent)){
|
||||||
|
// throw new ServiceException(GlobalErrorCodeConstants.LOCKED.getCode(),"无法获取到流水线执行Agent!");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// WebSocketSession session = SocketServerHandler.sessionMap.get(agent.getAddress());
|
||||||
|
// if (Objects.isNull(session)){
|
||||||
|
// throw new ApplicationException("流水线Agent断开连接,无法执行。");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 判断同一任务是否在运行
|
||||||
|
// Pipeline pipeline = validExecPipeline(runMsg);
|
||||||
|
// String pipelineId = pipeline.getId();
|
||||||
|
// pipelineIdOrAgentId.put(pipelineId, agent);
|
||||||
|
//
|
||||||
|
// // 判断磁盘空间是否足够
|
||||||
|
// diskService.validationStorageSpace();
|
||||||
|
//
|
||||||
|
// // 资源限制
|
||||||
|
// resourcesService.judgeResources();
|
||||||
|
//
|
||||||
|
// // 进入执行
|
||||||
|
// runMsg.setPipeline(pipeline);
|
||||||
|
// runMsg.setAgent(agent);
|
||||||
|
// return beginExecPipeline(runMsg);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 放入正在执行的流水线缓存中
|
||||||
|
// * @param runMsg 流水线id
|
||||||
|
// * @return 流水线信息
|
||||||
|
// */
|
||||||
|
// public Pipeline validExecPipeline(PipelineRunMsg runMsg){
|
||||||
|
// String pipelineId = runMsg.getPipelineId();
|
||||||
|
//
|
||||||
|
// List<Stage> allMainStage = stageService.findAllMainStage(pipelineId);
|
||||||
|
// if (allMainStage.isEmpty()){
|
||||||
|
// throw new ApplicationException(2000,"当前流水线不存在可构建任务!");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Boolean isVip = versionService.isVip();
|
||||||
|
//
|
||||||
|
// Pipeline pipeline = pipelineService.findPipelineById(pipelineId);
|
||||||
|
//
|
||||||
|
// int size = pipelineIdOrInstanceId.size();
|
||||||
|
//
|
||||||
|
// // 资源限制放入缓存中等待执行
|
||||||
|
// if ((!isVip && size >= 2) || (isVip && size >= 4) ){
|
||||||
|
// throw new ApplicationException(2000,"并行任务已满,等待执行!");
|
||||||
|
// }
|
||||||
|
// return pipeline;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 执行流水线
|
||||||
|
// * @param runMsg 流水线信息
|
||||||
|
// * @return 流水线实例
|
||||||
|
// */
|
||||||
|
// public PipelineInstance beginExecPipeline(PipelineRunMsg runMsg){
|
||||||
|
// String pipelineId = runMsg.getPipelineId();
|
||||||
|
// Pipeline pipeline = pipelineService.findPipelineById(pipelineId);
|
||||||
|
// pipeline.setState(2);
|
||||||
|
// pipelineService.updatePipeline(pipeline);
|
||||||
|
// runMsg.setPipeline(pipeline);
|
||||||
|
//
|
||||||
|
// logger.info("流水线{}开始运行",pipeline.getName());
|
||||||
|
// PipelineInstance pipelineInstance = pipelineInstanceService.initializeInstance(runMsg);
|
||||||
|
// // 添加到缓存
|
||||||
|
// String instanceId = pipelineInstance.getInstanceId();
|
||||||
|
// pipelineInstanceService.instanceRuntime(pipelineInstance.getInstanceId());
|
||||||
|
// joinTemplate.joinQuery(pipelineInstance);
|
||||||
|
//
|
||||||
|
// // 运行实例放入内存中
|
||||||
|
// pipelineIdOrInstanceId.put(pipelineId, instanceId);
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// // 创建多阶段运行实例
|
||||||
|
// List<Stage> stageList = stageExecService.createStageExecInstance(pipelineId, instanceId);
|
||||||
|
//
|
||||||
|
// List<Postprocess> postprocessList = postExecService.createPipelinePostInstance(pipelineId, instanceId);
|
||||||
|
//
|
||||||
|
// PipelineDetails pipelineDetails = new PipelineDetails();
|
||||||
|
//
|
||||||
|
// // 流水线基本运行信息
|
||||||
|
// pipelineDetails.setPipelineId(pipelineId);
|
||||||
|
// pipelineDetails.setInstanceId(instanceId);
|
||||||
|
// pipelineDetails.setRunWay(runMsg.getRunWay());
|
||||||
|
// pipelineDetails.setAgent(runMsg.getAgent());
|
||||||
|
//
|
||||||
|
// // 流水线运行任务
|
||||||
|
// pipelineDetails.setStageList(stageList);
|
||||||
|
//
|
||||||
|
// // 流水线后置处理
|
||||||
|
// pipelineDetails.setPostprocessList(postprocessList);
|
||||||
|
//
|
||||||
|
// // 数据路径,源码,日志保存
|
||||||
|
// String sourceDir = utilService.findPipelineDefaultAddress(pipelineId,1);
|
||||||
|
// String logDir = utilService.findPipelineDefaultAddress(pipelineId,2);
|
||||||
|
// pipelineDetails.setSourceDir(sourceDir);
|
||||||
|
// pipelineDetails.setLogDir(logDir);
|
||||||
|
//
|
||||||
|
// // 环境
|
||||||
|
// List<Scm> scmList = scmService.findAllPipelineScm();
|
||||||
|
// pipelineDetails.setScmList(scmList);
|
||||||
|
//
|
||||||
|
// // 变量
|
||||||
|
// List<Variable> variableList = variableService.findAllVariable(pipelineId);
|
||||||
|
// pipelineDetails.setVariableList(variableList);
|
||||||
|
//
|
||||||
|
// AgentMessage agentMessage = new AgentMessage();
|
||||||
|
// agentMessage.setType("exec");
|
||||||
|
// agentMessage.setMessage(pipelineDetails);
|
||||||
|
// agentMessage.setPipelineId(pipelineId);
|
||||||
|
//
|
||||||
|
// Agent agent = pipelineDetails.getAgent();
|
||||||
|
//
|
||||||
|
// String id = agent.getAddress();
|
||||||
|
//
|
||||||
|
// WebSocketSession session = SocketServerHandler.sessionMap.get(id);
|
||||||
|
// if (Objects.isNull(session)) {
|
||||||
|
// throw new SystemException("客户端推送消息失败,无法获取客户端连接,客户端信息:"+id);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// SocketServerHandler.instance().sendHandleMessage(id,agentMessage);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// throw new SystemException("客户端推送消息失败,错误信息:" + e.getMessage());
|
||||||
|
// }
|
||||||
|
// }catch (Exception e){
|
||||||
|
// logger.error("流水线执行出错了:{}",e.getMessage() );
|
||||||
|
// stop(pipelineId);
|
||||||
|
// }
|
||||||
|
// return pipelineInstance;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void stop(String pipelineId){
|
||||||
|
// Pipeline pipeline = pipelineService.findPipelineById(pipelineId);
|
||||||
|
//
|
||||||
|
// Agent agent = pipelineIdOrAgentId.get(pipelineId);
|
||||||
|
// if (Objects.isNull(agent)){
|
||||||
|
// pipeline.setState(1);
|
||||||
|
// pipelineService.updatePipeline(pipeline);
|
||||||
|
//
|
||||||
|
// PipelineInstanceQuery pipelineInstanceQuery = new PipelineInstanceQuery();
|
||||||
|
// pipelineInstanceQuery.setState(PipelineFinal.RUN_RUN);
|
||||||
|
// pipelineInstanceQuery.setPipelineId(pipelineId);
|
||||||
|
// List<PipelineInstance> pipelineInstanceList = pipelineInstanceService.findPipelineInstanceList(pipelineInstanceQuery);
|
||||||
|
// for (PipelineInstance pipelineInstance : pipelineInstanceList) {
|
||||||
|
// String instanceId = pipelineInstance.getInstanceId();
|
||||||
|
// pipelineInstance.setRunStatus(PipelineFinal.RUN_HALT);
|
||||||
|
// int runtime = pipelineInstanceService.findInstanceRuntime(instanceId);
|
||||||
|
// pipelineInstance.setRunTime(runtime);
|
||||||
|
// pipelineInstanceService.updateInstance(pipelineInstance);
|
||||||
|
// }
|
||||||
|
// removeExecCache(pipelineId);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// AgentMessage agentMessage = new AgentMessage();
|
||||||
|
// agentMessage.setType("stop");
|
||||||
|
// agentMessage.setMessage(pipelineId);
|
||||||
|
// agentMessage.setPipelineId(pipelineId);
|
||||||
|
// SocketServerHandler.instance().sendHandleMessage(agent.getAddress(),agentMessage);
|
||||||
|
// }catch (Exception e){
|
||||||
|
// logger.error(e.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 添加资源配置
|
||||||
|
// // resourcesService.instanceResources(integer);
|
||||||
|
//
|
||||||
|
// // 更新流水线状态
|
||||||
|
// pipeline.setState(1);
|
||||||
|
// pipelineService.updatePipeline(pipeline);
|
||||||
|
//
|
||||||
|
// PipelineInstanceQuery pipelineInstanceQuery = new PipelineInstanceQuery();
|
||||||
|
// pipelineInstanceQuery.setState(PipelineFinal.RUN_RUN);
|
||||||
|
// pipelineInstanceQuery.setPipelineId(pipelineId);
|
||||||
|
// List<PipelineInstance> pipelineInstanceList = pipelineInstanceService.findPipelineInstanceList(pipelineInstanceQuery);
|
||||||
|
// for (PipelineInstance pipelineInstance : pipelineInstanceList) {
|
||||||
|
// pipelineInstance.setRunStatus(PipelineFinal.RUN_HALT);
|
||||||
|
// int runtime = pipelineInstanceService.findInstanceRuntime(pipelineInstance.getInstanceId());
|
||||||
|
// pipelineInstance.setRunTime(runtime);
|
||||||
|
// pipelineInstanceService.updateInstance(pipelineInstance);
|
||||||
|
// }
|
||||||
|
// removeExecCache(pipelineId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void removeExecCache(String pipelineId){
|
||||||
|
// String instanceId = pipelineIdOrInstanceId.get(pipelineId);
|
||||||
|
// PipelineInstanceServiceImpl.runTimeMap.remove(instanceId);
|
||||||
|
// pipelineInstanceService.stopThread(instanceId);
|
||||||
|
// pipelineIdOrInstanceId.remove(pipelineId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void keepOn(String pipelineId){
|
||||||
|
// Agent agent = pipelineIdOrAgentId.get(pipelineId);
|
||||||
|
// String id = agent.getAddress();
|
||||||
|
// AgentMessage agentMessage = new AgentMessage();
|
||||||
|
// agentMessage.setType("keepOn");
|
||||||
|
// agentMessage.setMessage(pipelineId);
|
||||||
|
// agentMessage.setPipelineId(pipelineId);
|
||||||
|
// WebSocketSession session = SocketServerHandler.sessionMap.get(id);
|
||||||
|
// if (Objects.isNull(session)) {
|
||||||
|
// throw new SystemException("客户端推送消息失败,无法获取客户端连接,客户端信息:"+id);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// SocketServerHandler.instance().sendHandleMessage(id,agentMessage);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// throw new SystemException("客户端推送消息失败,错误信息:" + e.getMessage());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
@ -0,0 +1,9 @@
|
|||||||
|
package cd.casic.module.process.privilege.role.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PatchUser {
|
||||||
|
private String userId;
|
||||||
|
private Integer roleType = 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user