Search in sources :

Example 11 with SecHubExecutionException

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

Example 12 with SecHubExecutionException

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.

the class SecHubReportProductTransformerService method createResult.

ReportTransformationResult createResult(UUID secHubJobUUID) throws SecHubExecutionException {
    notNull(secHubJobUUID, "secHubJobUUID may not be null!");
    List<ProductResult> reportProductResults = productResultRepository.findAllProductResults(secHubJobUUID, SERECO);
    if (reportProductResults.isEmpty()) {
        throw new SecHubExecutionException("No report result found for:" + secHubJobUUID);
    }
    int reportProductResultAmount = reportProductResults.size();
    if (reportProductResultAmount > 1) {
        LOG.warn("Found {} report product results, should normally be only one!", reportProductResultAmount);
    }
    ReportTransformationResult transformResult = null;
    for (ProductResult reportProductResult : reportProductResults) {
        for (ReportProductResultTransformer transformer : transformers) {
            if (transformer.canTransform(reportProductResult.getProductIdentifier())) {
                LOG.debug("Transformer {} is used to transform result", transformer.getClass().getSimpleName());
                ReportTransformationResult transformedResult = transformer.transform(reportProductResult);
                transformResult = resultMerger.merge(transformResult, transformedResult);
            }
        }
    }
    if (transformResult == null) {
        throw new SecHubExecutionException("No transformable report result format found for:" + secHubJobUUID);
    }
    return transformResult;
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ReportProductResultTransformer(com.mercedesbenz.sechub.domain.scan.report.ReportProductResultTransformer)

Example 13 with SecHubExecutionException

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.

the class AbstractProductExecutionService method executeProductsAndStoreResults.

/**
 * Executes product executors and stores results. If a result of an executor is
 * <code>null</code> an error will be logged but
 *
 * @param context
 * @throws SecHubExecutionException
 */
public void executeProductsAndStoreResults(SecHubExecutionContext context) throws SecHubExecutionException {
    try {
        UUIDTraceLogID traceLogID = traceLogID(context.getSechubJobUUID());
        SecHubConfiguration configuration = context.getConfiguration();
        if (context.isCanceledOrAbandonded()) {
            LOG.debug("{} canceled or abandoned, so ignored by {}", traceLogID, getClass().getSimpleName());
            return;
        }
        if (!isExecutionNecessary(context, traceLogID, configuration)) {
            LOG.debug("{} NO execution necessary by {}", traceLogID, getClass().getSimpleName());
            return;
        }
        runOnAllAvailableExecutors(getProductExecutors(), context, traceLogID);
    } catch (RuntimeException e) {
        /* catch runtime errors and move and wrapt in SecHubExecutionException */
        throw new SecHubExecutionException("Product execution + store failed unexpected", e);
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)

Example 14 with SecHubExecutionException

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException in project sechub by mercedes-benz.

the class AbstractInstallSetupProductExecutor method execute.

@Override
public final List<ProductResult> execute(SecHubExecutionContext context, ProductExecutorContext executorContext) throws SecHubExecutionException {
    UUIDTraceLogID traceLogId = context.getTraceLogId();
    LOG.debug("Executing {}", traceLogId);
    SecHubConfiguration config = context.getConfiguration();
    S setup = getInstallSetup();
    TargetRegistry registry = createTargetRegistry();
    List<URI> uris = resolveURIsForTarget(config);
    registerURIs(traceLogId, setup, registry, uris);
    List<InetAddress> inetAdresses = resolveInetAdressForTarget(config);
    registerInetAdresses(traceLogId, setup, registry, inetAdresses);
    customRegistration(traceLogId, setup, registry, config);
    try {
        return execute(context, executorContext, registry, setup);
    } catch (SecHubExecutionException e) {
        throw e;
    } catch (Exception e) {
        /*
             * every other exception is wrapped to a SecHub execution exception which is
             * handled
             */
        throw new SecHubExecutionException(getIdentifier() + " execution failed." + traceLogId, e);
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) TargetRegistry(com.mercedesbenz.sechub.domain.scan.TargetRegistry) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) URI(java.net.URI) InetAddress(java.net.InetAddress) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Aggregations

SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)14 Test (org.junit.Test)6 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)3 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)3 UUID (java.util.UUID)3 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)2 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)2 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)2 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)2 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 IOException (java.io.IOException)2 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)1 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)1 TrafficLight (com.mercedesbenz.sechub.commons.model.TrafficLight)1 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)1 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)1 TargetRegistry (com.mercedesbenz.sechub.domain.scan.TargetRegistry)1 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)1