Parcourir la source

更新 DeployStatImpl

reghao il y a 1 an
Parent
commit
8b7f2f4d08

+ 0 - 1
web/src/main/java/cn/reghao/devops/web/mgr/app/db/repository/log/DeployLogRepository.java

@@ -16,5 +16,4 @@ public interface DeployLogRepository extends JpaRepository<DeployLog, String>, J
     void deleteByBuildLog(BuildLog buildLog);
 
     Page<DeployLog> findByBuildLogAndMachineHost(BuildLog buildLog, MachineHost machineHost, Pageable pageable);
-    Page<DeployLog> findByMachineHostAndCode(MachineHost machineHost, int code, Pageable pageable);
 }

+ 0 - 30
web/src/main/java/cn/reghao/devops/web/mgr/app/model/po/AppDeploying.java

@@ -1,13 +1,9 @@
 package cn.reghao.devops.web.mgr.app.model.po;
 
-import cn.reghao.devops.common.msg.event.EvtAppStatResult;
-import cn.reghao.devops.web.mgr.app.model.constant.DeployStatus;
 import cn.reghao.devops.web.mgr.app.model.po.config.AppConfig;
 import cn.reghao.devops.web.mgr.app.model.po.config.AppDeployConfig;
 import cn.reghao.devops.web.mgr.app.model.po.log.BuildLog;
 import cn.reghao.devops.web.admin.util.BaseEntity;
-import cn.reghao.jutil.jdk.converter.DateTimeConverter;
-import cn.reghao.jutil.jdk.result.ResultStatus;
 import lombok.*;
 import org.hibernate.annotations.LazyCollection;
 import org.hibernate.annotations.LazyCollectionOption;
@@ -43,30 +39,4 @@ public class AppDeploying extends BaseEntity {
         this.appConfig = appDeployConfig.getAppConfig();
         this.deployingNodes = List.of(new AppDeployingNode(appDeployConfig));
     }
-
-    public void afterBuild(AppBuilding appBuilding) {
-        this.buildLog = appBuilding.getBuildLog();
-        deployingNodes.forEach(deployNode -> {
-            deployNode.setDeployResult(DeployStatus.neverDeploy.getDesc());
-            deployNode.setOnDeploying(false);
-            deployNode.setDeployed(false);
-        });
-    }
-
-    public void afterDeploy(EvtAppStatResult deployResult) {
-        String machineId = deployResult.getMachineId();
-        deployingNodes.forEach(deployNode -> {
-            deployNode.setOnDeploying(false);
-            deployNode.setDeployed(true);
-            deployNode.setDeployTime(DateTimeConverter.localDateTime(deployResult.getResult().getTimestamp()));
-            if (deployResult.getResult().getCode() == ResultStatus.SUCCESS.getCode()) {
-                deployNode.setDeployResult(DeployStatus.deploySuccess.getDesc());
-            } else {
-                deployNode.setDeployResult(DeployStatus.deployFail.getDesc());
-            }
-
-            deployNode.setDeployResult(DeployStatus.onDeploying.getDesc());
-
-        });
-    }
 }

+ 0 - 2
web/src/main/java/cn/reghao/devops/web/mgr/app/model/po/AppDeployingNode.java

@@ -22,7 +22,6 @@ import java.time.LocalDateTime;
 public class AppDeployingNode implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    //private Integer deployConfigId;
     @OneToOne
     private AppDeployConfig deployConfig;
     private LocalDateTime deployTime;
