Skip to content

Commit 67d7335

Browse files
authored
One bus short circuit debug mode (#823)
Signed-off-by: Thang PHAM <[email protected]>
1 parent 5336895 commit 67d7335

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

src/main/java/org/gridsuite/study/server/service/ConsumerService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,11 @@ public Consumer<Message<String>> consumeLoadFlowFailed() {
768768

769769
@Bean
770770
public Consumer<Message<String>> consumeShortCircuitAnalysisDebug() {
771-
return message -> consumeCalculationDebug(message, SHORT_CIRCUIT);
771+
return message -> {
772+
String busId = message.getHeaders().get(HEADER_BUS_ID, String.class);
773+
ComputationType computationType = !StringUtils.isEmpty(busId) ? SHORT_CIRCUIT_ONE_BUS : SHORT_CIRCUIT;
774+
consumeCalculationDebug(message, computationType);
775+
};
772776
}
773777

774778
@Bean

src/test/java/org/gridsuite/study/server/ShortCircuitTest.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757

5858
import java.util.*;
5959

60-
import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER;
61-
import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID;
60+
import static org.gridsuite.study.server.StudyConstants.*;
6261
import static org.gridsuite.study.server.notification.NotificationService.HEADER_UPDATE_TYPE;
6362
import static org.gridsuite.study.server.notification.NotificationService.UPDATE_TYPE_COMPUTATION_PARAMETERS;
6463
import static org.gridsuite.study.server.utils.TestUtils.getBinaryAsBuffer;
@@ -165,6 +164,7 @@ class ShortCircuitTest implements WithAssertions {
165164
//output destinations
166165
private final String studyUpdateDestination = "study.update";
167166
private final String elementUpdateDestination = "element.update";
167+
private final String shortCircuitAnalysisDebugDestination = "shortcircuitanalysis.debug";
168168
private final String shortCircuitAnalysisResultDestination = "shortcircuitanalysis.result";
169169
private final String shortCircuitAnalysisStoppedDestination = "shortcircuitanalysis.stopped";
170170
private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.run.dlx";
@@ -196,14 +196,40 @@ public MockResponse dispatch(RecordedRequest request) {
196196
String path = Objects.requireNonNull(request.getPath());
197197
String method = Objects.requireNonNull(request.getMethod());
198198

199-
if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&busId=BUS_TEST_ID&variantId=" + VARIANT_ID_2)) {
199+
if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&busId=BUS_TEST_ID&variantId=" + VARIANT_ID_2 + "&debug=.*")) {
200+
String receiver = "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D";
201+
input.send(MessageBuilder.withPayload("")
202+
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
203+
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D")
204+
.setHeader("busId", "BUS_TEST_ID")
205+
.build(), shortCircuitAnalysisResultDestination);
206+
// mock the notification from shortcircuit-server to send a debug status notif
207+
input.send(MessageBuilder.withPayload("")
208+
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
209+
.setHeader("receiver", receiver)
210+
.setHeader("busId", "BUS_TEST_ID")
211+
.build(), shortCircuitAnalysisDebugDestination);
212+
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), shortCircuitAnalysisResultUuidStr);
213+
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&busId=BUS_TEST_ID&variantId=" + VARIANT_ID_2)) {
200214
input.send(MessageBuilder.withPayload("")
201215
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
202216
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D")
203217
.setHeader("busId", "BUS_TEST_ID")
204218
.build(), shortCircuitAnalysisResultDestination);
205219
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), shortCircuitAnalysisResultUuidStr);
206-
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + ".*")) {
220+
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + "&debug=.*")) {
221+
String receiver = "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D";
222+
input.send(MessageBuilder.withPayload("")
223+
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
224+
.setHeader("receiver", receiver)
225+
.build(), shortCircuitAnalysisResultDestination);
226+
// mock the notification from shortcircuit-server to send a debug status notif
227+
input.send(MessageBuilder.withPayload("")
228+
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
229+
.setHeader("receiver", receiver)
230+
.build(), shortCircuitAnalysisDebugDestination);
231+
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), shortCircuitAnalysisResultUuidStr);
232+
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2)) {
207233
input.send(MessageBuilder.withPayload("")
208234
.setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID)
209235
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D")
@@ -340,16 +366,18 @@ void testAllBusesShortCircuit(final MockWebServer server) throws Exception {
340366
.header("userId", "userId"))
341367
.andExpect(status().isForbidden());
342368

343-
//run an all-buses short circuit analysis
369+
//run in debug mode an all-buses short circuit analysis
344370
mockMvc.perform(put("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, firstRootNetworkUuid, modificationNode3Uuid)
345-
.param("debug", "true")
371+
.param(QUERY_PARAM_DEBUG, "true")
346372
.header("userId", "userId"))
347373
.andExpect(status().isOk());
348374

349375
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS);
350376

351377
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_RESULT);
352378

