refactor(接口定义): node的jar包去主服务下载

--story=1011108 --user=王孝刚 资源池加载插件直接从MinIO获取
https://www.tapd.cn/55049933/s/1331634
This commit is contained in:
wxg0103 2023-02-14 10:48:00 +08:00 committed by wxg0103
parent 4fa0d70196
commit f895d3d719
2 changed files with 35 additions and 7 deletions

View File

@ -18,8 +18,12 @@ import io.metersphere.dto.AttachmentBodyFile;
import io.metersphere.dto.JmeterRunRequestDTO;
import io.metersphere.dto.ProjectJarConfig;
import io.metersphere.environment.service.BaseEnvGroupProjectService;
import io.metersphere.metadata.service.FileCenter;
import io.metersphere.metadata.service.FileMetadataService;
import io.metersphere.metadata.vo.FileRequest;
import io.metersphere.metadata.vo.RemoteFileAttachInfo;
import io.metersphere.request.BodyFile;
import io.metersphere.utils.JsonUtils;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.vo.BooleanPool;
import jakarta.annotation.Resource;
@ -151,9 +155,8 @@ public class ApiJMeterFileService {
FileMetadataService fileMetadataService = CommonBeanFactory.getBean(FileMetadataService.class);
map.forEach((key, value) -> {
//历史数据
value.forEach(s -> {
//获取文件内容;
// 兼容历史数据
value.stream().filter(s -> s.isHasFile()).forEach(s -> {
//获取文件内容 兼容历史数据
byte[] bytes = fileMetadataService.getContent(s.getId());
files.put(StringUtils.join(
key,
@ -162,6 +165,31 @@ public class ApiJMeterFileService {
File.separator,
String.valueOf(s.getUpdateTime()), ".jar"), bytes);
});
// 获取文件服务器的数据
value.stream().filter(s -> !s.isHasFile()).forEach(s -> {
//获取文件内容;
try {
FileRequest fileRequest = new FileRequest();
if (StringUtils.isNotBlank(s.getAttachInfo())) {
fileRequest.setFileAttachInfo(JsonUtils.parseObject(s.getAttachInfo(), RemoteFileAttachInfo.class));
}
fileRequest.setProjectId(key);
fileRequest.setFileName(s.getName());
fileRequest.setStorage(s.getStorage());
LoggerUtil.info("开始下载服务器中的Jar包文件名" + s.getName());
byte[] gitFiles = FileCenter.getRepository(s.getStorage()).getFile(fileRequest);
files.put(StringUtils.join(
key,
File.separator,
s.getId(),
File.separator,
String.valueOf(s.getUpdateTime()), ".jar"), gitFiles);
} catch (Exception e) {
LoggerUtil.error(e.getMessage(), e);
LoggerUtil.error("Jar包下载失败不存在Git仓库中");
}
});
});
}
return listBytesToZip(files);

View File

@ -51,10 +51,10 @@ public class JarConfigUtils {
//资源id目录存在需要判断文件的时间戳与数据记录的时间戳是不是同一个 不是同一个的需要删除jar然后重新下载
List<String> jarFiles = getFileNames(StringUtils.join(localPath, File.separator, item, File.separator, projectJarConfig.getId()));
if (CollectionUtils.isNotEmpty(jarFiles)) {
jarFiles.forEach(jarfile -> {
jarFiles.forEach(jarFile -> {
long updateTime = projectJarConfig.getUpdateTime();
if (!StringUtils.equals(StringUtils.substringBefore(jarfile, ".jar"), String.valueOf(updateTime))) {
deleteFile(StringUtils.join(localPath, File.separator, item, File.separator, refId, File.separator, jarfile));
if (!StringUtils.equals(StringUtils.substringBefore(jarFile, ".jar"), String.valueOf(updateTime))) {
deleteFile(StringUtils.join(localPath, File.separator, item, File.separator, refId, File.separator, jarFile));
jarConfigs.add(projectJarConfig);
}
});
@ -90,7 +90,7 @@ public class JarConfigUtils {
File fa[] = f.listFiles();
for (int i = 0; i < fa.length; i++) {
File fs = fa[i];
if (fs.exists()) {
if (fs.exists() && !StringUtils.equals(fs.getName(), ".DS_Store")) {
fileNames.add(fs.getName());
}
}