From ee585fe263e3e617c2f77396d28c6ef7f0c0d692 Mon Sep 17 00:00:00 2001 From: even <827656971@qq.com> Date: Thu, 19 Jun 2025 18:15:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ci/process/engine/worker/SastWorker.java | 62 +++++++++---------- .../service/sast/impl/SastServiceImpl.java | 3 + 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/engine/worker/SastWorker.java b/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/engine/worker/SastWorker.java index 69bb5825..c468ed07 100644 --- a/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/engine/worker/SastWorker.java +++ b/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/engine/worker/SastWorker.java @@ -60,36 +60,36 @@ public class SastWorker extends BaseWorker { sastApplicationCreateReq.setFileId(list); append(context,"开始启动SAST任务,检测文件信息:{}"+JSON.toJSONString(applicationEcho.getLodeFiles())); log.info("SAST启动任务入参:{}",JSON.toJSONString(sastApplicationCreateReq)); - SastApplicationCreateResp sastApplicationCreateResp = sastService.applicationCreate(sastApplicationCreateReq); - log.info("SAST启动任务返回值:{}",JSON.toJSONString(sastApplicationCreateResp)); - append(context,"启动任务完毕"); -// 检测状态是否完毕 - applicationStatus = sastService.getApplicationStatus(applicationId); - int repeat = 0; - while (!SastConstant.STATUS_JOB_DONE.equals(applicationStatus.getJobStatus())) { - try { - Thread.sleep(20000L); - } catch (InterruptedException e) { - log.error("SAST WORKER线程中断"); - } - try { - applicationStatus=sastService.getApplicationStatus(applicationId); - } catch (Exception e) { - log.error("sastWorker执行失败",e); - append(context,"获取状态失败"); - if (repeat++>3) { - append(context,"获取状态失败,尝试超过三次执行失败"); - toBadEnding(); - } - continue; - } - append(context,"当前SAST运行中,运行状态:"+applicationStatus.getJobStatus()); - if (SastConstant.STATUS_PENDING.equals(applicationStatus.getJobStatus())) { - append(context,"任务被取消"); - toBadEnding(); - } - repeat = 0; - } +// SastApplicationCreateResp sastApplicationCreateResp = sastService.applicationCreate(sastApplicationCreateReq); +// log.info("SAST启动任务返回值:{}",JSON.toJSONString(sastApplicationCreateResp)); +// append(context,"启动任务完毕"); +//// 检测状态是否完毕 +// applicationStatus = sastService.getApplicationStatus(applicationId); +// int repeat = 0; +// while (!SastConstant.STATUS_JOB_DONE.equals(applicationStatus.getJobStatus())) { +// try { +// Thread.sleep(20000L); +// } catch (InterruptedException e) { +// log.error("SAST WORKER线程中断"); +// } +// try { +// applicationStatus=sastService.getApplicationStatus(applicationId); +// } catch (Exception e) { +// log.error("sastWorker执行失败",e); +// append(context,"获取状态失败"); +// if (repeat++>3) { +// append(context,"获取状态失败,尝试超过三次执行失败"); +// toBadEnding(); +// } +// continue; +// } +// append(context,"当前SAST运行中,运行状态:"+applicationStatus.getJobStatus()); +// if (SastConstant.STATUS_PENDING.equals(applicationStatus.getJobStatus())) { +// append(context,"任务被取消"); +// toBadEnding(); +// } +// repeat = 0; +// } JSONObject reportJSON = getReportJSON(applicationId, SastConstant.REPORT_MODE_DETAILS); String reportUrl = getReportUrl(applicationId, SastConstant.REPORT_MODE_DETAILS); task.getTaskProperties().put(SastConstant.REPORT_JSON,reportJSON); @@ -105,7 +105,7 @@ public class SastWorker extends BaseWorker { sastReportCreateReq.setApplicationIds(Collections.singletonList(applicationId)); log.info("获取JSON报告请求参数{}",JSON.toJSONString(sastReportCreateReq)); String reportId = sastService.reportIndex(sastReportCreateReq); - log.info("获取JSON报告获得url{}",reportId); + log.info("获取JSON报告获得reportId{}",reportId); JSONObject jsonObject = getJSONString(reportId).getJSONObject("task_summary"); JSONObject severity = jsonObject.getJSONObject("defect_severity_distribution"); JSONObject rule = jsonObject.getJSONObject("detection_rule_distribution"); diff --git a/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/process/service/sast/impl/SastServiceImpl.java b/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/process/service/sast/impl/SastServiceImpl.java index 93310e45..38a22f95 100644 --- a/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/process/service/sast/impl/SastServiceImpl.java +++ b/modules/module-ci-process-biz/src/main/java/cd/casic/ci/process/process/service/sast/impl/SastServiceImpl.java @@ -16,6 +16,7 @@ import com.alibaba.fastjson.JSONObject; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import kotlin.text.Charsets; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.luaj.vm2.ast.Str; import org.springframework.core.io.FileSystemResource; @@ -39,6 +40,7 @@ import java.util.Map; import static cd.casic.ci.process.constant.SastUrlConstant.*; @Service +@Slf4j public class SastServiceImpl implements SastService { @Resource private RedisTemplateUtils redisTemplateUtils; @@ -248,6 +250,7 @@ public class SastServiceImpl implements SastService { HttpEntity> entity = new HttpEntity<>(entityMap,httpHeaders); String uriString=UriComponentsBuilder.fromUriString(sastProperties.getBaseUrl()+jsonReportDownload) .queryParam("reportId",reportId).toUriString(); + log.info("sast 下载报告url:{}",uriString); ResponseEntity exchange = restTemplate.exchange(uriString, HttpMethod.GET,entity, String.class,new HashMap<>()); return JSON.parseObject(exchange.getBody()); }