逻辑修改日志添加
This commit is contained in:
parent
c9f72c1621
commit
ee585fe263
@ -60,36 +60,36 @@ public class SastWorker extends BaseWorker {
|
|||||||
sastApplicationCreateReq.setFileId(list);
|
sastApplicationCreateReq.setFileId(list);
|
||||||
append(context,"开始启动SAST任务,检测文件信息:{}"+JSON.toJSONString(applicationEcho.getLodeFiles()));
|
append(context,"开始启动SAST任务,检测文件信息:{}"+JSON.toJSONString(applicationEcho.getLodeFiles()));
|
||||||
log.info("SAST启动任务入参:{}",JSON.toJSONString(sastApplicationCreateReq));
|
log.info("SAST启动任务入参:{}",JSON.toJSONString(sastApplicationCreateReq));
|
||||||
SastApplicationCreateResp sastApplicationCreateResp = sastService.applicationCreate(sastApplicationCreateReq);
|
// SastApplicationCreateResp sastApplicationCreateResp = sastService.applicationCreate(sastApplicationCreateReq);
|
||||||
log.info("SAST启动任务返回值:{}",JSON.toJSONString(sastApplicationCreateResp));
|
// log.info("SAST启动任务返回值:{}",JSON.toJSONString(sastApplicationCreateResp));
|
||||||
append(context,"启动任务完毕");
|
// append(context,"启动任务完毕");
|
||||||
// 检测状态是否完毕
|
//// 检测状态是否完毕
|
||||||
applicationStatus = sastService.getApplicationStatus(applicationId);
|
// applicationStatus = sastService.getApplicationStatus(applicationId);
|
||||||
int repeat = 0;
|
// int repeat = 0;
|
||||||
while (!SastConstant.STATUS_JOB_DONE.equals(applicationStatus.getJobStatus())) {
|
// while (!SastConstant.STATUS_JOB_DONE.equals(applicationStatus.getJobStatus())) {
|
||||||
try {
|
// try {
|
||||||
Thread.sleep(20000L);
|
// Thread.sleep(20000L);
|
||||||
} catch (InterruptedException e) {
|
// } catch (InterruptedException e) {
|
||||||
log.error("SAST WORKER线程中断");
|
// log.error("SAST WORKER线程中断");
|
||||||
}
|
// }
|
||||||
try {
|
// try {
|
||||||
applicationStatus=sastService.getApplicationStatus(applicationId);
|
// applicationStatus=sastService.getApplicationStatus(applicationId);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("sastWorker执行失败",e);
|
// log.error("sastWorker执行失败",e);
|
||||||
append(context,"获取状态失败");
|
// append(context,"获取状态失败");
|
||||||
if (repeat++>3) {
|
// if (repeat++>3) {
|
||||||
append(context,"获取状态失败,尝试超过三次执行失败");
|
// append(context,"获取状态失败,尝试超过三次执行失败");
|
||||||
toBadEnding();
|
// toBadEnding();
|
||||||
}
|
// }
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
append(context,"当前SAST运行中,运行状态:"+applicationStatus.getJobStatus());
|
// append(context,"当前SAST运行中,运行状态:"+applicationStatus.getJobStatus());
|
||||||
if (SastConstant.STATUS_PENDING.equals(applicationStatus.getJobStatus())) {
|
// if (SastConstant.STATUS_PENDING.equals(applicationStatus.getJobStatus())) {
|
||||||
append(context,"任务被取消");
|
// append(context,"任务被取消");
|
||||||
toBadEnding();
|
// toBadEnding();
|
||||||
}
|
// }
|
||||||
repeat = 0;
|
// repeat = 0;
|
||||||
}
|
// }
|
||||||
JSONObject reportJSON = getReportJSON(applicationId, SastConstant.REPORT_MODE_DETAILS);
|
JSONObject reportJSON = getReportJSON(applicationId, SastConstant.REPORT_MODE_DETAILS);
|
||||||
String reportUrl = getReportUrl(applicationId, SastConstant.REPORT_MODE_DETAILS);
|
String reportUrl = getReportUrl(applicationId, SastConstant.REPORT_MODE_DETAILS);
|
||||||
task.getTaskProperties().put(SastConstant.REPORT_JSON,reportJSON);
|
task.getTaskProperties().put(SastConstant.REPORT_JSON,reportJSON);
|
||||||
@ -105,7 +105,7 @@ public class SastWorker extends BaseWorker {
|
|||||||
sastReportCreateReq.setApplicationIds(Collections.singletonList(applicationId));
|
sastReportCreateReq.setApplicationIds(Collections.singletonList(applicationId));
|
||||||
log.info("获取JSON报告请求参数{}",JSON.toJSONString(sastReportCreateReq));
|
log.info("获取JSON报告请求参数{}",JSON.toJSONString(sastReportCreateReq));
|
||||||
String reportId = sastService.reportIndex(sastReportCreateReq);
|
String reportId = sastService.reportIndex(sastReportCreateReq);
|
||||||
log.info("获取JSON报告获得url{}",reportId);
|
log.info("获取JSON报告获得reportId{}",reportId);
|
||||||
JSONObject jsonObject = getJSONString(reportId).getJSONObject("task_summary");
|
JSONObject jsonObject = getJSONString(reportId).getJSONObject("task_summary");
|
||||||
JSONObject severity = jsonObject.getJSONObject("defect_severity_distribution");
|
JSONObject severity = jsonObject.getJSONObject("defect_severity_distribution");
|
||||||
JSONObject rule = jsonObject.getJSONObject("detection_rule_distribution");
|
JSONObject rule = jsonObject.getJSONObject("detection_rule_distribution");
|
||||||
|
@ -16,6 +16,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import kotlin.text.Charsets;
|
import kotlin.text.Charsets;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.luaj.vm2.ast.Str;
|
import org.luaj.vm2.ast.Str;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
@ -39,6 +40,7 @@ import java.util.Map;
|
|||||||
import static cd.casic.ci.process.constant.SastUrlConstant.*;
|
import static cd.casic.ci.process.constant.SastUrlConstant.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class SastServiceImpl implements SastService {
|
public class SastServiceImpl implements SastService {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplateUtils redisTemplateUtils;
|
private RedisTemplateUtils redisTemplateUtils;
|
||||||
@ -248,6 +250,7 @@ public class SastServiceImpl implements SastService {
|
|||||||
HttpEntity<Map<String, String>> entity = new HttpEntity<>(entityMap,httpHeaders);
|
HttpEntity<Map<String, String>> entity = new HttpEntity<>(entityMap,httpHeaders);
|
||||||
String uriString=UriComponentsBuilder.fromUriString(sastProperties.getBaseUrl()+jsonReportDownload)
|
String uriString=UriComponentsBuilder.fromUriString(sastProperties.getBaseUrl()+jsonReportDownload)
|
||||||
.queryParam("reportId",reportId).toUriString();
|
.queryParam("reportId",reportId).toUriString();
|
||||||
|
log.info("sast 下载报告url:{}",uriString);
|
||||||
ResponseEntity<String> exchange = restTemplate.exchange(uriString, HttpMethod.GET,entity, String.class,new HashMap<>());
|
ResponseEntity<String> exchange = restTemplate.exchange(uriString, HttpMethod.GET,entity, String.class,new HashMap<>());
|
||||||
return JSON.parseObject(exchange.getBody());
|
return JSON.parseObject(exchange.getBody());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user