소스 검색

日志管理功能代码提交

jingyuanchao 1 년 전
부모
커밋
dac62460b0

+ 4 - 5
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysServerController.java

@@ -5,7 +5,6 @@ import com.xunmei.common.core.web.domain.AjaxResult;
 import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.log.annotation.Log;
 import com.xunmei.common.log.enums.BusinessType;
-import com.xunmei.system.domain.SysServer;
 import com.xunmei.system.dto.server.SysServerEditDto;
 import com.xunmei.system.dto.server.SysServerPageDto;
 import com.xunmei.system.service.ISysServerService;
@@ -72,10 +71,10 @@ public class SysServerController extends BaseController {
         return toAjax(sysServerService.deleteSysServerByIds(ids));
     }
 
-    @ApiOperation(value = "查询SysServer列表")
-    @PostMapping("/logs")
-    public AjaxResult getLogs(@RequestBody SysServer sysServer) {
-        Object logs = sysServerService.getLogs(sysServer);
+    @ApiOperation(value = "获取服务下的日志")
+    @GetMapping("/getLogList/{serverId}/{checkId}")
+    public AjaxResult getLogList(@PathVariable Long serverId, @PathVariable Long checkId) {
+        Object logs = sysServerService.getLogList(serverId,checkId);
         return success(logs);
     }
 }

+ 1 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/domain/SysServer.java

