瀏覽代碼

feat: 续上个commit,漏提交的文件

370774330@qq.com 5 年之前
父節點
當前提交
9ceb42b4fc

+ 26 - 0
web/src/main/java/cn/seecoder/web/dao/project/FuncTestRecordMapper.java

@@ -0,0 +1,26 @@
+package cn.seecoder.web.dao.project;
+
+import cn.seecoder.web.dao.provider.GeneralInsertUpdateSqlProvider;
+import cn.seecoder.web.model.po.project.FuncTestRecordPO;
+import org.apache.ibatis.annotations.InsertProvider;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/22
+ * @description:
+ */
+public interface FuncTestRecordMapper {
+
+    @InsertProvider(type = GeneralInsertUpdateSqlProvider.class, method = "insert")
+    @Options(useGeneratedKeys = true, keyProperty = "param1.id", keyColumn = "id")
+    int insert(FuncTestRecordPO funcTestRecordPO, String... ignoredCols);
+
+    @Select("select * " +
+            "from func_test_record " +
+            "where pipeline_record_id = #{historyId} ")
+    List<FuncTestRecordPO> selectByPipelineHistoryId(Integer historyId);
+}

+ 1 - 1
web/src/main/java/cn/seecoder/web/dao/provider/GeneralInsertUpdateSqlProvider.java

