逻辑修改日志添加

This commit is contained in:
even 2025-06-19 18:15:04 +08:00
parent c9f72c1621
commit ee585fe263
2 changed files with 34 additions and 31 deletions

View File

@ -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");

View File

@ -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<Map<String, String>> entity = new HttpEntity<>(entityMap,httpHeaders);
String uriString=UriComponentsBuilder.fromUriString(sastProperties.getBaseUrl()+jsonReportDownload)
.queryParam("reportId",reportId).toUriString();
log.info("sast 下载报告url:{}",uriString);
ResponseEntity<String> exchange = restTemplate.exchange(uriString, HttpMethod.GET,entity, String.class,new HashMap<>());
return JSON.parseObject(exchange.getBody());
}