机器管理代码格式化提交
This commit is contained in:
parent
c26a183209
commit
ea35ed1f0b
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
import static cd.casic.framework.commons.pojo.CommonResult.success;
|
||||||
|
@ -35,7 +35,7 @@ public class MachineProxyController {
|
|||||||
|
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
@Operation(summary = "获取代理列表")
|
@Operation(summary = "获取代理列表")
|
||||||
public CommonResult list(MachineProxyDTO machineProxyDTO) {
|
public CommonResult list(@RequestBody MachineProxyDTO machineProxyDTO) {
|
||||||
return success(machineProxyService.list(machineProxyDTO));
|
return success(machineProxyService.list(machineProxyDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,8 @@ public class MachineProxyController {
|
|||||||
@DeleteMapping("/batch")
|
@DeleteMapping("/batch")
|
||||||
@Operation(summary = "批量删除代理")
|
@Operation(summary = "批量删除代理")
|
||||||
public CommonResult deleteBatch(@RequestParam String ids) {
|
public CommonResult deleteBatch(@RequestParam String ids) {
|
||||||
return success(machineProxyService.delete(ids));
|
machineProxyService.delete(ids);
|
||||||
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package cd.casic.module.machine.controller;
|
package cd.casic.module.machine.controller;
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
import cd.casic.module.machine.entity.SecretKey;
|
import cd.casic.module.machine.entity.SecretKey;
|
||||||
import cd.casic.module.machine.service.SecretKeyService;
|
import cd.casic.module.machine.service.SecretKeyService;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package cd.casic.module.machine.dto;
|
package cd.casic.module.machine.dto;
|
||||||
|
|
||||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
package cd.casic.module.machine.entity;
|
package cd.casic.module.machine.entity;
|
||||||
|
|
||||||
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import cd.casic.module.machine.enums.MachineInfoStatus;
|
import cd.casic.module.machine.enums.MachineInfoStatus;
|
||||||
import cd.casic.module.machine.enums.MachineProxyType;
|
import cd.casic.module.machine.enums.MachineProxyType;
|
||||||
@ -45,7 +47,7 @@ public class MachineProxy extends BaseEntity implements Serializable {
|
|||||||
* 代理状态 (online, offline, installing, updating, error)
|
* 代理状态 (online, offline, installing, updating, error)
|
||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private MachineInfoStatus status;
|
private MachineProxyStatus status;
|
||||||
|
|
||||||
@TableField(value = "status_code")
|
@TableField(value = "status_code")
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
@ -67,5 +69,4 @@ public class MachineProxy extends BaseEntity implements Serializable {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -482,11 +482,13 @@ public class ConnectionSession implements AutoCloseable {
|
|||||||
log.debug("Created remote directory: {}", directory);
|
log.debug("Created remote directory: {}", directory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取路径的父目录
|
// 获取路径的父目录
|
||||||
private String getParentDirectory(String path) {
|
private String getParentDirectory(String path) {
|
||||||
int lastSlash = path.lastIndexOf('/');
|
int lastSlash = path.lastIndexOf('/');
|
||||||
return lastSlash > 0 ? path.substring(0, lastSlash) : "";
|
return lastSlash > 0 ? path.substring(0, lastSlash) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 断开SFTP通道
|
// 断开SFTP通道
|
||||||
private void disconnectChannel(Channel channel) {
|
private void disconnectChannel(Channel channel) {
|
||||||
if (channel != null && channel.isConnected()) {
|
if (channel != null && channel.isConnected()) {
|
||||||
@ -513,6 +515,7 @@ public class ConnectionSession implements AutoCloseable {
|
|||||||
disconnectChannel(channel);
|
disconnectChannel(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增强的进度监控器
|
// 增强的进度监控器
|
||||||
private static class ProgressMonitorAdapter implements SftpProgressMonitor {
|
private static class ProgressMonitorAdapter implements SftpProgressMonitor {
|
||||||
private final long totalBytes;
|
private final long totalBytes;
|
||||||
@ -575,7 +578,6 @@ public class ConnectionSession implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查连接状态
|
* 检查连接状态
|
||||||
*/
|
*/
|
||||||
|
@ -16,6 +16,7 @@ public interface MachineEnvService extends IService<MachineEnv> {
|
|||||||
* 创建或更新机器的环境变量(一对一关系)
|
* 创建或更新机器的环境变量(一对一关系)
|
||||||
*/
|
*/
|
||||||
boolean add(MachineEnvDTO machineEnvDTO);
|
boolean add(MachineEnvDTO machineEnvDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除机器的环境变量
|
* 删除机器的环境变量
|
||||||
*/
|
*/
|
||||||
@ -23,6 +24,7 @@ public interface MachineEnvService extends IService<MachineEnv> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取机器的环境变量
|
* 获取机器的环境变量
|
||||||
|
*
|
||||||
* @param machineId 机器ID
|
* @param machineId 机器ID
|
||||||
* @return 环境变量DTO
|
* @return 环境变量DTO
|
||||||
*/
|
*/
|
||||||
|
@ -25,9 +25,9 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
void deleteMachineInfo(Long machineInfoId);
|
void deleteMachineInfo(Long machineInfoId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试机器连接
|
* 测试机器连接
|
||||||
|
*
|
||||||
* @param machineInfo 机器信息
|
* @param machineInfo 机器信息
|
||||||
* @return 连接是否成功
|
* @return 连接是否成功
|
||||||
*/
|
*/
|
||||||
@ -35,6 +35,7 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取机器连接状态
|
* 获取机器连接状态
|
||||||
|
*
|
||||||
* @param machineName 机器名称
|
* @param machineName 机器名称
|
||||||
* @return 连接状态
|
* @return 连接状态
|
||||||
*/
|
*/
|
||||||
@ -42,12 +43,14 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有连接状态
|
* 获取所有连接状态
|
||||||
|
*
|
||||||
* @return 机器名称到连接状态的映射
|
* @return 机器名称到连接状态的映射
|
||||||
*/
|
*/
|
||||||
Map<String, ConnectionStatus> getAllConnectionStatus();
|
Map<String, ConnectionStatus> getAllConnectionStatus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 建立机器连接
|
* 建立机器连接
|
||||||
|
*
|
||||||
* @param machineInfo 机器信息
|
* @param machineInfo 机器信息
|
||||||
* @return 连接会话ID
|
* @return 连接会话ID
|
||||||
*/
|
*/
|
||||||
@ -55,6 +58,7 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 断开机器连接
|
* 断开机器连接
|
||||||
|
*
|
||||||
* @param sessionId 会话ID
|
* @param sessionId 会话ID
|
||||||
* @return 操作结果
|
* @return 操作结果
|
||||||
*/
|
*/
|
||||||
@ -62,6 +66,7 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行远程命令
|
* 执行远程命令
|
||||||
|
*
|
||||||
* @param sessionId 会话ID
|
* @param sessionId 会话ID
|
||||||
* @param command 命令
|
* @param command 命令
|
||||||
* @return 命令执行结果
|
* @return 命令执行结果
|
||||||
@ -70,6 +75,7 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件到远程机器
|
* 上传文件到远程机器
|
||||||
|
*
|
||||||
* @param sessionId 会话ID
|
* @param sessionId 会话ID
|
||||||
* @param localFilePath 本地文件路径
|
* @param localFilePath 本地文件路径
|
||||||
* @param remoteFilePath 远程文件路径
|
* @param remoteFilePath 远程文件路径
|
||||||
@ -79,6 +85,7 @@ public interface MachineInfoService extends IService<MachineInfo> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从远程机器下载文件
|
* 从远程机器下载文件
|
||||||
|
*
|
||||||
* @param sessionId 会话ID
|
* @param sessionId 会话ID
|
||||||
* @param remoteFilePath 远程文件路径
|
* @param remoteFilePath 远程文件路径
|
||||||
* @param localFilePath 本地文件路径
|
* @param localFilePath 本地文件路径
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package cd.casic.module.machine.service;
|
package cd.casic.module.machine.service;
|
||||||
|
|
||||||
import cd.casic.module.machine.dto.MachineProxyDTO;
|
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||||
import cd.casic.module.machine.entity.MachineProxy;
|
import cd.casic.module.machine.entity.MachineProxy;
|
||||||
import cd.casic.module.machine.utils.PageResult;
|
import cd.casic.module.machine.utils.PageResult;
|
||||||
@ -22,7 +23,6 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
|||||||
boolean updateStatus(MachineProxyDTO machineProxyDTO);
|
boolean updateStatus(MachineProxyDTO machineProxyDTO);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有代理的状态统计
|
* 获取所有代理的状态统计
|
||||||
*
|
*
|
||||||
@ -38,9 +38,10 @@ public interface MachineProxyService extends IService<MachineProxy> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除代理
|
* 批量删除代理
|
||||||
|
*
|
||||||
* @param proxyIds 代理ID列表
|
* @param proxyIds 代理ID列表
|
||||||
*/
|
*/
|
||||||
String delete(String proxyIds);
|
void delete(String proxyIds);
|
||||||
|
|
||||||
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
|
PageResult<MachineProxyDTO> list(MachineProxyDTO machineProxyDTO);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package cd.casic.module.machine.service.impl;
|
package cd.casic.module.machine.service.impl;
|
||||||
|
|
||||||
import cd.casic.module.machine.dto.MachineEnvDTO;
|
import cd.casic.module.machine.dto.MachineEnvDTO;
|
||||||
import cd.casic.module.machine.entity.MachineEnv;
|
import cd.casic.module.machine.entity.MachineEnv;
|
||||||
import cd.casic.module.machine.exception.ServiceException;
|
import cd.casic.module.machine.exception.ServiceException;
|
||||||
@ -55,7 +56,6 @@ public class MachineEnvServiceImpl extends ServiceImpl<MachineEnvMapper, Machine
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MachineEnvDTO getByMachineId(Long machineId) {
|
public MachineEnvDTO getByMachineId(Long machineId) {
|
||||||
if (machineId == null) {
|
if (machineId == null) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package cd.casic.module.machine.service.impl;
|
package cd.casic.module.machine.service.impl;
|
||||||
|
|
||||||
import cd.casic.module.machine.dto.MachineProxyDTO;
|
import cd.casic.module.machine.dto.MachineProxyDTO;
|
||||||
import cd.casic.module.machine.entity.MachineProxy;
|
import cd.casic.module.machine.entity.MachineProxy;
|
||||||
import cd.casic.module.machine.enums.MachineProxyStatus;
|
import cd.casic.module.machine.enums.MachineProxyStatus;
|
||||||
@ -18,6 +19,7 @@ import org.springframework.beans.BeanUtils;
|
|||||||
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.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -38,7 +40,7 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
|||||||
BeanUtils.copyProperties(machineProxyDTO, proxy);
|
BeanUtils.copyProperties(machineProxyDTO, proxy);
|
||||||
proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
proxy.setProxyTypeCode(EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||||
proxy.setVersion("1.0.0");
|
proxy.setVersion("1.0.0");
|
||||||
proxy.setStatusCode(MachineProxyStatus.INSTALLING.getCode());
|
proxy.setStatusCode(MachineProxyStatus.ONLINE.getCode());
|
||||||
return save(proxy);
|
return save(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +65,6 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Long> getStatusStatistics() {
|
public Map<String, Long> getStatusStatistics() {
|
||||||
List<MachineProxy> proxyList = list();
|
List<MachineProxy> proxyList = list();
|
||||||
@ -97,10 +98,9 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String delete(String ids) {
|
public void delete(String ids) {
|
||||||
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
List<Long> machineProxyIds = Arrays.stream(ids.split(","))
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.filter(s -> !s.isEmpty())
|
.filter(s -> !s.isEmpty())
|
||||||
@ -110,26 +110,10 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
|||||||
if (CollectionUtils.isEmpty(machineProxyIds)) {
|
if (CollectionUtils.isEmpty(machineProxyIds)) {
|
||||||
throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
throw new ServiceException(ServiceException.PARAMETER_ERROR, "参数错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询在线代理
|
|
||||||
List<MachineProxy> onlineProxies = list(new LambdaQueryWrapper<MachineProxy>()
|
|
||||||
.in(MachineProxy::getId, machineProxyIds)
|
|
||||||
.eq(MachineProxy::getStatusCode, MachineProxyStatus.ONLINE.getCode()));
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(onlineProxies)) {
|
|
||||||
List<Long> onlineIds = onlineProxies.stream()
|
|
||||||
.map(MachineProxy::getId)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
// 将 [10, 9] 转换为 "10, 9"
|
|
||||||
String idStr = onlineIds.toString().replaceAll("[\\[\\]]", "");
|
|
||||||
return "以下代理处于在线状态,无法删除: " + idStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 批量逻辑删除
|
// 批量逻辑删除
|
||||||
remove(new LambdaQueryWrapper<MachineProxy>()
|
remove(new LambdaQueryWrapper<MachineProxy>()
|
||||||
.in(MachineProxy::getId, machineProxyIds));
|
.in(MachineProxy::getId, machineProxyIds)
|
||||||
return "";
|
.ne(MachineProxy::getStatus, MachineProxyStatus.ONLINE.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -169,6 +153,9 @@ public class MachineProxyServiceImpl extends ServiceImpl<MachineProxyMapper, Mac
|
|||||||
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
if (machineProxyDTO.getStatus() != null && !machineProxyDTO.getStatus().isEmpty()) {
|
||||||
queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
queryWrapper.like("status_code", EnumUtils.getEnumByMessage(machineProxyDTO.getStatus(), MachineProxyStatus.class).getCode());
|
||||||
}
|
}
|
||||||
|
if (machineProxyDTO.getProxyType() != null && !machineProxyDTO.getProxyType().isEmpty()) {
|
||||||
|
queryWrapper.like("proxy_type_code", EnumUtils.getEnumByMessage(machineProxyDTO.getProxyType(), MachineProxyType.class).getCode());
|
||||||
|
}
|
||||||
return queryWrapper.orderByDesc("create_date");
|
return queryWrapper.orderByDesc("create_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
|
|||||||
* 机器名称 -> 会话ID
|
* 机器名称 -> 会话ID
|
||||||
*/
|
*/
|
||||||
private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
private final Map<String, String> machineSessionMapping = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
public boolean addMachineInfo(MachineInfoDto machineInfoDto) {
|
||||||
if (machineInfoDto == null) {
|
if (machineInfoDto == null) {
|
||||||
@ -182,8 +183,6 @@ public class MachineinfoServiceImpl extends ServiceImpl<MachineInfoMapper, Machi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean testConnection(MachineInfo machineInfo) {
|
public boolean testConnection(MachineInfo machineInfo) {
|
||||||
if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
if (machineInfo.getStatus().getCode() == UN_ENABLE) {
|
||||||
|
@ -43,7 +43,6 @@ public class SecretKeyServiceImpl extends ServiceImpl<SecretServiceMapper, Secre
|
|||||||
private SecretServiceMapper secretServiceMapper;
|
private SecretServiceMapper secretServiceMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//todo public方便测试,后面改为private
|
//todo public方便测试,后面改为private
|
||||||
public static final ExecutorService FILE_DELETE_EXECUTOR = Executors.newFixedThreadPool(10);
|
public static final ExecutorService FILE_DELETE_EXECUTOR = Executors.newFixedThreadPool(10);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user