Browse Source

feat: 获取部署历史记录的日志详情的功能拆分出来,防止日志太大影响性能

370774330@qq.com 5 years ago
parent
commit
fa02688bcd

+ 12 - 4
web/src/main/java/cn/seecoder/web/controller/pipeline/PipelineController.java

@@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.*;
 import cn.seecoder.common.exceptions.AccessDeniedException;
 import cn.seecoder.common.exceptions.AccessDeniedException;
 import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.model.vo.Response;
 import cn.seecoder.web.model.vo.Response;
-import seecoder.devcloud.web.model.vo.pipeline.*;
 import cn.seecoder.web.service.pipeline.PipelineService;
 import cn.seecoder.web.service.pipeline.PipelineService;
 
 
 import java.util.List;
 import java.util.List;
@@ -63,11 +62,20 @@ public class PipelineController {
         return Response.buildSuccess(pipelineService.retrievePipelineHistory(projectId,pipelineId));
         return Response.buildSuccess(pipelineService.retrievePipelineHistory(projectId,pipelineId));
     }
     }
 
 
+    @GetMapping("/history/details")
+    @ApiOperation(value = "获取指定一条构建信息的日志详情", httpMethod = "GET")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "historyId", dataType ="int",paramType = "query"),
+    })
+    public Response<String> retrievePipelineHistoryDetails(@RequestParam("historyId")Integer historyId) {
+        return Response.buildSuccess(pipelineService.retrievePipelineHistoryDetails(historyId));
+    }
+
 
 
     @ApiOperation(value = "依据模板创建一个流水线配置", httpMethod = "POST")
     @ApiOperation(value = "依据模板创建一个流水线配置", httpMethod = "POST")
     @ApiImplicitParam(name = "pipelineCreateVO", value = "流水线创建配置信息",dataType = "object",paramType = "body")
     @ApiImplicitParam(name = "pipelineCreateVO", value = "流水线创建配置信息",dataType = "object",paramType = "body")
     @PostMapping
     @PostMapping
-    public Response createPipelineConfig(@RequestBody @Validated PipelineCreateVO pipelineCreateVO) throws ServiceException {
+    public Response<Object> createPipelineConfig(@RequestBody @Validated PipelineCreateVO pipelineCreateVO) throws ServiceException {
         pipelineService.createPipelineConfig(pipelineCreateVO);
         pipelineService.createPipelineConfig(pipelineCreateVO);
         return Response.buildSuccess();
         return Response.buildSuccess();
     }
     }
@@ -77,7 +85,7 @@ public class PipelineController {
 
 
     @ApiImplicitParam(name = "pipelineUpdateConfigVO", dataType ="object",paramType = "body")
     @ApiImplicitParam(name = "pipelineUpdateConfigVO", dataType ="object",paramType = "body")
 
 
-    public Response savePipelineConfig(@RequestBody PipelineUpdateConfigVO pipelineUpdateConfigVO) throws AccessDeniedException {
+    public Response<Object> savePipelineConfig(@RequestBody PipelineUpdateConfigVO pipelineUpdateConfigVO) throws AccessDeniedException {
         pipelineService.savePipelineConfig(pipelineUpdateConfigVO);
         pipelineService.savePipelineConfig(pipelineUpdateConfigVO);
         return Response.buildSuccess();
         return Response.buildSuccess();
     }
     }
@@ -88,7 +96,7 @@ public class PipelineController {
             @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query"),
             @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query"),
     })
     })
     @DeleteMapping
     @DeleteMapping
-    public Response deletePipelineInfo(Integer projectId,Integer pipelineId) throws AccessDeniedException {
+    public Response<Object> deletePipelineInfo(Integer projectId,Integer pipelineId) throws AccessDeniedException {
         pipelineService.deletePipelineConfig(projectId, pipelineId);
         pipelineService.deletePipelineConfig(projectId, pipelineId);
         return Response.buildSuccess();
         return Response.buildSuccess();
     }
     }

+ 3 - 1
web/src/main/java/cn/seecoder/web/dao/pipeline/PipelineHistoryMapper.java

