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

Add logs on voltage limits #46

Merged
merged 57 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c8c4009
Unnecessary `@ComponentScan`
Tristan-WorkGH Mar 19, 2024
2ddfc46
fix final root reporter
Tristan-WorkGH Mar 19, 2024
c6ede79
simplify streams
Tristan-WorkGH Mar 19, 2024
bc03a8f
simplify chrono
Tristan-WorkGH Mar 19, 2024
70739ca
refactor voltage limits
Tristan-WorkGH Mar 19, 2024
508c5ac
fix cast
Tristan-WorkGH Mar 20, 2024
71180a9
fix constructor
Tristan-WorkGH Mar 20, 2024
aff60c2
migrate tests to junit5
Tristan-WorkGH Mar 20, 2024
44f827a
clean SpringBootTest
Tristan-WorkGH Mar 21, 2024
bd91ab1
prepare test
Tristan-WorkGH Mar 21, 2024
71585a3
Add basic logs control
Tristan-WorkGH Mar 22, 2024
5ab800f
Move reporter logs near building logic
Tristan-WorkGH Mar 22, 2024
8fb02ec
Added new logs
Tristan-WorkGH Mar 22, 2024
96cc4bd
Merge remote-tracking branch 'origin/main' into add_logs
Tristan-WorkGH Mar 22, 2024
9b3dbc3
fix checkstyle
Tristan-WorkGH Mar 22, 2024
cd42064
Add missing lombok config
Tristan-WorkGH Mar 22, 2024
fc7e221
clean PR
Tristan-WorkGH Mar 22, 2024
d06fe52
Merge remote-tracking branch 'origin/main' into add_logs
Tristan-WorkGH Mar 26, 2024
438e199
review
Tristan-WorkGH Mar 27, 2024
68cf7b5
fix tests
Tristan-WorkGH Mar 27, 2024
e0ec908
review
Tristan-WorkGH Mar 27, 2024
a319191
review
Tristan-WorkGH Mar 27, 2024
81a5645
Git diff track correct file
Tristan-WorkGH Apr 3, 2024
ef08b99
DB not clean by `@DirtiesContext` ?
Tristan-WorkGH Apr 3, 2024
86fc6fd
clean PR
Tristan-WorkGH Apr 3, 2024
cf2c51f
clean
Tristan-WorkGH Apr 3, 2024
e55c5b2
review
Tristan-WorkGH Apr 3, 2024
1bfd3cb
Merge remote-tracking branch 'origin/main' into add_logs
Tristan-WorkGH Apr 4, 2024
482d1ff
fix: relative override need to be calculated
Tristan-WorkGH Apr 4, 2024
59af616
fix limits set counters
Tristan-WorkGH Apr 4, 2024
61944b6
review
Tristan-WorkGH Apr 4, 2024
37d7f93
review
Tristan-WorkGH Apr 5, 2024
c6803d2
fix counter
Tristan-WorkGH Apr 5, 2024
da02c0c
review
Tristan-WorkGH Apr 5, 2024
6b0ac31
try to fix counter
Tristan-WorkGH Apr 5, 2024
98f9936
review
Tristan-WorkGH Apr 8, 2024
50c62ff
fix log
Tristan-WorkGH Apr 8, 2024
9473f45
hum... something is wrong with counters...
Tristan-WorkGH Apr 8, 2024
4a3d669
fix logline message
Tristan-WorkGH Apr 8, 2024
22b73d4
found it!
Tristan-WorkGH Apr 8, 2024
5805e75
checkstyle
Tristan-WorkGH Apr 8, 2024
0a96d37
review
Tristan-WorkGH Apr 8, 2024
27f6583
review
Tristan-WorkGH Apr 8, 2024
3f94e7c
revert 5805e754904e78b4ba6416581d2e2200d3501641
Tristan-WorkGH Apr 9, 2024
8301e9d
review
Tristan-WorkGH Apr 9, 2024
1a7f24d
review (bis)
Tristan-WorkGH Apr 9, 2024
dbb6a39
review
Tristan-WorkGH Apr 9, 2024
5e6bdda
optimize memory usage
Tristan-WorkGH Apr 9, 2024
50266a1
fix message value format
Tristan-WorkGH Apr 10, 2024
4fe8d79
Revert "optimize memory usage"
Tristan-WorkGH Apr 10, 2024
f61e7a7
checkstyle
Tristan-WorkGH Apr 10, 2024
7d042e2
review
Tristan-WorkGH Apr 10, 2024
b4f051a
Merge remote-tracking branch 'origin/main' into add_logs
Tristan-WorkGH Apr 10, 2024
01020e9
rename constant
Tristan-WorkGH Apr 10, 2024
94000b5
review
Tristan-WorkGH Apr 10, 2024
6291593
fix sanor
Tristan-WorkGH Apr 10, 2024
c21ef21
review
Tristan-WorkGH Apr 10, 2024
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
Empty file added .mvn/lombok-config-copy.marker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project was missing .mvn/lombok-config-copy.marker & lombok.config, with consequence of very bad coverage with Sonar for example.

