use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult in project sechub by mercedes-benz.
the class SchedulerBatchJobStatusRequestHandler method returnStatus.
@IsSendingSyncMessageAnswer(value = MessageID.BATCH_JOB_STATUS, answeringTo = MessageID.REQUEST_BATCH_JOB_STATUS, branchName = "success")
private DomainMessageSynchronousResult returnStatus(DomainMessage request) {
DomainMessageSynchronousResult result = new DomainMessageSynchronousResult(MessageID.BATCH_JOB_STATUS);
BatchJobMessage batchJobMessage = request.get(MessageDataKeys.BATCH_JOB_STATUS);
UUID sechubBatchJobUUID = batchJobMessage.getSechubJobUUID();
long batchJobId = batchJobMessage.getBatchJobId();
BatchJobMessage status = new BatchJobMessage();
status.setBatchJobId(batchJobId);
status.setSecHubJobUUID(sechubBatchJobUUID);
/* find */
JobExecution jobExecution = explorer.getJobExecution(batchJobId);
if (jobExecution == null) {
status.setExisting(false);
} else {
BatchStatus batchStatus = jobExecution.getStatus();
status.setCanceled(checkRepresentsCancel(batchStatus));
status.setAbandoned(checkRepresentsAbandoned(batchStatus));
status.setExisting(true);
}
result.set(MessageDataKeys.BATCH_JOB_STATUS, status);
return result;
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult in project sechub by mercedes-benz.
the class SynchronSecHubJobExecutor method execute.
@IsSendingSyncMessage(MessageID.START_SCAN)
public void execute(final ScheduleSecHubJob secHubJob, final Long batchJobId) {
Thread scanThread = new Thread(new Runnable() {
@Override
public void run() {
UUID secHubJobUUID = secHubJob.getUUID();
String secHubJobUUIDAsString = secHubJobUUID.toString();
try {
String secHubConfiguration = secHubJob.getJsonConfiguration();
/* own thread so MDC.put necessary */
MDC.clear();
MDC.put(LogConstants.MDC_SECHUB_JOB_UUID, secHubJobUUIDAsString);
MDC.put(LogConstants.MDC_SECHUB_PROJECT_ID, secHubJob.getProjectId());
LOG.info("Executing sechub job: {}", secHubJobUUIDAsString);
/* we send no a synchronous SCAN event */
DomainMessage request = new DomainMessage(MessageID.START_SCAN);
request.set(MessageDataKeys.EXECUTED_BY, secHubJob.getOwner());
request.set(MessageDataKeys.SECHUB_UUID, secHubJobUUID);
request.set(MessageDataKeys.SECHUB_CONFIG, MessageDataKeys.SECHUB_CONFIG.getProvider().get(secHubConfiguration));
BatchJobMessage batchJobIdMessage = new BatchJobMessage();
batchJobIdMessage.setBatchJobId(batchJobId);
batchJobIdMessage.setSecHubJobUUID(secHubJobUUID);
request.set(MessageDataKeys.BATCH_JOB_ID, batchJobIdMessage);
/* wait for scan event result - synchron */
DomainMessageSynchronousResult response = messageService.sendSynchron(request);
updateSecHubJob(secHubJobUUID, response);
sendJobDoneMessageWhenNotAbandonded(secHubJobUUID, response);
} catch (Exception e) {
LOG.error("Error happend at spring batch task execution:" + e.getMessage(), e);
markSechHubJobFailed(secHubJobUUID);
sendJobFailed(secHubJobUUID);
} finally {
/* cleanup MDC */
MDC.clear();
}
}
}, "scan_" + secHubJob.getUUID());
scanThread.start();
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult in project sechub by mercedes-benz.
the class SchedulerRestartJobService method sendPurgeJobResultsSynchronousRequest.
@IsSendingSyncMessage(MessageID.REQUEST_PURGE_JOB_RESULTS)
private void sendPurgeJobResultsSynchronousRequest(ScheduleSecHubJob secHubJob) {
DomainMessage request = DomainMessageFactory.createEmptyRequest(MessageID.REQUEST_PURGE_JOB_RESULTS);
request.set(MessageDataKeys.SECHUB_UUID, secHubJob.getUUID());
request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, sechubEnvironment.getServerBaseUrl());
DomainMessageSynchronousResult result = eventBus.sendSynchron(request);
if (result.hasFailed()) {
throw new SecHubRuntimeException("Purge failed!");
}
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult in project sechub by mercedes-benz.
the class ScanServiceTest method scanservice_does_cleanup_storage_of_job__when_HAS_failed.
/**
* Here we test that on failure the storage is ALSO cleaned. Why? Because in
* future there should be the possiblity for a retry mechanism, but currently
* there is none. When this is implemented we must change the test so it will
* check there is NO cleaning. But having no retry mechanism implemented, we
* expect the cleanup process done even when failing.
*
* @throws Exception
*/
@Test
public void scanservice_does_cleanup_storage_of_job__when_HAS_failed() throws Exception {
/* prepare */
DomainMessage request = prepareValidRequest();
doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any());
/* execute */
DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request);
/* test */
assertTrue(result.hasFailed());
verify(jobStorage).deleteAll();
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult in project sechub by mercedes-benz.
the class ScanServiceTest method scanservice_does_NOT_execute_reportservice_when_webscan_throws_sechubexception.
@Test
public void scanservice_does_NOT_execute_reportservice_when_webscan_throws_sechubexception() throws Exception {
/* prepare */
DomainMessage request = prepareValidRequest();
doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any());
/* execute */
DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request);
/* test */
assertTrue(result.hasFailed());
verify(webScanProductExecutionService).executeProductsAndStoreResults(any());
verify(reportService, never()).createReport(any());
}
Aggregations