Search in sources :

Example 1 with IsSendingSyncMessageAnswer

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

the class DomainMessagingModel method updateGivenDomainPartMessageInfoList.

private <T extends Annotation> void updateGivenDomainPartMessageInfoList(Class<T> clazz, MessageID messageId, List<DomainPartMessageInfo<T>> list, Domain domain, DomainPart domainPart) {
    List<T> receiverClazzList = domainPart.fetchList(clazz);
    if (DEBUG) {
        LOG.info(" >enter:{},{}, found:{}", domain, domainPart, list);
    }
    for (T receiverClazz : receiverClazzList) {
        MessageID foundMessageId = getMessageIdToSearchFor(receiverClazz);
        boolean sameMessageId = foundMessageId == messageId;
        if (sameMessageId) {
            DomainPartMessageInfo<T> info = new DomainPartMessageInfo<>();
            info.messageInfo = receiverClazz;
            info.part = domainPart;
            if (receiverClazz instanceof IsSendingSyncMessageAnswer) {
                IsSendingSyncMessageAnswer answer = (IsSendingSyncMessageAnswer) receiverClazz;
                info.messageId = answer.value();
                info.answeringTo = answer.answeringTo();
                info.branchName = answer.branchName();
            } else {
                info.messageId = messageId;
            }
            list.add(info);
        }
    }
}
Also used : IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer) MessageID(com.mercedesbenz.sechub.sharedkernel.messaging.MessageID)

Example 2 with IsSendingSyncMessageAnswer

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

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

the class ScanMessageHandler method purgeDone.

@IsSendingSyncMessageAnswer(value = MessageID.JOB_RESULT_PURGE_DONE, answeringTo = MessageID.REQUEST_PURGE_JOB_RESULTS, branchName = "success")
private DomainMessageSynchronousResult purgeDone(UUID jobUUID) {
    DomainMessageSynchronousResult result = new DomainMessageSynchronousResult(MessageID.JOB_RESULT_PURGE_DONE);
    result.set(MessageDataKeys.SECHUB_UUID, jobUUID);
    return result;
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Example 4 with IsSendingSyncMessageAnswer

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

the class ScanMessageHandler method purgeFailed.

@IsSendingSyncMessageAnswer(value = MessageID.JOB_RESULT_PURGE_FAILED, answeringTo = MessageID.REQUEST_PURGE_JOB_RESULTS, branchName = "failed")
private DomainMessageSynchronousResult purgeFailed(UUID jobUUID, Exception e) {
    DomainMessageSynchronousResult result = new DomainMessageSynchronousResult(MessageID.JOB_RESULT_PURGE_FAILED, e);
    result.set(MessageDataKeys.SECHUB_UUID, jobUUID);
    return result;
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Example 5 with IsSendingSyncMessageAnswer

use of com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer 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);
            }
        }
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) 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) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Aggregations

IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)5 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)4 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)1 MessageID (com.mercedesbenz.sechub.sharedkernel.messaging.MessageID)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 BatchStatus (org.springframework.batch.core.BatchStatus)1 JobExecution (org.springframework.batch.core.JobExecution)1