Empty file.
1 change: 1 addition & 0 deletions lombok.config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use common lombok config as base

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import target/configs/powsybl-build-tools.jar!powsybl-build-tools/lombok.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
*/
package org.gridsuite.voltageinit.server.service;

import lombok.Getter;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
*/
@Getter
@Data
Copy link
Collaborator

@etiennehomer etiennehomer Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Getter is fine here. No need for @Data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but need toString when dumping the object

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And when do you dump it ?

public class VoltageInitRunContext {
private static final String VOLTAGE_INIT_TYPE_REPORT = "VoltageInit";

private final UUID networkUuid;

Tristan-WorkGH marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -35,6 +39,7 @@ public class VoltageInitRunContext {
private final UUID parametersUuid;

private final Map<String, Double> voltageLevelsIdsRestricted;
Tristan-WorkGH marked this conversation as resolved.
Show resolved Hide resolved
private final Reporter rootReporter;

public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid, Map<String, Double> voltageLevelsIdsRestricted) {
this.networkUuid = Objects.requireNonNull(networkUuid);
Expand All @@ -46,5 +51,15 @@ public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver
this.userId = userId;
this.parametersUuid = parametersUuid;
this.voltageLevelsIdsRestricted = voltageLevelsIdsRestricted;
if (this.reportUuid == null) {
Tristan-WorkGH marked this conversation as resolved.
Show resolved Hide resolved
this.rootReporter = Reporter.NO_OP;
} else {
final String rootReporterId = reporterId == null ? VOLTAGE_INIT_TYPE_REPORT : reporterId + "@" + reportType;
this.rootReporter = new ReporterModel(rootReporterId, rootReporterId);
}
}

public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid) {
this(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, new HashMap<>());
}
}
Comment on lines +50 to 53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Contributor Author

@Tristan-WorkGH Tristan-WorkGH Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We sometimes construct the context without specifying all data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove if you don't use it in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used in VoltageInitResultContext

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because you added it in 0a96d37...

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

import com.google.common.collect.Sets;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
Expand Down Expand Up @@ -58,8 +54,6 @@ public class VoltageInitWorkerService {
private static final String ERROR = "error";
private static final String ERROR_DURING_VOLTAGE_PROFILE_INITIALISATION = "Error during voltage profile initialization";

private static final String VOLTAGE_INIT_TYPE_REPORT = "VoltageInit";

private final NetworkStoreService networkStoreService;

private final NetworkModificationService networkModificationService;
Expand Down Expand Up @@ -113,43 +107,22 @@ private Network getNetwork(UUID networkUuid, String variantId) {
return network;
}

public static void addRestrictedVoltageLevelReport(Map<String, Double> voltageLevelsIdsRestricted, Reporter reporter) {
if (!voltageLevelsIdsRestricted.isEmpty()) {
String joinedVoltageLevelsIds = voltageLevelsIdsRestricted.entrySet()
.stream()
.map(entry -> entry.getKey() + " : " + entry.getValue())
.collect(Collectors.joining(", "));

reporter.report(Report.builder()
.withKey("restrictedVoltageLevels")
.withDefaultMessage(String.format("The modifications to the low limits for certain voltage levels have been restricted to avoid negative voltage limits: %s", joinedVoltageLevelsIds))
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
}
}

private Pair<Network, OpenReacResult> run(VoltageInitRunContext context, UUID resultUuid) throws Exception {
Objects.requireNonNull(context);

LOGGER.info("Run voltage init...");
Network network = voltageInitObserver.observe("network.load", () ->
getNetwork(context.getNetworkUuid(), context.getVariantId()));

AtomicReference<Reporter> rootReporter = new AtomicReference<>(Reporter.NO_OP);
Reporter reporter = Reporter.NO_OP;
if (context.getReportUuid() != null) {
String rootReporterId = context.getReporterId() == null ? VOLTAGE_INIT_TYPE_REPORT : context.getReporterId() + "@" + context.getReportType();
rootReporter.set(new ReporterModel(rootReporterId, rootReporterId));
reporter = rootReporter.get().createSubReporter(context.getReportType(), VOLTAGE_INIT_TYPE_REPORT, VOLTAGE_INIT_TYPE_REPORT, context.getReportUuid().toString());
// Delete any previous VoltageInit computation logs
voltageInitObserver.observe("report.delete", () ->
reportService.deleteReport(context.getReportUuid(), context.getReportType()));
}
CompletableFuture<OpenReacResult> future = runVoltageInitAsync(context, network, resultUuid);
if (context.getReportUuid() != null) {
addRestrictedVoltageLevelReport(context.getVoltageLevelsIdsRestricted(), reporter);
voltageInitObserver.observe("report.send", () ->
reportService.sendReport(context.getReportUuid(), rootReporter.get()));
reportService.sendReport(context.getReportUuid(), context.getRootReporter()));
}

Tristan-WorkGH marked this conversation as resolved.
Show resolved Hide resolved
return future == null ? Pair.of(network, null) : Pair.of(network, voltageInitObserver.observeRun("run", future::get));
Expand Down
Loading
Loading