Browse Source

应用相关的 API 基本建立,后面开始调整优化

reghao 6 năm trước cách đây
mục cha
commit
bcb95017c6
39 tập tin đã thay đổi với 568 bổ sung302 xóa
  1. 1 0
      common/src/main/java/cn/reghao/autodop/common/utils/JsonUtil.java
  2. 2 2
      dagent/pom.xml
  3. 0 15
      dagent/src/main/java/cn/reghao/autodop/dagent/kvm/Kvm.java
  4. 10 0
      dagent/src/main/java/cn/reghao/autodop/dagent/kvm/KvmManager.java
  5. 8 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/caching/DeployCaching.java
  6. 58 22
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildController.java
  7. 10 19
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppOrchestrateController.java
  8. 4 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppStatusController.java
  9. 3 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/AppBuild.java
  10. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/BuildDeployEnv.java
  11. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/BuildDeployStage.java
  12. 3 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/AppDeploy.java
  13. 4 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/DeployedApp.java
  14. 18 25
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildDeployLog.java
  15. 10 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildLog.java
  16. 13 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/DeployLog.java
  17. 3 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java
  18. 2 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/deploy/DeployedAppRepository.java
  19. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/BuildLogRepository.java
  20. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/DeployLogRepository.java
  21. 76 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/LogRepository.java
  22. 25 26
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppDAO.java
  23. 2 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppOrchestrationRepository.java
  24. 59 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppRepository.java
  25. 69 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildService.java
  26. 3 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppLogManager.java
  27. 14 24
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppOrchestrateService.java
  28. 10 15
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppStatusManager.java
  29. 11 13
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java
  30. 49 44
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java
  31. 7 9
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java
  32. 1 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeployTask.java
  33. 9 8
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeployer.java
  34. 19 29
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/LogConsumer.java
  35. 2 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java
  36. 3 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CommitLog.java
  37. 20 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppBuildVO.java
  38. 10 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppToBuild.java
  39. 3 1
      dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestrationTest.java

+ 1 - 0
common/src/main/java/cn/reghao/autodop/common/utils/JsonUtil.java

@@ -17,6 +17,7 @@ import java.util.List;
  * @date 2020-01-15 17:52:23
  */
 public class JsonUtil<T> {
+    // TODO 采用 Jackson
     private static Gson gson = new Gson();
 
     /**

+ 2 - 2
dagent/pom.xml

@@ -26,11 +26,11 @@
             <version>1.0.0</version>
         </dependency>
 
-        <dependency>
+        <!--<dependency>
             <groupId>org.libvirt</groupId>
             <artifactId>libvirt</artifactId>
             <version>0.5.1</version>
-        </dependency>
+        </dependency>-->
     </dependencies>
 
     <profiles>

+ 0 - 15
dagent/src/main/java/cn/reghao/autodop/dagent/kvm/Kvm.java

@@ -1,15 +0,0 @@
-package cn.reghao.autodop.dagent.kvm;
-
-import org.libvirt.Connect;
-import org.libvirt.Domain;
-
-/**
- * @author reghao
- * @date 2020-05-08 22:37:05
- */
-public class Kvm {
-    public static void main(String[] args) throws Exception {
-        Connect conn = new Connect("test://default", true);
-        Domain domain = conn.domainLookupByName("test");
-    }
-}

+ 10 - 0
dagent/src/main/java/cn/reghao/autodop/dagent/kvm/KvmManager.java

@@ -0,0 +1,10 @@
+package cn.reghao.autodop.dagent.kvm;
+
+/**
+ * @author reghao
+ * @date 2020-05-08 22:37:05
+ */
+public class KvmManager {
+    public static void main(String[] args) throws Exception {
+    }
+}

+ 8 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/caching/DeployCaching.java

@@ -1,10 +1,12 @@
 package cn.reghao.autodop.dmaster.app.caching;
 
 import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.repository.deploy.DeployedAppRepository;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -27,15 +29,17 @@ public class DeployCaching {
     }*/
 
     @Cacheable(cacheNames = "deployedApp", key = "#appId", unless = "#result != null")
-    public DeployedApp isAppDeployed(String appId) {
-        return deployedAppRepository.findByAppId(appId);
+    public DeployedApp isAppDeployed(AppOrchestration app) {
+        return deployedAppRepository.findByApp(app);
     }
 
     @Cacheable(cacheNames = "deployedApp", unless = "#result != null")
     public List<String> deployedApps() {
-        List<DeployedApp> deployedApps = deployedAppRepository.findAll();
+        /*List<DeployedApp> deployedApps = deployedAppRepository.findAll();
         return deployedApps.stream()
                 .map(deployedApp -> deployedApp.getAppId())
-                .collect(Collectors.toList());
+                .collect(Collectors.toList());*/
+
+        return new ArrayList<>();
     }
 }

+ 58 - 22
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildController.java

@@ -1,6 +1,11 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import cn.reghao.autodop.dmaster.app.service.AppBuildService;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.CommitLog;
+import cn.reghao.autodop.dmaster.app.vo.AppToBuild;
+import cn.reghao.autodop.dmaster.app.vo.PageList;
 import cn.reghao.autodop.dmaster.app.vo.result.BuildResult;
 import cn.reghao.autodop.dmaster.app.service.OssService;
 import cn.reghao.autodop.dmaster.app.service.build.BuildDispatcher;
@@ -31,14 +36,38 @@ import java.util.stream.Collectors;
 @RestController
 @RequestMapping("/api/app")
 public class AppBuildController {
+    private AppBuildService buildService;
     private BuildDispatcher buildDispatcher;
     private OssService ossService;
 
-    public AppBuildController(BuildDispatcher buildDispatcher, OssService ossService) {
+    public AppBuildController(AppBuildService buildService, BuildDispatcher buildDispatcher, OssService ossService) {
+        this.buildService = buildService;
         this.buildDispatcher = buildDispatcher;
         this.ossService = ossService;
     }
 
+    // TODO 添加一个 from 参数来表示构建部署请求来自何处,是主动构建还是自动构建
+    @ApiOperation(value = "构建部署应用")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
+                    paramType="path", dataType = "String")
+    )
+    @PostMapping("/pipeline/{appId}")
+    public String buildAndDeploy(@PathVariable("appId") String appId) throws Exception {
+        Set<String> apps = checkArgs(appId);
+        List<BuildDeployLog> buildDeployLogs;
+        if (apps.size() == 0) {
+            return WebResult.success("ok");
+        } else {
+            buildDeployLogs = buildDispatcher.dispatch(apps, true);
+            List<DeployResult> deployResults = buildDeployLogs.stream()
+                    .map(BuildDeployLog::deployResult)
+                    .collect(Collectors.toList());
+
+            return WebResult.success(deployResults);
+        }
+    }
+
     @ApiOperation(value = "构建应用")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
@@ -71,27 +100,6 @@ public class AppBuildController {
         return null;
     }
 
-    @ApiOperation(value = "构建部署应用")
-    @ApiImplicitParams(
-            @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
-                    paramType="path", dataType = "String")
-    )
-    @PostMapping("/pipeline/{appId}")
-    public String buildAndDeploy(@PathVariable("appId") String appId) throws Exception {
-        Set<String> apps = checkArgs(appId);
-        List<BuildDeployLog> buildDeployLogs;
-        if (apps.size() == 0) {
-            return WebResult.success("ok");
-        } else {
-            buildDeployLogs = buildDispatcher.dispatch(apps, true);
-            List<DeployResult> deployResults = buildDeployLogs.stream()
-                    .map(BuildDeployLog::deployResult)
-                    .collect(Collectors.toList());
-
-            return WebResult.success(deployResults);
-        }
-    }
-
     @ApiOperation(value = "部署 OSS 资源")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
