Skip to content

Commit

Permalink
Upgrade to powsybl-dependencies 2024.1.0 (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: achour94 <[email protected]>
Co-authored-by: Franck LECUYER <[email protected]>
Co-authored-by: Etienne <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent b66d39d commit 9957a3e
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 249 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
</developers>

<properties>
<powsybl-ws-dependencies.version>2.9.0</powsybl-ws-dependencies.version>
<powsybl-open-reac.version>0.6.0</powsybl-open-reac.version>
<gridsuite-dependencies.version>29</gridsuite-dependencies.version>
<powsybl-open-reac.version>0.7.0</powsybl-open-reac.version>
<mockito-inline.version>3.11.1</mockito-inline.version>
<liquibase-hibernate-package>org.gridsuite.voltageinit.server</liquibase-hibernate-package>
</properties>
Expand Down Expand Up @@ -91,9 +91,9 @@

<!-- imports -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-dependencies</artifactId>
<version>${powsybl-ws-dependencies.version}</version>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-dependencies</artifactId>
<version>${gridsuite-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.powsybl.commons.reporter.ReporterModelDeserializer;
import com.powsybl.commons.reporter.ReporterModelJsonModule;
import com.powsybl.commons.report.ReportNodeDeserializer;
import com.powsybl.commons.report.ReportNodeJsonModule;
import com.powsybl.openreac.parameters.input.json.OpenReactJsonModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -50,9 +50,9 @@ private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(
private static ObjectMapper createObjectMapper() {
var objectMapper = Jackson2ObjectMapperBuilder.json().build();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
objectMapper.registerModule(new ReporterModelJsonModule());
objectMapper.registerModule(new ReportNodeJsonModule());
objectMapper.registerModule(new OpenReactJsonModule());
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ReporterModelDeserializer.DICTIONARY_VALUE_ID, null));
objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ReportNodeDeserializer.DICTIONARY_VALUE_ID, null));
return objectMapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package org.gridsuite.voltageinit.server.computation.service;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -28,5 +28,5 @@ public abstract class AbstractComputationRunContext<P> {
private final String userId;
@Setter protected String provider;
@Setter protected P parameters;
@Setter Reporter reporter;
@Setter ReportNode reportNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.network.store.client.NetworkStoreService;
Expand Down Expand Up @@ -184,19 +183,20 @@ protected void preRun(R ignoredRunContext) {

protected S run(Network network, R runContext, UUID resultUuid) throws Exception {
String provider = runContext.getProvider();
AtomicReference<Reporter> rootReporter = new AtomicReference<>(Reporter.NO_OP);
Reporter reporter = Reporter.NO_OP;
AtomicReference<ReportNode> rootReporter = new AtomicReference<>(ReportNode.NO_OP);
ReportNode reporter = ReportNode.NO_OP;

if (runContext.getReportInfos().reportUuid() != null) {
final String reportType = runContext.getReportInfos().computationType();
String rootReporterId = runContext.getReportInfos().reporterId() == null ? reportType : runContext.getReportInfos().reporterId() + "@" + reportType;
rootReporter.set(new ReporterModel(rootReporterId, rootReporterId));
reporter = rootReporter.get().createSubReporter(reportType, String.format("%s (%s)", reportType, provider), "providerToUse", provider);
rootReporter.set(ReportNode.newRootReportNode().withMessageTemplate(rootReporterId, rootReporterId).build());
reporter = rootReporter.get().newReportNode().withMessageTemplate(reportType, String.format("%s (%s)", reportType, provider))
.withUntypedValue("providerToUse", provider).add();
// Delete any previous computation logs
observer.observe("report.delete",
runContext, () -> reportService.deleteReport(runContext.getReportInfos().reportUuid(), reportType));
}
runContext.setReporter(reporter);
runContext.setReportNode(reporter);

preRun(runContext);
CompletableFuture<S> future = runAsync(network, runContext, provider, resultUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModelJsonModule;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.ReportNodeJsonModule;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
Expand Down Expand Up @@ -47,15 +47,15 @@ public ReportService(ObjectMapper objectMapper,
this.reportServerBaseUri = reportServerBaseUri;
this.objectMapper = objectMapper;
this.restTemplate = restTemplate;
ReporterModelJsonModule reporterModelJsonModule = new ReporterModelJsonModule();
objectMapper.registerModule(reporterModelJsonModule);
ReportNodeJsonModule reportNodeJsonModule = new ReportNodeJsonModule();
objectMapper.registerModule(reportNodeJsonModule);
}

private String getReportServerURI() {
return this.reportServerBaseUri + DELIMITER + REPORT_API_VERSION + DELIMITER + "reports" + DELIMITER;
}

public void sendReport(UUID reportUuid, Reporter reporter) {
public void sendReport(UUID reportUuid, ReportNode reportNode) {
Objects.requireNonNull(reportUuid);

var path = UriComponentsBuilder.fromPath("{reportUuid}")
Expand All @@ -65,7 +65,7 @@ public void sendReport(UUID reportUuid, Reporter reporter) {
headers.setContentType(MediaType.APPLICATION_JSON);

try {
restTemplate.exchange(getReportServerURI() + path, HttpMethod.PUT, new HttpEntity<>(objectMapper.writeValueAsString(reporter), headers), Reporter.class);
restTemplate.exchange(getReportServerURI() + path, HttpMethod.PUT, new HttpEntity<>(objectMapper.writeValueAsString(reportNode), headers), ReportNode.class);
} catch (JsonProcessingException error) {
throw new PowsyblException("Error sending report", error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package org.gridsuite.voltageinit.server.service;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import lombok.Getter;
import org.gridsuite.voltageinit.server.computation.dto.ReportInfos;
import org.gridsuite.voltageinit.server.computation.service.AbstractComputationRunContext;
Expand All @@ -26,7 +26,7 @@ public class VoltageInitRunContext extends AbstractComputationRunContext<Void> {
private final Map<String, Double> voltageLevelsIdsRestricted;

public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid, Map<String, Double> voltageLevelsIdsRestricted) {
super(networkUuid, variantId, receiver, new ReportInfos(reportUuid, reporterId, reportType), userId, "", null, Reporter.NO_OP);
super(networkUuid, variantId, receiver, new ReportInfos(reportUuid, reporterId, reportType), userId, "", null, ReportNode.NO_OP);
this.parametersUuid = parametersUuid;
this.voltageLevelsIdsRestricted = voltageLevelsIdsRestricted;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
package org.gridsuite.voltageinit.server.service;

import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Network;
import com.powsybl.network.store.client.NetworkStoreService;
Expand Down Expand Up @@ -82,7 +81,7 @@ private boolean checkReactiveSlacksOverThreshold(OpenReacResult openReacResult,
protected CompletableFuture<OpenReacResult> getCompletableFuture(Network network, VoltageInitRunContext context, String provider, UUID resultUuid) {
OpenReacParameters parameters = voltageInitParametersService.buildOpenReacParameters(context, network);
OpenReacConfig config = OpenReacConfig.load();
return OpenReacRunner.runAsync(network, network.getVariantManager().getWorkingVariantId(), parameters, config, executionService.getComputationManager());
return OpenReacRunner.runAsync(network, network.getVariantManager().getWorkingVariantId(), parameters, config, executionService.getComputationManager(), context.getReportNode(), null);
}

@Override
Expand Down Expand Up @@ -133,12 +132,11 @@ protected void postRun(VoltageInitRunContext runContext, OpenReacResult result)
double reactiveSlacksThreshold = voltageInitParametersService.getReactiveSlacksThreshold(runContext.getParametersUuid());
boolean resultCheckReactiveSlacks = checkReactiveSlacksOverThreshold(result, reactiveSlacksThreshold);
if (resultCheckReactiveSlacks) {
runContext.getReporter().report(Report.builder()
.withKey("reactiveSlacksOverThreshold")
.withDefaultMessage("Reactive slack exceeds ${threshold} MVar for at least one bus")
.withValue("threshold", reactiveSlacksThreshold)
runContext.getReportNode().newReportNode()
.withMessageTemplate("reactiveSlacksOverThreshold", "Reactive slack exceeds ${threshold} MVar for at least one bus")
.withUntypedValue("threshold", reactiveSlacksThreshold)
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
.add();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
package org.gridsuite.voltageinit.server.service.parameters;

import com.google.common.annotations.VisibleForTesting;
import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.openreac.parameters.input.OpenReacParameters;
Expand Down Expand Up @@ -198,9 +197,10 @@ private static CounterToIncrement generateHighVoltageLimit(List<VoltageLimitOver
@Transactional(readOnly = true)
public OpenReacParameters buildOpenReacParameters(VoltageInitRunContext context, Network network) {
final long startTime = System.nanoTime();
final Reporter reporter = context.getReporter().createSubReporter("VoltageInitParameters", "VoltageInit parameters", Map.of(
"parameters_id", new TypedValue(Objects.toString(context.getParametersUuid()), "ID")
));
final ReportNode reportNode = context.getReportNode().newReportNode()
.withMessageTemplate("VoltageInitParameters", "VoltageInit parameters")
.withTypedValue("parameters_id", Objects.toString(context.getParametersUuid()), "ID")
.add();
OpenReacParameters parameters = new OpenReacParameters();
final MutableInt missingVoltageLimitsCounter = new MutableInt(0);
final MutableInt voltageLimitModificationsCounter = new MutableInt(0);
Expand All @@ -223,16 +223,16 @@ public OpenReacParameters buildOpenReacParameters(VoltageInitRunContext context,
voltageLevelModificationLimits, voltageLevelDefaultLimits,
voltageLevel, context.getVoltageLevelsIdsRestricted()));
parameters.addSpecificVoltageLimits(specificVoltageLimits);
logRestrictedVoltageLevels(reporter, context.getVoltageLevelsIdsRestricted());
logRestrictedVoltageLevels(reportNode, context.getVoltageLevelsIdsRestricted());
}

parameters.addConstantQGenerators(toEquipmentIdsList(context.getNetworkUuid(), context.getVariantId(), voltageInitParameters.getConstantQGenerators()))
.addVariableTwoWindingsTransformers(toEquipmentIdsList(context.getNetworkUuid(), context.getVariantId(), voltageInitParameters.getVariableTwoWindingsTransformers()))
.addVariableShuntCompensators(toEquipmentIdsList(context.getNetworkUuid(), context.getVariantId(), voltageInitParameters.getVariableShuntCompensators()));
});

logVoltageLimitsModifications(reporter, network, parameters.getSpecificVoltageLimits());
logVoltageLimitsModificationCounters(reporter, missingVoltageLimitsCounter, voltageLimitModificationsCounter);
logVoltageLimitsModifications(reportNode, network, parameters.getSpecificVoltageLimits());
logVoltageLimitsModificationCounters(reportNode, missingVoltageLimitsCounter, voltageLimitModificationsCounter);

//The optimizer will attach reactive slack variables to all buses
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL);
Expand All @@ -254,39 +254,36 @@ private List<String> toEquipmentIdsList(UUID networkUuid, String variantId, List
.toList();
}

private static void logRestrictedVoltageLevels(final Reporter reporter, final Map<String, Double> voltageLevelsIdsRestricted) {
private static void logRestrictedVoltageLevels(final ReportNode reportNode, final Map<String, Double> voltageLevelsIdsRestricted) {
if (!voltageLevelsIdsRestricted.isEmpty()) {
reporter.report(Report.builder()
.withKey("restrictedVoltageLevels")
.withDefaultMessage("The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: ${joinedVoltageLevelsIds}")
.withValue("joinedVoltageLevelsIds", voltageLevelsIdsRestricted
reportNode.newReportNode()
.withMessageTemplate("restrictedVoltageLevels", "The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: ${joinedVoltageLevelsIds}")
.withUntypedValue("joinedVoltageLevelsIds", voltageLevelsIdsRestricted
.entrySet()
.stream()
.map(entry -> entry.getKey() + " : " + VOLTAGE_FORMAT.format(ObjectUtils.defaultIfNull(entry.getValue(), Double.NaN)))
.collect(Collectors.joining(", ")))
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
.add();
}
}

private static void logVoltageLimitsModificationCounters(final Reporter reporter,
private static void logVoltageLimitsModificationCounters(final ReportNode reportNode,
final MutableInt counterMissingVoltageLimits,
final MutableInt counterVoltageLimitModifications) {
reporter.report(Report.builder()
.withKey("missingVoltageLimits")
.withDefaultMessage("Missing voltage limits of ${nbMissingVoltageLimits} voltage levels have been replaced with user-defined default values.")
.withValue("nbMissingVoltageLimits", counterMissingVoltageLimits.longValue())
reportNode.newReportNode()
.withMessageTemplate("missingVoltageLimits", "Missing voltage limits of ${nbMissingVoltageLimits} voltage levels have been replaced with user-defined default values.")
.withUntypedValue("nbMissingVoltageLimits", counterMissingVoltageLimits.longValue())
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
reporter.report(Report.builder()
.withKey("voltageLimitModifications")
.withDefaultMessage("Voltage limits of ${nbVoltageLimitModifications} voltage levels have been modified according to user input.")
.withValue("nbVoltageLimitModifications", counterVoltageLimitModifications.longValue())
.add();
reportNode.newReportNode()
.withMessageTemplate("voltageLimitModifications", "Voltage limits of ${nbVoltageLimitModifications} voltage levels have been modified according to user input.")
.withUntypedValue("nbVoltageLimitModifications", counterVoltageLimitModifications.longValue())
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
.add();
}

private static void logVoltageLimitsModifications(final Reporter reporter,
private static void logVoltageLimitsModifications(final ReportNode reporter,
final Network network,
final List<VoltageLimitOverride> specificVoltageLimits) {
specificVoltageLimits
Expand All @@ -304,14 +301,13 @@ private static void logVoltageLimitsModifications(final Reporter reporter,
final VoltageLevel voltageLevel = network.getVoltageLevel(id);
final double initialLowVoltageLimit = voltageLevel.getLowVoltageLimit();
final double initialHighVoltage = voltageLevel.getHighVoltageLimit();
reporter.report(Report.builder()
.withKey("voltageLimitModified")
.withDefaultMessage("Voltage limits of ${voltageLevelId} modified: low voltage limit = ${lowVoltageLimit}, high voltage limit = ${highVoltageLimit}")
reporter.newReportNode()
.withMessageTemplate("voltageLimitModified", "Voltage limits of ${voltageLevelId} modified: low voltage limit = ${lowVoltageLimit}, high voltage limit = ${highVoltageLimit}")
.withTypedValue("voltageLevelId", voltageLevel.getId(), TypedValue.VOLTAGE_LEVEL)
.withTypedValue("lowVoltageLimit", computeRelativeVoltageLevel(initialLowVoltageLimit, voltageLimits.get(VoltageLimitType.LOW_VOLTAGE_LIMIT)), TypedValue.VOLTAGE)
.withTypedValue("highVoltageLimit", computeRelativeVoltageLevel(initialHighVoltage, voltageLimits.get(VoltageLimitType.HIGH_VOLTAGE_LIMIT)), TypedValue.VOLTAGE)
.withSeverity(TypedValue.TRACE_SEVERITY)
.build());
.add();
});
}

Expand Down
Loading

0 comments on commit 9957a3e

Please sign in to comment.