Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gridsuite dependencies 27 #89

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<jaxb-api.version>2.4.0-b180830.0359</jaxb-api.version>
<jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>
<jib.from.image>gridsuite/java-simulator:2.0.0</jib.from.image>
<gridsuite-dependencies.version>26</gridsuite-dependencies.version>
<gridsuite-dependencies.version>27</gridsuite-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
</properties>

Expand Down Expand Up @@ -118,10 +118,6 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-contingency-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-mergingview</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-xml-converter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.UUID;

Expand All @@ -50,10 +49,6 @@ public SecurityAnalysisController(SecurityAnalysisService service, SecurityAnaly
this.workerService = workerService;
}

private static List<UUID> getNonNullOtherNetworkUuids(List<UUID> otherNetworkUuids) {
return otherNetworkUuids != null ? otherNetworkUuids : Collections.emptyList();
}

@PostMapping(value = "/networks/{networkUuid}/run", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Run a security analysis on a network")
@ApiResponses(value = {@ApiResponse(responseCode = "200",
Expand All @@ -62,15 +57,14 @@ private static List<UUID> getNonNullOtherNetworkUuids(List<UUID> otherNetworkUui
schema = @Schema(implementation = SecurityAnalysisResult.class))})})
public ResponseEntity<SecurityAnalysisResult> run(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Other networks UUID (to merge with main one))") @RequestParam(name = "networkUuid", required = false) List<UUID> otherNetworkUuids,
@Parameter(description = "Contingency list name") @RequestParam(name = "contingencyListName", required = false) List<String> contigencyListNames,
@Parameter(description = "Provider") @RequestParam(name = "provider", required = false) String provider,
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@RequestBody(required = false) SecurityAnalysisParametersInfos parameters) {
String providerToUse = provider != null ? provider : service.getDefaultProvider();
List<UUID> nonNullOtherNetworkUuids = getNonNullOtherNetworkUuids(otherNetworkUuids);
SecurityAnalysisResult result = workerService.run(new SecurityAnalysisRunContext(networkUuid, variantId, nonNullOtherNetworkUuids, contigencyListNames, null, providerToUse, parameters, reportUuid, reporterId));
SecurityAnalysisResult result = workerService.run(new SecurityAnalysisRunContext(networkUuid, variantId, contigencyListNames, null, providerToUse, parameters, reportUuid, reporterId));

return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(result);
}

