Skip to content

Commit

Permalink
gridsuite dependencies 27 (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
  • Loading branch information
AbdelHedhili authored Oct 31, 2023
1 parent 43f9960 commit 616fa3e
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 78 deletions.
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<jaxb-runtime.version>2.4.0-b180830.0438</jaxb-runtime.version>
<jib.from.image>gridsuite/java-simulator:2.0.0</jib.from.image>
<liquibase-hibernate-package>org.gridsuite.loadflow.server</liquibase-hibernate-package>
<gridsuite-dependencies.version>26</gridsuite-dependencies.version>
<gridsuite-dependencies.version>27</gridsuite-dependencies.version>
<!--
antlr4 from openloadflow conflicts ? Only on repository.count() method in this project..
[ERROR] org.gridsuite.loadflow.server.SupervisionControllerTest.testResultCount <<< ERROR!
Expand Down Expand Up @@ -124,10 +124,6 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-mergingview</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

import static org.gridsuite.loadflow.server.service.NotificationService.HEADER_USER_ID;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
Expand All @@ -49,7 +47,6 @@ public class LoadFlowController {
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The load flow has been performed")})
public ResponseEntity<UUID> 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") @RequestParam(name = "networkUuid", required = false) List<String> otherNetworks,
@Parameter(description = "Provider") @RequestParam(name = "provider", required = false) String provider,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportId,
Expand All @@ -59,11 +56,9 @@ public ResponseEntity<UUID> run(@Parameter(description = "Network UUID") @PathVa
@RequestBody(required = false) LoadFlowParametersInfos loadflowParams
) {
String providerToUse = provider != null ? provider : loadFlowService.getDefaultProvider();
List<UUID> otherNetworksUuids = otherNetworks != null ? otherNetworks.stream().map(UUID::fromString).collect(Collectors.toList()) : Collections.emptyList();
LoadFlowRunContext loadFlowRunContext = LoadFlowRunContext.builder()
.networkUuid(networkUuid)
.variantId(variantId)
.otherNetworksUuids(otherNetworksUuids)
.receiver(receiver)
.provider(providerToUse)
.parameters(loadflowParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.UncheckedIOException;
import java.util.*;
import java.util.stream.Collectors;

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

Expand All @@ -44,16 +43,6 @@ public LoadFlowResultContext(UUID resultUuid, LoadFlowRunContext runContext) {
this.runContext = Objects.requireNonNull(runContext);
}

private static List<UUID> getHeaderList(MessageHeaders headers, String name) {
String header = (String) headers.get(name);
if (header == null || header.isEmpty()) {
return Collections.emptyList();
}
return Arrays.asList(header.split(",")).stream()
.map(UUID::fromString)
.collect(Collectors.toList());
}

public static LoadFlowResultContext fromMessage(Message<String> message, ObjectMapper objectMapper) {
Objects.requireNonNull(message);
MessageHeaders headers = message.getHeaders();
Expand All @@ -64,8 +53,6 @@ public static LoadFlowResultContext fromMessage(Message<String> message, ObjectM
String provider = (String) headers.get(HEADER_PROVIDER);
String userId = (String) headers.get(HEADER_USER_ID);

List<UUID> otherNetworkUuids = getHeaderList(headers, "otherNetworkUuids");

LoadFlowParametersInfos parameters;
try {
// can't use the following line because jackson doesn't unwrap null in the rootname
Expand All @@ -84,7 +71,6 @@ public static LoadFlowResultContext fromMessage(Message<String> message, ObjectM
LoadFlowRunContext.builder()
.networkUuid(networkUuid)
.variantId(variantId)
.otherNetworksUuids(otherNetworkUuids)
.receiver(receiver)
.provider(provider)
.parameters(parameters)
Expand All @@ -110,7 +96,6 @@ public Message<String> toMessage(ObjectMapper objectMapper) {
.setHeader("resultUuid", resultUuid.toString())
.setHeader("networkUuid", runContext.getNetworkUuid().toString())
.setHeader(VARIANT_ID_HEADER, runContext.getVariantId())
.setHeader("otherNetworkUuids", runContext.getOtherNetworksUuids().stream().map(UUID::toString).collect(Collectors.joining(",")))
.setHeader(HEADER_RECEIVER, runContext.getReceiver())
.setHeader(HEADER_PROVIDER, runContext.getProvider())
.setHeader(HEADER_USER_ID, runContext.getUserId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.gridsuite.loadflow.server.dto.LoadFlowParametersInfos;
import org.gridsuite.loadflow.server.utils.ReportContext;

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

/**
Expand All @@ -29,8 +28,6 @@ public class LoadFlowRunContext {

private final String variantId;

private final List<UUID> otherNetworksUuids;

private final String receiver;

private final String provider;
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.computation.local.LocalComputationManager;
import com.powsybl.iidm.mergingview.MergingView;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.loadflow.LoadFlow;
Expand All @@ -39,7 +38,6 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static org.gridsuite.loadflow.server.service.LoadFlowRunContext.buildParameters;
import static org.gridsuite.loadflow.server.service.NotificationService.FAIL_MESSAGE;
Expand Down Expand Up @@ -90,21 +88,6 @@ private Network getNetwork(UUID networkUuid, String variantId) {
return network;
}

private Network getNetwork(UUID networkUuid, List<UUID> otherNetworkUuids, String variantId) {
Network network = getNetwork(networkUuid, variantId);
if (otherNetworkUuids.isEmpty()) {
return network;
} else {
List<Network> otherNetworks = otherNetworkUuids.stream().map(uuid -> getNetwork(uuid, variantId)).collect(Collectors.toList());
List<Network> networks = new ArrayList<>();
networks.add(network);
networks.addAll(otherNetworks);
MergingView mergingView = MergingView.create("merge", "iidm");
mergingView.merge(networks.toArray(new Network[0]));
return mergingView;
}
}

private CompletableFuture<LoadFlowResult> runLoadFlowAsync(
Network network,
String variantId,
Expand All @@ -131,6 +114,7 @@ private CompletableFuture<LoadFlowResult> runLoadFlowAsync(
public LoadFlowResult run(Network network, LoadFlowRunContext context, UUID resultUuid) throws ExecutionException, InterruptedException {
LoadFlowParameters params = buildParameters(context.getParameters(), context.getProvider());
LOGGER.info("Run loadFlow...");

String provider = context.getProvider();

Reporter rootReporter = Reporter.NO_OP;
Expand Down Expand Up @@ -207,8 +191,7 @@ public Consumer<Message<String>> consumeRun() {
AtomicReference<Long> startTime = new AtomicReference<>();

startTime.set(System.nanoTime());
Network network = getNetwork(resultContext.getRunContext().getNetworkUuid(),
resultContext.getRunContext().getOtherNetworksUuids(), resultContext.getRunContext().getVariantId());
Network network = getNetwork(resultContext.getRunContext().getNetworkUuid(), resultContext.getRunContext().getVariantId());

LoadFlowResult result = run(network, resultContext.getRunContext(), resultContext.getResultUuid());
long nanoTime = System.nanoTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public class LoadFlowControllerTest {
private static final UUID NETWORK_UUID = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
private static final UUID RESULT_UUID = UUID.fromString("0c8de370-3e6c-4d72-b292-d355a97e0d5d");
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 UUID REPORT_UUID = UUID.fromString("762b7298-8c0f-11ed-a1eb-0242ac120002");

private static final String VARIANT_1_ID = "variant_1";
Expand Down Expand Up @@ -129,8 +127,6 @@ private static final class LimitViolationsMock {
private ObjectMapper mapper;
private Network network;
private Network network1;
private Network networkForMergingView;
private Network otherNetworkForMergingView;

private static void assertResultsEquals(LoadFlowResult result, org.gridsuite.loadflow.server.dto.LoadFlowResult resultDto) {
assertEquals(result.getComponentResults().size(), resultDto.getComponentResults().size());
Expand Down Expand Up @@ -175,12 +171,6 @@ public void setUp() throws Exception {

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

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

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

network1 = EurostagTutorialExample1Factory.createWithMoreGenerators(new NetworkFactoryImpl());
network1.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID);

Expand Down Expand Up @@ -368,27 +358,6 @@ public void stopTest() throws Exception {
}
}

@SneakyThrows
@Test
public void mergingViewTest() {
LoadFlow.Runner runner = Mockito.mock(LoadFlow.Runner.class);
try (MockedStatic<LoadFlow> loadFlowMockedStatic = Mockito.mockStatic(LoadFlow.class)) {
loadFlowMockedStatic.when(() -> LoadFlow.find(any())).thenReturn(runner);
Mockito.when(runner.runAsync(eq(network), eq(VARIANT_2_ID), eq(LocalComputationManager.getDefault()),
any(LoadFlowParameters.class), any(Reporter.class)))
.thenReturn(CompletableFuture.completedFuture(LoadFlowResultMock.RESULT));

MvcResult result = mockMvc.perform(post(
"/" + VERSION + "/networks/{networkUuid}/run-and-save?receiver=me&networkUuid=" + NETWORK_FOR_MERGING_VIEW_UUID, OTHER_NETWORK_FOR_MERGING_VIEW_UUID)
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();

assertEquals(RESULT_UUID, mapper.readValue(result.getResponse().getContentAsString(), UUID.class));
}
}

@SneakyThrows
@Test
public void testStatus() {
Expand Down

0 comments on commit 616fa3e

Please sign in to comment.