接口优化。以及 AFL相关work修改
This commit is contained in:
parent
21b2319093
commit
22ec4646e8
@ -138,6 +138,8 @@ public interface AdminUserService {
|
|||||||
*/
|
*/
|
||||||
AdminUserDO getUser(Long id);
|
AdminUserDO getUser(Long id);
|
||||||
|
|
||||||
|
public List<AdminUserDO> getUserListByIds(Collection<Long> idList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得指定部门的用户数组
|
* 获得指定部门的用户数组
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,6 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cd.casic.framework.commons.enums.CommonStatusEnum;
|
import cd.casic.framework.commons.enums.CommonStatusEnum;
|
||||||
import cd.casic.framework.commons.exception.ServiceException;
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
import cd.casic.framework.commons.util.collection.CollectionUtils;
|
|
||||||
import cd.casic.framework.commons.util.object.BeanUtils;
|
import cd.casic.framework.commons.util.object.BeanUtils;
|
||||||
import cd.casic.framework.commons.util.validation.ValidationUtils;
|
import cd.casic.framework.commons.util.validation.ValidationUtils;
|
||||||
|
|
||||||
@ -43,10 +42,13 @@ import org.springframework.context.annotation.Lazy;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
|
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cd.casic.framework.commons.util.collection.CollectionUtils.*;
|
import static cd.casic.framework.commons.util.collection.CollectionUtils.*;
|
||||||
@ -286,6 +288,13 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|||||||
public AdminUserDO getUser(Long id) {
|
public AdminUserDO getUser(Long id) {
|
||||||
return userMapper.selectById(id);
|
return userMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public List<AdminUserDO> getUserListByIds(Collection<Long> idList){
|
||||||
|
if (CollectionUtils.isEmpty(idList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return userMapper.selectByIds(idList);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds) {
|
public List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds) {
|
||||||
@ -322,7 +331,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|||||||
}
|
}
|
||||||
// 获得岗位信息
|
// 获得岗位信息
|
||||||
List<AdminUserDO> users = userMapper.selectBatchIds(ids);
|
List<AdminUserDO> users = userMapper.selectBatchIds(ids);
|
||||||
Map<Long, AdminUserDO> userMap = CollectionUtils.convertMap(users, AdminUserDO::getId);
|
Map<Long, AdminUserDO> userMap = users.stream().collect(Collectors.toMap(AdminUserDO::getId,Function.identity()));
|
||||||
// 校验
|
// 校验
|
||||||
ids.forEach(id -> {
|
ids.forEach(id -> {
|
||||||
AdminUserDO user = userMap.get(id);
|
AdminUserDO user = userMap.get(id);
|
||||||
@ -368,7 +377,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|||||||
// 校验邮箱唯一
|
// 校验邮箱唯一
|
||||||
validateEmailUnique(id, email);
|
validateEmailUnique(id, email);
|
||||||
// 校验部门处于开启状态
|
// 校验部门处于开启状态
|
||||||
deptService.validateDeptList(CollectionUtils.singleton(deptId));
|
deptService.validateDeptList(Collections.singleton(deptId));
|
||||||
// 校验岗位处于开启状态
|
// 校验岗位处于开启状态
|
||||||
postService.validatePostList(postIds);
|
postService.validatePostList(postIds);
|
||||||
return user;
|
return user;
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package cd.casic.ci.process.dto.resp.docker;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DockerImageNameResp {
|
||||||
|
private String id;
|
||||||
|
private String value;
|
||||||
|
}
|
@ -15,6 +15,7 @@ import cd.casic.ci.process.process.dataObject.target.TargetVersion;
|
|||||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||||
import cd.casic.ci.process.process.service.target.TargetVersionService;
|
import cd.casic.ci.process.process.service.target.TargetVersionService;
|
||||||
|
import cd.casic.ci.process.util.CryptogramUtil;
|
||||||
import cd.casic.ci.process.util.SftpUploadUtil;
|
import cd.casic.ci.process.util.SftpUploadUtil;
|
||||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
||||||
@ -62,6 +63,8 @@ public class AFLSlotCompileWorker extends DockerWorker {
|
|||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(task.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(task.getPipelineId()).getContextDef();
|
||||||
// 获取目标文件
|
// 获取目标文件
|
||||||
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
||||||
|
String fileName = targetVersion.getFileName();
|
||||||
|
append(context,"读取到当前文件名称:"+fileName);
|
||||||
String filePath = targetVersion.getFilePath();
|
String filePath = targetVersion.getFilePath();
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (!file.exists() || !file.canRead()) {
|
if (!file.exists() || !file.canRead()) {
|
||||||
@ -74,25 +77,49 @@ public class AFLSlotCompileWorker extends DockerWorker {
|
|||||||
String realPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX+File.separator+ workDir;
|
String realPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX+File.separator+ workDir;
|
||||||
// 上传目标文件 到指定资源服务器
|
// 上传目标文件 到指定资源服务器
|
||||||
try {
|
try {
|
||||||
|
append(context,"AFL编译,上传文件路径:"+realPath);
|
||||||
SftpUploadUtil.uploadFileViaSftp(
|
SftpUploadUtil.uploadFileViaSftp(
|
||||||
machineInfo.getMachineHost()
|
machineInfo.getMachineHost()
|
||||||
,Integer.valueOf(machineInfo.getSshPort()),machineInfo.getUsername(),machineInfo.getPassword(),"",filePath,realPath,file.getName());
|
,Integer.valueOf(machineInfo.getSshPort()),machineInfo.getUsername(), CryptogramUtil.doDecrypt(machineInfo.getPassword()),"",filePath,realPath,file.getName());
|
||||||
} catch (SftpUploadUtil.SftpUploadException e) {
|
} catch (SftpUploadUtil.SftpUploadException e) {
|
||||||
append(context,"上传文件失败,请确认资源信息是否有误:"+JSON.toJSONString(machineInfo));
|
append(context,"上传文件失败,请确认资源信息是否有误:"+JSON.toJSONString(machineInfo));
|
||||||
|
log.error("上传文件报错",e);
|
||||||
toBadEnding();
|
toBadEnding();
|
||||||
}
|
}
|
||||||
// 执行预设命令 ,进入目录
|
// 执行预设命令 ,进入目录
|
||||||
String allCommand = "docker run -v "+ PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX +":"+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+" -it "+imageName+" bash\n" +
|
String allCommand = "docker run -v "+ PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX +":"+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+" -it "+imageName+" bash\n" +
|
||||||
"cd "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+"\n"+// 进入到容器中的卷挂载目录
|
"cd "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+"\n"+// 进入到容器中的卷挂载目录
|
||||||
"mkdir -p "+workDir+"\n"+
|
"mkdir -p "+workDir+"\n"+
|
||||||
"cd "+workDir+"\n";
|
"cd "+workDir+"\n"+handleZipFile(fileName);
|
||||||
Object commandScriptObj = taskProperties.get(AFLSlotCompileConstant.COMMAND_SCRIPT);
|
Object commandScriptObj = taskProperties.get(AFLSlotCompileConstant.COMMAND_SCRIPT);
|
||||||
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
||||||
allCommand += commandScript+"\nll -s";
|
allCommand += commandScript+"\n";
|
||||||
log.info("AFL插装编译容器内执行的命令:{}",allCommand);
|
log.info("AFL插装编译容器内执行的命令:{}",allCommand);
|
||||||
dockerRun(allCommand,dockerInfo,context);
|
dockerRun(allCommand,dockerInfo,context);
|
||||||
// 更新全局变量
|
// 更新全局变量
|
||||||
// /test目录下当前流水线工作目录
|
// /test目录下当前流水线工作目录
|
||||||
globalVariables.put(PipelineGlobalVariableConstant.AFL_DOCKER_WORK_DIR_KEY,workDir);
|
globalVariables.put(PipelineGlobalVariableConstant.AFL_DOCKER_WORK_DIR_KEY,workDir);
|
||||||
}
|
}
|
||||||
|
private String handleZipFile(String fileName){
|
||||||
|
if (StringUtils.isEmpty(fileName)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
int i = fileName.lastIndexOf(".");
|
||||||
|
if (i==-1||i>=fileName.length()-1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String prefix = fileName.substring(0, i);
|
||||||
|
String suffix = fileName.substring(i + 1);
|
||||||
|
if ("zip".equals(suffix)) {
|
||||||
|
String cmd ="unzip -o "+fileName+"\n" +
|
||||||
|
"cd "+prefix;
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
if ("tar".equals(suffix)) {
|
||||||
|
String cmd ="tar -zxvf "+fileName+"\n" +
|
||||||
|
"cd "+prefix;
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,11 @@ import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
|||||||
import cd.casic.ci.process.engine.constant.PipelineGlobalVariableConstant;
|
import cd.casic.ci.process.engine.constant.PipelineGlobalVariableConstant;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
import cd.casic.ci.process.engine.worker.base.DockerWorker;
|
import cd.casic.ci.process.engine.worker.base.DockerWorker;
|
||||||
|
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
|
||||||
|
import cd.casic.ci.process.process.dataObject.target.TargetVersion;
|
||||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.service.target.TargetVersionService;
|
||||||
|
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.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@ -19,8 +23,8 @@ import java.util.Map;
|
|||||||
@WorkAtom(taskType = "AFL")
|
@WorkAtom(taskType = "AFL")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AFLWorker extends DockerWorker {
|
public class AFLWorker extends DockerWorker {
|
||||||
|
@Resource
|
||||||
|
private TargetVersionService targetVersionService;
|
||||||
@Override
|
@Override
|
||||||
public void execute(TaskRunContext context) {
|
public void execute(TaskRunContext context) {
|
||||||
int statusCode = -1;
|
int statusCode = -1;
|
||||||
@ -54,13 +58,18 @@ public class AFLWorker extends DockerWorker {
|
|||||||
append(context,"当前机器不支持docker");
|
append(context,"当前机器不支持docker");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String output = workDir+PipelineGlobalVariableConstant.AFL_DOCKER_OUTPUT;
|
String output = workDir + PipelineGlobalVariableConstant.AFL_DOCKER_OUTPUT;
|
||||||
//
|
//
|
||||||
String volumeWorkDirPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX;
|
String volumeWorkDirPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX;
|
||||||
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
|
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
||||||
|
String fileName = targetVersion.getFileName();
|
||||||
|
|
||||||
|
|
||||||
String commandScript = "docker run -v "+volumeWorkDirPath+":/test -it "+imageName+" bash\n" +
|
String commandScript = "docker run -v "+volumeWorkDirPath+":/test -it "+imageName+" bash\n" +
|
||||||
"cd /test\n" +
|
"cd " +PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+ getSourceName(fileName) +
|
||||||
"mkdir -p"+output+"\n" +
|
"mkdir -p "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+File.separator+output+"\n" +
|
||||||
"afl-fuzz -i "+seedPath+" -o "+output+" "+workDir+ File.separator+commandEnd;
|
"afl-fuzz -i "+seedPath+" -o "+output+" "+commandEnd;
|
||||||
try {
|
try {
|
||||||
//将节点的配置信息反编译成对象
|
//将节点的配置信息反编译成对象
|
||||||
log.info("AFL模糊测试执行脚本:{}",commandScript);
|
log.info("AFL模糊测试执行脚本:{}",commandScript);
|
||||||
@ -75,4 +84,11 @@ public class AFLWorker extends DockerWorker {
|
|||||||
localVariables.put(DIYImageExecuteCommandConstant.STATUS_CODE, statusCode);
|
localVariables.put(DIYImageExecuteCommandConstant.STATUS_CODE, statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public String getSourceName(String fileName){
|
||||||
|
int dotIndex = fileName.lastIndexOf(".");
|
||||||
|
if (dotIndex!=-1) {
|
||||||
|
return "cd "+fileName.substring(0, dotIndex)+"\n";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
String seedPath= workDir+File.separator+PipelineGlobalVariableConstant.AFL_DOCKER_SEED;
|
String seedPath= workDir+File.separator+PipelineGlobalVariableConstant.AFL_DOCKER_SEED;
|
||||||
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
||||||
Object caseType = taskProperties.get(TestCaseGenerationConstant.CASE_TYPE_KEY);
|
Object caseType = taskProperties.get(TestCaseGenerationConstant.CASE_TYPE_KEY);
|
||||||
String binaryName = taskProperties.get("binaryName").toString();
|
String binaryName = taskProperties.get("binaryName") instanceof String ? ((String) taskProperties.get("binaryName")) : null;
|
||||||
String managerId = taskProperties.get("managerId") instanceof String ? ((String) taskProperties.get("managerId")) : null;
|
String managerId = taskProperties.get("managerId") instanceof String ? ((String) taskProperties.get("managerId")) : null;
|
||||||
ResourceFindResp resourceById = resourceManagerService.findResourceById(managerId);
|
ResourceFindResp resourceById = resourceManagerService.findResourceById(managerId);
|
||||||
String machineId = resourceById.getMachineId();
|
String machineId = resourceById.getMachineId();
|
||||||
@ -73,17 +73,19 @@ public class TestCaseGenerationWorker extends DockerWorker {
|
|||||||
toBadEnding();
|
toBadEnding();
|
||||||
}
|
}
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
String seedTarget = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX+workDir+File.separator+seedPath;
|
String seedTarget = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX+File.separator+seedPath;
|
||||||
// 将文件上传到服务器的 目录底下
|
// 将文件上传到服务器的 目录底下
|
||||||
log.info("测试用例选用上传模式,种子文件路径:{},种子上传路径:{}",filePath,seedTarget);
|
log.info("测试用例选用上传模式,种子文件路径:{},种子上传路径:{}",filePath,seedTarget);
|
||||||
|
append(context,"测试用例选用上传模式,种子文件路径:"+filePath+",种子上传路径:"+seedPath);
|
||||||
try {
|
try {
|
||||||
SftpUploadUtil.uploadFileViaSftp(
|
SftpUploadUtil.uploadFileViaSftp(
|
||||||
machineInfo.getMachineHost()
|
machineInfo.getMachineHost()
|
||||||
,Integer.valueOf(machineInfo.getSshPort()),machineInfo.getUsername(),machineInfo.getPassword(),"",filePath,seedTarget,file.getName());
|
,Integer.valueOf(machineInfo.getSshPort()),machineInfo.getUsername(),CryptogramUtil.doDecrypt(machineInfo.getPassword()),"",filePath,seedTarget,file.getName());
|
||||||
} catch (SftpUploadUtil.SftpUploadException e) {
|
} catch (SftpUploadUtil.SftpUploadException e) {
|
||||||
append(context,"seed文件上传失败");
|
append(context,"seed文件上传失败");
|
||||||
log.error("seed文件上传失败",e);
|
log.error("seed文件上传失败",e);
|
||||||
}
|
}
|
||||||
|
append(context,"上传文件成功!");
|
||||||
}
|
}
|
||||||
globalVariables.put(PipelineGlobalVariableConstant.AFL_DOCKER_SEED_PATH_KEY,seedPath);
|
globalVariables.put(PipelineGlobalVariableConstant.AFL_DOCKER_SEED_PATH_KEY,seedPath);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import org.assertj.core.util.Lists;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -48,16 +49,27 @@ public class DockerServiceImpl implements DockerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(uri).build();
|
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(uri).build();
|
||||||
DockerClient build = DockerClientBuilder.getInstance().withDockerHttpClient(httpClient).build();
|
DockerClient build = null;
|
||||||
List<Image> exec = build.listImagesCmd().exec();
|
try{
|
||||||
List<String> res = new LinkedList<>();
|
build = DockerClientBuilder.getInstance().withDockerHttpClient(httpClient).build();
|
||||||
for (Image image : exec) {
|
List<Image> exec = build.listImagesCmd().exec();
|
||||||
String[] repoTags = image.getRepoTags();
|
List<String> res = new LinkedList<>();
|
||||||
if (image.getRepoTags() != null && repoTags.length > 0) {
|
for (Image image : exec) {
|
||||||
res.add(repoTags[0]);
|
String[] repoTags = image.getRepoTags();
|
||||||
|
if (image.getRepoTags() != null && repoTags.length > 0) {
|
||||||
|
res.add(repoTags[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} finally {
|
||||||
|
if (build!=null) {
|
||||||
|
try {
|
||||||
|
build.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,15 +84,26 @@ public class DockerServiceImpl implements DockerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(uri).build();
|
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder().dockerHost(uri).build();
|
||||||
DockerClient build = DockerClientBuilder.getInstance().withDockerHttpClient(httpClient).build();
|
DockerClient build = null;
|
||||||
List<Image> exec = build.listImagesCmd().exec();
|
try{
|
||||||
List<String> res = new LinkedList<>();
|
build = DockerClientBuilder.getInstance().withDockerHttpClient(httpClient).build();
|
||||||
for (Image image : exec) {
|
List<Image> exec = build.listImagesCmd().exec();
|
||||||
String[] repoTags = image.getRepoTags();
|
List<String> res = new LinkedList<>();
|
||||||
if (image.getRepoTags() != null && repoTags.length > 0) {
|
for (Image image : exec) {
|
||||||
res.add(repoTags[0]);
|
String[] repoTags = image.getRepoTags();
|
||||||
|
if (image.getRepoTags() != null && repoTags.length > 0) {
|
||||||
|
res.add(repoTags[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} finally {
|
||||||
|
if (build!=null) {
|
||||||
|
try {
|
||||||
|
build.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ import org.springframework.util.ObjectUtils;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author HopeLi
|
* @author HopeLi
|
||||||
@ -231,7 +233,8 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
|||||||
//对流水线进行流水线信息赋值
|
//对流水线进行流水线信息赋值
|
||||||
respList.forEach(this::setStageAndTask);
|
respList.forEach(this::setStageAndTask);
|
||||||
//对用户姓名进行赋值
|
//对用户姓名进行赋值
|
||||||
respList.forEach(this::setUserName);
|
// respList.forEach(this::setUserName);
|
||||||
|
setUserName(respList);
|
||||||
return respList;
|
return respList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,32 +319,49 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineDao, PipPipeline> i
|
|||||||
List<PipelineFindResp> respList = PipelineConverter.INSTANCE.toRespList(pipPipelinePage.getRecords());
|
List<PipelineFindResp> respList = PipelineConverter.INSTANCE.toRespList(pipPipelinePage.getRecords());
|
||||||
|
|
||||||
//对流水线进行流水线信息赋值
|
//对流水线进行流水线信息赋值
|
||||||
respList.forEach(this::setStageAndTask);
|
// respList.forEach(this::setStageAndTask);
|
||||||
respList.forEach(this::setUserName);
|
// respList.forEach(this::setUserName);
|
||||||
|
setUserName(respList);
|
||||||
PageResult<PipelineFindResp> pageResult = new PageResult<>(respList,pipPipelinePage.getTotal(),pipPipelinePage.getCurrent(),pipPipelinePage.getSize());
|
PageResult<PipelineFindResp> pageResult = new PageResult<>(respList,pipPipelinePage.getTotal(),pipPipelinePage.getCurrent(),pipPipelinePage.getSize());
|
||||||
return pageResult;
|
return pageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUserName(PipelineFindResp pipelineFindResp) {
|
private void setUserName(List<PipelineFindResp> pipelineFindRespList) {
|
||||||
if (!StringUtils.isEmpty(pipelineFindResp.getCreator())){
|
Set<Long> userIdSet = new HashSet<>(pipelineFindRespList.size()*3);
|
||||||
AdminUserDO user = adminUserService.getUser(Long.valueOf(pipelineFindResp.getCreator()));
|
for (PipelineFindResp pipelineFindResp : pipelineFindRespList) {
|
||||||
if (!ObjectUtils.isEmpty(user)){
|
if (!StringUtils.isEmpty(pipelineFindResp.getCreator())){
|
||||||
pipelineFindResp.setCreatorName(user.getUsername());
|
userIdSet.add(Long.valueOf(pipelineFindResp.getCreator()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(pipelineFindResp.getUpdater())){
|
||||||
|
userIdSet.add(Long.valueOf(pipelineFindResp.getUpdater()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(pipelineFindResp.getExecuteUserId())){
|
||||||
|
userIdSet.add(Long.valueOf(pipelineFindResp.getExecuteUserId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Map<Long, AdminUserDO> userIdMap = adminUserService.getUserListByIds(userIdSet).stream().collect(Collectors.toMap(AdminUserDO::getId, Function.identity()));
|
||||||
if (!StringUtils.isEmpty(pipelineFindResp.getUpdater())){
|
for (PipelineFindResp pipelineFindResp : pipelineFindRespList) {
|
||||||
AdminUserDO user = adminUserService.getUser(Long.valueOf(pipelineFindResp.getUpdater()));
|
if (!StringUtils.isEmpty(pipelineFindResp.getCreator())){
|
||||||
if (!ObjectUtils.isEmpty(user)){
|
AdminUserDO user = userIdMap.get(Long.valueOf(pipelineFindResp.getCreator()));
|
||||||
pipelineFindResp.setUpdaterName(user.getUsername());
|
if (!ObjectUtils.isEmpty(user)){
|
||||||
|
pipelineFindResp.setCreatorName(user.getUsername());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(pipelineFindResp.getExecuteUserId())){
|
if (!StringUtils.isEmpty(pipelineFindResp.getUpdater())){
|
||||||
AdminUserDO user = adminUserService.getUser(Long.valueOf(pipelineFindResp.getExecuteUserId()));
|
AdminUserDO user = userIdMap.get(Long.valueOf(pipelineFindResp.getUpdater()));
|
||||||
if (!ObjectUtils.isEmpty(user)){
|
if (!ObjectUtils.isEmpty(user)){
|
||||||
pipelineFindResp.setExecuteUserName(user.getUsername());
|
pipelineFindResp.setUpdaterName(user.getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(pipelineFindResp.getExecuteUserId())){
|
||||||
|
AdminUserDO user = userIdMap.get(Long.valueOf(pipelineFindResp.getExecuteUserId()));
|
||||||
|
if (!ObjectUtils.isEmpty(user)){
|
||||||
|
pipelineFindResp.setExecuteUserName(user.getUsername());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user