sbom 日志添加
This commit is contained in:
parent
5c0196c868
commit
622567d385
@ -128,22 +128,24 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
append(context,"===============SCA上传成功=================");
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
Integer scaTaskId = data.getInteger("scaTaskId");
|
||||
|
||||
append(context,"上传完毕获取scaTaskId:"+scaTaskId);
|
||||
//更新scaTaskId数据到task表
|
||||
scaSbomConfigInfo.put("scaTaskId",scaTaskId);
|
||||
pipTask.setTaskProperties(scaSbomConfigInfo);
|
||||
pipTaskDao.updateById(pipTask);
|
||||
|
||||
pollTaskStatus(restTemplate, scaTaskId);
|
||||
append(context,"任务正在运行中,正在查询执行状态,当前scaTaskId :"+scaTaskId);
|
||||
pollTaskStatus(restTemplate, scaTaskId,context);
|
||||
} else if (message.equals("应用已经存在")) {
|
||||
append(context,message);
|
||||
Integer oldScaTaskId = (Integer) scaSbomConfigInfo.get("scaTaskId");
|
||||
Integer oldApplicationId = (Integer) scaSbomConfigInfo.get("applicationId");
|
||||
append(context,"跳过上传步骤,获取scaTaskId:"+oldScaTaskId);
|
||||
append(context,"重新运行上一次的,scaTaskId:"+oldScaTaskId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
if (restartResult != 0) {
|
||||
return;
|
||||
}
|
||||
pollTaskStatus(restTemplate, oldScaTaskId);
|
||||
pollTaskStatus(restTemplate, oldScaTaskId,context);
|
||||
} else {
|
||||
append(context,"==================SCA接口异常,调用失败=================");
|
||||
append(context,message);
|
||||
@ -179,7 +181,7 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param scaTaskId
|
||||
*/
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId) {
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId,BaseRunContext context) {
|
||||
int currentPollingTimes = 0;
|
||||
while (currentPollingTimes < MAX_POLLING_TIMES) {
|
||||
try {
|
||||
@ -192,18 +194,23 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
if (Objects.requireNonNull(response.getBody()).getString("message").equals("success")) {
|
||||
//"status": 5, //状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中
|
||||
int status = response.getBody().getJSONObject("data").getInteger("status");
|
||||
append(context,"\"状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中\"");
|
||||
log.info("当前任务状态: " + status);
|
||||
append(context,"当前任务状态: " + status);
|
||||
if (status == 5) {
|
||||
System.out.println("任务已完成,停止轮询。");
|
||||
log.info("任务已完成,停止轮询。");
|
||||
append(context,"任务已完成,停止状态获取。" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.error("获取任务状态失败: " + response.getBody().getString("message"));
|
||||
append(context,"获取任务状态失败" );
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务状态时发生错误: " + e.getMessage());
|
||||
append(context,"获取任务状态时发生错误" );
|
||||
}
|
||||
try {
|
||||
// 轮询间隔 5 秒
|
||||
|
@ -4,6 +4,7 @@ package cd.casic.ci.process.engine.worker.base;
|
||||
import cd.casic.ci.process.constant.CommandConstant;
|
||||
import cd.casic.ci.process.engine.constant.EngineRuntimeConstant;
|
||||
import cd.casic.ci.process.engine.constant.PipelineBehaviorConstant;
|
||||
import cd.casic.ci.process.engine.context.ConstantContext;
|
||||
import cd.casic.ci.process.engine.enums.ContextStateEnum;
|
||||
import cd.casic.ci.process.engine.manager.LoggerManager;
|
||||
import cd.casic.ci.process.engine.manager.RunContextManager;
|
||||
@ -101,6 +102,7 @@ public abstract class BaseWorker implements Runnable{
|
||||
}
|
||||
public void append(BaseRunContext context, String content){
|
||||
if (context instanceof TaskRunContext taskRunContext) {
|
||||
content = content+ CommandConstant.ENTER;
|
||||
loggerManager.append(taskRunContext.getContextDef().getId(),content);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user