[ Project ] 适配前端部分代码

This commit is contained in:
zeaslity
2023-08-02 14:30:01 +08:00
parent 98467f9590
commit 8e2eacfa47
22 changed files with 596 additions and 142 deletions

View File

@@ -189,7 +189,7 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
}
log.Info(fmt.Sprintf("agent server info is %v", string(jsonFormat)))
// build a operator cache
// build operator cache
BuildAgentOsOperator(agentServerInfo)
return agentServerInfo
@@ -197,21 +197,13 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
executor.AgentOsOperatorCache = &executor.AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: agentServerInfo,
}
// call the init exec function
agentOsOperator := executor.BuildAgentOsOperator(agentServerInfo.OSInfo)
// assign the agentServerInfo
agentOsOperator.AgentServerInfo = agentServerInfo
// debug
marshal, _ := json.Marshal(executor.AgentOsOperatorCache)
log.DebugF("cached agent operator is %s", marshal)
marshal, _ := json.Marshal(agentOsOperator)
log.DebugF("[Agent INIT] cached agent operator is %s", marshal)
}

View File

@@ -69,13 +69,17 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
var output []byte
var err error
for i, command := range pipeLineCommand {
cmd := exec.Command(command[0], command[1:]...)
cmd.Stdin = bytes.NewReader(output)
output, err = cmd.Output()
if err != nil {
return strings.Split(string(output), "\n"), err
}
if i == len(pipeLineCommand)-1 {
return strings.Split(string(output), "\n"), nil
}

View File

@@ -0,0 +1,80 @@
package executor
import "strings"
func BuildAgentOsOperator(osInfo string) *AgentOsOperator {
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: nil,
}
// os type
detectByOsType(AgentOsOperatorCache, osInfo)
// internet
detectByInternet(AgentOsOperatorCache)
return AgentOsOperatorCache
}
func detectByOsType(os *AgentOsOperator, osInfo string) {
ubuntuSsRealseCode := [][]string{
{
"cat",
"/etc/os-release",
},
{
"grep",
"CODE",
},
{
"head",
"-1",
},
{
"cut",
"-d",
"=",
"-f",
"2",
},
}
if strings.HasPrefix(osInfo, "Ce") {
// centos
os.IsOsTypeUbuntu = false
os.InstallCommandPrefix = []string{
"yum", "install", "-y",
}
os.RemoveCommandPrefix = []string{
"yum", "remove",
}
} else {
// ubuntu
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "-y",
}
// os release code
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osRealseResult[0]
}
}
func detectByInternet(os *AgentOsOperator) {
}

View File

