Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
<properties>
<gridsuite-dependencies.version>42.0.0</gridsuite-dependencies.version>
<!-- FIXME to remove at next upgrade of gridsuite-dependencies -->
<gridsuite-computation.version>1.0.0</gridsuite-computation.version>
<gridsuite-computation.version>1.1.0</gridsuite-computation.version>
<!-- FIXME to remove at next upgrade of powsybl-ws-dependencies -->
<powsybl-ws-commons.version>1.28.0</powsybl-ws-commons.version>
<powsybl-ws-commons.version>1.28.1</powsybl-ws-commons.version>
<powsybl-open-reac.version>0.14.0</powsybl-open-reac.version>
<powsybl-optimizer-commons.version>0.13.0</powsybl-optimizer-commons.version>
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
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;
import org.gridsuite.voltageinit.server.service.VoltageInitService;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.UUID;

import static org.gridsuite.computation.service.NotificationService.HEADER_USER_ID;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
Expand Down Expand Up @@ -52,9 +51,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") @RequestParam(name = "debug", required = false, defaultValue = "false") boolean debug,
@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, debug);
UUID resultUuid = voltageInitService.runAndSaveResult(runContext);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(resultUuid);
}
Expand Down Expand Up @@ -124,4 +124,12 @@ public ResponseEntity<Void> resetModificationsGroupUuidInResult(@Parameter(descr
voltageInitService.resetModificationsGroupUuid(resultUuid);
return ResponseEntity.ok().build();
}

@GetMapping(value = "/results/{resultUuid}/download-debug-file", produces = "application/json")
@Operation(summary = "Download a voltage init debug file")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Voltage init debug file"),
@ApiResponse(responseCode = "404", description = "Voltage init debug file has not been found")})
public ResponseEntity<Resource> downloadDebugFile(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid) {
return voltageInitService.downloadDebugFile(resultUuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@
*/
package org.gridsuite.voltageinit.server.entities;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>
*/
Expand Down Expand Up @@ -62,4 +54,7 @@ public class VoltageInitResultEntity {

@Column
private Double reactiveSlacksThreshold;

@Column(name = "debug_file_location")
private String debugFileLocation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
*/
package org.gridsuite.voltageinit.server.repository;

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

import org.gridsuite.voltageinit.server.entities.VoltageInitResultEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

/**
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>
*/
Expand All @@ -23,4 +26,8 @@ public interface ResultRepository extends JpaRepository<VoltageInitResultEntity,
Optional<VoltageInitResultEntity> findByResultUuid(UUID resultUuid);

void deleteByResultUuid(UUID resultUuid);

@Modifying
@Query("UPDATE VoltageInitResultEntity r SET r.debugFileLocation = :debugFileLocation WHERE r.resultUuid = :resultUuid")
int updateDebugFileLocation(@Param("resultUuid") UUID resultUuid, @Param("debugFileLocation") String debugFileLocation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import java.io.UncheckedIOException;
import java.util.*;

import static org.gridsuite.computation.service.NotificationService.HEADER_RECEIVER;
import static org.gridsuite.computation.service.NotificationService.HEADER_USER_ID;
import static org.gridsuite.computation.service.NotificationService.*;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
Expand Down Expand Up @@ -51,6 +50,7 @@ public static VoltageInitResultContext fromMessage(Message<String> message, Obje
String variantId = (String) headers.get(VARIANT_ID_HEADER);
String receiver = (String) headers.get(HEADER_RECEIVER);
String userId = (String) headers.get(HEADER_USER_ID);
Boolean debug = (Boolean) headers.get(HEADER_DEBUG);
Map<String, Double> voltageLevelsIdsRestricted;
try {
voltageLevelsIdsRestricted = headers.get(VOLTAGE_LEVELS_IDS_RESTRICTED) != null ?
Expand All @@ -68,8 +68,7 @@ public static VoltageInitResultContext fromMessage(Message<String> message, Obje
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;
VoltageInitRunContext runContext = new VoltageInitRunContext(
networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, voltageLevelsIdsRestricted
);
networkUuid, variantId, receiver, reportUuid, reporterId, reportType, userId, parametersUuid, voltageLevelsIdsRestricted, debug);
return new VoltageInitResultContext(resultUuid, runContext);
}

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

import com.powsybl.iidm.network.Bus;
import com.powsybl.openreac.parameters.output.OpenReacResult;
import org.gridsuite.computation.service.AbstractComputationResultService;
import org.gridsuite.voltageinit.server.dto.VoltageInitStatus;
import org.gridsuite.voltageinit.server.entities.BusVoltageEmbeddable;
Expand All @@ -19,14 +20,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.powsybl.openreac.parameters.output.OpenReacResult;

import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -64,7 +59,7 @@ private static VoltageInitResultEntity toVoltageInitResultEntity(UUID resultUuid
}
).filter(Objects::nonNull).toList();
return new VoltageInitResultEntity(resultUuid, Instant.now(), indicators, reactiveSlacks, busVoltages, modificationsGroupUuid,
isReactiveSlacksOverThreshold, reactiveSlacksThreshold);
isReactiveSlacksOverThreshold, reactiveSlacksThreshold, null);
}

@Override
Expand Down Expand Up @@ -129,6 +124,25 @@ public void insert(UUID resultUuid, OpenReacResult result, Map<String, Bus> netw
@Transactional
public void insertErrorResult(UUID resultUuid, Map<String, String> errorIndicators) {
Objects.requireNonNull(resultUuid);
resultRepository.save(new VoltageInitResultEntity(resultUuid, Instant.now(), errorIndicators, List.of(), List.of(), null, false, null));
resultRepository.save(new VoltageInitResultEntity(resultUuid, Instant.now(), errorIndicators, List.of(), List.of(), null, false, null, null));
}

@Override
@Transactional
public void saveDebugFileLocation(UUID resultUuid, String debugFilePath) {
resultRepository.findById(resultUuid).ifPresentOrElse(
(var resultEntity) -> resultRepository.updateDebugFileLocation(resultUuid, debugFilePath),
() -> resultRepository.save(new VoltageInitResultEntity(resultUuid, null, null, null, null, null,
false, null, debugFilePath))
);
}

@Override
@Transactional(readOnly = true)
public String findDebugFileLocation(UUID resultUuid) {
Objects.requireNonNull(resultUuid);
return resultRepository.findById(resultUuid)
.map(VoltageInitResultEntity::getDebugFileLocation)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ 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) {
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,
"default-provider", // TODO : replace with null when fix in powsybl-ws-commons will handle null provider
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 @@ -8,8 +8,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.network.store.client.NetworkStoreService;

import org.gridsuite.computation.dto.GlobalFilter;
import org.gridsuite.computation.s3.ComputationS3Service;
import org.gridsuite.computation.service.AbstractComputationService;
import org.gridsuite.computation.service.NotificationService;
import org.gridsuite.computation.service.UuidGeneratorService;
Expand Down Expand Up @@ -45,9 +45,11 @@ public VoltageInitService(NotificationService notificationService,
NetworkModificationService networkModificationService,
UuidGeneratorService uuidGeneratorService,
VoltageInitResultService resultService,
@Autowired(required = false)
ComputationS3Service computationS3Service,
FilterService filterService,
ObjectMapper objectMapper) {
super(notificationService, resultService, objectMapper, uuidGeneratorService, null);
super(notificationService, resultService, computationS3Service, objectMapper, uuidGeneratorService, null);
this.networkModificationService = Objects.requireNonNull(networkModificationService);
this.filterService = Objects.requireNonNull(filterService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import com.powsybl.openreac.parameters.input.OpenReacParameters;
import com.powsybl.openreac.parameters.output.OpenReacResult;
import com.powsybl.openreac.parameters.output.OpenReacStatus;
import org.gridsuite.computation.s3.ComputationS3Service;
import org.gridsuite.computation.service.*;
import org.gridsuite.voltageinit.server.dto.VoltageInitStatus;
import org.gridsuite.voltageinit.server.dto.parameters.VoltageInitParametersInfos;
import org.gridsuite.voltageinit.server.service.parameters.VoltageInitParametersService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -63,10 +65,12 @@ public VoltageInitWorkerService(NetworkStoreService networkStoreService,
NetworkModificationService networkModificationService,
VoltageInitParametersService voltageInitParametersService,
VoltageInitResultService resultService,
@Autowired(required = false)
ComputationS3Service computationS3Service,
ReportService reportService,
VoltageInitObserver voltageInitObserver,
ObjectMapper objectMapper) {
super(networkStoreService, notificationService, reportService, resultService, executionService, voltageInitObserver, objectMapper);
super(networkStoreService, notificationService, reportService, resultService, computationS3Service, executionService, voltageInitObserver, objectMapper);
this.networkModificationService = Objects.requireNonNull(networkModificationService);
this.voltageInitParametersService = Objects.requireNonNull(voltageInitParametersService);
}
Expand All @@ -88,6 +92,9 @@ private boolean checkReactiveSlacksOverThreshold(OpenReacResult openReacResult,
@Override
protected CompletableFuture<OpenReacResult> getCompletableFuture(VoltageInitRunContext context, String provider, UUID resultUuid) {
OpenReacParameters parameters = voltageInitParametersService.buildOpenReacParameters(context, context.getNetwork());
if (context.getDebugDir() != null) {
parameters.setDebugDir(context.getDebugDir().toString());
}
OpenReacConfig config = OpenReacConfig.load();
return OpenReacRunner.runAsync(context.getNetwork(), context.getNetwork().getVariantManager().getWorkingVariantId(), parameters, config, executionService.getComputationManager(), context.getReportNode(), null);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ server:
spring:
rabbitmq:
addresses: localhost
cloud:
aws:
endpoint: http://localhost:19000

powsybl-ws:
database:
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spring:
max-attempts: 1
publishRun-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}voltageinit.run
publishDebug-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}voltageinit.debug
publishResult-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}voltageinit.result
consumeCancel-in-0:
Expand All @@ -25,7 +27,7 @@ spring:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}voltageinit.stopped
publishCancelFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}voltageinit.cancelfailed
output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishCancelFailed-out-0
output-bindings: publishRun-out-0;publishDebug-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishCancelFailed-out-0
rabbit:
bindings:
consumeRun-in-0:
Expand All @@ -38,6 +40,12 @@ spring:
enabled: true
delivery-limit: 2

computation:
s3:
enabled: true

debug-subpath: debug

powsybl-ws:
database:
name: voltageinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="phamquy (generated)" id="1754054948453-5">
<addColumn tableName="voltage_init_result">
<column name="debug_file_location" type="varchar(255)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20250711T130602Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20250801T132858Z.xml
relativeToChangelogFile: true
Loading