@@ -38,7 +37,6 @@ public class AppDeployingNode implements Serializable {
     private LocalDateTime lastCheck;
 
     public AppDeployingNode(AppDeployConfig deployConfig) {
-        //this.deployConfigId = deployConfigId;
         this.deployConfig = deployConfig;
         this.deployResult = DeployStatus.neverDeploy.getDesc();
         this.deployTime = DateTimeConverter.localDateTime(0);

+ 0 - 21
web/src/main/java/cn/reghao/devops/web/mgr/app/model/vo/AppDeployingVO.java

@@ -22,27 +22,6 @@ public class AppDeployingVO {
     private String deployTime;
     private String deployResult;
 
-    public AppDeployingVO(AppDeployingNode deployingNode, BuildLog buildLog, String machineStatus, String deployResult) {
-        MachineHost machineHost = deployingNode.getDeployConfig().getMachineHost();
-        this.machineId = machineHost.getMachineId();
-        this.machineIpv4 = machineHost.getMachineIpv4();
-        this.machineStatus = machineStatus;
-
-        if (buildLog != null) {
-            this.commitId = buildLog.getCommitId() != null ? buildLog.getCommitId() : NotAvailable.na.getDesc();
-            this.packagePath = buildLog.getPackagePath() != null ? buildLog.getPackagePath() : NotAvailable.na.getDesc();
-        } else {
-            this.commitId = NotAvailable.na.getDesc();
-            this.packagePath = NotAvailable.na.getDesc();
-        }
-
-        this.deployBy = deployingNode.getDeployBy() != null ?
-                deployingNode.getDeployBy() : NotAvailable.na.getDesc();
-        this.deployTime = deployingNode.getDeployTime() != null ?
-                DateTimeConverter.format(deployingNode.getDeployTime()) : NotAvailable.na.getDesc();
-        this.deployResult = deployResult;
-    }
-
     public AppDeployingVO(AppDeployingNode deployingNode, BuildLog buildLog, String machineStatus) {
         MachineHost machineHost = deployingNode.getDeployConfig().getMachineHost();
         this.machineId = machineHost.getMachineId();

+ 39 - 16
web/src/main/java/cn/reghao/devops/web/mgr/app/service/bd/impl/DeployStatImpl.java

@@ -95,6 +95,12 @@ public class DeployStatImpl implements DeployStat {
         AppConfig appConfig = appBuilding.getAppConfig();
         AppDeploying appDeploying = deployingRepository.findByAppConfig(appConfig);
         if (appDeploying != null) {
+            appDeploying.getDeployingNodes().forEach(deployNode -> {
+                deployNode.setDeployResult(DeployStatus.neverDeploy.getDesc());
+                deployNode.setOnDeploying(false);
+                deployNode.setDeployed(false);
+            });
+
             appDeploying.setBuildLog(appBuilding.getBuildLog());
             deployingRepository.save(appDeploying);
         }
@@ -104,15 +110,16 @@ public class DeployStatImpl implements DeployStat {
     public void beforeDeploy(AppBuilding appBuilding, String machineId, String deployBy) {
         AppDeploying appDeploying = deployingRepository.findByAppConfig(appBuilding.getAppConfig());
         appDeploying.setBuildLog(appBuilding.getBuildLog());
-        for (AppDeployingNode deployNode : appDeploying.getDeployingNodes()) {
-            String machineId1 = deployNode.getDeployConfig().getMachineHost().getMachineId();
+        appDeploying.getDeployingNodes().forEach(appDeployingNode -> {
+            String machineId1 = appDeployingNode.getDeployConfig().getMachineHost().getMachineId();
             if (machineId1.equals(machineId)) {
-                deployNode.setDeployResult(DeployStatus.onDeploying.getDesc());
-                deployNode.setDeployBy(deployBy);
-                deployNode.setOnDeploying(true);
-                deployNode.setDeployed(false);
+                appDeployingNode.setDeployResult(DeployStatus.onDeploying.getDesc());
+                appDeployingNode.setDeployBy(deployBy);
+                appDeployingNode.setOnDeploying(true);
+                appDeployingNode.setDeployed(false);
             }
-        }
+        });
+
         deployingRepository.save(appDeploying);
     }
 
@@ -122,15 +129,20 @@ public class DeployStatImpl implements DeployStat {
         String machineId = deployResult.getMachineId();
         String appId = deployResult.getAppId();
         AppDeploying appDeploying = deployingRepository.findByAppConfig_AppId(appId);
-        for (AppDeployingNode deployNode : appDeploying.getDeployingNodes()) {
+        appDeploying.getDeployingNodes().forEach(deployNode -> {
             String machineId1 = deployNode.getDeployConfig().getMachineHost().getMachineId();
             if (machineId1.equals(machineId)) {
-                appDeploying.afterDeploy(deployResult);
+                deployNode.setOnDeploying(false);
+                deployNode.setDeployed(true);
+                deployNode.setDeployTime(DateTimeConverter.localDateTime(deployResult.getResult().getTimestamp()));
                 if (deployResult.getResult().getCode() == ResultStatus.SUCCESS.getCode()) {
+                    deployNode.setDeployResult(DeployStatus.deploySuccess.getDesc());
                     deployNode.setStatus(deployResult.getStatus());
                     deployNode.setStartTime(deployResult.getStartTime());
                     deployNode.setPid(deployResult.getPid());
                     deployNode.setLastCheck(DateTimeConverter.localDateTime(deployResult.getResult().getTimestamp()));
+                } else {
+                    deployNode.setDeployResult(DeployStatus.deployFail.getDesc());
                 }
 
                 MachineHost machineHost = deployNode.getDeployConfig().getMachineHost();
@@ -141,13 +153,29 @@ public class DeployStatImpl implements DeployStat {
                 buildDeployNotify.deployNotify(deployLog);
                 log.info("{} 的通知已发送", deployResult.getAppId());
             }
-        }
+        });
 
         deployingRepository.save(appDeploying);
     }
 
     @Override
     public void refresh(EvtAppStatResult statResult) {
+        String appId = statResult.getAppId();
+        String machineId = statResult.getMachineId();
+        AppDeploying appDeploying = deployingRepository.findByAppConfig_AppId(appId);
+        if (appDeploying != null) {
+            appDeploying.getDeployingNodes().forEach(appDeployingNode -> {
+                String machineId1 = appDeployingNode.getDeployConfig().getMachineHost().getMachineId();
+                if (machineId1.equals(machineId)) {
+                    appDeployingNode.setStatus(statResult.getStatus());
+                    appDeployingNode.setStartTime(statResult.getStartTime());
+                    appDeployingNode.setPid(statResult.getPid());
+                    appDeployingNode.setLastCheck(DateTimeConverter.localDateTime(statResult.getResult().getTimestamp()));
+                }
+            });
+
+            deployingRepository.save(appDeploying);
+        }
     }
 
     @Override
@@ -178,12 +206,7 @@ public class DeployStatImpl implements DeployStat {
             MachineHost machineHost = appDeployingNode.getDeployConfig().getMachineHost();
             String machineStatus = machineService.isAgentOnline(machineHost.getMachineId())
                     ? NodeStatus.Online.name() : NodeStatus.Offline.name();
-
-            if (buildLog == null || buildLog.getCode() != ResultStatus.SUCCESS.getCode()) {
-                return new AppDeployingVO(appDeployingNode, null, machineStatus);
-            }
-
-            return new AppDeployingVO(appDeployingNode, buildLog, machineStatus, DeployStatus.neverDeploy.getDesc());
+            return new AppDeployingVO(appDeployingNode, buildLog, machineStatus);
         }).sorted(Comparator.comparing(AppDeployingVO::getDeployTime).reversed()).collect(Collectors.toList());
     }