Просмотр исходного кода

对应前端编排和构建配置页面的修改

reghao 5 лет назад
Родитель
Сommit
3b620245f0
33 измененных файлов с 710 добавлено и 117 удалено
  1. 63 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildConfigController.java
  2. 19 11
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildController.java
  3. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppManageController.java
  4. 19 15
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppOrchestrateController.java
  5. 7 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/compile/AppCompile.java
  6. 7 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/pack/AppPack.java
  7. 7 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/build/update/AppUpdate.java
  8. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/AppDeploy.java
  9. 23 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/ConfigFile.java
  10. 7 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java
  11. 25 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/LocalFsConfig.java
  12. 8 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/Notification.java
  13. 4 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppDAO.java
  14. 4 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppOrchestrationRepository.java
  15. 202 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppRepository.java
  16. 13 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/LocalFsConfigRepository.java
  17. 160 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildConfigService.java
  18. 13 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildService.java
  19. 1 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppLogManager.java
  20. 16 16
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppOrchestrateService.java
  21. 5 10
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppStatusManager.java
  22. 7 6
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java
  23. 10 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java
  24. 4 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java
  25. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeployer.java
  26. 4 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DotnetPreCompile.java
  27. 0 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppBuildVO.java
  28. 9 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppVO.java
  29. 18 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/BuildConfig.java
  30. 10 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/PageList.java
  31. 30 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/SelectOption.java
  32. 5 5
      dmaster/src/test/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestrationTest.java
  33. 5 5
      scripts/build-and-deploy.sh

+ 63 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildConfigController.java

@@ -0,0 +1,63 @@
+package cn.reghao.autodop.dmaster.app.controller;
+
+import cn.reghao.autodop.dmaster.app.service.AppBuildConfigService;
+import cn.reghao.autodop.dmaster.app.vo.PageList;
+import cn.reghao.autodop.dmaster.common.webresult.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.data.domain.Sort;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author reghao
+ * @date 2019-08-30 18:49:15
+ */
+@Slf4j
+@Api(tags = "应用构建部署接口")
+@RestController
+@RequestMapping("/api/app/build/config")
+public class AppBuildConfigController {
+    private AppBuildConfigService buildConfigService;
+
+    public AppBuildConfigController(AppBuildConfigService buildConfigService) {
+        this.buildConfigService = buildConfigService;
+    }
+
+    @ApiOperation(value = "添加项目/应用编排")
+    @PostMapping(value = "/{type}", consumes = "application/json")
+    public ResponseEntity<String>addOrchestration(@PathVariable("type") int type,
+                                                  @RequestBody String json) throws Exception {
+        buildConfigService.saveOrUpdate(type, json);
+        return ResponseEntity.ok().body(WebResult.success("ok"));
+    }
+
+    @ApiOperation(value = "分页获取项目/应用编排(更新时间倒序)")
+    @GetMapping("/{type}")
+    public ResponseEntity<String>getOrchestrationByPage(@PathVariable("type") int type,
+                                                        @RequestParam("page") int page,
+                                                        @RequestParam("size") int size) {
+        PageRequest pageRequest =
+                PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
+        PageList pageList = buildConfigService.getByPage(type, pageRequest);
+        return ResponseEntity.ok().body(WebResult.success(pageList));
+    }
+
+    @ApiOperation(value = "修改项目/应用编排")
+    @PutMapping("/{type}")
+    public ResponseEntity<String> modifyOrchestration(@PathVariable("type") int type,
+                                                      @RequestBody String json) throws Exception {
+        buildConfigService.saveOrUpdate(type, json);
+        return ResponseEntity.ok().body(WebResult.success("ok"));
+    }
+
+    @ApiOperation(value = "删除项目/应用编排")
+    @DeleteMapping("/{type}/{name}")
+    public ResponseEntity<String>deleteOrchestration(@PathVariable("type") int type,
+                                                     @PathVariable("name") String name) {
+        buildConfigService.delete(type, name);
+        return ResponseEntity.ok().body(WebResult.success("ok"));
+    }
+}

+ 19 - 11
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppBuildController.java

@@ -44,6 +44,8 @@ public class AppBuildController {
         this.ossService = ossService;
     }
 
