0619 ljc work模块修改
This commit is contained in:
parent
b712c13170
commit
6c2139b0f3
@ -4,6 +4,7 @@ package cd.casic.ci.api;
|
|||||||
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
||||||
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
import cd.casic.ci.process.process.service.resource.ResourceManagerService;
|
||||||
import cd.casic.framework.commons.pojo.CommonResult;
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
@ -84,4 +85,23 @@ public class ResourceManagerController {
|
|||||||
return CommonResult.success(resp);
|
return CommonResult.success(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findResourceListByType")
|
||||||
|
public CommonResult<TaskResourceFindResp> findResourceListByType(@RequestBody @Valid ResourceQueryReq req){
|
||||||
|
|
||||||
|
TaskResourceFindResp ResourceFindResp = resourceManagerService.findResourceListByType(req);
|
||||||
|
|
||||||
|
return CommonResult.success(ResourceFindResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findResourceListForObjectByType")
|
||||||
|
public CommonResult<List> findResourceListForObjectByType(@RequestBody @Valid ResourceQueryReq req){
|
||||||
|
|
||||||
|
List resp = resourceManagerService.findResourceListForObjectByType(req);
|
||||||
|
|
||||||
|
return CommonResult.success(resp);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
package cd.casic.ci.api;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.taskResource.TaskResourceQueryReq;
|
|
||||||
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
|
||||||
import cd.casic.ci.process.process.service.taskResource.TaskResourceManagerService;
|
|
||||||
import cd.casic.framework.commons.pojo.CommonResult;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName ResourceController
|
|
||||||
* @Author hopeli
|
|
||||||
* @Date 2025/5/10 10:57
|
|
||||||
* @Version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
//@RestController
|
|
||||||
@RequestMapping("/taskResource")
|
|
||||||
public class TaskResourceManagerController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private TaskResourceManagerService resourceManagerService;
|
|
||||||
|
|
||||||
@PostMapping(path="/findResourceList")
|
|
||||||
public CommonResult<TaskResourceFindResp> findResourceList(@RequestBody @Valid TaskResourceQueryReq req){
|
|
||||||
|
|
||||||
TaskResourceFindResp ResourceFindResp = resourceManagerService.findResourceList(req);
|
|
||||||
|
|
||||||
return CommonResult.success(ResourceFindResp);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -14,6 +14,9 @@ public class ResourceQueryReq extends PageParam {
|
|||||||
|
|
||||||
private List<String> idList;
|
private List<String> idList;
|
||||||
|
|
||||||
|
//资源类型
|
||||||
|
private String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* docker镜像服务器信息id
|
* docker镜像服务器信息id
|
||||||
*/
|
*/
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
package cd.casic.ci.process.dto.req.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.framework.commons.pojo.PageParam;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class TaskResourceQueryReq extends PageParam {
|
|
||||||
/**
|
|
||||||
* 主键id
|
|
||||||
*/
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
private List<String> idList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源类型
|
|
||||||
*/
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源名称
|
|
||||||
*/
|
|
||||||
private String resourceName;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建人用户id
|
|
||||||
*/
|
|
||||||
private String creator;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package cd.casic.ci.process.dto.req.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceCloud;
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceK8S;
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
|
||||||
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class TaskResourceReq {
|
|
||||||
private String id;
|
|
||||||
/**
|
|
||||||
* docker镜像服务器信息id
|
|
||||||
*/
|
|
||||||
private String dockerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* k8s服务器信息id
|
|
||||||
*/
|
|
||||||
private String k8sId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器服务器信息id
|
|
||||||
*/
|
|
||||||
private String machineId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 弹性云服务器信息id
|
|
||||||
*/
|
|
||||||
private String cloudId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源名称
|
|
||||||
*/
|
|
||||||
private String resourceName;
|
|
||||||
|
|
||||||
private PipResourceMachine resourceMachine;
|
|
||||||
|
|
||||||
private DockerEndpointDo dockerEndpoint;
|
|
||||||
|
|
||||||
private PipResourceK8S pipResourceK8S;
|
|
||||||
|
|
||||||
private PipResourceCloud pipResourceCloud;
|
|
||||||
}
|
|
@ -1,21 +1,21 @@
|
|||||||
package cd.casic.ci.process.dto.resp.taskResource;
|
package cd.casic.ci.process.dto.resp.taskResource;
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceCloud;
|
import cd.casic.ci.process.process.dataObject.resource.PipResourceCloud;
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceDockerEndpoint;
|
import cd.casic.ci.process.process.dataObject.resource.PipResourceK8S;
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceK8S;
|
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceMachine;
|
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class TaskResourceFindResp {
|
public class TaskResourceFindResp {
|
||||||
private List<ResourceMachine> resourceMachineList;
|
private List<PipResourceMachine> resourceMachineList;
|
||||||
|
|
||||||
private List<ResourceDockerEndpoint> dockerEndpointList;
|
private List<DockerEndpointDo> dockerEndpointList;
|
||||||
|
|
||||||
private List<ResourceK8S> resourceK8SList;
|
private List<PipResourceK8S> resourceK8SList;
|
||||||
|
|
||||||
private List<ResourceCloud> resourceCloudList;
|
private List<PipResourceCloud> resourceCloudList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
package cd.casic.ci.process.dto.resp.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceK8S;
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipelineDockerEndpoint;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class TaskResourceResp {
|
|
||||||
/**
|
|
||||||
* 主键id
|
|
||||||
*/
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* docker镜像服务器信息id
|
|
||||||
*/
|
|
||||||
private String dockerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* k8s服务器信息id
|
|
||||||
*/
|
|
||||||
private String k8sId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器服务器信息id
|
|
||||||
*/
|
|
||||||
private String machineId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 弹性云服务器信息id
|
|
||||||
*/
|
|
||||||
private String cloudId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源名称
|
|
||||||
*/
|
|
||||||
private String resourceName;
|
|
||||||
|
|
||||||
//创建人id
|
|
||||||
private String creator;
|
|
||||||
|
|
||||||
//创建人姓名
|
|
||||||
private String creatorName;
|
|
||||||
|
|
||||||
//最后修改人id
|
|
||||||
private String updater;
|
|
||||||
|
|
||||||
//最后修改人姓名
|
|
||||||
private String updaterName;
|
|
||||||
|
|
||||||
private String remark;
|
|
||||||
|
|
||||||
private PipResourceMachine resourceMachine;
|
|
||||||
|
|
||||||
private PipelineDockerEndpoint dockerEndpoint;
|
|
||||||
|
|
||||||
private PipResourceK8S pipResourceK8S;
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +1,16 @@
|
|||||||
package cd.casic.ci.process.engine.worker;
|
package cd.casic.ci.process.engine.worker;
|
||||||
|
|
||||||
import cd.casic.ci.process.common.WorkAtom;
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.engine.constant.AFLConstant;
|
import cd.casic.ci.process.engine.constant.AFLConstant;
|
||||||
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
||||||
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.task.PipTask;
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
|
||||||
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 java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -30,15 +30,23 @@ public class AFLWorker extends DockerWorker {
|
|||||||
// Object machineIdObj = taskProperties.get(DIYImageExecuteCommandConstant.MACHINE_ID);
|
// Object machineIdObj = taskProperties.get(DIYImageExecuteCommandConstant.MACHINE_ID);
|
||||||
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
||||||
|
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
// PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
String resourceId = pipeline.getResourceId();
|
// String resourceId = pipeline.getResourceId();
|
||||||
if (StringUtils.isEmpty(commandScript)||StringUtils.isEmpty(resourceId)) {
|
|
||||||
|
//从taskProperties中获取资源id
|
||||||
|
String resourceType = taskProperties.get("resourceType").toString();
|
||||||
|
String resourceId = taskProperties.get("resourceId").toString();
|
||||||
|
if (StringUtils.isEmpty(commandScript) || StringUtils.isEmpty(resourceId) || StringUtils.isEmpty(resourceType)) {
|
||||||
// 缺少参数
|
// 缺少参数
|
||||||
toBadEnding();
|
toBadEnding();
|
||||||
}
|
}
|
||||||
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
// ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
||||||
DockerEndpointDo dockerEndpoint = resourceById.getDockerEndpoint();
|
// DockerEndpointDo dockerEndpoint = resourceById.getDockerEndpoint();
|
||||||
if (dockerEndpoint==null) {
|
ResourceQueryReq req = new ResourceQueryReq();
|
||||||
|
req.setId(resourceId);
|
||||||
|
req.setType(resourceType);
|
||||||
|
TaskResourceFindResp resourceListByType = getResourceManagerService().findResourceListByType(req);
|
||||||
|
if (CollectionUtils.isEmpty(resourceListByType.getDockerEndpointList())) {
|
||||||
append(context,"当前机器不支持docker");
|
append(context,"当前机器不支持docker");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -52,7 +60,7 @@ public class AFLWorker extends DockerWorker {
|
|||||||
// MachineInfo machineInfoDO = this.getMachineInfoService().getById(machineId);
|
// MachineInfo machineInfoDO = this.getMachineInfoService().getById(machineId);
|
||||||
// 获取docker 暂时先写固定值
|
// 获取docker 暂时先写固定值
|
||||||
// TODO dockerEndpoint替换为查询
|
// TODO dockerEndpoint替换为查询
|
||||||
dockerRun(commandScript,dockerEndpoint,context);
|
dockerRun(commandScript,resourceListByType.getDockerEndpointList().get(0),context);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
|
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
|
||||||
log.error("执行ssh失败:", e);
|
log.error("执行ssh失败:", e);
|
||||||
|
@ -2,7 +2,8 @@ package cd.casic.ci.process.engine.worker;
|
|||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.common.WorkAtom;
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
import cd.casic.ci.process.engine.worker.base.SshWorker;
|
import cd.casic.ci.process.engine.worker.base.SshWorker;
|
||||||
@ -18,6 +19,7 @@ import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
|||||||
import jakarta.annotation.Resource;
|
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 java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -59,11 +61,28 @@ public class CustomCompilerWorker extends SshWorker {
|
|||||||
|
|
||||||
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
||||||
|
|
||||||
//获取机器
|
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
String resourceId = pipeline.getResourceId();
|
// String resourceId = pipeline.getResourceId();
|
||||||
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
// ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
||||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
// PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||||
|
|
||||||
|
//获取机器
|
||||||
|
String resourceType = taskProperties.get("resourceType").toString();
|
||||||
|
String resourceId = taskProperties.get("resourceId").toString();
|
||||||
|
if (StringUtils.isEmpty(resourceId) || StringUtils.isEmpty(resourceType)) {
|
||||||
|
// 缺少参数
|
||||||
|
toBadEnding();
|
||||||
|
}
|
||||||
|
ResourceQueryReq req = new ResourceQueryReq();
|
||||||
|
req.setId(resourceId);
|
||||||
|
req.setType(resourceType);
|
||||||
|
TaskResourceFindResp resourceListByType = getResourceManagerService().findResourceListByType(req);
|
||||||
|
if (CollectionUtils.isEmpty(resourceListByType.getResourceMachineList())) {
|
||||||
|
append(context,"当前机器不支持machine");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PipResourceMachine resourceMachine = resourceListByType.getResourceMachineList().get(0);
|
||||||
|
|
||||||
//根据目标id查询目标信息
|
//根据目标id查询目标信息
|
||||||
if (StringUtils.isEmpty(pipeline.getTargetVersionId())){
|
if (StringUtils.isEmpty(pipeline.getTargetVersionId())){
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在");
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在");
|
||||||
@ -81,7 +100,13 @@ public class CustomCompilerWorker extends SshWorker {
|
|||||||
append(context,"上传文件"+targetVersion.getFileName()+"到目标服务器IP:"+resourceMachine.getMachineHost());
|
append(context,"上传文件"+targetVersion.getFileName()+"到目标服务器IP:"+resourceMachine.getMachineHost());
|
||||||
append(context,"上传路径:"+"/home/casic/706/ai_test_527");
|
append(context,"上传路径:"+"/home/casic/706/ai_test_527");
|
||||||
// 上传目标 到目标服务器
|
// 上传目标 到目标服务器
|
||||||
SftpUploadUtil.uploadFileViaSftp(resourceMachine.getMachineHost(),Integer.valueOf(resourceMachine.getSshPort()),resourceMachine.getUsername(), CryptogramUtil.doDecrypt(resourceMachine.getPassword()),null,file.getAbsolutePath(),"/home/casic/706/ai_test_527",file.getName());
|
//通过taskProperties获取制品路径
|
||||||
|
String remoteDir = taskProperties.get("remoteDir").toString();
|
||||||
|
if (StringUtils.isEmpty(remoteDir)){
|
||||||
|
//则默认路径写死
|
||||||
|
remoteDir = "/home/casic/706/ai_test_527";
|
||||||
|
}
|
||||||
|
SftpUploadUtil.uploadFileViaSftp(resourceMachine.getMachineHost(),Integer.valueOf(resourceMachine.getSshPort()),resourceMachine.getUsername(), CryptogramUtil.doDecrypt(resourceMachine.getPassword()),null,file.getAbsolutePath(),remoteDir,file.getName());
|
||||||
|
|
||||||
//TODO 得改一下
|
//TODO 得改一下
|
||||||
statusCode = shell(resourceMachine, null,context,
|
statusCode = shell(resourceMachine, null,context,
|
||||||
|
@ -2,7 +2,8 @@ package cd.casic.ci.process.engine.worker;
|
|||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.common.WorkAtom;
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
import cd.casic.ci.process.engine.worker.base.SshWorker;
|
import cd.casic.ci.process.engine.worker.base.SshWorker;
|
||||||
@ -11,6 +12,7 @@ import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
|
|||||||
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
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 java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -33,16 +35,8 @@ public class DIYImageExecuteCommandWorker extends SshWorker {
|
|||||||
log.info(taskDef.getTaskName());
|
log.info(taskDef.getTaskName());
|
||||||
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
Map<String, Object> taskProperties = taskDef.getTaskProperties();
|
||||||
Object commandScriptObj = taskProperties.get(DIYImageExecuteCommandConstant.COMMAND_SCRIPT);
|
Object commandScriptObj = taskProperties.get(DIYImageExecuteCommandConstant.COMMAND_SCRIPT);
|
||||||
Object machineIdObj = taskProperties.get(DIYImageExecuteCommandConstant.MACHINE_ID);
|
|
||||||
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
||||||
Long machineId = null;
|
if (StringUtils.isEmpty(commandScript)) {
|
||||||
try {
|
|
||||||
machineId=Long.valueOf(String.valueOf(machineIdObj));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
log.error("缺少参数:{}",DIYImageExecuteCommandConstant.MACHINE_ID);
|
|
||||||
toBadEnding();
|
|
||||||
}
|
|
||||||
if (StringUtils.isEmpty(commandScript) ||machineIdObj == null) {
|
|
||||||
// 缺少参数
|
// 缺少参数
|
||||||
toBadEnding();
|
toBadEnding();
|
||||||
}
|
}
|
||||||
@ -53,11 +47,27 @@ public class DIYImageExecuteCommandWorker extends SshWorker {
|
|||||||
|
|
||||||
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
||||||
|
|
||||||
//获取机器
|
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
String resourceId = pipeline.getResourceId();
|
// String resourceId = pipeline.getResourceId();
|
||||||
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
// ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
||||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
// PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||||
|
|
||||||
|
//获取机器
|
||||||
|
String resourceType = taskProperties.get("resourceType").toString();
|
||||||
|
String resourceId = taskProperties.get("resourceId").toString();
|
||||||
|
if (StringUtils.isEmpty(resourceId) || StringUtils.isEmpty(resourceType)) {
|
||||||
|
// 缺少参数
|
||||||
|
toBadEnding();
|
||||||
|
}
|
||||||
|
ResourceQueryReq req = new ResourceQueryReq();
|
||||||
|
req.setId(resourceId);
|
||||||
|
req.setType(resourceType);
|
||||||
|
TaskResourceFindResp resourceListByType = getResourceManagerService().findResourceListByType(req);
|
||||||
|
if (CollectionUtils.isEmpty(resourceListByType.getResourceMachineList())) {
|
||||||
|
append(context,"当前机器不支持machine");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PipResourceMachine resourceMachine = resourceListByType.getResourceMachineList().get(0);
|
||||||
//TODO 得改一下
|
//TODO 得改一下
|
||||||
statusCode = shell(resourceMachine, null,context,
|
statusCode = shell(resourceMachine, null,context,
|
||||||
"echo \"自定义镜像执行命令\"",
|
"echo \"自定义镜像执行命令\"",
|
||||||
|
@ -2,7 +2,8 @@ package cd.casic.ci.process.engine.worker;
|
|||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.process.common.WorkAtom;
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
|
||||||
import cd.casic.ci.process.engine.constant.TestCaseGenerationConstant;
|
import cd.casic.ci.process.engine.constant.TestCaseGenerationConstant;
|
||||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
@ -13,6 +14,7 @@ import cd.casic.ci.process.process.dataObject.task.PipTask;
|
|||||||
import cd.casic.ci.process.util.CryptogramUtil;
|
import cd.casic.ci.process.util.CryptogramUtil;
|
||||||
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 java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -31,7 +33,6 @@ public class TestCaseGenerationWorker extends SshWorker {
|
|||||||
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
||||||
|
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
String machineId = pipeline.getMachineId();
|
|
||||||
if (StringUtils.isEmpty(commandScript)) {
|
if (StringUtils.isEmpty(commandScript)) {
|
||||||
// 缺少参数
|
// 缺少参数
|
||||||
toBadEnding();
|
toBadEnding();
|
||||||
@ -40,10 +41,25 @@ public class TestCaseGenerationWorker extends SshWorker {
|
|||||||
try {
|
try {
|
||||||
//将节点的配置信息反编译成对象
|
//将节点的配置信息反编译成对象
|
||||||
log.info("构建脚本" + commandScript);
|
log.info("构建脚本" + commandScript);
|
||||||
String resourceId = pipeline.getResourceId();
|
String resourceType = taskProperties.get("resourceType").toString();
|
||||||
|
String resourceId = taskProperties.get("resourceId").toString();
|
||||||
|
if (StringUtils.isEmpty(resourceId) || StringUtils.isEmpty(resourceType)) {
|
||||||
|
// 缺少参数
|
||||||
|
toBadEnding();
|
||||||
|
}
|
||||||
|
ResourceQueryReq req = new ResourceQueryReq();
|
||||||
|
req.setId(resourceId);
|
||||||
|
req.setType(resourceType);
|
||||||
|
TaskResourceFindResp resourceListByType = getResourceManagerService().findResourceListByType(req);
|
||||||
|
if (CollectionUtils.isEmpty(resourceListByType.getResourceMachineList())) {
|
||||||
|
append(context,"当前机器不支持machine");
|
||||||
|
return;
|
||||||
|
}
|
||||||
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
//如果machineId为0,则说明该节点没有配置机器,则使用开始节点的机器
|
||||||
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
PipResourceMachine resourceMachine = resourceListByType.getResourceMachineList().get(0);
|
||||||
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
|
||||||
|
// ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
|
||||||
|
// PipResourceMachine resourceMachine = resourceById.getResourceMachine();
|
||||||
//获取机器
|
//获取机器
|
||||||
statusCode = shell(resourceMachine, CryptogramUtil.doDecrypt(resourceMachine.getPassword()), context,
|
statusCode = shell(resourceMachine, CryptogramUtil.doDecrypt(resourceMachine.getPassword()), context,
|
||||||
"echo \"自定义镜像执行命令\"",
|
"echo \"自定义镜像执行命令\"",
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dao.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceCloud;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName PipResourceMachineDao
|
|
||||||
* @Date: 2025/5/13 14:39
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface ResourceCloudDao extends BaseMapperX<ResourceCloud> {
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dao.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceDockerEndpoint;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName PipResourceDockerEndpointDao
|
|
||||||
* @Date: 2025/5/13 14:39
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface ResourceDockerEndpointDao extends BaseMapperX<ResourceDockerEndpoint> {
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dao.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceK8S;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName PipResourceK8SDao
|
|
||||||
* @Date: 2025/5/13 14:39
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface ResourceK8SDao extends BaseMapperX<ResourceK8S> {
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dao.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceMachine;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName PipResourceMachineDao
|
|
||||||
* @Date: 2025/5/13 14:39
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface ResourceMachineDao extends BaseMapperX<ResourceMachine> {
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dao.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceManager;
|
|
||||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName PipResourceDao
|
|
||||||
* @Date: 2025/5/13 14:39
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface ResourceManagerDao {
|
|
||||||
//public interface ResourceManagerDao extends BaseMapperX<ResourceManager> {
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName PipResourceCloud
|
|
||||||
* @Author hopeli
|
|
||||||
* @Date 2025/5/31 22:19
|
|
||||||
* @Version 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class ResourceCloud extends PipBaseElement {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 虚拟机类型
|
|
||||||
*/
|
|
||||||
private String vmType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 虚拟机名称
|
|
||||||
*/
|
|
||||||
private String vmName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 到期释放时间
|
|
||||||
*/
|
|
||||||
private String expirationTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数量
|
|
||||||
*/
|
|
||||||
private String sum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 平台
|
|
||||||
*/
|
|
||||||
private String platform;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cpu架构
|
|
||||||
*/
|
|
||||||
private String cpuFramework;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GPU配置状态
|
|
||||||
*/
|
|
||||||
private String gpuStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cpu内核数量
|
|
||||||
*/
|
|
||||||
private String cpuCoreSum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内存
|
|
||||||
*/
|
|
||||||
private String internalStorage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作系统
|
|
||||||
*/
|
|
||||||
private String os;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统盘类型
|
|
||||||
*/
|
|
||||||
private String systemDiskType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统盘内存大小
|
|
||||||
*/
|
|
||||||
private String systemDiskInternalStorage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员账号
|
|
||||||
*/
|
|
||||||
private String managerAccount;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员密码
|
|
||||||
*/
|
|
||||||
private String managerPassword;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 安全组
|
|
||||||
*/
|
|
||||||
private String securityGroup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度策略
|
|
||||||
*/
|
|
||||||
private String schedulingPolicy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 引导方式
|
|
||||||
*/
|
|
||||||
private String bootMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 备份机
|
|
||||||
*/
|
|
||||||
private String backup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 反亲和组
|
|
||||||
*/
|
|
||||||
private String antiAffinityGroup;
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName PipelineDockerEndpoint
|
|
||||||
* @Author hopeli
|
|
||||||
* @Date 2025/5/31 21:54
|
|
||||||
* @Version 1.0
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class ResourceDockerEndpoint extends PipBaseElement {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Docker 类型:远程/本地
|
|
||||||
*/
|
|
||||||
private String dockerType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Docker 状态(参考 DockerEndpointStateEnum)
|
|
||||||
*/
|
|
||||||
private String state;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主机地址
|
|
||||||
*/
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 端口
|
|
||||||
*/
|
|
||||||
private String port;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最近测试时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime latestTestTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 类型(可能用于扩展分类)
|
|
||||||
*/
|
|
||||||
private String type;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class ResourceK8S extends PipBaseElement {
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName PipResourceMachine
|
|
||||||
* @Author hopeli
|
|
||||||
* @Date 2025/31 21:48
|
|
||||||
* @Version 1.0
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class ResourceMachine extends PipBaseElement {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主机地址
|
|
||||||
*/
|
|
||||||
private String machineHost;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述
|
|
||||||
*/
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器状态
|
|
||||||
*/
|
|
||||||
private String machineStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录用户名
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SSH 端口
|
|
||||||
*/
|
|
||||||
private String sshPort;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 秘钥 ID
|
|
||||||
*/
|
|
||||||
private Long secretKeyId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 代理 ID
|
|
||||||
*/
|
|
||||||
private Long proxyId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 认证类型编码
|
|
||||||
*/
|
|
||||||
private Integer authenticationTypeCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 认证类型
|
|
||||||
*/
|
|
||||||
private String authType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作系统
|
|
||||||
*/
|
|
||||||
private String osSystem;
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName PipResourceTmp
|
|
||||||
* @Author hopeli
|
|
||||||
* @Date 2025/31 21:40
|
|
||||||
* @Version 1.0
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class ResourceManager extends PipBaseElement {
|
|
||||||
/**
|
|
||||||
* docker镜像服务器信息id
|
|
||||||
*/
|
|
||||||
private String dockerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* k8s服务器信息id
|
|
||||||
*/
|
|
||||||
private String k8sId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 机器服务器信息id
|
|
||||||
*/
|
|
||||||
private String machineId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 弹性云服务器信息id
|
|
||||||
*/
|
|
||||||
private String cloudId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源名称
|
|
||||||
*/
|
|
||||||
private String resourceName;
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.process.service.resource;
|
|||||||
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.process.dataObject.resource.PipResourceManager;
|
import cd.casic.ci.process.process.dataObject.resource.PipResourceManager;
|
||||||
import cd.casic.framework.commons.pojo.PageResult;
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
@ -29,4 +30,8 @@ public interface ResourceManagerService extends IService<PipResourceManager> {
|
|||||||
List<ResourceFindResp> findResourceList(@Valid ResourceQueryReq req);
|
List<ResourceFindResp> findResourceList(@Valid ResourceQueryReq req);
|
||||||
|
|
||||||
PageResult<ResourceFindResp> findResourcePage(@Valid ResourceQueryReq req);
|
PageResult<ResourceFindResp> findResourcePage(@Valid ResourceQueryReq req);
|
||||||
|
|
||||||
|
TaskResourceFindResp findResourceListByType(@Valid ResourceQueryReq req);
|
||||||
|
|
||||||
|
List findResourceListForObjectByType(@Valid ResourceQueryReq req);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.process.service.resource.impl;
|
|||||||
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceQueryReq;
|
||||||
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
import cd.casic.ci.process.dto.req.resource.ResourceReq;
|
||||||
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
import cd.casic.ci.process.dto.resp.resource.ResourceFindResp;
|
||||||
|
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
||||||
import cd.casic.ci.process.process.converter.ResourceConverter;
|
import cd.casic.ci.process.process.converter.ResourceConverter;
|
||||||
import cd.casic.ci.process.process.dao.pipeline.PipResourceCloudDao;
|
import cd.casic.ci.process.process.dao.pipeline.PipResourceCloudDao;
|
||||||
import cd.casic.ci.process.process.dao.pipeline.PipResourceK8SDao;
|
import cd.casic.ci.process.process.dao.pipeline.PipResourceK8SDao;
|
||||||
@ -274,6 +275,97 @@ public class ResourceManagerServiceImpl extends ServiceImpl<PipResourceManagerDa
|
|||||||
return pageResult;
|
return pageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskResourceFindResp findResourceListByType(ResourceQueryReq query) {
|
||||||
|
TaskResourceFindResp taskResourceFindResp = new TaskResourceFindResp();
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(query.getType())){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型不可为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (query.getType()) {
|
||||||
|
case "docker":
|
||||||
|
QueryWrapper<DockerEndpointDo> dockerWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
dockerWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
List<DockerEndpointDo> resourceDockerEndpoints = dockerEndpointDao.selectList(dockerWrapper);
|
||||||
|
if (!ObjectUtils.isEmpty(resourceDockerEndpoints)){
|
||||||
|
taskResourceFindResp.setDockerEndpointList(resourceDockerEndpoints);
|
||||||
|
}
|
||||||
|
return taskResourceFindResp;
|
||||||
|
case "k8s":
|
||||||
|
QueryWrapper<PipResourceK8S> k8sWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
k8sWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
List<PipResourceK8S> resourceK8S = k8SDao.selectList(k8sWrapper);
|
||||||
|
if (!ObjectUtils.isEmpty(resourceK8S)){
|
||||||
|
taskResourceFindResp.setResourceK8SList(resourceK8S);
|
||||||
|
}
|
||||||
|
return taskResourceFindResp;
|
||||||
|
case "machine":
|
||||||
|
QueryWrapper<PipResourceMachine> machineWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
machineWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
List<PipResourceMachine> resourceMachines = machineDao.selectList(machineWrapper);
|
||||||
|
if (!ObjectUtils.isEmpty(resourceMachines)){
|
||||||
|
taskResourceFindResp.setResourceMachineList(resourceMachines);
|
||||||
|
}
|
||||||
|
return taskResourceFindResp;
|
||||||
|
case "cloud":
|
||||||
|
QueryWrapper<PipResourceCloud> cloudWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
cloudWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
List<PipResourceCloud> resourceClouds = cloudDao.selectList(cloudWrapper);
|
||||||
|
if (!ObjectUtils.isEmpty(resourceClouds)){
|
||||||
|
taskResourceFindResp.setResourceCloudList(resourceClouds);
|
||||||
|
}
|
||||||
|
return taskResourceFindResp;
|
||||||
|
default:
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List findResourceListForObjectByType(ResourceQueryReq query) {
|
||||||
|
if (StringUtils.isEmpty(query.getType())){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型不可为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (query.getType()) {
|
||||||
|
case "docker":
|
||||||
|
QueryWrapper<DockerEndpointDo> dockerWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
dockerWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
return dockerEndpointDao.selectList(dockerWrapper);
|
||||||
|
case "k8s":
|
||||||
|
QueryWrapper<PipResourceK8S> k8sWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
k8sWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
return k8SDao.selectList(k8sWrapper);
|
||||||
|
case "machine":
|
||||||
|
QueryWrapper<PipResourceMachine> machineWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
machineWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
return machineDao.selectList(machineWrapper);
|
||||||
|
case "cloud":
|
||||||
|
QueryWrapper<PipResourceCloud> cloudWrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getId())){
|
||||||
|
cloudWrapper.eq("id",query.getId());
|
||||||
|
}
|
||||||
|
return cloudDao.selectList(cloudWrapper);
|
||||||
|
default:
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setResource(ResourceFindResp resourceFindResp) {
|
private void setResource(ResourceFindResp resourceFindResp) {
|
||||||
if (!StringUtils.isEmpty(resourceFindResp.getMachineId())){
|
if (!StringUtils.isEmpty(resourceFindResp.getMachineId())){
|
||||||
PipResourceMachine resourceMachine = machineDao.selectById(resourceFindResp.getMachineId());
|
PipResourceMachine resourceMachine = machineDao.selectById(resourceFindResp.getMachineId());
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.taskResource;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.taskResource.TaskResourceQueryReq;
|
|
||||||
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.ResourceManager;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName ResourceService
|
|
||||||
* @Date: 2025/5/13 10:27
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public interface TaskResourceManagerService {
|
|
||||||
//public interface TaskResourceManagerService extends IService<ResourceManager> {
|
|
||||||
|
|
||||||
TaskResourceFindResp findResourceList(@Valid TaskResourceQueryReq req);
|
|
||||||
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.taskResource.impl;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.dto.req.taskResource.TaskResourceQueryReq;
|
|
||||||
import cd.casic.ci.process.dto.resp.taskResource.TaskResourceFindResp;
|
|
||||||
import cd.casic.ci.process.process.dao.taskResource.*;
|
|
||||||
import cd.casic.ci.process.process.dataObject.taskResource.*;
|
|
||||||
import cd.casic.ci.process.process.service.taskResource.TaskResourceManagerService;
|
|
||||||
import cd.casic.framework.commons.exception.ServiceException;
|
|
||||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HopeLi
|
|
||||||
* @version v1.0
|
|
||||||
* @ClassName ResourceServiceImpl
|
|
||||||
* @Date: 2025/5/13 10:31
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
//@Service
|
|
||||||
@Slf4j
|
|
||||||
public class TaskResourceManagerServiceImpl implements TaskResourceManagerService {
|
|
||||||
//public class TaskResourceManagerServiceImpl extends ServiceImpl<ResourceManagerDao, ResourceManager> implements TaskResourceManagerService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ResourceMachineDao machineDao;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ResourceDockerEndpointDao dockerEndpointDao;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ResourceK8SDao k8SDao;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ResourceCloudDao cloudDao;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TaskResourceFindResp findResourceList(TaskResourceQueryReq query) {
|
|
||||||
TaskResourceFindResp taskResourceFindResp = new TaskResourceFindResp();
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(query.getType())){
|
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型不可为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (query.getType()) {
|
|
||||||
case "docker":
|
|
||||||
List<ResourceDockerEndpoint> resourceDockerEndpoints = dockerEndpointDao.selectList(new QueryWrapper<>());
|
|
||||||
if (!ObjectUtils.isEmpty(resourceDockerEndpoints)){
|
|
||||||
taskResourceFindResp.setDockerEndpointList(resourceDockerEndpoints);
|
|
||||||
}
|
|
||||||
return taskResourceFindResp;
|
|
||||||
case "k8s":
|
|
||||||
List<ResourceK8S> resourceK8S = k8SDao.selectList(new QueryWrapper<>());
|
|
||||||
if (!ObjectUtils.isEmpty(resourceK8S)){
|
|
||||||
taskResourceFindResp.setResourceK8SList(resourceK8S);
|
|
||||||
}
|
|
||||||
return taskResourceFindResp;
|
|
||||||
case "machine":
|
|
||||||
List<ResourceMachine> resourceMachines = machineDao.selectList(new QueryWrapper<>());
|
|
||||||
if (!ObjectUtils.isEmpty(resourceMachines)){
|
|
||||||
taskResourceFindResp.setResourceMachineList(resourceMachines);
|
|
||||||
}
|
|
||||||
return taskResourceFindResp;
|
|
||||||
case "cloud":
|
|
||||||
List<ResourceCloud> resourceClouds = cloudDao.selectList(new QueryWrapper<>());
|
|
||||||
if (!ObjectUtils.isEmpty(resourceClouds)){
|
|
||||||
taskResourceFindResp.setResourceCloudList(resourceClouds);
|
|
||||||
}
|
|
||||||
return taskResourceFindResp;
|
|
||||||
default:
|
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"资源类型错误");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user