From 68a392fbbb9a7a71e9f49ed161bc1cb1eb938d1a Mon Sep 17 00:00:00 2001 From: Slimane AMAR Date: Fri, 3 Jan 2025 15:49:11 +0100 Subject: [PATCH] Review Signed-off-by: Slimane AMAR --- pom.xml | 9 ++------- .../sld/server/NetworkAreaDiagramService.java | 13 +++++++++++-- ...ervice.java => NetworkAreaExecutionService.java} | 6 +++--- .../sld/server/SingleLineDiagramController.java | 13 +++---------- 4 files changed, 19 insertions(+), 22 deletions(-) rename src/main/java/com/powsybl/sld/server/{DiagramGenerationExecutionService.java => NetworkAreaExecutionService.java} (79%) diff --git a/pom.xml b/pom.xml index e5fd24d..da2c83a 100644 --- a/pom.xml +++ b/pom.xml @@ -131,8 +131,8 @@ springdoc-openapi-starter-webmvc-ui - io.micrometer - micrometer-core + org.springframework.boot + spring-boot-starter-actuator @@ -141,11 +141,6 @@ powsybl-config-classic runtime - - org.springframework.boot - spring-boot-starter-actuator - runtime - io.micrometer micrometer-registry-prometheus diff --git a/src/main/java/com/powsybl/sld/server/NetworkAreaDiagramService.java b/src/main/java/com/powsybl/sld/server/NetworkAreaDiagramService.java index d64971e..f0f799f 100644 --- a/src/main/java/com/powsybl/sld/server/NetworkAreaDiagramService.java +++ b/src/main/java/com/powsybl/sld/server/NetworkAreaDiagramService.java @@ -57,16 +57,25 @@ class NetworkAreaDiagramService { private final NetworkStoreService networkStoreService; private final GeoDataService geoDataService; + private final NetworkAreaExecutionService diagramExecutionService; private final ObjectMapper objectMapper; - public NetworkAreaDiagramService(NetworkStoreService networkStoreService, GeoDataService geoDataService, ObjectMapper objectMapper) { + public NetworkAreaDiagramService(NetworkStoreService networkStoreService, GeoDataService geoDataService, + NetworkAreaExecutionService diagramExecutionService, ObjectMapper objectMapper) { this.networkStoreService = networkStoreService; this.geoDataService = geoDataService; + this.diagramExecutionService = diagramExecutionService; this.objectMapper = objectMapper; } - public String getNetworkAreaDiagramSvg(UUID networkUuid, String variantId, List voltageLevelsIds, int depth, boolean withGeoData) { + public String getNetworkAreaDiagramSvgAsync(UUID networkUuid, String variantId, List voltageLevelsIds, int depth, boolean withGeoData) { + return diagramExecutionService + .supplyAsync(() -> getNetworkAreaDiagramSvg(networkUuid, variantId, voltageLevelsIds, depth, withGeoData)) + .join(); + } + + private String getNetworkAreaDiagramSvg(UUID networkUuid, String variantId, List voltageLevelsIds, int depth, boolean withGeoData) { try { SvgAndMetadata svgAndMetadata = generateNetworkAreaDiagramSvg(networkUuid, variantId, voltageLevelsIds, depth, withGeoData); String svg = svgAndMetadata.getSvg(); diff --git a/src/main/java/com/powsybl/sld/server/DiagramGenerationExecutionService.java b/src/main/java/com/powsybl/sld/server/NetworkAreaExecutionService.java similarity index 79% rename from src/main/java/com/powsybl/sld/server/DiagramGenerationExecutionService.java rename to src/main/java/com/powsybl/sld/server/NetworkAreaExecutionService.java index 0aecaed..3301e1f 100644 --- a/src/main/java/com/powsybl/sld/server/DiagramGenerationExecutionService.java +++ b/src/main/java/com/powsybl/sld/server/NetworkAreaExecutionService.java @@ -19,12 +19,12 @@ * @author Slimane Amar */ @Service -public class DiagramGenerationExecutionService { +public class NetworkAreaExecutionService { private ThreadPoolExecutor executorService; - public DiagramGenerationExecutionService(@Value("${max-concurrent-nad-generations}") int maxConcurrentNadGenerations, - @NonNull DiagramGenerationObserver diagramGenerationObserver) { + public NetworkAreaExecutionService(@Value("${max-concurrent-nad-generations}") int maxConcurrentNadGenerations, + @NonNull DiagramGenerationObserver diagramGenerationObserver) { executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(maxConcurrentNadGenerations); diagramGenerationObserver.createThreadPoolMetric(executorService); } diff --git a/src/main/java/com/powsybl/sld/server/SingleLineDiagramController.java b/src/main/java/com/powsybl/sld/server/SingleLineDiagramController.java index 2455ed4..a034331 100644 --- a/src/main/java/com/powsybl/sld/server/SingleLineDiagramController.java +++ b/src/main/java/com/powsybl/sld/server/SingleLineDiagramController.java @@ -27,7 +27,6 @@ import java.util.Collection; import java.util.List; import java.util.UUID; -import java.util.concurrent.ExecutionException; import static com.powsybl.sld.server.NetworkAreaDiagramService.*; import static com.powsybl.ws.commons.LogUtils.sanitizeParam; @@ -52,14 +51,10 @@ public class SingleLineDiagramController { private final NetworkAreaDiagramService networkAreaDiagramService; - private final DiagramGenerationExecutionService diagramExecutionService; - public SingleLineDiagramController(SingleLineDiagramService singleLineDiagramService, - NetworkAreaDiagramService networkAreaDiagramService, - DiagramGenerationExecutionService diagramExecutionService) { + NetworkAreaDiagramService networkAreaDiagramService) { this.singleLineDiagramService = singleLineDiagramService; this.networkAreaDiagramService = networkAreaDiagramService; - this.diagramExecutionService = diagramExecutionService; } // voltage levels @@ -272,12 +267,10 @@ public ResponseEntity> getAvailableSvgComponentLibraries() { @Parameter(description = "Voltage levels ids") @RequestParam(name = "voltageLevelsIds", required = false) List voltageLevelsIds, @Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId, @Parameter(description = "depth") @RequestParam(name = "depth", required = false) int depth, - @Parameter(description = "Initialize NAD with Geographical Data") @RequestParam(name = "withGeoData", defaultValue = "true") boolean withGeoData) throws InterruptedException, ExecutionException { + @Parameter(description = "Initialize NAD with Geographical Data") @RequestParam(name = "withGeoData", defaultValue = "true") boolean withGeoData) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("getNetworkAreaDiagramSvg request received with parameter networkUuid = {}, voltageLevelsIds = {}, depth = {}", networkUuid, sanitizeParam(voltageLevelsIds.toString()), depth); } - return diagramExecutionService - .supplyAsync(() -> networkAreaDiagramService.getNetworkAreaDiagramSvg(networkUuid, variantId, voltageLevelsIds, depth, withGeoData)) - .get(); + return networkAreaDiagramService.getNetworkAreaDiagramSvgAsync(networkUuid, variantId, voltageLevelsIds, depth, withGeoData); } }