From 756d3eab16f490df8b5e6d16573f0636108b36a2 Mon Sep 17 00:00:00 2001 From: Abdelsalem Date: Fri, 18 Aug 2023 13:08:44 +0200 Subject: [PATCH 1/9] springboot 3.1.2 Signed-off-by: Abdelsalem --- pom.xml | 8 +++----- .../shortcircuit/server/entities/FaultEmbeddable.java | 8 ++++---- .../shortcircuit/server/entities/FaultResultEntity.java | 2 +- .../server/entities/FeederResultEmbeddable.java | 4 ++-- .../shortcircuit/server/entities/GlobalStatusEntity.java | 6 +++--- .../server/entities/LimitViolationEmbeddable.java | 8 ++++---- .../server/entities/ShortCircuitAnalysisResultEntity.java | 2 +- .../server/ShortCircuitAnalysisControllerTest.java | 2 -- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index bc6685ac..67d72486 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.powsybl powsybl-parent-ws - 12 + 14 @@ -42,7 +42,7 @@ - 25 + 26 org.gridsuite.shortcircuit.server 3.11.1 @@ -218,10 +218,8 @@ org.springframework.cloud - spring-cloud-stream - test-jar + spring-cloud-stream-test-binder test - test-binder com.h2database diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultEmbeddable.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultEmbeddable.java index 20caa9fa..420af124 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultEmbeddable.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultEmbeddable.java @@ -11,10 +11,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; /** * @author Nicolas Noir diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultResultEntity.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultResultEntity.java index 6ee6b070..78505347 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultResultEntity.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/FaultResultEntity.java @@ -10,7 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.*; +import jakarta.persistence.*; import java.util.List; import java.util.UUID; diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/FeederResultEmbeddable.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/FeederResultEmbeddable.java index 50a708e7..c67d510b 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/FeederResultEmbeddable.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/FeederResultEmbeddable.java @@ -10,8 +10,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Embeddable; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; /** * @author Nicolas Noir diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/GlobalStatusEntity.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/GlobalStatusEntity.java index 8005ab63..a24d1c9d 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/GlobalStatusEntity.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/GlobalStatusEntity.java @@ -10,9 +10,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.io.Serializable; import java.util.UUID; diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/LimitViolationEmbeddable.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/LimitViolationEmbeddable.java index 2c94e1a5..669228d4 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/LimitViolationEmbeddable.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/LimitViolationEmbeddable.java @@ -11,10 +11,10 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; /** * @author Nicolas Noir diff --git a/src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitAnalysisResultEntity.java b/src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitAnalysisResultEntity.java index fefa9f71..d41ec58e 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitAnalysisResultEntity.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/entities/ShortCircuitAnalysisResultEntity.java @@ -10,7 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.*; +import jakarta.persistence.*; import java.time.ZonedDateTime; import java.util.Set; import java.util.UUID; diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index 16949986..715b8687 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -274,10 +274,8 @@ public void stopTest() throws Exception { .andReturn(); // stop shortcircuit analysis - assertNotNull(output.receive(TIMEOUT, "shortcircuitanalysis.run")); mockMvc.perform(put("/" + VERSION + "/results/{resultUuid}/stop" + "?receiver=me", RESULT_UUID)) .andExpect(status().isOk()); - assertNotNull(output.receive(TIMEOUT, "shortcircuitanalysis.cancel")); Message message = output.receive(TIMEOUT, "shortcircuitanalysis.stopped"); assertNotNull(message); From 91da49d6b6c04fe56f8fc510998d34d6b9a3395d Mon Sep 17 00:00:00 2001 From: Abdelsalem Date: Thu, 31 Aug 2023 14:22:08 +0200 Subject: [PATCH 2/9] fix swagger-ui Signed-off-by: Abdelsalem --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 67d72486..d8b19207 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui com.powsybl From 05a543150aa7faa083ff0d41a40d3c4deeb61eda Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Thu, 7 Sep 2023 11:49:54 +0200 Subject: [PATCH 3/9] pl.project13.maven:io.github.git-commit-id -> io.github.git-commit-id:git-commit-id-maven-plugin Signed-off-by: HARPER Jon --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d8b19207..6dc85f49 100644 --- a/pom.xml +++ b/pom.xml @@ -75,8 +75,8 @@ spring-boot-maven-plugin - pl.project13.maven - git-commit-id-plugin + io.github.git-commit-id + git-commit-id-maven-plugin From 2b388ddc9e9cb6d8f9f965541fc644c4b60384af Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Fri, 8 Sep 2023 18:25:39 +0200 Subject: [PATCH 4/9] spring cloud stream source (deprecated) -> output-bindings --- src/main/resources/config/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config/application.yaml b/src/main/resources/config/application.yaml index 5eeaaeca..8690e7fe 100644 --- a/src/main/resources/config/application.yaml +++ b/src/main/resources/config/application.yaml @@ -32,7 +32,7 @@ spring: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.stopped publishFailed-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.failed - source: publishRun;publishResult;publishCancel;publishStopped;publishFailed + output-bindings: publishRun;publishResult;publishCancel;publishStopped;publishFailed powsybl-ws: database: From 780921039c80d955a8ee1ee2a5e643419999d31f Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Wed, 13 Sep 2023 17:44:36 +0200 Subject: [PATCH 5/9] wrap loadflow parameters of json notification messages in an object for spring cloud stream 4+ compatibility when the object is null It works with 3.2.4 but with 4.0.3 i'm getting java.lang.ClassCastException: class [B cannot be cast to class java.lang.String For spring cloud stream 4 vs spring cloud stream 3, in both cases, our string is converted to a byte[] with content-type application/json, but for 3.2.4 the byte[] gets converted back to the original string, whereas with 4.0.3 it gets converted to the parsed json object. -> "null" -> [110, 117, 108, 108] (spring cloud to byte[]) -> null # instead of "null" With 3.2.4 the byte[] gets converted to string here: https://github.com/spring-cloud/spring-cloud-stream/blob/6bc8330dcbdee52e44266cbf0f0043cf4fc3c0d4/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/ApplicationJsonMessageMarshallingConverter.java#L109 With 4.0.3 it uses spring cloud function org.springframework.cloud.function.context.config.SmartCompositeMessageConverter which uses jackson readValue on the string. With 4.0.3 if I send a non null object, I get the previous behavior (because of an intermediate try/catch in spring cloud stream which falls back to restoring the string, I guess not very good for performance and design?): "com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT)" https://github.com/spring-cloud/spring-cloud-function/blob/cc740db82e27efee4e23af4ad8e1de6f6a6fc9e9/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/config/JsonMessageConverter.java#L98 --- .../server/service/ShortCircuitResultContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitResultContext.java b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitResultContext.java index 3bd24641..67886d8c 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitResultContext.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitResultContext.java @@ -33,6 +33,8 @@ public class ShortCircuitResultContext { public static final String REPORTER_ID_HEADER = "reporterId"; + private static final String MESSAGE_ROOT_NAME = "parameters"; + private final UUID resultUuid; private final ShortCircuitRunContext runContext; @@ -74,7 +76,9 @@ public static ShortCircuitResultContext fromMessage(Message message, Obj ShortCircuitParameters parameters; try { - parameters = objectMapper.readValue(message.getPayload(), ShortCircuitParameters.class); + // can't use the following line because jackson doesn't play well with null..? + // parameters = objectMapper.reader().withRootName(MESSAGE_ROOT_NAME).readValue(message.getPayload(), LoadFlowParametersInfos.class); + parameters = objectMapper.treeToValue(objectMapper.readTree(message.getPayload()).get(MESSAGE_ROOT_NAME), ShortCircuitParameters.class); } catch (JsonProcessingException e) { throw new UncheckedIOException(e); } @@ -89,7 +93,9 @@ public static ShortCircuitResultContext fromMessage(Message message, Obj public Message toMessage(ObjectMapper objectMapper) { String parametersJson; try { - parametersJson = objectMapper.writeValueAsString(runContext.getParameters()); + // can't use the following line because jackson doesn't play well with null..? + // parametersJson = objectMapper.writer().withRootName(MESSAGE_ROOT_NAME).writeValueAsString(runContext.getParameters()); + parametersJson = objectMapper.writeValueAsString(objectMapper.createObjectNode().putPOJO(MESSAGE_ROOT_NAME, runContext.getParameters())); } catch (JsonProcessingException e) { throw new UncheckedIOException(e); } From a254fc611fc0fdd53a0208824e8b40385757fe5c Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Thu, 14 Sep 2023 10:21:39 +0200 Subject: [PATCH 6/9] output-bindings readd suffixes?? --- src/main/resources/config/application.yaml | 2 +- .../server/ShortCircuitAnalysisControllerTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/resources/config/application.yaml b/src/main/resources/config/application.yaml index 8690e7fe..67bc8669 100644 --- a/src/main/resources/config/application.yaml +++ b/src/main/resources/config/application.yaml @@ -32,7 +32,7 @@ spring: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.stopped publishFailed-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.failed - output-bindings: publishRun;publishResult;publishCancel;publishStopped;publishFailed + output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-0 powsybl-ws: database: diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index 99ed04b2..336d8ee1 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -528,6 +528,9 @@ public void stopTest() throws Exception { mockMvc.perform(put("/" + VERSION + "/results/{resultUuid}/stop" + "?receiver=me", RESULT_UUID_TO_STOP)) .andExpect(status().isOk()); + assertNotNull(output.receive(TIMEOUT, shortCircuitAnalysisResultDestination)); + assertNotNull(output.receive(TIMEOUT, shortCircuitAnalysisCancelDestination)); + Message message = output.receive(TIMEOUT, shortCircuitAnalysisStoppedDestination); assertNotNull(message); assertEquals(RESULT_UUID_TO_STOP.toString(), message.getHeaders().get("resultUuid")); From 2f24bed5c0f4772aa1f352d055df7b7b9381db99 Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Thu, 14 Sep 2023 10:54:28 +0200 Subject: [PATCH 7/9] wip workaround hibernate change ??? the getFeederResults and getLimitViolations were empty, but now they have [null, null, null] ?? --- .../ShortCircuitAnalysisResultRepository.java | 12 ++++++++++++ .../server/service/ShortCircuitService.java | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java b/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java index 1632070c..98a8ff7f 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java @@ -151,6 +151,12 @@ public Optional findFullResults(UUID resultUui if (!result.isPresent()) { return result; } + // TODO why is this needed ? And is it needed in other places ? + result.get().getFaultResults().forEach(x -> { + x.getFeederResults().toArray(); +// x.getLimitViolations().toArray(); /// XXX not needed ? + }); + // using the the Hibernate First-Level Cache or Persistence Context // cf.https://vladmihalcea.com/spring-data-jpa-multiplebagfetchexception/ if (!result.get().getFaultResults().isEmpty()) { @@ -166,6 +172,12 @@ public Optional findResultsWithLimitViolations if (!result.isPresent()) { return result; } + // TODO why is this needed ? And is it needed in other places ? + result.get().getFaultResults().forEach(x -> { + x.getFeederResults().toArray(); +// x.getLimitViolations().toArray(); /// XXX not needed ? + }); + List faultResultsUuidWithLimitViolations = result.get().getFaultResults().stream() .filter(fr -> !fr.getLimitViolations().isEmpty()) .map(FaultResultEntity::getFaultResultUuid) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java index b5c1c25e..5a47de3e 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java @@ -137,6 +137,13 @@ public Page getFaultResultsPage(UUID resultUuid, FaultResultsMode m Optional result; // get without faultResults : FaultResultsM.NONE result = resultRepository.find(resultUuid); + + // TODO why is this needed ? And is it needed in other places ? + result.get().getFaultResults().forEach(x -> { + x.getFeederResults().toArray(); + x.getLimitViolations().toArray(); + }); + if (result.isPresent()) { Optional> faultResultEntitiesPage = Optional.empty(); switch (mode) { From 2a05da3b03a81ff8e6ae7907de17db85415d604a Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Thu, 21 Sep 2023 14:41:11 +0200 Subject: [PATCH 8/9] remove workaround springboot 3.1.3 hibernate 6.2.7 HH-16811 --- .../ShortCircuitAnalysisResultRepository.java | 12 ------------ .../server/service/ShortCircuitService.java | 7 ------- 2 files changed, 19 deletions(-) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java b/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java index 98a8ff7f..1632070c 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/repositories/ShortCircuitAnalysisResultRepository.java @@ -151,12 +151,6 @@ public Optional findFullResults(UUID resultUui if (!result.isPresent()) { return result; } - // TODO why is this needed ? And is it needed in other places ? - result.get().getFaultResults().forEach(x -> { - x.getFeederResults().toArray(); -// x.getLimitViolations().toArray(); /// XXX not needed ? - }); - // using the the Hibernate First-Level Cache or Persistence Context // cf.https://vladmihalcea.com/spring-data-jpa-multiplebagfetchexception/ if (!result.get().getFaultResults().isEmpty()) { @@ -172,12 +166,6 @@ public Optional findResultsWithLimitViolations if (!result.isPresent()) { return result; } - // TODO why is this needed ? And is it needed in other places ? - result.get().getFaultResults().forEach(x -> { - x.getFeederResults().toArray(); -// x.getLimitViolations().toArray(); /// XXX not needed ? - }); - List faultResultsUuidWithLimitViolations = result.get().getFaultResults().stream() .filter(fr -> !fr.getLimitViolations().isEmpty()) .map(FaultResultEntity::getFaultResultUuid) diff --git a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java index 5a47de3e..b5c1c25e 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitService.java @@ -137,13 +137,6 @@ public Page getFaultResultsPage(UUID resultUuid, FaultResultsMode m Optional result; // get without faultResults : FaultResultsM.NONE result = resultRepository.find(resultUuid); - - // TODO why is this needed ? And is it needed in other places ? - result.get().getFaultResults().forEach(x -> { - x.getFeederResults().toArray(); - x.getLimitViolations().toArray(); - }); - if (result.isPresent()) { Optional> faultResultEntitiesPage = Optional.empty(); switch (mode) { From 0b3f8cd354b0ca00af4762f451098b851fab47f0 Mon Sep 17 00:00:00 2001 From: HARPER Jon Date: Thu, 21 Sep 2023 14:52:02 +0200 Subject: [PATCH 9/9] springboot3 released in parent15 Signed-off-by: HARPER Jon --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dc85f49..f6367aad 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.powsybl powsybl-parent-ws - 14 + 15