Expand All @@ -82,16 +76,14 @@ public ResponseEntity<SecurityAnalysisResult> run(@Parameter(description = "Netw
schema = @Schema(implementation = SecurityAnalysisResult.class))})})
public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid,
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Other networks UUID (to merge with main one))") @RequestParam(name = "networkUuid", required = false) List<UUID> otherNetworkUuids,
@Parameter(description = "Contingency list name") @RequestParam(name = "contingencyListName", required = false) List<String> contigencyListNames,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@Parameter(description = "Provider") @RequestParam(name = "provider", required = false) String provider,
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@RequestBody(required = false) SecurityAnalysisParametersInfos parameters) {
String providerToUse = provider != null ? provider : service.getDefaultProvider();
List<UUID> nonNullOtherNetworkUuids = getNonNullOtherNetworkUuids(otherNetworkUuids);
UUID resultUuid = service.runAndSaveResult(new SecurityAnalysisRunContext(networkUuid, variantId, nonNullOtherNetworkUuids, contigencyListNames, receiver, providerToUse, parameters, reportUuid, reporterId));
UUID resultUuid = service.runAndSaveResult(new SecurityAnalysisRunContext(networkUuid, variantId, contigencyListNames, receiver, providerToUse, parameters, reportUuid, reporterId));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class NotificationService {
public static final String MESSAGE_HEADER = "message";
public static final String NETWORK_UUID_HEADER = "networkUuid";
public static final String VARIANT_ID_HEADER = "variantId";
public static final String OTHER_NETWORK_UUIDS_HEADER = "otherNetworkUuids";
public static final String CONTINGENCY_LIST_NAMES_HEADER = "contingencyListNames";
public static final String PROVIDER_HEADER = "provider";
public static final String REPORT_UUID_HEADER = "reportUuid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;

import static org.gridsuite.securityanalysis.server.service.NotificationService.*;

Expand Down Expand Up @@ -68,10 +67,6 @@ public static SecurityAnalysisResultContext fromMessage(Message<String> message,
UUID resultUuid = UUID.fromString(getNonNullHeader(headers, RESULT_UUID_HEADER));
UUID networkUuid = UUID.fromString(getNonNullHeader(headers, NETWORK_UUID_HEADER));
String variantId = (String) headers.get(VARIANT_ID_HEADER);
List<UUID> otherNetworkUuids = getHeaderList(headers, OTHER_NETWORK_UUIDS_HEADER)
.stream()
.map(UUID::fromString)
.collect(Collectors.toList());
List<String> contingencyListNames = getHeaderList(headers, CONTINGENCY_LIST_NAMES_HEADER);
String receiver = (String) headers.get(RECEIVER_HEADER);
String provider = (String) headers.get(PROVIDER_HEADER);
Expand All @@ -83,7 +78,7 @@ public static SecurityAnalysisResultContext fromMessage(Message<String> message,
}
UUID reportUuid = headers.containsKey(REPORT_UUID_HEADER) ? UUID.fromString((String) headers.get(REPORT_UUID_HEADER)) : null;
String reporterId = headers.containsKey(REPORTER_ID_HEADER) ? (String) headers.get(REPORTER_ID_HEADER) : null;
SecurityAnalysisRunContext runContext = new SecurityAnalysisRunContext(networkUuid, variantId, otherNetworkUuids, contingencyListNames, receiver, provider, parameters, reportUuid, reporterId);
SecurityAnalysisRunContext runContext = new SecurityAnalysisRunContext(networkUuid, variantId, contingencyListNames, receiver, provider, parameters, reportUuid, reporterId);
return new SecurityAnalysisResultContext(resultUuid, runContext);
}

Expand All @@ -98,8 +93,6 @@ public Message<String> toMessage(ObjectMapper objectMapper) {
.setHeader(RESULT_UUID_HEADER, resultUuid.toString())
.setHeader(NETWORK_UUID_HEADER, runContext.getNetworkUuid().toString())
.setHeader(VARIANT_ID_HEADER, runContext.getVariantId())
.setHeader(OTHER_NETWORK_UUIDS_HEADER, runContext.getOtherNetworkUuids().stream()
.map(UUID::toString).collect(Collectors.joining(",")))
.setHeader(CONTINGENCY_LIST_NAMES_HEADER, String.join(",", runContext.getContingencyListNames()))
.setHeader(RECEIVER_HEADER, runContext.getReceiver())
.setHeader(PROVIDER_HEADER, runContext.getProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class SecurityAnalysisRunContext {

private final String variantId;

private final List<UUID> otherNetworkUuids;

private final List<String> contingencyListNames;

private final String receiver;
Expand All @@ -40,16 +38,15 @@ public class SecurityAnalysisRunContext {

private final String reporterId;

public SecurityAnalysisRunContext(UUID networkUuid, String variantId, List<UUID> otherNetworkUuids, List<String> contingencyListNames,
public SecurityAnalysisRunContext(UUID networkUuid, String variantId, List<String> contingencyListNames,
String receiver, String provider, SecurityAnalysisParametersInfos parameters, UUID reportUuid, String reporterId) {
this(networkUuid, variantId, otherNetworkUuids, contingencyListNames, receiver, provider, buildParameters(parameters, provider), reportUuid, reporterId);
this(networkUuid, variantId, contingencyListNames, receiver, provider, buildParameters(parameters, provider), reportUuid, reporterId);
}

public SecurityAnalysisRunContext(UUID networkUuid, String variantId, List<UUID> otherNetworkUuids, List<String> contingencyListNames,
public SecurityAnalysisRunContext(UUID networkUuid, String variantId, List<String> contingencyListNames,
String receiver, String provider, SecurityAnalysisParameters parameters, UUID reportUuid, String reporterId) {
this.networkUuid = Objects.requireNonNull(networkUuid);
this.variantId = variantId;
this.otherNetworkUuids = Objects.requireNonNull(otherNetworkUuids);
this.contingencyListNames = Objects.requireNonNull(contingencyListNames);
this.receiver = receiver;
this.provider = provider;
Expand Down Expand Up @@ -81,10 +78,6 @@ public String getVariantId() {
return variantId;
}

public List<UUID> getOtherNetworkUuids() {
return otherNetworkUuids;
}

public List<String> getContingencyListNames() {
return contingencyListNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.mergingview.MergingView;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.loadflow.LoadFlowResult;
Expand All @@ -34,7 +33,6 @@
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,27 +110,6 @@ private Network getNetwork(UUID networkUuid) {
}
}

private Network getNetwork(UUID networkUuid, List<UUID> otherNetworkUuids) {
Network network = getNetwork(networkUuid);
if (otherNetworkUuids.isEmpty()) {
return network;
} else {
List<Network> networks = new ArrayList<>();
List<Network> otherNetworks = otherNetworkUuids
.stream()
.map(this::getNetwork)
.collect(Collectors.toList());

networks.add(network);
networks.addAll(otherNetworks);

MergingView mergingView = MergingView.create("merge", "iidm");
mergingView.merge(networks.toArray(new Network[0]));

return mergingView;
}
}

public SecurityAnalysisResult run(SecurityAnalysisRunContext context) {
return run(context, null);
}
Expand Down Expand Up @@ -201,7 +178,7 @@ private SecurityAnalysisResult run(SecurityAnalysisRunContext context, UUID resu

LOGGER.info("Run security analysis on contingency lists: {}", context.getContingencyListNames().stream().map(LogUtils::sanitizeParam).collect(Collectors.toList()));

Network network = getNetwork(context.getNetworkUuid(), context.getOtherNetworkUuids());
Network network = getNetwork(context.getNetworkUuid());

List<Contingency> contingencies = context.getContingencyListNames().stream()
.map(contingencyListName -> actionsService.getContingencyList(contingencyListName, context.getNetworkUuid(), context.getVariantId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public class SecurityAnalysisControllerTest {
private static final UUID RESULT_UUID = UUID.fromString("0c8de370-3e6c-4d72-b292-d355a97e0d5d");
private static final UUID REPORT_UUID = UUID.fromString("0c4de370-3e6a-4d72-b292-d355a97e0d53");
private static final UUID OTHER_RESULT_UUID = UUID.fromString("0c8de370-3e6c-4d72-b292-d355a97e0d5a");
private static final UUID NETWORK_FOR_MERGING_VIEW_UUID = UUID.fromString("11111111-7977-4592-ba19-88027e4254e4");
private static final UUID OTHER_NETWORK_FOR_MERGING_VIEW_UUID = UUID.fromString("22222222-7977-4592-ba19-88027e4254e4");

private static final int TIMEOUT = 1000;

Expand Down Expand Up @@ -127,12 +125,6 @@ public void setUp() throws Exception {

given(networkStoreService.getNetwork(NETWORK_UUID, PreloadingStrategy.COLLECTION)).willReturn(network);

Network networkForMergingView = new NetworkFactoryImpl().createNetwork("mergingView", "test");
given(networkStoreService.getNetwork(NETWORK_FOR_MERGING_VIEW_UUID, PreloadingStrategy.COLLECTION)).willReturn(networkForMergingView);

Network otherNetworkForMergingView = new NetworkFactoryImpl().createNetwork("other", "test 2");
given(networkStoreService.getNetwork(OTHER_NETWORK_FOR_MERGING_VIEW_UUID, PreloadingStrategy.COLLECTION)).willReturn(otherNetworkForMergingView);

when(networkStoreService.getNetwork(NETWORK_STOP_UUID, PreloadingStrategy.COLLECTION)).thenAnswer((Answer) invocation -> {
//Needed so the stop call doesn't arrive too late
Network network1 = new NetworkFactoryImpl().createNetwork("other", "test");
Expand All @@ -159,10 +151,6 @@ public void setUp() throws Exception {
.willReturn(SecurityAnalysisProviderMock.CONTINGENCIES);
given(actionsService.getContingencyList(CONTINGENCY_LIST_NAME, NETWORK_STOP_UUID, VARIANT_TO_STOP_ID))
.willReturn(SecurityAnalysisProviderMock.CONTINGENCIES);
given(actionsService.getContingencyList(CONTINGENCY_LIST_NAME, NETWORK_FOR_MERGING_VIEW_UUID, null))
.willReturn(SecurityAnalysisProviderMock.CONTINGENCIES);
given(actionsService.getContingencyList(CONTINGENCY_LIST_NAME, OTHER_NETWORK_FOR_MERGING_VIEW_UUID, null))
.willReturn(SecurityAnalysisProviderMock.CONTINGENCIES);

// UUID service mocking to always generate the same result UUID
given(uuidGeneratorService.generate()).willReturn(RESULT_UUID);
Expand Down Expand Up @@ -354,22 +342,6 @@ public void deleteResultsTest() throws Exception {
assertResultNotFound(RESULT_UUID);
}

@Test
public void mergingViewTest() throws Exception {
MvcResult mvcResult;
String resultAsString;

mvcResult = mockMvc.perform(post("/" + VERSION + "/networks/" + NETWORK_FOR_MERGING_VIEW_UUID + "/run?contingencyListName=" + CONTINGENCY_LIST_NAME + "&networkUuid=" + OTHER_NETWORK_FOR_MERGING_VIEW_UUID))
.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON)
).andReturn();

resultAsString = mvcResult.getResponse().getContentAsString();
SecurityAnalysisResult securityAnalysisResult = mapper.readValue(resultAsString, SecurityAnalysisResult.class);
assertThat(RESULT, new MatcherJson<>(mapper, securityAnalysisResult));
}

@Test
public void testStatus() throws Exception {
MvcResult mvcResult;
Expand Down
Loading