@@ -20,7 +20,7 @@ public class GeneralInsertUpdateSqlProvider {
      * @param ignoredCols 插入时需要忽略的列名 列名格式是Underscore,如created_at
      * @return sql
      *  插入单个参数(除了ignoredCols以外的参数)时,mapper写方法就行,实例见 UserMapper.insert
-     *  插入时填入了ignoredCols参数(比如不要id、startTime等自增、默认值字段),实例见PipelineHistoryMapper.insert
+     *  插入时填入了ignoredCols参数(比如不要id、startTime等自增、默认值字段),实例见PipelineRecordMapper.insert
      */
     public static String insert(Object obj,String... ignoredCols){
         Map<String, String> map;

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/po/pipeline/PipelineHistoryPO.java → web/src/main/java/cn/seecoder/web/model/po/pipeline/PipelineRecordPO.java

@@ -16,7 +16,7 @@ import java.sql.Timestamp;
 @AllArgsConstructor
 @NoArgsConstructor
 @Builder
-public class PipelineHistoryPO {
+public class PipelineRecordPO {
 
     /**
      * id

+ 29 - 0
web/src/main/java/cn/seecoder/web/model/po/project/FuncTestRecordPO.java

@@ -0,0 +1,29 @@
+package cn.seecoder.web.model.po.project;
+
+import cn.seecoder.web.model.enums.FuncTestOperatorEnum;
+import lombok.Builder;
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/22
+ * @description:
+ */
+@Data
+@Builder
+public class FuncTestRecordPO {
+
+    Integer id;
+
+    Timestamp timestamp;
+
+    FuncTestOperatorEnum operationType;
+
+    /**
+     * 关联的流水线部署信息id
+     */
+    Integer pipelineRecordId;
+
+}

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/vo/pipeline/DeploymentInfoVO.java

@@ -11,7 +11,7 @@ import java.sql.Timestamp;
  * @author PuHong Weng
  * @date 2021/3/11
  * @description:
- * 部署的实例的字段其实来自于pipeline和pipeline history
+ * 部署的实例的字段其实来自于pipeline和pipeline record
  * status字段也需要去取
  * 所以目前没有为部署实例编写持久化PO
  */

+ 10 - 10
web/src/main/java/cn/seecoder/web/model/vo/pipeline/PipelineInfoVO.java

@@ -1,6 +1,6 @@
 package cn.seecoder.web.model.vo.pipeline;
 
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
 import cn.seecoder.web.model.po.pipeline.PipelinePO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -43,15 +43,15 @@ public class PipelineInfoVO {
     String details;
 
     @ApiModelProperty("最后一次发起流水线构建的历史信息id")
-    Integer historyId;
-
-    public PipelineInfoVO(PipelinePO pipelinePO, PipelineHistoryPO pipelineHistoryPO, String username){
-        if (pipelineHistoryPO != null && username != null){
-            startTime = pipelineHistoryPO.getStartTime();
-            userId = pipelineHistoryPO.getUserId();
-            result = pipelineHistoryPO.getResult();
-            details = pipelineHistoryPO.getDetails();
-            historyId = pipelineHistoryPO.getId();
+    Integer recordId;
+
+    public PipelineInfoVO(PipelinePO pipelinePO, PipelineRecordPO pipelineRecordPO, String username){
+        if (pipelineRecordPO != null && username != null){
+            startTime = pipelineRecordPO.getStartTime();
+            userId = pipelineRecordPO.getUserId();
+            result = pipelineRecordPO.getResult();
+            details = pipelineRecordPO.getDetails();
+            recordId = pipelineRecordPO.getId();
             this.username = username;
         }
         name = pipelinePO.getName();

+ 3 - 3
web/src/main/java/cn/seecoder/web/model/vo/project/TestCaseVO.java → web/src/main/java/cn/seecoder/web/model/vo/project/FuncTestCaseVO.java

@@ -1,6 +1,6 @@
 package cn.seecoder.web.model.vo.project;
 
-import cn.seecoder.web.model.po.project.TestCasePO;
+import cn.seecoder.web.model.po.project.FuncTestCasePO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -19,7 +19,7 @@ import org.springframework.beans.BeanUtils;
 @NoArgsConstructor
 @AllArgsConstructor
 @ApiModel
-public class TestCaseVO {
+public class FuncTestCaseVO {
 
     @ApiModelProperty("id")
     Integer id;
@@ -33,7 +33,7 @@ public class TestCaseVO {
     @ApiModelProperty("代表这个测试用例是否通过")
     Boolean pass;
 
-    public TestCaseVO(TestCasePO po) {
+    public FuncTestCaseVO(FuncTestCasePO po) {
         BeanUtils.copyProperties(po,this);
     }
 }

+ 34 - 0
web/src/main/java/cn/seecoder/web/model/vo/project/FuncTestRecordVO.java

@@ -0,0 +1,34 @@
+package cn.seecoder.web.model.vo.project;
+
+import cn.seecoder.web.model.enums.FuncTestOperatorEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/23
+ * @description:
+ */
+@Data
+@ApiModel("测试的记录信息展示")
+public class FuncTestRecordVO {
+
+    @ApiModelProperty("id")
+    Integer id;
+
+    @ApiModelProperty("pipeline id")
+    Integer pipelineId;
+
+    @ApiModelProperty("操作时间")
+    Timestamp timestamp;
+
+    @ApiModelProperty("操作类型")
+    FuncTestOperatorEnum operationType;
+
+    @ApiModelProperty("关联的流水线部署信息id")
+    Integer pipelineRecordId;
+
+}

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/vo/project/TestStepVO.java → web/src/main/java/cn/seecoder/web/model/vo/project/FuncTestStepVO.java

@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class TestStepVO {
+public class FuncTestStepVO {
 
     @ApiModelProperty("id")
     Integer id;

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

@@ -1,11 +1,11 @@
 package cn.seecoder.web.service.impl.pipeline;
 
 import cn.seecoder.web.dao.pipeline.DeploymentMapper;
-import cn.seecoder.web.dao.pipeline.PipelineHistoryMapper;
+import cn.seecoder.web.dao.pipeline.PipelineRecordMapper;
 import cn.seecoder.web.dao.pipeline.PipelineMapper;
 import cn.seecoder.web.dao.project.ProjectMapper;
 import cn.seecoder.web.model.po.pipeline.DeploymentPO;
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
 import cn.seecoder.web.model.po.pipeline.PipelinePO;
 import cn.seecoder.web.model.po.project.ProjectPO;
 import io.kubernetes.client.openapi.models.V1DeploymentStatus;
@@ -39,7 +39,7 @@ public class DeploymentServiceImpl implements DeploymentService {
 
     private final PipelineMapper pipelineMapper;
 
-    private final PipelineHistoryMapper pipelineHistoryMapper;
+    private final PipelineRecordMapper pipelineRecordMapper;
 
     private final ProjectMapper projectMapper;
 
@@ -49,9 +49,9 @@ public class DeploymentServiceImpl implements DeploymentService {
 
 
     @Autowired
-    public DeploymentServiceImpl(PipelineMapper pipelineMapper, PipelineHistoryMapper pipelineHistoryMapper, ProjectMapper projectMapper, ApplicationProperties properties, DeploymentMapper deploymentMapper) {
+    public DeploymentServiceImpl(PipelineMapper pipelineMapper, PipelineRecordMapper pipelineRecordMapper, ProjectMapper projectMapper, ApplicationProperties properties, DeploymentMapper deploymentMapper) {
         this.pipelineMapper = pipelineMapper;
-        this.pipelineHistoryMapper = pipelineHistoryMapper;
+        this.pipelineRecordMapper = pipelineRecordMapper;
         this.projectMapper = projectMapper;
         this.properties = properties;
         this.deploymentMapper = deploymentMapper;
@@ -97,14 +97,14 @@ public class DeploymentServiceImpl implements DeploymentService {
         PipelinePO pipelinePO = pipelineMapper.selectById(pipelineId);
         ProjectPO projectPO = projectMapper.getProjectById(projectId);
         //历史记录
-        PipelineHistoryPO history = PipelineHistoryPO.builder()
+        PipelineRecordPO record = PipelineRecordPO.builder()
                 .result("部署中")
                 .pipelineId(pipelinePO.getId())
                 .userId(userId)
                 .details("")
                 .startTime(new Timestamp(System.currentTimeMillis()))
                 .build();
-        pipelineHistoryMapper.insert(history);
+        pipelineRecordMapper.insert(record);
 
 
         DeploymentPO deployment = deploymentMapper.selectByPipelineId(pipelineId);
@@ -116,31 +116,31 @@ public class DeploymentServiceImpl implements DeploymentService {
                     .deployName(pipelinePO.getName())
                     .accessUrl(accessUrl)
                     .pipelineId(pipelineId)
-                    .deployedTime(history.getStartTime())
+                    .deployedTime(record.getStartTime())
                     .build());
         } else {
-            deployment.setDeployedTime(history.getStartTime());
+            deployment.setDeployedTime(record.getStartTime());
             deploymentMapper.update(deployment);
         }
 
         Pipeline pipeline = null;
         try {
             pipeline = PipelineFactory.init(pipelinePO.getConfigJson(), projectPO.getUniqueK8sNamespace(), pipelinePO.getName());
-            pipeline.addConfig("pipelineHistoryId", history.getId().toString());
+            pipeline.addConfig("pipelineRecordId", record.getId().toString());
             pipeline.start();
-            history.setResult("部署成功");
-            history.setDetails(pipeline.getContext().getResult());
+            record.setResult("部署成功");
+            record.setDetails(pipeline.getContext().getResult());
         } catch (PipelineException e) {
-            history.setResult("部署失败");
-            history.setDetails(pipeline.getContext().getResult());
+            record.setResult("部署失败");
+            record.setDetails(pipeline.getContext().getResult());
             throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR,"应用部署失败",e);
         } catch (RuntimeException e){
             pipeline.getContext().appendErrorResult("运行时错误: ", e);
-            history.setResult("部署失败");
-            history.setDetails(pipeline.getContext().getResult());
+            record.setResult("部署失败");
+            record.setDetails(pipeline.getContext().getResult());
             throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR,"应用部署失败",e);
         } finally {
-            pipelineHistoryMapper.update(history);
+            pipelineRecordMapper.update(record);
         }
 
     }

+ 3 - 3
web/src/main/resources/sql/init.sql

@@ -171,7 +171,7 @@ create table if not exists devcloud.commit
         foreign key (user_id) references devcloud.user (id)
 );
 
-create table if not exists devcloud.pipeline_history
+create table if not exists devcloud.pipeline_record
 (
     id          int auto_increment
         primary key,
@@ -180,9 +180,9 @@ create table if not exists devcloud.pipeline_history
     user_id     int                                 null,
     result      varchar(15)                         null,
     details     longtext                            null,
-    constraint pipeline_history_pipeline_id_fk
+    constraint pipeline_record_pipeline_id_fk
         foreign key (pipeline_id) references devcloud.pipeline (id),
-    constraint pipeline_history_user_id_fk
+    constraint pipeline_record_user_id_fk
         foreign key (user_id) references devcloud.user (id)
 );
 

+ 0 - 40
web/src/test/java/cn/seecoder/web/dao/tree/TreeLogMapperTest.java

@@ -1,40 +0,0 @@
-package cn.seecoder.web.dao.tree;
-
-import cn.seecoder.web.model.po.tree.TreeLogPO;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
-import org.springframework.test.context.junit4.SpringRunner;
-import cn.seecoder.web.model.enums.OperationEnum;
-
-import java.util.List;
-
-@RunWith(SpringRunner.class)
-@MybatisTest
-@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
-public class TreeLogMapperTest {
-    @Autowired
-    TreeLogMapper treeLogMapper;
-
-    @Test
-    public void testInsertAndSelect(){
-        TreeLogPO treeLogPO = new TreeLogPO();
-        treeLogPO.setTreeId(1);
-        treeLogPO.setUserId(1);
-        treeLogPO.setUserName("test");
-        treeLogPO.setOperation(OperationEnum.START);
-        treeLogMapper.insertTreeLog(treeLogPO,"time");
-        List<TreeLogPO> logList = treeLogMapper.listTreeLogsByTreeId(1);
-        boolean res = false;
-        for(TreeLogPO log:logList){
-            if(log.equals(treeLogPO)){
-                res = true;
-                System.out.println(log);
-                break;
-            }
-        }
-        assert res;
-    }
-}