diff --git a/pom.xml b/pom.xml index 10f93172..c3e86221 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ powsybl/java-dynawo:2.1.0 - 31 + 32 org.gridsuite.securityanalysis.server 1.0.5 1.16.0 diff --git a/src/main/java/org/gridsuite/securityanalysis/server/SecurityAnalysisController.java b/src/main/java/org/gridsuite/securityanalysis/server/SecurityAnalysisController.java index df8ecd25..978fe048 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/SecurityAnalysisController.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/SecurityAnalysisController.java @@ -229,8 +229,9 @@ public ResponseEntity invalidateStatus(@Parameter(description = "Result uu @Operation(summary = "Stop a security analysis computation") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis has been stopped")}) public ResponseEntity stop(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid, - @Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver) { - securityAnalysisService.stop(resultUuid, receiver); + @Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver, + @RequestHeader(HEADER_USER_ID) String userId) { + securityAnalysisService.stop(resultUuid, receiver, userId); return ResponseEntity.ok().build(); } diff --git a/src/main/resources/config/application.yaml b/src/main/resources/config/application.yaml index 3efd276d..94e6263b 100644 --- a/src/main/resources/config/application.yaml +++ b/src/main/resources/config/application.yaml @@ -32,7 +32,9 @@ spring: destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.stopped publishFailed-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.failed - output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-0 + publishCancelFailed-out-0: + destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.cancelfailed + output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-;publishCancelFailed-out-0 powsybl-ws: database: diff --git a/src/test/java/org/gridsuite/securityanalysis/server/SecurityAnalysisControllerTest.java b/src/test/java/org/gridsuite/securityanalysis/server/SecurityAnalysisControllerTest.java index 394d73ab..05a9eef7 100644 --- a/src/test/java/org/gridsuite/securityanalysis/server/SecurityAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/securityanalysis/server/SecurityAnalysisControllerTest.java @@ -648,8 +648,8 @@ public void stopTest() throws Exception { // wait for security analysis to actually run before trying to stop it countDownLatch.await(); - mockMvc.perform(put("/" + VERSION + "/results/" + RESULT_UUID + "/stop" - + "?receiver=me")) + mockMvc.perform(put("/" + VERSION + "/results/" + RESULT_UUID + "/stop" + "?receiver=me") + .header(HEADER_USER_ID, "testUserId")) .andExpect(status().isOk()); Message message = output.receive(TIMEOUT * 3, "sa.stopped"); @@ -658,6 +658,19 @@ public void stopTest() throws Exception { assertEquals(getCancelMessage(COMPUTATION_TYPE), message.getHeaders().get("message")); } + @Test + public void testStopAndFail() throws Exception { + UUID randomUuid = UUID.randomUUID(); + mockMvc.perform(put("/" + VERSION + "/results/" + randomUuid + "/stop" + "?receiver=me") + .header(HEADER_USER_ID, "testUserId")) + .andExpect(status().isOk()); + + Message message = output.receive(TIMEOUT * 3, "sa.cancelfailed"); + assertEquals(randomUuid.toString(), message.getHeaders().get("resultUuid")); + assertEquals("me", message.getHeaders().get("receiver")); + assertEquals(getCancelFailedMessage(COMPUTATION_TYPE), message.getHeaders().get("message")); + } + @Test public void runTestWithError() throws Exception { MvcResult mvcResult;