Skip to content

Commit e26f652

Browse files
authored
Remove filter extension for in-memory copy with OLF (#165)
1 parent abdaf0e commit e26f652

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisWorkerService.java

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.gridsuite.securityanalysis.server.service;
88

99
import com.fasterxml.jackson.databind.ObjectMapper;
10-
import com.powsybl.commons.io.TreeDataFormat;
1110
import com.powsybl.commons.report.ReportNode;
1211
import com.powsybl.commons.report.TypedValue;
1312
import com.powsybl.contingency.Contingency;
@@ -21,8 +20,6 @@
2120
import com.powsybl.iidm.network.Network;
2221
import com.powsybl.iidm.network.NetworkFactory;
2322
import com.powsybl.iidm.network.VariantManagerConstants;
24-
import com.powsybl.iidm.serde.ExportOptions;
25-
import com.powsybl.iidm.serde.ImportOptions;
2623
import com.powsybl.iidm.serde.NetworkSerDe;
2724
import com.powsybl.loadflow.LoadFlowResult;
2825
import com.powsybl.network.store.client.NetworkStoreService;
@@ -43,10 +40,8 @@
4340
import org.springframework.stereotype.Service;
4441
import org.springframework.util.CollectionUtils;
4542

46-
import java.io.*;
4743
import java.util.*;
4844
import java.util.concurrent.CompletableFuture;
49-
import java.util.concurrent.ForkJoinPool;
5045
import java.util.concurrent.TimeUnit;
5146
import java.util.concurrent.atomic.AtomicReference;
5247
import 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

Comments
 (0)