Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ion-server into create-modification-without-applying
  • Loading branch information
Slimane AMAR committed Jan 22, 2025
2 parents 9c11b44 + afe603a commit 126de23
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 138 deletions.
47 changes: 26 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-network-modification-server</artifactId>
<version>2.11.0-SNAPSHOT</version>
<version>2.13.0-SNAPSHOT</version>

<packaging>jar</packaging>
<name>Network modification server</name>
Expand All @@ -44,18 +44,15 @@
</developers>

<properties>
<gridsuite-dependencies.version>35</gridsuite-dependencies.version>
<gridsuite-dependencies.version>36</gridsuite-dependencies.version>
<db-util.version>1.0.5</db-util.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
<liquibase-hibernate-package>org.gridsuite.modification.server</liquibase-hibernate-package>
<!-- FIXME: powsybl-network-store modules'version is overloaded in the dependencies section.The overloads and this property below have to be removed at next powsybl-ws-dependencies.version upgra
e -->
<powsybl-network-store.version>1.21.1</powsybl-network-store.version>
<sonar.coverage.exclusions>**/migration/**/*</sonar.coverage.exclusions>
<network-modification.version>0.4.0</network-modification.version>
<!-- FIXME : Remove when gridsuite-dependencies.version are updated to include gridsuite-filter
version 1.0.16 or later -->
<filter.version>1.0.16</filter.version>

<!-- FIXME: powsybl-ws-commons module's version is overloaded in the dependencies section.The overloads and this property below have to be removed at next powsybl-ws-commons.version upgrade -->
<powsybl-ws-commons.version>1.18.0</powsybl-ws-commons.version>
<network-modification.version>0.5.0</network-modification.version>
</properties>

<build>
Expand Down Expand Up @@ -98,12 +95,23 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- FIXME : Remove this dependency when gridsuite-dependencies.version are updated to include gridsuite-filter
version ${filter.version} below or later -->
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>${filter.version}</version>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-model</artifactId>
<version>${powsybl-network-store.version}</version>
</dependency>

