Browse Source

update DeployStatImpl

reghao 1 năm trước cách đây
mục cha
commit
fc2ff75543

+ 1 - 0
web/src/main/java/cn/reghao/bnt/web/devops/app/db/repository/AppDeployingRepository.java

@@ -15,4 +15,5 @@ import java.util.List;
 public interface AppDeployingRepository extends JpaRepository<AppDeploying, Integer> {
     AppDeploying findByAppConfig(AppConfig appConfig);
     AppDeploying findByAppConfig_AppId(String appId);
+    Page<AppDeploying> findAllByAppConfig_EnvAndAppConfig_AppType(String env, String appType, Pageable pageable);
 }

+ 1 - 3
web/src/main/java/cn/reghao/bnt/web/devops/app/model/vo/AppRunning.java

@@ -27,8 +27,7 @@ public class AppRunning {
     private int pid;
     private String lastCheck;
 
-    public AppRunning(AppDeploying appDeploying) {
-        AppDeployingNode deployingNode = appDeploying.getDeployingNodes().get(0);
+    public AppRunning(AppDeployingNode deployingNode, BuildLog buildLog) {
         AppConfig appConfig = deployingNode.getDeployConfig().getAppConfig();
         MachineHost machineHost = deployingNode.getDeployConfig().getMachineHost();
         this.appId = appConfig.getAppId();
@@ -38,7 +37,6 @@ public class AppRunning {
         this.bindPorts = appConfig.getBindPorts();
         this.healthCheck = appConfig.getHealthCheck();
 
-        BuildLog buildLog = appDeploying.getBuildLog();
         if (buildLog != null) {
             this.packagePath = buildLog.getPackagePath();
             this.status = deployingNode.getStatus();

+ 24 - 14
web/src/main/java/cn/reghao/bnt/web/devops/app/service/bd/impl/DeployStatImpl.java

@@ -218,33 +218,43 @@ public class DeployStatImpl implements DeployStat {
     @Override
     public PageList<AppRunningVO> getByPage(String env, String appType, int pageNumber, int pageSize) {
         PageRequest pageRequest = PageRequest.of(pageNumber-1, pageSize);
-        Page<AppDeploying> page = Page.empty();
-        List<AppRunningVO> list2 = page.getContent().stream().map(appDeploying -> {
-            AppConfig appConfig = appDeploying.getDeployingNodes().get(0).getDeployConfig().getAppConfig();
+        Page<AppDeploying> page = deployingRepository.findAllByAppConfig_EnvAndAppConfig_AppType(env, appType, pageRequest);
+        List<AppRunningVO> list = page.getContent().stream().map(appDeploying -> {
+            List<AppDeployingNode> deployingNodes = appDeploying.getDeployingNodes();
+            if (deployingNodes.isEmpty()) {
+                return null;
+            }
 
+            AppConfig appConfig = deployingNodes.get(0).getDeployConfig().getAppConfig();
             String appId = appConfig.getAppId();
             String appName = appConfig.getAppName();
             String bindPorts = appConfig.getBindPorts();
-            String packagePath = "";
+
+            String packagePath = "N/A";
             BuildLog buildLog = appDeploying.getBuildLog();
             if (buildLog != null) {
                 packagePath = buildLog.getPackagePath();
             }
-            int totalDeployed = 0;
-            return new AppRunningVO(appId, appName, bindPorts, packagePath, totalDeployed);
-        }).collect(Collectors.toList());
 
-        return PageList.pageList(pageNumber, pageSize, (int) page.getTotalElements(), list2);
+            int totalDeployed = deployingNodes.size();
+            return new AppRunningVO(appId, appName, bindPorts, packagePath, totalDeployed);
+        }).filter(Objects::nonNull).collect(Collectors.toList());
+        return PageList.pageList(pageNumber, pageSize, (int) page.getTotalElements(), list);
     }
 
     @Override
     public List<AppRunning> getAppRunning(String appId) {
-        return Collections.emptyList();
-        /*return deployingRepository.findAllByAppDeployConfig_AppConfig_AppId(appId).stream()
-                //.filter(AppDeploying::isDeployed)
-                //.sorted(Comparator.comparing(AppDeploying::getDeployTime).reversed())
-                .map(AppRunning::new)
-                .collect(Collectors.toList());*/
+        AppDeploying appDeploying = deployingRepository.findByAppConfig_AppId(appId);
+        if (appDeploying == null) {
+            return Collections.emptyList();
+        }
+
+        BuildLog buildLog = appDeploying.getBuildLog();
+        return appDeploying.getDeployingNodes().stream()
+                .map(appDeployingNode -> new AppRunning(appDeployingNode, buildLog))
+                /*.filter(AppDeploying::isDeployed)
+                .sorted(Comparator.comparing(AppDeploying::getDeployTime).reversed())*/
+                .collect(Collectors.toList());
     }
 
     @Override

+ 3 - 1
web/src/main/resources/templates/devops/app/stat/index1.html

@@ -48,6 +48,7 @@
                 <tr>
                     <th class="sortable" data-field="appName">应用</th>
                     <th class="sortable" data-field="bindPorts">监听端口</th>
+                    <th class="sortable" data-field="packagePath">包路径</th>
                     <th class="sortable" data-field="totalDeployed">部署数量</th>
                     <th>运行状态</th>
                 </tr>
@@ -59,7 +60,8 @@
                            th:text="${item.appName}" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"></a>
                     </td>
                     <td th:text="${item.bindPorts}">监听端口</td>
-                    <td th:text="${item.totalDeployed}">部署数量</td>
+                    <td th:text="${item.packagePath}">部署数量</td>
+                    <td style="color: red" th:text="${item.totalDeployed}">部署数量</td>
                     <td>
                         <a class="open-popup"
                            th:attr="data-title=${item.appName} + ' - 运行状态', data-url=@{'/app/stat/detail/'+${item.appId}}"