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

feat: redirect build failures on rabbit dlq #122

Open
wants to merge 4 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
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->

<dependency><!-- To remove when integrate in next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
<version>1.19.0</version>
</dependency>
<!-- imports -->
<dependency>
<groupId>org.gridsuite</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ protected void sendResultMessage(AbstractResultContext<ShortCircuitRunContext> r
resultContext.getRunContext().getUserId(), additionalHeaders);
}

@Override
protected void publishFail(AbstractResultContext<ShortCircuitRunContext> resultContext, String message) {
ShortCircuitRunContext context = resultContext.getRunContext();
String busId = context.getBusId();
Map<String, Object> additionalHeaders = new HashMap<>();
additionalHeaders.put(HEADER_BUS_ID, busId);
Comment on lines -108 to -109
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure we can remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because it is set in the run message already, so if it is defined in the run message it will be forwarded in the DLQ


notificationService.publishFail(resultContext.getResultUuid(), resultContext.getRunContext().getReceiver(),
message, resultContext.getRunContext().getUserId(), getComputationType(), additionalHeaders);
}

@Override
protected CompletableFuture<ShortCircuitAnalysisResult> getCompletableFuture(ShortCircuitRunContext runContext, String provider, UUID resultUuid) {
List<Fault> faults = runContext.getBusId() == null ? getAllBusfaultFromNetwork(runContext) : getBusFaultFromBusId(runContext);
Expand Down
16 changes: 13 additions & 3 deletions src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spring:
group: shortcircuitanalysisGroup
consumer:
concurrency: 2
max-attempts: 1
publishRun-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run
publishResult-out-0:
Expand All @@ -30,11 +31,20 @@ spring:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.cancel
publishStopped-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.stopped
publishFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.failed
publishCancelFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.cancelfailed
output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-0:publishCancelFailed-out-0
output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0:publishCancelFailed-out-0
rabbit:
bindings:
consumeRun-in-0:
consumer:
auto-bind-dlq: true
dead-letter-exchange: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run.dlx
dead-letter-queue-name: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run.dlx.dlq
dead-letter-exchange-type: topic
quorum:
enabled: true
delivery-limit: 2

powsybl-ws:
database:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
import static org.gridsuite.shortcircuit.server.TestUtils.unzip;
import static org.gridsuite.shortcircuit.server.service.ShortCircuitResultContext.HEADER_BUS_ID;
import static org.gridsuite.shortcircuit.server.service.ShortCircuitWorkerService.COMPUTATION_TYPE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doAnswer;
Expand Down Expand Up @@ -197,7 +196,7 @@ public String getVersion() {
private final String shortCircuitAnalysisRunDestination = "shortcircuitanalysis.run";
private final String shortCircuitAnalysisCancelDestination = "shortcircuitanalysis.cancel";
private final String shortCircuitAnalysisStoppedDestination = "shortcircuitanalysis.stopped";
private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.failed";
private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.run.dlx.dlq";
private final String shortCircuitAnalysisCancelFailedDestination = "shortcircuitanalysis.cancelfailed";

@Autowired
Expand Down Expand Up @@ -665,11 +664,7 @@ void runWithBusBarSectionIdAndErrorTest() throws Exception {
assertEquals("me", runMessage.getHeaders().get("receiver"));
assertEquals("BUSBARSECTION_ID_NOT_EXISTING", runMessage.getHeaders().get(HEADER_BUS_ID));

Message<byte[]> failedMessage = output.receive(TIMEOUT, shortCircuitAnalysisFailedDestination);
assertEquals(RESULT_UUID.toString(), failedMessage.getHeaders().get("resultUuid"));
assertEquals("me", failedMessage.getHeaders().get("receiver"));
assertEquals("BUSBARSECTION_ID_NOT_EXISTING", failedMessage.getHeaders().get(HEADER_BUS_ID));

assertNull(output.receive(TIMEOUT, shortCircuitAnalysisResultDestination));
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we have the same message without the additional header?

Copy link
Contributor

Choose a reason for hiding this comment

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

check computationexception?

mockMvc.perform(get(
"/" + VERSION + "/results/{resultUuid}", RESULT_UUID))
.andExpect(status().isNotFound());
Expand Down Expand Up @@ -851,11 +846,10 @@ void runWithNoShortCircuitDataTest() throws Exception {
assertEquals(RESULT_UUID.toString(), runMessage.getHeaders().get("resultUuid"));
assertEquals("me", runMessage.getHeaders().get("receiver"));

//networkWithoutExtension has no shortcircuit data so the computation should fail
Message<byte[]> resultMessage = output.receive(TIMEOUT, shortCircuitAnalysisFailedDestination);
assertEquals("Short circuit analysis has failed : Missing short-circuit extension data", resultMessage.getHeaders().get("message"));
assertEquals(RESULT_UUID.toString(), resultMessage.getHeaders().get("resultUuid"));
assertEquals("me", resultMessage.getHeaders().get("receiver"));
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we have the same message without the additional header?

Copy link
Contributor

Choose a reason for hiding this comment

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

check computationexception?

assertNull(output.receive(TIMEOUT, shortCircuitAnalysisResultDestination));
mockMvc.perform(get(
"/" + VERSION + "/results/{resultUuid}", RESULT_UUID))
.andExpect(status().isNotFound());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.network.store.client.PreloadingStrategy;
import com.powsybl.shortcircuit.*;
import com.powsybl.ws.commons.computation.ComputationException;
import com.powsybl.ws.commons.computation.service.ExecutionService;
import com.powsybl.ws.commons.computation.service.NotificationService;
import com.powsybl.ws.commons.computation.service.ReportService;
Expand All @@ -43,6 +44,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -148,8 +150,7 @@ void testGetBusFaultFromOutOfVoltageBus() throws Exception {
try (var shortCircuitAnalysisMockedStatic = TestUtils.injectShortCircuitAnalysisProvider(analysisProvider);
var shortCircuitResultContextMockedStatic = mockStatic(ShortCircuitResultContext.class)) {
shortCircuitResultContextMockedStatic.when(() -> ShortCircuitResultContext.fromMessage(message, objectMapper)).thenReturn(resultContext);
workerService.consumeRun().accept(message);
verify(notificationService).publishFail(any(), any(), eq("Selected bus is out of voltage"), any(), any(), any());
assertThrows(ComputationException.class, () -> workerService.consumeRun().accept(message));
Copy link
Contributor

Choose a reason for hiding this comment

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

could keep checking "Selected bus is out of voltage" ?

}
}

Expand Down
Loading