@@ -11,7 +11,6 @@ import (
type RabbitMQ interface {
RabbitSendWriter
RabbitConnectCloser
}
@@ -29,6 +28,7 @@ type RabbitConnectCloser interface {
type RabbitQueue struct {
RabbitConn *RabbitMQConn
RabbitProp *ConnectProperty
}

View File

@@ -3,14 +3,13 @@ package status
import (
"fmt"
"github.com/shirou/gopsutil/v3/disk"
"runtime"
"time"
)
type DiskStatus struct {
Total uint64
Used uint64
LogicalDisk []disk.PartitionStat
Total uint64
Used uint64
//LogicalDisk []disk.PartitionStat
}
func GetDiskStatus() *DiskStatus {
@@ -22,11 +21,12 @@ func GetDiskStatus() *DiskStatus {
ds.Total = du.Total
ds.Used = du.Used
// 2023年7月14日 去除此部分 没什么用
// Get logical disk info for Linux systems
if runtime.GOOS == "linux" {
ld, _ := disk.Partitions(true)
ds.LogicalDisk = ld
}
//if runtime.GOOS == "linux" {
// ld, _ := disk.Partitions(true)
// ds.LogicalDisk = ld
//}
return ds
}

View File

@@ -1,19 +1,19 @@
package io.wdd.common.beans.executor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
@Deprecated
public class ExecutorFunctionMessage {
String functionName;
String functionContent;
}
//package io.wdd.common.beans.executor;
//
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//import lombok.experimental.SuperBuilder;
//
//@Data
//@NoArgsConstructor
//@AllArgsConstructor
//@SuperBuilder(toBuilder = true)
//@Deprecated
//public class ExecutorFunctionMessage {
//
// String functionName;
//
// String functionContent;
//
//}

View File

@@ -1,13 +1,7 @@
package io.wdd.common;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CommonApplicationTests {
@Test
void contextLoads() {
public class CommonApplicationTests {
public static void main(String[] args) {
System.out.println((double) System.currentTimeMillis());
}
}
}

View File

@@ -0,0 +1,25 @@
package io.wdd.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("*") // 允许所有来源
.allowedMethods(
"GET",
"POST",
"PUT",
"DELETE"
) // 允许的请求方法
.allowedHeaders("*") // 允许的请求头
.allowCredentials(true); // 是否允许发送Cookie
}
}

View File

@@ -81,6 +81,11 @@ public class TimeUtils {
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
}
public static double utcTimeStampOfDouble() {
return (double) System.currentTimeMillis();
}
/**
* @return 获取五秒时间误差内的统一时间

View File

@@ -0,0 +1,20 @@
package io.wdd.rpc.beans.request;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("查询Agent运行状态的请求实体")
public class MetricQueryEntity {
double metricStartTimeStamp;
double metricEndTimeStamp;
String agentTopicName;
}

View File

@@ -4,14 +4,14 @@ package io.wdd.rpc.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.wdd.common.response.R;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.scheduler.service.status.AgentAliveStatusMonitorService;
import io.wdd.rpc.status.beans.AgentStatus;
import io.wdd.rpc.status.service.SyncStatusService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,7 +55,6 @@ public class StatusController {
@PostMapping("/agent/all/string")
public R<String> GetAllAgentString() {
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
data.replace("[",
"");
@@ -86,4 +85,14 @@ public class StatusController {
}
@ApiOperation("[ Agent-Metric ] 获取Agent的Metric信息")
@PostMapping("/agent/metric")
public R<ArrayList<AgentStatus>> QueryMetricStatus(
@RequestBody MetricQueryEntity metricQueryEntity
) {
return R.ok(syncStatusService.QueryMetricStatus(metricQueryEntity));
}
}

View File

@@ -1,15 +1,19 @@
package io.wdd.rpc.scheduler.service.status;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.status.beans.AgentStatus;
import io.wdd.rpc.status.service.SyncStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Map;
import static io.wdd.common.utils.OctopusObjectMapperConfig.OctopusObjectMapper;
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
/**
@@ -23,6 +27,9 @@ public class AgentMetricStatusCollectService {
@Resource
SyncStatusService syncStatusService;
@Resource
RedisTemplate redisTemplate;
/**
* 收集所有健康主机的运行数据
*/
@@ -40,12 +47,42 @@ public class AgentMetricStatusCollectService {
10
);
// todo 需要进行存储或者咋滴
// 2023年7月14日 使用redis存储状态数据
log.info(
"[Agent Metric] - 所有主机的状态为 => {}",
agentMetricStatusMap
);
agentMetricStatusMap
.entrySet()
.stream()
.forEach(
entry -> {
try {
String agentMetricString = OctopusObjectMapper.writeValueAsString(entry.getValue());
double currentTime = TimeUtils.utcTimeStampOfDouble();
redisTemplate
.opsForZSet()
.add(
entry.getKey() + "-Metric",
agentMetricString,
currentTime
);
// todo 处理长度缓存
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
);
}

View File

@@ -119,12 +119,15 @@ public class CommonAndStatusCache {
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
ALL_AGENT_TOPIC_NAME_SET.addAll(collect);
String[] all_agent_topic_name_array = new String[ALL_AGENT_TOPIC_NAME_LIST.size()];
ALL_AGENT_TOPIC_NAME_LIST.toArray(all_agent_topic_name_array);
// 2023年7月10日 同步缓存至Redis中
redisTemplate
.opsForSet()
.add(
ALL_AGENT_TOPIC_NAME_REDIS_KEY,
ALL_AGENT_TOPIC_NAME_SET
all_agent_topic_name_array
);
}

View File

@@ -17,7 +17,7 @@ public class CPUStatus {
@JsonProperty("NumCores")
private Integer numCores;
@JsonProperty("CPUStatus")
@JsonProperty("CPUInfo")
private List<CPUInfoDTO> cPUInfo;
@JsonProperty("CPUPercent")
private Double cPUPercent;

View File

@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@NoArgsConstructor
@Data
public class DiskStatus {
@@ -14,19 +12,19 @@ public class DiskStatus {
private Long total;
@JsonProperty("Used")
private Long used;
@JsonProperty("LogicalDisk")
private List<LogicalDiskDTO> logicalDisk;
// @JsonProperty("LogicalDisk")
// private List<LogicalDiskDTO> logicalDisk;
@NoArgsConstructor
@Data
public static class LogicalDiskDTO {
@JsonProperty("device")
private String device;
@JsonProperty("mountpoint")
private String mountpoint;
@JsonProperty("fstype")
private String fstype;
@JsonProperty("opts")
private List<String> opts;
}
// @NoArgsConstructor
// @Data
// public static class LogicalDiskDTO {
// @JsonProperty("device")
// private String device;
// @JsonProperty("mountpoint")
// private String mountpoint;
// @JsonProperty("fstype")
// private String fstype;
// @JsonProperty("opts")
// private List<String> opts;
// }
}

View File

@@ -1,7 +1,9 @@
package io.wdd.rpc.status.service;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.status.beans.AgentStatus;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -24,4 +26,15 @@ public interface SyncStatusService {
* @return
*/
Map<String, AgentStatus> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
/* Metric 调用的后端接口 */
/**
* 根据前端的请求实体查询相应的Metric信息
*
* @return
*/
ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity);
}

View File

@@ -2,6 +2,7 @@ package io.wdd.rpc.status.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
import io.wdd.rpc.message.handler.async.AsyncWaitOctopusMessageResultService;
@@ -9,10 +10,12 @@ import io.wdd.rpc.message.handler.async.OctopusMessageSynScReplayContend;
import io.wdd.rpc.message.sender.OMessageToAgentSender;
import io.wdd.rpc.status.beans.AgentStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,6 +38,9 @@ public class SyncStatusServiceImpl implements SyncStatusService {
@Resource
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
@Resource
RedisTemplate redisTemplate;
@Override
public Map<String, Boolean> SyncCollectAgentAliveStatus(List<String> agentTopicNameList, int aliveStatusWaitMaxTime) {
@@ -185,6 +191,52 @@ public class SyncStatusServiceImpl implements SyncStatusService {
return metricMap;
}
@Override
public ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity) {
String queryRedisKey = metricQueryEntity.getAgentTopicName() + "-Metric";
if (!redisTemplate.hasKey(queryRedisKey)) {
log.error(
"[Metric] - 查询到没有此Agent {} 的Metric信息直接返回",
metricQueryEntity.getAgentTopicName()
);
}
double start = metricQueryEntity.getMetricStartTimeStamp();
double end = metricQueryEntity.getMetricEndTimeStamp();
ArrayList<AgentStatus> statusArrayList = new ArrayList<>();
redisTemplate
.opsForZSet()
.rangeByScore(
queryRedisKey,
start,
end
)
.stream()
.forEachOrdered(
metricString -> {
try {
AgentStatus agentStatus = OctopusObjectMapper.readValue(
(String) metricString,
AgentStatus.class
);
statusArrayList.add(agentStatus);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
);
return statusArrayList;
}
/**
* 2023年7月10日 通用的底层构造方法 Status类型的Octopus Message

View File

@@ -0,0 +1,29 @@
package io.wdd.server.beans.request;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 前端请求 Server模块 的请求查询体
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("前端请求 Server模块 的请求查询体")
public class ServerQueryEntity {
/*分页相关*/
Integer pageNumber;
Integer pageSize;
/*条件查询*/
String serverName;
String serverIPv4;
String serverLocation;
}

View File

@@ -16,6 +16,8 @@ import java.time.LocalDateTime;
@SuperBuilder(toBuilder = true)
public class ServerInfoVO {
private Integer id;
/**
* server host name
*/
@@ -23,7 +25,6 @@ public class ServerInfoVO {
/**
* server public ipv4
*/
private String serverIpPbV4;

View File

@@ -1,12 +1,14 @@
package io.wdd.server.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.wdd.common.response.R;
import io.wdd.server.beans.po.DomainInfoPO;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.request.ServerQueryEntity;
import io.wdd.server.beans.vo.AppInfoVO;
import io.wdd.server.beans.vo.DomainInfoVO;
import io.wdd.server.beans.vo.ServerInfoVO;
@@ -34,6 +36,15 @@ public class ServerController {
return R.ok(coreServerService.serverGetAll());
}
@PostMapping("/all")
@ApiOperation("获取服务器信息-web")
public R<Page<ServerInfoVO>> serverGetAllByPage(
@RequestBody ServerQueryEntity serverQueryEntity
) {
return R.ok(coreServerService.serverGetByPage(serverQueryEntity));
}
@GetMapping("/allIncludeDelete")
public R<List> serverGetAllIncludeDelete() {
@@ -41,8 +52,8 @@ public class ServerController {
}
@PostMapping("/single")
@ApiOperation("根据信息查询单个服务器信息")
public R serverGetSingle(
@ApiOperation("根据信息查询单个服务器信息-非页面")
public R<List<ServerInfoVO>> serverGetSingle(
@RequestParam(value = "serverIPv4", required = false) @ApiParam(value = "服务器IPv4地址", required = false) @Nullable String ipv4,
@RequestParam(value = "serverName", required = false) @ApiParam(value = "服务器名称", required = false) @Nullable String serverName,
@RequestParam(value = "serverLocation", required = false) @ApiParam(value = "服务器地理位置", required = false) @Nullable String serverLocation

View File

@@ -1,20 +1,26 @@
package io.wdd.server.coreService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.wdd.server.beans.po.DomainInfoPO;
import io.wdd.server.beans.po.ServerInfoPO;
import io.wdd.server.beans.request.ServerQueryEntity;
import io.wdd.server.beans.vo.AppInfoVO;
import io.wdd.server.beans.vo.DomainInfoVO;
import io.wdd.server.beans.vo.ServerInfoVO;
import java.util.List;
import java.util.Set;
public interface CoreServerService {
List<ServerInfoPO> serverGetSingle(String serverName, String ipv4, String serverLocation);
List<ServerInfoVO> serverGetSingle(String serverName, String ipv4, String serverLocation);
List<ServerInfoVO> serverGetAll();
/**
* 查询主机信息,但是是条件查询
*/
Page<ServerInfoVO> serverGetByPage(ServerQueryEntity serverQueryEntity);
List<ServerInfoVO> serverGetAllIncludeDelete();
boolean serverCreate(ServerInfoVO serverInfoVO);

View File

@@ -1,9 +1,11 @@
package io.wdd.server.coreService.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.google.errorprone.annotations.Var;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.wdd.server.beans.po.*;
import io.wdd.server.beans.request.ServerQueryEntity;
import io.wdd.server.beans.vo.AppInfoVO;
import io.wdd.server.beans.vo.DomainInfoVO;
import io.wdd.server.beans.vo.ServerInfoVO;
@@ -14,15 +16,15 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -46,14 +48,30 @@ public class CoreServerServiceImpl implements CoreServerService {
DomainInfoService domainInfoService;
@Override
public List<ServerInfoPO> serverGetSingle(String serverName, String ipv4, String serverLocation) {
public List<ServerInfoVO> serverGetSingle(String serverName, String ipv4, String serverLocation) {
// ignore if deleted !
return new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper())
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
.eq(StringUtils.isNoneEmpty(ipv4), ServerInfoPO::getServerIpPbV4, ipv4)
.eq(StringUtils.isNoneEmpty(serverLocation), ServerInfoPO::getLocation, serverLocation)
List<ServerInfoPO> list = new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper())
.eq(
StringUtils.isNoneEmpty(serverName),
ServerInfoPO::getServerName,
serverName
)
.eq(
StringUtils.isNoneEmpty(ipv4),
ServerInfoPO::getServerIpPbV4,
ipv4
)
.eq(
StringUtils.isNoneEmpty(serverLocation),
ServerInfoPO::getLocation,
serverLocation
)
.list();
return this.covertServerPOtoVO(
list,
0
);
}
@@ -63,7 +81,59 @@ public class CoreServerServiceImpl implements CoreServerService {
List<ServerInfoPO> serverInfoPOWithOutDelete = serverInfoService.list();
return covertServerPOtoVO(serverInfoPOWithOutDelete);
return covertServerPOtoVO(
serverInfoPOWithOutDelete,
0
);
}
@Override
public Page<ServerInfoVO> serverGetByPage(ServerQueryEntity serverQueryEntity) {
Page<ServerInfoPO> serverInfoPOPage = new Page<>(
serverQueryEntity.getPageNumber(),
serverQueryEntity.getPageSize()
);
// 查询Page会直接写入到serverInfoPOPage中
serverInfoService
.getBaseMapper()
.selectPage(
serverInfoPOPage,
new QueryWrapper<ServerInfoPO>()
.like(
StringUtils.isNoneEmpty(serverQueryEntity.getServerName()),
"server_name",
serverQueryEntity.getServerName()
)
.likeRight(
StringUtils.isNoneEmpty(serverQueryEntity.getServerIPv4()),
"server_ip_pb_v4",
serverQueryEntity.getServerIPv4()
)
.likeRight(
StringUtils.isNoneEmpty(serverQueryEntity.getServerLocation()),
"location",
serverQueryEntity.getServerLocation()
)
.orderByAsc("server_id")
);
// 将查询结果中的User对象转换为UserVO对象
Page<ServerInfoVO> serverInfoVOPage = new Page<>(
serverInfoPOPage.getCurrent(),
serverInfoPOPage.getSize()
);
serverInfoVOPage.setTotal(serverInfoPOPage.getTotal());
serverInfoVOPage.setRecords(
this.covertServerPOtoVO(
serverInfoPOPage.getRecords(),
(serverQueryEntity.getPageNumber() - 1) * serverQueryEntity.getPageSize()
)
);
return serverInfoVOPage;
}
@Override
@@ -79,7 +149,10 @@ public class CoreServerServiceImpl implements CoreServerService {
public boolean serverCreate(ServerInfoVO serverInfoVO) {
// BeanUtils.copyProperties(serverInfoVO, serverInfoPO);
ServerInfoPO serverInfoPO = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
ServerInfoPO serverInfoPO = EntityUtils.cvToTarget(
serverInfoVO,
ServerInfoPO.class
);
return serverInfoService.save(serverInfoPO);
}
@@ -88,18 +161,28 @@ public class CoreServerServiceImpl implements CoreServerService {
public boolean serverCreateOrUpdate(ServerInfoVO serverInfoVO) {
ServerInfoPO po = new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
.eq(ServerInfoPO::getServerName, serverInfoVO.getServerName()).one();
.eq(
ServerInfoPO::getServerName,
serverInfoVO.getServerName()
)
.one();
if (ObjectUtils.isNotEmpty(po)) {
try {
org.apache.commons.beanutils.BeanUtils.copyProperties(po, serverInfoVO);
org.apache.commons.beanutils.BeanUtils.copyProperties(
po,
serverInfoVO
);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
po = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
po = EntityUtils.cvToTarget(
serverInfoVO,
ServerInfoPO.class
);
}
return serverInfoService.saveOrUpdate(po);
@@ -113,7 +196,10 @@ public class CoreServerServiceImpl implements CoreServerService {
}
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
.eq(ServerInfoPO::getServerId, serverInfoPO.getServerId())
.eq(
ServerInfoPO::getServerId,
serverInfoPO.getServerId()
)
.update(serverInfoPO);
}
@@ -126,9 +212,20 @@ public class CoreServerServiceImpl implements CoreServerService {
// set isDelete = 1
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
.eq(serverId != null, ServerInfoPO::getServerId, serverId)
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
.set(ServerInfoPO::getIsDelete, 1)
.eq(
serverId != null,
ServerInfoPO::getServerId,
serverId
)
.eq(
StringUtils.isNoneEmpty(serverName),
ServerInfoPO::getServerName,
serverName
)
.set(
ServerInfoPO::getIsDelete,
1
)
.update();
}
@@ -138,27 +235,47 @@ public class CoreServerServiceImpl implements CoreServerService {
// serverInfo --- server_app_relation --- appInfo
List<ServerAppRelationPO> serverAppRelationPOList = new LambdaQueryChainWrapper<ServerAppRelationPO>(serverAppRelationService.getBaseMapper()).eq(ServerAppRelationPO::getServerId, serverId).list();
List<ServerAppRelationPO> serverAppRelationPOList = new LambdaQueryChainWrapper<ServerAppRelationPO>(serverAppRelationService.getBaseMapper())
.eq(
ServerAppRelationPO::getServerId,
serverId
)
.list();
Assert.notEmpty(serverAppRelationPOList,"No server find");
Assert.notEmpty(
serverAppRelationPOList,
"No server find"
);
// query the app info with specific server id
List<AppInfoPO> appInfoPOList = appInfoService.listByIds(serverAppRelationPOList.stream().map(
serverAppRelationPO -> serverAppRelationPO.getAppId()
).collect(Collectors.toList()));
List<AppInfoPO> appInfoPOList = appInfoService.listByIds(serverAppRelationPOList
.stream()
.map(
serverAppRelationPO -> serverAppRelationPO.getAppId()
)
.collect(Collectors.toList()));
return EntityUtils.cvToTarget(appInfoPOList,AppInfoVO.class);
return EntityUtils.cvToTarget(
appInfoPOList,
AppInfoVO.class
);
}
@Override
@Transactional
public AppInfoVO appCreate(Long serverId, AppInfoVO appInfoVO) {
Assert.notNull(serverInfoService.getById(serverId),"server not find, can't create a app");
Assert.notNull(
serverInfoService.getById(serverId),
"server not find, can't create a app"
);
// 1- save appInfo itself
AppInfoPO appInfoPO = EntityUtils.cvToTarget(appInfoVO, AppInfoPO.class);
AppInfoPO appInfoPO = EntityUtils.cvToTarget(
appInfoVO,
AppInfoPO.class
);
appInfoService.save(appInfoPO);
// 2. create the relation
@@ -168,15 +285,24 @@ public class CoreServerServiceImpl implements CoreServerService {
serverAppRelationService.save(relationPO);
return EntityUtils.cvToTarget(appInfoPO, AppInfoVO.class);
return EntityUtils.cvToTarget(
appInfoPO,
AppInfoVO.class
);
}
@Override
@Transactional
public boolean appDelete(Long serverId, Long appId) {
Assert.notNull(serverInfoService.getById(serverId),"server not find, can't delete a app");
Assert.notNull(appInfoService.getById(appId),"app not find, can't delete a app");
Assert.notNull(
serverInfoService.getById(serverId),
"server not find, can't delete a app"
);
Assert.notNull(
appInfoService.getById(appId),
"app not find, can't delete a app"
);
// 1. delete the relation
serverAppRelationService.removeById(serverId);
@@ -186,65 +312,114 @@ public class CoreServerServiceImpl implements CoreServerService {
return true;
}
private List<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList) {
private List<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList, int startIndex) {
if (null == serverInfoPOList || serverInfoPOList.size() == 0) {
return Collections.emptyList();
}
ArrayList<ServerInfoVO> serverInfoVOList = new ArrayList<>(32);
return serverInfoPOList.stream().map(serverInfoPO -> {
ServerInfoVO serverInfoVO = new ServerInfoVO();
BeanUtils.copyProperties(serverInfoPO, serverInfoVO);
return serverInfoVO;
}
).collect(Collectors.toList());
for (int i = 0; i < serverInfoPOList.size(); i++) {
ServerInfoVO serverInfoVO = new ServerInfoVO();
BeanUtils.copyProperties(
serverInfoPOList.get(i),
serverInfoVO
);
// 2023年7月13日 设置序号
serverInfoVO.setId(startIndex++);
serverInfoVOList.add(serverInfoVO);
}
return serverInfoVOList;
}
/*
* below is server associated domain
* server --- domain
* 1 ----------- n
* */
* below is server associated domain
* server --- domain
* 1 ----------- n
* */
@Override
public List<DomainInfoVO> domainGetAll(Long serverId) {
Assert.notNull(serverInfoService.getById(serverId),"server not find, can't create a app");
Assert.notNull(
serverInfoService.getById(serverId),
"server not find, can't create a app"
);
List<ServerDomainRelationPO> domainRelationPOList = new LambdaQueryChainWrapper<ServerDomainRelationPO>(serverDomainRelationService.getBaseMapper())
.eq(ServerDomainRelationPO::getServerId, serverId).list();
.eq(
ServerDomainRelationPO::getServerId,
serverId
)
.list();
List<DomainInfoPO> domainInfoPOList = domainInfoService.listByIds(domainRelationPOList.stream().map(
domainRelationPO -> domainRelationPO.getDomainId()
).collect(Collectors.toList()));
List<DomainInfoPO> domainInfoPOList = domainInfoService.listByIds(domainRelationPOList
.stream()
.map(
domainRelationPO -> domainRelationPO.getDomainId()
)
.collect(Collectors.toList()));
return EntityUtils.cvToTarget(domainInfoPOList, DomainInfoVO.class);
return EntityUtils.cvToTarget(
domainInfoPOList,
DomainInfoVO.class
);
}
@Override
public List<DomainInfoVO> domainGetSingle(Long serverId, String domainName, String dnsIP) {
Assert.notNull(serverInfoService.getById(serverId),"server not find, can't create a app");
Assert.notNull(
serverInfoService.getById(serverId),
"server not find, can't create a app"
);
List<ServerDomainRelationPO> domainRelationPOList = new LambdaQueryChainWrapper<ServerDomainRelationPO>(serverDomainRelationService.getBaseMapper())
.eq(ServerDomainRelationPO::getServerId, serverId).list();
.eq(
ServerDomainRelationPO::getServerId,
serverId
)
.list();
List<DomainInfoPO> domainInfoPOList = domainRelationPOList.stream().map(
domainPO -> {
// query single according to every server id related domain ID
return new LambdaQueryChainWrapper<DomainInfoPO>(domainInfoService.getBaseMapper())
.eq(DomainInfoPO::getDomainId, domainPO.getDomainId())
.like(StringUtils.isNotEmpty(domainName), DomainInfoPO::getDomainName, domainName)
.eq(StringUtils.isNoneEmpty(dnsIP), DomainInfoPO::getDnsIp, dnsIP)
.one();
}
).collect(Collectors.toList());
List<DomainInfoPO> domainInfoPOList = domainRelationPOList
.stream()
.map(
domainPO -> {
// query single according to every server id related domain ID
return new LambdaQueryChainWrapper<DomainInfoPO>(domainInfoService.getBaseMapper())
.eq(
DomainInfoPO::getDomainId,
domainPO.getDomainId()
)
.like(
StringUtils.isNotEmpty(domainName),
DomainInfoPO::getDomainName,
domainName
)
.eq(
StringUtils.isNoneEmpty(dnsIP),
DomainInfoPO::getDnsIp,
dnsIP
)
.one();
}
)
.collect(Collectors.toList());
return EntityUtils.cvToTarget(domainInfoPOList, DomainInfoVO.class);
return EntityUtils.cvToTarget(
domainInfoPOList,
DomainInfoVO.class
);
}
@Override