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

优化编排配置的 CRUD 接口

reghao 5 лет назад
Родитель
Сommit
8ea65ade6f

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/ConfigType.java

@@ -11,7 +11,7 @@ public enum ConfigType {
     localDir("LocalDir"), notifier("Notifier"),
     repo("Repo"), compiler("Compiler"), packer("Packer"),
     repoAuth("RepoAuth"),
-    update("Update"), compile("Compile"), pack("Pack");
+    proj("Proj"), update("Update"), compile("Compile"), pack("Pack"), notify("Notify");
 
     private String value;
 

+ 2 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/ConfigController.java

@@ -119,9 +119,11 @@ public class ConfigController {
                     map.put(config.name(), config.getValue());
                 }
                 break;
+            case proj:
             case update:
             case compile:
             case pack:
+            case notify:
                 map.putAll(configService.buildConfigs(configType));
                 break;
             default:

+ 6 - 43
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/OrchestrateController.java

@@ -1,9 +1,7 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.dmaster.app.constant.EnvType;
-import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.service.OrchestrateService;
-import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
 import cn.reghao.autodop.common.result.WebResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -13,8 +11,6 @@ import org.springframework.data.domain.Sort;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.stream.Collectors;
-
 /**
  * @author reghao
  * @date 2019-11-27 11:29:43
@@ -32,22 +28,9 @@ public class OrchestrateController {
 
     @ApiOperation(value = "添加项目/应用编排")
     @PostMapping(value = "/{type}", consumes = "application/json")
-    public ResponseEntity<String> addOrchestration(@PathVariable("type") int type,
-                                                  @RequestBody String json) throws Exception {
-        /*switch (type) {
-            case 1:
-                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
-                appOrchestrateService.addOrUpdateProj(proj);
-                break;
-            case 2:
-                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
-                checkApp(app);
-                appOrchestrateService.addOrUpdateApp(app);
-                break;
-            default:
-                break;
-        }*/
-        orchestrateService.add(type, json);
+    public ResponseEntity<String> addOrchestration(@PathVariable("type") int type, @RequestBody String json)
+            throws Exception {
+        orchestrateService.addOrModify(type, json, "add");
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
 
@@ -86,15 +69,10 @@ public class OrchestrateController {
 
     @ApiOperation(value = "修改项目/应用编排")
     @PutMapping("/{type}")
-    public ResponseEntity<String> modifyOrchestration(@PathVariable("type") int type, @RequestBody String json) {
+    public ResponseEntity<String> modifyOrchestration(@PathVariable("type") int type, @RequestBody String json)
+            throws Exception {
         // TODO 修改仓库相关的字段时应该删除本地仓库
-        /*boolean res = orchestrateService.modify(type, json);
-        if (res) {
-            return ResponseEntity.ok().body(WebResult.success("ok"));
-        } else {
-            return ResponseEntity.ok().body(WebResult.fail("ok"));
-        }*/
-
+        orchestrateService.addOrModify(type, json, "modify");
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
 
@@ -105,19 +83,4 @@ public class OrchestrateController {
         orchestrateService.delete(type, appId);
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
-
-    @ApiOperation(value = "获取编排应用时需要用到的配置")
-    @GetMapping("/build")
-    public ResponseEntity<String> buildConfigs() {
-        /*BuildConfig buildConfig = orchestrateService.buildConfig();
-        return ResponseEntity.ok().body(WebResult.success(buildConfig));*/
-        return ResponseEntity.ok().body(WebResult.success("buildConfig"));
-    }
-
-    @ApiOperation(value = "获取编排应用时需要用到的配置")
-    @GetMapping("/configs/{type}")
-    public ResponseEntity<String> getConfigs(@PathVariable("type") String type) {
-        BuildConfig buildConfig = orchestrateService.buildConfig(type);
-        return ResponseEntity.ok().body(WebResult.success(buildConfig));
-    }
 }

+ 0 - 68
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/dao/ConfigDAO.java

@@ -1,68 +0,0 @@
-package cn.reghao.autodop.dmaster.app.repository.dao;
-
-import org.hibernate.Session;
-import org.springframework.stereotype.Repository;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author reghao
- * @date 2020-03-02 16:45:12
- */
-@Repository
-public class ConfigDAO {
-    private EntityManager em;
-
-    public ConfigDAO(EntityManager em) {
-        this.em = em;
-    }
-
-    public Map<String, Map<String, String[]>> buildConfigs() {
-        Map<String, Map<String, String[]>> map = new HashMap<>();
-        try (Session session = (Session) em.getDelegate()) {
-            String sql1 = "select repo_type,group_concat(repo_name separator ',' ) as repo_names " +
-                    "from app_update " +
-                    "group by repo_type";
-            Query sqlQuery1 = session.createSQLQuery(sql1);
-            Map<String, String[]> map1 = new HashMap<>();
-            sqlQuery1.getResultList().forEach(res -> {
-                Object[] result = (Object[]) res;
-                String key = (String) result[0];
-                String[] value = ((String) result[1]).split(",");
-                map1.put(key, value);
-            });
-            map.put("repos", map1);
-
-            String sql2 = "select compiler_type,group_concat(compiler_name separator ',' ) as compiler_names " +
-                    "from app_compile " +
-                    "group by compiler_type";
-            Query sqlQuery2 = session.createSQLQuery(sql2);
-            Map<String, String[]> map2 = new HashMap<>();
-            sqlQuery2.getResultList().forEach(res -> {
-                Object[] result = (Object[]) res;
-                String key = (String) result[0];
-                String[] value = ((String) result[1]).split(",");
-                map2.put(key, value);
-            });
-            map.put("compilers", map2);
-
-            String sql3 = "select packer_type,group_concat(packer_name separator ',' ) as packer_names " +
-                    "from app_pack " +
-                    "group by packer_type";
-            Query sqlQuery3 = session.createSQLQuery(sql3);
-            Map<String, String[]> map3 = new HashMap<>();
-            sqlQuery3.getResultList().forEach(res -> {
-                Object[] result = (Object[]) res;
-                String key = (String) result[0];
-                String[] value = ((String) result[1]).split(",");
-                map3.put(key, value);
-            });
-            map.put("packers", map3);
-        }
-
-        return map;
-    }
-}

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

@@ -1,65 +0,0 @@
-package cn.reghao.autodop.dmaster.app.repository.orchestration;
-
-import cn.reghao.autodop.dmaster.app.entity.build.AppCompile;
-import cn.reghao.autodop.dmaster.app.entity.build.AppPack;
-import cn.reghao.autodop.dmaster.app.entity.build.AppUpdate;
-import cn.reghao.autodop.dmaster.app.entity.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.BuildConfig;
-import org.springframework.stereotype.Repository;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @author reghao
- * @date 2020-06-01 11:09:06
- */
-@Repository
-public class AppRepository {
-    private AppUpdateRepository updateRepository;
-    private AppCompileRepository compileRepository;
-    private AppPackRepository packRepository;
-    private AppOrchestrationRepository orchestrationRepository;
-    private ProjOrchestrationRepository projRepository;
-    private NotificationRepository notificationRepository;
-
-    public AppRepository(AppUpdateRepository updateRepository,
-                         AppCompileRepository compileRepository,
-                         AppPackRepository packRepository,
-                         ProjOrchestrationRepository projRepository,
-                         AppOrchestrationRepository orchestrationRepository,
-                         NotificationRepository notificationRepository) {
-        this.updateRepository = updateRepository;
-        this.compileRepository = compileRepository;
-        this.packRepository = packRepository;
-        this.orchestrationRepository = orchestrationRepository;
-        this.projRepository = projRepository;
-        this.notificationRepository = notificationRepository;
-    }
-
-    public BuildConfig buildConfig() {
-        List<AppUpdate> appUpdates = updateRepository.findAll();
-        List<AppCompile> appCompiles = compileRepository.findAll();
-        List<AppPack> appPacks = packRepository.findAll();
-        List<Notification> notifications = notificationRepository.findAll();
-
-        BuildConfig buildConfig = new BuildConfig();
-        buildConfig.setAppUpdates(appUpdates);
-        buildConfig.setAppCompiles(appCompiles);
-        buildConfig.setAppPacks(appPacks);
-        buildConfig.setNotifications(notifications);
-
-        return buildConfig;
-    }
-
-    public void projs(BuildConfig buildConfig) {
-        List<String> projs = projRepository.findAll().stream()
-                .map(ProjOrchestration::getProjId)
-                .collect(Collectors.toList());
-        buildConfig.setProjs(projs);
-    }
-}

+ 21 - 10
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/ConfigService.java

@@ -9,12 +9,13 @@ import cn.reghao.autodop.dmaster.app.entity.build.AppPack;
 import cn.reghao.autodop.dmaster.app.entity.build.AppUpdate;
 import cn.reghao.autodop.dmaster.app.entity.LocalDir;
 import cn.reghao.autodop.dmaster.app.entity.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.repository.dao.ConfigDAO;
 import cn.reghao.autodop.dmaster.app.repository.orchestration.LocalDirRepository;
 import cn.reghao.autodop.dmaster.app.repository.orchestration.NotificationRepository;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.ProjOrchestrationRepository;
 import cn.reghao.autodop.dmaster.app.vo.PageList;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
@@ -32,24 +33,24 @@ import java.util.stream.Collectors;
 @Service
 public class ConfigService {
     private LocalDirRepository configRepository;
-    private NotificationRepository notifyRepository;
+    private ProjOrchestrationRepository projRepository;
     private AppUpdateRepository updateRepository;
     private AppCompileRepository compileRepository;
     private AppPackRepository packRepository;
-    private ConfigDAO configDAO;
+    private NotificationRepository notifyRepository;
 
     public ConfigService(LocalDirRepository configRepository,
-                         NotificationRepository notifyRepository,
+                         ProjOrchestrationRepository projRepository,
                          AppUpdateRepository updateRepository,
                          AppCompileRepository compileRepository,
                          AppPackRepository packRepository,
-                         ConfigDAO configDAO) {
+                         NotificationRepository notifyRepository) {
         this.configRepository = configRepository;
-        this.notifyRepository = notifyRepository;
+        this.projRepository = projRepository;
         this.updateRepository = updateRepository;
         this.compileRepository = compileRepository;
         this.packRepository = packRepository;
-        this.configDAO = configDAO;
+        this.notifyRepository = notifyRepository;
     }
 
     public void add(String configType, String json) throws Exception {
@@ -254,19 +255,29 @@ public class ConfigService {
     public Map<String, String> buildConfigs(String buildConfig) {
         Map<String, String> map = new HashMap<>();
         switch (ConfigType.valueOf(buildConfig)) {
+            case proj:
+                for (ProjOrchestration proj : projRepository.findAll()) {
+                    map.put(proj.getProjId(), proj.getProjId());
+                }
+                break;
             case update:
                 for (AppUpdate appUpdate : updateRepository.findAll()) {
-                    map.put(appUpdate.getRepoType(), appUpdate.getRepoName());
+                    map.put(appUpdate.getRepoName(), appUpdate.getRepoName());
                 }
                 break;
             case compile:
                 for (AppCompile appCompile : compileRepository.findAll()) {
-                    map.put(appCompile.getCompilerType(), appCompile.getCompilerName());
+                    map.put(appCompile.getCompilerName(), appCompile.getCompilerName());
                 }
                 break;
             case pack:
                 for (AppPack appPack : packRepository.findAll()) {
-                    map.put(appPack.getPackerType(), appPack.getPackerName());
+                    map.put(appPack.getPackerName(), appPack.getPackerName());
+                }
+                break;
+            case notify:
+                for (Notification notification : notifyRepository.findAll()) {
+                    map.put(notification.getNotifierName(), notification.getNotifierName());
                 }
                 break;
             default:

+ 92 - 163
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OrchestrateService.java

@@ -12,17 +12,12 @@ 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.BuildConfig;
-import cn.reghao.autodop.dmaster.app.vo.PageList;
-import cn.reghao.autodop.dmaster.app.vo.OrchestrationVO;
-import org.springframework.beans.factory.annotation.Autowired;
+import cn.reghao.autodop.dmaster.app.vo.*;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
-import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -37,213 +32,154 @@ public class OrchestrateService {
     private AppCompileRepository appCompileRepository;
     private AppPackRepository appPackRepository;
     private NotificationRepository notificationRepository;
-    private AppRepository repository;
 
     public OrchestrateService(ProjOrchestrationRepository projRepository,
                               AppOrchestrationRepository appRepository,
                               AppUpdateRepository appUpdateRepository,
                               AppCompileRepository appCompileRepository,
                               AppPackRepository appPackRepository,
-                              NotificationRepository notificationRepository,
-                              AppRepository repository) {
+                              NotificationRepository notificationRepository) {
         this.projRepository = projRepository;
         this.appRepository = appRepository;
         this.appUpdateRepository = appUpdateRepository;
         this.appCompileRepository = appCompileRepository;
         this.appPackRepository = appPackRepository;
         this.notificationRepository = notificationRepository;
-        this.repository = repository;
     }
 
-    public void add(int type, String json) {
-        AppBuild appBuild;
+    public void addOrModify(int type, String json, String type1) throws Exception {
         switch (type) {
             case 1:
                 // 项目编排
-                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
-                appBuild = proj.getAppBuild();
-                checkSharedEntity(appBuild);
+                ProjOrchestrationVO projVO = (ProjOrchestrationVO) JsonUtil.jsonToObject(json, ProjOrchestrationVO.class);
+                AppBuild appBuild = checkSharedBuildConfig(projVO.getAppBuild());
+                ProjOrchestration proj = projVO.to();
+                proj.setAppBuild(appBuild);
                 projRepository.save(proj);
                 break;
             case 2:
                 // 应用编排
-                // TODO 添加应用的配置文件
-                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
-                saveApp(app);
+                AppOrchestrationVO appVO = (AppOrchestrationVO) JsonUtil.jsonToObject(json, AppOrchestrationVO.class);
+                AppOrchestration app = appVO.to();
+                if (appVO.getProjId() == null) {
+                    AppBuild appBuild1 = checkSharedBuildConfig(appVO.getAppBuild());
+                    app.setAppBuild(appBuild1);
+
+                    String notifier = appVO.getNotifier();
+                    checkSharedNotification(app, notifier);
+                } else {
+                    // TODO
+                    ProjOrchestration entity = projRepository.findByProjId(appVO.getProjId());
+                    app.setProj(entity);
+                }
+
+                if ("add".equals(type1)) {
+                    appRepository.save(app);
+                } else {
+                    AppOrchestration entity = appRepository.findByAppId(app.getAppId());
+                    if (entity == null) {
+                        throw new Exception(app.getAppId() + " 不存在...");
+                    }
+                    app.setId(entity.getId());
+                    app.setCreateTime(entity.getCreateTime());
+                    app.setUpdateTime(LocalDateTime.now());
+                    appRepository.save(app);
+                }
             default:
         }
     }
 
-    private void saveApp(AppOrchestration app) {
-        ProjOrchestration proj = app.getProj();
-        if (proj != null) {
-            ProjOrchestration projEntity = projRepository.findByProjId(proj.getProjId());
-            if (projEntity != null) {
-                app.setProj(projEntity);
-            } else {
-                projRepository.save(proj);
-            }
-        } else {
-            AppBuild appBuild = app.getAppBuild();
-            checkSharedEntity(appBuild);
+    private AppBuild checkSharedBuildConfig(AppBuildVO buildVO) throws Exception {
+        AppBuild appBuild = new AppBuild();
+        String updater = buildVO.getUpdater();
+        AppUpdate appUpdate = appUpdateRepository.findByRepoName(updater);
+        if (appUpdate == null) {
+            throw new Exception(updater + " 不存在...");
         }
+        appBuild.setAppUpdate(appUpdate);
 
-        Notification notification = app.getNotification();
-        Notification notifierEntity = notificationRepository.findByNotifierName(notification.getNotifierName());
-        if (notifierEntity != null) {
-            app.setNotification(notifierEntity);
-        } else {
-            notificationRepository.save(notification);
+        String compiler = buildVO.getCompiler();
+        AppCompile appCompile = appCompileRepository.findByCompilerName(compiler);
+        if (appCompile == null) {
+            throw new Exception(compiler + " 不存在...");
         }
+        appBuild.setAppCompile(appCompile);
 
-        appRepository.save(app);
+        String packer = buildVO.getPacker();
+        AppPack appPack = appPackRepository.findByPackerName(packer);
+        if (appPack == null) {
+            throw new Exception(packer + " 不存在...");
+        }
+        appBuild.setAppPack(appPack);
+        return appBuild;
+    }
+
+    private void checkSharedNotification(AppOrchestration app, String notifier) throws Exception {
+        if (notifier != null) {
+            Notification notification = notificationRepository.findByNotifierName(notifier);
+            if (notification == null) {
+                throw new Exception(notification + " 不存在...");
+            }
+            app.setNotification(notification);
+        }
     }
 
-    public boolean copy(int type, String from, String to) throws Exception {
+    public boolean copy(int type, String from, String to) throws CloneNotSupportedException {
         switch (type) {
             case 1:
-                ProjOrchestration projEntity = projRepository.findByProjId(from);
-                ProjOrchestration proj = projRepository.findByProjId(to);
-                if (projEntity != null && proj == null) {
-                    proj = (ProjOrchestration) projEntity.clone();
-                    proj.setProjId(to);
-                    proj.setId(null);
-                    checkSharedEntity(proj.getAppBuild());
-                    projRepository.save(proj);
-                    return true;
-                }
                 break;
             case 2:
                 AppOrchestration appEntity = appRepository.findByAppId(from);
-                AppOrchestration app = appRepository.findByAppId(to);
-                if (appEntity != null && app == null) {
-                    app = (AppOrchestration) appEntity.clone();
-                    app.setAppId(to);
-                    app.setId(null);
-                    // TODO 复制共享引用
-                    /*
-                    app.setDependencyRepos(null);
-                    app.getAppDeploy().setHosts(null);
-                    app.getAppDeploy().setLogs(null);*/
-                    saveApp(app);
-                    return true;
+                AppOrchestration newApp = appRepository.findByAppId(to);
+                if (appEntity == null || newApp != null) {
+                    return false;
                 }
+                newApp = (AppOrchestration) appEntity.clone();
+                newApp.setAppId(to);
+                newApp.setId(null);
+                newApp.setCreateTime(LocalDateTime.now());
+                newApp.setUpdateTime(LocalDateTime.now());
+                // 处理共享集合
+                newApp.getAppDeploy().setHosts(null);
+                newApp.getAppRunning().setLogs(null);
+                appRepository.save(newApp);
                 break;
             default:
                 return false;
         }
 
-        return false;
-    }
-
-    /**
-     * 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);
-            }
-        }
+        return true;
     }
 
     public Object get(int type, String id) {
-        switch (type) {
-            case 1:
-                ProjOrchestration proj = projRepository.findByProjId(id);
-                return OrchestrationVO.projVO(proj);
-            case 2:
-                AppOrchestration app = appRepository.findByAppId(id);
-                return OrchestrationVO.appVO(app);
-            default:
-                return "编排类型错误";
-        }
+        return null;
     }
 
     public Object getByPage(int type, String env, PageRequest pageRequest) {
         switch (type) {
             case 1:
                 Page<ProjOrchestration> projPages = projRepository.findAll(pageRequest);
-                List<ProjOrchestration> projVOs = new ArrayList<>();
-                projPages.forEach(proj -> {
-                    projVOs.add(OrchestrationVO.projVO(proj));
-                });
-
-                PageList<ProjOrchestration> projs = new PageList<>();
-                projs.setList(projVOs);
-                projs.setTotalSize(projPages.getTotalElements());
-                projs.setTotalPages(projPages.getTotalPages());
-                return projs;
+                PageList<ProjOrchestrationVO> projVOs = new PageList<>();
+                projVOs.setTotalSize(projPages.getTotalElements());
+                projVOs.setTotalPages(projPages.getTotalPages());
+                projVOs.setList(projPages.getContent().stream()
+                        .map(proj -> new ProjOrchestrationVO().from(proj))
+                        .collect(Collectors.toList()));
+                return projVOs;
             case 2:
                 Page<AppOrchestration> appPages = appRepository.findByEnv(env, pageRequest);
-                PageList<AppOrchestration> apps = new PageList<>();
-                apps.setTotalSize(appPages.getTotalElements());
-                apps.setTotalPages(appPages.getTotalPages());
-                apps.setList(appPages.getContent().stream().map(OrchestrationVO::appVO).collect(Collectors.toList()));
-                return apps;
+                PageList<AppOrchestrationVO> appVOs = new PageList<>();
+                appVOs.setTotalSize(appPages.getTotalElements());
+                appVOs.setTotalPages(appPages.getTotalPages());
+                appVOs.setList(appPages.getContent().stream()
+                        .map(app -> new AppOrchestrationVO().from(app))
+                        .collect(Collectors.toList()));
+                return appVOs;
             default:
                 return "编排类型错误";
         }
     }
 
-    public boolean modify(int type, String json) {
-        switch (type) {
-            case 1:
-                ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
-                ProjOrchestration projEntity = projRepository.findByProjId(proj.getProjId());
-                if (projEntity != null) {
-                    AppBuild appBuild = proj.getAppBuild();
-                    checkSharedEntity(appBuild);
-
-                    proj.setId(projEntity.getId());
-                    proj.setCreateTime(projEntity.getCreateTime());
-                    proj.setUpdateTime(LocalDateTime.now());
-                    projRepository.save(proj);
-                    return true;
-                }
-            case 2:
-                // TODO 若修改了部署的 host,需要额外的处理
-                AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
-                String appId = app.getAppId();
-                AppOrchestration appEntity = appRepository.findByAppId(appId);
-                if (appEntity != null) {
-                    app.setId(appEntity.getId());
-                    app.setCreateTime(appEntity.getCreateTime());
-                    app.setUpdateTime(LocalDateTime.now());
-                    saveApp(app);
-                    return true;
-                }
-            default:
-                return false;
-        }
-    }
-
     /**
      * TODO 除了删除数据库中所有与应用相关的数据,还应删除文件系统和 docker 中与应用相关的数据
      *
@@ -258,15 +194,8 @@ public class OrchestrateService {
                 break;
             case 2:
                 appRepository.deleteByAppId(appId);
+                break;
             default:
         }
     }
-
-    public BuildConfig buildConfig(String type) {
-
-
-        BuildConfig buildConfig = repository.buildConfig();
-        repository.projs(buildConfig);
-        return buildConfig;
-    }
 }

+ 12 - 9
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppBuildVO.java

@@ -1,19 +1,22 @@
 package cn.reghao.autodop.dmaster.app.vo;
 
-import cn.reghao.autodop.dmaster.app.entity.build.AppCompile;
-import cn.reghao.autodop.dmaster.app.entity.build.AppPack;
-import cn.reghao.autodop.dmaster.app.entity.build.AppUpdate;
+import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
 import lombok.Data;
 
-import java.util.List;
-
 /**
  * @author reghao
- * @date 2020-06-01 11:05:48
+ * @date 2020-09-17 15:06:22
  */
 @Data
 public class AppBuildVO {
-    private List<AppUpdate> appUpdates;
-    private List<AppCompile> appCompiles;
-    private List<AppPack> appPacks;
+    private String updater;
+    private String compiler;
+    private String packer;
+
+    public AppBuildVO appBuildVO(AppBuild appBuild) {
+        this.updater = appBuild.getAppUpdate().getRepoName();
+        this.compiler = appBuild.getAppCompile().getCompilerName();
+        this.packer = appBuild.getAppPack().getPackerName();
+        return this;
+    }
 }

+ 66 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/AppOrchestrationVO.java

@@ -0,0 +1,66 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import cn.reghao.autodop.dmaster.app.entity.deploy.AppDeploy;
+import cn.reghao.autodop.dmaster.app.entity.deploy.AppRunning;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-02-29 17:22:19
+ */
+@Data
+public class AppOrchestrationVO {
+    private String appId;
+    private String projId;
+    private String description;
+    private String env;
+    private String appType;
+    private String appRepo;
+    private String branch;
+    private String dirname;
+    private String compileDir;
+    private boolean enable;
+    private boolean alwaysBuild;
+    private AppBuildVO appBuild;
+    private AppDeploy appDeploy;
+    private AppRunning appRunning;
+    private String notifier;
+
+    public AppOrchestration to() {
+        AppOrchestration app = new AppOrchestration();
+        app.setAppId(this.appId);
+        app.setDescription(this.description);
+        app.setEnv(this.env);
+        app.setAppType(this.appType);
+        app.setAppRepo(this.appRepo);
+        app.setBranch(this.branch);
+        app.setDirname(this.dirname);
+        app.setCompileDir(this.compileDir);
+        app.setEnable(this.enable);
+        app.setAlwaysBuild(this.alwaysBuild);
+        app.setAppDeploy(this.appDeploy);
+        app.setAppRunning(this.appRunning);
+
+        return app;
+    }
+
+    public AppOrchestrationVO from(AppOrchestration app) {
+        this.appId = app.getAppId();
+        this.description = app.getDescription();
+        this.env = app.getEnv();
+        this.appType = app.getAppType();
+        this.appRepo = app.getAppRepo();
+        this.branch = app.getBranch();
+        this.dirname = app.getDirname();
+        this.compileDir = app.getCompileDir();
+        this.enable = app.isEnable();
+        this.alwaysBuild = app.isAlwaysBuild();
+        this.appDeploy = app.getAppDeploy();
+        this.appRunning = app.getAppRunning();
+
+        this.notifier = app.getNotification().getNotifierName();
+        this.appBuild = new AppBuildVO().appBuildVO(app.getAppBuild());
+        return this;
+    }
+}

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

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

+ 0 - 38
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/OrchestrationVO.java

@@ -1,38 +0,0 @@
-package cn.reghao.autodop.dmaster.app.vo;
-
-import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
-import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
-
-/**
- * @author reghao
- * @date 2020-02-29 17:22:19
- */
-public class OrchestrationVO {
-    public static AppOrchestration appVO(AppOrchestration app) {
-        ClassUtil.setParentFieldNull(app);
-        ClassUtil.setParentFieldNull(app.getNotification());
-
-        ProjOrchestration proj = app.getProj();
-        if (proj == null) {
-            appBuildVO(app.getAppBuild());
-        } else {
-            ClassUtil.setParentFieldNull(proj);
-            appBuildVO(proj.getAppBuild());
-        }
-
-        return app;
-    }
-
-    public static ProjOrchestration projVO(ProjOrchestration proj) {
-        ClassUtil.setParentFieldNull(proj);
-        appBuildVO(proj.getAppBuild());
-        return proj;
-    }
-
-    private static void appBuildVO(AppBuild appBuild) {
-        ClassUtil.setParentFieldNull(appBuild.getAppUpdate());
-        ClassUtil.setParentFieldNull(appBuild.getAppCompile());
-        ClassUtil.setParentFieldNull(appBuild.getAppPack());
-    }
-}

+ 37 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/ProjOrchestrationVO.java

@@ -0,0 +1,37 @@
+package cn.reghao.autodop.dmaster.app.vo;
+
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-02-29 17:22:19
+ */
+@Data
+public class ProjOrchestrationVO {
+    private String projId;
+    private String description;
+    private String projRepo;
+    private String branch;
+    private AppBuildVO appBuild;
+
+    public ProjOrchestration to() {
+        ProjOrchestration proj = new ProjOrchestration();
+        proj.setProjId(this.projId);
+        proj.setDescription(this.description);
+        proj.setProjRepo(this.projRepo);
+        proj.setBranch(this.branch);
+        return proj;
+    }
+
+    public ProjOrchestrationVO from(ProjOrchestration proj) {
+        this.projId = proj.getProjId();
+        this.description = proj.getDescription();
+        this.projRepo = proj.getProjRepo();
+        this.branch = proj.getBranch();
+
+        this.appBuild = new AppBuildVO().appBuildVO(proj.getAppBuild());;
+
+        return this;
+    }
+}