Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public ResponseEntity<UUID> exportNetwork(@Parameter(description = "Network UUID
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "File name") @RequestParam(name = "fileName", required = false) String fileName,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@Parameter(description = "export infos") @RequestParam(name="exportInfos", required = false) String exportInfos,
@org.springframework.web.bind.annotation.RequestBody(required = false) Map<String, Object> formatParameters
) {
LOGGER.debug("Exporting asynchronously network {} ...", networkUuid);
UUID exportUuid = UUID.randomUUID();
networkConversionService.exportNetworkAsynchronously(networkUuid, variantId, fileName, format, receiver, exportUuid, formatParameters);
networkConversionService.exportNetworkAsynchronously(networkUuid, variantId, fileName, format, receiver, exportInfos, exportUuid, formatParameters);
return ResponseEntity.ok().body(exportUuid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ void importCaseAsynchronously(UUID caseUuid, String variantId, UUID reportUuid,
notificationService.emitCaseImportStart(caseUuid, variantId, reportUuid, caseFormat, importParameters, receiver);
}

void exportNetworkAsynchronously(UUID networkUuid, String variantId, String fileName, String format, String receiver, UUID exportUuid, Map<String, Object> formatParameters) {
notificationService.emitNetworkExportStart(networkUuid, variantId, fileName, format, receiver, exportUuid, formatParameters);
void exportNetworkAsynchronously(UUID networkUuid, String variantId, String fileName, String format, String receiver, String exportInfos, UUID exportUuid, Map<String, Object> formatParameters) {
notificationService.emitNetworkExportStart(networkUuid, variantId, fileName, format, receiver, exportInfos, exportUuid, formatParameters);
}

void exportCaseAsynchronously(UUID caseUuid, String fileName, String format, String userId, UUID exportUuid, Map<String, Object> formatParameters) {
Expand Down Expand Up @@ -231,6 +231,7 @@ Consumer<Message<UUID>> consumeNetworkExportStart() {
String format = message.getHeaders().get(NotificationService.HEADER_FORMAT, String.class);
String receiver = message.getHeaders().get(NotificationService.HEADER_RECEIVER, String.class);
String exportUuidStr = message.getHeaders().get(NotificationService.HEADER_EXPORT_UUID, String.class);
String exportInfos = message.getHeaders().get(NotificationService.HEADER_EXPORT_INFOS, String.class);
UUID exportUuid = exportUuidStr != null ? UUID.fromString(exportUuidStr) : null;
Map<String, Object> formatParameters = extractFormatParameters(message);
ExportNetworkInfos exportNetworkInfos = null;
Expand All @@ -242,9 +243,9 @@ Consumer<Message<UUID>> consumeNetworkExportStart() {
);
String s3Key = exportRootPath + DELIMITER + exportUuid + DELIMITER + exportNetworkInfos.getTempFilePath().getFileName();
uploadFile(exportNetworkInfos.getTempFilePath(), s3Key);
notificationService.emitNetworkExportFinished(exportUuid, receiver, null);
notificationService.emitNetworkExportFinished(exportUuid, fileName, receiver, exportInfos, null);
} catch (Exception e) {
notificationService.emitNetworkExportFinished(exportUuid, receiver, String.format("Export failed for network %s", fileName));
notificationService.emitNetworkExportFinished(exportUuid, fileName, receiver, exportInfos, String.format("Export failed for network %s", fileName));
LOGGER.error(String.format("Export failed for network %s (uuid: %s):", fileName, networkUuid), e);
} finally {
if (exportNetworkInfos != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
Expand All @@ -32,6 +33,7 @@ public class NotificationService {
public static final String HEADER_NETWORK_ID = "networkId";
public static final String HEADER_NETWORK_UUID = "networkUuid";
public static final String HEADER_RECEIVER = "receiver";
public static final String HEADER_EXPORT_INFOS = "exportInfos";
public static final String HEADER_IMPORT_PARAMETERS = "importParameters";
public static final String HEADER_CASE_FORMAT = "caseFormat";
public static final String HEADER_CASE_NAME = "caseName";
Expand All @@ -41,10 +43,14 @@ public class NotificationService {
public static final String HEADER_USER_ID = "userId";
public static final String HEADER_EXPORT_UUID = "exportUuid";
public static final String HEADER_ERROR = "error";
public static final String HEADER_EXPORT_FOLDER = "exportFolder";

@Autowired
private StreamBridge networkConversionPublisher;

@Value("${powsybl-ws.s3.subpath.prefix:}${export-subpath}")
String exportRootPath;

private void sendCaseImportStartMessage(Message<UUID> message) {
MESSAGE_OUTPUT_LOGGER.debug("Sending import start message : {}", message);
networkConversionPublisher.send("publishCaseImportStart-out-0", message);
Expand Down Expand Up @@ -96,9 +102,13 @@ public void emitCaseImportSucceeded(NetworkInfos networkInfos, String caseNameSt
.build());
}

public void emitNetworkExportFinished(UUID exportUuid, String receiver, String error) {
public void emitNetworkExportFinished(UUID exportUuid, String fileName, String receiver, String exportInfos, String error) {

sendNetworkExportFinishedMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_FILE_NAME, fileName)
.setHeader(HEADER_RECEIVER, receiver)
.setHeader(HEADER_EXPORT_INFOS, exportInfos)
.setHeader(HEADER_EXPORT_FOLDER, exportRootPath)
.setHeader(HEADER_EXPORT_UUID, exportUuid != null ? exportUuid.toString() : null)
.setHeader(HEADER_ERROR, error)
.build());
Expand All @@ -112,12 +122,13 @@ public void emitCaseExportFinished(UUID exportUuid, String userId, String error)
.build());
}

public void emitNetworkExportStart(UUID networkUuid, String variantId, String fileName, String format, String receiver, UUID exportUuid, Map<String, Object> formatParameters) {
public void emitNetworkExportStart(UUID networkUuid, String variantId, String fileName, String format, String receiver, String exportInfos, UUID exportUuid, Map<String, Object> formatParameters) {
sendNetworkExportStartMessage(MessageBuilder.withPayload(networkUuid)
.setHeader(HEADER_VARIANT_ID, variantId)
.setHeader(HEADER_FILE_NAME, fileName)
.setHeader(HEADER_FORMAT, format)
.setHeader(HEADER_RECEIVER, receiver)
.setHeader(HEADER_EXPORT_INFOS, exportInfos)
.setHeader(HEADER_EXPORT_UUID, exportUuid != null ? exportUuid.toString() : null)
.setHeader(HEADER_EXPORT_PARAMETERS, formatParameters)
.build());
Expand Down
Loading