@@ -40,7 +40,7 @@ public class SysServer extends BaseEntity {
 
     @TableField("server_port")
     @ApiModelProperty(value = "看门猫端口")
-    private String serverPort;
+    private Integer serverPort;
 
     @TableField("server_name")
     @ApiModelProperty(value = "服务器名称")

+ 1 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/dto/server/SysServerEditDto.java

@@ -22,9 +22,8 @@ public class SysServerEditDto {
 
 
     @NotNull(message = "请填写看门猫端口")
-    @NotBlank(message = "请填写看门猫端口")
     @ApiModelProperty(value = "看门猫端口")
-    private String serverPort;
+    private Integer serverPort;
 
     @ApiModelProperty(value = "服务器名称")
     private String serverName;

+ 3 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysServerService.java

@@ -5,6 +5,7 @@ import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.system.domain.SysServer;
 import com.xunmei.system.dto.server.SysServerEditDto;
 import com.xunmei.system.dto.server.SysServerPageDto;
+import com.xunmei.system.vo.server.CheckListVo;
 import com.xunmei.system.vo.server.SysServerPageVo;
 
 import java.util.List;
@@ -71,5 +72,6 @@ public interface ISysServerService extends IService<SysServer> {
      * @param sysServer
      * @return
      */
-    Object getLogs( SysServer sysServer);
+    Object getLogList(Long serverId,Long checkId);
+    List<CheckListVo> getServerList(Long serverId);
 }

+ 74 - 19
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysServerServiceImpl.java

@@ -1,13 +1,16 @@
 package com.xunmei.system.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpException;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.thread.ThreadPoolConfig;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
@@ -18,14 +21,22 @@ import com.xunmei.system.dto.server.SysServerPageDto;
 import com.xunmei.system.mapper.SysServerMapper;
 import com.xunmei.system.service.ISysServerService;
 import com.xunmei.system.vo.server.CheckListVo;
+import com.xunmei.system.vo.server.FileInfoVo;
 import com.xunmei.system.vo.server.SysServerPageVo;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 /**
  * 服务器维护Service业务层处理
@@ -39,42 +50,86 @@ public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer
     @Autowired
     private SysServerMapper sysServerMapper;
 
+    @Autowired
+    @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
     @Override
     public TableDataInfo<SysServerPageVo> selectPage(SysServerPageDto req) {
 
         //获取数据
         Page<SysServerPageVo> page = sysServerMapper.selectPageData(req.getPageRequest(), req);
+        if (ObjectUtil.isNotEmpty(page.getRecords())) {
+            for (SysServerPageVo record : page.getRecords()) {
+                CompletableFuture<List<CheckListVo>> future = CompletableFuture.supplyAsync(() -> {
+                    return getServerList(record.getId());
+                }, threadPoolTaskExecutor);
+                try {
+                    List<CheckListVo> checkListVos = future.get(3, TimeUnit.SECONDS);
+                    if (ObjectUtil.isNotEmpty(checkListVos)) {
+                        for (CheckListVo listVo : checkListVos) {
+                            if (ObjectUtil.equal(0, listVo.getCheckStatus())) {
+                                listVo.setCheckStatusText("未启动");
+                            }
+                            if (ObjectUtil.equal(1, listVo.getCheckStatus())) {
+                                listVo.setCheckStatusText("重启中");
+                            }
+                            if (ObjectUtil.equal(2, listVo.getCheckStatus())) {
+                                listVo.setCheckStatusText("已启动");
+                            }
+                        }
+                    }
+                    record.setServerList(checkListVos);
+                } catch (InterruptedException | ExecutionException | TimeoutException e) {
+
+                }
+            }
+        }
         //抓换为TableDataInfo适配前端
         return TableDataInfo.build(page);
+    }
 
-
+    @Override
+    public List<CheckListVo> getServerList(Long serverId) {
+        try {
+            SysServer server = this.selectSysServerById(serverId);
+            server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
+            server.setServerIp("10.87.10.196");
+            server.setServerPort(8091);
+            String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
+            String getServicesApi = "/result/list?size=10000&current=1";
+            HttpResponse response = HttpUtil.createPost(baseUrl + getServicesApi)
+                    .header("token", server.getServerToken())
+                    .execute();
+            String serverJson = response.body();
+            JSONObject parse = JSONObject.parseObject(serverJson);
+            return parse.getObject("rows", new TypeReference<List<CheckListVo>>() {
+            });
+        } catch (HttpException e) {
+            return new ArrayList<>();
+        }
     }
 
     @Override
-    public Object getLogs(SysServer sysServer) {
-        SysServer server = this.selectSysServerById(sysServer.getId());
-        StringBuffer baseUrl = new StringBuffer("http://");
-        baseUrl.append(server.getServerIp()).append(":")
-                .append(server.getServerPort());
-        String rootUrl = baseUrl.toString();
+    public Object getLogList(Long serverId, Long checkId) {
+        // http://10.87.10.196:8091/index1.html?token=d033e22ae348aeb5660fc2140aec35850c4da997
+        SysServer server = this.selectSysServerById(serverId);
 
-        String getServices = "/result/list?size=10000&current=1";
-        String getLogs = "/result/fileList?checkId=";
+        server.setServerToken("d033e22ae348aeb5660fc2140aec35850c4da997");
+        server.setServerIp("10.87.10.196");
+        server.setServerPort(8091);
 
+        String baseUrl = String.format("http://%s:%d", server.getServerIp(), server.getServerPort());
+        String getLogs = "/result/fileList?checkId=" + checkId;
         //获取服务器列表
-        HttpResponse response = HttpUtil.createPost(rootUrl + getServices)
-                .header("Token", server.getServerToken())
+        HttpResponse response = HttpUtil.createPost(baseUrl + getLogs)
+                .header("token", server.getServerToken())
                 .execute();
         String serverJson = response.body();
-        JSONObject parse = JSONObject.parse(serverJson);
-        List<CheckListVo> checks = JSONArray.parseArray(parse.getString("rows"), CheckListVo.class);
+        List<FileInfoVo> checks = JSONArray.parseArray(serverJson, FileInfoVo.class);
 
-        for (CheckListVo check : checks) {
-            System.out.println(JSON.toJSONString(check));
-
-        }
 
-        return null;
+        return checks;
     }
 
 

+ 7 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/vo/server/CheckListVo.java

@@ -10,10 +10,12 @@ import java.util.Date;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
-public class CheckListVo  implements Serializable {
+public class CheckListVo implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+
+    private String id;
     /**
      * 服务名称
      */
@@ -26,7 +28,7 @@ public class CheckListVo  implements Serializable {
     /**
      * 进程名称
      */
-    private String pId;
+    private String pid;
 
     /**
      * 服务版本号
@@ -43,6 +45,8 @@ public class CheckListVo  implements Serializable {
      */
     private Integer checkStatus;
 
+    private String checkStatusText;
+
     /**
      * 日志文件路径
      */
@@ -53,4 +57,5 @@ public class CheckListVo  implements Serializable {
      */
     private String startLong;
 
+
 }

+ 3 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/vo/server/SysServerPageVo.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * @author jingyuanchao
@@ -33,4 +34,6 @@ public class SysServerPageVo {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     @ApiModelProperty(value = "修改时间")
     private Date updateTime;
+
+    List<CheckListVo> serverList;
 }