This commit is contained in:
Hope Li 2025-07-13 05:03:15 +08:00
parent 6c465c3e31
commit 560cebd6cf
3 changed files with 101 additions and 0 deletions

View File

@ -85,6 +85,15 @@ public class AflManagerController {
} }
@PostMapping(path="/findCrashesNow")
public CommonResult<List<AflCrashesInfoResp>> findCrashesNow(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
List<AflCrashesInfoResp> respList = aflCrashesInfoService.findCrashesNow(req);
return CommonResult.success(respList);
}
@PostMapping(path="/findAflCrashesInfoListByHistory") @PostMapping(path="/findAflCrashesInfoListByHistory")
public CommonResult<List<AflCrashesInfoResp>> findAflCrashesInfoListByHistory(@RequestBody @Valid AflManagerReq req){ public CommonResult<List<AflCrashesInfoResp>> findAflCrashesInfoListByHistory(@RequestBody @Valid AflManagerReq req){

View File

@ -26,4 +26,6 @@ public interface AflCrashesInfoService extends IService<AflCrashesInfo> {
AflCrashesResp findCrashesCount(@Valid AflManagerReq req); AflCrashesResp findCrashesCount(@Valid AflManagerReq req);
List<AflCrashesInfoResp> findCrashesNow(@Valid AflManagerReq req);
} }

View File

@ -271,4 +271,94 @@ public class AflCrashesInfoServiceImpl extends ServiceImpl<AflCrashesInfoDao, Af
} }
return aflCrashesResp; return aflCrashesResp;
} }
@Override
public List<AflCrashesInfoResp> findCrashesNow(AflManagerReq req) {
List<AflCrashesInfoResp> respList = new ArrayList<>(0);
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;
// String resourceId = "2";
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 {
// 步骤1使用自定义sql获取崩溃文件的创建时间
//查询创建时间
List<String> resultList = SftpUploadUtil.findCreateTimeByCommand(
resourceMachine.getMachineHost(),
Integer.parseInt(resourceMachine.getSshPort()),
resourceMachine.getUsername(),
resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
if (CollectionUtils.isEmpty(resultList)){
return respList;
}
//解析文件名和创建时间
for (String o : resultList) {
String[] lineParts = o.split("\\s+创建时间:\\s+");
if (lineParts.length < 2) {
System.err.println("无效格式: " + o);
break;
}
AflCrashesInfoResp aflCrashesInfoResp = new AflCrashesInfoResp();
String fileName = lineParts[0].substring(2).trim(); // 文件信息部分
String createTime = lineParts[1].trim(); // 创建时间
aflCrashesInfoResp.setCrashesName(fileName);
aflCrashesInfoResp.setCrashesCreateTime(createTime);
aflCrashesInfoResp.setFilePath(remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath + fileName);
respList.add(aflCrashesInfoResp);
}
// 步驟2.查询文件大小
List<String> fileResultList = SftpUploadUtil.findFileByteByCommand(
resourceMachine.getMachineHost(),
Integer.parseInt(resourceMachine.getSshPort()),
resourceMachine.getUsername(),
resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + crashesFilePath);
if (CollectionUtils.isEmpty(fileResultList)){
return null;
}
//解析文件名和文件大小
for (String o : fileResultList) {
// 按空白字符分割
String[] parts = o.trim().split("\\s+");
String fileName = parts[0]; // 文件名称
Integer fileLength = Integer.parseInt(parts[1]); // 文件大小
if (!CollectionUtils.isEmpty(respList)){
for (AflCrashesInfoResp aflCrashesInfoResp : respList) {
if (aflCrashesInfoResp.getCrashesName().equals(fileName)) {
aflCrashesInfoResp.setCrashesLength(fileLength);
}
}
}
}
return respList;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"crashes入库失败");
}
}
} }