0706 ljc afl模块文件操作以及入库操作以及时序表操作等接口开发,包含分片代码以及文件工具类代码
This commit is contained in:
parent
25a6687abb
commit
b498c519db
@ -12,6 +12,7 @@ import cd.casic.ci.process.process.dataObject.aflManager.AflCrashesInfo;
|
||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
||||
import cd.casic.ci.process.process.service.aflManager.AflCrashesInfoService;
|
||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||
import cd.casic.ci.process.util.CryptogramUtil;
|
||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
@ -69,6 +70,8 @@ public class AflCrashesInfoServiceImpl extends ServiceImpl<AflCrashesInfoDao, Af
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
|
||||
try {
|
||||
// 步骤1:列出源目录下的所有文件
|
||||
@ -99,10 +102,6 @@ public class AflCrashesInfoServiceImpl extends ServiceImpl<AflCrashesInfoDao, Af
|
||||
});
|
||||
baseMapper.insertBatch(aflCrashesInfos);
|
||||
}
|
||||
|
||||
// 步骤3:删除旧目录
|
||||
SftpUploadUtil.clearRemoteDirectoryFiles(req.getMachineHost(), Integer.parseInt(req.getSshPort()), req.getUsername(), req.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
|
||||
System.out.println("crashes目录下文件已删除: " + remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
|
||||
return uuid;
|
||||
}else {
|
||||
return null;
|
||||
|
@ -12,6 +12,7 @@ import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
||||
import cd.casic.ci.process.process.service.aflManager.AflInfoService;
|
||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||
import cd.casic.ci.process.util.CryptogramUtil;
|
||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
@ -66,8 +67,8 @@ public class AflInfoServiceImpl extends ServiceImpl<AflInfoDao, AflInfo> impleme
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
// resourceMachine.setPassword("hnidc0628cn!@#lld");
|
||||
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
AflInfo aflInfo = SftpUploadUtil.downloadFileSftpForInputStreamAndSetAflInfo(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/fuzzer_stats");
|
||||
//在本地创建一个新文件夹,将远程文件复制一份过去
|
||||
List<String> sourceFilePaths = new ArrayList<>();
|
||||
@ -122,6 +123,8 @@ public class AflInfoServiceImpl extends ServiceImpl<AflInfoDao, AflInfo> impleme
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
AflInfo aflInfo = SftpUploadUtil.downloadFileSftpForInputStreamAndSetAflInfo(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/fuzzer_stats");
|
||||
|
||||
return AflManagerConverter.INSTANCE.toAflInfoResp(aflInfo);
|
||||
|
@ -12,6 +12,7 @@ import cd.casic.ci.process.process.dataObject.aflManager.AflPlotInfo;
|
||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
||||
import cd.casic.ci.process.process.service.aflManager.AflPlotInfoService;
|
||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||
import cd.casic.ci.process.util.CryptogramUtil;
|
||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
@ -65,6 +66,8 @@ public class AflPlotInfoServiceImpl extends ServiceImpl<AflPlotInfoDao, AflPlotI
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
|
||||
AflPlotInfo aflPlotInfo = SftpUploadUtil.downloadFileSftpForLastLineAndSetAflPlotInfo(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/plot_data");
|
||||
//在本地创建一个新文件夹,将远程文件复制一份过去
|
||||
@ -120,6 +123,8 @@ public class AflPlotInfoServiceImpl extends ServiceImpl<AflPlotInfoDao, AflPlotI
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
AflPlotInfo aflPlotInfo = SftpUploadUtil.downloadFileSftpForLastLineAndSetAflPlotInfo(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/plot_data");
|
||||
|
||||
return AflManagerConverter.INSTANCE.toAflPlotInfoResp(aflPlotInfo);
|
||||
|
@ -11,6 +11,7 @@ import cd.casic.ci.process.process.dataObject.aflManager.AflSeedInfo;
|
||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
||||
import cd.casic.ci.process.process.service.aflManager.AflSeedInfoService;
|
||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||
import cd.casic.ci.process.util.CryptogramUtil;
|
||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
@ -25,7 +26,6 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -73,6 +73,8 @@ public class AflSeedInfoServiceImpl extends ServiceImpl<AflSeedInfoDao, AflSeedI
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
|
||||
List<String> resultList = SftpUploadUtil.findSeedCount(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/queue/");
|
||||
|
||||
@ -108,9 +110,13 @@ public class AflSeedInfoServiceImpl extends ServiceImpl<AflSeedInfoDao, AflSeedI
|
||||
}
|
||||
|
||||
// 解析创建时间
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss[.SSSSSSSSS] XXX");
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(createTime, formatter);
|
||||
LocalDateTime createDateTime = zonedDateTime.toLocalDateTime();
|
||||
// 截取到秒部分(即去掉 .934800255 +0000)
|
||||
String truncatedTime = createTime.split("\\.")[0]; // 得到:2025-07-06 02:17:39
|
||||
|
||||
// 使用仅包含年月日时分秒的格式解析
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
LocalDateTime createDateTime = LocalDateTime.parse(truncatedTime, formatter);
|
||||
|
||||
// 获取开始时间
|
||||
BaseRunContext taskRunContext = runContextManager.getContext(req.getTaskId());
|
||||
@ -174,7 +180,8 @@ public class AflSeedInfoServiceImpl extends ServiceImpl<AflSeedInfoDao, AflSeedI
|
||||
}
|
||||
|
||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||
|
||||
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||
resourceMachine.setPassword(password);
|
||||
try {
|
||||
// 步骤1:列出源目录下的所有文件
|
||||
List<String> files = SftpUploadUtil.listFilesInRemoteDirectory(
|
||||
|
@ -7,6 +7,7 @@ import com.amazonaws.util.IOUtils;
|
||||
import com.jcraft.jsch.*;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
@ -622,8 +623,8 @@ public class SftpUploadUtil {
|
||||
//解析 key=value 内容
|
||||
Map<String, String> statsMap = new HashMap<>();
|
||||
for (String line : fileContent.split("\\r?\\n")) {
|
||||
if (line.contains("=")) {
|
||||
String[] parts = line.split("=", 2);
|
||||
if (line.contains(":")) {
|
||||
String[] parts = line.split(":", 2);
|
||||
statsMap.put(parts[0].trim(), parts[1].trim());
|
||||
}
|
||||
}
|
||||
@ -865,15 +866,17 @@ public class SftpUploadUtil {
|
||||
channelSftp.cd(remoteDir);
|
||||
|
||||
// 列出文件
|
||||
Vector<ChannelSftp.LsEntry> entries = channelSftp.ls(".");
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
|
||||
Vector<ChannelSftp.LsEntry> entries = channelSftp.ls(".");
|
||||
if (!ObjectUtils.isEmpty(entries)){
|
||||
for (ChannelSftp.LsEntry entry : entries) {
|
||||
String name = entry.getFilename();
|
||||
if (!name.equals(".") && !name.equals("..")) {
|
||||
fileNames.add(remoteDir + name); // 返回完整路径
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return fileNames;
|
||||
} catch (JSchException e) {
|
||||
throw new SftpUploadException("SFTP 连接或认证失败: " + e.getMessage(), e);
|
||||
@ -1198,7 +1201,7 @@ public class SftpUploadUtil {
|
||||
// 遍历远程文件路径并下载
|
||||
for (String remoteFile : remoteFilePaths) {
|
||||
String fileName = new File(remoteFile).getName();
|
||||
String localFilePath = localDir + File.separator + fileName;
|
||||
String localFilePath = localDir + fileName;
|
||||
|
||||
try (InputStream in = channelSftp.get(remoteFile);
|
||||
FileOutputStream out = new FileOutputStream(localFilePath)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user