reghao 5 лет назад
Родитель
Сommit
4bbbbba661
19 измененных файлов с 90 добавлено и 304 удалено
  1. 16 234
      common/src/main/java/cn/reghao/autodop/common/utils/FileOps.java
  2. 0 11
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/CompilerType.java
  3. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/CompilerType.java
  4. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/PackerType.java
  5. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/RepoAuthType.java
  6. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/RepoType.java
  7. 4 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/ConfigController.java
  8. 2 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/config/orchestration/AppOrchestration.java
  9. 10 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/BuildDeployDispatcher.java
  10. 4 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java
  11. 4 14
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java
  12. 10 17
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/compiler/MavenCompiler.java
  13. 3 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/packer/ZipPack.java
  14. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/repo/GitImpl.java
  15. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/crud/build/PackerConfigCrudService.java
  16. 9 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogConsumer.java
  17. 5 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogService.java
  18. 3 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/orchestration/AppVO.java
  19. 4 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/orchestration/ProjVO.java

+ 16 - 234
common/src/main/java/cn/reghao/autodop/common/utils/FileOps.java

@@ -1,15 +1,13 @@
 package cn.reghao.autodop.common.utils;
 
 import cn.reghao.autodop.common.utils.text.FileProcessor;
-import cn.reghao.autodop.common.utils.text.TextFile;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 
 import java.io.*;
 import java.nio.file.*;
 import java.nio.file.attribute.BasicFileAttributes;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Objects;
 
 /**
  * 文件,目录操作类(新建,删除,复制,移动,清空)
@@ -20,86 +18,30 @@ import java.util.Map;
 @Slf4j
 public class FileOps {
     /**
-     * TODO: 复制文件或目录
+     * 将目录的文件和子目录复制到另一个目录(非当前目录或其子目录)
      *
-     *
-     * @param
-     * @return
-     * @date 2019-08-27 下午10:37
-     */
-    public static boolean cp(String src, String dst) throws IOException {
-        if (src.equals(dst)) {
-            return false;
-        }
-
-        File srcFile = new File(src);
-        File dstFile = new File(dst);
-        copyFile(srcFile, dstFile);
-        return true;
-    }
-
-    public static boolean copyFile(String src, String dst) throws IOException {
-        if (src.equals(dst)) {
-            return false;
-        }
-
-        File srcFile = new File(src);
-        File dstFile = new File(dst);
-        if (!srcFile.exists() || srcFile.isDirectory()) {
-            return false;
-        }
-
-        if (dstFile.isFile()) {
-            copyFile(srcFile, dstFile);
-        } else if (!dstFile.exists()) {
-            if (!dstFile.createNewFile()) {
-                log.info("创建 {} 失败...", dst);
-                return false;
-            }
-            copyFile(srcFile, dstFile);
-        } else if (dstFile.isDirectory()) {
-            log.info("not implementation");
-        }
-
-        return true;
-    }
-
-    /**
-     * 移动目录
-     *
-     * @param
+     * @param src 要复制的目录
+     * @param dst 目的目录(若不存在则新建)
      * @return
-     * @date 2019-09-10 下午5:52
+     * @date 2019-09-09 下午6:11
      */
