Search in sources :

Example 1 with BatchJobMessage

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

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

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

the class ScanServiceTest method prepareRequest.

private DomainMessage prepareRequest(SecHubConfiguration configMin) {
    DomainMessage request = new DomainMessage(MessageID.START_SCAN);
    request.set(MessageDataKeys.SECHUB_UUID, UUID);
    request.set(MessageDataKeys.SECHUB_CONFIG, configMin);
    BatchJobMessage batchJobMessage = new BatchJobMessage();
    batchJobMessage.setSecHubJobUUID(UUID);
    batchJobMessage.setBatchJobId(42);
    request.set(MessageDataKeys.BATCH_JOB_ID, batchJobMessage);
    return request;
}
Also used : BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)

Example 4 with BatchJobMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage 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)

Example 5 with BatchJobMessage

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

the class ScanService method executeScan.

protected void executeScan(SecHubExecutionContext context, DomainMessage request) throws SecHubExecutionException {
    DomainDataTraceLogID sechubJobUUID = traceLogID(request);
    LOG.info("start scan for {}", sechubJobUUID);
    UUID logUUID = scanLogService.logScanStarted(context);
    try {
        BatchJobMessage jobIdMessage = request.get(MessageDataKeys.BATCH_JOB_ID);
        if (jobIdMessage == null) {
            throw new IllegalStateException("no batch job id set for sechub job:" + sechubJobUUID);
        }
        long batchJobId = jobIdMessage.getBatchJobId();
        ProgressMonitor progressMonitor = monitorFactory.createProgressMonitor(batchJobId);
        /* delegate execution : */
        ScanJobExecutor executor = new ScanJobExecutor(this, context, progressMonitor, millisecondsToWaitBeforeCancelCheck);
        executor.execute();
        scanLogService.logScanEnded(logUUID);
    } catch (Exception e) {
        if (context.isAbandonded()) {
            scanLogService.logScanAbandoned(logUUID);
        } else {
            scanLogService.logScanFailed(logUUID);
        }
        /* rethrow when already an execution exception */
        if (e instanceof SecHubExecutionException) {
            SecHubExecutionException exceptionToRethrow = (SecHubExecutionException) e;
            throw exceptionToRethrow;
        }
        /* wrap it */
        throw new SecHubExecutionException("Execute scan failed", e);
    }
}
Also used : ProgressMonitor(com.mercedesbenz.sechub.sharedkernel.ProgressMonitor) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) DomainDataTraceLogID(com.mercedesbenz.sechub.sharedkernel.messaging.DomainDataTraceLogID) UUID(java.util.UUID) JSONConverterException(com.mercedesbenz.sechub.commons.model.JSONConverterException) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) IOException(java.io.IOException) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Aggregations

BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)5 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)3 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)3 UUID (java.util.UUID)3 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 ProgressMonitor (com.mercedesbenz.sechub.sharedkernel.ProgressMonitor)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 DomainDataTraceLogID (com.mercedesbenz.sechub.sharedkernel.messaging.DomainDataTraceLogID)1 IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)1 IOException (java.io.IOException)1 BatchStatus (org.springframework.batch.core.BatchStatus)1 JobExecution (org.springframework.batch.core.JobExecution)1