379+
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.COMPUTATION_DEBUG_FILE_STATUS);
380+
353381
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS);
354382

355383
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + "&debug=true")));
@@ -557,19 +585,22 @@ void testOneBusShortCircuit(final MockWebServer server) throws Exception {
557585
.header("userId", "userId"))
558586
.andExpect(status().isForbidden());
559587

560-
//run a one bus short circuit analysis
588+
//run in debug mode a one bus short circuit analysis
561589
mockMvc.perform(put("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, firstRootNetworkUuid, modificationNode3Uuid)
562590
.param("busId", "BUS_TEST_ID")
591+
.param(QUERY_PARAM_DEBUG, "true")
563592
.header("userId", "userId"))
564593
.andExpect(status().isOk());
565594

566595
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS);
567596

568597
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_RESULT);
569598

599+
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.COMPUTATION_DEBUG_FILE_STATUS);
600+
570601
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS);
571602

572-
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2)));
603+
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + "&debug=true")));
573604

574605
assertEquals(1, rootNetworkNodeInfoRepository.findAllByOneBusShortCircuitAnalysisResultUuidNotNull().size());
575606

src/test/java/org/gridsuite/study/server/StudyControllerDynamicSecurityAnalysisTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.UUID;
5858

5959
import static org.assertj.core.api.Assertions.assertThat;
60+
import static org.gridsuite.study.server.StudyConstants.QUERY_PARAM_DEBUG;
6061
import static org.junit.jupiter.api.Assertions.assertEquals;
6162
import static org.mockito.BDDMockito.any;
6263
import static org.mockito.BDDMockito.eq;
@@ -219,12 +220,13 @@ void testRunDynamicSecurityAnalysisGivenRegularNodeAndFailed() throws Exception
219220
doAnswer(invocation -> RESULT_UUID)
220221
.when(spyDynamicSecurityAnalysisService).runDynamicSecurityAnalysis(
221222
any(), eq(modificationNode1Uuid), eq(firstRootNetworkUuid), eq(NETWORK_UUID), eq(VARIANT_ID),
222-
any(), any(), any(), any(), eq(false));
223+
any(), any(), any(), any(), eq(true));
223224

224225
// --- call endpoint to be tested --- //
225-
// run on a regular node which allows a run
226+
// run in debug mode on a regular node which allows a run
226227
studyClient.perform(post(STUDY_BASE_URL + DELIMITER + STUDY_DYNAMIC_SECURITY_ANALYSIS_END_POINT_RUN,
227228
studyUuid, firstRootNetworkUuid, modificationNode1Uuid)
229+
.param(QUERY_PARAM_DEBUG, "true")
228230
.header(HEADER_USER_ID_NAME, HEADER_USER_ID_VALUE))
229231
.andExpect(status().isOk());
230232