@@ -23,9 +23,11 @@ public interface PipelineHistoryMapper {
     int update(PipelineHistoryPO pipelineHistoryPO);
     int update(PipelineHistoryPO pipelineHistoryPO);
 
 
 
 
-    @Select("select * from pipeline_history where pipeline_id = #{pipelineId}")
+    @Select("select id, pipeline_id, start_time, user_id, result from pipeline_history where pipeline_id = #{pipelineId}")
     List<PipelineHistoryPO> selectByPipelineId(Integer pipelineId);
     List<PipelineHistoryPO> selectByPipelineId(Integer pipelineId);
 
 
+    @Select("select details from pipeline_history where id = #{id}")
+    String selectDetailsById(Integer id);
 
 
     /**
     /**
      * 获取一个项目里所有流水线配置的最新构建历史
      * 获取一个项目里所有流水线配置的最新构建历史

+ 16 - 17
web/src/main/java/cn/seecoder/web/service/impl/pipeline/PipelineServiceImpl.java

@@ -1,21 +1,18 @@
 package cn.seecoder.web.service.impl.pipeline;
 package cn.seecoder.web.service.impl.pipeline;
 
 
+import cn.seecoder.common.exceptions.ServiceException;
+import cn.seecoder.core.pipeline.PipelineException;
+import cn.seecoder.core.pipeline.template.PipelineTemplateTable;
 import cn.seecoder.web.dao.pipeline.PipelineHistoryMapper;
 import cn.seecoder.web.dao.pipeline.PipelineHistoryMapper;
 import cn.seecoder.web.dao.pipeline.PipelineMapper;
 import cn.seecoder.web.dao.pipeline.PipelineMapper;
-import cn.seecoder.web.dao.project.ProjectMapper;
 import cn.seecoder.web.dao.user.UserMapper;
 import cn.seecoder.web.dao.user.UserMapper;
 import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
 import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
 import cn.seecoder.web.model.po.pipeline.PipelinePO;
 import cn.seecoder.web.model.po.pipeline.PipelinePO;
 import cn.seecoder.web.model.po.user.UserPO;
 import cn.seecoder.web.model.po.user.UserPO;
 import cn.seecoder.web.model.vo.pipeline.*;
 import cn.seecoder.web.model.vo.pipeline.*;
+import cn.seecoder.web.service.pipeline.PipelineService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
-import cn.seecoder.common.exceptions.AccessDeniedException;
-import cn.seecoder.common.exceptions.ServiceException;
-import cn.seecoder.core.pipeline.PipelineException;
-import cn.seecoder.core.pipeline.template.PipelineTemplateTable;
-import seecoder.devcloud.web.model.vo.pipeline.*;
-import cn.seecoder.web.service.pipeline.PipelineService;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
@@ -34,22 +31,19 @@ public class PipelineServiceImpl implements PipelineService {
 
 
     private final PipelineMapper pipelineMapper;
     private final PipelineMapper pipelineMapper;
 
 
-    private final ProjectMapper projectMapper;
-
     private final UserMapper userMapper;
     private final UserMapper userMapper;
 
 
 
 
     @Autowired
     @Autowired
-    public PipelineServiceImpl(PipelineHistoryMapper pipelineHistoryMapper, PipelineMapper pipelineMapper, ProjectMapper projectMapper, UserMapper userMapper) {
+    public PipelineServiceImpl(PipelineHistoryMapper pipelineHistoryMapper, PipelineMapper pipelineMapper, UserMapper userMapper) {
         this.pipelineHistoryMapper = pipelineHistoryMapper;
         this.pipelineHistoryMapper = pipelineHistoryMapper;
         this.pipelineMapper = pipelineMapper;
         this.pipelineMapper = pipelineMapper;
-        this.projectMapper = projectMapper;
         this.userMapper = userMapper;
         this.userMapper = userMapper;
     }
     }
 
 
 
 
     @Override
     @Override
-    public List<PipelineInfoVO> retrievePipelineInfos(Integer projectId) throws AccessDeniedException {
+    public List<PipelineInfoVO> retrievePipelineInfos(Integer projectId) {
         //projectAuthentication(projectId);
         //projectAuthentication(projectId);
         // 获取项目所关联的所有流水线
         // 获取项目所关联的所有流水线
         List<PipelinePO> pipelinePOS = pipelineMapper.selectByProjectId(projectId);
         List<PipelinePO> pipelinePOS = pipelineMapper.selectByProjectId(projectId);
@@ -75,13 +69,13 @@ public class PipelineServiceImpl implements PipelineService {
     }
     }
 
 
     @Override
     @Override
-    public PipelineConfigVO retrievePipelineConfig(Integer projectId, Integer pipelineId) throws AccessDeniedException {
+    public PipelineConfigVO retrievePipelineConfig(Integer projectId, Integer pipelineId) {
         //projectAuthentication(projectId);
         //projectAuthentication(projectId);
         return new PipelineConfigVO(pipelineMapper.selectById(pipelineId));
         return new PipelineConfigVO(pipelineMapper.selectById(pipelineId));
     }
     }
 
 
     @Override
     @Override
-    public List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) throws AccessDeniedException {
+    public List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) {
         //projectAuthentication(projectId);
         //projectAuthentication(projectId);
         List<PipelineHistoryPO> histories = pipelineHistoryMapper.selectByPipelineId(pipelineId);
         List<PipelineHistoryPO> histories = pipelineHistoryMapper.selectByPipelineId(pipelineId);
         List<Integer> userIds = histories.stream().map(PipelineHistoryPO::getUserId).collect(Collectors.toList());
         List<Integer> userIds = histories.stream().map(PipelineHistoryPO::getUserId).collect(Collectors.toList());
@@ -89,10 +83,15 @@ public class PipelineServiceImpl implements PipelineService {
         return histories.stream().map(x->new PipelineHistoryVO(x,usernameMap.get(x.getUserId()))).collect(Collectors.toList());
         return histories.stream().map(x->new PipelineHistoryVO(x,usernameMap.get(x.getUserId()))).collect(Collectors.toList());
     }
     }
 
 
+    @Override
+    public String retrievePipelineHistoryDetails(Integer historyId) {
+        return pipelineHistoryMapper.selectDetailsById(historyId);
+    }
+
     @Override
     @Override
     public void createPipelineConfig(PipelineCreateVO pipelineCreateVO) throws ServiceException {
     public void createPipelineConfig(PipelineCreateVO pipelineCreateVO) throws ServiceException {
         //projectAuthentication(pipelineCreateVO.getProjectId());
         //projectAuthentication(pipelineCreateVO.getProjectId());
-        PipelinePO pipeline = null;
+        PipelinePO pipeline;
         try {
         try {
             pipeline = PipelinePO.builder()
             pipeline = PipelinePO.builder()
                     .name(pipelineCreateVO.getName())
                     .name(pipelineCreateVO.getName())
@@ -109,14 +108,14 @@ public class PipelineServiceImpl implements PipelineService {
     }
     }
 
 
     @Override
     @Override
-    public void savePipelineConfig(PipelineUpdateConfigVO pipelineUpdateConfigVO) throws AccessDeniedException {
+    public void savePipelineConfig(PipelineUpdateConfigVO pipelineUpdateConfigVO) {
         //projectAuthentication(projectId);
         //projectAuthentication(projectId);
         pipelineMapper.updateConfigJson(pipelineUpdateConfigVO.getPipelineId(),pipelineUpdateConfigVO.getConfigJson());
         pipelineMapper.updateConfigJson(pipelineUpdateConfigVO.getPipelineId(),pipelineUpdateConfigVO.getConfigJson());
 
 
     }
     }
 
 
     @Override
     @Override
-    public void deletePipelineConfig(Integer projectId, Integer pipelineId) throws AccessDeniedException {
+    public void deletePipelineConfig(Integer projectId, Integer pipelineId) {
         //projectAuthentication(projectId);
         //projectAuthentication(projectId);
         //todo 是否要连带部署实例一起删除
         //todo 是否要连带部署实例一起删除
         pipelineMapper.delete(pipelineId);
         pipelineMapper.delete(pipelineId);

+ 5 - 1
web/src/main/java/cn/seecoder/web/service/pipeline/PipelineService.java

@@ -3,7 +3,6 @@ package cn.seecoder.web.service.pipeline;
 import cn.seecoder.web.model.vo.pipeline.*;
 import cn.seecoder.web.model.vo.pipeline.*;
 import cn.seecoder.common.exceptions.AccessDeniedException;
 import cn.seecoder.common.exceptions.AccessDeniedException;
 import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.common.exceptions.ServiceException;
-import seecoder.devcloud.web.model.vo.pipeline.*;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -37,6 +36,11 @@ public interface PipelineService {
      */
      */
     List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) throws AccessDeniedException;
     List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) throws AccessDeniedException;
 
 
+    /**
+     * 获取流水线日志的详情
+     */
+    String retrievePipelineHistoryDetails(Integer historyId);
+
     /**
     /**
      * 依据模板创建一个流水线配置
      * 依据模板创建一个流水线配置
      */
      */