Compare commits

..

No commits in common. "898de4e49a6ef7e73b7e0ce220bc68498a8ef3c8" and "c5563ad8e0b7181484474889c5c4fafc86d21493" have entirely different histories.

11 changed files with 23 additions and 90 deletions

View File

@ -31,7 +31,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collection; import java.util.Collection;
@ -152,8 +151,7 @@ public class DefaultRunContextManager implements RunContextManager {
} }
pipelineRunContext.changeContextStateAndChild(stateEnum); pipelineRunContext.changeContextStateAndChild(stateEnum);
} }
// 记录日志需要新事物成功或失败不影响流水线执行 @Transactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
public void toHistory(String pipelineId){ public void toHistory(String pipelineId){
log.info("========================开始入库"); log.info("========================开始入库");
BaseRunContext context = getContext(pipelineId); BaseRunContext context = getContext(pipelineId);

View File

@ -118,7 +118,7 @@ public class MemoryLogManager implements LoggerManager {
} }
} }
} }
@Transactional(rollbackFor = Exception.class) @Transactional
public void flushMemory(List<TaskRunContext> taskContextList){ public void flushMemory(List<TaskRunContext> taskContextList){
log.info("流水线日志开始入库"); log.info("流水线日志开始入库");
List<PipTaskLog> insertList = new ArrayList<>(); List<PipTaskLog> insertList = new ArrayList<>();

View File

@ -95,12 +95,10 @@ public class PipelineRunContext extends BaseRunContext{
||ContextStateEnum.BAD_ENDING.equals(stateEnum) ||ContextStateEnum.BAD_ENDING.equals(stateEnum)
||ContextStateEnum.SKIP_TO.equals(stateEnum)) { ||ContextStateEnum.SKIP_TO.equals(stateEnum)) {
this.endTime=LocalDateTime.now(); this.endTime=LocalDateTime.now();
if (!curr.equals(ContextStateEnum.HAPPY_ENDING)) {
// 入库保存 // 入库保存
contextManager.toHistory(getContextDef().getId()); contextManager.toHistory(getContextDef().getId());
} }
callParentChange(stateEnum);
}
} else { } else {
log.error("非法状态扭转直接忽略,{},{}",curr,stateEnum); log.error("非法状态扭转直接忽略,{},{}",curr,stateEnum);
} }

View File

@ -149,8 +149,7 @@ public class ApplicationWorker extends HttpWorker {
append(context,message); append(context,message);
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-应用包审查分析节点执行失败"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-应用包审查分析节点执行失败");
} }
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
} }
private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> applicationConfigInfo, File file) { private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> applicationConfigInfo, File file) {
@ -215,8 +214,7 @@ public class ApplicationWorker extends HttpWorker {
// 轮询间隔 5 // 轮询间隔 5
Thread.sleep(POLLING_INTERVAL); Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
log.error("轮询被中断: " + e.getMessage()); log.error("轮询被中断: " + e.getMessage());
} }
currentPollingTimes++; currentPollingTimes++;

View File

@ -194,8 +194,7 @@ public class CodingWorker extends HttpWorker {
// 轮询间隔 5 // 轮询间隔 5
Thread.sleep(POLLING_INTERVAL); Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
log.error("轮询被中断: " + e.getMessage()); log.error("轮询被中断: " + e.getMessage());
} }
currentPollingTimes++; currentPollingTimes++;

View File

