Search in sources :

Example 1 with DomainMessageSynchronousResult

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;
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) BatchStatus(org.springframework.batch.core.BatchStatus) UUID(java.util.UUID) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Example 2 with DomainMessageSynchronousResult

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();
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) UUID(java.util.UUID) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingSyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)

Example 3 with DomainMessageSynchronousResult

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!");
    }
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingSyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)

Example 4 with DomainMessageSynchronousResult

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();
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 5 with DomainMessageSynchronousResult

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());
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Aggregations

DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)15 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)8 Test (org.junit.Test)8 IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)4 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)3 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)3 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)3 UUID (java.util.UUID)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 IOException (java.io.IOException)1 BatchStatus (org.springframework.batch.core.BatchStatus)1 JobExecution (org.springframework.batch.core.JobExecution)1