<!-- imports -->
Expand Down Expand Up @@ -146,8 +154,6 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<!-- FIXME: to be removed at next powsybl-ws-dependencies upgrade -->
<version>${powsybl-ws-commons.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand All @@ -174,6 +180,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- elasticsearch -->
<dependency>
Expand All @@ -188,11 +198,6 @@
<artifactId>powsybl-config-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.gridsuite.modification.server;

/**
* @author Joris Mancini <joris.mancini_externe at rte-france.com>
*/
public class BuildException extends RuntimeException {
public BuildException(String message, Throwable e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.network.store.client.PreloadingStrategy;

import jakarta.annotation.PreDestroy;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -30,6 +28,7 @@
import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService;
import org.gridsuite.modification.server.impacts.AbstractBaseImpact;
import org.gridsuite.modification.server.service.FilterService;
import org.gridsuite.modification.server.service.LargeNetworkModificationExecutionService;
import org.gridsuite.modification.server.service.NetworkModificationObserver;
import org.gridsuite.modification.server.service.ReportService;
import org.slf4j.Logger;
Expand All @@ -39,9 +38,6 @@

import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
Expand All @@ -58,7 +54,7 @@ public class NetworkModificationApplicator {

@Getter private final FilterService filterService;

private final ExecutorService applicationExecutor;
private final LargeNetworkModificationExecutionService largeNetworkModificationExecutionService;

private final NetworkModificationObserver networkModificationObserver;

Expand All @@ -68,18 +64,18 @@ public class NetworkModificationApplicator {

public NetworkModificationApplicator(NetworkStoreService networkStoreService, EquipmentInfosService equipmentInfosService,
ReportService reportService, FilterService filterService,
@Value("${max-large-concurrent-applications}") int maxConcurrentApplications,
NetworkModificationObserver networkModificationObserver) {
NetworkModificationObserver networkModificationObserver,
LargeNetworkModificationExecutionService largeNetworkModificationExecutionService) {
this.networkStoreService = networkStoreService;
this.equipmentInfosService = equipmentInfosService;
this.reportService = reportService;
this.filterService = filterService;
this.applicationExecutor = Executors.newFixedThreadPool(maxConcurrentApplications);
this.networkModificationObserver = networkModificationObserver;
this.largeNetworkModificationExecutionService = largeNetworkModificationExecutionService;

}

/* This method is used when creating, inserting, moving or duplicating modifications
/* This method is used for incremental modifications
* Since there is no queue for these operations and they can be memory consuming when the preloading strategy is large
* (for example for VOLTAGE_INIT_MODIFICATION),
* we limit the number of concurrent applications of these modifications to avoid out of memory issues.
Expand All @@ -97,15 +93,16 @@ public NetworkModificationResult applyModifications(List<ModificationInfos> modi
.map(ModificationType::getStrategy)
.orElse(PreloadingStrategy.NONE);
if (preloadingStrategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW) {
CompletableFuture<NetworkModificationResult> future = CompletableFuture.supplyAsync(() -> processApplication(modificationInfosList, networkInfos, reportInfos), applicationExecutor);
return future.join();
return largeNetworkModificationExecutionService
.supplyAsync(() -> apply(modificationInfosList, networkInfos, reportInfos))
.join();
} else {
return processApplication(modificationInfosList, networkInfos, reportInfos);
return apply(modificationInfosList, networkInfos, reportInfos);
}
}

// used for creating, inserting, moving or duplicating modifications
private NetworkModificationResult processApplication(List<ModificationInfos> modificationInfosList, NetworkInfos networkInfos, ReportInfos reportInfos) {
// This method is used for incremental modifications
private NetworkModificationResult apply(List<ModificationInfos> modificationInfosList, NetworkInfos networkInfos, ReportInfos reportInfos) {
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService, collectionThreshold);
ApplicationStatus groupApplicationStatus = apply(modificationInfosList, listener.getNetwork(), reportInfos);
List<AbstractBaseImpact> networkImpacts = listener.flushNetworkModifications();
Expand Down Expand Up @@ -134,15 +131,16 @@ public NetworkModificationResult applyModifications(List<Pair<ReportInfos, List<
.map(ModificationType::getStrategy)
.orElse(PreloadingStrategy.NONE);
if (preloadingStrategy == PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW) {
CompletableFuture<NetworkModificationResult> future = CompletableFuture.supplyAsync(() -> processApplication(modificationInfosGroups, networkInfos), applicationExecutor);
return future.join();
return largeNetworkModificationExecutionService
.supplyAsync(() -> apply(modificationInfosGroups, networkInfos))
.join();
} else {
return processApplication(modificationInfosGroups, networkInfos);
return apply(modificationInfosGroups, networkInfos);
}
}

// used for building a variant
private NetworkModificationResult processApplication(List<Pair<ReportInfos, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos) {
// This method is used when building a variant
private NetworkModificationResult apply(List<Pair<ReportInfos, List<ModificationInfos>>> modificationInfosGroups, NetworkInfos networkInfos) {
NetworkStoreListener listener = NetworkStoreListener.create(networkInfos.getNetwork(), networkInfos.getNetworkUuuid(), networkStoreService, equipmentInfosService, collectionThreshold);
List<ApplicationStatus> groupsApplicationStatuses =
modificationInfosGroups.stream()
Expand Down Expand Up @@ -233,9 +231,4 @@ public static ApplicationStatus getApplicationStatus(ReportNode reportNode) {
throw new IllegalArgumentException(String.format("Report severity '%s' unknown !", severity.getValue()));
}
}

@PreDestroy
public void shutdown() {
applicationExecutor.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,20 @@ private void addSimpleModificationImpact(Identifiable<?> identifiable) {
}

@Override
public void onElementRemoved(Identifiable identifiable, String attribute, Object oldValue) {
public void onPropertyRemoved(Identifiable identifiable, String attribute, Object oldValue) {
addSimpleModificationImpact(identifiable);
}

@Override
public void onElementAdded(Identifiable identifiable, String attribute, Object newValue) {
public void onPropertyAdded(Identifiable identifiable, String attribute, Object newValue) {
addSimpleModificationImpact(identifiable);
}

@Override
public void onElementReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
public void onPropertyReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
addSimpleModificationImpact(identifiable);
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
addSimpleModificationImpact(identifiable);
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) {
addSimpleModificationImpact(identifiable);
Expand Down Expand Up @@ -337,8 +331,23 @@ public void onExtensionBeforeRemoval(Extension<?> extension) {
}

@Override
public void onExtensionUpdate(Extension<?> extendable, String attribute, Object oldValue, Object newValue) {
public void onExtensionUpdate(Extension<?> extendable, String attribute, String variantId, Object oldValue, Object newValue) {
Identifiable<?> identifiable = (Identifiable<?>) extendable.getExtendable();
onUpdate(identifiable, attribute, variantId, oldValue, newValue);
}

@Override
public void onVariantCreated(String sourceVariantId, String targetVariantId) {
// FIXME: implement this method
}

@Override
public void onVariantOverwritten(String sourceVariantId, String targetVariantId) {
// FIXME: implement this method
}

@Override
public void onVariantRemoved(String variantId) {
// FIXME: implement this method
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
import lombok.NonNull;
import org.gridsuite.modification.server.BuildException;
import org.gridsuite.modification.server.dto.BuildInfos;
import org.gridsuite.modification.server.dto.NetworkModificationResult;
import org.slf4j.Logger;
Expand Down Expand Up @@ -46,8 +47,6 @@ public class BuildWorkerService {

private final BuildStoppedPublisherService stoppedPublisherService;

private final BuildFailedPublisherService failedPublisherService;

private final Map<String, CompletableFuture<NetworkModificationResult>> futures = new ConcurrentHashMap<>();

private final Map<String, BuildCancelContext> cancelBuildRequests = new ConcurrentHashMap<>();
Expand All @@ -61,12 +60,10 @@ public class BuildWorkerService {

public BuildWorkerService(@NonNull NetworkModificationService networkModificationService,
@NonNull ObjectMapper objectMapper,
@NonNull BuildStoppedPublisherService stoppedPublisherService,
@NonNull BuildFailedPublisherService failedPublisherService) {
@NonNull BuildStoppedPublisherService stoppedPublisherService) {
this.networkModificationService = networkModificationService;
this.objectMapper = objectMapper;
this.stoppedPublisherService = stoppedPublisherService;
this.failedPublisherService = failedPublisherService;
}

private CompletableFuture<NetworkModificationResult> execBuildVariant(BuildExecContext execContext, BuildInfos buildInfos) {
Expand Down Expand Up @@ -98,11 +95,11 @@ private CompletableFuture<NetworkModificationResult> execBuildVariant(BuildExecC
@Bean
public Consumer<Message<String>> consumeBuild() {
return message -> {
BuildExecContext execContext = null;
BuildExecContext execContext;
try {
execContext = BuildExecContext.fromMessage(message, objectMapper);
} catch (Exception e) {
LOGGER.error("Error retrieving message in consumeBuild", e);
throw new BuildException("Failed to read build message", e);
}
startBuild(Objects.requireNonNull(execContext));
};
Expand All @@ -113,7 +110,7 @@ private void startBuild(BuildExecContext execContext) {
BuildInfos buildInfos = execContext.getBuildInfos();
CompletableFuture<NetworkModificationResult> future = execBuildVariant(execContext, buildInfos);
NetworkModificationResult result;
if (future != null && (result = future.get()) != null) { // result available
if (future != null && (result = future.join()) != null) { // result available
notificationService.emitBuildResultMessage(result, execContext.getReceiver());
LOGGER.info("Build complete on node '{}'", execContext.getReceiver());
} else { // result not available : stop build request
Expand All @@ -123,13 +120,8 @@ private void startBuild(BuildExecContext execContext) {
}
} catch (CancellationException e) {
stoppedPublisherService.publishCancel(execContext.getReceiver(), CANCEL_MESSAGE);
} catch (InterruptedException e) {
LOGGER.error(FAIL_MESSAGE, e);
failedPublisherService.publishFail(execContext.getReceiver(), FAIL_MESSAGE + " : " + e.getMessage());
Thread.currentThread().interrupt();
} catch (Exception e) {
LOGGER.error(FAIL_MESSAGE, e);
failedPublisherService.publishFail(execContext.getReceiver(), FAIL_MESSAGE + " : " + e.getMessage());
throw new BuildException("Node build failed", e);
} finally {
futures.remove(execContext.getReceiver());
cancelBuildRequests.remove(execContext.getReceiver());
Expand Down
Loading

0 comments on commit 126de23

Please sign in to comment.