Przeglądaj źródła

重构构建部署接口...

reghao 5 lat temu
rodzic
commit
a717c84455

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/log/DeployLogRepository.java

@@ -10,5 +10,5 @@ import org.springframework.data.mongodb.repository.MongoRepository;
  * @date 2020-01-21 14:53:03
  */
 public interface DeployLogRepository extends MongoRepository<DeployLog, Long> {
-    Page<DeployLog> findDeployLogByAppId(String appId, Pageable pageable);
+    Page<DeployLog> findDeployLogByAppIdAndStatusCode(String appId, int statusCode, Pageable pageable);
 }

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

@@ -161,7 +161,7 @@ public class BuildDeployDispatcher {
         DeployResult deployResult = appDeployer.deploy(buildLog, deployConfigs);
         // TODO 部署完成后发出通知
         onDeploying.remove(buildLog.getAppId());
-        deployResult.getDeployLogs().forEach(deployLog -> buildDeployLogConsumer.addDeployLog(deployLog));
+        buildDeployLogConsumer.addDeployLog(deployResult);
         return deployResult;
     }
 
@@ -169,7 +169,6 @@ public class BuildDeployDispatcher {
         BuildLog buildLog = cache.findByAppIdAndCommitId(appId, commitId);
         DeployResult deployResult = deployApp(buildLog);
         assert deployResult != null;
-        deployResult.getDeployLogs().forEach(deployLog -> buildDeployLogConsumer.addDeployLog(deployLog));
         return BuildDeployApp.of(deployResult);
     }
 

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

@@ -126,8 +126,8 @@ public class BuildService {
 
     public PageList<CurrentRunningCommit> deployedApp(String appId, int page, int size) {
         PageRequest pageRequest =
-                PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "createTime"));
-        Page<DeployLog> deployLogs = deployLogRepository.findDeployLogByAppId(appId, pageRequest);
+                PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "deployTime"));
+        Page<DeployLog> deployLogs = deployLogRepository.findDeployLogByAppIdAndStatusCode(appId, 0, pageRequest);
         List<CurrentRunningCommit> apps = deployLogs.getContent().stream()
                 .map(deployLog -> new CurrentRunningCommit(deployLog.getMachineId(), deployLog.getCommitId(), ""))
                 .collect(Collectors.toList());

+ 7 - 6
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogConsumer.java

@@ -3,6 +3,7 @@ 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 lombok.extern.slf4j.Slf4j;
 
 import java.util.concurrent.BlockingQueue;
@@ -31,8 +32,8 @@ public class BuildDeployLogConsumer implements Runnable {
         logQueue.add(buildLog);
     }
 
-    public void addDeployLog(DeployLog deployLog) {
-        logQueue.add(deployLog);
+    public void addDeployLog(DeployResult deployResult) {
+        logQueue.add(deployResult);
     }
 
     @Override
@@ -49,10 +50,10 @@ public class BuildDeployLogConsumer implements Runnable {
                     BuildLog buildLog = (BuildLog) object;
                     logService.saveBuildLog(buildLog);
                     log.info("持久化 {} 构建日志完成...", buildLog.getAppId());
-                } else if (object instanceof DeployLog) {
-                    DeployLog deployLog = (DeployLog) object;
-                    logService.saveDeployLog(deployLog);
-                    log.info("持久化 {} 部署日志完成...", deployLog.getAppId());
+                } else if (object instanceof DeployResult) {
+                    DeployResult deployResult = (DeployResult) object;
+                    logService.saveDeployLog(deployResult);
+                    log.info("持久化 {} 部署日志完成...", deployResult.getAppId());
                 }
             } catch (InterruptedException e) {
                 // 中断线程

+ 4 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/log/BuildDeployLogService.java

@@ -1,12 +1,9 @@
 package cn.reghao.autodop.dmaster.app.service.log;
 
-import cn.reghao.autodop.dmaster.app.entity.log.BuildDeployApp;
-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.*;
 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.entity.log.CommitLog;
 import cn.reghao.autodop.dmaster.app.service.crud.BuildDeployAppCrudService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -48,8 +45,8 @@ public class BuildDeployLogService {
     }
 
     @Transactional(rollbackFor = {Exception.class})
-    public void saveDeployLog(DeployLog deployLog) {
-        deployLogRepository.save(deployLog);
-        //buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(deployLog));
+    public void saveDeployLog(DeployResult deployResult) throws Exception {
+        deployResult.getDeployLogs().forEach(deployLog -> deployLogRepository.save(deployLog));
+        buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(deployResult));
     }
 }