diff --git a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionException.java b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionException.java index f2924697..5257c6b9 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionException.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionException.java @@ -21,7 +21,8 @@ public enum Type { UNSUPPORTED_FORMAT(HttpStatus.INTERNAL_SERVER_ERROR), UNKNOWN_EQUIPMENT_TYPE(HttpStatus.INTERNAL_SERVER_ERROR), UNKNOWN_VARIANT_ID(HttpStatus.NOT_FOUND), - FAILED_NETWORK_SAVING(HttpStatus.INTERNAL_SERVER_ERROR); + FAILED_NETWORK_SAVING(HttpStatus.INTERNAL_SERVER_ERROR), + FAILED_CASE_IMPORT(HttpStatus.INTERNAL_SERVER_ERROR); public final HttpStatus status; @@ -68,4 +69,8 @@ public static NetworkConversionException createVariantIdUnknown(String variantId public static NetworkConversionException createFailedNetworkSaving(UUID networkUuid, Exception cause) { return new NetworkConversionException(Type.FAILED_NETWORK_SAVING, String.format("The save of network '%s' has failed", networkUuid), cause); } + + public static NetworkConversionException createFailedCaseImport(Exception cause) { + return new NetworkConversionException(Type.FAILED_CASE_IMPORT, "Case import failed", cause); + } } diff --git a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java index de6aa69a..f920911c 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -167,8 +167,7 @@ Consumer> consumeCaseImportStart() { NetworkInfos networkInfos = importCase(caseUuid, variantId, reportUuid, caseInfos.getFormat(), changedImportParameters); notificationService.emitCaseImportSucceeded(networkInfos, caseInfos.getName(), caseInfos.getFormat(), receiver, allImportParameters); } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - notificationService.emitCaseImportFailed(receiver, e.getMessage()); + throw NetworkConversionException.createFailedCaseImport(e); } }; } diff --git a/src/main/java/com/powsybl/network/conversion/server/NotificationService.java b/src/main/java/com/powsybl/network/conversion/server/NotificationService.java index 6267901e..235a7bbe 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NotificationService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NotificationService.java @@ -32,7 +32,6 @@ 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_ERROR_MESSAGE = "errorMessage"; public static final String HEADER_IMPORT_PARAMETERS = "importParameters"; public static final String HEADER_CASE_FORMAT = "caseFormat"; public static final String HEADER_CASE_NAME = "caseName"; @@ -50,11 +49,6 @@ private void sendCaseImportSucceededMessage(Message message) { networkConversionPublisher.send("publishCaseImportSucceeded-out-0", message); } - private void sendCaseImportFailedMessage(Message message) { - MESSAGE_OUTPUT_LOGGER.debug("Sending import failed message : {}", message); - networkConversionPublisher.send("publishCaseImportFailed-out-0", message); - } - public void emitCaseImportStart(UUID caseUuid, String variantId, UUID reportUuid, String caseFormat, Map importParameters, String receiver) { sendCaseImportStartMessage(MessageBuilder.withPayload(caseUuid) .setHeader(HEADER_VARIANT_ID, variantId) @@ -75,11 +69,4 @@ public void emitCaseImportSucceeded(NetworkInfos networkInfos, String caseNameSt .setHeader(HEADER_IMPORT_PARAMETERS, importParameters) .build()); } - - public void emitCaseImportFailed(String receiver, String errorMessage) { - sendCaseImportFailedMessage(MessageBuilder.withPayload("") - .setHeader(HEADER_RECEIVER, receiver) - .setHeader(HEADER_ERROR_MESSAGE, errorMessage) - .build()); - } } diff --git a/src/main/resources/config/application.yaml b/src/main/resources/config/application.yaml index 239c705f..e0b0e68c 100644 --- a/src/main/resources/config/application.yaml +++ b/src/main/resources/config/application.yaml @@ -11,14 +11,24 @@ spring: destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start publishCaseImportSucceeded-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.succeeded - publishCaseImportFailed-out-0: - destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.failed consumeCaseImportStart-in-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start group: importGroup consumer: concurrency: 2 - output-bindings: publishCaseImportStart-out-0;publishCaseImportSucceeded-out-0;publishCaseImportFailed-out-0 + max-attempts: 1 + output-bindings: publishCaseImportStart-out-0;publishCaseImportSucceeded-out-0 + rabbit: + bindings: + consumeRun-in-0: + consumer: + auto-bind-dlq: true + dead-letter-exchange: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start.dlx + dead-letter-queue-name: ${powsybl-ws.rabbitmq.destination.prefix:}case.import.start.dlq + dead-letter-exchange-type: topic + quorum: + enabled: true + delivery-limit: 2 powsybl: services: diff --git a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java index 7c886fd0..74888ded 100644 --- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java +++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java @@ -349,9 +349,8 @@ void testFailedAsyncImport() throws Exception { .param("caseFormat", "XIIDM")) .andExpect(status().isOk()); - Message message = output.receive(1000, "case.import.failed"); + Message message = output.receive(1000, "case.import.start"); assertEquals(receiver, message.getHeaders().get(NotificationService.HEADER_RECEIVER)); - assertEquals(IMPORT_CASE_ERROR_MESSAGE, message.getHeaders().get(NotificationService.HEADER_ERROR_MESSAGE)); } @Test