-    public static void mvDir(String src, String dst) throws IOException {
+    public static void copyDirContentToDir(String src, String dst) throws IOException {
         File srcDir = new File(src);
-        File dstDir = new File(dst);
-
         if (!srcDir.exists() || srcDir.isFile()) {
-            log.info("{} 不存在", src);
+            log.error("{} -> 源目录不存在", src);
             return;
         }
 
-        FileUtils.moveDirectoryToDirectory(srcDir, dstDir, true);
-    }
-
-    /**
-     * 将目录的内容复制到一个新位置
-     *
-     * @param src 要复制内容的目录
-     * @param dst 目的目录(若不存在则新建)
-     * @return
-     * @date 2019-09-09 下午6:11
-     */
-    public static void copyDir(String src, String dst) throws IOException {
-        File srcFile = new File(src);
-        if (!srcFile.exists() || srcFile.isFile()) {
-            log.error("{} -> 目录不存在", src);
-            return;
+        File dstDir = new File(dst);
+        for (File file : Objects.requireNonNull(srcDir.listFiles())) {
+            if (file.isDirectory()) {
+                String dirname = file.getName();
+                File dstdir = new File(dst + "/" + dirname);
+                FileUtils.copyDirectory(file, dstdir);
+            } else {
+                FileUtils.copyFileToDirectory(file, dstDir);
+            }
         }
-
-        File dstFile = new File(dst);
-        FileUtils.copyDirectory(srcFile, dstFile);
     }
 
     /**
@@ -121,83 +63,6 @@ public class FileOps {
         FileUtils.copyDirectory(srcDir, dstDir);
     }
 
-    /**
-     * 复制文件
-     *
-     * @param
-     * @return
-     * @date 2019-09-06 下午11:19
-     */
-    private static void copyFile(File src, File dst) throws IOException {
-        InputStream in = new BufferedInputStream(new FileInputStream(src));
-        OutputStream out = new BufferedOutputStream(new FileOutputStream(dst));
-
-        byte[] bytes = new byte[1024];
-        int size;
-        while ((size = in.read(bytes)) != -1) {
-            out.write(bytes, 0, size);
-        }
-
-        // TODO 抛出异常时处理未关闭的流
-        in.close();
-        out.close();
-    }
-
-    /**
-     * 移动文件到目录或文件
-     *
-     * @param src 文件绝对路径
-     * @param dst 文件或目录绝对路径,若 dst 不存在,则默认其为文件
-     * @return
-     * @date 2019-08-27 下午9:52
-     */
-    public static boolean mvFile(String src, String dst) throws IOException {
-        File srcFile = new File(src);
-        File dstFile = new File(dst);
-
-        if (src.equals(dst) || !srcFile.exists() || srcFile.isDirectory()) {
-            log.info("{} 移动失败...", src);
-            return false;
-        }
-
-        if (dstFile.exists()) {
-            if (dstFile.isFile()) {
-                writeFile(srcFile, dstFile);
-            } else {
-                // 移动文件到目录
-                String newPath = dst + "/" + srcFile.getName();
-                File newFile = new File(newPath);
-                srcFile.renameTo(newFile);
-            }
-
-            return true;
-        } else {
-            if (!dstFile.createNewFile()) {
-                log.info("{} 创建失败...", dst);
-                return false;
-            }
-
-            writeFile(srcFile, dstFile);
-            return true;
-        }
-    }
-
-    private static void writeFile(File src, File dst) throws IOException {
-        BufferedReader reader;
-        BufferedWriter writer;
-        reader = new BufferedReader(new FileReader(src));
-        writer = new BufferedWriter(new FileWriter(dst));
-
-        String line;
-        while ((line = reader.readLine()) != null) {
-            writer.write(line + System.lineSeparator());
-        }
-
-        // TODO: 处理关闭时的异常
-        reader.close();
-        writer.close();
-    }
-
     /**
      * 创建目录,若目录存在则返回
      *
@@ -226,32 +91,6 @@ public class FileOps {
         return dir.exists() && dir.isDirectory();
     }
 
-    /**
-     * 删除目录及其包含的所有子目录或文件
-     *
-     * @param
-     * @return
-     * @date 2019-08-27 下午10:38
-     */
-    public static boolean rmDir(String src) {
-        File file = new File(src);
-        if (!file.exists() || file.isFile()) {
-            log.info("目录不存在 -> {}", src);
-            return false;
-        }
-
-        if (file.isDirectory()) {
-            try {
-                FileUtils.deleteDirectory(file);
-            } catch (IOException e) {
-                e.printStackTrace();
-                return false;
-            }
-        }
-
-        return true;
-    }
-
     /**
      * 提取一个绝对路径中的目录部分
      *
@@ -264,29 +103,6 @@ public class FileOps {
         return path.substring(0, index);
     }
 
-    /**
-     * 文件指纹
-     *
-     * @param
-     * @return
-     * @date 2019-08-28 下午1:21
-     */
-    public static Map<String, String> fingerPrint(String filePath) {
-        File file = new File(filePath);
-        if (!file.exists()) {
-            return null;
-        }
-
-        Map<String, String> res = new HashMap<>();
-        if (!file.isDirectory()) {
-            res.put(filePath, null);
-        } else {
-
-        }
-
-        return res;
-    }
-
     /**
      * 遍历并处理文本文件
      *
@@ -327,23 +143,6 @@ public class FileOps {
         }
     }
 
-    /**
-     * 清空目录
-     *
-     * @param
-     * @return
-     * @date 2019-09-27 下午3:20
-     */
-    public static void eraseDir(String dirPath) throws IOException {
-        File dir = new File(dirPath);
-        if (!dir.exists() || dir.isFile()) {
-            log.info("{} -> 目录不存在", dirPath);
-            return;
-        }
-
-        FileUtils.cleanDirectory(dir);
-    }
-
     public static void eraseDir(File dir) throws IOException {
         if (!dir.exists() || dir.isFile()) {
             log.info("{} -> 目录不存在", dir.getPath());
@@ -352,21 +151,4 @@ public class FileOps {
 
         FileUtils.cleanDirectory(dir);
     }
-
-    /**
-     * 新建一个文件
-     *
-     * @param
-     * @return
-     * @date 2020-03-10 上午10:36
-     */
-    public static void newFile(String filepath, String filecontent) throws IOException {
-        File file = new File(filepath);
-        if (!file.exists() && !file.createNewFile()) {
-            log.info("创建 {} 失败", filepath);
-        }
-
-        /*TextFile.empty(file);
-        TextFile.write(file, filecontent);*/
-    }
 }

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

@@ -1,11 +0,0 @@
-package cn.reghao.autodop.dmaster.app.constant;
-
-/**
- * 编译工具
- *
- * @author reghao
- * @date 2019-10-18 14:31:29
- */
-public enum CompilerType {
-    shell, maven, none
-}

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/CompilerType.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.constant.build;
+
+/**
+ * 编译工具类型,应和和 @AppType 一致
+ *
+ * @author reghao
+ * @date 2019-10-18 14:31:29
+ */
+public enum CompilerType {
+    none, shell, dotnet, maven, npm, cmake, python
+}

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

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.constant;
+package cn.reghao.autodop.dmaster.app.constant.build;
 
 /**
  * @author reghao

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/RepoAuthType.java → dmaster/src/main/java/cn/reghao/autodop/dmaster/app/constant/build/RepoAuthType.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.constant;
+package cn.reghao.autodop.dmaster.app.constant.build;
 
 /**
  * @author reghao

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

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.constant;
+package cn.reghao.autodop.dmaster.app.constant.build;
 
 /**
  * @author reghao

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

@@ -2,6 +2,10 @@ package cn.reghao.autodop.dmaster.app.controller;
 
 import cn.reghao.autodop.common.result.WebResult;
 import cn.reghao.autodop.dmaster.app.constant.*;
+import cn.reghao.autodop.dmaster.app.constant.build.CompilerType;
+import cn.reghao.autodop.dmaster.app.constant.build.PackerType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoAuthType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoType;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.ResponseEntity;

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

@@ -36,6 +36,8 @@ public class AppOrchestration extends BaseEntity implements Cloneable {
     // 启用编排
     @Column(nullable = false)
     private boolean enable;
+    // 构建生成的可执行二进制文件名
+    private String execBinName;
 
     @Column(nullable = false)
     private String appRepo;

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

@@ -75,14 +75,19 @@ public class BuildDeployDispatcher {
 
         // TODO 抛出异常时从 onBuilding 中移除当前应用
         BuildLog buildLog = buildPipeline(appIntegrate);
+        buildDeployLogConsumer.addBuildLog(buildLog);
         onBuilding.remove(appId);
+        BuildDeployApp buildDeployApp;
         if (buildLog.getStatusCode() == 0 && isDeploy) {
             DeployResult deployResult = deployApp(buildLog);
             assert deployResult != null;
-            return BuildDeployApp.of(deployResult);
+            buildDeployApp = BuildDeployApp.of(deployResult);
         } else {
-            return BuildDeployApp.of(buildLog);
+            buildDeployApp = BuildDeployApp.of(buildLog);
         }
+
+        buildDeployLogConsumer.addBuildDeployApp(buildDeployApp);
+        return buildDeployApp;
     }
 
     /**
@@ -105,7 +110,6 @@ public class BuildDeployDispatcher {
             buildDeployLogConsumer.addCommitLog(commitLog);
         } catch (Exception e) {
             buildException(buildLog, BuildStage.update, e);
-            buildDeployLogConsumer.addBuildLog(buildLog);
             return buildLog;
         }
 
@@ -115,7 +119,6 @@ public class BuildDeployDispatcher {
             buildLog.setCompileTotalTime(System.currentTimeMillis()-start);
         } catch (Exception e) {
             buildException(buildLog, BuildStage.compile, e);
-            buildDeployLogConsumer.addBuildLog(buildLog);
             return buildLog;
         }
 
@@ -126,14 +129,12 @@ public class BuildDeployDispatcher {
             buildLog.setPackTotalTime(System.currentTimeMillis()-start);
         } catch (Exception e) {
             buildException(buildLog, BuildStage.pack, e);
-            buildDeployLogConsumer.addBuildLog(buildLog);
             return buildLog;
         }
 
         buildLog.setStage(BuildStage.done);
         buildLog.setStatusCode(0);
         buildLog.setBuildTime(LocalDateTime.now());
-        buildDeployLogConsumer.addBuildLog(buildLog);
         return buildLog;
     }
 
@@ -169,7 +170,9 @@ public class BuildDeployDispatcher {
         BuildLog buildLog = cache.findByAppIdAndCommitId(appId, commitId);
         DeployResult deployResult = deployApp(buildLog);
         assert deployResult != null;
-        return BuildDeployApp.of(deployResult);
+        BuildDeployApp buildDeployApp = BuildDeployApp.of(deployResult);
+        buildDeployLogConsumer.addBuildDeployApp(buildDeployApp);
+        return buildDeployApp;
     }
 
     public void deployNotify(NotifierConfig notifierConfig, DeployLog deployLog) {

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

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.dmaster.app.constant.PackerType;
-import cn.reghao.autodop.dmaster.app.constant.RepoType;
+import cn.reghao.autodop.dmaster.app.constant.build.PackerType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoType;
 import cn.reghao.autodop.dmaster.app.entity.config.build.BuildConfig;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.*;
 import cn.reghao.autodop.dmaster.app.entity.config.orchestration.AppOrchestration;
@@ -113,7 +113,7 @@ public class AppIntegrate {
             case dotnet:
                 break;
             case maven:
-                codeCompiler = new MavenCompiler(compilerConfig);
+                codeCompiler = new MavenCompiler(compilerConfig, app.getDirname());
                 break;
             case npm:
                 break;
@@ -182,6 +182,7 @@ public class AppIntegrate {
 
     public void compile() throws Exception {
         // TODO 通过脚本调用编译器时会卡住
+        // TODO 编译主目录分为项目中的应用和独立应用
         codeCompiler.compile(app.getAppId(), appCompileDir + app.getCompileHome());
     }
 

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

@@ -8,8 +8,10 @@ import cn.reghao.autodop.dmaster.app.entity.config.orchestration.ProjOrchestrati
 import cn.reghao.autodop.dmaster.common.config.SysConfig;
 import lombok.extern.slf4j.Slf4j;
 
+import javax.persistence.ForeignKey;
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 
 /**
  * @author reghao
@@ -35,9 +37,9 @@ public class BuilderUtil {
         ProjOrchestration proj = app.getProj();
         if (proj != null) {
             appLocalRepo += dirname(proj.getProjRepo());
-            copy(appLocalRepo, appCompileDir, app);
+            FileOps.copyDirContentToDir(appLocalRepo, appCompileDir);
         } else {
-            copy(appLocalRepo, appCompileDir, app);
+            FileOps.copyDirToDir(appLocalRepo + "/" + app.getDirname(), appCompileDir);
         }
 
         // Dotnet 应用需要额外的处理
@@ -47,18 +49,6 @@ public class BuilderUtil {
         }
     }
 
-    private static void copy(String from, String to, AppOrchestration app) throws IOException {
-        FileOps.copyDirToDir(from + "/" + app.getDirname(), to);
-        /*Set<String> dep = app.getDependencyRepos();
-        if (dep != null && !dep.isEmpty()) {
-            for (String repo : dep) {
-                if (!repo.isEmpty()) {
-                    FileUtil.copyDirToDir(from + dirname(repo), to);
-                }
-            }
-        }*/
-    }
-
     /**
      * 获取目录名字
      *

+ 10 - 17
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/compiler/MavenCompiler.java

@@ -18,40 +18,42 @@ import java.util.List;
  */
 @Slf4j
 public class MavenCompiler implements CodeCompiler {
+    private String dirname;
     private String env;
     private InvocationRequest request;
     private Invoker invoker;
     private List<String> compileLog;
 
-    public MavenCompiler(CompilerConfig compilerConfig) {
+    public MavenCompiler(CompilerConfig compilerConfig, String dirname) {
         System.setProperty("maven.home", compilerConfig.getHomePath());
         this.env = compilerConfig.getEnv();
         this.request = new DefaultInvocationRequest();
         this.invoker = new DefaultInvoker();
         this.compileLog = new ArrayList<>();
+        this.dirname = dirname;
     }
 
     @Override
     public void compile(String appName, String appCompileHome) throws Exception {
         String pomPath = appCompileHome + "/pom.xml";
-        setInvocationRequest(appName, pomPath);
+        setInvocationRequest(pomPath);
         InvocationResult result = invoker.execute(request);
         if (result.getExitCode() != 0) {
-            log.info("构建失败... {}", result.getExecutionException().getMessage());
+            throw new Exception(compileLog.toString());
         } else {
             log.info("构建成功...");
         }
     }
 
     /**
-     * mvn clean package -am -Ptest -pl ${app}
+     * mvn clean package -am -Pdev -pl ${app}
      * // TODO 注意线程安全,也可每个线程创建一个对象
      *
      * @param
      * @return
      * @date 2020-05-12 上午10:36
      */
-    private void setInvocationRequest(String appName, String pomPath) {
+    private void setInvocationRequest(String pomPath) {
         // 清空前一次构建的日志
         compileLog.clear();
         request.setPomFile(new File(pomPath));
@@ -59,19 +61,10 @@ public class MavenCompiler implements CodeCompiler {
         request.setGoals(Arrays.asList("clean", "package"));
         // -am
         request.setAlsoMake(true);
-        // -Ptest
+        // -Penv
         request.setProfiles(Collections.singletonList(env));
-        // -pl auth
-        request.setProjects(Collections.singletonList(appName));
+        // -pl app
+        request.setProjects(Collections.singletonList(dirname));
         request.setOutputHandler(line -> compileLog.add(line));
     }
-
-    public static void main(String[] args) throws Exception {
-        String mvnHome = "/home/reghao/dev/tools/maven-3.6.0";
-        String compileHome = "/home/reghao/code/aha/spiderlab";
-
-        CompilerConfig compilerConfig = new CompilerConfig();
-        CodeCompiler codeCompiler = new MavenCompiler(compilerConfig);
-        codeCompiler.compile("crawler", compileHome);
-    }
 }

+ 3 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/packer/ZipPack.java

@@ -25,12 +25,13 @@ public class ZipPack implements CodePacker {
 
     @Override
     public String pack(String appId, String commitId, String appCompileHome) throws Exception {
-        String tag = appId + "_" + commitId + SUFFIX;
+        log.info("生成 zip 包...");
+        /*String tag = appId + "_" + commitId + SUFFIX;
         String dst = targetPath + "/" + tag;
         if (new File(dst).exists()) {
             return null;
         }
-        ZipFiles.zip(new File(appCompileHome), dst);
+        ZipFiles.zip(new File(appCompileHome), dst);*/
         return null;
     }
 }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/tools/repo/GitImpl.java

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service.build.tools.repo;
 
 import cn.reghao.autodop.common.utils.text.TextFile;
-import cn.reghao.autodop.dmaster.app.constant.RepoAuthType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoAuthType;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.RepoConfig;
 import cn.reghao.autodop.dmaster.app.entity.log.ChangedFile;
 import cn.reghao.autodop.dmaster.app.entity.log.CommitLog;

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/crud/build/PackerConfigCrudService.java

@@ -3,7 +3,7 @@ package cn.reghao.autodop.dmaster.app.service.crud.build;
 import cn.reghao.autodop.common.utils.data.db.CrudOps;
 import cn.reghao.autodop.common.utils.data.db.PageList;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.PackerConfig;
-import cn.reghao.autodop.dmaster.app.constant.PackerType;
+import cn.reghao.autodop.dmaster.app.constant.build.PackerType;
 import cn.reghao.autodop.dmaster.app.repository.build.PackerConfigRepository;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;

+ 9 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogConsumer.java

@@ -1,9 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.log;
 
-import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
-import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
-import cn.reghao.autodop.dmaster.app.entity.log.CommitLog;
-import cn.reghao.autodop.dmaster.app.entity.log.DeployResult;
+import cn.reghao.autodop.dmaster.app.entity.log.*;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.BlockingQueue;
@@ -36,6 +33,10 @@ public class BuildDeployLogConsumer implements Runnable {
         logQueue.add(deployResult);
     }
 
+    public void addBuildDeployApp(BuildDeployApp buildDeployApp) {
+        logQueue.add(buildDeployApp);
+    }
+
     @Override
     public void run() {
         log.info("日志持久化线程已启动...");
@@ -54,6 +55,10 @@ public class BuildDeployLogConsumer implements Runnable {
                     DeployResult deployResult = (DeployResult) object;
                     logService.saveDeployLog(deployResult);
                     log.info("持久化 {} 部署日志完成...", deployResult.getAppId());
+                } else if (object instanceof BuildDeployApp) {
+                    BuildDeployApp buildDeployApp = (BuildDeployApp) object;
+                    logService.saveBuildDeployApp(buildDeployApp);
+                    log.info("持久化 {} 构建部署日志完成...", buildDeployApp.getAppId());
                 }
             } catch (InterruptedException e) {
                 // 中断线程

+ 5 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogService.java

@@ -41,12 +41,15 @@ public class BuildDeployLogService {
     @Transactional(rollbackFor = {Exception.class})
     public void saveBuildLog(BuildLog buildLog) throws Exception {
         buildLogRepository.save(buildLog);
-        buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(buildLog));
     }
 
     @Transactional(rollbackFor = {Exception.class})
     public void saveDeployLog(DeployResult deployResult) throws Exception {
         deployResult.getDeployLogs().forEach(deployLog -> deployLogRepository.save(deployLog));
-        buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(deployResult));
+    }
+
+    @Transactional(rollbackFor = {Exception.class})
+    public void saveBuildDeployApp(BuildDeployApp buildDeployApp) throws Exception {
+        buildDeployAppCrudService.addOrUpdate(buildDeployApp);
     }
 }

+ 3 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/orchestration/AppVO.java

@@ -3,9 +3,9 @@ package cn.reghao.autodop.dmaster.app.vo.orchestration;
 import cn.reghao.autodop.common.dagent.app.api.data.log.LogLevel;
 import cn.reghao.autodop.common.dagent.app.api.data.log.LogType;
 import cn.reghao.autodop.common.utils.data.serializer.JsonConverter;
-import cn.reghao.autodop.dmaster.app.constant.PackerType;
-import cn.reghao.autodop.dmaster.app.constant.RepoAuthType;
-import cn.reghao.autodop.dmaster.app.constant.RepoType;
+import cn.reghao.autodop.dmaster.app.constant.build.PackerType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoAuthType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoType;
 import cn.reghao.autodop.dmaster.app.entity.config.NotifierConfig;
 import cn.reghao.autodop.dmaster.app.constant.NotifierType;
 import cn.reghao.autodop.dmaster.app.entity.config.build.BuildConfig;

+ 4 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/vo/orchestration/ProjVO.java

@@ -1,10 +1,12 @@
 package cn.reghao.autodop.dmaster.app.vo.orchestration;
 
 import cn.reghao.autodop.common.utils.data.serializer.JsonConverter;
-import cn.reghao.autodop.dmaster.app.constant.*;
+import cn.reghao.autodop.dmaster.app.constant.build.CompilerType;
+import cn.reghao.autodop.dmaster.app.constant.build.PackerType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoAuthType;
+import cn.reghao.autodop.dmaster.app.constant.build.RepoType;
 import cn.reghao.autodop.dmaster.app.entity.config.build.BuildConfig;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.CompilerConfig;
-import cn.reghao.autodop.dmaster.app.entity.config.build.tools.CompilerType;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.PackerConfig;
 import cn.reghao.autodop.dmaster.app.entity.config.build.tools.RepoConfig;
 import cn.reghao.autodop.dmaster.app.entity.config.orchestration.ProjOrchestration;