use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.
the class CreateScanReportService method createReport.
/**
* Creates a report based on product results. There is no security check because
* its only called internally from system.
*
* @param context
* @return report, never <code>null</code>
* @throws ScanReportException
*/
public ScanReport createReport(SecHubExecutionContext context) throws ScanReportException {
notNull(context, "Context may not be null!");
UUID sechubJobUUID = context.getSechubJobUUID();
if (sechubJobUUID == null) {
throw new ScanReportException("Cannot create a report for Job UUID:null");
}
LOG.info("Creating report for {}, will delete former reports if existing", traceLogID(sechubJobUUID));
/* we allow only one report for one job */
scanReportTransactionService.deleteAllReportsForSecHubJobUUIDinOwnTransaction(sechubJobUUID);
/*
* create report - project id in configuration was set on job creation time and
* is always correct/valid and will differ between api parameter and config..!
*/
ScanReport scanReport = new ScanReport(sechubJobUUID, context.getConfiguration().getProjectId());
scanReport.setStarted(LocalDateTime.now());
/* execute report products */
try {
reportProductExecutionService.executeProductsAndStoreResults(context);
} catch (SecHubExecutionException e) {
throw new ScanReportException("Report product execution failed", e);
}
/* transform */
ReportTransformationResult reportTransformerResult;
try {
reportTransformerResult = reportTransformerService.createResult(context);
scanReport.setResultType(ScanReportResultType.MODEL);
scanReport.setResult(reportTransformerResult.toJSON());
} catch (Exception e) {
throw new ScanReportException("Was not able to build sechub result", e);
}
/* create and set the traffic light */
TrafficLight trafficLight = trafficLightCalculator.calculateTrafficLight(reportTransformerResult);
scanReport.setTrafficLight(trafficLight);
/* update time stamp */
scanReport.setEnded(LocalDateTime.now());
/* persist */
return reportRepository.save(scanReport);
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.
the class CheckmarxBadRequestConsultantTest method nested_http_bad_request_400_exception_wrapped_in_runtime_and_sechubexecution_exception_returns_retry_proposal_with_3_retries_and_2000_millis_to_wait.
@Test
public void nested_http_bad_request_400_exception_wrapped_in_runtime_and_sechubexecution_exception_returns_retry_proposal_with_3_retries_and_2000_millis_to_wait() {
/* prepare */
when(context.getCurrentError()).thenReturn(new SecHubExecutionException("se1", new RuntimeException(new HttpClientErrorException(HttpStatus.BAD_REQUEST))));
/* execute */
ResilienceProposal proposal = consultantToTest.consultFor(context);
/* test */
assertNotNull(proposal);
assertTrue(proposal instanceof RetryResilienceProposal);
RetryResilienceProposal rrp = (RetryResilienceProposal) proposal;
assertEquals(3, rrp.getMaximumAmountOfRetries());
assertEquals(2000, rrp.getMillisecondsToWaitBeforeRetry());
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.
the class AbstractProductExecutionServiceTest method sechub_execution_error_on_execution_shall_not_break_the_build_but_safe_fallbackresult.
@Test
public void sechub_execution_error_on_execution_shall_not_break_the_build_but_safe_fallbackresult() throws Exception {
/* prepare */
ArgumentCaptor<ProductResult> productResultCaptor = ArgumentCaptor.forClass(ProductResult.class);
SecHubExecutionException exception = new SecHubExecutionException("an-error occurred on execution, but this should not break at all!");
when(executor.execute(context, productExecutorContext)).thenThrow(exception);
/* execute */
serviceToTest.runOnAllAvailableExecutors(executors, context, traceLogID);
/* test */
verify(productResultRepository).findProductResults(sechubJobUUID, config1);
verify(productExecutorContext).persist(productResultCaptor.capture());
ProductResult captured = productResultCaptor.getValue();
assertEquals(USED_PRODUCT_IDENTIFIER, captured.getProductIdentifier());
assertEquals("", captured.getResult());
ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
verify(logger).error(stringCaptor.capture(), eq(USED_PRODUCT_IDENTIFIER), eq(traceLogID), eq(exception));
assertTrue(stringCaptor.getValue().startsWith("Product executor failed"));
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.
the class ScanJobExecutor method execute.
public void execute() throws SecHubExecutionException {
String jobUUID = context.getTraceLogId().getPlainId();
CanceableScanJobRunnable canceableJobRunner = new CanceableScanJobRunnable(jobUUID);
Thread canceableJobThread = new Thread(canceableJobRunner, "SecHub-exec-" + jobUUID + "-" + progress.getId());
canceableJobRunner.executorThread = canceableJobThread;
UUID sechubJobUUID = context.getSechubJobUUID();
try {
canceableJobThread.start();
this.scanService.scanJobListener.started(sechubJobUUID, canceableJobRunner);
/* wait for job runnable - except when canceled */
while (canceableJobThread.isAlive()) {
try {
LOG.debug("will wait max {} milliseconds before cancel checks - job thread is:{}", millisecondsToWaitBeforeCancelCheck, canceableJobThread.getName());
/* we simply join scan thread until we do next cancel check */
canceableJobThread.join(millisecondsToWaitBeforeCancelCheck);
if (progress.isCanceled()) {
handleCanceled(canceableJobRunner, sechubJobUUID);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
SecHubExecutionException exception = canceableJobRunner.exception;
handleErrors(exception);
} catch (Exception e) {
/* should never happen, because all handled by runnable, but... */
handleErrors(new SecHubExecutionException("Scan failed - but not handled by runnable.", e));
} finally {
this.scanService.scanJobListener.ended(sechubJobUUID);
}
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.
the class ScanService method startScan.
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_DONE, answeringTo = MessageID.START_SCAN, branchName = "success")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_FAILED, answeringTo = MessageID.START_SCAN, branchName = "failure")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_ABANDONDED, answeringTo = MessageID.START_SCAN, branchName = "failure")
DomainMessageSynchronousResult startScan(DomainMessage request) {
SecHubExecutionContext context = null;
try {
context = createExecutionContext(request);
executeScan(context, request);
ScanReport report = reportService.createReport(context);
DomainMessageSynchronousResult response = new DomainMessageSynchronousResult(MessageID.SCAN_DONE);
response.set(REPORT_TRAFFIC_LIGHT, report.getTrafficLightAsString());
return response;
} catch (ScanReportException e) {
LOG.error("Execution was possible, but report failed." + traceLogID(request), e);
return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
} catch (SecHubExecutionAbandonedException e) {
LOG.info("Execution abandoned on scan {} - message: {}", traceLogID(request), e.getMessage());
return new DomainMessageSynchronousResult(MessageID.SCAN_ABANDONDED, e);
} catch (SecHubExecutionException e) {
LOG.error("Execution problems on scan." + traceLogID(request), e);
return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
} catch (Exception e) {
LOG.error("Was not able to start scan." + traceLogID(request), e);
return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
} finally {
if (context == null) {
LOG.warn("No sechub execution context available, so cannot check state or cleanup storage");
} else {
if (!context.isAbandonded()) {
cleanupStorage(context);
}
}
}
}
Aggregations