Search in sources :

Example 1 with IsSendingSyncMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage 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 2 with IsSendingSyncMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage 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 3 with IsSendingSyncMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage in project sechub by mercedes-benz.

the class ScanProgressMonitor method sendRequestBatchJobStatusRequestSynchron.

@IsSendingSyncMessage(MessageID.REQUEST_BATCH_JOB_STATUS)
protected BatchJobMessage sendRequestBatchJobStatusRequestSynchron() {
    DomainMessage request = new DomainMessage(MessageID.REQUEST_BATCH_JOB_STATUS);
    BatchJobMessage statusRequestMessage = new BatchJobMessage();
    statusRequestMessage.setBatchJobId(batchJobId);
    request.set(MessageDataKeys.BATCH_JOB_STATUS, statusRequestMessage);
    /* ask for status */
    DomainMessageSynchronousResult response = eventBus.sendSynchron(request);
    BatchJobMessage jobStatusRepsonse = response.get(MessageDataKeys.BATCH_JOB_STATUS);
    return jobStatusRepsonse;
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingSyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)

Aggregations

DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)3 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)3 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)3 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 UUID (java.util.UUID)1