Przeglądaj źródła

调整数据模型

reghao 6 lat temu
rodzic
commit
3cdde10527
93 zmienionych plików z 986 dodań i 1425 usunięć
  1. 43 1
      dmaster/pom.xml
  2. 3 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/FileController.java
  3. 51 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/OrchestrateController.java
  4. 3 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/BaseEntity.java
  5. 25 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/AppBuild.java
  6. 23 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/compile/AppCompile.java
  7. 24 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/pack/AppPack.java
  8. 23 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/update/AppUpdate.java
  9. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/CompilerType.java
  10. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/NotifyType.java
  11. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/PackerType.java
  12. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/RepoType.java
  13. 6 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/AppDeploy.java
  14. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildLog.java
  15. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/DeployLog.java
  16. 41 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java
  17. 22 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/Notification.java
  18. 25 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/ProjOrchestration.java
  19. 0 17
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/AppBuild.java
  20. 0 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/compile/AppCompile.java
  21. 0 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/pack/AppPack.java
  22. 0 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppRepo.java
  23. 0 13
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppUpdate.java
  24. 0 15
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/RepoAuth.java
  25. 0 29
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/AppOrchestration.java
  26. 0 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/Notification.java
  27. 0 16
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/ProjOrchestration.java
  28. 4 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/AppDAO.java
  29. 0 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/Pagination.java
  30. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppCompileRepository.java
  31. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppPackRepository.java
  32. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppUpdateRepository.java
  33. 4 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppOrchestrationRepository.java
  34. 12 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/NotificationRepository.java
  35. 4 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/ProjectOrchestrationRepository.java
  36. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppManager.java
  37. 185 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OrchestrateService.java
  38. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OssService.java
  39. 5 9
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java
  40. 10 11
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java
  41. 10 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java
  42. 7 10
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java
  43. 10 13
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/ProjectUpdateTask.java
  44. 4 9
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeploy.java
  45. 6 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/Deployer.java
  46. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DnktMgrPreCompile.java
  47. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DotnetPreCompile.java
  48. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/PreCompile.java
  49. 0 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DockerPack.java
  50. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/ChangedFile.java
  51. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CodeUpdater.java
  52. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CommitInfo.java
  53. 65 28
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/GitImpl.java
  54. 65 17
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/SvnImpl.java
  55. 16 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppVO.java
  56. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/PageList.java
  57. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/ProjVO.java
  58. 4 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/utils/SysInitializer.java
  59. 0 68
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/caching/OrchestrationCaching.java
  60. 0 88
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/controller/OrchestrateController.java
  61. 0 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/SysConfig.java
  62. 0 27
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppBuild.java
  63. 0 18
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppDeploy.java
  64. 0 17
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppLog.java
  65. 0 21
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppRunning.java
  66. 0 23
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/CodeRepos.java
  67. 0 16
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/ConfigFile.java
  68. 0 20
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/ProjBuild.java
  69. 0 28
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/AppOrchestration.java
  70. 0 26
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/Orchestration.java
  71. 0 19
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/ProjOrchestration.java
  72. 0 26
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/AppPacker.java
  73. 0 25
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/CodeCompiler.java
  74. 0 21
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/Notifier.java
  75. 0 36
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/ReposAuth.java
  76. 0 32
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/CompilerType.java
  77. 0 28
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/OrchestrationType.java
  78. 0 30
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/PackerType.java
  79. 0 28
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/ReposType.java
  80. 0 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/NotifierRepository.java
  81. 0 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/AppPackerRepository.java
  82. 0 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/CodeCompilerRepository.java
  83. 0 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/ReposAuthRepository.java
  84. 0 329
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/service/OrchestrateService.java
  85. 0 65
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/AppVO.java
  86. 0 11
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/OrchestrationVO.java
  87. 0 49
      dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/ProjVO.java
  88. 1 1
      dmaster/src/main/resources/application-dev.yml
  89. 72 0
      dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestrationTest.java
  90. 49 0
      dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/ProjOrchestrationTest.java
  91. 21 0
      scripts/app-in-proj.json
  92. 39 0
      scripts/app.json
  93. 24 0
      scripts/proj.json

+ 43 - 1
dmaster/pom.xml

@@ -65,7 +65,7 @@
         <dependency>
             <groupId>org.tmatesoft.svnkit</groupId>
             <artifactId>svnkit</artifactId>
-            <version>1.9.3</version>
+            <version>1.10.1</version>
         </dependency>
 
         <dependency>
@@ -130,6 +130,48 @@
             <artifactId>libvirt</artifactId>
             <version>0.5.1</version>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>RELEASE</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 3 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/FileController.java

@@ -2,7 +2,6 @@ package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.dmaster.common.result.WebResult;
 import cn.reghao.autodop.dmaster.common.utils.SpringBootUtil;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -30,7 +29,7 @@ public class FileController {
     )
     @GetMapping("/file/dl/{filename}")
     public String download(@PathVariable("filename") String filename, HttpServletResponse response) throws IOException {
-        String filepath = SysConfig.packDir + "/" + filename;
+        /*String filepath = SysConfig.packDir + "/" + filename;
         File file = new File(filepath);
         if (file.exists()) {
             response.setHeader("content-type", "application/octet-stream");
@@ -46,12 +45,10 @@ public class FileController {
             while (i != -1) {
                 os.write(buffer, 0, i);
                 i = bis.read(buffer);
-            }
+            }*/
 
             return new WebResult<String>().jsonResult("文件已下载");
-        }
-
-        return new WebResult<String>().jsonResult("文件不存在");
+        //return new WebResult<String>().jsonResult("文件不存在");
     }
 
     @ApiOperation(value = "上传文件")
@@ -59,7 +56,6 @@ public class FileController {
     public String ossUpload(@RequestParam("file") MultipartFile file) {
         String filename = file.getOriginalFilename();
         String filePath = SpringBootUtil.saveFile(file, "/tmp");
-
         return filePath;
     }
 }

+ 51 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/OrchestrateController.java

@@ -0,0 +1,51 @@
+package cn.reghao.autodop.dmaster.app.controller;
+
+import cn.reghao.autodop.dmaster.app.service.OrchestrateService;
+import cn.reghao.autodop.dmaster.common.result.ResultCode;
+import cn.reghao.autodop.dmaster.common.result.WebResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author reghao
+ * @date 2019-11-27 11:29:43
+ */
+@Slf4j
+@Api(tags = "应用编排 CURD 接口")
+@RestController
+@RequestMapping("/api/app/orchestrate")
+public class OrchestrateController {
+    private OrchestrateService orchestrateService;
+
+    public OrchestrateController(OrchestrateService orchestrateService) {
+        this.orchestrateService = orchestrateService;
+    }
+
+    @ApiOperation(value = "添加项目/应用编排")
+    @PostMapping(value = "/{type}", consumes = "application/json")
+    public String addOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
+        orchestrateService.add(type, json);
+        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
+    }
+
+    @ApiOperation(value = "批量添加项目/应用编排")
+    @PostMapping(value = "/batch/{type}", consumes = "application/json")
+    public String batchAddOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
+        orchestrateService.batchAdd(type, json);
+        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
+    }
+
+    @ApiOperation(value = "分页获取项目/应用编排")
+    @GetMapping("/{type}")
+    public String getOrchestrationByPage(@PathVariable("type") int type,
+                                         @RequestParam("page") int page,
+                                         @RequestParam("size") int size) {
+
+        //Pagination pagination = new Pagination(page, size);
+        PageRequest pageRequest = PageRequest.of(page-1, size);
+        return orchestrateService.getByPage(type, pageRequest);
+    }
+}

+ 3 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/BaseEntity.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/BaseEntity.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo;
+package cn.reghao.autodop.dmaster.app.entity;
 
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -26,4 +26,6 @@ public class BaseEntity implements Serializable {
     @CreationTimestamp
     @Column(updatable = false)
     protected Date createTime;
+    @CreationTimestamp
+    protected Date updateTime;
 }

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

@@ -0,0 +1,25 @@
+package cn.reghao.autodop.dmaster.app.entity.build;
+
+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 javax.persistence.CascadeType;
+import javax.persistence.Embeddable;
+import javax.persistence.ManyToOne;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+@Embeddable
+public class AppBuild {
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private AppUpdate appUpdate;
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private AppCompile appCompile;
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private AppPack appPack;
+}

+ 23 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/compile/AppCompile.java

@@ -0,0 +1,23 @@
+package cn.reghao.autodop.dmaster.app.entity.build.compile;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class AppCompile extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String compilerName;
+    private String compilerType;
+    private String compilerHome;
+    private String script;
+}

+ 24 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/pack/AppPack.java

@@ -0,0 +1,24 @@
+package cn.reghao.autodop.dmaster.app.entity.build.pack;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class AppPack extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String packerName;
+    private String packerType;
+    // 应用打包后存放的位置,可以是一个本地位置,也可以是一个网络位置
+    // 根据打包类型来确定
+    private String packerPath;
+}

+ 23 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/update/AppUpdate.java

@@ -0,0 +1,23 @@
+package cn.reghao.autodop.dmaster.app.entity.build.update;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class AppUpdate extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String repoName;
+    private String repoType;
+    private String username;
+    private String password;
+}

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/CompilerType.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/CompilerType.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo.constant;
+package cn.reghao.autodop.dmaster.app.entity.constant;
 
 /**
  * 编译工具

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/NotifyType.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/NotifyType.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo.constant;
+package cn.reghao.autodop.dmaster.app.entity.constant;
 
 /**
  * 通知工具

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/PackerType.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/PackerType.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo.constant;
+package cn.reghao.autodop.dmaster.app.entity.constant;
 
 /**
  * 打包工具

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/RepoType.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/constant/RepoType.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo.constant;
+package cn.reghao.autodop.dmaster.app.entity.constant;
 
 /**
  * 版本管理工具

+ 6 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/deploy/AppDeploy.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/AppDeploy.java

@@ -1,18 +1,20 @@
-package cn.reghao.autodop.dmaster.app.pojo.deploy;
+package cn.reghao.autodop.dmaster.app.entity.deploy;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppLog;
 import lombok.Data;
 
+import javax.persistence.Embeddable;
+
 /**
  * @author reghao
  * @date 2020-05-13 16:59:20
  */
 @Data
+@Embeddable
 public class AppDeploy {
     // 多台主机以 “,” 分隔
     private String hosts;
-    private int port;
+    private int httpPort;
     private String healthCheck;
     private String runningDir;
-    private AppLog log;
+    //private AppLog log;
 }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/BuildLog.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/BuildLog.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo;
+package cn.reghao.autodop.dmaster.app.entity.log;
 
 import lombok.AllArgsConstructor;
 

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/DeployLog.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/log/DeployLog.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.pojo;
+package cn.reghao.autodop.dmaster.app.entity.log;
 
 import lombok.AllArgsConstructor;
 

+ 41 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java

@@ -0,0 +1,41 @@
+package cn.reghao.autodop.dmaster.app.entity.orchestration;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
+import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.*;
+import java.util.Map;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:11:02
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class AppOrchestration extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String appId;
+    // 应用代码所在目录的名字
+    private String dirname;
+    private String description;
+    private String env;
+    // 编译 app 时所处的目录,以仓库目录为起点
+    private String entryDir;
+    // 配置文件
+    @ElementCollection(fetch = FetchType.EAGER)
+    private Map<String, String> configFiles;
+    private String appRepo;
+    @Column(length = 1024)
+    private String dependencyRepos;
+
+    // projId 和 appBuild 二者只能存在一个
+    private String projId;
+    private AppBuild appBuild;
+    private AppDeploy appDeploy;
+    @ManyToOne(cascade = CascadeType.PERSIST)
+    private Notification notification;
+}

+ 22 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/Notification.java

