From e2af02b819b1bd7dd8f789d43b6901ba4259e405 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Fri, 15 May 2026 15:14:19 +0200 Subject: [PATCH 1/2] do not throw when there is no contingency Signed-off-by: Etienne LESOT --- .../SecurityAnalysisWorkerService.java | 26 ++++++++++++++----- .../server/reports.properties | 1 + 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java index 6cf176d0..fb1c1f2e 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java @@ -44,16 +44,14 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.client.HttpClientErrorException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Function; +import static com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status.NO_CALCULATION; import static org.gridsuite.computation.service.NotificationService.getFailedMessage; import static org.gridsuite.securityanalysis.server.service.SecurityAnalysisService.COMPUTATION_TYPE; @@ -65,7 +63,6 @@ public class SecurityAnalysisWorkerService extends AbstractWorkerService { private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnalysisWorkerService.class); private final ActionsService actionsService; - private final LimitReductionService limitReductionService; private Function securityAnalysisFactorySupplier; @@ -110,6 +107,10 @@ protected String getComputationType() { @Override protected CompletableFuture getCompletableFuture(SecurityAnalysisRunContext runContext, String provider, UUID resultUuid) { + if (runContext.getContingencies().stream().allMatch(contingencyInfos -> contingencyInfos.getContingency() == null)) { + return CompletableFuture.completedFuture( + new SecurityAnalysisResult(new LimitViolationsResult(Collections.emptyList()), NO_CALCULATION, Collections.emptyList())); + } SecurityAnalysis.Runner securityAnalysisRunner = securityAnalysisFactorySupplier.apply(provider); String variantId = runContext.getVariantId() != null ? runContext.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID; @@ -177,8 +178,14 @@ protected void preRun(SecurityAnalysisRunContext runContext) { actionsService.getContingencyList(runContext.getParameters().contingencyListUuids(), runContext.getNetworkUuid(), runContext.getVariantId()) ); runContext.setContingencies(contingencies); + if (contingencies.stream().allMatch(contingencyInfos -> contingencyInfos.getContingency() == null)) { + logNoContingencies(runContext); + return; + } } catch (IllegalArgumentException e) { - throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.CONTINGENCY_LIST_CONFIG_EMPTY, "The configuration does not contain any contingency."); + // Illegal argument exception seems to be linked to no contingency + logNoContingencies(runContext); + return; } catch (HttpClientErrorException.NotFound e) { throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.MISSING_CONTINGENCY_LIST, "The configuration contains one or more contingency lists that have been deleted."); } @@ -290,4 +297,11 @@ private void logContingencyEquipmentsNotConnected(SecurityAnalysisRunContext run }); } + private void logNoContingencies(SecurityAnalysisRunContext runContext) { + runContext.getReportNode().newReportNode() + .withMessageTemplate("security.analysis.server.noContingency") + .withSeverity(TypedValue.WARN_SEVERITY) + .add(); + } + } diff --git a/src/main/resources/org/gridsuite/securityanalysis/server/reports.properties b/src/main/resources/org/gridsuite/securityanalysis/server/reports.properties index ee8d5a57..ee105b98 100644 --- a/src/main/resources/org/gridsuite/securityanalysis/server/reports.properties +++ b/src/main/resources/org/gridsuite/securityanalysis/server/reports.properties @@ -1,4 +1,5 @@ security.analysis.server.notFoundEquipments = Equipments not found security.analysis.server.contingencyEquipmentNotFound = Cannot find the following equipments ${elementsIds} in contingency ${contingencyId} security.analysis.server.notConnectedEquipments = Equipments not connected +security.analysis.server.noContingency = The configuration does not contain any contingency. security.analysis.server.contingencyEquipmentNotConnected = The following equipments ${elementsIds} in contingency ${contingencyId} are not connected From f94d19c163b18b1740e7f38c2207c0b79518974d Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Mon, 18 May 2026 15:06:02 +0200 Subject: [PATCH 2/2] revert Signed-off-by: Etienne LESOT --- .../server/service/SecurityAnalysisWorkerService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java index fb1c1f2e..71f74797 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java @@ -183,9 +183,7 @@ protected void preRun(SecurityAnalysisRunContext runContext) { return; } } catch (IllegalArgumentException e) { - // Illegal argument exception seems to be linked to no contingency - logNoContingencies(runContext); - return; + throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.CONTINGENCY_LIST_CONFIG_EMPTY, "The configuration does not contain any contingency."); } catch (HttpClientErrorException.NotFound e) { throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.MISSING_CONTINGENCY_LIST, "The configuration contains one or more contingency lists that have been deleted."); }