ソースを参照

milestone - 测试环境运行版本

reghao 5 年 前
コミット
6cdbc922c3

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

@@ -63,6 +63,7 @@ public class AppBuildController {
         } else {
             buildDeployLogs = buildDispatcher.dispatch(apps, true);
             List<DeployLogVO> deployResultVOS = buildDeployLogs.stream()
+                    .filter(buildDeployLog -> buildDeployLog.getDeployLog() != null)
                     .map(BuildDeployLog::deployLog)
                     .collect(Collectors.toList());
 

+ 36 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppOrchestrateController.java

@@ -1,5 +1,8 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
+import cn.reghao.autodop.common.utils.JsonUtil;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.service.AppOrchestrateService;
 import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
 import cn.reghao.autodop.dmaster.common.webresult.WebResult;
@@ -11,6 +14,9 @@ import org.springframework.data.domain.Sort;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Set;
+import java.util.stream.Collectors;
+
 /**
  * @author reghao
  * @date 2019-11-27 11:29:43
@@ -28,12 +34,38 @@ public class AppOrchestrateController {
 
     @ApiOperation(value = "添加项目/应用编排")
     @PostMapping(value = "/{type}", consumes = "application/json")
-    public ResponseEntity<String>addOrchestration(@PathVariable("type") int type,
+    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;
+        }*/
         appOrchestrateService.add(type, json);
         return ResponseEntity.ok().body(WebResult.success("ok"));
     }
 
+    //private void addOr
+
+    private void checkApp(AppOrchestration app) {
+        app.setConfigFiles(app.getConfigFiles().stream()
+                .filter(configFile -> !configFile.getFilename().isEmpty())
+                .collect(Collectors.toSet()));
+
+        app.setDependencyRepos(app.getDependencyRepos().stream()
+                .filter(dep -> !dep.isEmpty())
+                .collect(Collectors.toSet()));
+
+    }
+
     @ApiOperation(value = "拷贝项目/应用编排")
     @PostMapping(value = "/copy/{type}")
     public ResponseEntity<String> copyOrchestration(@PathVariable("type") int type,
@@ -56,7 +88,7 @@ public class AppOrchestrateController {
 
     @ApiOperation(value = "分页获取项目/应用编排(更新时间倒序)")
     @GetMapping("/{type}")
-    public ResponseEntity<String>getOrchestrationByPage(@PathVariable("type") int type,
+    public ResponseEntity<String> getOrchestrationByPage(@PathVariable("type") int type,
                                                         @RequestParam("env") String env,
                                                         @RequestParam("page") int page,
                                                         @RequestParam("size") int size) {
@@ -69,6 +101,8 @@ public class AppOrchestrateController {
     @ApiOperation(value = "修改项目/应用编排")
     @PutMapping("/{type}")
     public ResponseEntity<String> modifyOrchestration(@PathVariable("type") int type, @RequestBody String json) {
+
+
         boolean res = appOrchestrateService.modify(type, json);
         if (res) {
             return ResponseEntity.ok().body(WebResult.success("ok"));

+ 5 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/orchestration/AppOrchestration.java

@@ -8,8 +8,6 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 
 import javax.persistence.*;
-import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 /**
@@ -25,10 +23,13 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
     @Column(nullable = false, unique = true)
     private String appId;
     // 应用代码所在目录的名字
+    @Column(nullable = false)
     private String dirname;
     private String description;
+    @Column(nullable = false)
     private String env;
     // 是否总是构建
+    @Column(nullable = false)
     private boolean alwaysBuild;
     // 编译 app 时所处的目录,以仓库目录为起点
     private String compileDir;
@@ -37,6 +38,7 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
     // 配置文件
     @ElementCollection(fetch = FetchType.EAGER)
     private Set<ConfigFile> configFiles;
+    @Column(nullable = false)
     private String appRepo;
     @Column(length = 1024)
     @ElementCollection(fetch = FetchType.EAGER)
@@ -52,6 +54,7 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
     @JoinColumn(name = "notification_id", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
     private Notification notification;
     // 是否启用编排
+    @Column(nullable = false)
     private boolean enable;
 
     @Override

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

@@ -19,6 +19,7 @@ public class ProjOrchestration extends BaseEntity implements Cloneable {
     @Column(nullable = false, unique = true)
     private String projId;
     private String description;
+    @Column(nullable = false)
     private String projRepo;
     // 同一个项目内所有应用的构建策略是相同的
     private AppBuild appBuild;

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

@@ -21,7 +21,6 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * @author reghao
@@ -53,6 +52,14 @@ public class AppOrchestrateService {
         this.repository = repository;
     }
 
+    public void addOrUpdateApp(AppOrchestration app) {
+
+    }
+
+    public void addOrUpdateProj(ProjOrchestration proj) {
+
+    }
+
     public void add(int type, String json) {
         AppBuild appBuild;
         switch (type) {

+ 3 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -212,7 +212,9 @@ public class AppIntegrate {
             Set<String> dep = app.getDependencyRepos();
             if (dep != null && !dep.isEmpty()) {
                 for (String repo : dep) {
-                    codeUpdater.update(repo, appLocalRepo + BuilderUtil.dirname(repo));
+                    if (!repo.isEmpty()) {
+                        codeUpdater.update(repo, appLocalRepo + app.getDirname());
+                    }
                 }
             }
             return new AppUpdateStatus(app, current, true);

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

@@ -39,12 +39,14 @@ public class BuilderUtil {
             FileUtil.eraseDir(compileDir);
         }
 
-        String remoteRepo = app.getAppRepo();
-        FileUtil.copyDirToDir(appLocalRepo + dirname(remoteRepo), appCompileDir);
+        //
+        FileUtil.copyDirToDir(appLocalRepo + "/" + app.getDirname(), appCompileDir);
         Set<String> dep = app.getDependencyRepos();
         if (dep != null && !dep.isEmpty()) {
             for (String repo : dep) {
-                FileUtil.copyDirToDir(appLocalRepo + dirname(repo), appCompileDir);
+                if (!repo.isEmpty()) {
+                    FileUtil.copyDirToDir(appLocalRepo + dirname(repo), appCompileDir);
+                }
             }
         }