@ -2,80 +2,25 @@ 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.dal.resp.resource.ResourceFindResp;
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.BaseWorker; import cd.casic.ci.process.engine.worker.base.BaseWorker;
import cd.casic.ci.process.engine.worker.base.SshWorker;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement; import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.ci.process.util.CryptogramUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/** /**
* 自定义编译 * 自定义编译
* */ * */
@Slf4j @Slf4j
@WorkAtom(taskType = "CUSTOM_COMPILE") @WorkAtom(taskType = "CUSTOM_COMPILE")
public class CustomCompilerWorker extends SshWorker { public class CustomCompilerWorker extends BaseWorker {
@Override @Override
public void execute(TaskRunContext context) { public void execute(TaskRunContext context) {
int statusCode = -1; PipBaseElement contextDef = context.getContextDef();
Map<String, Object> localVariables = context.getLocalVariables(); String id = contextDef.getId();
if (context.getContextDef() instanceof PipTask taskDef) { log.info("==============触发worker执行========");
log.info(taskDef.getTaskName()); log.info("==========运行context{}===========", JSON.toJSONString(context));
Map<String, Object> taskProperties = taskDef.getTaskProperties();
Object commandScriptObj = taskProperties.get(DIYImageExecuteCommandConstant.COMMAND_SCRIPT);
Object machineIdObj = taskProperties.get(DIYImageExecuteCommandConstant.MACHINE_ID);
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
Long machineId = null;
try {
machineId=Long.valueOf(String.valueOf(machineIdObj));
} catch (NumberFormatException e) {
log.error("缺少参数:{}",DIYImageExecuteCommandConstant.MACHINE_ID);
toBadEnding();
}
if (StringUtils.isEmpty(commandScript) ||machineIdObj == null) {
// 缺少参数
toBadEnding();
}
try {
//将节点的配置信息反编译成对象
log.info("构建脚本" + commandScript);
//如果machineId为0则说明该节点没有配置机器则使用开始节点的机器
//获取机器
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
String resourceId = pipeline.getResourceId();
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
//TODO 得改一下
statusCode = shell(resourceMachine, CryptogramUtil.doDecrypt(resourceMachine.getPassword()),context,
"echo \"编译命令执行\"",
commandScript
);
} catch (Exception e) {
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
log.error("执行ssh失败:",e);
append(context,errorMessage);
toBadEnding();
}
if (statusCode == 0) {
log.info("节点执行完成");
} else {
log.error("节点执行失败");
}
localVariables.put(DIYImageExecuteCommandConstant.STATUS_CODE,statusCode);
}
} }
} }

View File

@ -158,8 +158,7 @@ public class ScaBinaryWorker extends HttpWorker {
append(context,message); append(context,message);
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败");
} }
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
} }
private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaBinaryConfigInfo, File file) { private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaBinaryConfigInfo, File file) {
@ -225,8 +224,7 @@ public class ScaBinaryWorker extends HttpWorker {
// 轮询间隔 5 // 轮询间隔 5
Thread.sleep(POLLING_INTERVAL); Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
log.error("轮询被中断: " + e.getMessage()); log.error("轮询被中断: " + e.getMessage());
} }
currentPollingTimes++; currentPollingTimes++;

View File

@ -155,8 +155,7 @@ public class ScaMirrorWorker extends HttpWorker {
append(context,message); append(context,message);
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败");
} }
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
} }
private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaMirrorConfigInfo, File file) { private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaMirrorConfigInfo, File file) {
@ -228,8 +227,7 @@ public class ScaMirrorWorker extends HttpWorker {
// 轮询间隔 5 // 轮询间隔 5
Thread.sleep(POLLING_INTERVAL); Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
log.error("轮询被中断: " + e.getMessage()); log.error("轮询被中断: " + e.getMessage());
} }
currentPollingTimes++; currentPollingTimes++;

View File

@ -85,8 +85,8 @@ public class ScaSbomWorker extends HttpWorker {
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"目标文件不存在");
} }
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId()); TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
// filePath = targetVersion.getFilePath(); filePath = targetVersion.getFilePath();
filePath = "C:\\Users\\admin\\Desktop\\新建文件夹\\dist.zip";
try { try {
@ -151,8 +151,7 @@ public class ScaSbomWorker extends HttpWorker {
append(context,message); append(context,message);
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败"); throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"SCA-SBOM节点执行失败");
} }
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
} }
private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaSbomConfigInfo, File file) { private MultiValueMap<String, Object> buildRequestBody(Map<String, Object> scaSbomConfigInfo, File file) {
@ -217,8 +216,7 @@ public class ScaSbomWorker extends HttpWorker {
// 轮询间隔 5 // 轮询间隔 5
Thread.sleep(POLLING_INTERVAL); Thread.sleep(POLLING_INTERVAL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
toBadEnding();
log.error("轮询被中断: " + e.getMessage()); log.error("轮询被中断: " + e.getMessage());
} }
currentPollingTimes++; currentPollingTimes++;

View File

@ -33,7 +33,7 @@ public class TestCaseGenerationWorker extends SshWorker {
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef(); PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
String machineId = pipeline.getMachineId(); String machineId = pipeline.getMachineId();
if (StringUtils.isEmpty(commandScript)) { if (StringUtils.isEmpty(commandScript)||StringUtils.isEmpty(machineId)) {
// 缺少参数 // 缺少参数
toBadEnding(); toBadEnding();
} }

View File

@ -59,6 +59,7 @@ public abstract class BaseWorker implements Runnable{
} }
doWorker(contextKey); doWorker(contextKey);
} }
public void doWorker(String contextKey){ public void doWorker(String contextKey){
BaseRunContext context = contextManager.getContext(contextKey); BaseRunContext context = contextManager.getContext(contextKey);
if (context instanceof TaskRunContext taskRunContext){ if (context instanceof TaskRunContext taskRunContext){