@@ -115,4 +123,32 @@ public class AppBuildController {
         String[] array = appId.replaceAll(whiteSpace, "").split(",");
         return new HashSet<>(Arrays.asList(array));
     }
+
+    @ApiOperation(value = "待构建的应用列表")
+    @GetMapping("/build/list")
+    public ResponseEntity<String> buildList(/*@RequestParam("env") String env
+            @RequestParam("page") int page, @RequestParam("size") int size*/) {
+        //PageRequest pageRequest = PageRequest.of(page-1, size);
+        List<AppToBuild> res = buildService.buildList("dev");
+
+        PageList<AppToBuild> pageList = new PageList<>();
+        pageList.setList(res);
+        pageList.setSize(res.size());
+
+        return ResponseEntity.ok().body(WebResult.success(pageList));
+    }
+
+    @ApiOperation(value = "")
+    @GetMapping("/build/commitlog")
+    public ResponseEntity<String> commitLog() {
+        List<CommitLog> res = buildService.commitLogs();
+        return ResponseEntity.ok().body(WebResult.success(res));
+    }
+
+    @ApiOperation(value = "")
+    @GetMapping("/build/buildlog")
+    public ResponseEntity<String> buildLog() {
+        List<BuildLog> res = buildService.buildLogs();
+        return ResponseEntity.ok().body(WebResult.success(res));
+    }
 }

+ 10 - 19
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppOrchestrateController.java

@@ -1,8 +1,7 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.dmaster.app.service.AppOrchestrateService;
-import cn.reghao.autodop.dmaster.app.vo.AppToBuild;
-import cn.reghao.autodop.dmaster.app.vo.PageList;
+import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
 import cn.reghao.autodop.dmaster.common.webresult.WebResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -11,8 +10,6 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-
 /**
  * @author reghao
  * @date 2019-11-27 11:29:43
@@ -36,15 +33,15 @@ public class AppOrchestrateController {
     }
 
     @ApiOperation(value = "复制项目/应用编排")
-    @PostMapping(value = "/duplicate/{type}", consumes = "application/json")
+    @PostMapping(value = "/copy/{type}", consumes = "application/json")
     public ResponseEntity<String>duplicateOrchestration(@PathVariable("type") int type,
                                          @RequestParam("from") String from,
                                          @RequestParam("to") String to) throws Exception {
-        boolean res = appOrchestrateService.duplicate(type, from, to);
+        boolean res = appOrchestrateService.copy(type, from, to);
         if (res) {
-            return ResponseEntity.ok().body(WebResult.success("复制成功"));
+            return ResponseEntity.ok().body(WebResult.success("拷贝成功"));
         } else {
-            return ResponseEntity.ok().body(WebResult.fail("复制失败"));
+            return ResponseEntity.ok().body(WebResult.fail("拷贝失败"));
         }
     }
 
@@ -84,16 +81,10 @@ public class AppOrchestrateController {
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
 
-    @ApiOperation(value = "待构建的应用列表")
-    @GetMapping("/build/list")
-    public ResponseEntity<String> buildList(/*@RequestParam("page") int page, @RequestParam("size") int size*/) {
-        //PageRequest pageRequest = PageRequest.of(page-1, size);
-        List<AppToBuild> res = appOrchestrateService.buildList();
-
-        PageList<AppToBuild> pageList = new PageList<>();
-        pageList.setList(res);
-        pageList.setSize(res.size());
-
-        return ResponseEntity.ok().body(WebResult.success(pageList));
+    @ApiOperation(value = "获取编排应用时需要用到的配置")
+    @GetMapping("/app/builds")
+    public ResponseEntity<String> getAppBuilds() {
+        AppBuildVO appBuildVO = appOrchestrateService.appBuilds();
+        return ResponseEntity.ok().body(WebResult.success(appBuildVO));
     }
 }

+ 4 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppStatusController.java

@@ -2,7 +2,7 @@ package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.common.deploy.AppStatus;
 import cn.reghao.autodop.common.dockerc.exception.DockerException;
-import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.constant.BuildDeployEnv;
 import cn.reghao.autodop.dmaster.app.service.AppStatusManager;
 import cn.reghao.autodop.dmaster.app.vo.PageList;
 import cn.reghao.autodop.dmaster.common.webresult.WebResult;