+    // TODO docker 打包时 repository:tag 为空
+    // TODO docker push 没有成功
     // TODO 添加一个 from 参数来表示构建部署请求来自何处,是主动构建还是自动构建
     @ApiOperation(value = "构建部署应用")
     @ApiImplicitParams(
@@ -127,43 +129,49 @@ public class AppBuildController {
                                             @RequestParam("page") int page,
                                             @RequestParam("size") int size) {
         //PageRequest pageRequest = PageRequest.of(page-1, size);
-        List<AppToBuild> res = buildService.buildList(env);
+        List<AppToBuild> res = buildService.buildList(env, null);
         PageList<AppToBuild> pageList = new PageList<>();
         pageList.setList(res);
-        pageList.setSize(res.size());
+        pageList.setTotalSize(res.size());
 
         return ResponseEntity.ok().body(WebResult.success(pageList));
     }
 
     @ApiOperation(value = "代码提交日志")
     @GetMapping("/logs/commit")
-    public ResponseEntity<String> commitLog() {
-        List<CommitLogVO> res = buildService.commitLogs();
+    public ResponseEntity<String> commitLogs(@RequestParam("env") String env,
+                                             @RequestParam("page") int page,
+                                             @RequestParam("size") int size) {
+        List<CommitLogVO> res = buildService.commitLogs(env);
         PageList<CommitLogVO> logs = new PageList<>();
         logs.setList(res);
-        logs.setSize(res.size());
+        logs.setTotalSize(res.size());
 
         return ResponseEntity.ok().body(WebResult.success(logs));
     }
 
     @ApiOperation(value = "构建日志")
     @GetMapping("/logs/build")
-    public ResponseEntity<String> buildLog() {
-        List<BuildLogVO> res = buildService.buildLogs();
+    public ResponseEntity<String> buildLogs(@RequestParam("env") String env,
+                                            @RequestParam("page") int page,
+                                            @RequestParam("size") int size) {
+        List<BuildLogVO> res = buildService.buildLogs(env);
         PageList<BuildLogVO> logs = new PageList<>();
         logs.setList(res);
-        logs.setSize(res.size());
+        logs.setTotalSize(res.size());
 
         return ResponseEntity.ok().body(WebResult.success(logs));
     }
 
     @ApiOperation(value = "部署日志")
     @GetMapping("/logs/deploy")
-    public ResponseEntity<String> deployLog() {
-        List<DeployLogVO> res = buildService.deployLogs();
+    public ResponseEntity<String> deployLogs(@RequestParam("env") String env,
+                                             @RequestParam("page") int page,
+                                             @RequestParam("size") int size) {
+        List<DeployLogVO> res = buildService.deployLogs(env);
         PageList<DeployLogVO> logs = new PageList<>();
         logs.setList(res);
-        logs.setSize(res.size());
+        logs.setTotalSize(res.size());
 
         return ResponseEntity.ok().body(WebResult.success(logs));
     }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppManageController.java

@@ -60,7 +60,7 @@ public class AppManageController {
         List<AppStatus> statusList = statusManager.status("dev");
         PageList<AppStatus> pageList = new PageList<>();
         pageList.setList(statusList);
-        pageList.setSize(statusList.size());
+        pageList.setTotalSize(statusList.size());
 
         return ResponseEntity.ok().body(WebResult.success(pageList));
     }

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

@@ -1,12 +1,13 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.dmaster.app.service.AppOrchestrateService;
-import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
+import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
 import cn.reghao.autodop.dmaster.common.webresult.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.data.domain.Sort;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
@@ -27,16 +28,17 @@ public class AppOrchestrateController {
 
     @ApiOperation(value = "添加项目/应用编排")
     @PostMapping(value = "/{type}", consumes = "application/json")
-    public ResponseEntity<String>addOrchestration(@PathVariable("type") int type, @RequestBody String json) throws Exception {
+    public ResponseEntity<String>addOrchestration(@PathVariable("type") int type,
+                                                  @RequestBody String json) throws Exception {
         appOrchestrateService.add(type, json);
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
 
-    @ApiOperation(value = "复制项目/应用编排")
-    @PostMapping(value = "/copy/{type}", consumes = "application/json")
-    public ResponseEntity<String>duplicateOrchestration(@PathVariable("type") int type,
-                                         @RequestParam("from") String from,
-                                         @RequestParam("to") String to) throws Exception {
+    @ApiOperation(value = "拷贝项目/应用编排")
+    @PostMapping(value = "/copy/{type}")
+    public ResponseEntity<String> copyOrchestration(@PathVariable("type") int type,
+                                                    @RequestParam("from") String from,
+                                                    @RequestParam("to") String to) throws Exception {
         boolean res = appOrchestrateService.copy(type, from, to);
         if (res) {
             return ResponseEntity.ok().body(WebResult.success("拷贝成功"));
@@ -52,13 +54,15 @@ public class AppOrchestrateController {
         return ResponseEntity.ok().body(WebResult.success(res));
     }
 
-    @ApiOperation(value = "分页获取项目/应用编排")
+    @ApiOperation(value = "分页获取项目/应用编排(更新时间倒序)")
     @GetMapping("/{type}")
     public ResponseEntity<String>getOrchestrationByPage(@PathVariable("type") int type,
-                                         @RequestParam("page") int page,
-                                         @RequestParam("size") int size) {
-        PageRequest pageRequest = PageRequest.of(page-1, size);
-        Object res = appOrchestrateService.getByPage(type, pageRequest);
+                                                        @RequestParam("env") String env,
+                                                        @RequestParam("page") int page,
+                                                        @RequestParam("size") int size) {
+        PageRequest pageRequest =
+                PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
+        Object res = appOrchestrateService.getByPage(type, env, pageRequest);
         return ResponseEntity.ok().body(WebResult.success(res));
     }
 
@@ -83,8 +87,8 @@ public class AppOrchestrateController {
 
     @ApiOperation(value = "获取编排应用时需要用到的配置")
     @GetMapping("/build")
-    public ResponseEntity<String> getAppBuilds() {
-        AppBuildVO appBuildVO = appOrchestrateService.appBuilds();
-        return ResponseEntity.ok().body(WebResult.success(appBuildVO));
+    public ResponseEntity<String> buildConfigs() {
+        BuildConfig buildConfig = appOrchestrateService.buildConfig();
+        return ResponseEntity.ok().body(WebResult.success(buildConfig));
     }
 }

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

@@ -20,4 +20,11 @@ public class AppCompile extends BaseEntity {
     private String compilerName;
     private String compilerHome;
     private String script;
+
+    public AppCompile  vo() {
+        this.setId(null);
+        this.setCreateTime(null);
+        this.setUpdateTime(null);
+        return this;
+    }
 }

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

@@ -21,4 +21,11 @@ public class AppPack extends BaseEntity {
     // 应用打包后存放的位置,可以是一个本地位置,也可以是一个网络位置
     // 根据打包类型来确定
     private String packerPath;
+
+    public AppPack vo() {
+        this.setId(null);
+        this.setCreateTime(null);
+        this.setUpdateTime(null);
+        return this;
+    }
 }

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

@@ -20,4 +20,11 @@ public class AppUpdate extends BaseEntity {
     private String repoName;
     private String username;
     private String password;
+
+    public AppUpdate vo() {
+        this.setId(null);
+        this.setCreateTime(null);
+        this.setUpdateTime(null);
+        return this;
+    }
 }

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

@@ -12,8 +12,8 @@ import java.util.Set;
 @Data
 @Embeddable
 public class AppDeploy {
-    // 多台主机以 “,” 分隔
-    private String hosts;
+    @ElementCollection(fetch = FetchType.EAGER)
+    private Set<String> hosts;
     private int httpPort;
     private String healthCheck;
     // 绝对路径

+ 23 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/deploy/ConfigFile.java

@@ -0,0 +1,23 @@
+package cn.reghao.autodop.dmaster.app.entity.deploy;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Embeddable;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author reghao
+ * @date 2020-05-19 09:24:41
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Embeddable
+public class ConfigFile {
+    @NotNull
+    private String filename;
+    @NotNull
+    private String filecontent;
+}

+ 7 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java

@@ -3,11 +3,14 @@ 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 cn.reghao.autodop.dmaster.app.entity.deploy.ConfigFile;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
 import javax.persistence.*;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * TODO 添加定时构建部署参数
@@ -28,16 +31,16 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
     // 是否总是构建
     private boolean alwaysBuild;
     // 编译 app 时所处的目录,以仓库目录为起点
-    private String entryDir;
+    private String compileDir;
     // TODO 添加定时构建部署选项
     // TODO 接入到项目管理系统
     // 配置文件
     @ElementCollection(fetch = FetchType.EAGER)
-    private Map<String, String> configFiles;
+    private Set<ConfigFile> configFiles;
     private String appRepo;
     @Column(length = 1024)
-    // TODO 使用 List
-    private String dependencyRepos;
+    @ElementCollection(fetch = FetchType.EAGER)
+    private Set<String> dependencyRepos;
 
     // projId 和 appBuild 二者只能存在一个
     @ManyToOne(cascade = CascadeType.PERSIST)

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

@@ -0,0 +1,25 @@
+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 2019-08-27 00:17:55
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Entity
+public class LocalFsConfig extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    private String env;
+    private String localRepo;
+    private String compileDir;
+    private String packDir;
+}

+ 8 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/Notification.java

@@ -18,5 +18,12 @@ public class Notification extends BaseEntity {
     private String notifierType;
     @Column(nullable = false, unique = true)
     private String notifierName;
-    private String destination;
+    private String webhook;
+
+    public Notification vo() {
+        this.setId(null);
+        this.setCreateTime(null);
+        this.setUpdateTime(null);
+        return this;
+    }
 }

+ 4 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppDAO.java

@@ -32,6 +32,10 @@ public class AppDAO {
                     .setParameter("enable", true)
                     .setParameter("env", env);
 
+            int page = 1;
+            int size = 10;
+            int index = 0;
+            hqlQuery.setFirstResult(index).setMaxResults(size).getResultList();
             return hqlQuery.getResultList();
         }
     }

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

@@ -1,11 +1,12 @@
 package cn.reghao.autodop.dmaster.app.repository.orchestration;
 
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 
 import javax.transaction.Transactional;
-import java.util.List;
 
 /**
  *
@@ -14,7 +15,8 @@ import java.util.List;
  */
 public interface AppOrchestrationRepository extends JpaRepository<AppOrchestration, Long> {
     AppOrchestration findByAppId(String appId);
-    List<AppOrchestration> findAllByEnableIsTrue();
+    Page<AppOrchestration> findAllByEnableIsTrue(String env, Pageable pageable);
+    Page<AppOrchestration> findByEnv(String env, Pageable pageable);
 
     @Modifying
     @Transactional

+ 202 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/AppRepository.java

@@ -3,14 +3,17 @@ package cn.reghao.autodop.dmaster.app.repository.orchestration;
 import cn.reghao.autodop.dmaster.app.entity.build.compile.AppCompile;
 import cn.reghao.autodop.dmaster.app.entity.build.pack.AppPack;
 import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.repository.build.AppCompileRepository;
 import cn.reghao.autodop.dmaster.app.repository.build.AppPackRepository;
 import cn.reghao.autodop.dmaster.app.repository.build.AppUpdateRepository;
 import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
+import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
+import cn.reghao.autodop.dmaster.app.vo.SelectOption;
 import org.springframework.stereotype.Repository;
 
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -24,36 +27,223 @@ public class AppRepository {
     private AppPackRepository packRepository;
     private AppOrchestrationRepository orchestrationRepository;
     private ProjectOrchestrationRepository projRepository;
+    private NotificationRepository notificationRepository;
 
     public AppRepository(AppUpdateRepository updateRepository,
                          AppCompileRepository compileRepository,
                          AppPackRepository packRepository,
                          ProjectOrchestrationRepository projRepository,
-                         AppOrchestrationRepository orchestrationRepository) {
+                         AppOrchestrationRepository orchestrationRepository,
+                         NotificationRepository notificationRepository) {
         this.updateRepository = updateRepository;
         this.compileRepository = compileRepository;
         this.packRepository = packRepository;
         this.orchestrationRepository = orchestrationRepository;
         this.projRepository = projRepository;
+        this.notificationRepository = notificationRepository;
     }
 
-    public AppBuildVO appBuilds() {
+    public BuildConfig buildConfig() {
         List<AppUpdate> appUpdates = updateRepository.findAll();
         List<AppCompile> appCompiles = compileRepository.findAll();
         List<AppPack> appPacks = packRepository.findAll();
+        List<Notification> notifications = notificationRepository.findAll();
 
-        AppBuildVO appBuildVO = new AppBuildVO();
-        appBuildVO.setAppUpdates(appUpdates);
-        appBuildVO.setAppCompiles(appCompiles);
-        appBuildVO.setAppPacks(appPacks);
+        List<SelectOption> updateOptions = new ArrayList<>();
+        convertToAppUpdates(appUpdates, updateOptions);
+        List<SelectOption> compileOptions = new ArrayList<>();
+        convertToAppCompiles(appCompiles, compileOptions);
+        List<SelectOption> packOptions = new ArrayList<>();
+        convertToAppPacks(appPacks, packOptions);
+        List<SelectOption> notificationOptions = new ArrayList<>();
+        convertToNotifications(notifications, notificationOptions);
 
-        return appBuildVO;
+        BuildConfig buildConfig = new BuildConfig();
+        buildConfig.setAppUpdates(updateOptions);
+        buildConfig.setAppCompiles(compileOptions);
+        buildConfig.setAppPacks(packOptions);
+        buildConfig.setNotifications(notificationOptions);
+
+        return buildConfig;
+    }
+
+    private void convertToAppUpdates(List<AppUpdate> appUpdates, List<SelectOption> options) {
+        Map<String, Integer> keys1 = new HashMap<>();
+        Map<String, Integer> keys2 = new HashMap<>();
+        Map<String, Integer> keys3 = new HashMap<>();
+        for (AppUpdate appUpdate : appUpdates) {
+            String repoType = appUpdate.getRepoType();
+            String repoName = appUpdate.getRepoName();
+            String username = appUpdate.getUsername();
+
+            Integer index1 = keys1.get(repoType);
+            Integer index2 = keys2.get(repoType + repoName);
+            Integer index3 = keys3.get(repoType + repoName + username);
+            if (index3 == null) {
+                if (index2 == null) {
+                    if (index1 == null) {
+                        SelectOption option1 = new SelectOption();
+                        option1.setValue(repoType);
+                        options.add(option1);
+                        keys1.put(repoType, options.size()-1);
+
+                        SelectOption option2 = new SelectOption();
+                        option2.setValue(repoName);
+                        List<SelectOption> list2 = new ArrayList<>();
+                        list2.add(option2);
+                        option1.setChildren(list2);
+                        keys2.put(repoType + repoName, list2.size()-1);
+
+                        SelectOption option3 = new SelectOption();
+                        option3.setValue(username);
+                        List<SelectOption> list3 = new ArrayList<>();
+                        list3.add(option3);
+                        option2.setChildren(list3);
+                        keys3.put(repoType + repoName + username, list3.size()-1);
+                    } else {
+                        SelectOption option1 = options.get(index1);
+
+                        SelectOption option2 = new SelectOption();
+                        option2.setValue(repoName);
+                        List<SelectOption> list2 = new ArrayList<>();
+                        list2.add(option2);
+                        option1.setChildren(list2);
+                        keys2.put(repoType + repoName, list2.size()-1);
+
+                        SelectOption option3 = new SelectOption();
+                        option3.setValue(username);
+                        List<SelectOption> list3 = new ArrayList<>();
+                        list3.add(option3);
+                        option2.setChildren(list3);
+                        keys3.put(repoType + repoName + username, list3.size()-1);
+                    }
+                } else {
+                    SelectOption option1 = options.get(index1);
+                    SelectOption option2 = option1.getChildren().get(index2);
+
+                    SelectOption option3 = new SelectOption();
+                    option3.setValue(username);
+                    List<SelectOption> list3 = new ArrayList<>();
+                    list3.add(option3);
+                    option2.setChildren(list3);
+                    keys3.put(repoType + repoName + username, list3.size()-1);
+                }
+            }
+        }
+    }
+
+    private void convertToAppCompiles(List<AppCompile> appCompiles, List<SelectOption> options) {
+        Map<String, Integer> keys1 = new HashMap<>();
+        Map<String, Integer> keys2 = new HashMap<>();
+        for (AppCompile appCompile : appCompiles) {
+            String compilerType = appCompile.getCompilerType();
+            String compilerName = appCompile.getCompilerName();
+
+            Integer index1 = keys1.get(compilerType);
+            Integer index2 = keys2.get(compilerType + compilerName);
+            if (index2 == null) {
+                if (index1 == null) {
+                    SelectOption option1 = new SelectOption();
+                    option1.setValue(compilerType);
+                    options.add(option1);
+                    keys1.put(compilerType, options.size()-1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(compilerName);
+                    List<SelectOption> list2 = new ArrayList<>();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(compilerType + compilerName, list2.size()-1);
+                } else {
+                    SelectOption option1 = options.get(index1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(compilerName);
+                    List<SelectOption> list2 = option1.getChildren();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(compilerType + compilerName, list2.size()-1);
+                }
+            }
+        }
+    }
+
+    private void convertToAppPacks(List<AppPack> appPacks, List<SelectOption> options) {
+        Map<String, Integer> keys1 = new HashMap<>();
+        Map<String, Integer> keys2 = new HashMap<>();
+        for (AppPack appPack : appPacks) {
+            String packerType = appPack.getPackerType();
+            String packerName = appPack.getPackerName();
+
+            Integer index1 = keys1.get(packerType);
+            Integer index2 = keys2.get(packerType + packerName);
+            if (index2 == null) {
+                if (index1 == null) {
+                    SelectOption option1 = new SelectOption();
+                    option1.setValue(packerType);
+                    options.add(option1);
+                    keys1.put(packerType, options.size()-1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(packerName);
+                    List<SelectOption> list2 = new ArrayList<>();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(packerType + packerName, list2.size()-1);
+                } else {
+                    SelectOption option1 = options.get(index1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(packerName);
+                    List<SelectOption> list2 = option1.getChildren();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(packerType + packerName, list2.size()-1);
+                }
+            }
+        }
+    }
+
+    private void convertToNotifications(List<Notification> notifications, List<SelectOption> options) {
+        Map<String, Integer> keys1 = new HashMap<>();
+        Map<String, Integer> keys2 = new HashMap<>();
+        for (Notification notification : notifications) {
+            String notifierType = notification.getNotifierType();
+            String notifierName = notification.getNotifierName();
+
+            Integer index1 = keys1.get(notifierType);
+            Integer index2 = keys2.get(notifierType + notifierName);
+            if (index2 == null) {
+                if (index1 == null) {
+                    SelectOption option1 = new SelectOption();
+                    option1.setValue(notifierType);
+                    options.add(option1);
+                    keys1.put(notifierType, options.size()-1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(notifierName);
+                    List<SelectOption> list2 = new ArrayList<>();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(notifierType + notifierName, list2.size()-1);
+                } else {
+                    SelectOption option1 = options.get(index1);
+
+                    SelectOption option2 = new SelectOption();
+                    option2.setValue(notifierName);
+                    List<SelectOption> list2 = option1.getChildren();
+                    list2.add(option2);
+                    option1.setChildren(list2);
+                    keys2.put(notifierType + notifierName, list2.size()-1);
+                }
+            }
+        }
     }
 
-    public void projIds(AppBuildVO appBuildVO) {
-        List<String> projIds = projRepository.findAll().stream()
-                .map(ProjOrchestration::getProjId)
+    public void projs(BuildConfig buildConfig) {
+        List<SelectOption> projs = projRepository.findAll().stream()
+                .map(proj -> new SelectOption(proj.getProjId(), proj.getDescription()))
                 .collect(Collectors.toList());
-        appBuildVO.setProjIds(projIds);
+        buildConfig.setProjs(projs);
     }
 }

+ 13 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/orchestration/LocalFsConfigRepository.java

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

+ 160 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildConfigService.java

@@ -0,0 +1,160 @@
+package cn.reghao.autodop.dmaster.app.service;
+
+import cn.reghao.autodop.common.utils.JsonUtil;
+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.LocalFsConfig;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
+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.LocalFsConfigRepository;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.NotificationRepository;
+import cn.reghao.autodop.dmaster.app.vo.PageList;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 17:10:37
+ */
+@Service
+public class AppBuildConfigService {
+    private NotificationRepository notificationRepository;
+    private AppUpdateRepository updateRepository;
+    private AppCompileRepository compileRepository;
+    private AppPackRepository packRepository;
+    private LocalFsConfigRepository configRepository;
+
+    public AppBuildConfigService(NotificationRepository notificationRepository,
+                                 AppUpdateRepository updateRepository,
+                                 AppCompileRepository compileRepository,
+                                 AppPackRepository packRepository,
+                                 LocalFsConfigRepository configRepository) {
+        this.notificationRepository = notificationRepository;
+        this.updateRepository = updateRepository;
+        this.compileRepository = compileRepository;
+        this.packRepository = packRepository;
+        this.configRepository = configRepository;
+    }
+
+    public void saveOrUpdate(int type, String json) throws Exception {
+        switch (type) {
+            case 0:
+                Notification notification = (Notification) JsonUtil.jsonToObject(json, Notification.class);
+                Notification notificationEntity =
+                        notificationRepository.findByNotifierName(notification.getNotifierName());
+                if (notificationEntity != null) {
+                    notification.setId(notificationEntity.getId());
+                    notification.setCreateTime(notificationEntity.getCreateTime());
+                    notification.setUpdateTime(LocalDateTime.now());
+                }
+                notificationRepository.save(notification);
+                return;
+            case 1:
+                AppUpdate appUpdate = (AppUpdate) JsonUtil.jsonToObject(json, AppUpdate.class);
+                AppUpdate updateEntity = updateRepository.findByRepoName(appUpdate.getRepoName());
+                if (updateEntity != null) {
+                    appUpdate.setId(updateEntity.getId());
+                    appUpdate.setCreateTime(updateEntity.getCreateTime());
+                    appUpdate.setUpdateTime(LocalDateTime.now());
+                }
+                updateRepository.save(appUpdate);
+                return;
+            case 2:
+                AppCompile appCompile = (AppCompile) JsonUtil.jsonToObject(json, AppCompile.class);
+                AppCompile compileEntity = compileRepository.findByCompilerName(appCompile.getCompilerName());
+                if (compileEntity != null) {
+                    appCompile.setId(compileEntity.getId());
+                    appCompile.setCreateTime(compileEntity.getCreateTime());
+                    appCompile.setUpdateTime(LocalDateTime.now());
+                }
+                compileRepository.save(appCompile);
+                return;
+            case 3:
+                AppPack appPack = (AppPack) JsonUtil.jsonToObject(json, AppPack.class);
+                AppPack packEntity = packRepository.findByPackerName(appPack.getPackerName());
+                if (packEntity != null) {
+                    appPack.setId(packEntity.getId());
+                    appPack.setCreateTime(packEntity.getCreateTime());
+                    appPack.setUpdateTime(LocalDateTime.now());
+                }
+                packRepository.save(appPack);
+                return;
+            case 4:
+                // TODO 有且仅执行一次,在系统初始化时执行
+                LocalFsConfig localFsConfig = (LocalFsConfig) JsonUtil.jsonToObject(json, LocalFsConfig.class);
+                LocalFsConfig configEntity = configRepository.findByEnv(localFsConfig.getEnv());
+                if (configEntity != null) {
+                    localFsConfig.setId(configEntity.getId());
+                    localFsConfig.setCreateTime(configEntity.getCreateTime());
+                    localFsConfig.setUpdateTime(LocalDateTime.now());
+                }
+                configRepository.save(localFsConfig);
+                return;
+            default:
+                throw new Exception(type + " 类型不存在");
+        }
+    }
+
+    public PageList getByPage(int type, PageRequest pageRequest) {
+        switch (type) {
+            case 0:
+                Page<Notification> notifications = notificationRepository.findAll(pageRequest);
+                PageList<Notification> pageList = new PageList<>();
+                pageList.setList(notifications.getContent());
+                pageList.setTotalSize(notifications.getTotalElements());
+                pageList.setTotalPages(notifications.getTotalPages());
+                return pageList;
+            case 1:
+                Page<AppUpdate> appUpdates = updateRepository.findAll(pageRequest);
+                PageList<AppUpdate> pageList1 = new PageList<>();
+                pageList1.setList(appUpdates.getContent());
+                pageList1.setTotalSize(appUpdates.getTotalElements());
+                pageList1.setTotalPages(appUpdates.getTotalPages());
+                return pageList1;
+            case 2:
+                Page<AppCompile> appCompiles = compileRepository.findAll(pageRequest);
+                PageList<AppCompile> pageList2 = new PageList<>();
+                pageList2.setList(appCompiles.getContent());
+                pageList2.setTotalSize(appCompiles.getTotalElements());
+                pageList2.setTotalPages(appCompiles.getTotalPages());
+                return pageList2;
+            case 3:
+                Page<AppPack> appPacks = packRepository.findAll(pageRequest);
+                PageList<AppPack> pageList3 = new PageList<>();
+                pageList3.setList(appPacks.getContent());
+                pageList3.setTotalSize(appPacks.getTotalElements());
+                pageList3.setTotalPages(appPacks.getTotalPages());
+                return pageList3;
+            case 4:
+                Page<LocalFsConfig> localFsConfigs = configRepository.findAll(pageRequest);
+                PageList<LocalFsConfig> pageList4 = new PageList<>();
+                pageList4.setList(localFsConfigs.getContent());
+                pageList4.setTotalSize(localFsConfigs.getTotalElements());
+                pageList4.setTotalPages(localFsConfigs.getTotalPages());
+                return pageList4;
+            default:
+                return null;
+        }
+    }
+
+    public void delete(int type, String name) {
+        switch (type) {
+            case 0:
+                break;
+            case 1:
+                break;
+            case 2:
+                break;
+            case 3:
+                break;
+            default:
+                break;
+        }
+    }
+}

+ 13 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildService.java

@@ -11,6 +11,8 @@ import cn.reghao.autodop.dmaster.app.vo.log.BuildLogVO;
 import cn.reghao.autodop.dmaster.app.vo.log.CommitLogVO;
 import cn.reghao.autodop.dmaster.app.vo.log.DeployLogVO;
 import cn.reghao.autodop.dmaster.app.vo.log.DeployResultVO;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -39,8 +41,8 @@ public class AppBuildService {
         this.appDAO = appDAO;
     }
 
-    public List<AppToBuild> buildList(String env) {
-        List<AppOrchestration> apps = appRepository.findAllByEnableIsTrue();
+    public List<AppToBuild> buildList(String env, PageRequest pageRequest) {
+        Page<AppOrchestration> apps = appRepository.findAllByEnableIsTrue(env, pageRequest);
         Set<String> appIds = apps.stream()
                 .filter(app -> app.getEnv().equals(env))
                 .map(AppOrchestration::getAppId)
@@ -62,26 +64,30 @@ public class AppBuildService {
         return appToBuilds;
     }
 
-    public List<CommitLogVO> commitLogs() {
+    public List<CommitLogVO> commitLogs(String env) {
         return buildLogRepository.findAll().stream()
+                .filter(buildLog -> buildLog.getApp().getEnv().equals(env))
                 .map(buildLog -> CommitLogVO.of(buildLog.getApp().getAppId(), buildLog.getCommitLog()))
                 .collect(Collectors.toList());
     }
 
-    public List<BuildLogVO> buildLogs() {
+    public List<BuildLogVO> buildLogs(String env) {
         List<BuildLog> buildLogs = buildLogRepository.findAll();
         return buildLogs.stream()
+                .filter(buildLog -> buildLog.getApp().getEnv().equals(env))
                 .map(BuildLogVO::of)
                 .collect(Collectors.toList());
     }
 
-    public List<DeployLogVO> deployLogs() {
-        List<DeployLog> deployLogs = deployLogRepository.findAll();
+    public List<DeployLogVO> deployLogs(String env) {
+        List<DeployLog> deployLogs = deployLogRepository.findAll().stream()
+                .filter(deployLog -> deployLog.getBuildLog().getApp().getEnv().equals(env))
+                .collect(Collectors.toList());
+
         List<DeployLogVO> deployLogVOS = new ArrayList<>();
         for (DeployLog deployLog : deployLogs) {
             BuildLog buildLog = deployLog.getBuildLog();
             String appId = buildLog.getApp().getAppId();
-            String env = buildLog.getApp().getEnv();
             String remoteRepoUrl = buildLog.getCommitLog().getRemoteRepoUrl();
             String branch = buildLog.getCommitLog().getBranch();
             String commitId = buildLog.getCommitLog().getCommitId();

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

@@ -72,8 +72,7 @@ public class AppLogManager {
             }
         }
 
-        String[] hosts = app.getAppDeploy().getHosts().split(",");
-        for (String host : hosts) {
+        for (String host : app.getAppDeploy().getHosts()) {
             AppLogService logService = (AppLogService) new GrpcClientProxy<AppLogService>()
                     .getProxy(host, GRPC_PORT, AppLogService.class);
 

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

@@ -12,7 +12,7 @@ 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.*;
-import cn.reghao.autodop.dmaster.app.vo.AppBuildVO;
+import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
 import cn.reghao.autodop.dmaster.app.vo.PageList;
 import cn.reghao.autodop.dmaster.app.vo.ResultVO;
 import org.springframework.data.domain.Page;
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author reghao
@@ -116,8 +117,10 @@ public class AppOrchestrateService {
                     app = (AppOrchestration) appEntity.clone();
                     app.setAppId(to);
                     app.setId(null);
-                    // TODO 复制共享实体
+                    // TODO 复制共享引用
                     app.setConfigFiles(null);
+                    app.setDependencyRepos(null);
+                    app.getAppDeploy().setHosts(null);
                     app.getAppDeploy().setLogs(null);
                     saveApp(app);
                     return true;
@@ -177,7 +180,7 @@ public class AppOrchestrateService {
         }
     }
 
-    public Object getByPage(int type, PageRequest pageRequest) {
+    public Object getByPage(int type, String env, PageRequest pageRequest) {
         switch (type) {
             case 1:
                 Page<ProjOrchestration> projPages = projRepository.findAll(pageRequest);
@@ -188,18 +191,15 @@ public class AppOrchestrateService {
 
                 PageList<ProjOrchestration> projs = new PageList<>();
                 projs.setList(projVOs);
-                projs.setSize(projVOs.size());
+                projs.setTotalSize(projPages.getTotalElements());
+                projs.setTotalPages(projPages.getTotalPages());
                 return projs;
             case 2:
-                Page<AppOrchestration> appPages = appRepository.findAll(pageRequest);
-                List<AppOrchestration> appVOs = new ArrayList<>();
-                appPages.getContent().forEach(app -> {
-                    appVOs.add(ResultVO.appVO(app));
-                });
-
+                Page<AppOrchestration> appPages = appRepository.findByEnv(env, pageRequest);
                 PageList<AppOrchestration> apps = new PageList<>();
-                apps.setList(appVOs);
-                apps.setSize(appVOs.size());
+                apps.setList(appPages.getContent());
+                apps.setTotalSize(appPages.getTotalElements());
+                apps.setTotalPages(appPages.getTotalPages());
                 return apps;
             default:
                 return "编排类型错误";
@@ -256,9 +256,9 @@ public class AppOrchestrateService {
         }
     }
 
-    public AppBuildVO appBuilds() {
-        AppBuildVO appBuildVO = repository.appBuilds();
-        repository.projIds(appBuildVO);
-        return appBuildVO;
+    public BuildConfig buildConfig() {
+        BuildConfig buildConfig = repository.buildConfig();
+        repository.projs(buildConfig);
+        return buildConfig;
     }
 }

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

@@ -33,8 +33,7 @@ public class AppStatusManager {
 
     public void run(String appId, String commitId) throws DockerException {
         AppOrchestration app = caching.findByAppId(appId);
-        String[] hosts = app.getAppDeploy().getHosts().split(",");
-        for (String host : hosts) {
+        for (String host : app.getAppDeploy().getHosts()) {
             AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                     .getProxy(host, GRPC_PORT, AppStatusService.class);
 
@@ -44,8 +43,7 @@ public class AppStatusManager {
 
     public void start(String appId) throws DockerException {
         AppOrchestration app = caching.findByAppId(appId);
-        String[] hosts = app.getAppDeploy().getHosts().split(",");
-        for (String host : hosts) {
+        for (String host : app.getAppDeploy().getHosts()) {
             AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                     .getProxy(host, GRPC_PORT, AppStatusService.class);
 
@@ -55,8 +53,7 @@ public class AppStatusManager {
 
     public void stop(String appId) throws DockerException {
         AppOrchestration app = caching.findByAppId(appId);
-        String[] hosts = app.getAppDeploy().getHosts().split(",");
-        for (String host : hosts) {
+        for (String host : app.getAppDeploy().getHosts()) {
             AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                     .getProxy(host, GRPC_PORT, AppStatusService.class);
 
@@ -66,8 +63,7 @@ public class AppStatusManager {
 
     public void restart(String appId) throws DockerException {
         AppOrchestration app = caching.findByAppId(appId);
-        String[] hosts = app.getAppDeploy().getHosts().split(",");
-        for (String host : hosts) {
+        for (String host : app.getAppDeploy().getHosts()) {
             AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                     .getProxy(host, GRPC_PORT, AppStatusService.class);
 
@@ -81,8 +77,7 @@ public class AppStatusManager {
         // TODO 异步处理
         try {
             for (DeployedApp deployedApp : deployedApps) {
-                String[] hosts = deployedApp.getApp().getAppDeploy().getHosts().split(",");
-                for (String host : hosts) {
+                for (String host : deployedApp.getApp().getAppDeploy().getHosts()) {
                     AppStatusService appStatusService = (AppStatusService) new GrpcClientProxy<AppStatusService>()
                             .getProxy(host, GRPC_PORT, AppStatusService.class);
 

+ 7 - 6
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -25,6 +25,8 @@ import cn.reghao.autodop.dmaster.common.config.SysConfig;
 import lombok.extern.slf4j.Slf4j;
 
 import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Set;
 
 /**
  * 应用构建部署,根据 AppOrchestration 的值完成应用构建和部署的配置
@@ -207,10 +209,9 @@ public class AppIntegrate {
                 current.getCommitTime() > lastCommitLog.getCommitTime() ||
                 app.isAlwaysBuild()) {
             // TODO 通常情况下独立应用才会有依赖,不过应该很少出现
-            String dep = app.getDependencyRepos();
+            Set<String> dep = app.getDependencyRepos();
             if (dep != null && !dep.isEmpty()) {
-                String[] dependencyRepos = dep.split(",");
-                for (String repo : dependencyRepos) {
+                for (String repo : dep) {
                     codeUpdater.update(repo, appLocalRepo + BuilderUtil.dirname(repo));
                 }
             }
@@ -223,10 +224,10 @@ public class AppIntegrate {
     public boolean compile() {
         try {
             if (needPreCompile()) {
-                preCompile(appCompileDir + app.getEntryDir());
+                preCompile(appCompileDir + app.getCompileDir());
             }
             // TODO 在通过脚本调用编译器时会卡住
-            codeCompiler.compile(app.getDirname(), appCompileDir + app.getEntryDir());
+            codeCompiler.compile(app.getDirname(), appCompileDir + app.getCompileDir());
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -241,7 +242,7 @@ public class AppIntegrate {
     public boolean pack() {
         try {
             String appPath = codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(),
-                    appCompileDir + app.getEntryDir());
+                    appCompileDir + app.getCompileDir());
             buildLog.setAppPath(appPath);
             buildLog.setBuildTime(LocalDateTime.now());
             return true;

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

@@ -22,12 +22,14 @@ import java.util.concurrent.*;
 @Slf4j
 @Service
 public class BuildDispatcher {
+    // TODO 多线程访问的集合
+    private Set<String> buildingApps;
     private OrchestrationCaching caching;
     private LogConsumer logConsumer;
     private ExecutorService threadPool;
 
-    public BuildDispatcher(OrchestrationCaching caching,
-                           LogRepository logDAO) {
+    public BuildDispatcher(OrchestrationCaching caching, LogRepository logDAO) {
+        this.buildingApps = new HashSet<>();
         this.caching = caching;
         this.logConsumer = new LogConsumer(logDAO);
         this.threadPool = ThreadPoolWrapper.threadPool("app-build-deploy");
@@ -50,10 +52,11 @@ public class BuildDispatcher {
         } else {
             appIds.forEach(appId -> {
                 AppOrchestration app = caching.findByAppId(appId);
-                if (app != null) {
+                if (app != null && !buildingApps.contains(appId)) {
+                    buildingApps.add(appId);
                     existApps.add(app);
                 } else {
-                    // TODO 应用不存在
+                    // TODO 应用不存在或正在构建中
                     /*BuildLog buildLog = new BuildLog();
                     buildLog.setAppId(appId);
                     buildLog.setCode(1);
@@ -79,7 +82,9 @@ public class BuildDispatcher {
                 Thread.sleep(1_000);
             }
 
-            results.add(future.get());
+            BuildDeployLog buildDeployLog = future.get();
+            results.add(buildDeployLog);
+            buildingApps.remove(buildDeployLog.getBuildLog().getApp().getAppId());
             iterator1.remove();
         }
 

+ 4 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java

@@ -14,6 +14,8 @@ import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
+import java.util.Set;
 
 /**
  * @author reghao
@@ -39,10 +41,9 @@ public class BuilderUtil {
 
         String remoteRepo = app.getAppRepo();
         FileUtil.copyDirToDir(appLocalRepo + dirname(remoteRepo), appCompileDir);
-        String dep = app.getDependencyRepos();
+        Set<String> dep = app.getDependencyRepos();
         if (dep != null && !dep.isEmpty()) {
-            String[] dependencyRepos = dep.split(",");
-            for (String repo : dependencyRepos) {
+            for (String repo : dep) {
                 FileUtil.copyDirToDir(appLocalRepo + dirname(repo), appCompileDir);
             }
         }

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

@@ -34,7 +34,7 @@ public class AppDeployer {
     public static DeployLog deploy(AppOrchestration app, BuildLog buildLog) {
         Notification notification = app.getNotification();
         String notifierType = notification.getNotifierType();
-        String dest = notification.getDestination();
+        String dest = notification.getWebhook();
         Notify notify = null;
         if (notifierType.equals(NotifierType.ding.name())) {
             notify = new DingNotify();
@@ -42,9 +42,8 @@ public class AppDeployer {
 
         AppPack appPack = app.getAppBuild().getAppPack();
         AppDeploy appDeploy = app.getAppDeploy();
-        String[] hosts = appDeploy.getHosts().split(",");
         Map<String, Future<Boolean>> futureMap = new HashMap<>();
-        for (String host : hosts) {
+        for (String host : appDeploy.getHosts()) {
             DeployConfig deployConfig = new DeployConfig();
             deployConfig.setAppId(app.getAppId());
             deployConfig.setAppPath(buildLog.getAppPath());

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

@@ -1,11 +1,11 @@
 package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.utils.FileUtil;
+import cn.reghao.autodop.dmaster.app.entity.deploy.ConfigFile;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * @author reghao
@@ -15,10 +15,9 @@ import java.util.Map;
 public class DotnetPreCompile implements PreCompile {
     @Override
     public void preCompile(AppOrchestration app, String appEntryDir) throws IOException {
-        Map<String, String> configFiles = app.getConfigFiles();
-        for (Map.Entry<String, String> entry : configFiles.entrySet()) {
-            String filepath = appEntryDir + "/" + entry.getKey();
-            String filecontent = entry.getValue();
+        for (ConfigFile configFile : app.getConfigFiles()) {
+            String filepath = appEntryDir + "/" + configFile.getFilename();
+            String filecontent = configFile.getFilecontent();
             FileUtil.newFile(filepath, filecontent);
             log.info("成功向 {}  文件写入内容", filepath);
         }

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

@@ -16,5 +16,4 @@ public class AppBuildVO {
     private List<AppUpdate> appUpdates;
     private List<AppCompile> appCompiles;
     private List<AppPack> appPacks;
-    private List<String> projIds;
 }

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

@@ -0,0 +1,9 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+/**
+ * @author reghao
+ * @date 2020-06-09 17:18:14
+ */
+public class AppVO {
+
+}

+ 18 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/BuildConfig.java

@@ -0,0 +1,18 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2020-06-01 11:05:48
+ */
+@Data
+public class BuildConfig {
+    private List<SelectOption> appUpdates;
+    private List<SelectOption> appCompiles;
+    private List<SelectOption> appPacks;
+    private List<SelectOption> notifications;
+    private List<SelectOption> projs;
+}

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

@@ -13,6 +13,15 @@ import java.util.List;
 @Data
 public class PageList<T> {
     private List<T> list;
-    private int size;
+    private long totalSize;
+    private int totalPages;
     private boolean hasNext;
+
+    public PageList<T> page(List<T> list) {
+        PageList<T> pageList = new PageList<>();
+        pageList.setList(list);
+
+
+        return null;
+    }
 }

+ 30 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/SelectOption.java

@@ -0,0 +1,30 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * 对应前端 select 元素的 option
+ *
+ * @author reghao
+ * @date 2020-06-09 10:15:45
+ */
+@NoArgsConstructor
+@Data
+public class SelectOption {
+    private String value;
+    private String label;
+    List<SelectOption> children;
+
+    public SelectOption(String value, String label) {
+        this.value = value;
+        this.label = label;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+        this.label = value;
+    }
+}

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

@@ -81,7 +81,7 @@ class AppOrchestrationTest {
         appLogs.add(new AppLog("file", "error", "/Logs/Error/2020-05-19.log"));
 
         AppDeploy appDeploy = new AppDeploy();
-        appDeploy.setHosts("localhost");
+        //appDeploy.setHosts("localhost");
         appDeploy.setHttpPort(8002);
         appDeploy.setHealthCheck("/health");
         appDeploy.setRunningDir("");
@@ -90,19 +90,19 @@ class AppOrchestrationTest {
         Notification notification = new Notification();
         notification.setNotifierName("ding 通知");
         notification.setNotifierType(NotifierType.ding.name());
-        notification.setDestination("https://oapi.dingtalk.com/robot/send?access_token=ba9cf0d846cff8c471168e0d2f91ec0c44645a086cf5e4e421697c9b0c606bd2");
+        notification.setWebhook("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," +
+        /*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");
+                "svn://192.168.0.214/azy/CodeRepositories/IQuizoo.Service/branches/20200509/DotNetCore");*/
         app.setEnv("dev");
-        app.setEntryDir("/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService");
+        app.setCompileDir("/ContentService/4-ContentPresentation/Com.IQuizoo.ContentService");
 
         app.setProj(proj());
         //app.setAppBuild(appBuild);

+ 5 - 5
scripts/build-and-deploy.sh

@@ -6,8 +6,8 @@
 sh build.sh test dmaster
 sh deploy.sh autodop-dmaster 192.168.0.50 gjs &
 
-sh build.sh test dagent
-sh deploy.sh autodop-dagent 192.168.0.171 gjs &
-sh deploy.sh autodop-dagent 192.168.0.172 guanjingsong &
-sh deploy.sh autodop-dagent 192.168.0.173 guanjingsong &
-sh deploy.sh autodop-dagent 192.168.0.174 guanjingsong &
+#sh build.sh test dagent
+#sh deploy.sh autodop-dagent 192.168.0.171 gjs &
+#sh deploy.sh autodop-dagent 192.168.0.172 guanjingsong &
+#sh deploy.sh autodop-dagent 192.168.0.173 guanjingsong &
+#sh deploy.sh autodop-dagent 192.168.0.174 guanjingsong &