|
|
@@ -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¤t=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¤t=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;
|
|
|
}
|
|
|
|
|
|
|