0708 ljc afl模块文件操作以及入库操作以及时序表操作等接口开发,包含分片代码以及文件工具类代码
This commit is contained in:
parent
777af59e6e
commit
fa13ec406a
@ -94,6 +94,15 @@ public class AflManagerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findImperfection")
|
||||||
|
public CommonResult<AflImperfectionResp> findImperfection(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
|
||||||
|
|
||||||
|
AflImperfectionResp resp = aflSeedInfoService.findImperfection(req);
|
||||||
|
|
||||||
|
return CommonResult.success(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(path="/saveAflSeedInfo")
|
@PostMapping(path="/saveAflSeedInfo")
|
||||||
public CommonResult<Void> saveAflSeedInfo(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
|
public CommonResult<Void> saveAflSeedInfo(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package cd.casic.ci.process.dto.resp.aflManager;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReportResp
|
||||||
|
* @Author hopeli
|
||||||
|
* @Date 2025/5/10 10:53
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AflImperfectionResp {
|
||||||
|
private Integer imperfectionCount = 0;
|
||||||
|
|
||||||
|
private Integer verifiedCount = 0;
|
||||||
|
|
||||||
|
private Integer unverifiedCount = 0;
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package cd.casic.ci.process.process.service.aflManager;
|
package cd.casic.ci.process.process.service.aflManager;
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.aflManager.AflManagerReq;
|
import cd.casic.ci.process.dto.req.aflManager.AflManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.aflManager.AflImperfectionResp;
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.SeedsCountResp;
|
import cd.casic.ci.process.dto.resp.aflManager.SeedsCountResp;
|
||||||
import cd.casic.ci.process.process.dataObject.aflManager.AflSeedInfo;
|
import cd.casic.ci.process.process.dataObject.aflManager.AflSeedInfo;
|
||||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||||
@ -23,4 +24,6 @@ public interface AflSeedInfoService extends IService<AflSeedInfo> {
|
|||||||
void saveAflSeedInfo(@Valid AflManagerReq req);
|
void saveAflSeedInfo(@Valid AflManagerReq req);
|
||||||
|
|
||||||
void updateHistoryPipelineIdByAflSeedInfo(@Valid AflManagerReq req);
|
void updateHistoryPipelineIdByAflSeedInfo(@Valid AflManagerReq req);
|
||||||
|
|
||||||
|
AflImperfectionResp findImperfection(@Valid AflManagerReq req);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package cd.casic.ci.process.process.service.aflManager.impl;
|
package cd.casic.ci.process.process.service.aflManager.impl;
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.aflManager.AflManagerReq;
|
import cd.casic.ci.process.dto.req.aflManager.AflManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.aflManager.AflImperfectionResp;
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.SeedsCountResp;
|
import cd.casic.ci.process.dto.resp.aflManager.SeedsCountResp;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
||||||
import cd.casic.ci.process.engine.constant.PipelineVariableConstant;
|
import cd.casic.ci.process.engine.constant.PipelineVariableConstant;
|
||||||
import cd.casic.ci.process.engine.manager.RunContextManager;
|
import cd.casic.ci.process.engine.manager.RunContextManager;
|
||||||
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
||||||
import cd.casic.ci.process.process.dao.aflManager.AflSeedInfoDao;
|
import cd.casic.ci.process.process.dao.aflManager.AflSeedInfoDao;
|
||||||
|
import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
||||||
import cd.casic.ci.process.process.dataObject.aflManager.AflSeedInfo;
|
import cd.casic.ci.process.process.dataObject.aflManager.AflSeedInfo;
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
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.aflManager.AflSeedInfoService;
|
||||||
@ -289,4 +291,51 @@ public class AflSeedInfoServiceImpl extends ServiceImpl<AflSeedInfoDao, AflSeedI
|
|||||||
}
|
}
|
||||||
baseMapper.updateBatch(aflSeedInfos);
|
baseMapper.updateBatch(aflSeedInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AflImperfectionResp findImperfection(AflManagerReq req) {
|
||||||
|
AflImperfectionResp aflImperfectionResp = new AflImperfectionResp();
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(req.getPipelineId()) || StringUtils.isEmpty(req.getTaskId())){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"pipelineId或者taskId不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseRunContext runContext = runContextManager.getContext(req.getPipelineId());
|
||||||
|
if (ObjectUtils.isEmpty(runContext)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到运行上下文");
|
||||||
|
}
|
||||||
|
String resourceId = runContext.getGlobalVariables().get(PipelineVariableConstant.AFL_RESOURCE_MANAGER_ID_KEY) instanceof String ? ((String) runContext.getGlobalVariables().get(PipelineVariableConstant.AFL_RESOURCE_MANAGER_ID_KEY)) : null;
|
||||||
|
if (StringUtils.isEmpty(resourceId)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到资源");
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceFindResp resourceById = resourceManagerService.findResourceById(resourceId);
|
||||||
|
if (resourceById == null || resourceById.getResourceMachine() == null) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源信息错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||||
|
String password = CryptogramUtil.doDecrypt(resourceMachine.getPassword());
|
||||||
|
resourceMachine.setPassword(password);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 查询所有缺陷数
|
||||||
|
List<String> files = SftpUploadUtil.listFilesInRemoteDirectory(
|
||||||
|
resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + seedFilePath);
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(files)){
|
||||||
|
aflImperfectionResp.setImperfectionCount(files.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询已验证和未验证缺陷数
|
||||||
|
AflInfo aflInfo = SftpUploadUtil.downloadFileSftpForInputStreamAndSetAflInfo(resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(),null, remoteFilePath + "PIP_" + req.getPipelineId() + "/ai_afl/default/fuzzer_stats");
|
||||||
|
if (!ObjectUtils.isEmpty(aflInfo)){
|
||||||
|
aflImperfectionResp.setVerifiedCount(Integer.parseInt(aflInfo.getSavedCrashes()));
|
||||||
|
aflImperfectionResp.setUnverifiedCount(Integer.parseInt(aflInfo.getPendingFavs()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return aflImperfectionResp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user