|
|
@@ -13,9 +13,11 @@ import seecoder.devcloud.core.pipeline.PipelineException;
|
|
|
import seecoder.devcloud.core.pipeline.PipelineFactory;
|
|
|
import seecoder.devcloud.core.pipeline.inspector.PipelineInspector;
|
|
|
import seecoder.devcloud.core.pipeline.inspector.PipelineInspectorFactory;
|
|
|
+import seecoder.devcloud.web.dao.pipeline.DeploymentMapper;
|
|
|
import seecoder.devcloud.web.dao.pipeline.PipelineHistoryMapper;
|
|
|
import seecoder.devcloud.web.dao.pipeline.PipelineMapper;
|
|
|
import seecoder.devcloud.web.dao.project.ProjectMapper;
|
|
|
+import seecoder.devcloud.web.model.po.pipeline.DeploymentPO;
|
|
|
import seecoder.devcloud.web.model.po.pipeline.PipelineHistoryPO;
|
|
|
import seecoder.devcloud.web.model.po.pipeline.PipelinePO;
|
|
|
import seecoder.devcloud.web.model.po.project.ProjectPO;
|
|
|
@@ -23,8 +25,8 @@ import seecoder.devcloud.web.model.vo.pipeline.DeploymentInfoVO;
|
|
|
import seecoder.devcloud.web.service.pipeline.DeploymentService;
|
|
|
import seecoder.devcloud.web.service.user.UserService;
|
|
|
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -43,13 +45,16 @@ public class DeploymentServiceImpl implements DeploymentService {
|
|
|
|
|
|
private final ApplicationProperties properties;
|
|
|
|
|
|
+ private final DeploymentMapper deploymentMapper;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
- public DeploymentServiceImpl(PipelineMapper pipelineMapper, PipelineHistoryMapper pipelineHistoryMapper, ProjectMapper projectMapper, ApplicationProperties properties) {
|
|
|
+ public DeploymentServiceImpl(PipelineMapper pipelineMapper, PipelineHistoryMapper pipelineHistoryMapper, ProjectMapper projectMapper, ApplicationProperties properties, DeploymentMapper deploymentMapper) {
|
|
|
this.pipelineMapper = pipelineMapper;
|
|
|
this.pipelineHistoryMapper = pipelineHistoryMapper;
|
|
|
this.projectMapper = projectMapper;
|
|
|
this.properties = properties;
|
|
|
+ this.deploymentMapper = deploymentMapper;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -60,13 +65,10 @@ public class DeploymentServiceImpl implements DeploymentService {
|
|
|
List<PipelinePO> pipelines = pipelineMapper.selectByProjectId(projectId);
|
|
|
// 获取项目所关联的所有流水线
|
|
|
List<Integer> pipelineIds = pipelines.stream().map(PipelinePO::getId).collect(Collectors.toList());
|
|
|
- // 获取流水线历史
|
|
|
- List<PipelineHistoryPO> histories = pipelineHistoryMapper.selectPipelinesRecentlyHistory(pipelineIds);
|
|
|
- Map<Integer, PipelineHistoryPO> historyMap = histories.stream().collect(Collectors.toMap(PipelineHistoryPO::getPipelineId, x->x));
|
|
|
- return pipelines.stream().map(x->{
|
|
|
- String accessUrl = x.getName()+"."+project.getName()+ properties.getK8s().getIngressHostSuffix();
|
|
|
- PipelineHistoryPO history = historyMap.get(x.getId());
|
|
|
- PipelineInspector inspector = PipelineInspectorFactory.init(project.getName(),x.getName(),x.getId(),x.getTemplateName());
|
|
|
+
|
|
|
+ List<DeploymentPO> deployments = deploymentMapper.selectByPipelineIds(pipelineIds);
|
|
|
+ return deployments.stream().map(x->{
|
|
|
+ PipelineInspector inspector = PipelineInspectorFactory.init(x.getNamespace(),x.getDeployName());
|
|
|
//获取状态
|
|
|
String status = null;
|
|
|
DeploymentStatus deploymentStatus = inspector.inspectStatus();
|
|
|
@@ -76,10 +78,10 @@ public class DeploymentServiceImpl implements DeploymentService {
|
|
|
status = "不可用: " + deploymentStatus.getProgressingMessage();
|
|
|
}
|
|
|
return DeploymentInfoVO.builder()
|
|
|
- .pipelineId(x.getId())
|
|
|
- .name(x.getName())
|
|
|
- .deployedTime(history.getStartTime())
|
|
|
- .accessUrl(accessUrl)
|
|
|
+ .pipelineId(x.getPipelineId())
|
|
|
+ .name(x.getDeployName()+"."+x.getNamespace())
|
|
|
+ .deployedTime(x.getDeployedTime())
|
|
|
+ .accessUrl(x.getAccessUrl())
|
|
|
.status(status)
|
|
|
.build();
|
|
|
}).collect(Collectors.toList());
|
|
|
@@ -88,27 +90,39 @@ public class DeploymentServiceImpl implements DeploymentService {
|
|
|
@Override
|
|
|
@Async
|
|
|
public void deploy(Integer projectId, Integer pipelineId) throws ServiceException {
|
|
|
- try {
|
|
|
- Thread.sleep(3000);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- System.out.println(Thread.currentThread().getName());
|
|
|
- System.out.println(System.currentTimeMillis());
|
|
|
-
|
|
|
//projectAuthentication(projectId);
|
|
|
PipelinePO pipelinePO = pipelineMapper.selectById(pipelineId);
|
|
|
ProjectPO projectPO = projectMapper.getProjectById(projectId);
|
|
|
+ //历史记录
|
|
|
PipelineHistoryPO history = PipelineHistoryPO.builder()
|
|
|
.result("部署中")
|
|
|
.pipelineId(pipelinePO.getId())
|
|
|
.userId(UserService.loginUser().getId())
|
|
|
.details("")
|
|
|
+ .startTime(new Timestamp(System.currentTimeMillis()))
|
|
|
.build();
|
|
|
- pipelineHistoryMapper.insert(history,"id","startTime");
|
|
|
+ pipelineHistoryMapper.insert(history);
|
|
|
+
|
|
|
+
|
|
|
+ DeploymentPO deployment = deploymentMapper.selectByPipelineId(pipelineId);
|
|
|
+ if (deployment == null){
|
|
|
+ //第一次部署
|
|
|
+ String accessUrl = pipelinePO.getName()+"."+projectPO.getUniqueK8sNamespace()+ properties.getK8s().getIngressHostSuffix();
|
|
|
+ deploymentMapper.insert(DeploymentPO.builder()
|
|
|
+ .namespace(projectPO.getUniqueK8sNamespace())
|
|
|
+ .deployName(pipelinePO.getName())
|
|
|
+ .accessUrl(accessUrl)
|
|
|
+ .pipelineId(pipelineId)
|
|
|
+ .deployedTime(history.getStartTime())
|
|
|
+ .build());
|
|
|
+ } else {
|
|
|
+ deployment.setDeployedTime(history.getStartTime());
|
|
|
+ deploymentMapper.update(deployment);
|
|
|
+ }
|
|
|
+
|
|
|
Pipeline pipeline = null;
|
|
|
try {
|
|
|
- pipeline = PipelineFactory.init(pipelinePO.getConfigJson(), projectPO.getName(), pipelinePO.getName(), pipelineId, pipelinePO.getTemplateName());
|
|
|
+ pipeline = PipelineFactory.init(pipelinePO.getConfigJson(), projectPO.getName(), pipelinePO.getName(),pipelinePO.getTemplateName());
|
|
|
pipeline.start();
|
|
|
history.setResult("部署成功");
|
|
|
history.setDetails(pipeline.getContext().getResult());
|
|
|
@@ -126,9 +140,8 @@ public class DeploymentServiceImpl implements DeploymentService {
|
|
|
@Async
|
|
|
public void delete(Integer projectId, Integer pipelineId) throws AccessDeniedException {
|
|
|
//projectAuthentication(projectId);
|
|
|
- ProjectPO project = projectMapper.getProjectById(projectId);
|
|
|
- PipelinePO pipelinePO = pipelineMapper.selectById(pipelineId);
|
|
|
- PipelineInspector inspector = PipelineInspectorFactory.init(project.getName(),pipelinePO.getName(),pipelineId,pipelinePO.getTemplateName());
|
|
|
+ DeploymentPO deployment = deploymentMapper.selectByPipelineId(pipelineId);
|
|
|
+ PipelineInspector inspector = PipelineInspectorFactory.init(deployment.getNamespace(),deployment.getDeployName());
|
|
|
inspector.delete();
|
|
|
}
|
|
|
}
|