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

[POC] Computation debug mode #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>1.20.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.gridsuite.voltageinit.server.dto.VoltageInitResult;
import org.gridsuite.voltageinit.server.dto.VoltageInitStatus;
import org.gridsuite.voltageinit.server.service.VoltageInitRunContext;
Expand All @@ -21,6 +20,7 @@
import org.springframework.web.bind.annotation.*;

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

import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_USER_ID;
Expand Down Expand Up @@ -49,9 +49,10 @@ public ResponseEntity<UUID> runAndSave(@Parameter(description = "Network UUID")
@Parameter(description = "reportUuid") @RequestParam(name = "reportUuid", required = false) UUID reportUuid,
@Parameter(description = "reporterId") @RequestParam(name = "reporterId", required = false) String reporterId,
@Parameter(description = "The type name for the report") @RequestParam(name = "reportType", required = false, defaultValue = "VoltageInit") String reportType,
@Parameter(description = "Debug mode") @RequestParam(name = "debug", required = false) Boolean debug,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use default value

@Parameter(description = "parametersUuid") @RequestParam(name = "parametersUuid", required = false) UUID parametersUuid,
@RequestHeader(HEADER_USER_ID) String userId) {
VoltageInitRunContext runContext = new VoltageInitRunContext(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid);
VoltageInitRunContext runContext = new VoltageInitRunContext(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, Optional.ofNullable(debug).orElse(false));
UUID resultUuid = voltageInitService.runAndSaveResult(runContext);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.commons.PowsyblException;
import lombok.Getter;
import com.powsybl.ws.commons.computation.service.AbstractResultContext;
import lombok.Getter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

Expand Down Expand Up @@ -67,8 +67,9 @@ public static VoltageInitResultContext fromMessage(Message<String> message, Obje
.orElse(null);
String reporterId = headers.containsKey(REPORTER_ID_HEADER) ? (String) headers.get(REPORTER_ID_HEADER) : null;
String reportType = headers.containsKey(REPORT_TYPE_HEADER) ? (String) headers.get(REPORT_TYPE_HEADER) : null;
Boolean debug = (Boolean) headers.get(DEBUG_HEADER);
VoltageInitRunContext runContext = new VoltageInitRunContext(
networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, voltageLevelsIdsRestricted
networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, voltageLevelsIdsRestricted, Optional.ofNullable(debug).orElse(false)
);
return new VoltageInitResultContext(resultUuid, runContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
package org.gridsuite.voltageinit.server.service;

import lombok.Getter;
import com.powsybl.ws.commons.computation.dto.ReportInfos;
import com.powsybl.ws.commons.computation.service.AbstractComputationRunContext;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -24,13 +24,13 @@ 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, null);
public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid, Map<String, Double> voltageLevelsIdsRestricted, boolean debug) {
super(networkUuid, variantId, receiver, new ReportInfos(reportUuid, reporterId, reportType), userId, null, null, debug);
this.parametersUuid = parametersUuid;
this.voltageLevelsIdsRestricted = voltageLevelsIdsRestricted;
}

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<>());
public VoltageInitRunContext(UUID networkUuid, String variantId, String receiver, UUID reportUuid, String reporterId, String reportType, String userId, UUID parametersUuid, boolean debug) {
this(networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, new HashMap<>(), debug);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private boolean checkReactiveSlacksOverThreshold(OpenReacResult openReacResult,
protected CompletableFuture<OpenReacResult> getCompletableFuture(VoltageInitRunContext context, String provider, UUID resultUuid) {
OpenReacParameters parameters = voltageInitParametersService.buildOpenReacParameters(context, context.getNetwork());
OpenReacConfig config = OpenReacConfig.load();
return OpenReacRunner.runAsync(context.getNetwork(), context.getNetwork().getVariantManager().getWorkingVariantId(), parameters, config, executionService.getComputationManager(), context.getReportNode(), null);
return OpenReacRunner.runAsync(context.getNetwork(), context.getNetwork().getVariantManager().getWorkingVariantId(), parameters, config, context.getComputationManager(), context.getReportNode(), null);
}

@Override
Expand Down Expand Up @@ -147,14 +147,14 @@ protected void postRun(VoltageInitRunContext runContext, AtomicReference<ReportN
}

@Override
protected void sendResultMessage(AbstractResultContext<VoltageInitRunContext> resultContext, OpenReacResult result) {
public Map<String, Object> getResultHeaders(AbstractResultContext<VoltageInitRunContext> resultContext, OpenReacResult result) {
Map<String, Object> additionalHeaders = super.getResultHeaders(resultContext, result);
VoltageInitRunContext context = resultContext.getRunContext();
double reactiveSlacksThreshold = voltageInitParametersService.getReactiveSlacksThreshold(context.getParametersUuid());
boolean resultCheckReactiveSlacks = checkReactiveSlacksOverThreshold(result, reactiveSlacksThreshold);
Map<String, Object> additionalHeaders = new HashMap<>();
additionalHeaders.put(HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, resultCheckReactiveSlacks);
additionalHeaders.put(HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE, reactiveSlacksThreshold);
notificationService.sendResultMessage(resultContext.getResultUuid(), context.getReceiver(), context.getUserId(), additionalHeaders);
return additionalHeaders;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private ListAssert<VoltageLimitOverride> testsBuildSpecificVoltageLimitsCommon(L
final VoltageInitParametersEntity voltageInitParameters = entityManager.persistFlushFind(
new VoltageInitParametersEntity(null, null, "", voltageLimits, null, null, null, 100., 0., false)
);
final VoltageInitRunContext context = new VoltageInitRunContext(NETWORK_UUID, VARIANT_ID_1, null, REPORT_UUID, null, "", "", voltageInitParameters.getId());
final VoltageInitRunContext context = new VoltageInitRunContext(NETWORK_UUID, VARIANT_ID_1, null, REPORT_UUID, null, "", "", voltageInitParameters.getId(), true);
context.setReportNode(ReportNode.newRootReportNode().withMessageTemplate(COMPUTATION_TYPE, COMPUTATION_TYPE).build());
final OpenReacParameters openReacParameters = voltageInitParametersService.buildOpenReacParameters(context, network);
log.debug("openReac build parameters report: {}", mapper.writeValueAsString(context.getReportNode()));
Expand Down Expand Up @@ -258,7 +258,7 @@ void testsBuildSpecificVoltageLimitsWithFourSubstationStudy() throws Exception {
new VoltageInitParametersEntity(null, null, "", List.of(vl1, vl2, vl3, vl4), null, null, null, 100., 0., false)
);

final VoltageInitRunContext context = new VoltageInitRunContext(networkUuid, variantId, null, REPORT_UUID, null, "", "", voltageInitParameters.getId());
final VoltageInitRunContext context = new VoltageInitRunContext(networkUuid, variantId, null, REPORT_UUID, null, "", "", voltageInitParameters.getId(), false);
context.setReportNode(ReportNode.newRootReportNode().withMessageTemplate("VoltageInit", "VoltageInit").build());
final OpenReacParameters openReacParameters = voltageInitParametersService.buildOpenReacParameters(context, network);
if (log.isDebugEnabled()) {
Expand Down
Loading