@@ -0,0 +1,22 @@
+package cn.reghao.autodop.dmaster.app.entity.orchestration;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * @author reghao
+ * @date 2020-03-06 21:20:06
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class Notification extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String notifyName;
+    private String notifyType;
+    private String destination;
+}

+ 25 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/ProjOrchestration.java

@@ -0,0 +1,25 @@
+package cn.reghao.autodop.dmaster.app.entity.orchestration;
+
+import cn.reghao.autodop.dmaster.app.entity.BaseEntity;
+import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:11:18
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class ProjOrchestration extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String projId;
+    private String description;
+    private String projRepo;
+    // 同一个项目内所有应用的构建策略是相同的
+    private AppBuild appBuild;
+}

+ 0 - 17
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/AppBuild.java

@@ -1,17 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build;
-
-import cn.reghao.autodop.dmaster.app.pojo.build.compile.AppCompile;
-import cn.reghao.autodop.dmaster.app.pojo.build.pack.AppPack;
-import cn.reghao.autodop.dmaster.app.pojo.build.update.AppUpdate;
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-05-13 16:40:22
- */
-@Data
-public class AppBuild {
-    private AppUpdate appUpdate;
-    private AppCompile appCompile;
-    private AppPack appPack;
-}

+ 0 - 14
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/compile/AppCompile.java

@@ -1,14 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build.compile;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-05-13 16:40:22
- */
-@Data
-public class AppCompile {
-    private String compilerName;
-    private String compilerType;
-    private String script;
-}

+ 0 - 14
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/pack/AppPack.java

@@ -1,14 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build.pack;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-05-13 16:40:22
- */
-@Data
-public class AppPack {
-    private String packerName;
-    private String packerType;
-    private String appRootPath;
-}

+ 0 - 14
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppRepo.java

@@ -1,14 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build.update;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:35:42
- */
-@Data
-public class AppRepo {
-    private String repo;
-    // 多个仓库以 "," 分隔
-    private String dependencyRepos;
-}

+ 0 - 13
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppUpdate.java

@@ -1,13 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build.update;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-05-13 16:40:22
- */
-@Data
-public class AppUpdate {
-    private RepoAuth repoAuth;
-    private AppRepo appRepo;
-}

+ 0 - 15
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/RepoAuth.java

@@ -1,15 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.build.update;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:12:33
- */
-@Data
-public class RepoAuth {
-    private String repoName;
-    private String repoType;
-    private String username;
-    private String password;
-}

+ 0 - 29
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/AppOrchestration.java

@@ -1,29 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.orchestration;
-
-import cn.reghao.autodop.dmaster.app.pojo.build.AppBuild;
-import cn.reghao.autodop.dmaster.app.pojo.deploy.AppDeploy;
-import lombok.Data;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:11:02
- */
-@Data
-public class AppOrchestration {
-    private String appId;
-    // 应用代码所在目录的名字
-    private String dirname;
-    private String description;
-    private String env;
-    // 编译 app 时所处的目录,以仓库目录为起点
-    private String entryDir;
-    // 配置文件
-    private Map<String, String> configFiles;
-
-    // projId 和 appBuild 二者只能存在一个
-    private String projId;
-    private AppBuild appBuild;
-    private AppDeploy appDeploy;
-    private Notification notification;
-}

+ 0 - 14
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/Notification.java

@@ -1,14 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.orchestration;
-
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-03-06 21:20:06
- */
-@Data
-public class Notification {
-    private String notifyName;
-    private String notifyType;
-    private String destination;
-}

+ 0 - 16
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/ProjOrchestration.java

@@ -1,16 +0,0 @@
-package cn.reghao.autodop.dmaster.app.pojo.orchestration;
-
-import cn.reghao.autodop.dmaster.app.pojo.build.AppBuild;
-import lombok.Data;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:11:18
- */
-@Data
-public class ProjOrchestration {
-    private String projId;
-    private String description;
-    // 同一个项目内所有应用的构建策略是相同的
-    private AppBuild build;
-}

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/dao/AppDAO.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/AppDAO.java

@@ -1,6 +1,6 @@
-package cn.reghao.autodop.dmaster.orchestrate.dao;
+package cn.reghao.autodop.dmaster.app.repository;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import org.hibernate.Session;
 import org.springframework.stereotype.Service;
 
