77package org .gridsuite .securityanalysis .server .service ;
88
99import com .fasterxml .jackson .databind .ObjectMapper ;
10- import com .powsybl .commons .io .TreeDataFormat ;
1110import com .powsybl .commons .report .ReportNode ;
1211import com .powsybl .commons .report .TypedValue ;
1312import com .powsybl .contingency .Contingency ;
2120import com .powsybl .iidm .network .Network ;
2221import com .powsybl .iidm .network .NetworkFactory ;
2322import com .powsybl .iidm .network .VariantManagerConstants ;
24- import com .powsybl .iidm .serde .ExportOptions ;
25- import com .powsybl .iidm .serde .ImportOptions ;
2623import com .powsybl .iidm .serde .NetworkSerDe ;
2724import com .powsybl .loadflow .LoadFlowResult ;
2825import com .powsybl .network .store .client .NetworkStoreService ;
4340import org .springframework .stereotype .Service ;
4441import org .springframework .util .CollectionUtils ;
4542
46- import java .io .*;
4743import java .util .*;
4844import java .util .concurrent .CompletableFuture ;
49- import java .util .concurrent .ForkJoinPool ;
5045import java .util .concurrent .TimeUnit ;
5146import java .util .concurrent .atomic .AtomicReference ;
5247import java .util .function .Consumer ;
@@ -68,22 +63,6 @@ public class SecurityAnalysisWorkerService extends AbstractWorkerService<Securit
6863
6964 private Function <String , SecurityAnalysis .Runner > securityAnalysisFactorySupplier ;
7065
71- private static final Set <String > OPENLOADFLOW_SECURITY_ANALYSIS_EXTENSIONS = Set .of (
72- "detail" ,
73- "slackTerminal" ,
74- "activePowerControl" ,
75- "voltageRegulation" ,
76- "lineFortescue" ,
77- "loadAsymmetrical" ,
78- "coordinatedReactiveControl" ,
79- "generatorFortescue" ,
80- "hvdcAngleDroopActivePowerControl" ,
81- "hvdcOperatorActivePowerRange" ,
82- "secondaryVoltageControl" ,
83- "voltagePerReactivePowerControl" ,
84- "standbyAutomaton" ,
85- "generatorRemoteReactivePowerControl" );
86-
8766 public SecurityAnalysisWorkerService (NetworkStoreService networkStoreService , ActionsService actionsService , ReportService reportService ,
8867 SecurityAnalysisResultService resultService , ObjectMapper objectMapper ,
8968 SecurityAnalysisRunnerSupplier securityAnalysisRunnerSupplier , NotificationService notificationService , ExecutionService executionService ,
@@ -140,7 +119,7 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
140119 String originalVariant = originalNetwork .getVariantManager ().getWorkingVariantId ();
141120 originalNetwork .getVariantManager ().setWorkingVariant (variantId );
142121
143- network = copy (originalNetwork , NetworkFactory .find ("Default" ));
122+ network = NetworkSerDe . copy (originalNetwork , NetworkFactory .find ("Default" ));
144123 if (!variantId .equals (VariantManagerConstants .INITIAL_VARIANT_ID )) {
145124 network .getVariantManager ().cloneVariant (VariantManagerConstants .INITIAL_VARIANT_ID , variantId );
146125 }
@@ -163,30 +142,6 @@ protected CompletableFuture<SecurityAnalysisResult> getCompletableFuture(Securit
163142 .thenApply (SecurityAnalysisReport ::getResult );
164143 }
165144
166- private static Network copy (Network network , NetworkFactory networkFactory ) {
167- Objects .requireNonNull (network );
168- Objects .requireNonNull (networkFactory );
169- PipedOutputStream pos = new PipedOutputStream ();
170- try (InputStream is = new PipedInputStream (pos )) {
171- ForkJoinPool .commonPool ().execute (() -> {
172- try {
173- NetworkSerDe .write (network , new ExportOptions ().setExtensions (OPENLOADFLOW_SECURITY_ANALYSIS_EXTENSIONS ).setFormat (TreeDataFormat .JSON ), pos );
174- } catch (Exception t ) {
175- LOGGER .error (t .toString (), t );
176- } finally {
177- try {
178- pos .close ();
179- } catch (IOException e ) {
180- LOGGER .error (e .toString (), e );
181- }
182- }
183- });
184- return NetworkSerDe .read (is , new ImportOptions ().setExtensions (OPENLOADFLOW_SECURITY_ANALYSIS_EXTENSIONS ).setFormat (TreeDataFormat .JSON ), null , networkFactory , ReportNode .NO_OP );
185- } catch (IOException e ) {
186- throw new UncheckedIOException (e );
187- }
188- }
189-
190145 private List <LimitReduction > createLimitReductions (SecurityAnalysisRunContext runContext ) {
191146 List <LimitReduction > limitReductions = new ArrayList <>(limitReductionService .getVoltageLevels ().size () * limitReductionService .getLimitDurations ().size ());
192147
0 commit comments