src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,13 @@ void testRunDynamicSimulationGivenRegularNodeAndFailed() throws Exception {
269269
UUID modificationNode1Uuid = modificationNode1.getId();
270270
when(loadFlowService.getLoadFlowStatus(any())).thenReturn(LoadFlowStatus.CONVERGED);
271271
// setup DynamicSimulationService mock
272-
Mockito.doAnswer(invocation -> RESULT_UUID).when(dynamicSimulationService).runDynamicSimulation(any(), eq(modificationNode1Uuid), eq(firstRootNetworkUuid), eq(NETWORK_UUID), eq(VARIANT_ID), any(), any(), any(), eq(true));
272+
Mockito.doAnswer(invocation -> RESULT_UUID)
273+
.when(dynamicSimulationService).runDynamicSimulation(
274+
any(), eq(modificationNode1Uuid), eq(firstRootNetworkUuid), eq(NETWORK_UUID), eq(VARIANT_ID),
275+
any(), any(), any(), eq(true));
273276

274277
// --- call endpoint to be tested --- //
275-
// run on a regular node which allows a run
278+
// run in debug mode on a regular node which allows a run
276279
studyClient.perform(post(STUDY_BASE_URL + DELIMITER + STUDY_DYNAMIC_SIMULATION_END_POINT_RUN,
277280
studyUuid, firstRootNetworkUuid, modificationNode1Uuid)
278281
.param(QUERY_PARAM_DEBUG, "true")

src/test/java/org/gridsuite/study/server/VoltageInitTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class VoltageInitTest {
265265

266266
//output destinations
267267
private final String studyUpdateDestination = "study.update";
268+
private final String voltageInitDebugDestination = "voltageinit.debug";
268269
private final String voltageInitResultDestination = "voltageinit.result";
269270
private final String voltageInitStoppedDestination = "voltageinit.stopped";
270271
private final String voltageInitFailedDestination = "voltageinit.run.dlx";
@@ -316,7 +317,22 @@ public MockResponse dispatch(RecordedRequest request) {
316317
.setHeader(HEADER_VOLTAGE_LEVEL_LIMITS_OUT_OF_NOMINAL_VOLTAGE_RANGE, Boolean.TRUE)
317318
.build(), voltageInitResultDestination);
318319
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), voltageInitResultUuidStr2);
319-
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + ".*")) {
320+
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + "&debug=.*")) {
321+
String receiver = "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D";
322+
input.send(MessageBuilder.withPayload("")
323+
.setHeader("resultUuid", VOLTAGE_INIT_RESULT_UUID)
324+
.setHeader("receiver", receiver)
325+
.setHeader(HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, Boolean.TRUE)
326+
.setHeader(HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE, 10.)
327+
.setHeader(HEADER_VOLTAGE_LEVEL_LIMITS_OUT_OF_NOMINAL_VOLTAGE_RANGE, Boolean.TRUE)
328+
.build(), voltageInitResultDestination);
329+
// mock the notification from voltage-init-server to send a debug status notif
330+
input.send(MessageBuilder.withPayload("")
331+
.setHeader("resultUuid", VOLTAGE_INIT_RESULT_UUID)
332+
.setHeader("receiver", receiver)
333+
.build(), voltageInitDebugDestination);
334+
return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), voltageInitResultUuidStr);
335+
} else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2)) {
320336
input.send(MessageBuilder.withPayload("")
321337
.setHeader("resultUuid", VOLTAGE_INIT_RESULT_UUID)
322338
.setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%20%22rootNetworkUuid%22%3A%20%22" + request.getPath().split("%")[11].substring(4) + "%22%2C%20%22userId%22%3A%22userId%22%7D")
@@ -577,6 +593,8 @@ void testVoltageInit(final MockWebServer server) throws Exception {
577593
checkReactiveSlacksAlertMessagesReceived(studyNameUserIdUuid, 10.);
578594
checkVoltageLevelLimitsOutOfRangeAlertMessagesReceived(studyNameUserIdUuid);
579595

596+
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, firstRootNetworkUuid, NotificationService.COMPUTATION_DEBUG_FILE_STATUS);
597+
580598
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, firstRootNetworkUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS);
581599

582600
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID_2 + "&debug=true")));

0 commit comments

Comments
 (0)