Jelajahi Sumber

代码重构中...

reghao 5 tahun lalu
induk
melakukan
35f3b42c46

+ 8 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/cache/OrchestrationCache.java

@@ -1,11 +1,13 @@
 package cn.reghao.autodop.dmaster.app.cache;
 
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
+import cn.reghao.autodop.dmaster.app.repository.orchestration.ProjOrchestrationRepository;
 import org.springframework.stereotype.Service;
 
 /**
- * 应用编排缓存
+ * 编排缓存
  *
  * @author reghao
  * @date 2020-03-06 15:17:33
@@ -13,9 +15,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class OrchestrationCache {
     private AppOrchestrationRepository appRepository;
+    private ProjOrchestrationRepository projRepository;
 
-    public OrchestrationCache(AppOrchestrationRepository appRepository) {
+    public OrchestrationCache(AppOrchestrationRepository appRepository, ProjOrchestrationRepository projRepository) {
         this.appRepository = appRepository;
+        this.projRepository = projRepository;
     }
 
     // TODO @Cacheable(cacheNames = "app", key = "#appId")
@@ -24,8 +28,7 @@ public class OrchestrationCache {
         return app;
     }
 
-    public AppOrchestration findByRepoAndBranch(String repo, String branch) {
-        AppOrchestration app = appRepository.findByIsDeleteFalseAndAppRepoAndBranch(repo, branch);
-        return app;
+    public ProjOrchestration findByProjId(String projId) {
+        return null;
     }
 }

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

@@ -50,8 +50,8 @@ public class BuildController {
     )
     @PostMapping("/pipeline")
     public String buildAndDeploy(@RequestParam("appId") String appId) throws Exception {
-        BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(appId, true);
-        return WebResult.success(buildDeployResult);
+        //BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(appId, true);
+        return WebResult.success("buildDeployResult");
     }
 
     @ApiOperation(value = "构建应用")
@@ -61,8 +61,8 @@ public class BuildController {
     )
     @PostMapping("/build")
     public String build(@RequestParam("appId") String appId) throws Exception {
-        BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(appId, false);
-        return WebResult.success(buildDeployResult);
+        //BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(appId, false);
+        return WebResult.success("buildDeployResult");
     }
 
     @ApiOperation(value = "部署应用")
@@ -73,8 +73,8 @@ public class BuildController {
     @PostMapping("/deploy")
     public String deploy(@RequestParam("appId") String appId, @RequestParam("commitId") String commitId) {
         // TODO 单独部署某个或几个节点
-        BuildDeployResult buildDeployResult = buildDispatcher.deploy(appId, commitId);
-        return WebResult.success(buildDeployResult);
+        //BuildDeployResult buildDeployResult = buildDispatcher.deploy(appId, commitId);
+        return WebResult.success("buildDeployResult");
     }
 
     @ApiOperation(value = "部署 OSS 资源")

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

@@ -30,7 +30,7 @@ public class WebhookController {
         String repo = jsonObject.get("repository").getAsJsonObject().get("url").getAsString();
         String ref = jsonObject.get("ref").getAsString();
         String branch = ref.substring(ref.lastIndexOf("/")+1);
-        BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(repo, branch, true);
-        return WebResult.success(buildDeployResult);
+        //BuildDeployResult buildDeployResult = buildDispatcher.buildAndDeploy(repo, branch, true);
+        return WebResult.success("buildDeployResult");
     }
 }

+ 2 - 88
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -4,8 +4,6 @@ import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
 import cn.reghao.autodop.dmaster.app.entity.build.tools.CompilerConfig;
 import cn.reghao.autodop.dmaster.app.entity.build.tools.PackerConfig;
 import cn.reghao.autodop.dmaster.app.entity.build.tools.RepoConfig;
-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.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
 import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.CodeCompiler;
@@ -15,21 +13,16 @@ import cn.reghao.autodop.dmaster.app.service.build.tools.compiler.ShellCompiler;
 import cn.reghao.autodop.dmaster.app.service.build.tools.packer.CodePacker;
 import cn.reghao.autodop.dmaster.app.service.build.tools.packer.DockerPack;
 import cn.reghao.autodop.dmaster.app.service.build.tools.packer.ZipPack;
-import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
 import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CodeUpdater;
 import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CommitLog;
 import cn.reghao.autodop.dmaster.app.service.build.tools.updater.GitImpl;
 import cn.reghao.autodop.dmaster.app.service.build.tools.updater.SvnImpl;
 import cn.reghao.autodop.dmaster.common.config.SysConfig;
-import cn.reghao.autodop.dmaster.common.exception.ExceptionUtil;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;
-import java.time.LocalDateTime;
-import java.util.List;
-import java.util.Set;
 
 /**
  * 应用构建部署,每个应用持有一个对象
@@ -50,18 +43,12 @@ public class AppIntegrate {
     private CodeUpdater codeUpdater;
     private CodeCompiler codeCompiler;
     private CodePacker codePacker;
-    private AppDeployer appDeployer;
 
-    public AppIntegrate(AppOrchestration app, AppDeployer appDeployer) {
+    public AppIntegrate(AppOrchestration app) {
         this.app = app;
-        this.appDeployer = appDeployer;
         init();
     }
 
-    public AppOrchestration getApp() {
-        return this.app;
-    }
-
     public String appId() {
         return app.getAppId();
     }
@@ -80,7 +67,6 @@ public class AppIntegrate {
     private void init() {
         initLocalDir();
         initBuildConfig();
-        initDeployConfig();
     }
 
     private void initLocalDir() {
@@ -150,67 +136,6 @@ public class AppIntegrate {
         }
     }
 
-    private void initDeployConfig() {
-
-    }
-
-    /* 构建:更新 -> 编译 -> 打包 */
-    // TODO 处理集群部署时,不同节点使用不同配置文件的问题
-    public BuildLog build() {
-        BuildLog buildLog = new BuildLog();
-        /*buildLog.setAppId(app.getAppId());
-        buildLog.setAppType(app.getAppType());
-        buildLog.setEnv(app.getEnv());
-        buildLog.setAppCompile(app.getAppBuild().getAppCompile());
-        buildLog.setAppPack(app.getAppBuild().getAppPack());*/
-
-        /*boolean isUpdate;
-        try {
-            long start = System.currentTimeMillis();
-            isUpdate = update(buildLog);
-            buildLog.setUpdateTotalTime(System.currentTimeMillis() - start);
-            log.info("{} 更新完成...", app.getAppId());
-        } catch (Exception e) {
-            // TODO codeup IP 白名单异常
-            buildException(buildLog, e);
-            return buildLog;
-        }
-
-        if (isUpdate) {
-            try {
-                long start = System.currentTimeMillis();
-                compile();
-                buildLog.setCompileTotalTime(System.currentTimeMillis() - start);
-                log.info("{} 编译完成...", app.getAppId());
-            } catch (Exception e) {
-                buildException(buildLog, e);
-                return buildLog;
-            }
-
-            try {
-                long start = System.currentTimeMillis();
-                pack(buildLog);
-                buildLog.setPackTotalTime(System.currentTimeMillis() - start);
-                log.info("{} 打包完成...", app.getAppId());
-            } catch (Exception e) {
-                buildException(buildLog, e);
-                return buildLog;
-            }
-        } else {
-            buildLog.setCompileTotalTime(0);
-            buildLog.setPackTotalTime(0);
-            buildLog.setMsg("代码未变,无需构建");
-            buildLog.setStatusCode(2);
-            buildLog.setBuildTime(LocalDateTime.now());
-            return buildLog;
-        }
-
-        buildLog.setMsg("构建成功");
-        buildLog.setStatusCode(0);
-        buildLog.setBuildTime(LocalDateTime.now());*/
-        return buildLog;
-    }
-
     public CommitLog update() throws Exception {
         String remote;
         String branch;
@@ -232,7 +157,6 @@ public class AppIntegrate {
         // TODO 代码版本未更改的情况下,是否应该构建
         if (updateStatus.isUpdated || app.isAlwaysBuild()) {
             lastCommitLog = updateStatus.getLastCommitLog();
-            //buildLog.setCommitLog(lastCommitLog);
             BuilderUtil.copyToCompileDir(local, app);
         }
 
@@ -242,7 +166,6 @@ public class AppIntegrate {
     private UpdateStatus update0(String remote, String branch, String local) throws Exception {
         CommitLog current = codeUpdater.update(remote, branch, local);
         current.setAppId(app.getAppId());
-        //current.setEnv(app.getEnv());
         if (lastCommitLog != null) {
             if (lastCommitLog.getCommitId().equals(current.getCommitId())) {
                 return new UpdateStatus(current, false);
@@ -262,16 +185,7 @@ public class AppIntegrate {
 
     public String pack() throws Exception {
         String appEntryDir = appCompileDir + app.getCompileDir();
-        String appPath = codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(), appEntryDir);
-        return appPath;
-        //buildLog.setAppPath(appPath);
-    }
-
-    /* 部署 */
-    public List<DeployLog> deploy(BuildLog buildLog, Set<String> hosts) {
-        List<DeployLog> deployLogs = appDeployer.deploy(buildLog, app.getAppDeploy(), hosts);
-        log.info("{} 部署完成...", app.getAppId());
-        return deployLogs;
+        return codePacker.pack(app.getAppId(), lastCommitLog.getCommitId(), appEntryDir);
     }
 
     @Data

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

@@ -37,18 +37,20 @@ public class BuildDeployPipeline implements Callable<BuildDeployResult> {
      */
     @Override
     public BuildDeployResult call() {
-        BuildLog buildLog = appIntegrate.build();
+        BuildLog buildLog = new BuildLog();
         // 更新代码成功后才持久化构建日志
         /*if (buildLog.getCommitLog() != null) {
             logConsumer.addBuildLog(buildLog);
         }*/
 
-        if (buildLog.getStatusCode() == 0 && isDeploy) {
+        /*if (buildLog.getStatusCode() == 0 && isDeploy) {
             List<DeployLog> deployLogs = appIntegrate.deploy(buildLog, null);
             logConsumer.addDeployLogs(deployLogs);
             return BuildDeployResult.fromDeployLogs(deployLogs);
         } else {
             return BuildDeployResult.fromBuildLog(buildLog);
-        }
+        }*/
+
+        return BuildDeployResult.fromBuildLog(buildLog);
     }
 }

+ 91 - 151
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java

@@ -1,35 +1,26 @@
 package cn.reghao.autodop.dmaster.app.service.build;
 
-import cn.reghao.autodop.common.notification.DingNotify;
-import cn.reghao.autodop.common.notification.Notify;
 import cn.reghao.autodop.dmaster.app.cache.OrchestrationCache;
-import cn.reghao.autodop.dmaster.app.constant.NotifierType;
-import cn.reghao.autodop.dmaster.app.entity.Notification;
-import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
 import cn.reghao.autodop.dmaster.app.entity.build.BuildResult;
+import cn.reghao.autodop.dmaster.app.entity.build.BuildStage;
+import cn.reghao.autodop.dmaster.app.entity.deploy.DeployResult;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
-import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
-import cn.reghao.autodop.dmaster.app.repository.log.BuildLogRepository;
-import cn.reghao.autodop.dmaster.app.repository.log.CommitLogRepository;
-import cn.reghao.autodop.dmaster.app.repository.log.DeployLogRepository;
 import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
-import cn.reghao.autodop.dmaster.app.service.deploy.NotifyTask;
 import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CommitLog;
-import cn.reghao.autodop.dmaster.app.vo.log.BuildDeployResult;
 import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.app.repository.log.LogRepository;
 import cn.reghao.autodop.dmaster.app.service.log.LogConsumer;
-import cn.reghao.autodop.dmaster.common.thread.ThreadPoolWrapper;
-import lombok.Data;
+import cn.reghao.autodop.dmaster.common.exception.ExceptionUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.*;
-import java.util.stream.Collectors;
 
 /**
  * 应用构建部署分发器
+ * 多个线程访问同一个 BuildDispatcher 对象
  *
  * @author reghao
  * @date 2019-11-12 17:20:27
@@ -37,168 +28,117 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class BuildDispatcher {
-    private Map<String, AppIntegrate> appIntegrateMap;
-    private CommitLogRepository commitLogRepository;
-    private BuildLogRepository buildLogRepository;
-    private DeployLogRepository deployLogRepository;
-    private AppDeployer appDeployer;
     // TODO 多线程访问的集合
-    private Set<String> onBuilding;
-    private OrchestrationCache caching;
+    private Set<String> onBuilding = new ConcurrentSkipListSet<>();
+    private Set<String> onDeploying = new ConcurrentSkipListSet<>();
+    private Map<String, AppIntegrate> integrateMap = new ConcurrentHashMap<>();
+    private OrchestrationCache cache;
+    private AppDeployer appDeployer;
     private LogConsumer logConsumer;
-    private ExecutorService threadPool;
-
-    public BuildDispatcher(AppDeployer appDeployer,
-                           CommitLogRepository commitLogRepository,
-                           BuildLogRepository buildLogRepository,
-                           DeployLogRepository deployLogRepository,
-                           OrchestrationCache caching,
-                           LogRepository logDAO) {
-        this.commitLogRepository = commitLogRepository;
-        this.buildLogRepository = buildLogRepository;
-        this.deployLogRepository = deployLogRepository;
+
+    public BuildDispatcher(OrchestrationCache orchestrationCache, AppDeployer appDeployer, LogRepository logDAO) {
+        this.cache = orchestrationCache;
         this.appDeployer = appDeployer;
-        this.onBuilding = new HashSet<>();
-        this.appIntegrateMap = new HashMap<>();
-        this.caching = caching;
         this.logConsumer = new LogConsumer(logDAO);
-        this.threadPool = ThreadPoolWrapper.threadPool("build");
-        threadPool.submit(logConsumer);
     }
 
-    public BuildResult build(String appId) {
-        AppIntegrate appIntegrate = appIntegrateMap.get(appId);
-        if (appIntegrate != null) {
+    /**
+     * 构建部署应用
+     *
+     * @param
+     * @return
+     * @date 2021-02-06 上午1:46
+     */
+    public BuildResult buildAndDeploy(String appId, boolean isDeploy) {
+        if (!onBuilding.add(appId)) {
+            // TODO 应用正在构建中...
+            return null;
+        }
 
+        AppIntegrate appIntegrate = integrateMap.get(appId);
+        if (appIntegrate == null) {
+            AppOrchestration app = cache.findByAppId(appId);
+            appIntegrate = new AppIntegrate(app);
+            integrateMap.put(appId, appIntegrate);
         }
 
-        return null;
-    }
+        BuildLog buildLog = buildTask(appIntegrate);
+        onBuilding.remove(appId);
 
-    public BuildDeployResult buildAndDeploy(String appId, boolean isDeploy) {
-        AppOrchestration app = caching.findByAppId(appId);
-        return dispatch(app, isDeploy);
-    }
+        if (isDeploy) {
+            deploy(buildLog);
+        }
 
-    public BuildDeployResult buildAndDeploy(String repo, String branch, boolean isDeploy) {
-        AppOrchestration app = caching.findByRepoAndBranch(repo, branch);
-        return dispatch(app, isDeploy);
+        return null;
     }
 
-    public BuildDeployResult dispatch(AppOrchestration app, boolean isDeploy) {
-        String appId = app.getAppId();
-        if (!onBuilding.contains(appId)) {
-            onBuilding.add(appId);
-        } else {
-            log.info("{} 正在构建中...", appId);
-        }
+    /**
+     * 更新 -> 编译 -> 打包 -> 部署流水线
+     *
+     * @date 2019-11-07 下午10:14
+     */
+    private BuildLog buildTask(AppIntegrate appIntegrate) {
+        BuildLog buildLog = new BuildLog();
+        buildLog.setAppId(appIntegrate.appId());
 
-        AppIntegrate appIntegrate = getAppIntegrate(app);
-        Future<BuildDeployResult> future = threadPool.submit(new BuildDeployPipeline(appIntegrate, isDeploy, logConsumer));
-        while (!future.isDone() && !future.isCancelled()) {
-            try {
-                Thread.sleep(1_000);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
+        long start = System.currentTimeMillis();
+        try {
+            CommitLog commitLog = appIntegrate.update();
+            buildLog.setUpdate(commitLog.isUpdate());
+            buildLog.setCommitId(commitLog.getCommitId());
+            buildLog.setUpdateTotalTime(System.currentTimeMillis()-start);
+            logConsumer.addCommitLog(commitLog);
+        } catch (Exception e) {
+            buildException(buildLog, BuildStage.update, e);
+            return buildLog;
         }
 
-        BuildDeployResult buildDeployResult = null;
         try {
-            buildDeployResult = future.get();
-            if (buildDeployResult.isDeploy()) {
-                // TODO 异步发送通知
-                log.info("异步发送通知");
-                notifyAsync(app, buildDeployResult);
-            }
-        } catch (InterruptedException | ExecutionException e) {
-            e.printStackTrace();
-        } finally {
-            onBuilding.remove(appId);
+            start = System.currentTimeMillis();
+            appIntegrate.compile();
+            buildLog.setCompileTotalTime(System.currentTimeMillis()-start);
+        } catch (Exception e) {
+            buildException(buildLog, BuildStage.compile, e);
+            return buildLog;
         }
-        return buildDeployResult;
-    }
 
-    public BuildDeployResult deploy(String appId, String commitId) {
-        AppOrchestration app = caching.findByAppId(appId);
-        CommitLog commitLog = commitLogRepository.findByCommitId(commitId);
-        AppBuild appBuild = app.getAppBuild();
-        //BuildLog buildLog = buildLogRepository.findByIsDeleteFalseAndCommitLogAndAppCompileAndAppPackAndAppIdAndStatusCode(commitLog, appBuild.getAppCompile(), appBuild.getAppPack(), appId, 0);
-        BuildLog buildLog = new BuildLog();
-        if (buildLog != null) {
-            //Set<String> hosts = app.getAppDeploy().getHosts();
-            Set<String> hosts = new HashSet<>();
-            // 当前 commit 最近一次部署时已部署的主机
-            Set<String> deployedHosts = deployLogRepository.findByIsDeleteFalseAndBuildLog(buildLog).stream()
-                    .filter(deployLog -> deployLog.getStatusCode() != 0)
-                    .map(DeployLog::getHost)
-                    .collect(Collectors.toSet());
-
-            // TODO 比较 toDeployHosts 和 hosts,查看是否有新添加但未部署的主机
-            if (!hosts.isEmpty()) {
-                List<DeployLog> deployLogs1 = getAppIntegrate(app).deploy(buildLog, hosts);
-                logConsumer.addDeployLogs(deployLogs1);
-                BuildDeployResult buildDeployResult = BuildDeployResult.fromDeployLogs(deployLogs1);
-                notifyAsync(app, buildDeployResult);
-                return buildDeployResult;
-            } else {
-                BuildDeployResult buildDeployResult = new BuildDeployResult();
-                buildDeployResult.setAppId(appId);
-                buildDeployResult.setDeploy(true);
-                buildDeployResult.setCommitId(commitId);
-                buildDeployResult.setStatusCode(0);
-                buildDeployResult.setMsg("当前版本已部署到所有节点");
-                return buildDeployResult;
-            }
-        } else {
-            BuildDeployResult buildDeployResult = new BuildDeployResult();
-            buildDeployResult.setAppId(appId);
-            buildDeployResult.setDeploy(true);
-            buildDeployResult.setCommitId(commitId);
-            buildDeployResult.setStatusCode(1);
-            buildDeployResult.setMsg(appId + " 或 " + commitId + "不存在");
-            return buildDeployResult;
+        try {
+            start = System.currentTimeMillis();
+            String packagePath = appIntegrate.pack();
+            buildLog.setPackagePath(packagePath);
+            buildLog.setPackTotalTime(System.currentTimeMillis()-start);
+        } catch (Exception e) {
+            buildException(buildLog, BuildStage.pack, e);
+            return buildLog;
         }
-    }
 
-    private AppIntegrate getAppIntegrate(AppOrchestration app) {
-        return new AppIntegrate(app, appDeployer);
-        /*AppIntegrate appIntegrate = map.get(app.getAppId());
-        if (appIntegrate == null) {
-            appIntegrate = new AppIntegrate(app, appDeployer);
-            // TODO AppOrchestration 更新后 AppIntegrate 需要重新获取
-            map.put(app.getAppId(), appIntegrate);
-        }
-        return appIntegrate;*/
+        buildLog.setStage(BuildStage.done);
+        buildLog.setStatusCode(0);
+        buildLog.setBuildTime(LocalDateTime.now());
+        return buildLog;
     }
 
-    public void notifyAsync(AppOrchestration app, BuildDeployResult buildDeployResult) {
-        Notification notification = app.getNotification();
-        String notifierType = notification.getNotifierType();
-        String dest = notification.getUrl();
-        Notify notify = null;
-        if (notifierType.equals(NotifierType.webhook.name())) {
-            notify = new DingNotify();
-        }
-
-        // TODO 检查应用是否成功运行,若启动失败,则回退到上一个版本。若上一个版本仍失败,则返回错误并发出紧急通知
-        NotifyMsg notifyMsg = new NotifyMsg(app.getAppId(), app.getEnv(), buildDeployResult.getCommitId());
-        notifyMsg.setMsg(buildDeployResult.getMsg());
-        // TODO 检测通知是否成功发送
-        threadPool.submit(new NotifyTask(notify, dest, notifyMsg));
+    private void buildException(BuildLog log, BuildStage stage, Exception e) {
+        log.setStage(stage);
+        log.setStatusCode(1);
+        log.setErrDetail(ExceptionUtil.errorMsg(e));
+        log.setBuildTime(LocalDateTime.now());
     }
 
-    @Data
-    static class NotifyMsg {
-        private String appId;
-        private String env;
-        private String commitId;
-        private String msg;
-
-        public NotifyMsg(String appId, String env, String commitId) {
-            this.appId = appId;
-            this.env = env;
-            this.commitId = commitId;
+    /**
+     * 部署应用的最新版本
+     *
+     * @param
+     * @return
+     * @date 2021-02-06 上午2:02
+     */
+    public DeployResult deploy(BuildLog buildLog) {
+        if (!onDeploying.add(buildLog.getAppId())) {
+            // TODO 应用正在部署中...
+            return null;
         }
+
+        onDeploying.remove(buildLog.getAppId());
+        return null;
     }
 }

+ 0 - 87
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildTask.java

@@ -1,87 +0,0 @@
-package cn.reghao.autodop.dmaster.app.service.build;
-
-import cn.reghao.autodop.dmaster.app.entity.build.BuildResult;
-import cn.reghao.autodop.dmaster.app.entity.build.BuildStage;
-import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
-import cn.reghao.autodop.dmaster.app.service.build.tools.updater.CommitLog;
-import cn.reghao.autodop.dmaster.app.service.log.LogConsumer;
-import cn.reghao.autodop.dmaster.common.exception.ExceptionUtil;
-import lombok.extern.slf4j.Slf4j;
-
-import java.time.LocalDateTime;
-import java.util.concurrent.Callable;
-
-/**
- * 更新 -> 编译 -> 打包
- * 每个应用都对应一个构建任务
- *
- * @author reghao
- * @date 2019-11-16 21:39:53
- */
-@Slf4j
-public class BuildTask implements Callable<BuildLog> {
-    private AppIntegrate appIntegrate;
-    private LogConsumer logConsumer;
-
-    public BuildTask(AppIntegrate appIntegrate, LogConsumer logConsumer) {
-        this.appIntegrate = appIntegrate;
-        this.logConsumer = logConsumer;
-    }
-
-    /**
-     * 更新 -> 编译 -> 打包 -> 部署流水线
-     *
-     * @param
-     * @return 返回 JSON
-     * @date 2019-11-07 下午10:14
-     */
-    @Override
-    public BuildLog call() {
-        BuildLog buildLog = new BuildLog();
-        buildLog.setAppId(appIntegrate.appId());
-
-        long start = System.currentTimeMillis();
-        try {
-            CommitLog commitLog = appIntegrate.update();
-            buildLog.setUpdate(commitLog.isUpdate());
-            buildLog.setCommitId(commitLog.getCommitId());
-            buildLog.setUpdateTotalTime(System.currentTimeMillis()-start);
-            logConsumer.addCommitLog(commitLog);
-        } catch (Exception e) {
-            buildException(buildLog, BuildStage.update, e);
-            return buildLog;
-        }
-
-        try {
-            start = System.currentTimeMillis();
-            appIntegrate.compile();
-            buildLog.setCompileTotalTime(System.currentTimeMillis()-start);
-        } catch (Exception e) {
-            buildException(buildLog, BuildStage.compile, e);
-            return buildLog;
-        }
-
-        try {
-            start = System.currentTimeMillis();
-            String packagePath = appIntegrate.pack();
-            buildLog.setPackagePath(packagePath);
-            buildLog.setPackTotalTime(System.currentTimeMillis()-start);
-        } catch (Exception e) {
-            buildException(buildLog, BuildStage.pack, e);
-            return buildLog;
-        }
-        
-        buildLog.setStage(BuildStage.done);
-        buildLog.setStatusCode(0);
-        buildLog.setBuildTime(LocalDateTime.now());
-        logConsumer.addBuildLog(buildLog);
-        return buildLog;
-    }
-
-    private void buildException(BuildLog log, BuildStage stage, Exception e) {
-        log.setStage(stage);
-        log.setStatusCode(1);
-        log.setErrDetail(ExceptionUtil.errorMsg(e));
-        log.setBuildTime(LocalDateTime.now());
-    }
-}