[ Project ] 适配前端部分代码
This commit is contained in:
@@ -189,7 +189,7 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
|
|||||||
}
|
}
|
||||||
log.Info(fmt.Sprintf("agent server info is %v", string(jsonFormat)))
|
log.Info(fmt.Sprintf("agent server info is %v", string(jsonFormat)))
|
||||||
|
|
||||||
// build a operator cache
|
// build operator cache
|
||||||
BuildAgentOsOperator(agentServerInfo)
|
BuildAgentOsOperator(agentServerInfo)
|
||||||
|
|
||||||
return agentServerInfo
|
return agentServerInfo
|
||||||
@@ -197,21 +197,13 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
|
|||||||
|
|
||||||
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
|
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
|
||||||
|
|
||||||
executor.AgentOsOperatorCache = &executor.AgentOsOperator{
|
// call the init exec function
|
||||||
InstallCommandPrefix: []string{
|
agentOsOperator := executor.BuildAgentOsOperator(agentServerInfo.OSInfo)
|
||||||
"apt-get", "install", "-y",
|
|
||||||
},
|
// assign the agentServerInfo
|
||||||
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
|
agentOsOperator.AgentServerInfo = agentServerInfo
|
||||||
CanAccessInternet: true,
|
|
||||||
IsOsTypeUbuntu: true,
|
|
||||||
IsAgentInnerWall: true,
|
|
||||||
AgentArch: "amd64",
|
|
||||||
AgentOSReleaseCode: "focal",
|
|
||||||
AgentServerInfo: agentServerInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
marshal, _ := json.Marshal(executor.AgentOsOperatorCache)
|
marshal, _ := json.Marshal(agentOsOperator)
|
||||||
log.DebugF("cached agent operator is %s", marshal)
|
log.DebugF("[Agent INIT] cached agent operator is %s", marshal)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,13 +69,17 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
|||||||
|
|
||||||
var output []byte
|
var output []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for i, command := range pipeLineCommand {
|
for i, command := range pipeLineCommand {
|
||||||
|
|
||||||
cmd := exec.Command(command[0], command[1:]...)
|
cmd := exec.Command(command[0], command[1:]...)
|
||||||
cmd.Stdin = bytes.NewReader(output)
|
cmd.Stdin = bytes.NewReader(output)
|
||||||
|
|
||||||
output, err = cmd.Output()
|
output, err = cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return strings.Split(string(output), "\n"), err
|
return strings.Split(string(output), "\n"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == len(pipeLineCommand)-1 {
|
if i == len(pipeLineCommand)-1 {
|
||||||
return strings.Split(string(output), "\n"), nil
|
return strings.Split(string(output), "\n"), nil
|
||||||
}
|
}
|
||||||
|
|||||||
80
agent-go/executor/InitFunction.go
Normal file
80
agent-go/executor/InitFunction.go
Normal 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) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
type RabbitMQ interface {
|
type RabbitMQ interface {
|
||||||
RabbitSendWriter
|
RabbitSendWriter
|
||||||
|
|
||||||
RabbitConnectCloser
|
RabbitConnectCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ type RabbitConnectCloser interface {
|
|||||||
|
|
||||||
type RabbitQueue struct {
|
type RabbitQueue struct {
|
||||||
RabbitConn *RabbitMQConn
|
RabbitConn *RabbitMQConn
|
||||||
|
|
||||||
RabbitProp *ConnectProperty
|
RabbitProp *ConnectProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package status
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/shirou/gopsutil/v3/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiskStatus struct {
|
type DiskStatus struct {
|
||||||
Total uint64
|
Total uint64
|
||||||
Used uint64
|
Used uint64
|
||||||
LogicalDisk []disk.PartitionStat
|
//LogicalDisk []disk.PartitionStat
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDiskStatus() *DiskStatus {
|
func GetDiskStatus() *DiskStatus {
|
||||||
@@ -22,11 +21,12 @@ func GetDiskStatus() *DiskStatus {
|
|||||||
ds.Total = du.Total
|
ds.Total = du.Total
|
||||||
ds.Used = du.Used
|
ds.Used = du.Used
|
||||||
|
|
||||||
|
// 2023年7月14日 去除此部分 没什么用
|
||||||
// Get logical disk info for Linux systems
|
// Get logical disk info for Linux systems
|
||||||
if runtime.GOOS == "linux" {
|
//if runtime.GOOS == "linux" {
|
||||||
ld, _ := disk.Partitions(true)
|
// ld, _ := disk.Partitions(true)
|
||||||
ds.LogicalDisk = ld
|
// ds.LogicalDisk = ld
|
||||||
}
|
//}
|
||||||
|
|
||||||
return ds
|
return ds
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package io.wdd.common.beans.executor;
|
//package io.wdd.common.beans.executor;
|
||||||
|
//
|
||||||
import lombok.AllArgsConstructor;
|
//import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
//import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
//import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
//import lombok.experimental.SuperBuilder;
|
||||||
|
//
|
||||||
@Data
|
//@Data
|
||||||
@NoArgsConstructor
|
//@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
//@AllArgsConstructor
|
||||||
@SuperBuilder(toBuilder = true)
|
//@SuperBuilder(toBuilder = true)
|
||||||
@Deprecated
|
//@Deprecated
|
||||||
public class ExecutorFunctionMessage {
|
//public class ExecutorFunctionMessage {
|
||||||
|
//
|
||||||
String functionName;
|
// String functionName;
|
||||||
|
//
|
||||||
String functionContent;
|
// String functionContent;
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
package io.wdd.common;
|
package io.wdd.common;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
public class CommonApplicationTests {
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
public static void main(String[] args) {
|
||||||
|
System.out.println((double) System.currentTimeMillis());
|
||||||
@SpringBootTest
|
|
||||||
class CommonApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
25
server/src/main/java/io/wdd/common/config/CorsConfig.java
Normal file
25
server/src/main/java/io/wdd/common/config/CorsConfig.java
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -81,6 +81,11 @@ public class TimeUtils {
|
|||||||
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
|
return LocalDateTime.now(SYSTEM_TIME_ZONE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double utcTimeStampOfDouble() {
|
||||||
|
|
||||||
|
return (double) System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 获取五秒时间误差内的统一时间
|
* @return 获取五秒时间误差内的统一时间
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,14 +4,14 @@ package io.wdd.rpc.controller;
|
|||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.wdd.common.response.R;
|
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.scheduler.service.status.AgentAliveStatusMonitorService;
|
||||||
|
import io.wdd.rpc.status.beans.AgentStatus;
|
||||||
import io.wdd.rpc.status.service.SyncStatusService;
|
import io.wdd.rpc.status.service.SyncStatusService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -55,7 +55,6 @@ public class StatusController {
|
|||||||
@PostMapping("/agent/all/string")
|
@PostMapping("/agent/all/string")
|
||||||
public R<String> GetAllAgentString() {
|
public R<String> GetAllAgentString() {
|
||||||
|
|
||||||
|
|
||||||
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
|
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
|
||||||
data.replace("[",
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package io.wdd.rpc.scheduler.service.status;
|
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.beans.AgentStatus;
|
||||||
import io.wdd.rpc.status.service.SyncStatusService;
|
import io.wdd.rpc.status.service.SyncStatusService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
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;
|
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +27,9 @@ public class AgentMetricStatusCollectService {
|
|||||||
@Resource
|
@Resource
|
||||||
SyncStatusService syncStatusService;
|
SyncStatusService syncStatusService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
RedisTemplate redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收集所有健康主机的运行数据
|
* 收集所有健康主机的运行数据
|
||||||
*/
|
*/
|
||||||
@@ -40,12 +47,42 @@ public class AgentMetricStatusCollectService {
|
|||||||
10
|
10
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo 需要进行存储或者咋滴
|
// 2023年7月14日 使用redis存储状态数据
|
||||||
log.info(
|
log.info(
|
||||||
"[Agent Metric] - 所有主机的状态为 => {}",
|
"[Agent Metric] - 所有主机的状态为 => {}",
|
||||||
agentMetricStatusMap
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,12 +119,15 @@ public class CommonAndStatusCache {
|
|||||||
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
|
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
|
||||||
ALL_AGENT_TOPIC_NAME_SET.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中
|
// 2023年7月10日 同步缓存至Redis中
|
||||||
redisTemplate
|
redisTemplate
|
||||||
.opsForSet()
|
.opsForSet()
|
||||||
.add(
|
.add(
|
||||||
ALL_AGENT_TOPIC_NAME_REDIS_KEY,
|
ALL_AGENT_TOPIC_NAME_REDIS_KEY,
|
||||||
ALL_AGENT_TOPIC_NAME_SET
|
all_agent_topic_name_array
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class CPUStatus {
|
|||||||
|
|
||||||
@JsonProperty("NumCores")
|
@JsonProperty("NumCores")
|
||||||
private Integer numCores;
|
private Integer numCores;
|
||||||
@JsonProperty("CPUStatus")
|
@JsonProperty("CPUInfo")
|
||||||
private List<CPUInfoDTO> cPUInfo;
|
private List<CPUInfoDTO> cPUInfo;
|
||||||
@JsonProperty("CPUPercent")
|
@JsonProperty("CPUPercent")
|
||||||
private Double cPUPercent;
|
private Double cPUPercent;
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
public class DiskStatus {
|
public class DiskStatus {
|
||||||
@@ -14,19 +12,19 @@ public class DiskStatus {
|
|||||||
private Long total;
|
private Long total;
|
||||||
@JsonProperty("Used")
|
@JsonProperty("Used")
|
||||||
private Long used;
|
private Long used;
|
||||||
@JsonProperty("LogicalDisk")
|
// @JsonProperty("LogicalDisk")
|
||||||
private List<LogicalDiskDTO> logicalDisk;
|
// private List<LogicalDiskDTO> logicalDisk;
|
||||||
|
|
||||||
@NoArgsConstructor
|
// @NoArgsConstructor
|
||||||
@Data
|
// @Data
|
||||||
public static class LogicalDiskDTO {
|
// public static class LogicalDiskDTO {
|
||||||
@JsonProperty("device")
|
// @JsonProperty("device")
|
||||||
private String device;
|
// private String device;
|
||||||
@JsonProperty("mountpoint")
|
// @JsonProperty("mountpoint")
|
||||||
private String mountpoint;
|
// private String mountpoint;
|
||||||
@JsonProperty("fstype")
|
// @JsonProperty("fstype")
|
||||||
private String fstype;
|
// private String fstype;
|
||||||
@JsonProperty("opts")
|
// @JsonProperty("opts")
|
||||||
private List<String> opts;
|
// private List<String> opts;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package io.wdd.rpc.status.service;
|
package io.wdd.rpc.status.service;
|
||||||
|
|
||||||
|
import io.wdd.rpc.beans.request.MetricQueryEntity;
|
||||||
import io.wdd.rpc.status.beans.AgentStatus;
|
import io.wdd.rpc.status.beans.AgentStatus;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -24,4 +26,15 @@ public interface SyncStatusService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map<String, AgentStatus> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
|
Map<String, AgentStatus> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
|
||||||
|
|
||||||
|
|
||||||
|
/* Metric 调用的后端接口 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据前端的请求实体,查询相应的Metric信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package io.wdd.rpc.status.service;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.wdd.common.utils.TimeUtils;
|
import io.wdd.common.utils.TimeUtils;
|
||||||
|
import io.wdd.rpc.beans.request.MetricQueryEntity;
|
||||||
import io.wdd.rpc.message.OctopusMessage;
|
import io.wdd.rpc.message.OctopusMessage;
|
||||||
import io.wdd.rpc.message.OctopusMessageType;
|
import io.wdd.rpc.message.OctopusMessageType;
|
||||||
import io.wdd.rpc.message.handler.async.AsyncWaitOctopusMessageResultService;
|
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.message.sender.OMessageToAgentSender;
|
||||||
import io.wdd.rpc.status.beans.AgentStatus;
|
import io.wdd.rpc.status.beans.AgentStatus;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -35,6 +38,9 @@ public class SyncStatusServiceImpl implements SyncStatusService {
|
|||||||
@Resource
|
@Resource
|
||||||
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
|
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> SyncCollectAgentAliveStatus(List<String> agentTopicNameList, int aliveStatusWaitMaxTime) {
|
public Map<String, Boolean> SyncCollectAgentAliveStatus(List<String> agentTopicNameList, int aliveStatusWaitMaxTime) {
|
||||||
|
|
||||||
@@ -185,6 +191,52 @@ public class SyncStatusServiceImpl implements SyncStatusService {
|
|||||||
return metricMap;
|
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
|
* 2023年7月10日 通用的底层构造方法 Status类型的Octopus Message
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ import java.time.LocalDateTime;
|
|||||||
@SuperBuilder(toBuilder = true)
|
@SuperBuilder(toBuilder = true)
|
||||||
public class ServerInfoVO {
|
public class ServerInfoVO {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server host name
|
* server host name
|
||||||
*/
|
*/
|
||||||
@@ -23,7 +25,6 @@ public class ServerInfoVO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* server public ipv4
|
* server public ipv4
|
||||||
|
|
||||||
*/
|
*/
|
||||||
private String serverIpPbV4;
|
private String serverIpPbV4;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package io.wdd.server.controller;
|
package io.wdd.server.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import io.wdd.common.response.R;
|
import io.wdd.common.response.R;
|
||||||
import io.wdd.server.beans.po.DomainInfoPO;
|
import io.wdd.server.beans.po.DomainInfoPO;
|
||||||
import io.wdd.server.beans.po.ServerInfoPO;
|
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.AppInfoVO;
|
||||||
import io.wdd.server.beans.vo.DomainInfoVO;
|
import io.wdd.server.beans.vo.DomainInfoVO;
|
||||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||||
@@ -34,6 +36,15 @@ public class ServerController {
|
|||||||
return R.ok(coreServerService.serverGetAll());
|
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")
|
@GetMapping("/allIncludeDelete")
|
||||||
public R<List> serverGetAllIncludeDelete() {
|
public R<List> serverGetAllIncludeDelete() {
|
||||||
|
|
||||||
@@ -41,8 +52,8 @@ public class ServerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/single")
|
@PostMapping("/single")
|
||||||
@ApiOperation("根据信息查询单个服务器信息")
|
@ApiOperation("根据信息查询单个服务器信息-非页面")
|
||||||
public R serverGetSingle(
|
public R<List<ServerInfoVO>> serverGetSingle(
|
||||||
@RequestParam(value = "serverIPv4", required = false) @ApiParam(value = "服务器IPv4地址", required = false) @Nullable String ipv4,
|
@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 = "serverName", required = false) @ApiParam(value = "服务器名称", required = false) @Nullable String serverName,
|
||||||
@RequestParam(value = "serverLocation", required = false) @ApiParam(value = "服务器地理位置", required = false) @Nullable String serverLocation
|
@RequestParam(value = "serverLocation", required = false) @ApiParam(value = "服务器地理位置", required = false) @Nullable String serverLocation
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
package io.wdd.server.coreService;
|
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.DomainInfoPO;
|
||||||
import io.wdd.server.beans.po.ServerInfoPO;
|
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.AppInfoVO;
|
||||||
import io.wdd.server.beans.vo.DomainInfoVO;
|
import io.wdd.server.beans.vo.DomainInfoVO;
|
||||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface CoreServerService {
|
public interface CoreServerService {
|
||||||
|
|
||||||
List<ServerInfoPO> serverGetSingle(String serverName, String ipv4, String serverLocation);
|
List<ServerInfoVO> serverGetSingle(String serverName, String ipv4, String serverLocation);
|
||||||
|
|
||||||
List<ServerInfoVO> serverGetAll();
|
List<ServerInfoVO> serverGetAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询主机信息,但是是条件查询
|
||||||
|
*/
|
||||||
|
Page<ServerInfoVO> serverGetByPage(ServerQueryEntity serverQueryEntity);
|
||||||
|
|
||||||
List<ServerInfoVO> serverGetAllIncludeDelete();
|
List<ServerInfoVO> serverGetAllIncludeDelete();
|
||||||
|
|
||||||
boolean serverCreate(ServerInfoVO serverInfoVO);
|
boolean serverCreate(ServerInfoVO serverInfoVO);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package io.wdd.server.coreService.impl;
|
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.query.LambdaQueryChainWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
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.po.*;
|
||||||
|
import io.wdd.server.beans.request.ServerQueryEntity;
|
||||||
import io.wdd.server.beans.vo.AppInfoVO;
|
import io.wdd.server.beans.vo.AppInfoVO;
|
||||||
import io.wdd.server.beans.vo.DomainInfoVO;
|
import io.wdd.server.beans.vo.DomainInfoVO;
|
||||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
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.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
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;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -46,14 +48,30 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
DomainInfoService domainInfoService;
|
DomainInfoService domainInfoService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ServerInfoPO> serverGetSingle(String serverName, String ipv4, String serverLocation) {
|
public List<ServerInfoVO> serverGetSingle(String serverName, String ipv4, String serverLocation) {
|
||||||
|
|
||||||
// ignore if deleted !
|
// ignore if deleted !
|
||||||
return new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper())
|
List<ServerInfoPO> list = new LambdaQueryChainWrapper<>(serverInfoService.getBaseMapper())
|
||||||
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
|
.eq(
|
||||||
.eq(StringUtils.isNoneEmpty(ipv4), ServerInfoPO::getServerIpPbV4, ipv4)
|
StringUtils.isNoneEmpty(serverName),
|
||||||
.eq(StringUtils.isNoneEmpty(serverLocation), ServerInfoPO::getLocation, serverLocation)
|
ServerInfoPO::getServerName,
|
||||||
|
serverName
|
||||||
|
)
|
||||||
|
.eq(
|
||||||
|
StringUtils.isNoneEmpty(ipv4),
|
||||||
|
ServerInfoPO::getServerIpPbV4,
|
||||||
|
ipv4
|
||||||
|
)
|
||||||
|
.eq(
|
||||||
|
StringUtils.isNoneEmpty(serverLocation),
|
||||||
|
ServerInfoPO::getLocation,
|
||||||
|
serverLocation
|
||||||
|
)
|
||||||
.list();
|
.list();
|
||||||
|
return this.covertServerPOtoVO(
|
||||||
|
list,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +81,59 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
List<ServerInfoPO> serverInfoPOWithOutDelete = serverInfoService.list();
|
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
|
@Override
|
||||||
@@ -79,7 +149,10 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
public boolean serverCreate(ServerInfoVO serverInfoVO) {
|
public boolean serverCreate(ServerInfoVO serverInfoVO) {
|
||||||
|
|
||||||
// BeanUtils.copyProperties(serverInfoVO, serverInfoPO);
|
// BeanUtils.copyProperties(serverInfoVO, serverInfoPO);
|
||||||
ServerInfoPO serverInfoPO = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
|
ServerInfoPO serverInfoPO = EntityUtils.cvToTarget(
|
||||||
|
serverInfoVO,
|
||||||
|
ServerInfoPO.class
|
||||||
|
);
|
||||||
|
|
||||||
return serverInfoService.save(serverInfoPO);
|
return serverInfoService.save(serverInfoPO);
|
||||||
}
|
}
|
||||||
@@ -88,18 +161,28 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
public boolean serverCreateOrUpdate(ServerInfoVO serverInfoVO) {
|
public boolean serverCreateOrUpdate(ServerInfoVO serverInfoVO) {
|
||||||
|
|
||||||
ServerInfoPO po = new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
|
ServerInfoPO po = new LambdaQueryChainWrapper<ServerInfoPO>(serverInfoService.getBaseMapper())
|
||||||
.eq(ServerInfoPO::getServerName, serverInfoVO.getServerName()).one();
|
.eq(
|
||||||
|
ServerInfoPO::getServerName,
|
||||||
|
serverInfoVO.getServerName()
|
||||||
|
)
|
||||||
|
.one();
|
||||||
|
|
||||||
if (ObjectUtils.isNotEmpty(po)) {
|
if (ObjectUtils.isNotEmpty(po)) {
|
||||||
try {
|
try {
|
||||||
org.apache.commons.beanutils.BeanUtils.copyProperties(po, serverInfoVO);
|
org.apache.commons.beanutils.BeanUtils.copyProperties(
|
||||||
|
po,
|
||||||
|
serverInfoVO
|
||||||
|
);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
po = EntityUtils.cvToTarget(serverInfoVO, ServerInfoPO.class);
|
po = EntityUtils.cvToTarget(
|
||||||
|
serverInfoVO,
|
||||||
|
ServerInfoPO.class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return serverInfoService.saveOrUpdate(po);
|
return serverInfoService.saveOrUpdate(po);
|
||||||
@@ -113,7 +196,10 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
|
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
|
||||||
.eq(ServerInfoPO::getServerId, serverInfoPO.getServerId())
|
.eq(
|
||||||
|
ServerInfoPO::getServerId,
|
||||||
|
serverInfoPO.getServerId()
|
||||||
|
)
|
||||||
.update(serverInfoPO);
|
.update(serverInfoPO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +212,20 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
|
|
||||||
// set isDelete = 1
|
// set isDelete = 1
|
||||||
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
|
return new LambdaUpdateChainWrapper<>(serverInfoService.getBaseMapper())
|
||||||
.eq(serverId != null, ServerInfoPO::getServerId, serverId)
|
.eq(
|
||||||
.eq(StringUtils.isNoneEmpty(serverName), ServerInfoPO::getServerName, serverName)
|
serverId != null,
|
||||||
.set(ServerInfoPO::getIsDelete, 1)
|
ServerInfoPO::getServerId,
|
||||||
|
serverId
|
||||||
|
)
|
||||||
|
.eq(
|
||||||
|
StringUtils.isNoneEmpty(serverName),
|
||||||
|
ServerInfoPO::getServerName,
|
||||||
|
serverName
|
||||||
|
)
|
||||||
|
.set(
|
||||||
|
ServerInfoPO::getIsDelete,
|
||||||
|
1
|
||||||
|
)
|
||||||
.update();
|
.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -138,27 +235,47 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
|
|
||||||
// serverInfo --- server_app_relation --- appInfo
|
// 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
|
// query the app info with specific server id
|
||||||
List<AppInfoPO> appInfoPOList = appInfoService.listByIds(serverAppRelationPOList.stream().map(
|
List<AppInfoPO> appInfoPOList = appInfoService.listByIds(serverAppRelationPOList
|
||||||
serverAppRelationPO -> serverAppRelationPO.getAppId()
|
.stream()
|
||||||
).collect(Collectors.toList()));
|
.map(
|
||||||
|
serverAppRelationPO -> serverAppRelationPO.getAppId()
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
|
||||||
return EntityUtils.cvToTarget(appInfoPOList,AppInfoVO.class);
|
return EntityUtils.cvToTarget(
|
||||||
|
appInfoPOList,
|
||||||
|
AppInfoVO.class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public AppInfoVO appCreate(Long serverId, AppInfoVO appInfoVO) {
|
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
|
// 1- save appInfo itself
|
||||||
AppInfoPO appInfoPO = EntityUtils.cvToTarget(appInfoVO, AppInfoPO.class);
|
AppInfoPO appInfoPO = EntityUtils.cvToTarget(
|
||||||
|
appInfoVO,
|
||||||
|
AppInfoPO.class
|
||||||
|
);
|
||||||
appInfoService.save(appInfoPO);
|
appInfoService.save(appInfoPO);
|
||||||
|
|
||||||
// 2. create the relation
|
// 2. create the relation
|
||||||
@@ -168,15 +285,24 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
serverAppRelationService.save(relationPO);
|
serverAppRelationService.save(relationPO);
|
||||||
|
|
||||||
|
|
||||||
return EntityUtils.cvToTarget(appInfoPO, AppInfoVO.class);
|
return EntityUtils.cvToTarget(
|
||||||
|
appInfoPO,
|
||||||
|
AppInfoVO.class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean appDelete(Long serverId, Long appId) {
|
public boolean appDelete(Long serverId, Long appId) {
|
||||||
|
|
||||||
Assert.notNull(serverInfoService.getById(serverId),"server not find, can't delete a app");
|
Assert.notNull(
|
||||||
Assert.notNull(appInfoService.getById(appId),"app not find, can't delete a app");
|
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
|
// 1. delete the relation
|
||||||
serverAppRelationService.removeById(serverId);
|
serverAppRelationService.removeById(serverId);
|
||||||
@@ -186,65 +312,114 @@ public class CoreServerServiceImpl implements CoreServerService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList) {
|
private List<ServerInfoVO> covertServerPOtoVO(List<ServerInfoPO> serverInfoPOList, int startIndex) {
|
||||||
|
|
||||||
if (null == serverInfoPOList || serverInfoPOList.size() == 0) {
|
if (null == serverInfoPOList || serverInfoPOList.size() == 0) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
ArrayList<ServerInfoVO> serverInfoVOList = new ArrayList<>(32);
|
||||||
|
|
||||||
return serverInfoPOList.stream().map(serverInfoPO -> {
|
|
||||||
ServerInfoVO serverInfoVO = new ServerInfoVO();
|
for (int i = 0; i < serverInfoPOList.size(); i++) {
|
||||||
BeanUtils.copyProperties(serverInfoPO, serverInfoVO);
|
|
||||||
return serverInfoVO;
|
ServerInfoVO serverInfoVO = new ServerInfoVO();
|
||||||
}
|
|
||||||
).collect(Collectors.toList());
|
BeanUtils.copyProperties(
|
||||||
|
serverInfoPOList.get(i),
|
||||||
|
serverInfoVO
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2023年7月13日 设置序号
|
||||||
|
serverInfoVO.setId(startIndex++);
|
||||||
|
|
||||||
|
serverInfoVOList.add(serverInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverInfoVOList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* below is server associated domain
|
* below is server associated domain
|
||||||
* server --- domain
|
* server --- domain
|
||||||
* 1 ----------- n
|
* 1 ----------- n
|
||||||
* */
|
* */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DomainInfoVO> domainGetAll(Long serverId) {
|
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())
|
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(
|
List<DomainInfoPO> domainInfoPOList = domainInfoService.listByIds(domainRelationPOList
|
||||||
domainRelationPO -> domainRelationPO.getDomainId()
|
.stream()
|
||||||
).collect(Collectors.toList()));
|
.map(
|
||||||
|
domainRelationPO -> domainRelationPO.getDomainId()
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
|
||||||
return EntityUtils.cvToTarget(domainInfoPOList, DomainInfoVO.class);
|
return EntityUtils.cvToTarget(
|
||||||
|
domainInfoPOList,
|
||||||
|
DomainInfoVO.class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DomainInfoVO> domainGetSingle(Long serverId, String domainName, String dnsIP) {
|
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())
|
List<ServerDomainRelationPO> domainRelationPOList = new LambdaQueryChainWrapper<ServerDomainRelationPO>(serverDomainRelationService.getBaseMapper())
|
||||||
.eq(ServerDomainRelationPO::getServerId, serverId).list();
|
.eq(
|
||||||
|
ServerDomainRelationPO::getServerId,
|
||||||
|
serverId
|
||||||
|
)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
|
||||||
List<DomainInfoPO> domainInfoPOList = domainRelationPOList.stream().map(
|
List<DomainInfoPO> domainInfoPOList = domainRelationPOList
|
||||||
domainPO -> {
|
.stream()
|
||||||
// query single according to every server id related domain ID
|
.map(
|
||||||
return new LambdaQueryChainWrapper<DomainInfoPO>(domainInfoService.getBaseMapper())
|
domainPO -> {
|
||||||
.eq(DomainInfoPO::getDomainId, domainPO.getDomainId())
|
// query single according to every server id related domain ID
|
||||||
.like(StringUtils.isNotEmpty(domainName), DomainInfoPO::getDomainName, domainName)
|
return new LambdaQueryChainWrapper<DomainInfoPO>(domainInfoService.getBaseMapper())
|
||||||
.eq(StringUtils.isNoneEmpty(dnsIP), DomainInfoPO::getDnsIp, dnsIP)
|
.eq(
|
||||||
.one();
|
DomainInfoPO::getDomainId,
|
||||||
}
|
domainPO.getDomainId()
|
||||||
).collect(Collectors.toList());
|
)
|
||||||
|
.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
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user