@@ -66,8 +66,9 @@ public class AppStatusController {
 
     @ApiOperation(value = "获取所有已注册应用的运行状态")
     @GetMapping("/status")
-    public ResponseEntity<String> status() throws DockerException {
-        List<AppStatus> statusList = statusManager.status();
+    public ResponseEntity<String> status(/*@RequestParam("env") String env*/) throws DockerException {
+        //String env1 = BuildDeployEnv.valueOf(env).name();
+        List<AppStatus> statusList = statusManager.status("dev");
         PageList<AppStatus> pageList = new PageList<>();
         pageList.setList(statusList);
         pageList.setSize(statusList.size());

+ 3 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/AppBuild.java

@@ -15,12 +15,12 @@ import javax.persistence.*;
 @Embeddable
 public class AppBuild {
     @ManyToOne(cascade = CascadeType.PERSIST)
-    @JoinColumn(name = "repo_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    @JoinColumn(name = "app_update_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
     private AppUpdate appUpdate;
     @ManyToOne(cascade = CascadeType.PERSIST)
-    @JoinColumn(name = "compiler_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    @JoinColumn(name = "app_compile_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
     private AppCompile appCompile;
     @ManyToOne(cascade = CascadeType.PERSIST)
-    @JoinColumn(name = "packer_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    @JoinColumn(name = "app_pack_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
     private AppPack appPack;
 }

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/BuildDeployEnv.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.entity.constant;
+
+/**
+ * 应用构建部署时所处的环境
+ *
+ * @author reghao
+ * @date 2019-10-18 14:31:29
+ */
+public enum BuildDeployEnv {
+    dev, test, prod
+}

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/AppStage.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/BuildDeployStage.java

@@ -7,6 +7,6 @@ package cn.reghao.autodop.dmaster.app.entity.constant;
  * @author reghao
  * @date 2019-10-18 14:31:29
  */
-public enum AppStage {
-    update, compile, pack, build, deploy;
+public enum BuildDeployStage {
+    update, compile, pack, build, deploy
 }

+ 3 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/AppDeploy.java

@@ -3,7 +3,7 @@ package cn.reghao.autodop.dmaster.app.entity.deploy;
 import lombok.Data;
 
 import javax.persistence.*;
-import java.util.List;
+import java.util.Set;
 
 /**
  * @author reghao
@@ -17,6 +17,6 @@ public class AppDeploy {
     private int httpPort;
     private String healthCheck;
     private String runningDir;
-    @ElementCollection
-    private List<AppLog> logs;
+    @ElementCollection(fetch = FetchType.EAGER)
+    private Set<AppLog> logs;
 }

+ 4 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/DeployedApp.java

@@ -5,9 +5,7 @@ import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import java.util.Date;
+import javax.persistence.*;
 
 /**
  * 已部署的应用(应用第一次部署时记录)
@@ -19,14 +17,8 @@ import java.util.Date;
 @EqualsAndHashCode(callSuper = false)
 @Entity
 public class DeployedApp extends BaseEntity {
-    @Column(nullable = false, unique = true)
-    private String appId;
-    private String description;
-    private String env;
+    @OneToOne(cascade = CascadeType.DETACH)
+    @JoinColumn(name = "app_orchestration_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    private AppOrchestration app;
     private String commitId;
-    private Date deployTime;
-
-    public DeployedApp() {
-        this.deployTime = new Date();
-    }
 }

+ 18 - 25
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildDeployLog.java

@@ -1,18 +1,13 @@
 package cn.reghao.autodop.dmaster.app.entity.log;
 
-import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
-import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.CommitLog;
 import cn.reghao.autodop.dmaster.app.vo.result.BuildResult;
 import cn.reghao.autodop.dmaster.app.vo.result.DeployResult;
 import cn.reghao.autodop.dmaster.app.vo.result.DeployStatus;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
 
-import javax.persistence.*;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 
 /**
  * 应用构建部署日志
@@ -21,17 +16,15 @@ import java.util.Set;
  * @date 2020-03-12 14:56:05
  */
 @Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class BuildDeployLog extends BaseEntity {
-    // TODO 是否需要关联到 AppOrchestration
-    @ManyToOne(cascade = CascadeType.PERSIST)
-    @JoinColumn(name = "app_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
-    private AppOrchestration app;
+public class BuildDeployLog {
     private BuildLog buildLog;
     // 一个应用可能会部署到多台主机
-    @ElementCollection(fetch = FetchType.EAGER)
-    private Set<DeployLog> deployLogs;
+    private List<DeployLog> deployLogs;
+
+    public BuildDeployLog(BuildLog buildLog, List<DeployLog> deployLogs) {
+        this.buildLog = buildLog;
+        this.deployLogs = deployLogs;
+    }
 
     /**
      * 构建结果
@@ -42,18 +35,18 @@ public class BuildDeployLog extends BaseEntity {
      */
     public BuildResult buildResult() {
         BuildResult buildResult = new BuildResult();
-        buildResult.setStage(this.buildLog.getStage());
-        buildResult.setCode(this.buildLog.getCode());
-        buildResult.setMsg(this.buildLog.getMsg());
+        buildResult.setStage(buildLog.getStage());
+        buildResult.setCode(buildLog.getCode());
+        buildResult.setMsg(buildLog.getMsg());
 
-        buildResult.setAppId(this.getApp().getAppId());
-        buildResult.setDescription(this.getApp().getDescription());
-        buildResult.setEnv(this.getApp().getEnv());
-        CommitLog commitLog = this.buildLog.getCommitLog();
+        buildResult.setAppId(buildLog.getApp().getAppId());
+        buildResult.setDescription(buildLog.getApp().getDescription());
+        buildResult.setEnv(buildLog.getApp().getEnv());
+        CommitLog commitLog = buildLog.getCommitLog();
         if (commitLog != null) {
             buildResult.setCommitId(commitLog.getCommitId());
         }
-        buildResult.setAppPath(this.buildLog.getAppPath());
+        buildResult.setAppPath(buildLog.getAppPath());
 
         return buildResult;
     }
@@ -67,9 +60,9 @@ public class BuildDeployLog extends BaseEntity {
      */
     public DeployResult deployResult() {
         DeployResult deployResult = new DeployResult();
-        deployResult.setAppId(this.getApp().getAppId());
-        deployResult.setDescription(this.getApp().getDescription());
-        deployResult.setEnv(this.getApp().getEnv());
+        deployResult.setAppId(this.buildLog.getApp().getAppId());
+        deployResult.setDescription(this.buildLog.getApp().getDescription());
+        deployResult.setEnv(this.buildLog.getApp().getEnv());
         CommitLog commitLog = this.buildLog.getCommitLog();
         if (commitLog != null) {
             deployResult.setCommitId(commitLog.getCommitId());

+ 10 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildLog.java

@@ -1,7 +1,10 @@
 package cn.reghao.autodop.dmaster.app.entity.log;
 
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.CommitLog;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 
 import javax.persistence.*;
@@ -15,13 +18,18 @@ import java.util.Date;
  */
 @NoArgsConstructor
 @Data
-@Embeddable
-public class BuildLog {
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class BuildLog extends BaseEntity {
     private String stage;
     // 0 - 部署成功 1 - 部署失败
     private int code;
     @Column(length = 1024)
     private String msg;
+
+    @ManyToOne(cascade = CascadeType.DETACH)
+    @JoinColumn(name = "app_orchestration_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    private AppOrchestration app;
     private CommitLog commitLog;
     private String appPath;
     private Date buildTime;

+ 13 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/DeployLog.java

@@ -1,9 +1,11 @@
 package cn.reghao.autodop.dmaster.app.entity.log;
 
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 
-import javax.persistence.Embeddable;
+import javax.persistence.*;
 import java.util.Date;
 
 /**
@@ -14,22 +16,28 @@ import java.util.Date;
  */
 @NoArgsConstructor
 @Data
-@Embeddable
-public class DeployLog {
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class DeployLog extends BaseEntity {
     // 0 - 部署成功 1 - 部署失败
     private int code;
     private String msg;
 
+    @ManyToOne(cascade = CascadeType.DETACH)
+    @JoinColumn(name = "build_log_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    private BuildLog buildLog;
     private String host;
     private Date deployTime;
 
-    public DeployLog(String host) {
+    public DeployLog(BuildLog buildLog, String host) {
+        this.buildLog = buildLog;
         this.host = host;
         this.deployTime = new Date();
         this.code = 0;
     }
 
-    public DeployLog(String host, String msg) {
+    public DeployLog(BuildLog buildLog, String host, String msg) {
+        this.buildLog = buildLog;
         this.host = host;
         this.deployTime = new Date();
         this.code = 1;

+ 3 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java

@@ -10,6 +10,8 @@ import javax.persistence.*;
 import java.util.Map;
 
 /**
+ * TODO 添加定时构建部署参数
+ *
  * @author reghao
  * @date 2020-02-28 14:11:02
  */
@@ -39,7 +41,7 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
 
     // projId 和 appBuild 二者只能存在一个
     @ManyToOne(cascade = CascadeType.PERSIST)
-    @JoinColumn(name = "proj_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
+    @JoinColumn(name = "proj_orchestration_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
     private ProjOrchestration proj;
     private AppBuild appBuild;
     private AppDeploy appDeploy;

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/deploy/DeployedAppRepository.java

@@ -1,6 +1,7 @@
 package cn.reghao.autodop.dmaster.app.repository.deploy;
 
 import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 /**
@@ -8,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
  * @date 2020-01-21 14:53:03
  */
 public interface DeployedAppRepository extends JpaRepository<DeployedApp, Long> {
-    DeployedApp findByAppId(String appId);
+    DeployedApp findByApp(AppOrchestration app);
 }

+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/BuildLogRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.dmaster.app.repository.log;
+
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2020-01-21 14:53:03
+ */
+public interface BuildLogRepository extends JpaRepository<BuildLog, Long> {
+    BuildLog findByCommitLogRemoteRepoUrlAndCommitLogCommitId(String repoUrl, String commitId);
+}

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/BuildDeployLogRepository.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/DeployLogRepository.java

@@ -1,11 +1,11 @@
 package cn.reghao.autodop.dmaster.app.repository.log;
 
-import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 /**
  * @author reghao
  * @date 2020-01-21 14:53:03
  */
-public interface BuildDeployLogRepository extends JpaRepository<BuildDeployLog, Long> {
+public interface DeployLogRepository extends JpaRepository<DeployLog, Long> {
 }

+ 76 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/LogRepository.java

@@ -0,0 +1,76 @@
+package cn.reghao.autodop.dmaster.app.repository.log;
+
+import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.deploy.DeployedAppRepository;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * @author reghao
+ * @date 2020-05-26 17:35:26
+ */
+@Repository
+public class LogRepository {
+    private BuildLogRepository buildLogRepository;
+    private DeployLogRepository deployLogRepository;
+    private DeployedAppRepository deployedAppRepository;
+    private AppOrchestrationRepository appRepository;
+
+    public LogRepository(BuildLogRepository buildLogRepository,
+                         DeployLogRepository deployLogRepository,
+                         DeployedAppRepository deployedAppRepository,
+                         AppOrchestrationRepository appRepository) {
+        this.buildLogRepository = buildLogRepository;
+        this.deployLogRepository = deployLogRepository;
+        this.deployedAppRepository = deployedAppRepository;
+        this.appRepository = appRepository;
+    }
+
+    public void saveBuildLog(BuildLog buildLog) {
+        String repo = buildLog.getCommitLog().getRemoteRepoUrl();
+        String commitId = buildLog.getCommitLog().getCommitId();
+        // 构建日志存在时不再保存
+        BuildLog entity = buildLogRepository.findByCommitLogRemoteRepoUrlAndCommitLogCommitId(repo, commitId);
+        if (entity == null) {
+            AppOrchestration app = buildLog.getApp();
+            Optional<AppOrchestration> appEntity = appRepository.findById(app.getId());
+            if (appEntity.isPresent()) {
+                buildLog.setApp(appEntity.get());
+                buildLogRepository.save(buildLog);
+            }
+        }
+    }
+
+    public void saveDeployLogs(List<DeployLog> deployLogs) {
+        deployLogRepository.saveAll(deployLogs);
+    }
+
+    public void saveDeployedApp(BuildDeployLog buildDeployLog) {
+        AppOrchestration app = buildDeployLog.getBuildLog().getApp();
+        DeployedApp deployedApp = deployedAppRepository.findByApp(app);
+        // TODO 新增或更新
+        if (deployedApp == null) {
+            deployedApp = deployedApp(buildDeployLog);
+            deployedAppRepository.save(deployedApp);
+        } else {
+            deployedApp.setCommitId(buildDeployLog.getBuildLog().getCommitLog().getCommitId());
+            deployedApp.setUpdateTime(new Date());
+            deployedAppRepository.save(deployedApp);
+        }
+    }
+
+    private DeployedApp deployedApp(BuildDeployLog buildDeployLog) {
+        DeployedApp deployedApp = new DeployedApp();
+        deployedApp.setApp(buildDeployLog.getBuildLog().getApp());
+        deployedApp.setCommitId(buildDeployLog.getBuildLog().getCommitLog().getCommitId());
+        return deployedApp;
+    }
+}

+ 25 - 26
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppDAO.java

@@ -1,7 +1,8 @@
 package cn.reghao.autodop.dmaster.app.repository.orchestration;
 
+import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
 import org.hibernate.Session;
-import org.springframework.stereotype.Service;
+import org.springframework.stereotype.Repository;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
@@ -11,7 +12,7 @@ import java.util.List;
  * @author reghao
  * @date 2020-03-02 16:45:12
  */
-@Service
+@Repository
 public class AppDAO {
     private EntityManager em;
 
@@ -19,36 +20,34 @@ public class AppDAO {
         this.em = em;
     }
 
-    public void findByAppId(String appId) {
+    public List findBuildApps(String env) {
         try (Session session = (Session) em.getDelegate()) {
-            Query query = session
-                    .createQuery("select app from AppOrchestration app where app.appId = :appId")
-                    .setParameter("appId", appId);
+            // 实际执行 cross join
+            String hql = "select app.appId,app.env,log.buildLog.commitLog.commitId,log.buildLog.commitLog.commitAuthor,log.buildLog.commitLog.commitMsg " +
+                    "from AppOrchestration app,BuildDeployLog log " +
+                    "where log.app = app and app.enable=:enable and app.env=:env " +
+                    "group by app.appId";
+
+            Query hqlQuery = session.createQuery(hql)
+                    .setParameter("enable", true)
+                    .setParameter("env", env);
 
-            Object obj = query.getSingleResult();
+            return hqlQuery.getResultList();
         }
     }
 
-    public List findBuildApps() {
+    public List<DeployedApp> findDeployedApps(String env) {
         try (Session session = (Session) em.getDelegate()) {
-            String hql = "select app.appId,log1.commitId,log1.commitMsg, log1.commitAuthor from AppOrchestration app " +
-                    "inner join BuildDeployLog log " +
-                    "inner join CommitLog log1 " +
-                    "on app.appId = log.appId and log.buildLog.commitLog =log1 " +
-                    "where app.enable=true " +
-                    "group by app.appId";
-            Query query = session.createQuery(hql);
-
-            String sql = "select app.app_id,log1.commit_id,log1.commit_msg,log1.commit_author from app_orchestration app \n" +
-                    "inner join build_deploy_log log\n" +
-                    "inner join commit_log log1\n" +
-                    "on app.app_id=log.app_id and log.commit_log_id=log1.id\n" +
-                    "where app.enable=1\n" +
-                    "group by app.app_id";
-            Query sqlQuery = session.createSQLQuery(sql);
-
-            List list = sqlQuery.getResultList();
-            return list;
+            // 实际执行 cross join
+            String hql = "select deployed from DeployedApp deployed " +
+                    "inner join AppOrchestration app " +
+                    "on deployed.app=app " +
+                    "where app.env=:env ";
+
+            Query hqlQuery = session.createQuery(hql)
+                    .setParameter("env", env);
+
+            return hqlQuery.getResultList();
         }
     }
 }

+ 2 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppOrchestrationRepository.java

@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 
 import javax.transaction.Transactional;
+import java.util.List;
 
 /**
  *
@@ -13,6 +14,7 @@ import javax.transaction.Transactional;
  */
 public interface AppOrchestrationRepository extends JpaRepository<AppOrchestration, Long> {
     AppOrchestration findByAppId(String appId);
+    List<AppOrchestration> findAllByEnableIsTrue();
 
     @Modifying
     @Transactional

+ 59 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppRepository.java

@@ -0,0 +1,59 @@
+package cn.reghao.autodop.dmaster.app.repository.orchestration;
+
+import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
+import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
+import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.build.AppCompileRepository;
+import cn.reghao.autodop.dmaster.app.repository.build.AppPackRepository;
+import cn.reghao.autodop.dmaster.app.repository.build.AppUpdateRepository;
+import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author reghao
+ * @date 2020-06-01 11:09:06
+ */
+@Repository
+public class AppRepository {
+    private AppUpdateRepository updateRepository;
+    private AppCompileRepository compileRepository;
+    private AppPackRepository packRepository;
+    private AppOrchestrationRepository orchestrationRepository;
+    private ProjectOrchestrationRepository projRepository;
+
+    public AppRepository(AppUpdateRepository updateRepository,
+                         AppCompileRepository compileRepository,
+                         AppPackRepository packRepository,
+                         ProjectOrchestrationRepository projRepository,
+                         AppOrchestrationRepository orchestrationRepository) {
+        this.updateRepository = updateRepository;
+        this.compileRepository = compileRepository;
+        this.packRepository = packRepository;
+        this.orchestrationRepository = orchestrationRepository;
+        this.projRepository = projRepository;
+    }
+
+    public AppBuildVO appBuilds() {
+        List<AppUpdate> appUpdates = updateRepository.findAll();
+        List<AppCompile> appCompiles = compileRepository.findAll();
+        List<AppPack> appPacks = packRepository.findAll();
+
+        AppBuildVO appBuildVO = new AppBuildVO();
+        appBuildVO.setAppUpdates(appUpdates);
+        appBuildVO.setAppCompiles(appCompiles);
+        appBuildVO.setAppPacks(appPacks);
+
+        return appBuildVO;
+    }
+
+    public void projIds(AppBuildVO appBuildVO) {
+        List<String> projIds = projRepository.findAll().stream()
+                .map(ProjOrchestration::getProjId)
+                .collect(Collectors.toList());
+        appBuildVO.setProjIds(projIds);
+    }
+}

+ 69 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildService.java

@@ -0,0 +1,69 @@
+package cn.reghao.autodop.dmaster.app.service;
+
+import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.log.BuildLogRepository;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.*;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.CommitLog;
+import cn.reghao.autodop.dmaster.app.vo.AppToBuild;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 17:10:37
+ */
+@Service
+public class AppBuildService {
+    private AppOrchestrationRepository appRepository;
+    private BuildLogRepository logRepository;
+    private AppDAO appDAO;
+
+    public AppBuildService(AppOrchestrationRepository appRepository, BuildLogRepository logRepository,
+                           AppDAO appDAO) {
+        this.appRepository = appRepository;
+        this.logRepository = logRepository;
+        this.appDAO = appDAO;
+    }
+
+    public List<AppToBuild> buildList(String env) {
+        List<AppOrchestration> apps = appRepository.findAllByEnableIsTrue();
+        Set<String> appIds = apps.stream()
+                .filter(app -> app.getEnv().equals(env))
+                .map(AppOrchestration::getAppId)
+                .collect(Collectors.toSet());
+
+        List list = appDAO.findBuildApps(env);
+        List<AppToBuild> appToBuilds = new ArrayList<>();
+        list.forEach(object -> {
+            Object[] objects = (Object[]) object;
+            appIds.remove(String.valueOf(objects[0]));
+            appToBuilds.add(new AppToBuild(String.valueOf(objects[0]), String.valueOf(objects[1]),
+                    String.valueOf(objects[2]), String.valueOf(objects[3])));
+        });
+
+        appIds.forEach(appId -> {
+            appToBuilds.add(new AppToBuild(appId, env));
+        });
+
+        return appToBuilds;
+    }
+
+    public List<CommitLog> commitLogs() {
+        List<CommitLog> commitLogs = logRepository.findAll().stream()
+                .map(BuildLog::getCommitLog)
+                .collect(Collectors.toList());
+
+        return commitLogs;
+    }
+
+    public List<BuildLog> buildLogs() {
+        return null;
+    }
+}

+ 3 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppLogManager.java

@@ -10,6 +10,7 @@ import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * 应用日志管理
@@ -31,7 +32,7 @@ public class AppLogManager {
     public List<String> logFiles(String appId, String logType, String logLevel) throws Exception {
         AppOrchestration app = caching.findByAppId(appId);
         AppDeploy appDeploy = app.getAppDeploy();
-        List<AppLog> appLogs = appDeploy.getLogs();
+        Set<AppLog> appLogs = appDeploy.getLogs();
         if (appLogs.isEmpty()) {
             throw new Exception("日志未配置");
         }
@@ -61,7 +62,7 @@ public class AppLogManager {
     public List<String> logContent(String appId, String logType, String logLevel, String logName) throws Exception {
         AppOrchestration app = caching.findByAppId(appId);
         AppDeploy appDeploy = app.getAppDeploy();
-        List<AppLog> appLogs = appDeploy.getLogs();
+        Set<AppLog> appLogs = appDeploy.getLogs();
         if (appLogs.isEmpty()) {
             throw new Exception("日志未配置");
         }

+ 14 - 24
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppOrchestrateService.java

@@ -11,20 +11,15 @@ import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.repository.build.AppCompileRepository;
 import cn.reghao.autodop.dmaster.app.repository.build.AppPackRepository;
 import cn.reghao.autodop.dmaster.app.repository.build.AppUpdateRepository;
-import cn.reghao.autodop.dmaster.app.repository.orchestration.AppDAO;
-import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
-import cn.reghao.autodop.dmaster.app.repository.orchestration.NotificationRepository;
-import cn.reghao.autodop.dmaster.app.repository.orchestration.ProjectOrchestrationRepository;
-import cn.reghao.autodop.dmaster.app.vo.AppToBuild;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.*;
+import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
 import cn.reghao.autodop.dmaster.app.vo.PageList;
 import cn.reghao.autodop.dmaster.app.vo.ResultVO;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @author reghao
@@ -38,7 +33,7 @@ public class AppOrchestrateService {
     private AppCompileRepository appCompileRepository;
     private AppPackRepository appPackRepository;
     private NotificationRepository notificationRepository;
-    private AppDAO appDAO;
+    private AppRepository repository;
 
     public AppOrchestrateService(ProjectOrchestrationRepository projRepository,
                                  AppOrchestrationRepository appRepository,
@@ -46,14 +41,14 @@ public class AppOrchestrateService {
                                  AppCompileRepository appCompileRepository,
                                  AppPackRepository appPackRepository,
                                  NotificationRepository notificationRepository,
-                                 AppDAO appDAO) {
+                                 AppRepository repository) {
         this.projRepository = projRepository;
         this.appRepository = appRepository;
         this.appUpdateRepository = appUpdateRepository;
         this.appCompileRepository = appCompileRepository;
         this.appPackRepository = appPackRepository;
         this.notificationRepository = notificationRepository;
-        this.appDAO = appDAO;
+        this.repository = repository;
     }
 
     public void add(int type, String json) {
@@ -100,7 +95,7 @@ public class AppOrchestrateService {
         appRepository.save(app);
     }
 
-    public boolean duplicate(int type, String from, String to) throws Exception {
+    public boolean copy(int type, String from, String to) throws Exception {
         switch (type) {
             case 1:
                 ProjOrchestration projEntity = projRepository.findByProjId(from);
@@ -210,18 +205,6 @@ public class AppOrchestrateService {
         }
     }
 
-    public List<AppToBuild> buildList() {
-        List list = appDAO.findBuildApps();
-        List<AppToBuild> appToBuilds = new ArrayList<>();
-        list.forEach(object -> {
-            Object[] objects = (Object[]) object;
-            appToBuilds.add(new AppToBuild(String.valueOf(objects[0]), String.valueOf(objects[1]),
-                    String.valueOf(objects[2]), String.valueOf(objects[3])));
-        });
-
-        return appToBuilds;
-    }
-
     public boolean modify(int type, String json) {
         switch (type) {
             case 1:
@@ -238,6 +221,7 @@ public class AppOrchestrateService {
                     return true;
                 }
             case 2:
+                // TODO 若修改了部署的 host,需要额外的处理
                 AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
                 String appId = app.getAppId();
                 AppOrchestration appEntity = appRepository.findByAppId(appId);
@@ -270,4 +254,10 @@ public class AppOrchestrateService {
             default:
         }
     }
+
+    public AppBuildVO appBuilds() {
+        AppBuildVO appBuildVO = repository.appBuilds();
+        repository.projIds(appBuildVO);
+        return appBuildVO;
+    }
 }

+ 10 - 15
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppStatusManager.java

@@ -4,9 +4,10 @@ import cn.reghao.autodop.common.deploy.AppStatus;
 import cn.reghao.autodop.common.dockerc.exception.DockerException;
 import cn.reghao.autodop.common.grpc.client.GrpcClientProxy;
 import cn.reghao.autodop.common.grpc.facade.app.AppStatusService;
-import cn.reghao.autodop.dmaster.app.caching.DeployCaching;
 import cn.reghao.autodop.dmaster.app.caching.OrchestrationCaching;
+import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.AppDAO;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Service;
 
@@ -23,11 +24,11 @@ import java.util.List;
 public class AppStatusManager {
     private final int GRPC_PORT = 4001;
     private OrchestrationCaching caching;
-    private DeployCaching deployCaching;
+    private AppDAO appDAO;
 
-    public AppStatusManager(OrchestrationCaching caching, DeployCaching deployCaching) {
+    public AppStatusManager(OrchestrationCaching caching, AppDAO appDAO) {
         this.caching = caching;
-        this.deployCaching = deployCaching;
+        this.appDAO = appDAO;
     }
 
     public void run(String appId, String commitId) throws DockerException {
@@ -74,23 +75,17 @@ public class AppStatusManager {
         }
     }
 
-    public List<AppStatus> status() throws DockerException {
+    public List<AppStatus> status(String env) throws DockerException {
         List<AppStatus> appStatusList = new ArrayList<>();
-        List<String> appIds = deployCaching.deployedApps();
-
-        List<AppOrchestration> apps = new ArrayList<>();
-        appIds.forEach(appId -> {
-            apps.add(caching.findByAppId(appId));
-        });
-
+        List<DeployedApp> deployedApps = appDAO.findDeployedApps(env);
         // TODO 异步处理
-        for (AppOrchestration app : apps) {
-            String[] hosts = app.getAppDeploy().getHosts().split(",");
+        for (DeployedApp deployedApp : deployedApps) {
+            String[] hosts = deployedApp.getApp().getAppDeploy().getHosts().split(",");
             for (String host : hosts) {
                 AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                         .getProxy(host, GRPC_PORT, AppStatusService.class);
 
-                Object object = appStatusService.status(app.getAppId());
+                Object object = appStatusService.status(deployedApp.getApp().getAppId());
                 JSONObject jsonObject = (JSONObject) object;
                 AppStatus status = jsonObject.toJavaObject(AppStatus.class);
                 status.setHost(host);

+ 11 - 13
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java

@@ -1,6 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.dmaster.app.entity.constant.AppStage;
+import cn.reghao.autodop.dmaster.app.entity.constant.BuildDeployStage;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
 
 import java.util.concurrent.Callable;
@@ -44,22 +44,20 @@ public class AppBuildPipeline implements Callable<BuildDeployLog> {
         if (!appIntegrate.pack()) {
             return appIntegrate.log();
         }
+        buildSuccessfully();
 
-        if (isDeploy && !appIntegrate.deploy()) {
+        if (isDeploy) {
+            appIntegrate.deploy();
             return appIntegrate.log();
         }
 
-        BuildDeployLog buildDeployLog = appIntegrate.log();
-        if (!isDeploy) {
-            buildDeployLog.getBuildLog().setStage(AppStage.build.name());
-            buildDeployLog.getBuildLog().setCode(0);
-            buildDeployLog.getBuildLog().setMsg("构建成功");
-        } else {
-            buildDeployLog.getBuildLog().setStage(AppStage.deploy.name());
-            buildDeployLog.getBuildLog().setCode(0);
-            buildDeployLog.getBuildLog().setMsg("部署成功");
-        }
-
         return appIntegrate.log();
     }
+
+    private void buildSuccessfully() {
+        BuildDeployLog buildDeployLog = appIntegrate.log();
+        buildDeployLog.getBuildLog().setStage(BuildDeployStage.build.name());
+        buildDeployLog.getBuildLog().setCode(0);
+        buildDeployLog.getBuildLog().setMsg("构建成功");
+    }
 }

+ 49 - 44
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -4,13 +4,14 @@ import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
 import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
 import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
 import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
-import cn.reghao.autodop.dmaster.app.entity.constant.AppStage;
+import cn.reghao.autodop.dmaster.app.entity.constant.BuildDeployStage;
 import cn.reghao.autodop.dmaster.app.entity.constant.CompilerType;
 import cn.reghao.autodop.common.deploy.PackerType;
 import cn.reghao.autodop.dmaster.app.entity.constant.RepoType;
 import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
@@ -23,6 +24,9 @@ import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
 import cn.reghao.autodop.dmaster.common.config.SysConfig;
 import lombok.extern.slf4j.Slf4j;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * 应用构建部署,根据 AppOrchestration 的值完成应用构建和部署的配置
  *
@@ -39,6 +43,8 @@ public class AppIntegrate {
     private ProjOrchestration proj;
     // 远程仓库最近一次提交的信息
     private CommitLog lastCommitLog;
+    private BuildLog buildLog;
+    private List<DeployLog> deployLogs;
     private BuildDeployLog buildDeployLog;
 
     private CodeUpdater codeUpdater;
@@ -68,7 +74,7 @@ public class AppIntegrate {
 
     private void init() {
         initLocalDir();
-        initBuildDeployLog();
+        initBuildLog();
         initBuildDeployConfig();
     }
 
@@ -78,9 +84,9 @@ public class AppIntegrate {
         appPackDir = SysConfig.packDir + "/" + app.getAppId();
     }
 
-    private void initBuildDeployLog() {
-        buildDeployLog = new BuildDeployLog();
-        buildDeployLog.setApp(app);
+    private void initBuildLog() {
+        buildLog = new BuildLog();
+        buildLog.setApp(app);
     }
 
     private void initBuildDeployConfig() {
@@ -118,11 +124,11 @@ public class AppIntegrate {
         }
 
         // TODO 特定于 dnkt-mgr 项目的处理
-        if ("dnkt-mgr".equals(app.getAppId())) {
+        if (app.getAppId().startsWith("dnkt-mgr")) {
             codePacker = new DntkMgrDockerPack(appPack.getPackerPath(), app.getEnv());
         }
 
-        // 初始化部署配置
+        // TODO 初始化部署配置
         AppDeploy appDeploy = app.getAppDeploy();
     }
 
@@ -139,17 +145,6 @@ public class AppIntegrate {
         preCompile.preCompile(app, appEntryDir);
     }
 
-    /**
-     * 构建部署日志
-     *
-     * @param
-     * @return
-     * @date 2020-05-15 上午11:31
-     */
-    public BuildDeployLog log() {
-        return this.buildDeployLog;
-    }
-
     public boolean update() {
         try {
             if (lastCommitLog == null) {
@@ -163,28 +158,33 @@ public class AppIntegrate {
                 updateStatus = updateApp();
             }
             lastCommitLog = updateStatus.getLastCommitLog();
-            BuildLog buildLog = new BuildLog();
             buildLog.setCommitLog(lastCommitLog);
-            buildDeployLog.setBuildLog(buildLog);
 
             if (updateStatus.isUpdated()) {
                 BuilderUtil.copyToCompileDir(appLocalRepo, app);
                 return true;
             } else {
-                buildDeployLog.getBuildLog().setStage(AppStage.update.name());
-                buildDeployLog.getBuildLog().setCode(0);
-                buildDeployLog.getBuildLog().setMsg("应用代码未更新");
+                buildLog.setStage(BuildDeployStage.update.name());
+                buildLog.setCode(0);
+                buildLog.setMsg("应用代码未更新");
                 return false;
             }
         } catch (Exception e) {
             e.printStackTrace();
-            buildDeployLog.getBuildLog().setStage(AppStage.update.name());
-            buildDeployLog.getBuildLog().setCode(1);
-            buildDeployLog.getBuildLog().setMsg(e.getMessage());
+            buildLog.setStage(BuildDeployStage.update.name());
+            buildLog.setCode(1);
+            buildLog.setMsg(e.getMessage());
             return false;
         }
     }
 
+    /**
+     * TODO 拉取应用所在项目的所有代码,后期应该优化
+     *
+     * @param
+     * @return
+     * @date 2020-05-28 下午3:28
+     */
     private AppUpdateStatus updateProj() throws Exception {
         String remoteRepo = proj.getProjRepo();
         codeUpdater.update(remoteRepo, appLocalRepo);
@@ -229,9 +229,9 @@ public class AppIntegrate {
             return true;
         } catch (Exception e) {
             e.printStackTrace();
-            buildDeployLog.getBuildLog().setStage(AppStage.compile.name());
-            buildDeployLog.getBuildLog().setCode(1);
-            buildDeployLog.getBuildLog().setMsg(e.getMessage());
+            buildLog.setStage(BuildDeployStage.compile.name());
+            buildLog.setCode(1);
+            buildLog.setMsg(e.getMessage());
             return false;
         }
     }
@@ -240,27 +240,32 @@ public class AppIntegrate {
         try {
             String appPath = codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(),
                     appCompileDir + app.getEntryDir());
-            buildDeployLog.getBuildLog().setAppPath(appPath);
+            buildLog.setAppPath(appPath);
+            buildLog.setBuildTime(new Date());
             return true;
         } catch (Exception e) {
             e.printStackTrace();
-            buildDeployLog.getBuildLog().setStage(AppStage.pack.name());
-            buildDeployLog.getBuildLog().setCode(1);
-            buildDeployLog.getBuildLog().setMsg(e.getMessage());
+            buildLog.setStage(BuildDeployStage.pack.name());
+            buildLog.setCode(1);
+            // TODO 提取错误信息
+            buildLog.setMsg(e.getMessage());
             return false;
         }
     }
 
-    public boolean deploy() {
-        try {
-            AppDeployer.deploy(app, buildDeployLog);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            buildDeployLog.getBuildLog().setStage(AppStage.deploy.name());
-            buildDeployLog.getBuildLog().setCode(1);
-            buildDeployLog.getBuildLog().setMsg(e.getMessage());
-            return false;
-        }
+    public void deploy() {
+        deployLogs = AppDeployer.deploy(app, buildLog);
+    }
+
+    /**
+     * 构建部署日志
+     *
+     * @param
+     * @return
+     * @date 2020-05-15 上午11:31
+     */
+    public BuildDeployLog log() {
+        buildDeployLog = new BuildDeployLog(buildLog, deployLogs);
+        return buildDeployLog;
     }
 }

+ 7 - 9
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java

@@ -1,12 +1,10 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.dmaster.app.caching.DeployCaching;
 import cn.reghao.autodop.dmaster.app.caching.OrchestrationCaching;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
-import cn.reghao.autodop.dmaster.app.repository.deploy.DeployedAppRepository;
-import cn.reghao.autodop.dmaster.app.repository.log.BuildDeployLogRepository;
+import cn.reghao.autodop.dmaster.app.repository.log.LogRepository;
 import cn.reghao.autodop.dmaster.app.service.log.LogConsumer;
 import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
 import lombok.extern.slf4j.Slf4j;
@@ -26,14 +24,14 @@ import java.util.concurrent.*;
 public class BuildDispatcher {
     private OrchestrationCaching caching;
     private LogConsumer logConsumer;
+    private ExecutorService threadPool;
 
     public BuildDispatcher(OrchestrationCaching caching,
-                           DeployCaching deployCaching,
-                           BuildDeployLogRepository logRepository,
-                           DeployedAppRepository deployedAppRepository) {
+                           LogRepository logDAO) {
         this.caching = caching;
-        this.logConsumer = new LogConsumer(deployCaching, logRepository, deployedAppRepository);
-        ThreadPoolWrapper.threadPool("log").submit(logConsumer);
+        this.logConsumer = new LogConsumer(logDAO);
+        this.threadPool = ThreadPoolWrapper.threadPool("app-build-deploy");
+        threadPool.submit(logConsumer);
     }
 
     /**
@@ -67,7 +65,7 @@ public class BuildDispatcher {
 
         // TODO 缓存 appIntegrates,AppOrchestration 没有变化时 AppIntegrate 也应该不变
         List<AppIntegrate> appIntegrates = appIntegrates(existApps);
-        ExecutorService threadPool = ThreadPoolWrapper.threadPool("dispatcher");
+        //ExecutorService threadPool = ThreadPoolWrapper.threadPool("dispatcher");
         List<Future<BuildDeployLog>> appFutures = new ArrayList<>();
         appIntegrates.forEach(appIntegrate -> {
             appFutures.add(threadPool.submit(new AppBuildPipeline(appIntegrate, isDeploy)));

+ 1 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeployTask.java

@@ -21,6 +21,7 @@ public class AppDeployTask implements Callable<Boolean> {
         this.deployConfig = deployConfig;
     }
 
+    // 异常在 Future 中抛出
     @Override
     public Boolean call() throws Exception {
         // TODO 公共网络下,gRPC 调用需要经过认证

+ 9 - 8
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeployer.java

@@ -7,7 +7,7 @@ import cn.reghao.autodop.common.utils.JsonUtil;
 import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
 import cn.reghao.autodop.dmaster.app.entity.constant.NotifierType;
 import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
-import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
 import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
@@ -32,7 +32,7 @@ public class AppDeployer {
      * @return
      * @date 2020-03-13 下午1:00
      */
-    public static void deploy(AppOrchestration app, BuildDeployLog buildDeployLog) {
+    public static List<DeployLog> deploy(AppOrchestration app, BuildLog buildLog) {
         Notification notification = app.getNotification();
         String notifierType = notification.getNotifierType();
         String dest = notification.getDestination();
@@ -48,7 +48,7 @@ public class AppDeployer {
         for (String host : hosts) {
             DeployConfig deployConfig = new DeployConfig();
             deployConfig.setAppId(app.getAppId());
-            deployConfig.setAppPath(buildDeployLog.getBuildLog().getAppPath());
+            deployConfig.setAppPath(buildLog.getAppPath());
             deployConfig.setPackerType(appPack.getPackerType());
             deployConfig.setHost(host);
             deployConfig.setRunningDir(appDeploy.getRunningDir());
@@ -56,7 +56,7 @@ public class AppDeployer {
             futureMap.put(host, threadPool.submit(new AppDeployTask(deployConfig)));
         }
 
-        Set<DeployLog> deployLogs = new LinkedHashSet<>();
+        List<DeployLog> deployLogs = new ArrayList<>();
         for (Map.Entry<String, Future<Boolean>> entry : futureMap.entrySet()) {
             String host = entry.getKey();
             Future<Boolean> future = entry.getValue();
@@ -73,11 +73,11 @@ public class AppDeployer {
             try {
                 Boolean isDeploy = future.get();
                 if (isDeploy) {
-                    deployLogs.add(new DeployLog(host));
+                    deployLogs.add(new DeployLog(buildLog, host));
                 }
             } catch (Exception e) {
                 e.printStackTrace();
-                deployLogs.add(new DeployLog(host, e.getMessage()));
+                deployLogs.add(new DeployLog(buildLog, host, e.getMessage()));
             }
         }
 
@@ -88,13 +88,14 @@ public class AppDeployer {
 
         DeployMsg deployMsg = new DeployMsg();
         deployMsg.setAppId(app.getAppId());
-        deployMsg.setCommitId(buildDeployLog.getBuildLog().getCommitLog().getCommitId());
+        deployMsg.setCommitId(buildLog.getCommitLog().getCommitId());
         deployMsg.setHosts(sb.toString());
         // TODO 异步发送通知
         notify.send(dest, JsonUtil.objectToJson(deployMsg));
 
         // TODO 部署成功后记录到数据库
-        buildDeployLog.setDeployLogs(deployLogs);
+        //buildDeployLog.setDeployLogs(deployLogs);
+        return deployLogs;
     }
 
     @Data

+ 19 - 29
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/LogConsumer.java

@@ -1,12 +1,13 @@
 package cn.reghao.autodop.dmaster.app.service.log;
 
-import cn.reghao.autodop.dmaster.app.caching.DeployCaching;
-import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
+import cn.reghao.autodop.dmaster.app.entity.constant.BuildDeployStage;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployLog;
-import cn.reghao.autodop.dmaster.app.repository.deploy.DeployedAppRepository;
-import cn.reghao.autodop.dmaster.app.repository.log.BuildDeployLogRepository;
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
+import cn.reghao.autodop.dmaster.app.repository.log.LogRepository;
 import lombok.extern.slf4j.Slf4j;
 
+import java.util.List;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -19,47 +20,36 @@ import java.util.concurrent.LinkedBlockingQueue;
 @Slf4j
 public class LogConsumer implements Runnable {
     private static BlockingQueue<BuildDeployLog> queue = new LinkedBlockingQueue<>();
-    private DeployCaching deployCaching;
-    private BuildDeployLogRepository logRepository;
-    private DeployedAppRepository deployedAppRepository;
+    private LogRepository logDAO;
 
-    public LogConsumer(DeployCaching deployCaching,
-                       BuildDeployLogRepository logRepository,
-                       DeployedAppRepository deployedAppRepository) {
-        this.deployCaching = deployCaching;
-        this.logRepository = logRepository;
-        this.deployedAppRepository = deployedAppRepository;
+    public LogConsumer(LogRepository logDAO) {
+        this.logDAO = logDAO;
     }
 
     public void addLog(BuildDeployLog log) {
         queue.add(log);
     }
 
-    public DeployedApp deployedApp(BuildDeployLog buildDeployLog) {
-        DeployedApp deployedApp = new DeployedApp();
-        deployedApp.setAppId(buildDeployLog.getApp().getAppId());
-        deployedApp.setDescription(buildDeployLog.getApp().getDescription());
-        deployedApp.setEnv(buildDeployLog.getApp().getEnv());
-        deployedApp.setCommitId(buildDeployLog.getBuildLog().getCommitLog().getCommitId());
-
-        return deployedApp;
-    }
-
     @Override
     public void run() {
         log.info("构建部署日志持久化线程已启动...");
         while (!Thread.interrupted()) {
             try {
                 BuildDeployLog buildDeployLog = queue.take();
-                logRepository.save(buildDeployLog);
+                BuildLog buildLog = buildDeployLog.getBuildLog();
+                logDAO.saveBuildLog(buildLog);
+                List<DeployLog> deployLogs = buildDeployLog.getDeployLogs();
+                if (deployLogs != null && !deployLogs.isEmpty()) {
+                    logDAO.saveDeployLogs(deployLogs);
+                }
 
-                String appId = buildDeployLog.getApp().getAppId();
-                DeployedApp deployedApp = deployCaching.isAppDeployed(appId);
-                if (deployedApp == null) {
-                    deployedAppRepository.save(deployedApp(buildDeployLog));
+                String stage = buildDeployLog.getBuildLog().getStage();
+                int code = buildDeployLog.getBuildLog().getCode();
+                if (stage.equals(BuildDeployStage.deploy.name()) && code == 0) {
+                    logDAO.saveDeployedApp(buildDeployLog);
                 }
 
-                log.info("{} 构建部署日志已入库...", buildDeployLog.getApp().getAppId());
+                log.info("{} 构建部署日志已入库...", buildDeployLog.getBuildLog().getApp().getAppId());
             } catch (InterruptedException e) {
                 // 中断线程
                 Thread.currentThread().interrupt();

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java

@@ -2,6 +2,7 @@ package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.shell.ShellExecutor;
 import cn.reghao.autodop.common.shell.ShellResult;
+import cn.reghao.autodop.common.utils.JsonUtil;
 import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
 
 import java.util.HashMap;
@@ -30,7 +31,7 @@ public class ShellCompiler implements CodeCompiler {
             Map<String, List<String>> map = new HashMap<>();
             map.put("stdout", result.getStdout());
             map.put("stderr", result.getStderr());
-            throw new Exception(map.toString());
+            throw new Exception(JsonUtil.objectToJson(map));
         }
     }
 }

+ 3 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CommitLog.java

@@ -1,8 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.tools.updater;
 
-import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
 
 import javax.persistence.*;
 import java.util.List;
@@ -16,13 +14,13 @@ import java.util.List;
 @Data
 @Embeddable
 public class CommitLog {
-    private String commitId;
-    private String commitAuthor;
     private String remoteRepoUrl;
     private String branch;
+    private String commitId;
+    private String commitAuthor;
+    private String commitMsg;
     // 毫秒级时间戳
     private long commitTime;
-    private String commitMsg;
     @ElementCollection(fetch = FetchType.EAGER)
     private List<ChangedFile> changedFiles;
 }

+ 20 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppBuildVO.java

@@ -0,0 +1,20 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
+import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
+import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2020-06-01 11:05:48
+ */
+@Data
+public class AppBuildVO {
+    private List<AppUpdate> appUpdates;
+    private List<AppCompile> appCompiles;
+    private List<AppPack> appPacks;
+    private List<String> projIds;
+}

+ 10 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppToBuild.java

@@ -9,17 +9,23 @@ import lombok.Data;
  * @author reghao
  * @date 2020-05-25 11:23:28
  */
-@AllArgsConstructor
 @Data
 public class AppToBuild {
     private String appId;
+    private String env;
     private String commitId;
-    private String commitMsg;
     private String commitAuthor;
+    private String commitMsg;
 
-    public AppToBuild(String appId, String commitId, String commitMsg) {
+    public AppToBuild(String appId, String env, String commitId, String commitAuthor) {
         this.appId = appId;
+        this.env = env;
         this.commitId = commitId;
-        this.commitMsg = commitMsg;
+        this.commitAuthor = commitAuthor;
+    }
+
+    public AppToBuild(String appId, String env) {
+        this.appId = appId;
+        this.env = env;
     }
 }

+ 3 - 1
dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestrationTest.java

@@ -14,7 +14,9 @@ import cn.reghao.autodop.dmaster.app.entity.deploy.AppLog;
 import org.junit.jupiter.api.Test;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 class AppOrchestrationTest {
     ProjOrchestration proj() {
@@ -72,7 +74,7 @@ class AppOrchestrationTest {
         appBuild.setAppCompile(appCompile);
         appBuild.setAppPack(appPack);
 
-        List<AppLog> appLogs = new ArrayList<>();
+        Set<AppLog> appLogs = new HashSet<>();
         appLogs.add(new AppLog("console", "info", null));
         appLogs.add(new AppLog("console", "error", null));
         appLogs.add(new AppLog("file", "info", "/Logs/Info/2020-05-19.log"));