Merge branch 'master' of http://1.14.125.6:3000/mianbin/ops-pro
This commit is contained in:
commit
6a23613f25
@ -1,10 +1,7 @@
|
|||||||
package cd.casic.ci.api;
|
package cd.casic.ci.api;
|
||||||
|
|
||||||
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.AflCrashesInfoResp;
|
import cd.casic.ci.process.dto.resp.aflManager.*;
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.AflInfoResp;
|
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.AflPlotInfoResp;
|
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.SeedsCountResp;
|
|
||||||
import cd.casic.ci.process.process.service.aflManager.AflCrashesInfoService;
|
import cd.casic.ci.process.process.service.aflManager.AflCrashesInfoService;
|
||||||
import cd.casic.ci.process.process.service.aflManager.AflInfoService;
|
import cd.casic.ci.process.process.service.aflManager.AflInfoService;
|
||||||
import cd.casic.ci.process.process.service.aflManager.AflPlotInfoService;
|
import cd.casic.ci.process.process.service.aflManager.AflPlotInfoService;
|
||||||
@ -132,4 +129,13 @@ public class AflManagerController {
|
|||||||
|
|
||||||
return CommonResult.success(respList);
|
return CommonResult.success(respList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findAflBaseInfoList")
|
||||||
|
public CommonResult<AflBaseInfoResp> findAflBaseInfoList(@RequestBody @Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
|
||||||
|
|
||||||
|
AflBaseInfoResp resp = aflInfoService.findAflBaseInfoList(req);
|
||||||
|
|
||||||
|
return CommonResult.success(resp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package cd.casic.ci.process.dto.resp.aflManager;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ReportResp
|
||||||
|
* @Author hopeli
|
||||||
|
* @Date 2025/5/10 10:53
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AflBaseInfoResp {
|
||||||
|
|
||||||
|
//创建时间
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
//执行时间(分钟数)
|
||||||
|
private Integer durationTime;
|
||||||
|
|
||||||
|
//测试用例数量
|
||||||
|
private Integer testCaseCount;
|
||||||
|
|
||||||
|
//镜像名称
|
||||||
|
private String dockerName;
|
||||||
|
|
||||||
|
//运行状态 1-未开始 2-运行中 3-已结束
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
//应用名称
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
}
|
@ -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.AflBaseInfoResp;
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.AflInfoResp;
|
import cd.casic.ci.process.dto.resp.aflManager.AflInfoResp;
|
||||||
import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
||||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||||
@ -25,4 +26,6 @@ public interface AflInfoService extends IService<AflInfo> {
|
|||||||
AflInfoResp findAflInfo(@Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException;
|
AflInfoResp findAflInfo(@Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException;
|
||||||
|
|
||||||
List<AflInfoResp> findPipelineList(@Valid AflManagerReq req);
|
List<AflInfoResp> findPipelineList(@Valid AflManagerReq req);
|
||||||
|
|
||||||
|
AflBaseInfoResp findAflBaseInfoList(@Valid AflManagerReq req) throws SftpUploadUtil.SftpUploadException;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
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.AflBaseInfoResp;
|
||||||
import cd.casic.ci.process.dto.resp.aflManager.AflInfoResp;
|
import cd.casic.ci.process.dto.resp.aflManager.AflInfoResp;
|
||||||
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.manager.RunContextManager;
|
import cd.casic.ci.process.engine.manager.RunContextManager;
|
||||||
|
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
||||||
import cd.casic.ci.process.process.converter.AflManagerConverter;
|
import cd.casic.ci.process.process.converter.AflManagerConverter;
|
||||||
import cd.casic.ci.process.process.dao.aflManager.AflInfoDao;
|
import cd.casic.ci.process.process.dao.aflManager.AflInfoDao;
|
||||||
import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
import cd.casic.ci.process.process.dataObject.aflManager.AflInfo;
|
||||||
@ -21,8 +24,11 @@ import jakarta.annotation.Resource;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -162,21 +168,69 @@ public class AflInfoServiceImpl extends ServiceImpl<AflInfoDao, AflInfo> impleme
|
|||||||
return AflManagerConverter.INSTANCE.toAflInfoRespList(aflInfos);
|
return AflManagerConverter.INSTANCE.toAflInfoRespList(aflInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
/**
|
public AflBaseInfoResp findAflBaseInfoList(AflManagerReq req) throws SftpUploadUtil.SftpUploadException {
|
||||||
* 获取远程文件的输入流并设值给aflInfo
|
AflBaseInfoResp resp = new AflBaseInfoResp();
|
||||||
*
|
BaseRunContext taskRunContext = runContextManager.getContext(req.getTaskId());
|
||||||
* @param machineInfo 机器信息
|
if (ObjectUtils.isEmpty(taskRunContext)){
|
||||||
* @param remoteFilePath 远程文件路径
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到task运行上下文");
|
||||||
* @return 文件输入流
|
|
||||||
*/
|
|
||||||
private AflInfo getFileStreamAndSetAflInfo(PipResourceMachine machineInfo, String remoteFilePath) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
return SftpUploadUtil.downloadFileSftpForInputStreamAndSetAflInfo(machineInfo.getMachineHost(), Integer.parseInt(machineInfo.getSshPort()), machineInfo.getUsername(), machineInfo.getPassword(),null, remoteFilePath);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取远程文件流失败: {}", e.getMessage());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
LocalDateTime startTime = taskRunContext.getStartTime();
|
||||||
|
LocalDateTime endTime = taskRunContext.getEndTime();
|
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(startTime) && ObjectUtils.isEmpty(endTime)){
|
||||||
|
resp.setStatus("1");
|
||||||
|
}else if (!ObjectUtils.isEmpty(startTime) && ObjectUtils.isEmpty(endTime)){
|
||||||
|
resp.setStatus("2");
|
||||||
|
resp.setCreateTime(startTime);
|
||||||
|
// 计算时间差(分钟)
|
||||||
|
Duration duration = Duration.between(startTime, LocalDateTime.now());
|
||||||
|
int minutesDifference = Math.toIntExact(Math.abs(duration.toMinutes()));
|
||||||
|
resp.setDurationTime(minutesDifference);
|
||||||
|
}else if (!ObjectUtils.isEmpty(startTime) && !ObjectUtils.isEmpty(endTime)){
|
||||||
|
resp.setStatus("3");
|
||||||
|
resp.setCreateTime(startTime);
|
||||||
|
// 计算时间差(分钟)
|
||||||
|
Duration duration = Duration.between(startTime, endTime);
|
||||||
|
int minutesDifference = Math.toIntExact(Math.abs(duration.toMinutes()));
|
||||||
|
resp.setDurationTime(minutesDifference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String dockerName = taskRunContext.getGlobalVariables().get(PipelineVariableConstant.IMAGE_NAME) instanceof String ? ((String) taskRunContext.getGlobalVariables().get(PipelineVariableConstant.IMAGE_NAME)) : null;
|
||||||
|
String applicationName = taskRunContext.getGlobalVariables().get(PipelineVariableConstant.EXECUTABLE_NAME_KEY) instanceof String ? ((String) taskRunContext.getGlobalVariables().get(PipelineVariableConstant.EXECUTABLE_NAME_KEY)) : null;
|
||||||
|
resp.setDockerName(dockerName);
|
||||||
|
resp.setApplicationName(applicationName);
|
||||||
|
|
||||||
|
BaseRunContext pipelineCunContext = runContextManager.getContext(req.getPipelineId());
|
||||||
|
if (ObjectUtils.isEmpty(pipelineCunContext)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"未找到运行上下文");
|
||||||
|
}
|
||||||
|
String resourceId = pipelineCunContext.getGlobalVariables().get(PipelineVariableConstant.AFL_RESOURCE_MANAGER_ID_KEY) instanceof String ? ((String) pipelineCunContext.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);
|
||||||
|
|
||||||
|
//找出seed文件夹下的所有测试样例文件,计算数量
|
||||||
|
List<String> files = SftpUploadUtil.listFilesInRemoteDirectory(
|
||||||
|
resourceMachine.getMachineHost(), Integer.parseInt(resourceMachine.getSshPort()), resourceMachine.getUsername(), resourceMachine.getPassword(), null, remoteFilePath + "PIP_" + req.getPipelineId() + "/SEED/");
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(files)){
|
||||||
|
resp.setTestCaseCount(files.size());
|
||||||
|
}else {
|
||||||
|
resp.setTestCaseCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -741,6 +741,11 @@ public class SftpUploadUtil {
|
|||||||
List<String> copiedFiles = new ArrayList<>();
|
List<String> copiedFiles = new ArrayList<>();
|
||||||
|
|
||||||
for (String sourceFilePath : sourceFilePaths) {
|
for (String sourceFilePath : sourceFilePaths) {
|
||||||
|
String chmodDir = sourceFilePath.substring(0, sourceFilePath.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
// 获取源文件名
|
// 获取源文件名
|
||||||
String sourceFileName = sourceFilePath.substring(sourceFilePath.lastIndexOf('/') + 1);
|
String sourceFileName = sourceFilePath.substring(sourceFilePath.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
@ -865,6 +870,11 @@ public class SftpUploadUtil {
|
|||||||
|
|
||||||
channelSftp = (ChannelSftp) channel;
|
channelSftp = (ChannelSftp) channel;
|
||||||
|
|
||||||
|
String chmodDir = remoteDir.substring(0, remoteDir.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
// 切换到目标目录
|
// 切换到目标目录
|
||||||
channelSftp.cd(remoteDir);
|
channelSftp.cd(remoteDir);
|
||||||
|
|
||||||
@ -966,6 +976,11 @@ public class SftpUploadUtil {
|
|||||||
|
|
||||||
channelSftp = (ChannelSftp) channel;
|
channelSftp = (ChannelSftp) channel;
|
||||||
|
|
||||||
|
String chmodDir = remoteDir.substring(0, remoteDir.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
// 切换到目标目录
|
// 切换到目标目录
|
||||||
channelSftp.cd(remoteDir);
|
channelSftp.cd(remoteDir);
|
||||||
|
|
||||||
@ -1069,6 +1084,11 @@ public class SftpUploadUtil {
|
|||||||
session.connect();
|
session.connect();
|
||||||
System.out.println("SFTP Session 连接成功.");
|
System.out.println("SFTP Session 连接成功.");
|
||||||
|
|
||||||
|
String chmodDir = remoteDir.substring(0, remoteDir.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
// 开始执行 find 命令
|
// 开始执行 find 命令
|
||||||
ChannelExec execChannel = (ChannelExec) session.openChannel("exec");
|
ChannelExec execChannel = (ChannelExec) session.openChannel("exec");
|
||||||
|
|
||||||
@ -1196,6 +1216,11 @@ public class SftpUploadUtil {
|
|||||||
|
|
||||||
// 遍历远程文件路径并下载
|
// 遍历远程文件路径并下载
|
||||||
for (String remoteFile : remoteFilePaths) {
|
for (String remoteFile : remoteFilePaths) {
|
||||||
|
String chmodDir = remoteFile.substring(0, remoteFile.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
String fileName = new File(remoteFile).getName();
|
String fileName = new File(remoteFile).getName();
|
||||||
String localFilePath = localDir + fileName;
|
String localFilePath = localDir + fileName;
|
||||||
|
|
||||||
@ -1318,6 +1343,10 @@ public class SftpUploadUtil {
|
|||||||
System.out.println("SFTP Channel 打开成功.");
|
System.out.println("SFTP Channel 打开成功.");
|
||||||
|
|
||||||
channelSftp = (ChannelSftp) channel;
|
channelSftp = (ChannelSftp) channel;
|
||||||
|
String chmodDir = remoteFilePath.substring(0, remoteFilePath.indexOf("default"));
|
||||||
|
log.info("分配权限路径,{}",chmodDir);
|
||||||
|
// 切换目录并列出内容用于调试
|
||||||
|
sudoChmodORwx(session,chmodDir,password);
|
||||||
|
|
||||||
String remoteDir = remoteFilePath.substring(0, remoteFilePath.lastIndexOf('/'));
|
String remoteDir = remoteFilePath.substring(0, remoteFilePath.lastIndexOf('/'));
|
||||||
String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf('/') + 1);
|
String fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf('/') + 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user