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