Search in sources :

Example 1 with SecHubExecutionAbandonedException

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

the class ScanJobExecutor method handleCanceled.

private void handleCanceled(CanceableScanJobRunnable canceableJobRunner, UUID sechubJobUUID) throws SecHubExecutionAbandonedException {
    LOG.info("Received cancel signal, so start canceling job: {}", sechubJobUUID);
    canceableJobRunner.cancelScanJob();
    if (!(progress instanceof Abandonable)) {
        return;
    }
    Abandonable abandoble = (Abandonable) progress;
    LOG.info("Check if job {} shall be abandoned", sechubJobUUID);
    if (abandoble.isAbandoned()) {
        LOG.info("Must abandon {}", sechubJobUUID);
        throw new SecHubExecutionAbandonedException(context, "Abandonded job " + sechubJobUUID + " because canceled", null);
    }
}
Also used : SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) Abandonable(com.mercedesbenz.sechub.sharedkernel.Abandonable)

Example 2 with SecHubExecutionAbandonedException

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

the class ScanJobExecutor method handleErrors.

private void handleErrors(SecHubExecutionException exception) throws SecHubExecutionException {
    if (exception == null) {
        /* no failure - so just return */
        return;
    }
    /*
         * abdoned exception are treated special: executor will NOT persist result in
         * this case!
         */
    if (exception instanceof SecHubExecutionAbandonedException) {
        LOG.debug("Rethrow SecHubExecutionAbandonedException");
        // just rethrow abandoned
        throw exception;
    }
    LOG.debug("No SecHubExecutionAbandonedException");
    if (progress instanceof Abandonable) {
        LOG.debug("Start abandoble check");
        Abandonable abandonable = (Abandonable) progress;
        if (abandonable.isAbandoned()) {
            LOG.debug("Done abandoble check- IS abandonded");
            throw new SecHubExecutionAbandonedException(context, "A failure happend, but already abandoned job", exception);
        }
        LOG.debug("Done abandoble check- not abandonded");
    }
    LOG.debug("Rethrow normal sechub execution exception");
    throw exception;
}
Also used : SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) Abandonable(com.mercedesbenz.sechub.sharedkernel.Abandonable)

Example 3 with SecHubExecutionAbandonedException

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

SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)3 Abandonable (com.mercedesbenz.sechub.sharedkernel.Abandonable)2 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 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)1 IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)1 IOException (java.io.IOException)1