From 7abb2b5884caa17b33afbaa797b4e1bc88a46477 Mon Sep 17 00:00:00 2001 From: lisrte Date: Tue, 14 May 2024 17:24:13 +0200 Subject: [PATCH] Fix Breaking change Signed-off-by: lisrte --- .../DynaFlowSecurityAnalysisProvider.java | 33 +++++-------------- .../DynaFlowSecurityAnalysisTest.java | 20 ++++------- .../com/powsybl/dynawo/it/DynaFlowTest.java | 18 +++++----- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisProvider.java b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisProvider.java index bbcacc572..0e1bcb48c 100644 --- a/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisProvider.java +++ b/dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisProvider.java @@ -7,21 +7,14 @@ package com.powsybl.dynaflow; import com.google.auto.service.AutoService; -import com.powsybl.action.Action; import com.powsybl.commons.report.ReportNode; -import com.powsybl.computation.ComputationManager; import com.powsybl.contingency.ContingenciesProvider; import com.powsybl.dynawo.commons.PowsyblDynawoVersion; import com.powsybl.iidm.network.Network; import com.powsybl.security.*; -import com.powsybl.security.interceptors.SecurityAnalysisInterceptor; -import com.powsybl.security.limitreduction.LimitReduction; -import com.powsybl.security.monitor.StateMonitor; -import com.powsybl.security.strategy.OperatorStrategy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.List; import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -49,37 +42,29 @@ public DynaFlowSecurityAnalysisProvider(Supplier configSupplier) @Override public CompletableFuture run(Network network, String workingVariantId, - LimitViolationDetector detector, - LimitViolationFilter filter, - ComputationManager computationManager, - SecurityAnalysisParameters parameters, ContingenciesProvider contingenciesProvider, - List interceptors, - List operatorStrategies, - List actions, - List monitors, - List limitReductions, + SecurityAnalysisRunParameters runParameters, ReportNode reportNode) { - if (detector != null) { + if (runParameters.getDetector() != null) { LOG.error("LimitViolationDetector is not used in Dynaflow implementation."); } - if (monitors != null && !monitors.isEmpty()) { + if (runParameters.getMonitors() != null && !runParameters.getMonitors().isEmpty()) { LOG.error("Monitoring is not possible with Dynaflow implementation. There will not be supplementary information about monitored equipment."); } - if (operatorStrategies != null && !operatorStrategies.isEmpty()) { + if (runParameters.getOperatorStrategies() != null && !runParameters.getOperatorStrategies().isEmpty()) { LOG.error("Strategies are not implemented in Dynaflow"); } - if (actions != null && !actions.isEmpty()) { + if (runParameters.getActions() != null && !runParameters.getActions().isEmpty()) { LOG.error("Actions are not implemented in Dynaflow"); } - if (limitReductions != null && !limitReductions.isEmpty()) { + if (runParameters.getLimitReductions() != null && !runParameters.getLimitReductions().isEmpty()) { LOG.error("Limit reductions are not implemented in Dynaflow"); } - DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, filter, computationManager, configSupplier); - interceptors.forEach(securityAnalysis::addInterceptor); + DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, runParameters.getFilter(), runParameters.getComputationManager(), configSupplier); + runParameters.getInterceptors().forEach(securityAnalysis::addInterceptor); ReportNode dfsaReportNode = DynaflowReports.createDynaFlowSecurityAnalysisReportNode(reportNode, network.getId()); - return securityAnalysis.run(workingVariantId, parameters, contingenciesProvider, dfsaReportNode); + return securityAnalysis.run(workingVariantId, runParameters.getSecurityAnalysisParameters(), contingenciesProvider, dfsaReportNode); } @Override diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java index 454a0c920..554629932 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowSecurityAnalysisTest.java @@ -8,19 +8,14 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.commons.test.AbstractSerDeTest; -import com.powsybl.computation.ComputationManager; import com.powsybl.computation.local.LocalCommandExecutor; import com.powsybl.computation.local.LocalComputationConfig; import com.powsybl.computation.local.LocalComputationManager; -import com.powsybl.contingency.ContingenciesProvider; import com.powsybl.contingency.Contingency; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.loadflow.LoadFlowResult; -import com.powsybl.security.SecurityAnalysis; -import com.powsybl.security.SecurityAnalysisParameters; -import com.powsybl.security.SecurityAnalysisReport; -import com.powsybl.security.SecurityAnalysisResult; +import com.powsybl.security.*; import com.powsybl.security.json.SecurityAnalysisResultSerializer; import org.junit.jupiter.api.Test; @@ -120,9 +115,9 @@ void test() throws IOException { LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_version.out", "/SecurityAnalysis/input.xiidm", "/SecurityAnalysis/contingencies.json", contingencyIds, List.of("/SecurityAnalysis/constraints1.xml", "/SecurityAnalysis/constraints2.xml")); - ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()); - - SecurityAnalysisReport report = SecurityAnalysis.run(network, n -> contingencies, SecurityAnalysisParameters.load(), computationManager); + SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters() + .setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool())); + SecurityAnalysisReport report = SecurityAnalysis.run(network, contingencies, runParameters); SecurityAnalysisResult result = report.getResult(); assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getPreContingencyResult().getStatus()); @@ -134,11 +129,10 @@ void test() throws IOException { @Test void testCallingBadVersionDynawo() throws IOException { Network network = Network.create("test", "test"); - ContingenciesProvider contingenciesProvider = n -> List.of(); LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_bad_version.out", null); - ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()); - SecurityAnalysisParameters sap = SecurityAnalysisParameters.load(); - assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, contingenciesProvider, sap, computationManager)); + SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters() + .setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool())); + assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, List.of(), runParameters)); } private static Network buildNetwork() { diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java index bc4307ec4..a0d8f71f8 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java @@ -22,10 +22,9 @@ import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory; import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.loadflow.LoadFlowResult; -import com.powsybl.security.LimitViolationFilter; import com.powsybl.security.SecurityAnalysisParameters; import com.powsybl.security.SecurityAnalysisResult; -import com.powsybl.security.detectors.DefaultLimitViolationDetector; +import com.powsybl.security.SecurityAnalysisRunParameters; import com.powsybl.security.json.SecurityAnalysisResultSerializer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +34,6 @@ import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -125,9 +123,10 @@ void testSaBb() throws IOException { .toList(); ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate("root", "Root message").build(); - SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, new DefaultLimitViolationDetector(), - new LimitViolationFilter(), computationManager, securityAnalysisParameters, n -> contingencies, Collections.emptyList(), - Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), reportNode) + SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters() + .setComputationManager(computationManager) + .setSecurityAnalysisParameters(securityAnalysisParameters); + SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, n -> contingencies, runParameters, reportNode) .join() .getResult(); @@ -151,9 +150,10 @@ void testSaNb() throws IOException { List contingencies = network.getGeneratorStream() .map(g -> Contingency.generator(g.getId())) .toList(); - SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, new DefaultLimitViolationDetector(), - new LimitViolationFilter(), computationManager, securityAnalysisParameters, n -> contingencies, Collections.emptyList(), - Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), ReportNode.NO_OP) + SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters() + .setComputationManager(computationManager) + .setSecurityAnalysisParameters(securityAnalysisParameters); + SecurityAnalysisResult result = securityAnalysisProvider.run(network, VariantManagerConstants.INITIAL_VARIANT_ID, n -> contingencies, runParameters, ReportNode.NO_OP) .join() .getResult();