@@ -37,12 +37,12 @@ public class AppDAO {
 
         tx.commit();*/
         Query query = session
-                .createQuery("select app from AppOrchestration app where app.projBuild.projId = :projId")
+                .createQuery("select app from AppOrchestration app where app.projId = :projId")
                 .setParameter("projId", projId);
 
         List<String> appIds = new ArrayList<>();
         query.getResultList().forEach(app -> {
-            appIds.add(((AppOrchestration) app).getIdentifier());
+            appIds.add(((AppOrchestration) app).getAppId());
         });
 
         return appIds;

+ 0 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/Pagination.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/Pagination.java


+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppCompileRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.dmaster.app.repository.build;
+
+import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2020-01-21 14:53:03
+ */
+public interface AppCompileRepository extends JpaRepository<AppCompile, Long> {
+    AppCompile findByCompilerName(String compilerName);
+}

+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppPackRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.dmaster.app.repository.build;
+
+import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2020-01-21 14:53:03
+ */
+public interface AppPackRepository extends JpaRepository<AppPack, Long> {
+    AppPack findByPackerName(String packerName);
+}

+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/build/AppUpdateRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.dmaster.app.repository.build;
+
+import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2020-01-21 14:53:03
+ */
+public interface AppUpdateRepository extends JpaRepository<AppUpdate, Long> {
+    AppUpdate findByRepoName(String repoName);
+}

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/orchestration/AppOrchestrationRepository.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppOrchestrationRepository.java

@@ -1,6 +1,6 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository.orchestration;
+package cn.reghao.autodop.dmaster.app.repository.orchestration;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 
@@ -12,9 +12,9 @@ import javax.transaction.Transactional;
  * @date 2020-01-21 14:53:03
  */
 public interface AppOrchestrationRepository extends JpaRepository<AppOrchestration, Long> {
-    AppOrchestration findByIdentifier(String identifier);
+    AppOrchestration findByAppId(String appId);
 
     @Modifying
     @Transactional
-    void deleteByIdentifier(String identifier);
+    void deleteByAppId(String appId);
 }

+ 12 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/NotificationRepository.java

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

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/orchestration/ProjectOrchestrationRepository.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/ProjectOrchestrationRepository.java

@@ -1,6 +1,6 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository.orchestration;
+package cn.reghao.autodop.dmaster.app.repository.orchestration;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 
@@ -12,11 +12,11 @@ import javax.transaction.Transactional;
  * @date 2020-01-21 14:53:03
  */
 public interface ProjectOrchestrationRepository extends JpaRepository<ProjOrchestration, Long> {
-    ProjOrchestration findByIdentifier(String identifier);
+    ProjOrchestration findByProjId(String projId);
 
     @Modifying
     @Transactional
-    void deleteByIdentifier(String identifier);
+    void deleteByProjId(String projId);
 
     // TODO 添加分页参数
     /*@Query(value = "select proj.id as id,proj.proj_id as projId,proj.description as description,repo.repo_id as repoId,repo.username as username,repo.password as password,proj.repo as repo,compiler.compiler_id as compilerId,compiler.script as script,packer.packer_id as packerId,packer.app_root_path as appRootPath,group_concat(app.app_id separator ',') as apps,proj.create_time as createTime\n" +

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

@@ -1,7 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service;
 
 import cn.reghao.autodop.common.dockerc.DockerException;
-import cn.reghao.autodop.dmaster.orchestrate.caching.OrchestrationCaching;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -16,11 +15,11 @@ import java.util.List;
 @Service
 public class AppManager {
     private final int GRPC_PORT = 4001;
-    private OrchestrationCaching caching;
+    /*private OrchestrationCaching caching;
 
     public AppManager(OrchestrationCaching caching) {
         this.caching = caching;
-    }
+    }*/
 
     public void run(String appId, String version) {
 

+ 185 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OrchestrateService.java

@@ -0,0 +1,185 @@
+package cn.reghao.autodop.dmaster.app.service;
+
+import cn.reghao.autodop.common.utils.JsonUtil;
+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.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.AppDAO;
+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.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.AppVO;
+import cn.reghao.autodop.dmaster.app.vo.PageList;
+import cn.reghao.autodop.dmaster.app.vo.ProjVO;
+import cn.reghao.autodop.dmaster.common.result.ResultCode;
+import cn.reghao.autodop.dmaster.common.result.WebResult;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 17:10:37
+ */
+@Service
+public class OrchestrateService {
+    private ProjectOrchestrationRepository projRepository;
+    private AppOrchestrationRepository appRepository;
+    private AppUpdateRepository appUpdateRepository;
+    private AppCompileRepository appCompileRepository;
+    private AppPackRepository appPackRepository;
+    private NotificationRepository notificationRepository;
+    private AppDAO appDAO;
+
+    public OrchestrateService(ProjectOrchestrationRepository projRepository,
+                              AppOrchestrationRepository appRepository,
+                              AppUpdateRepository appUpdateRepository,
+                              AppCompileRepository appCompileRepository,
+                              AppPackRepository appPackRepository,
+                              NotificationRepository notificationRepository,
+                              AppDAO appDAO) {
+        this.projRepository = projRepository;
+        this.appRepository = appRepository;
+        this.appUpdateRepository = appUpdateRepository;
+        this.appCompileRepository = appCompileRepository;
+        this.appPackRepository = appPackRepository;
+        this.notificationRepository = notificationRepository;
+        this.appDAO = appDAO;
+    }
+
+    public void add(int type, String json) {
+        AppBuild appBuild;
+        switch (type) {
+            case 1:
+                // 项目编排
+                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
+                appBuild = proj.getAppBuild();
+                checkSharedEntity(appBuild);
+                projRepository.save(proj);
+                break;
+            case 2:
+                // 应用编排
+                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
+                String projId = app.getProjId();
+                if (projId == null) {
+                    appBuild = app.getAppBuild();
+                    checkSharedEntity(appBuild);
+                }
+
+                Notification notification = app.getNotification();
+                Notification notifyEntity = notificationRepository.findByNotifyName(notification.getNotifyName());
+                if (notifyEntity != null) {
+                    app.setNotification(notifyEntity);
+                } else {
+                    notificationRepository.save(notification);
+                }
+
+                appRepository.save(app);
+            default:
+        }
+    }
+
+    /**
+     * TODO 由于 AppBuild 和 ProjBuild 只能二选一,因此需要对 @ManyToOne 约束进行检查
+     * TODO 数据库查询异步化
+     * 检查构建阶段的共享实体是否存在
+     *
+     * @date 2020-03-01 下午6:34
+     */
+    private void checkSharedEntity(AppBuild build) {
+        AppUpdate appUpdate = build.getAppUpdate();
+        AppUpdate authEntity = appUpdateRepository.findByRepoName(appUpdate.getRepoName());
+        if (authEntity != null) {
+            build.setAppUpdate(authEntity);
+        } else {
+            appUpdateRepository.save(appUpdate);
+        }
+
+        AppCompile appCompile = build.getAppCompile();
+        if (appCompile != null) {
+            AppCompile compilerEntity = appCompileRepository.findByCompilerName(appCompile.getCompilerName());
+            if (compilerEntity != null) {
+                build.setAppCompile(compilerEntity);
+            } else {
+                appCompileRepository.save(appCompile);
+            }
+        }
+
+        AppPack packer = build.getAppPack();
+        if (packer != null) {
+            AppPack packerEntity = appPackRepository.findByPackerName(packer.getPackerName());
+            if (packerEntity != null) {
+                build.setAppPack(packerEntity);
+            } else {
+                appPackRepository.save(packer);
+            }
+        }
+    }
+
+    public void batchAdd(int type, String json) throws Exception {
+        // TODO 优化代码
+        switch (type) {
+            case 1:
+                List<Object> objs = JsonUtil.jsonToObjectArray(json, ProjOrchestration.class);
+                for (Object obj : objs) {
+                    ProjOrchestration proj = (ProjOrchestration) obj;
+                    //checkSharedEntity(proj);
+                    projRepository.save(proj);
+                }
+                break;
+            case 2:
+                List<Object> objs1 = JsonUtil.jsonToObjectArray(json, AppOrchestration.class);
+                for (Object obj : objs1) {
+                    AppOrchestration app = (AppOrchestration) obj;
+                    //checkSharedEntity(app);
+                    // TODO 使用 saveAll 时若多个编排中具有相同的 UNIQUE 约束值会引发 UNIQUE 约束异常
+                    appRepository.save(app);
+                }
+            default:
+        }
+    }
+
+    public String getByPage(int type, PageRequest pageRequest) {
+        switch (type) {
+            case 1:
+                Page<ProjOrchestration> projPages = projRepository.findAll(pageRequest);
+                List<ProjVO> vos = new ArrayList<>();
+                projPages.forEach(proj -> {
+                    List<String> appIds = appDAO.findAppsByProjId(proj.getProjId());
+                    ProjVO vo = ProjVO.of(proj, appIds.toString()
+                            .replace("[", "").replace("]", ""));
+                    vos.add(vo);
+                });
+
+                PageList<ProjVO> list = new PageList<>();
+                list.setList(vos);
+                list.setSize(vos.size());
+
+                return new WebResult<PageList>(ResultCode.SUCCESS).jsonResult(list);
+            case 2:
+                Page<AppOrchestration> appPages = appRepository.findAll(pageRequest);
+                List<AppVO> appVOS = new ArrayList<>();
+                appPages.getContent().forEach(app -> {
+                    appVOS.add(AppVO.of(app));
+                });
+
+                PageList<AppVO> list1 = new PageList<>();
+                list1.setList(appVOS);
+                list1.setSize(appVOS.size());
+
+                return new WebResult<PageList>(ResultCode.SUCCESS).jsonResult(list1);
+            default:
+                return null;
+        }
+    }
+}

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

@@ -1,7 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service;
 
 import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import cn.reghao.autodop.dmaster.common.utils.OssUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -23,8 +22,8 @@ public class OssService {
     public void upload(String dirname) throws SVNException {
         SvnImpl svn = new SvnImpl("gjs", "gjs1234");
         String remote = "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.C2Game/trunk/Codes/" + dirname;
-        String local = SysConfig.localRepos + "/c2game/" + dirname;
+        /*String local = SysConfig.localRepos + "/c2game/" + dirname;
         svn.update(remote, local);
-        ossUtil.backupAndUpload(dirname, local);
+        ossUtil.backupAndUpload(dirname, local);*/
     }
 }

+ 5 - 9
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java

@@ -2,13 +2,9 @@ package cn.reghao.autodop.dmaster.app.service.build;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
 import cn.reghao.autodop.common.utils.JsonUtil;
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.app.service.deploy.AppDeploy;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
-import cn.reghao.autodop.dmaster.app.service.tools.updater.CodeUpdater;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.List;
 import java.util.concurrent.Callable;
 
 /**
@@ -25,8 +21,8 @@ public class AppBuildPipeline implements Callable<String> {
     private boolean isDeploy;
     private AppIntegrate appIntegrate;
 
-    private final String appLocalRepo;
-    private final String appCompileDir;
+    private String appLocalRepo;
+    private String appCompileDir;
 
     public AppBuildPipeline(AppOrchestration app, String version, boolean isDeploy) {
         this.app = app;
@@ -37,8 +33,8 @@ public class AppBuildPipeline implements Callable<String> {
         /*this.appIntegrate = ProxyUtils.createProxyObject(AppIntegrate.class);
         this.appIntegrate.setApp(app);*/
 
-        this.appLocalRepo = SysConfig.localRepos + "/" + app.getAppId();
-        this.appCompileDir = SysConfig.compileDir + "/" + app.getAppId();
+        /*this.appLocalRepo = SysConfig.localRepos + "/" + app.getAppId();
+        this.appCompileDir = SysConfig.compileDir + "/" + app.getAppId();*/
     }
 
     /**

+ 10 - 11
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -1,16 +1,15 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.dmaster.app.pojo.build.AppBuild;
-import cn.reghao.autodop.dmaster.app.pojo.build.compile.AppCompile;
-import cn.reghao.autodop.dmaster.app.pojo.build.pack.AppPack;
-import cn.reghao.autodop.dmaster.app.pojo.constant.CompilerType;
-import cn.reghao.autodop.dmaster.app.pojo.constant.PackerType;
-import cn.reghao.autodop.dmaster.app.pojo.deploy.AppDeploy;
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
+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.constant.CompilerType;
+import cn.reghao.autodop.dmaster.app.entity.constant.PackerType;
+import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.service.tools.compiler.*;
 import cn.reghao.autodop.dmaster.app.service.tools.packer.*;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.CodeUpdater;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import lombok.extern.slf4j.Slf4j;
 
 /**
@@ -21,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
  */
 @Slf4j
 public class AppIntegrate {
-    private final String packDir = SysConfig.packDir;
+    private String packDir;
     private AppOrchestration app;
     private CodeUpdater codeUpdater;
     private PreCompile preCompile;
@@ -58,7 +57,7 @@ public class AppIntegrate {
         // 初始化打包配置
         AppPack appPack = appBuild.getAppPack();
         if (appPack.getPackerType().equals(PackerType.docker.name())) {
-            codePacker = new DockerPack(appPack.getAppRootPath());
+            codePacker = new DockerPack(appPack.getPackerPath());
         } else if (appPack.getPackerType().equals(PackerType.maven.name())) {
             codePacker = null;
         } else if (appPack.getPackerType().equals(PackerType.zip.name())) {
@@ -70,7 +69,7 @@ public class AppIntegrate {
         // TODO 特定于 dnkt-mgr 项目的处理
         if (app.getAppId().startsWith("dnkt-mgr")) {
             preCompile = new DnktMgrPreCompile();
-            codePacker = new DnktMgrZipPack(appPack.getAppRootPath());
+            codePacker = new DnktMgrZipPack(appPack.getPackerPath());
         }
 
         // 初始化部署配置

+ 10 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java

@@ -2,11 +2,9 @@ package cn.reghao.autodop.dmaster.app.service.build;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
 import cn.reghao.autodop.common.utils.JsonUtil;
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.orchestrate.caching.OrchestrationCaching;
+import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppBuild;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -21,11 +19,11 @@ import java.util.concurrent.*;
 @Service
 public class BuildDispatcher {
     private final String STANDALONE_APP = "standaloneApp";
-    private OrchestrationCaching caching;
+    /*private OrchestrationCaching caching;
 
     public BuildDispatcher(OrchestrationCaching caching) {
         this.caching = caching;
-    }
+    }*/
 
     /**
      * 根据项目分发应用
@@ -43,12 +41,12 @@ public class BuildDispatcher {
             // existApps.addAll(config.getApps().values());
         } else {
             appIds.forEach(appId -> {
-                AppOrchestration app = caching.findAppByIdentifier(appId);
+                /*AppOrchestration app = caching.findAppByIdentifier(appId);
                 if (app != null) {
                     existApps.add(app);
                 } else {
                     results.add(new BuildDeployResult(appId, "初始化", 0, "应用不存在"));
-                }
+                }*/
             });
         }
 
@@ -62,7 +60,7 @@ public class BuildDispatcher {
             List<AppOrchestration> apps = entry.getValue();
             if (!STANDALONE_APP.equalsIgnoreCase(key)) {
                 // 首先更新整个项目,然后再分别更新,编译,打包应用
-                ProjOrchestration proj = caching.findProjByIdentifier(key);
+                //ProjOrchestration proj = caching.findProjByIdentifier(key);
                 //projFutures.add(threadPool.submit(new ProjectUpdateTask(proj, apps)));
             } else {
                 // 更新,编译,打包独立的应用
@@ -90,7 +88,7 @@ public class BuildDispatcher {
                                 new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy)));*/
                     } else {
                         BuildDeployResult buildDeployResult = new BuildDeployResult();
-                        buildDeployResult.setAppId(appVersion.getApp().getIdentifier());
+                        //buildDeployResult.setAppId(appVersion.getApp());
                         buildDeployResult.setVersion(appVersion.getVersion());
                         buildDeployResult.setMsg("应用不需要更新");
                         results.add(buildDeployResult);
@@ -163,9 +161,9 @@ public class BuildDispatcher {
         //ProjBuild projBuild = app.getProjBuild();
 
         AppBuild appBuild = new AppBuild();
-        appBuild.setNotifier(build.getNotifier());
+        /*appBuild.setNotifier(build.getNotifier());
         appBuild.setCodeCompiler(build.getCodeCompiler());
-        appBuild.setAppPacker(build.getAppPacker());
+        appBuild.setAppPacker(build.getAppPacker());*/
 
         /*String projReposUrl = build.getCodeRepos().getReposUrl();
         String appReposUrl = projReposUrl + projBuild.getAppReposUrl();

+ 7 - 10
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java

@@ -2,16 +2,13 @@ package cn.reghao.autodop.dmaster.app.service.build;
 
 import cn.reghao.autodop.common.utils.FileUtil;
 import cn.reghao.autodop.common.utils.text.ReplaceCharacter;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.CodeRepos;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.ReposAuth;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.GitImpl;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
 import cn.reghao.autodop.dmaster.app.service.tools.updater.CodeUpdater;
 import lombok.extern.slf4j.Slf4j;
 
-import java.io.File;
 import java.io.IOException;
 
 /**
@@ -27,7 +24,7 @@ public class BuilderUtil {
      * @date 2019-12-03 上午9:55
      */
     public static void copyToCompileDir(String appLocalRepo, AppOrchestration app) throws IOException {
-        String appCompileDir = SysConfig.compileDir + "/" + app.getIdentifier();
+        /*String appCompileDir = SysConfig.compileDir + "/" + app.getIdentifier();
 
         File compileDir = new File(appCompileDir);
         if (!compileDir.exists() && !FileUtil.mkdir(compileDir)) {
@@ -51,7 +48,7 @@ public class BuilderUtil {
         if ("dotnet".equals(app.getBuild().getCodeCompiler().getCompilerType())) {
             // Dotnet 应用需要替换一些字符
             BuilderUtil.replaceCharacter(appCompileDir);
-        }
+        }*/
     }
 
     public static String dirname(String svnUrl) {
@@ -63,10 +60,10 @@ public class BuilderUtil {
         FileUtil.traversal(appCompileDir, new ReplaceCharacter());
     }
 
-    public static CodeUpdater versionControl(ReposAuth reposAuth) {
-        if ("svn".equals(reposAuth.getReposType())) {
+    public static CodeUpdater versionControl(AppUpdate reposAuth) {
+        if ("svn".equals(reposAuth.getRepoType())) {
             return new SvnImpl(reposAuth.getUsername(), reposAuth.getPassword());
-        } else if ("git".equals(reposAuth.getReposType())) {
+        } else if ("git".equals(reposAuth.getRepoType())) {
             return new GitImpl("");
         } else {
             return null;

+ 10 - 13
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/ProjectUpdateTask.java

@@ -1,9 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.CodeRepos;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
+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.tools.updater.CodeUpdater;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -26,15 +24,14 @@ import java.util.concurrent.Callable;
 public class ProjectUpdateTask implements Callable<List<ProjectUpdateTask.AppVersion>> {
     private ProjOrchestration proj;
     private List<AppOrchestration> apps;
-    private final String localRepos;
+    private String localRepos;
     private CodeUpdater vc;
 
     public ProjectUpdateTask(ProjOrchestration proj, List<AppOrchestration> apps) {
         this.proj = proj;
         this.apps = apps;
-        this.localRepos = SysConfig.localRepos;
-
-        this.vc = BuilderUtil.versionControl(proj.getBuild().getCodeRepos().getReposAuth());
+        /*this.localRepos = SysConfig.localRepos;
+        this.vc = BuilderUtil.versionControl(proj.getBuild().getCodeRepos().getReposAuth());*/
     }
 
     @Override
@@ -56,10 +53,10 @@ public class ProjectUpdateTask implements Callable<List<ProjectUpdateTask.AppVer
      * @date 2019-11-08 上午9:57
      */
     private void updateProject() throws Exception {
-        CodeRepos codeRepos = proj.getBuild().getCodeRepos();
+        /*CodeRepos codeRepos = proj.getBuild().getCodeRepos();
         String remote = codeRepos.getReposUrl();
         String local = localRepos + "/" + proj.getIdentifier();
-        vc.update(remote, local);
+        vc.update(remote, local);*/
     }
 
     /**
@@ -72,9 +69,9 @@ public class ProjectUpdateTask implements Callable<List<ProjectUpdateTask.AppVer
     private Map<AppOrchestration, String> checkAppVersion() throws Exception {
         Map<AppOrchestration, String> map = new HashMap<>();
         for (AppOrchestration app : apps) {
-            String appLocalRepos = localRepos + "/" + proj.getIdentifier() + app.getProjBuild().getAppReposUrl();
+            /*String appLocalRepos = localRepos + "/" + proj.getIdentifier() + app.getProjBuild().getAppReposUrl();
             String version = vc.localVersion(appLocalRepos);
-            map.put(app, version);
+            map.put(app, version);*/
         }
 
         return map;
@@ -89,7 +86,7 @@ public class ProjectUpdateTask implements Callable<List<ProjectUpdateTask.AppVer
             // 无论代码是否更新,都要构建
             if (version == null || Long.parseLong(version1) >= Long.parseLong(version)) {
                 list.add(new AppVersion(app, version, true));
-                String appLocalRepos = localRepos + "/" + proj.getIdentifier();
+                String appLocalRepos = localRepos + "/" + proj.getProjId();
                 // TODO 抛出异常
                 try {
                     BuilderUtil.copyToCompileDir(appLocalRepos, app);

+ 4 - 9
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeploy.java

@@ -1,13 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.deploy;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
-import cn.reghao.autodop.common.http.HttpApi;
-import cn.reghao.autodop.common.notification.DingNotify;
-import cn.reghao.autodop.common.notification.Notify;
-import cn.reghao.autodop.dmaster.app.pojo.BuildLog;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.List;
@@ -26,7 +20,7 @@ public class AppDeploy {
      * @date 2020-03-13 下午1:00
      */
     public static List<BuildDeployResult> deploy(AppOrchestration app, String version) throws Exception {
-        Notifier notifier = app.getBuild().getNotifier();
+        /*Notifier notifier = app.getBuild().getNotifier();
 
         Notify notify = null;
         if ("ding".equalsIgnoreCase(notifier.getNotifierType())) {
@@ -71,6 +65,7 @@ public class AppDeploy {
             }
         }
 
-        return results;
+        return results;*/
+        return null;
     }
 }

+ 6 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/Deployer.java

@@ -5,10 +5,9 @@ import cn.reghao.autodop.common.grpc.client.GrpcClientProxy;
 import cn.reghao.autodop.common.grpc.facade.DeployService;
 import cn.reghao.autodop.common.config.DeployConfig;
 import cn.reghao.autodop.common.http.HttpApi;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -29,13 +28,13 @@ public class Deployer {
      */
     public static List<BuildDeployResult> deploy(AppOrchestration app, String appPath) {
         DeployConfig deployConfig = new DeployConfig();
-        deployConfig.setAppId(app.getIdentifier());
+        deployConfig.setAppId(app.getAppId());
         deployConfig.setAppPath(appPath);
-        deployConfig.setPackerType(app.getBuild().getAppPacker().getPackerType());
-        deployConfig.setRunningDir(app.getRunning().getRunningDir());
+        /*deployConfig.setPackerType(app.getBuild().getAppPacker().getPackerType());
+        deployConfig.setRunningDir(app.getRunning().getRunningDir());*/
 
         List<BuildDeployResult> results = new ArrayList<>();
-        String[] hosts = app.getDeploy().getHosts().split(",");
+       /* String[] hosts = app.getDeploy().getHosts().split(",");
         // TODO 异步调用
         for (String host : hosts) {
             // TODO 公共网络下,gRPC 调用需要经过认证
@@ -55,7 +54,7 @@ public class Deployer {
             }
 
             results.add(result);
-        }
+        }*/
 
         return results;
     }

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

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.utils.FileUtil;
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;

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

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.utils.FileUtil;
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;

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

@@ -1,6 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 
 import java.io.IOException;
 

+ 0 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DockerPack.java

@@ -1,7 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
 import cn.reghao.autodop.common.dockerc.DockerClient;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
 
 /**
  * 打包为 docker 应用

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/ChangedFile.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.service.tools.updater;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-14 10:49:49
+ */
+@Data
+public class ChangedFile {
+    private String changeType;
+    private String oldFilePath;
+    private String newFilePath;
+}

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CodeUpdater.java

@@ -15,7 +15,7 @@ public interface CodeUpdater {
      * @return 当前代码仓库的版本
      * @date 2019-10-12 下午11:08
      */
-    String update(String remote, String local) throws Exception;
+    CommitInfo update(String remote, String local) throws Exception;
 
     /**
      * 本地代码版本

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CommitInfo.java

@@ -19,5 +19,5 @@ public class CommitInfo {
     // 毫秒级时间戳
     private long commitTime;
     private String commitMsg;
-    private List<String> commitFiles;
+    private List<ChangedFile> changedFiles;
 }

+ 65 - 28
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/GitImpl.java

@@ -5,16 +5,22 @@ import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.PullCommand;
 import org.eclipse.jgit.api.PullResult;
 import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.diff.DiffEntry;
 import org.eclipse.jgit.internal.storage.file.FileRepository;
 import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectReader;
 import org.eclipse.jgit.lib.Ref;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTree;
 import org.eclipse.jgit.revwalk.RevWalk;
 import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.eclipse.jgit.treewalk.CanonicalTreeParser;
+import org.eclipse.jgit.treewalk.TreeWalk;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -41,25 +47,25 @@ public class GitImpl implements CodeUpdater {
      * @date 2020-05-13 下午9:22
      */
     @Override
-    public String update(String remote, String local) throws Exception {
+    public CommitInfo update(String remote, String local) throws Exception {
         File localRepo = new File(local + "/.git");
+        CommitInfo commitInfo;
         if (!localRepo.exists()) {
-            CommitInfo commitInfo = clone(remote, local);
+            commitInfo = clone(remote, local);
+            commitInfo.setRepoUrl(remote);
         } else {
             try (Repository repo = new FileRepository(localRepo.getAbsolutePath())) {
                 PullCommand gitPull = new Git(repo).pull();
                 gitPull.call();
-                CommitInfo commitInfo = commitInfo(repo);
+                commitInfo = commitInfo(repo);
                 commitInfo.setRepoUrl(remote);
-            } catch (Exception e) {
-
+                commitInfo.setChangedFiles(changedFileList(repo));
             }
         }
-
-        return null;
+        return commitInfo;
     }
 
-    private CommitInfo clone(String remote, String local) {
+    private CommitInfo clone(String remote, String local) throws Exception {
         CloneCommand gitClone = Git.cloneRepository()
                 .setURI(remote)
                 .setBranch(branch)
@@ -67,19 +73,9 @@ public class GitImpl implements CodeUpdater {
 
         try (Git git = gitClone.call()) {
             Repository repo = git.getRepository();
-            Ref head = repo.findRef("refs/heads/master");
-            ObjectId objectId = head.getObjectId();
-
-            RevWalk walk = new RevWalk(repo);
-            RevCommit lastCommit = walk.parseCommit(objectId);
-
-            CommitInfo commitInfo = new CommitInfo();
-            commitInfo.setCommitId(objectId.name());
-            commitInfo.setRepoUrl(remote);
-
+            CommitInfo commitInfo = commitInfo(repo);
+            commitInfo.setChangedFiles(changedFileList(repo));
             return commitInfo;
-        } catch (Exception e) {
-            return null;
         }
     }
 
@@ -87,6 +83,7 @@ public class GitImpl implements CodeUpdater {
         Ref head = repo.findRef("refs/heads/master");
         ObjectId objectId = head.getObjectId();
         try (RevWalk walk = new RevWalk(repo)) {
+            // 最近一次提交的信息
             RevCommit lastCommit = walk.parseCommit(objectId);
             int commitTime = lastCommit.getCommitTime();
             String commitAuthor = lastCommit.getAuthorIdent().getName();
@@ -94,7 +91,8 @@ public class GitImpl implements CodeUpdater {
 
             CommitInfo commitInfo = new CommitInfo();
             commitInfo.setCommitId(objectId.name());
-            commitInfo.setCommitTime(commitTime*1000);
+            // TODO 转换为毫秒
+            commitInfo.setCommitTime(commitTime);
             commitInfo.setCommitAuthor(commitAuthor);
             commitInfo.setCommitMsg(commitMsg);
             commitInfo.setBranch(repo.getBranch());
@@ -102,20 +100,58 @@ public class GitImpl implements CodeUpdater {
         }
     }
 
-    List<String> changedFileList() {
-        return null;
+    private List<ChangedFile> changedFileList(Repository repo) throws Exception {
+        Ref headMaster = repo.findRef("refs/heads/master");
+        ObjectId objectId = headMaster.getObjectId();
+        try (RevWalk walk = new RevWalk(repo)) {
+            // 最近一次提交
+            RevCommit newCommit = walk.parseCommit(objectId);
+            walk.markStart(newCommit);
+            // 遍历两次找到 newCommit 的前一次提交,newCommit 不是第一次提交
+            walk.next();
+            RevCommit oldCommit = walk.next();
+
+            ObjectId newHead = newCommit.getTree().getId();
+            ObjectId oldHead = oldCommit.getTree().getId();
+
+            try (ObjectReader reader = repo.newObjectReader()) {
+                CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
+                newTreeIter.reset(reader, newHead);
+                CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
+                oldTreeIter.reset(reader, oldHead);
+                try (Git git = new Git(repo)) {
+                    List<DiffEntry> diffs= git.diff()
+                            .setNewTree(newTreeIter)
+                            .setOldTree(oldTreeIter)
+                            .call();
+
+                    List<ChangedFile> changedFiles = new ArrayList<>();
+                    for (DiffEntry entry : diffs) {
+                        ChangedFile changedFile = new ChangedFile();
+                        changedFile.setChangeType(entry.getChangeType().name());
+                        //changedFile.setFilePath(entry.getNewPath());
+                        changedFile.setOldFilePath(entry.getOldPath());
+                        changedFile.setNewFilePath(entry.getNewPath());
+                        changedFiles.add(changedFile);
+                    }
+
+                    return changedFiles;
+                }
+            }
+        }
     }
 
     @Override
-    public String localVersion(String local) {
+    public String localVersion(String local) throws Exception {
         File localRepo = new File(local + "/.git");
+        if (!localRepo.exists()) {
+            return null;
+        }
+
         try (Repository repo = new FileRepository(localRepo.getAbsolutePath())) {
             Ref head = repo.findRef("refs/heads/master");
             ObjectId objectId = head.getObjectId();
             return objectId.name();
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
         }
     }
 
@@ -124,6 +160,7 @@ public class GitImpl implements CodeUpdater {
         GitImpl git = new GitImpl(branch);
         String remote = "http://git.reghao.cn/reghao/spiderlab.git";
         String local = "/home/reghao/tmp/autodop/opt/data/git/spiderlab";
-        git.update(remote, local);
+        CommitInfo commitInfo = git.update(remote, local);
+        System.out.println(git.localVersion(local));
     }
 }

+ 65 - 17
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/SvnImpl.java

@@ -1,50 +1,92 @@
 package cn.reghao.autodop.dmaster.app.service.tools.updater;
 
-import org.tmatesoft.svn.core.SVNDepth;
-import org.tmatesoft.svn.core.SVNException;
-import org.tmatesoft.svn.core.SVNURL;
+import org.tmatesoft.svn.core.*;
 import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
-import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
 import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
 import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
 import org.tmatesoft.svn.core.wc.*;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
- * TODO 资源管理,完成后关闭连接
- * SVN 实现
+ * svn 实现
  *
  * @author reghao
  * @date 2019-09-07 16:18:46
  */
 public class SvnImpl implements CodeUpdater {
+    private SVNLogClient logClient;
     private SVNUpdateClient updateClient;
+    private SVNStatusClient statusClient;
 
     public SvnImpl(String username, String password) {
-        DAVRepositoryFactory.setup();
-        SVNRepositoryFactoryImpl.setup();
-
         ISVNAuthenticationManager authManager =
                 SVNWCUtil.createDefaultAuthenticationManager(username, password.toCharArray());
+        SVNRepositoryFactoryImpl.setup();
         DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
-
         SVNClientManager clientManager = SVNClientManager.newInstance(options, authManager);
+
+        logClient = clientManager.getLogClient();
         updateClient = clientManager.getUpdateClient();
         updateClient.setIgnoreExternals(false);
+        statusClient = clientManager.getStatusClient();
     }
 
     @Override
-    public String update(String remote, String local) throws SVNException {
+    public CommitInfo update(String remote, String local) throws SVNException {
         File localRepo = new File(local);
         if (!localRepo.exists()) {
             checkout(remote, localRepo);
         } else {
-            updateClient.doUpdate(
-                    localRepo, SVNRevision.HEAD, SVNDepth.INFINITY, true, false);
+            updateClient.doUpdate(localRepo, SVNRevision.HEAD, SVNDepth.INFINITY,
+                    true, false);
         }
 
-        return localVersion(local);
+        CommitInfo commitInfo = commitInfo(localRepo, Long.parseLong(localVersion(local)));
+        commitInfo.setRepoUrl(remote);
+        commitInfo.setBranch("");
+        return commitInfo;
+    }
+
+    private CommitInfo commitInfo(File localRepo, long version) throws SVNException {
+        File[] paths = { localRepo };
+        SVNRevision start = SVNRevision.create(version);
+        SVNRevision end = SVNRevision.create(version);
+        long limit = 9999L;
+        CommitInfo commitInfo = new CommitInfo();
+        logClient.doLog(paths, start, end, false, true, limit, logEntry -> {
+            String commitAuthor = logEntry.getAuthor();
+            String commitMsg = logEntry.getMessage();
+            long commitTime = logEntry.getDate().toInstant().toEpochMilli();
+            String commitId = String.valueOf(logEntry.getRevision());
+            Map<String, SVNLogEntryPath> changedPaths = logEntry.getChangedPaths();
+
+            //commitInfo.setRepoUrl(remote);
+            commitInfo.setCommitId(commitId);
+            commitInfo.setCommitMsg(commitMsg);
+            commitInfo.setCommitAuthor(commitAuthor);
+            commitInfo.setCommitTime(commitTime);
+            commitInfo.setChangedFiles(changedFileList(changedPaths));
+        });
+
+        return commitInfo;
+    }
+
+    private List<ChangedFile> changedFileList(Map<String, SVNLogEntryPath> changedPaths) {
+        List<ChangedFile> changedFiles = new ArrayList<>();
+        changedPaths.forEach((k, v) -> {
+            ChangedFile changedFile = new ChangedFile();
+            changedFile.setChangeType(String.valueOf(v.getType()));
+            // TODO 文件路径有问题
+            changedFile.setOldFilePath(v.getPath());
+            changedFile.setNewFilePath(v.getCopyPath());
+
+            changedFiles.add(changedFile);
+        });
+        return changedFiles;
     }
 
     /**
@@ -65,9 +107,15 @@ public class SvnImpl implements CodeUpdater {
             return null;
         }
 
-        SVNStatusClient statusClient = SVNClientManager.newInstance().getStatusClient();
-        final SVNStatus status = statusClient.doStatus(new File(local), false);
-
+        SVNStatus status = statusClient.doStatus(file, false);
         return status != null ? String.valueOf(status.getCommittedRevision().getNumber()) : null;
     }
+
+    public static void main(String[] args) throws SVNException {
+        String remote = "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Web.BMS/branches/20200205/IQuizoo_FrontEnd";
+        String local = "/home/reghao/tmp/autodop/opt/data/svn/IQuizoo_FrontEnd";
+        SvnImpl svn = new SvnImpl("gjs", "gjs1234");
+        CommitInfo commitInfo = svn.update(remote, local);
+        System.out.println(svn.localVersion(local));
+    }
 }

+ 16 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppVO.java

@@ -0,0 +1,16 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+
+/**
+ * @author reghao
+ * @date 2020-02-29 17:22:19
+ */
+public class AppVO {
+    protected String appId;
+
+    public static AppVO of(AppOrchestration app) {
+        AppVO vo = new AppVO();
+        return vo;
+    }
+}

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/PageList.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/PageList.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.orchestrate.vo;
+package cn.reghao.autodop.dmaster.app.vo;
 
 import lombok.Data;
 

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/ProjVO.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
+
+/**
+ * @author reghao
+ * @date 2020-02-29 17:22:19
+ */
+public class ProjVO {
+    public static ProjVO of(ProjOrchestration proj, String appIds) {
+        ProjVO vo = new ProjVO();
+        return vo;
+    }
+}

+ 4 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/utils/SysInitializer.java

@@ -2,7 +2,6 @@ package cn.reghao.autodop.dmaster.common.utils;
 
 import cn.reghao.autodop.common.utils.FileUtil;
 import cn.reghao.autodop.dmaster.common.config.SysConfigProperties;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
@@ -31,9 +30,9 @@ public class SysInitializer implements ApplicationRunner {
     }
 
     public void initialize() {
-        SysConfig.localRepos = sysConfigProperties.getLocalRepos();
+        /*SysConfig.localRepos = sysConfigProperties.getLocalRepos();
         SysConfig.compileDir = sysConfigProperties.getCompileDir();
-        SysConfig.packDir = sysConfigProperties.getPackDir();
+        SysConfig.packDir = sysConfigProperties.getPackDir();*/
 
         checkAndSet();
         log.info("autodop 系统初始化完成...");
@@ -45,7 +44,7 @@ public class SysInitializer implements ApplicationRunner {
      * @date 2019-11-17 上午11:38
      */
     private void checkAndSet() {
-        File localRepo = new File(SysConfig.localRepos);
+        /*File localRepo = new File(SysConfig.localRepos);
         if (!localRepo.exists() && !FileUtil.mkdir(localRepo)) {
             log.error("{} 不存在且创建失败...", localRepo.getAbsolutePath());
             throw new IllegalArgumentException(localRepo.getAbsolutePath() + " 不存在且创建失败...");
@@ -61,6 +60,6 @@ public class SysInitializer implements ApplicationRunner {
         if (!packDir.exists() && !FileUtil.mkdir(packDir)) {
             log.error("{} 不存在且创建失败...", packDir.getAbsolutePath());
             throw new IllegalArgumentException(packDir.getAbsolutePath() + " 不存在且创建失败...");
-        }
+        }*/
     }
 }

+ 0 - 68
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/caching/OrchestrationCaching.java

@@ -1,68 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.caching;
-
-import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.orchestrate.dao.AppDAO;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
-import cn.reghao.autodop.dmaster.orchestrate.repository.NotifierRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.AppPackerRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.CodeCompilerRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.ReposAuthRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.orchestration.AppOrchestrationRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.orchestration.ProjectOrchestrationRepository;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.cache.annotation.CachePut;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-
-/**
- * @author reghao
- * @date 2020-03-06 15:17:33
- */
-@Slf4j
-@Service
-public class OrchestrationCaching {
-    private ProjectOrchestrationRepository projRepository;
-    private AppOrchestrationRepository appRepository;
-    private AppDAO appDAO;
-
-    private NotifierRepository notifierRepository;
-    private ReposAuthRepository reposAuthRepository;
-    private CodeCompilerRepository codeCompilerRepository;
-    private AppPackerRepository appPackerRepository;
-
-    public OrchestrationCaching(ProjectOrchestrationRepository projRepository,
-                                AppOrchestrationRepository appRepository) {
-        this.projRepository = projRepository;
-        this.appRepository = appRepository;
-    }
-
-    //@Cacheable(cacheNames = "app", key = "#app.identifier")
-    public void add(AppOrchestration app) {
-    }
-
-    @Cacheable(cacheNames = "proj", key = "#identifier")
-    public ProjOrchestration findProjByIdentifier(String identifier) {
-        // TODO 数据库中没有数据时不缓存
-        ProjOrchestration proj = projRepository.findByIdentifier(identifier);
-        return proj;
-    }
-
-    //@Cacheable(cacheNames = "app", key = "#identifier", condition = "#app != null ", unless = "#app != null")
-    @Cacheable(cacheNames = "app", key = "#identifier")
-    public AppOrchestration findAppByIdentifier(String identifier) {
-        // TODO 数据库中没有数据时不缓存
-        /*AppOrchestration app = appRepository.findByIdentifier(identifier);
-        return app;*/
-
-        return null;
-    }
-
-    //@CachePut(cacheNames = "app", key = "#app.identifier")
-    public void modify(AppOrchestration app) {
-    }
-
-    //@CacheEvict(cacheNames = "app", key = "#identifier")
-    public void delete(String identifier) {
-    }
-}

+ 0 - 88
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/controller/OrchestrateController.java

@@ -1,88 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.controller;
-
-import cn.reghao.autodop.dmaster.common.result.ResultCode;
-import cn.reghao.autodop.dmaster.common.result.WebResult;
-import cn.reghao.autodop.dmaster.orchestrate.service.OrchestrateService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * @author reghao
- * @date 2019-11-27 11:29:43
- */
-@Slf4j
-@Api(tags = "应用编排 CURD 接口")
-@RestController
-@RequestMapping("/api/app")
-public class OrchestrateController {
-    private OrchestrateService orchestrateService;
-
-    public OrchestrateController(OrchestrateService orchestrateService) {
-        this.orchestrateService = orchestrateService;
-    }
-
-    @ApiOperation(value = "新增项目/应用编排")
-    @PostMapping(value = "/orchestrate/{type}", consumes = "application/json")
-    public String addOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
-        orchestrateService.add(type, json);
-        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
-    }
-
-    @ApiOperation(value = "批量新增项目/应用编排")
-    @PostMapping(value = "/orchestrate/batch/{type}", consumes = "application/json")
-    public String batchAddOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
-        orchestrateService.batchAdd(type, json);
-        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
-    }
-
-    @ApiOperation(value = "获取项目/应用编排")
-    @GetMapping("/orchestrate/{type}/{identifier}")
-    public String getOrchestration(@PathVariable("type") int type, @PathVariable("identifier") String identifier) {
-        return orchestrateService.get(type, identifier);
-    }
-
-    @ApiOperation(value = "分页获取所有的项目/应用编排")
-    @GetMapping("/orchestrate/{type}")
-    public String getOrchestrationByPage(@PathVariable("type") int type,
-                                         @RequestParam("page") int page,
-                                         @RequestParam("size") int size) {
-
-        //Pagination pagination = new Pagination(page, size);
-        PageRequest pageRequest = PageRequest.of(page-1, size);
-        return orchestrateService.getByPage(type, pageRequest);
-    }
-
-    // TODO 鉴于 Hibernate 特性,新增,修改和更新都合并到一个接口
-    @ApiOperation(value = "修改项目/应用编排字段")
-    @PatchMapping("/orchestrate/{type}/{identifier}")
-    public String modifyOrchestrationField(@PathVariable("type") int type,
-                                           @PathVariable("identifier") String identifier) {
-
-        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
-    }
-
-    @ApiOperation(value = "更新项目/应用编排")
-    @PutMapping("/orchestrate/{type}")
-    public String updateOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
-        orchestrateService.modify(type, json);
-        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
-    }
-
-    @ApiOperation(value = "删除项目/应用编排")
-    @DeleteMapping("/orchestrate/{type}/{identifier}")
-    public String deleteOrchestration(@PathVariable("type") int type,
-                                      @PathVariable("identifier") String identifier) {
-
-        orchestrateService.delete(type, identifier);
-        return new WebResult<String>(ResultCode.SUCCESS).jsonResult("ok");
-    }
-
-    @ApiOperation(value = "获取构建配置")
-    @GetMapping("/orchestrate/build/{type}")
-    public String getBuild(@PathVariable("type") int type) {
-        return orchestrateService.getBuild(type);
-    }
-}

+ 0 - 14
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/SysConfig.java

@@ -1,14 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo;
-
-/**
- * @author reghao
- * @date 2020-03-09 14:36:41
- */
-public class SysConfig {
-    // 本地仓库
-    public static String localRepos;
-    // 编译目录
-    public static String compileDir;
-    // 应用打包后存放的目录
-    public static String packDir;
-}

+ 0 - 27
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppBuild.java

@@ -1,27 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.CodeCompiler;
-import lombok.Data;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:39:22
- */
-@Data
-@Embeddable
-public class AppBuild {
-    @ManyToOne(cascade = CascadeType.PERSIST)
-    private Notifier notifier;
-
-    private CodeRepos codeRepos;
-
-    @ManyToOne(cascade = CascadeType.PERSIST)
-    private CodeCompiler codeCompiler;
-
-    @ManyToOne(cascade = CascadeType.PERSIST)
-    private AppPacker appPacker;
-}

+ 0 - 18
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppDeploy.java

@@ -1,18 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import lombok.Data;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:40:17
- */
-@Data
-@Embeddable
-public class AppDeploy {
-    /*@ElementCollection
-    private Set<String> hosts;*/
-    // 以 “,” 分割的字符串
-    private String hosts;
-}

+ 0 - 17
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppLog.java

@@ -1,17 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import lombok.Data;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author reghao
- * @date 2020-03-06 17:15:35
- */
-@Data
-@Embeddable
-public class AppLog {
-    // 只有 console 和 file 两种类型
-    private String logType;
-    private String logDir;
-}

+ 0 - 21
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/AppRunning.java

@@ -1,21 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import lombok.Data;
-
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:40:42
- */
-@Data
-@Embeddable
-public class AppRunning {
-    // 默认是 HTTP 端口
-    @Column(nullable = false)
-    private int port;
-    private String healthCheck;
-    private String runningDir;
-    private AppLog log;
-}

+ 0 - 23
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/CodeRepos.java

@@ -1,23 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.ReposAuth;
-import lombok.Data;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:35:42
- */
-@Data
-@Embeddable
-public class CodeRepos {
-    @ManyToOne(cascade = CascadeType.PERSIST)
-    private ReposAuth reposAuth;
-    private String reposUrl;
-
-    // TODO 由于前端不好处理,因此将集合存储为以 “,” 分割的字符串
-    /*@ElementCollection
-    private Set<String> dependencyUrls;*/
-    private String dependencyUrls;
-}

+ 0 - 16
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/ConfigFile.java

@@ -1,16 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import lombok.Data;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author reghao
- * @date 2020-02-29 13:12:33
- */
-@Data
-@Embeddable
-public class ConfigFile {
-    private String filename;
-    private String filecontent;
-}

+ 0 - 20
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/build/ProjBuild.java

@@ -1,20 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.build;
-
-import lombok.Data;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:42:04
- */
-@Data
-@Embeddable
-public class ProjBuild {
-    private String projId;
-    private String appReposUrl;
-
-    /*@ElementCollection
-    private Set<String> dependencyUrls;*/
-    private String appDependencyUrls;
-}

+ 0 - 28
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/AppOrchestration.java

@@ -1,28 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:11:02
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class AppOrchestration extends Orchestration {
-    private AppBuild build;
-    private ProjBuild projBuild;
-    private AppDeploy deploy;
-    private AppRunning running;
-    private String env;
-    // 编译 app 时所处的目录,以仓库目录为起点
-    private String entryDir;
-    // TODO 假设在集群部署时应用只有访问地址不一样,其它的配置文件都是一样
-    @ElementCollection(fetch = FetchType.EAGER)
-    private Map<String, String> configFiles;
-}

+ 0 - 26
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/Orchestration.java

@@ -1,26 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-
-/**
- * TODO 所有的编排都继承自此类
- *
- * @author reghao
- * @date 2020-02-28 14:11:18
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-@Inheritance(strategy = InheritanceType.JOINED)
-public class Orchestration extends BaseEntity {
-    @Column(nullable = false, unique = true)
-    protected String identifier;
-    protected String dirname;
-    protected String description;
-    //@Enumerated(EnumType.STRING)
-    protected String orchestrationType;
-}

+ 0 - 19
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/orchestration/ProjOrchestration.java

@@ -1,19 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppBuild;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:11:18
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-@Inheritance(strategy = InheritanceType.JOINED)
-public class ProjOrchestration extends Orchestration {
-    private AppBuild build;
-}

+ 0 - 26
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/AppPacker.java

@@ -1,26 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:17:15
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class AppPacker extends BaseEntity {
-    @Column(nullable = false, unique = true)
-    private String packerName;
-
-    // 获取已打包应用的路径
-    @Column(nullable = false)
-    private String appRootPath;
-
-    //@Enumerated(EnumType.STRING)
-    private String packerType;
-}

+ 0 - 25
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/CodeCompiler.java

@@ -1,25 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:15:22
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class CodeCompiler extends BaseEntity {
-    @Column(nullable = false, unique = true)
-    private String compilerName;
-
-    @Column(nullable = false)
-    private String script;
-
-    //@Enumerated(EnumType.STRING)
-    private String compilerType;
-}

+ 0 - 21
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/Notifier.java

@@ -1,21 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.Entity;
-
-/**
- * @author reghao
- * @date 2020-03-06 21:20:06
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class Notifier extends BaseEntity {
-    // ding, email, sms
-    private String notifierType;
-    private String notifierName;
-    private String notifierAddress;
-}

+ 0 - 36
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/ReposAuth.java

@@ -1,36 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.BaseEntity;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import javax.persistence.*;
-
-/**
- * @author reghao
- * @date 2020-02-28 14:12:33
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Entity
-public class ReposAuth extends BaseEntity {
-    /*@Id
-    @GeneratedValue(generator = "identifier_as_pk")
-    @GenericGenerator(
-            name = "identifier_as_pk",
-            strategy = "cn.reghao.autodop.dmaster.common.utils.hibernate.PrimaryKeyGenerator",
-            parameters = @org.hibernate.annotations.Parameter(name = "pkFiled", value = "authName")
-    )
-    private String id;*/
-    // TODO 考虑使用联合主键
-    @Column(nullable = false, unique = true)
-    private String reposName;
-
-    private String username;
-
-    @Column(nullable = false)
-    private String password;
-
-    //@Enumerated(EnumType.STRING)
-    private String reposType;
-}

+ 0 - 32
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/CompilerType.java

@@ -1,32 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools.constant;
-
-/**
- * 编译工具类型
- *
- * @author reghao
- * @date 2019-10-18 14:31:29
- */
-public enum CompilerType {
-    none(1, "不需要编译"),
-    dotnet(2, "编译 DotNet 应用"),
-    maven(3, "编译 Java 应用"),
-    npm(4, "编译 JS 应用"),
-    gobuild(5, "编译 Go 应用"),
-    gpp(6, "编译 C++ 应用");
-
-    private int code;
-    private String value;
-
-    CompilerType(int code, String value) {
-        this.code = code;
-        this.value = value;
-    }
-
-    public int code() {
-        return code;
-    }
-
-    public String value() {
-        return value;
-    }
-}

+ 0 - 28
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/OrchestrationType.java

@@ -1,28 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools.constant;
-
-/**
- * TODO 此包下面的所有枚举类都应该弃用,因为在运行时不能修改数据
- *
- * @author reghao
- * @date 2020-03-01 17:18:53
- */
-public enum OrchestrationType {
-    proj(1, "编排项目"),
-    app(2, "编排应用");
-
-    private int code;
-    private String value;
-
-    OrchestrationType(int code, String value) {
-        this.code = code;
-        this.value = value;
-    }
-
-    public int code() {
-        return code;
-    }
-
-    public String value() {
-        return value;
-    }
-}

+ 0 - 30
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/PackerType.java

@@ -1,30 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools.constant;
-
-/**
- * 打包工具类型
- *
- * @author reghao
- * @date 2019-11-15 21:59:35
- */
-public enum PackerType {
-    tar(1, "打包为 tar 文件"),
-    docker(2, "打包为 docker 应用"),
-    maven(3, "打包为 jar 应用或 war 应用"),
-    dotnetBinary(4, "打包为 dotnet 二进制应用");
-
-    private int code;
-    private String value;
-
-    PackerType(int code, String value) {
-        this.code = code;
-        this.value = value;
-    }
-
-    public int code() {
-        return code;
-    }
-
-    public String value() {
-        return value;
-    }
-}

+ 0 - 28
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/pojo/tools/constant/ReposType.java

@@ -1,28 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.pojo.tools.constant;
-
-/**
- * 版本管理系统类型
- *
- * @author reghao
- * @date 2019-11-15 22:41:04
- */
-public enum ReposType {
-    svn(1, "SVN 版本管理工具"),
-    git(2, "Git 版本管理工具");
-
-    private int code;
-    private String value;
-
-    ReposType(int code, String value) {
-        this.code = code;
-        this.value = value;
-    }
-
-    public int code() {
-        return code;
-    }
-
-    public String value() {
-        return value;
-    }
-}

+ 0 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/NotifierRepository.java

@@ -1,12 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-/**
- * @author reghao
- * @date 2020-01-21 14:53:03
- */
-public interface NotifierRepository extends JpaRepository<Notifier, Long> {
-    Notifier findByNotifierName(String notifierName);
-}

+ 0 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/AppPackerRepository.java

@@ -1,12 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository.build;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-/**
- * @author reghao
- * @date 2020-01-21 14:53:03
- */
-public interface AppPackerRepository extends JpaRepository<AppPacker, Long> {
-    AppPacker findByPackerName(String packerName);
-}

+ 0 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/CodeCompilerRepository.java

@@ -1,12 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository.build;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.CodeCompiler;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-/**
- * @author reghao
- * @date 2020-01-21 14:53:03
- */
-public interface CodeCompilerRepository extends JpaRepository<CodeCompiler, Long> {
-    CodeCompiler findByCompilerName(String compilerName);
-}

+ 0 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/repository/build/ReposAuthRepository.java

@@ -1,12 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.repository.build;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.ReposAuth;
-import org.springframework.data.jpa.repository.JpaRepository;
-
-/**
- * @author reghao
- * @date 2020-01-21 14:53:03
- */
-public interface ReposAuthRepository extends JpaRepository<ReposAuth, Long> {
-    ReposAuth findByReposName(String reposName);
-}

+ 0 - 329
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/service/OrchestrateService.java

@@ -1,329 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.service;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.CodeCompiler;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.ReposAuth;
-import cn.reghao.autodop.dmaster.common.result.ResultCode;
-import cn.reghao.autodop.dmaster.common.result.WebResult;
-import cn.reghao.autodop.common.utils.JsonUtil;
-import cn.reghao.autodop.dmaster.orchestrate.caching.OrchestrationCaching;
-import cn.reghao.autodop.dmaster.orchestrate.dao.AppDAO;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.*;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.*;
-import cn.reghao.autodop.dmaster.orchestrate.repository.NotifierRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.CodeCompilerRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.AppPackerRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.build.ReposAuthRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.orchestration.AppOrchestrationRepository;
-import cn.reghao.autodop.dmaster.orchestrate.repository.orchestration.ProjectOrchestrationRepository;
-import cn.reghao.autodop.dmaster.orchestrate.vo.AppVO;
-import cn.reghao.autodop.dmaster.orchestrate.vo.PageList;
-import cn.reghao.autodop.dmaster.orchestrate.vo.ProjVO;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2020-02-28 17:10:37
- */
-@Service
-public class OrchestrateService {
-    private ProjectOrchestrationRepository projOrchestrationRepository;
-    private AppOrchestrationRepository appOrchestrationRepository;
-    private AppDAO appDAO;
-
-    private NotifierRepository notifierRepository;
-    private ReposAuthRepository reposAuthRepository;
-    private CodeCompilerRepository codeCompilerRepository;
-    private AppPackerRepository appPackerRepository;
-    private OrchestrationCaching orchestrationCaching;
-    
-    public OrchestrateService(ProjectOrchestrationRepository projOrchestrationRepository,
-                              AppOrchestrationRepository appOrchestrationRepository,
-                              AppDAO appDAO,
-                              NotifierRepository notifierRepository,
-                              ReposAuthRepository reposAuthRepository,
-                              CodeCompilerRepository codeCompilerRepository,
-                              AppPackerRepository appPackerRepository,
-                              OrchestrationCaching orchestrationCaching) {
-
-        this.projOrchestrationRepository = projOrchestrationRepository;
-        this.appOrchestrationRepository = appOrchestrationRepository;
-        this.appDAO = appDAO;
-
-        this.notifierRepository = notifierRepository;
-        this.reposAuthRepository = reposAuthRepository;
-        this.codeCompilerRepository = codeCompilerRepository;
-        this.appPackerRepository = appPackerRepository;
-
-        this.orchestrationCaching = orchestrationCaching;
-    }
-
-    public String getBuild(int type) {
-        switch (type) {
-            case 1:
-                List<ReposAuth> auths = reposAuthRepository.findAll();
-                Map<String, List<ReposAuth>> authMap = new HashMap<>();
-                auths.forEach(auth -> {
-                    auth.setId(null);
-                    auth.setCreateTime(null);
-                    List<ReposAuth> list = authMap.get(auth.getReposType());
-                    if (list != null) {
-                        list.add(auth);
-                    } else {
-                        list = new ArrayList<>();
-                        list.add(auth);
-                        authMap.put(auth.getReposType(), list);
-                    }
-                });
-
-                return new WebResult<Map<String, List<ReposAuth>>>(ResultCode.SUCCESS).jsonResult(authMap);
-            case 2:
-                List<CodeCompiler> compilers = codeCompilerRepository.findAll();
-                Map<String, List<CodeCompiler>> compilerMap = new HashMap<>();
-                compilers.forEach(compiler -> {
-                    compiler.setId(null);
-                    compiler.setCreateTime(null);
-                    List<CodeCompiler> list = compilerMap.get(compiler.getCompilerType());
-                    if (list != null) {
-                        list.add(compiler);
-                    } else {
-                        list = new ArrayList<>();
-                        list.add(compiler);
-                        compilerMap.put(compiler.getCompilerType(), list);
-                    }
-                });
-
-                return new WebResult<Map<String, List<CodeCompiler>> >(ResultCode.SUCCESS).jsonResult(compilerMap);
-            case 3:
-                List<AppPacker> packers = appPackerRepository.findAll();
-                Map<String, List<AppPacker>> packerMap = new HashMap<>();
-                packers.forEach(packer -> {
-                    packer.setId(null);
-                    packer.setCreateTime(null);
-                    List<AppPacker> list = packerMap.get(packer.getPackerType());
-                    if (list != null) {
-                        list.add(packer);
-                    } else {
-                        list = new ArrayList<>();
-                        list.add(packer);
-                        packerMap.put(packer.getPackerType(), list);
-                    }
-                });
-                return new WebResult<Map<String, List<AppPacker>>>(ResultCode.SUCCESS).jsonResult(packerMap);
-            default:
-                return null;
-        }
-    }
-
-    /**
-     * TODO 由于 AppBuild 和 ProjBuild 只能二选一,因此需要对 @ManyToOne 约束进行检查
-     * 检查构建阶段的共享实体是否存在
-     *
-     * @param
-     * @return
-     * @date 2020-03-01 下午6:34
-     */
-    private void checkSharedEntity(Orchestration orchestration) throws Exception {
-        if (orchestration instanceof ProjOrchestration) {
-            AppBuild build = ((ProjOrchestration) orchestration).getBuild();
-            if (build != null) {
-                checkManyToOne(build);
-            } else {
-                throw new Exception("配置出错咯~");
-            }
-        } else if (orchestration instanceof AppOrchestration) {
-            AppOrchestration app = (AppOrchestration) orchestration;
-            AppBuild build = app.getBuild();
-            ProjBuild projBuild = app.getProjBuild();
-            if (build == null && projBuild == null) {
-                throw new Exception("配置出错咯~");
-            } else if (build == null) {
-                String projId = projBuild.getProjId();
-                ProjOrchestration proj = projOrchestrationRepository.findByIdentifier(projId);
-                if (proj == null) {
-                    throw new Exception("配置出错咯~");
-                }
-            } else if (projBuild == null) {
-                checkManyToOne(build);
-            } else {
-                // AppBuild 和 ProjBuild 均存在时,使用 AppBuild
-                app.setProjBuild(null);
-                checkManyToOne(build);
-            }
-        }
-    }
-
-    // TODO 数据库查询异步化
-    private void checkManyToOne(AppBuild build) {
-        Notifier notifier = build.getNotifier();
-        Notifier notifierEntity = notifierRepository.findByNotifierName(notifier.getNotifierName());
-        if (notifierEntity != null) {
-            build.setNotifier(notifierEntity);
-        } else {
-            notifierRepository.save(notifier);
-        }
-
-        ReposAuth reposAuth = build.getCodeRepos().getReposAuth();
-        ReposAuth authEntity = reposAuthRepository.findByReposName(reposAuth.getReposName());
-        if (authEntity != null) {
-            build.getCodeRepos().setReposAuth(authEntity);
-        } else {
-            reposAuthRepository.save(reposAuth);
-        }
-
-        CodeCompiler compiler = build.getCodeCompiler();
-        if (compiler != null) {
-            CodeCompiler compilerEntity = codeCompilerRepository.findByCompilerName(compiler.getCompilerName());
-            if (compilerEntity != null) {
-                build.setCodeCompiler(compilerEntity);
-            } else {
-                codeCompilerRepository.save(compiler);
-            }
-        }
-
-        AppPacker packer = build.getAppPacker();
-        if (packer != null) {
-            AppPacker packerEntity = appPackerRepository.findByPackerName(packer.getPackerName());
-            if (packerEntity != null) {
-                build.setAppPacker(packerEntity);
-            } else {
-                appPackerRepository.save(packer);
-            }
-        }
-    }
-
-    // TODO 后期将 batchAdd 合并到此方法
-    public void add(int type, String json) throws Exception {
-        switch (type) {
-            case 1:
-                // 项目编排
-                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
-                checkSharedEntity(proj);
-                projOrchestrationRepository.save(proj);
-                break;
-            case 2:
-                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
-                checkSharedEntity(app);
-                appOrchestrationRepository.save(app);
-            default:
-        }
-    }
-
-    public void batchAdd(int type, String json) throws Exception {
-        // TODO 优化代码
-        switch (type) {
-            case 1:
-                List<Object> objs = JsonUtil.jsonToObjectArray(json, ProjOrchestration.class);
-                for (Object obj : objs) {
-                    ProjOrchestration proj = (ProjOrchestration) obj;
-                    checkSharedEntity(proj);
-                    // TODO 使用 saveAll 时若多个编排中具有相同的 UNIQUE 约束列值,则会引发 UNIQUE 约束异常
-                    projOrchestrationRepository.save(proj);
-                }
-                break;
-            case 2:
-                List<Object> objs1 = JsonUtil.jsonToObjectArray(json, AppOrchestration.class);
-                for (Object obj : objs1) {
-                    AppOrchestration app = (AppOrchestration) obj;
-                    checkSharedEntity(app);
-                    // TODO 使用 saveAll 时若多个编排中具有相同的 UNIQUE 约束列值,则会引发 UNIQUE 约束异常
-                    appOrchestrationRepository.save(app);
-                }
-            default:
-        }
-    }
-
-    public String get(int type, String identifier) {
-        switch (type) {
-            case 1:
-                ProjOrchestration proj = projOrchestrationRepository.findByIdentifier(identifier);
-                return new WebResult<ProjOrchestration>(ResultCode.SUCCESS).jsonResult(proj);
-            case 2:
-                //AppOrchestration app = orchestrationCaching.findAppByIdentifier(identifier);
-                //AppOrchestration app = appOrchestrationRepository.findByIdentifier(identifier);
-                //return new WebResult<AppOrchestration>(ResultCode.SUCCESS).jsonResult(app);
-            default:
-                return null;
-        }
-    }
-
-    public String getByPage(int type, PageRequest pageRequest) {
-        switch (type) {
-            case 1:
-                Page<ProjOrchestration> projPages = projOrchestrationRepository.findAll(pageRequest);
-                List<ProjVO> vos = new ArrayList<>();
-                projPages.forEach(proj -> {
-                    List<String> appIds = appDAO.findAppsByProjId(proj.getIdentifier());
-                    ProjVO vo = ProjVO.of(proj, appIds.toString()
-                            .replace("[", "").replace("]", ""));
-                    vos.add(vo);
-                });
-
-                PageList<ProjVO> list = new PageList<>();
-                list.setList(vos);
-                list.setSize(vos.size());
-
-                return new WebResult<PageList>(ResultCode.SUCCESS).jsonResult(list);
-            case 2:
-                Page<AppOrchestration> appPages = appOrchestrationRepository.findAll(pageRequest);
-                List<AppVO> appVOS = new ArrayList<>();
-                appPages.getContent().forEach(app -> {
-                    appVOS.add(AppVO.of(app));
-                });
-
-                PageList<AppVO> list1 = new PageList<>();
-                list1.setList(appVOS);
-                list1.setSize(appVOS.size());
-
-                return new WebResult<PageList>(ResultCode.SUCCESS).jsonResult(list1);
-            default:
-                return null;
-        }
-    }
-
-    // TODO 注意对编排修改时产生的数据不一致
-    public void modify(int type, String json) throws Exception {
-        switch (type) {
-            case 1:
-                // TODO 修改 projEntity 中与 proj 不同的地方
-                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
-                ProjOrchestration projEntity = projOrchestrationRepository.findByIdentifier(proj.getIdentifier());
-                projEntity.setDescription(proj.getDescription());
-
-                checkSharedEntity(proj);
-                projOrchestrationRepository.save(projEntity);
-                break;
-            case 2:
-                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
-                AppOrchestration appEntity = appOrchestrationRepository.findByIdentifier(app.getIdentifier());
-
-                app.setId(appEntity.getId());
-                app.setCreateTime(appEntity.getCreateTime());
-                checkSharedEntity(app);
-                appOrchestrationRepository.save(app);
-                break;
-            default:
-        }
-    }
-
-    public void delete(int type, String identifier) {
-        switch (type) {
-            case 1:
-                // TODO 删除项目时,所有与项目关联的应用都会失效
-                projOrchestrationRepository.deleteByIdentifier(identifier);
-                break;
-            case 2:
-                appOrchestrationRepository.deleteByIdentifier(identifier);
-                break;
-            default:
-        }
-    }
-}

+ 0 - 65
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/AppVO.java

@@ -1,65 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.vo;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.*;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.CodeCompiler;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
-
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2020-02-29 17:22:19
- */
-public class AppVO extends OrchestrationVO {
-    private ProjBuild projBuild;
-    private AppBuild build;
-    private AppDeploy deploy;
-    private AppRunning running;
-    private String env;
-    private String entryDir;
-    private Map<String, String> configFiles;
-
-    public static AppVO of(AppOrchestration app) {
-        AppVO vo = new AppVO();
-
-        vo.identifier = app.getIdentifier();
-        vo.description = app.getDescription();
-        vo.env = app.getEnv();
-        vo.orchestrationType = app.getOrchestrationType();
-
-        if (app.getProjBuild() != null) {
-            vo.projBuild = app.getProjBuild();
-        } else {
-            vo.build = app.getBuild();
-            vo.build.getCodeRepos().getReposAuth().setId(null);
-            vo.build.getCodeRepos().getReposAuth().setCreateTime(null);
-
-            Notifier notifier = vo.build.getNotifier();
-            if (notifier != null) {
-                notifier.setId(null);
-                notifier.setCreateTime(null);
-            }
-
-            CodeCompiler compiler = vo.build.getCodeCompiler();
-            if (compiler != null) {
-                compiler.setId(null);
-                compiler.setCreateTime(null);
-            }
-
-            AppPacker packer = vo.build.getAppPacker();
-            if (packer != null) {
-                packer.setId(null);
-                packer.setCreateTime(null);
-            }
-        }
-
-        vo.deploy = app.getDeploy();
-        vo.running = app.getRunning();
-        vo.entryDir = app.getEntryDir();
-        vo.configFiles = app.getConfigFiles();
-
-        return vo;
-    }
-}

+ 0 - 11
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/OrchestrationVO.java

@@ -1,11 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.vo;
-
-/**
- * @author reghao
- * @date 2020-03-02 13:17:58
- */
-public class OrchestrationVO {
-    protected String identifier;
-    protected String description;
-    protected String orchestrationType;
-}

+ 0 - 49
dmaster/src/main/java/cn/reghao/autodop/dmaster/orchestrate/vo/ProjVO.java

@@ -1,49 +0,0 @@
-package cn.reghao.autodop.dmaster.orchestrate.vo;
-
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppBuild;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.CodeCompiler;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
-
-/**
- * @author reghao
- * @date 2020-02-29 17:22:19
- */
-public class ProjVO extends OrchestrationVO {
-    private AppBuild build;
-    private String appIds;
-
-    public static ProjVO of(ProjOrchestration proj, String appIds) {
-        ProjVO vo = new ProjVO();
-
-        vo.identifier = proj.getIdentifier();
-        vo.description = proj.getDescription();
-        vo.orchestrationType = proj.getOrchestrationType();
-
-        vo.build = proj.getBuild();
-        vo.build.getCodeRepos().getReposAuth().setId(null);
-        vo.build.getCodeRepos().getReposAuth().setCreateTime(null);
-        Notifier notifier = vo.build.getNotifier();
-        if (notifier != null) {
-            notifier.setId(null);
-            notifier.setCreateTime(null);
-        }
-
-        CodeCompiler compiler = vo.build.getCodeCompiler();
-        if (compiler != null) {
-            compiler.setId(null);
-            compiler.setCreateTime(null);
-        }
-
-        AppPacker packer = vo.build.getAppPacker();
-        if (packer != null) {
-            packer.setId(null);
-            packer.setCreateTime(null);
-        }
-
-        vo.appIds = appIds;
-
-        return vo;
-    }
-}

+ 1 - 1
dmaster/src/main/resources/application-dev.yml

@@ -1,6 +1,6 @@
 spring:
   datasource:
-    url: jdbc:mysql://localhost:3306/reghao_autodop_rdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
+    url: jdbc:mysql://localhost:3306/reghao_autodop_rdb1?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
     username: reghao
     password: 12345678
 sysconfig:

+ 72 - 0
dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestrationTest.java

@@ -0,0 +1,72 @@
+package cn.reghao.autodop.dmaster.app.entity.orchestration;
+
+import cn.reghao.autodop.common.utils.JsonUtil;
+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.CompilerType;
+import cn.reghao.autodop.dmaster.app.entity.constant.NotifyType;
+import cn.reghao.autodop.dmaster.app.entity.constant.PackerType;
+import cn.reghao.autodop.dmaster.app.entity.constant.RepoType;
+import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class AppOrchestrationTest {
+
+    @Test
+    void main() {
+        AppUpdate appUpdate = new AppUpdate();
+        appUpdate.setRepoName("svn-214");
+        appUpdate.setRepoType(RepoType.svn.name());
+        appUpdate.setUsername("gjs");
+        appUpdate.setPassword("gjs1234");
+
+        AppCompile appCompile = new AppCompile();
+        appCompile.setCompilerName("dotnet2.2");
+        appCompile.setCompilerType(CompilerType.dotnet.name());
+        appCompile.setCompilerHome("/home/reghao/opt/env/dotnet/dotnet-sdk-2.2.101");
+        appCompile.setScript("dotnet publish");
+
+        AppPack appPack = new AppPack();
+        appPack.setPackerName("docker");
+        appPack.setPackerType(PackerType.docker.name());
+        appPack.setPackerPath("192.168.0.222:5000/iq3x");
+
+        AppBuild appBuild = new AppBuild();
+        appBuild.setAppUpdate(appUpdate);
+        appBuild.setAppCompile(appCompile);
+        appBuild.setAppPack(appPack);
+
+        AppDeploy appDeploy = new AppDeploy();
+        appDeploy.setHosts("localhost");
+        appDeploy.setHttpPort(8002);
+        appDeploy.setHealthCheck("/health");
+        appDeploy.setRunningDir("");
+
+        Notification notification = new Notification();
+        notification.setNotifyName("ding 通知");
+        notification.setNotifyType(NotifyType.ding.name());
+        notification.setDestination("https://oapi.dingtalk.com/robot/send?access_token=ba9cf0d846cff8c471168e0d2f91ec0c44645a086cf5e4e421697c9b0c606bd2");
+
+        AppOrchestration app = new AppOrchestration();
+        app.setAppId("content");
+        app.setDirname("ContentService");
+        app.setDescription("内容服务");
+        app.setAppRepo("svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/ContentService");
+        app.setDependencyRepos("svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/DataCenter," +
+                "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/ContentService," +
+                "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/UserService," +
+                "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/DotNetCore");
+        app.setEnv("dev");
+        app.setEntryDir("/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService");
+        //app.setProjId("branch-20200509");
+        app.setAppBuild(appBuild);
+        app.setNotification(notification);
+        app.setAppDeploy(appDeploy);
+
+        System.out.println("\n" + JsonUtil.objectToJson(app));
+    }
+}

+ 49 - 0
dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/ProjOrchestrationTest.java

@@ -0,0 +1,49 @@
+package cn.reghao.autodop.dmaster.app.entity.orchestration;
+
+import cn.reghao.autodop.common.utils.JsonUtil;
+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.CompilerType;
+import cn.reghao.autodop.dmaster.app.entity.constant.PackerType;
+import cn.reghao.autodop.dmaster.app.entity.constant.RepoType;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ProjOrchestrationTest {
+
+    @Test
+    void main() {
+        AppUpdate appUpdate = new AppUpdate();
+        appUpdate.setRepoName("svn-214");
+        appUpdate.setRepoType(RepoType.svn.name());
+        appUpdate.setUsername("gjs");
+        appUpdate.setPassword("gjs1234");
+
+        AppCompile appCompile = new AppCompile();
+        appCompile.setCompilerName("dotnet2.2");
+        appCompile.setCompilerType(CompilerType.dotnet.name());
+        appCompile.setCompilerHome("/home/reghao/opt/env/dotnet/dotnet-sdk-2.2.101");
+        appCompile.setScript("dotnet publish");
+
+        AppPack appPack = new AppPack();
+        appPack.setPackerName("docker");
+        appPack.setPackerType(PackerType.docker.name());
+        appPack.setPackerPath("192.168.0.222:5000/iq3x");
+
+        AppBuild appBuild = new AppBuild();
+        appBuild.setAppUpdate(appUpdate);
+        appBuild.setAppCompile(appCompile);
+        appBuild.setAppPack(appPack);
+
+        ProjOrchestration proj = new ProjOrchestration();
+        proj.setProjId("branch-20200509");
+        proj.setDescription("20200509 分支");
+        proj.setProjRepo("svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509");
+        proj.setAppBuild(appBuild);
+
+        System.out.println("\n" + JsonUtil.objectToJson(proj));
+    }
+}

+ 21 - 0
scripts/app-in-proj.json

@@ -0,0 +1,21 @@
+{
+  "appId":"content",
+  "dirname":"ContentService",
+  "description":"内容服务",
+  "appRepo":"/ContentService",
+  "dependencyRepos":"/DataCenter,/ContentService,/UserService,/DotNetCore",
+  "env":"dev",
+  "entryDir":"/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService",
+  "projId":"branch-20200509",
+  "appDeploy":{
+    "hosts":"localhost",
+    "httpPort":8002,
+    "healthCheck":"/health",
+    "runningDir":""
+  },
+  "notification":{
+    "notifyName":"ding 通知",
+    "notifyType":"ding",
+    "destination":"https://oapi.dingtalk.com/robot/send?access_token=ba9cf0d846cff8c471168e0d2f91ec0c44645a086cf5e4e421697c9b0c606bd2"
+  }
+}

+ 39 - 0
scripts/app.json

@@ -0,0 +1,39 @@
+{
+  "appId":"content",
+  "dirname":"ContentService",
+  "description":"内容服务",
+  "env":"dev",
+  "entryDir":"/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService",
+  "appRepo":"svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/ContentService",
+  "dependencyRepos":"svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/DataCenter,svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/ContentService,svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/UserService,svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/DotNetCore",
+  "appBuild":{
+    "appUpdate":{
+      "repoName":"svn-214",
+      "repoType":"svn",
+      "username":"gjs",
+      "password":"gjs1234"
+    },
+    "appCompile":{
+      "compilerName":"dotnet2.2",
+      "compilerType":"dotnet",
+      "compilerHome":"/home/reghao/opt/env/dotnet/dotnet-sdk-2.2.101",
+      "script":"dotnet publish"
+    },
+    "appPack":{
+      "packerName":"docker",
+      "packerType":"docker",
+      "packerPath":"192.168.0.222:5000/iq3x"
+    }
+  },
+  "appDeploy":{
+    "hosts":"localhost",
+    "httpPort":8002,
+    "healthCheck":"/health",
+    "runningDir":""
+  },
+  "notification":{
+    "notifyName":"ding 通知",
+    "notifyType":"ding",
+    "destination":"https://oapi.dingtalk.com/robot/send?access_token=ba9cf0d846cff8c471168e0d2f91ec0c44645a086cf5e4e421697c9b0c606bd2"
+  }
+}

+ 24 - 0
scripts/proj.json

@@ -0,0 +1,24 @@
+{
+  "projId":"branch-20200509",
+  "description":"20200509 分支",
+  "projRepo":"svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509",
+  "appBuild":{
+    "appUpdate":{
+      "repoName":"svn-214",
+      "repoType":"svn",
+      "username":"gjs",
+      "password":"gjs1234"
+    },
+    "appCompile":{
+      "compilerName":"dotnet2.2",
+      "compilerType":"dotnet",
+      "compilerHome":"/home/reghao/opt/env/dotnet/dotnet-sdk-2.2.101",
+      "script":"dotnet publish"
+    },
+    "appPack":{
+      "packerName":"docker",
+      "packerType":"docker",
+      "packerPath":"192.168.0.222:5000/iq3x"
+    }
+  }
+}