diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/MessageType.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/MessageType.java similarity index 89% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/MessageType.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/MessageType.java index aed280fa..8a76c10b 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/MessageType.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/MessageType.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.messaging; /** * @author Antoine Bouhours diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStatusUpdate.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStatusUpdate.java similarity index 84% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStatusUpdate.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStatusUpdate.java index 494e15b4..7cee1605 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStatusUpdate.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStatusUpdate.java @@ -4,12 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.messaging; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; import java.time.Instant; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStep.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStep.java similarity index 81% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStep.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStep.java index 4d91d433..b7875ec8 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessExecutionStep.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessExecutionStep.java @@ -4,12 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.messaging; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.commons.types.result.ResultType; import java.time.Instant; import java.util.UUID; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessRunMessage.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessRunMessage.java similarity index 76% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessRunMessage.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessRunMessage.java index 8873ab16..1904163a 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessRunMessage.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/messaging/ProcessRunMessage.java @@ -4,10 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.messaging; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; import java.util.UUID; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessConfig.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/ProcessConfig.java similarity index 85% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessConfig.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/ProcessConfig.java index 419e426f..d5176671 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessConfig.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/ProcessConfig.java @@ -4,10 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.processconfig; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; import java.util.List; import java.util.UUID; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/SecurityAnalysisConfig.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/SecurityAnalysisConfig.java similarity index 83% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/SecurityAnalysisConfig.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/SecurityAnalysisConfig.java index b249cc8f..bda1e699 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/SecurityAnalysisConfig.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processconfig/SecurityAnalysisConfig.java @@ -4,7 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.processconfig; + +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; import java.util.List; import java.util.UUID; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessStatus.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessStatus.java similarity index 87% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessStatus.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessStatus.java index da5a24cc..b7e490d5 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessStatus.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessStatus.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.processexecution; /** * @author Antoine Bouhours diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessType.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessType.java similarity index 86% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessType.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessType.java index e5e54ac1..c4a13ec5 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ProcessType.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/ProcessType.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.processexecution; /** * @author Antoine Bouhours diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/StepStatus.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/StepStatus.java similarity index 87% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/StepStatus.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/StepStatus.java index 1c321d68..1f5dee0e 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/StepStatus.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/processexecution/StepStatus.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.processexecution; /** * @author Antoine Bouhours diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultInfos.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultInfos.java similarity index 89% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultInfos.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultInfos.java index 129ed1eb..5a56067c 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultInfos.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultInfos.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.result; import java.util.UUID; diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultType.java b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultType.java similarity index 88% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultType.java rename to monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultType.java index 19864a79..2f766dd0 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/ResultType.java +++ b/monitor-commons/src/main/java/org/gridsuite/monitor/commons/types/result/ResultType.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.commons.types.result; /** * @author Antoine Bouhours diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/ReportRestClient.java similarity index 79% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/clients/ReportRestClient.java index 4291f4e6..3788df96 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportRestService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/ReportRestClient.java @@ -4,9 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; -import org.gridsuite.monitor.server.dto.ReportPage; +import org.gridsuite.monitor.server.dto.report.ReportPage; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.stereotype.Service; @@ -18,14 +18,14 @@ * @author Franck Lecuyer */ @Service -public class ReportRestService { +public class ReportRestClient { private static final String REPORT_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient restClient; - public ReportRestService(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri, - RestClient.Builder restClientBuilder) { + public ReportRestClient(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri, + RestClient.Builder restClientBuilder) { this.restClient = restClientBuilder .baseUrl(reportServerBaseUri + DELIMITER + REPORT_API_VERSION + DELIMITER + "reports") .build(); diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/S3RestService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/S3RestClient.java similarity index 95% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/S3RestService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/clients/S3RestClient.java index 0c5b62d5..b4179967 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/S3RestService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/S3RestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; import software.amazon.awssdk.services.s3.S3Client; import software.amazon.awssdk.services.s3.model.*; @@ -21,12 +21,12 @@ /** * @author Kevin Le Saulnier */ -public class S3RestService { +public class S3RestClient { private final S3Client s3Client; private final String bucketName; - public S3RestService(S3Client s3Client, String bucketName) { + public S3RestClient(S3Client s3Client, String bucketName) { this.s3Client = s3Client; this.bucketName = bucketName; } diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClient.java similarity index 92% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClient.java index 98ed0f44..aacbb51c 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -15,13 +15,13 @@ * @author Kevin Le Saulnier */ @Service -public class SecurityAnalysisRestService { +public class SecurityAnalysisRestClient { static final String SA_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient restClient; - public SecurityAnalysisRestService( + public SecurityAnalysisRestClient( RestClient.Builder restClientBuilder, @Value("${gridsuite.services.security-analysis-server.base-uri:http://security-analysis-server/}") String securityAnalysisServerBaseUri) { this.restClient = restClientBuilder diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/config/S3Configuration.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/config/S3Configuration.java index 63712374..ab216c07 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/config/S3Configuration.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/config/S3Configuration.java @@ -6,7 +6,7 @@ */ package org.gridsuite.monitor.server.config; -import org.gridsuite.monitor.server.services.S3RestService; +import org.gridsuite.monitor.server.clients.S3RestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -28,8 +28,8 @@ public S3Configuration(@Value("${spring.cloud.aws.bucket:ws-bucket}") String buc @SuppressWarnings("checkstyle:MethodName") @Bean - public S3RestService s3RestService(S3Client s3Client) { + public S3RestClient s3RestService(S3Client s3Client) { LOGGER.info("Configuring S3Service with bucket: {}", bucketName); - return new S3RestService(s3Client, bucketName); + return new S3RestClient(s3Client, bucketName); } } diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java index d07f99b8..99bb4d5c 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java @@ -11,11 +11,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.server.dto.ProcessExecution; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.services.MonitorService; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.dto.processexecution.ProcessExecution; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.services.processexecution.ProcessExecutionService; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -33,12 +33,12 @@ @Tag(name = "Monitor server") public class MonitorController { - private final MonitorService monitorService; + private final ProcessExecutionService processExecutionService; public static final String HEADER_USER_ID = "userId"; - public MonitorController(MonitorService monitorService) { - this.monitorService = monitorService; + public MonitorController(ProcessExecutionService processExecutionService) { + this.processExecutionService = processExecutionService; } @PostMapping("/execute") @@ -50,7 +50,7 @@ public ResponseEntity executeProcess( @Parameter(description = "Process config uuid") @RequestParam(name = "processConfigUuid") UUID processConfigUuid, @RequestParam(required = false, defaultValue = "false") boolean isDebug, @RequestHeader(HEADER_USER_ID) String userId) { - Optional executionId = monitorService.executeProcess(caseUuid, userId, processConfigUuid, isDebug); + Optional executionId = processExecutionService.executeProcess(caseUuid, userId, processConfigUuid, isDebug); return executionId.isPresent() ? ResponseEntity.ok(executionId.get()) : ResponseEntity.notFound().build(); } @@ -58,7 +58,7 @@ public ResponseEntity executeProcess( @Operation(summary = "Get reports for an execution") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The execution reports")}) public ResponseEntity> getExecutionReports(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) { - List reports = monitorService.getReports(executionId); + List reports = processExecutionService.getReports(executionId); return ResponseEntity.ok(reports); } @@ -66,7 +66,7 @@ public ResponseEntity> getExecutionReports(@Parameter(descripti @Operation(summary = "Get results for an execution") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The execution results")}) public ResponseEntity> getExecutionResults(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) { - List results = monitorService.getResults(executionId); + List results = processExecutionService.getResults(executionId); return ResponseEntity.ok(results); } @@ -74,7 +74,7 @@ public ResponseEntity> getExecutionResults(@Parameter(description = @Operation(summary = "Get launched processes") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The launched processes")}) public ResponseEntity> getLaunchedProcesses(@Parameter(description = "Process type") @RequestParam(name = "processType") ProcessType processType) { - return ResponseEntity.ok(monitorService.getLaunchedProcesses(processType)); + return ResponseEntity.ok(processExecutionService.getLaunchedProcesses(processType)); } @GetMapping("/executions/{executionId}/step-infos") @@ -83,7 +83,7 @@ public ResponseEntity> getLaunchedProcesses(@Parameter(de @ApiResponse(responseCode = "200", description = "The execution steps statuses"), @ApiResponse(responseCode = "404", description = "execution id was not found")}) public ResponseEntity> getStepsInfos(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) { - return monitorService.getStepsInfos(executionId).map(list -> ResponseEntity.ok().body(list)) + return processExecutionService.getStepsInfos(executionId).map(list -> ResponseEntity.ok().body(list)) .orElseGet(() -> ResponseEntity.notFound().build()); } @@ -93,7 +93,7 @@ public ResponseEntity> getStepsInfos(@Parameter(descr @ApiResponse(responseCode = "200", description = "Debug file downloaded"), @ApiResponse(responseCode = "404", description = "execution id was not found")}) public ResponseEntity getDebugInfos(@Parameter(description = "Execution UUID") @PathVariable UUID executionId) { - return monitorService.getDebugInfos(executionId) + return processExecutionService.getDebugInfos(executionId) .map(bytes -> ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"archive.zip\"") @@ -108,7 +108,7 @@ public ResponseEntity getDebugInfos(@Parameter(description = "Execution @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Execution was deleted"), @ApiResponse(responseCode = "404", description = "Execution was not found")}) public ResponseEntity deleteExecution(@PathVariable UUID executionId) { - return monitorService.deleteExecution(executionId) ? + return processExecutionService.deleteExecution(executionId) ? ResponseEntity.ok().build() : ResponseEntity.notFound().build(); } diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java index 869e74d8..2236c41d 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java @@ -11,11 +11,11 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import org.gridsuite.monitor.commons.PersistedProcessConfig; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.server.dto.ProcessConfigComparison; -import org.gridsuite.monitor.server.services.ProcessConfigService; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigComparison; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Report.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Report.java deleted file mode 100644 index aa158854..00000000 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Report.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.server.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; - -import java.util.List; -import java.util.UUID; - -/** - * @author Antoine Bouhours - */ -@Schema(description = "Report data") -@Builder -public record Report( - UUID id, - UUID parentId, - String message, - Severity severity, - List subReports -) { } diff --git a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/PersistedProcessConfig.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/PersistedProcessConfig.java similarity index 77% rename from monitor-commons/src/main/java/org/gridsuite/monitor/commons/PersistedProcessConfig.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/PersistedProcessConfig.java index fe78f7da..b0bfb67c 100644 --- a/monitor-commons/src/main/java/org/gridsuite/monitor/commons/PersistedProcessConfig.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/PersistedProcessConfig.java @@ -4,7 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.commons; +package org.gridsuite.monitor.server.dto.processconfig; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; import java.util.UUID; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigComparison.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigComparison.java similarity index 92% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigComparison.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigComparison.java index cb811bfe..0b7fd42b 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigComparison.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigComparison.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.processconfig; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigFieldComparison.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigFieldComparison.java similarity index 90% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigFieldComparison.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigFieldComparison.java index 3fc8627f..71fd2310 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessConfigFieldComparison.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/ProcessConfigFieldComparison.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.processconfig; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessExecution.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processexecution/ProcessExecution.java similarity index 85% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessExecution.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processexecution/ProcessExecution.java index e44de71b..98b42968 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ProcessExecution.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processexecution/ProcessExecution.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.processexecution; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; -import org.gridsuite.monitor.commons.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; import java.time.Instant; import java.util.UUID; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportLog.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportLog.java similarity index 94% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportLog.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportLog.java index 01b39434..16506563 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportLog.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportLog.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.report; import com.fasterxml.jackson.annotation.JsonCreator; import lombok.Getter; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportPage.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportPage.java similarity index 89% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportPage.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportPage.java index 40fd1f5f..68922c2c 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/ReportPage.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/ReportPage.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.report; import org.springframework.data.domain.Page; @@ -16,6 +16,8 @@ * non-serializable instances (e.g., Pageable.unpaged()), making them unsuitable * for direct API responses. This record contains only the essential pagination * data needed by clients. + * + * @author Franck Lecuyer */ public record ReportPage(int number, List content, long totalElements, int totalPages) { public ReportPage(Page page) { diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Severity.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/Severity.java similarity index 94% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Severity.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/Severity.java index ae0a71f8..a007f187 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/Severity.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/dto/report/Severity.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.dto; +package org.gridsuite.monitor.server.dto.report; /** * @author Antoine Bouhours diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessConfigEntity.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/ProcessConfigEntity.java similarity index 94% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessConfigEntity.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/ProcessConfigEntity.java index 6cbd950f..e3c303cb 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessConfigEntity.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/ProcessConfigEntity.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.entities; +package org.gridsuite.monitor.server.entities.processconfig; import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; @@ -27,7 +27,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.gridsuite.monitor.commons.ProcessType; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; import java.util.List; import java.util.UUID; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/SecurityAnalysisConfigEntity.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/SecurityAnalysisConfigEntity.java similarity index 95% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/entities/SecurityAnalysisConfigEntity.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/SecurityAnalysisConfigEntity.java index b16b9c02..dc1776bc 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/SecurityAnalysisConfigEntity.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processconfig/SecurityAnalysisConfigEntity.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.entities; +package org.gridsuite.monitor.server.entities.processconfig; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorValue; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionEntity.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionEntity.java similarity index 91% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionEntity.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionEntity.java index da653890..6bf75dee 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionEntity.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionEntity.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.entities; +package org.gridsuite.monitor.server.entities.processexecution; import jakarta.persistence.*; import lombok.*; -import org.gridsuite.monitor.commons.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; import java.time.Instant; import java.util.List; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionStepEntity.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionStepEntity.java similarity index 83% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionStepEntity.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionStepEntity.java index a2b0a955..b498b631 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/ProcessExecutionStepEntity.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/entities/processexecution/ProcessExecutionStepEntity.java @@ -4,12 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.entities; +package org.gridsuite.monitor.server.entities.processexecution; import jakarta.persistence.*; import lombok.*; -import org.gridsuite.monitor.commons.ResultType; -import org.gridsuite.monitor.commons.StepStatus; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; import java.time.Instant; import java.util.UUID; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapper.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapper.java similarity index 78% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapper.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapper.java index acf3ef10..ba9089e4 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapper.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapper.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.mapper; +package org.gridsuite.monitor.server.mappers.processconfig; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.server.entities.SecurityAnalysisConfigEntity; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.server.entities.processconfig.SecurityAnalysisConfigEntity; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionMapper.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionMapper.java similarity index 69% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionMapper.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionMapper.java index 5f478331..3ec9a4c6 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionMapper.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionMapper.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.mapper; +package org.gridsuite.monitor.server.mappers.processexecution; -import org.gridsuite.monitor.server.dto.ProcessExecution; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; +import org.gridsuite.monitor.server.dto.processexecution.ProcessExecution; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; import org.mapstruct.Mapper; /** diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapper.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapper.java similarity index 78% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapper.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapper.java index ce8bdafb..9940cef6 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapper.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapper.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.mapper; +package org.gridsuite.monitor.server.mappers.processexecution; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.server.entities.ProcessExecutionStepEntity; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionStepEntity; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ConsumerService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java similarity index 78% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/ConsumerService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java index d134038f..9c93957c 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ConsumerService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java @@ -4,14 +4,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.messaging; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.commons.MessageType; -import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate; -import org.gridsuite.monitor.commons.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.messaging.MessageType; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.server.services.processexecution.ProcessExecutionService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,12 +36,12 @@ public class ConsumerService { public static final String HEADER_MESSAGE_TYPE = "messageType"; public static final String HEADER_EXECUTION_ID = "executionId"; - private final MonitorService monitorService; + private final ProcessExecutionService processExecutionService; private final ObjectMapper objectMapper; @Autowired - public ConsumerService(MonitorService monitorService, ObjectMapper objectMapper) { - this.monitorService = monitorService; + public ConsumerService(ProcessExecutionService processExecutionService, ObjectMapper objectMapper) { + this.processExecutionService = processExecutionService; this.objectMapper = objectMapper; } @@ -63,17 +64,17 @@ public Consumer> consumeMonitorUpdate() { private void handleExecutionStatusUpdate(UUID executionId, Message message) { ProcessExecutionStatusUpdate payload = parsePayload(message.getPayload(), ProcessExecutionStatusUpdate.class); - monitorService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt()); + processExecutionService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt()); } private void handleStepStatusUpdate(UUID executionId, Message message) { ProcessExecutionStep processExecutionStep = parsePayload(message.getPayload(), ProcessExecutionStep.class); - monitorService.updateStepStatus(executionId, processExecutionStep); + processExecutionService.updateStepStatus(executionId, processExecutionStep); } private void handleStepsStatusesUpdate(UUID executionId, Message message) { List processExecutionSteps = parsePayload(message.getPayload(), new TypeReference>() { }); - monitorService.updateStepsStatuses(executionId, processExecutionSteps); + processExecutionService.updateStepsStatuses(executionId, processExecutionSteps); } private T parsePayload(String payload, Class clazz) { diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/NotificationService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/NotificationService.java similarity index 84% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/NotificationService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/NotificationService.java index 49202af8..f107489b 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/NotificationService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/NotificationService.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.messaging; import lombok.RequiredArgsConstructor; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; import org.springframework.cloud.stream.function.StreamBridge; import org.springframework.stereotype.Service; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessConfigRepository.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessConfigRepository.java index 3a8f37ad..bafc6d23 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessConfigRepository.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessConfigRepository.java @@ -6,8 +6,8 @@ */ package org.gridsuite.monitor.server.repositories; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.server.entities.ProcessConfigEntity; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.entities.processconfig.ProcessConfigEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepository.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepository.java index 5c2938a9..fb91cc56 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepository.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepository.java @@ -6,7 +6,7 @@ */ package org.gridsuite.monitor.server.repositories; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ProcessConfigService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java similarity index 89% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/ProcessConfigService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java index c9e250ff..ff4608b1 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ProcessConfigService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java @@ -4,17 +4,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; - -import org.gridsuite.monitor.commons.PersistedProcessConfig; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.server.dto.ProcessConfigComparison; -import org.gridsuite.monitor.server.dto.ProcessConfigFieldComparison; -import org.gridsuite.monitor.server.entities.ProcessConfigEntity; -import org.gridsuite.monitor.server.entities.SecurityAnalysisConfigEntity; -import org.gridsuite.monitor.server.mapper.SecurityAnalysisConfigMapper; +package org.gridsuite.monitor.server.services.processconfig; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigComparison; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigFieldComparison; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.server.entities.processconfig.ProcessConfigEntity; +import org.gridsuite.monitor.server.entities.processconfig.SecurityAnalysisConfigEntity; +import org.gridsuite.monitor.server.mappers.processconfig.SecurityAnalysisConfigMapper; import org.gridsuite.monitor.server.repositories.ProcessConfigRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionService.java similarity index 73% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionService.java index a6226525..ba2fceea 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionService.java @@ -4,24 +4,29 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.processexecution; import com.powsybl.commons.PowsyblException; -import org.gridsuite.monitor.commons.PersistedProcessConfig; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.clients.ReportRestClient; +import org.gridsuite.monitor.server.dto.processexecution.ProcessExecution; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionStepEntity; +import org.gridsuite.monitor.server.mappers.processexecution.ProcessExecutionMapper; +import org.gridsuite.monitor.server.mappers.processexecution.ProcessExecutionStepMapper; +import org.gridsuite.monitor.server.messaging.NotificationService; +import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository; +import org.gridsuite.monitor.server.clients.S3RestClient; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; +import org.gridsuite.monitor.server.services.result.ResultService; +import org.gridsuite.monitor.server.utils.S3PathResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.ProcessStatus; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.ResultInfos; -import org.gridsuite.monitor.server.mapper.ProcessExecutionMapper; -import org.gridsuite.monitor.server.mapper.ProcessExecutionStepMapper; -import org.gridsuite.monitor.server.utils.S3PathResolver; -import org.gridsuite.monitor.server.dto.ProcessExecution; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; -import org.gridsuite.monitor.server.entities.ProcessExecutionStepEntity; -import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,36 +38,36 @@ * @author Antoine Bouhours */ @Service -public class MonitorService { +public class ProcessExecutionService { - private static final Logger LOGGER = LoggerFactory.getLogger(MonitorService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ProcessExecutionService.class); - private final ProcessExecutionRepository executionRepository; + private final ProcessExecutionRepository processExecutionRepository; private final NotificationService notificationService; private final ProcessConfigService processConfigService; - private final ReportRestService reportRestService; + private final ReportRestClient reportRestClient; private final ResultService resultService; - private final S3RestService s3RestService; + private final S3RestClient s3RestClient; private final S3PathResolver s3PathResolver; private final ProcessExecutionStepMapper processExecutionStepMapper; private final ProcessExecutionMapper processExecutionMapper; - public MonitorService(ProcessExecutionRepository executionRepository, + public ProcessExecutionService(ProcessExecutionRepository processExecutionRepository, NotificationService notificationService, ProcessConfigService processConfigService, - ReportRestService reportRestService, + ReportRestClient reportRestClient, ResultService resultService, - S3RestService s3RestService, + S3RestClient s3RestClient, S3PathResolver s3PathResolver, ProcessExecutionStepMapper processExecutionStepMapper, ProcessExecutionMapper processExecutionMapper) { - this.executionRepository = executionRepository; + this.processExecutionRepository = processExecutionRepository; this.notificationService = notificationService; this.processConfigService = processConfigService; - this.reportRestService = reportRestService; + this.reportRestClient = reportRestClient; this.resultService = resultService; - this.s3RestService = s3RestService; + this.s3RestClient = s3RestClient; this.s3PathResolver = s3PathResolver; this.processExecutionStepMapper = processExecutionStepMapper; this.processExecutionMapper = processExecutionMapper; @@ -85,7 +90,7 @@ public Optional executeProcess(UUID caseUuid, String userId, UUID processC if (isDebug) { execution.setDebugFileLocation(s3PathResolver.toDebugLocation(persistedProcessConfig.get().processConfig().processType().name(), executionId)); } - executionRepository.save(execution); + processExecutionRepository.save(execution); notificationService.sendProcessRunMessage(caseUuid, persistedProcessConfig.get().processConfig(), execution.getId(), execution.getDebugFileLocation()); @@ -97,7 +102,7 @@ public Optional executeProcess(UUID caseUuid, String userId, UUID processC @Transactional public void updateExecutionStatus(UUID executionId, ProcessStatus status, String executionEnvName, Instant startedAt, Instant completedAt) { - executionRepository.findById(executionId).ifPresentOrElse(execution -> { + processExecutionRepository.findById(executionId).ifPresentOrElse(execution -> { execution.setStatus(status); if (executionEnvName != null) { execution.setExecutionEnvName(executionEnvName); @@ -108,7 +113,7 @@ public void updateExecutionStatus(UUID executionId, ProcessStatus status, String if (completedAt != null) { execution.setCompletedAt(completedAt); } - executionRepository.save(execution); + processExecutionRepository.save(execution); }, () -> LOGGER.warn("Execution {} not found in DB, ignoring status update", executionId)); } @@ -128,21 +133,21 @@ private void updateStep(ProcessExecutionEntity execution, ProcessExecutionStepEn @Transactional public void updateStepStatus(UUID executionId, ProcessExecutionStep processExecutionStep) { - executionRepository.findById(executionId).ifPresentOrElse(execution -> { + processExecutionRepository.findById(executionId).ifPresentOrElse(execution -> { ProcessExecutionStepEntity stepEntity = processExecutionStepMapper.toEntity(processExecutionStep); updateStep(execution, stepEntity); - executionRepository.save(execution); + processExecutionRepository.save(execution); }, () -> LOGGER.warn("Execution {} not found in DB, ignoring step update", executionId)); } @Transactional public void updateStepsStatuses(UUID executionId, List processExecutionSteps) { - executionRepository.findById(executionId).ifPresentOrElse(execution -> { + processExecutionRepository.findById(executionId).ifPresentOrElse(execution -> { processExecutionSteps.forEach(processExecutionStep -> { ProcessExecutionStepEntity stepEntity = processExecutionStepMapper.toEntity(processExecutionStep); updateStep(execution, stepEntity); }); - executionRepository.save(execution); + processExecutionRepository.save(execution); }, () -> LOGGER.warn("Execution {} not found in DB, ignoring steps update", executionId)); } @@ -150,12 +155,12 @@ public void updateStepsStatuses(UUID executionId, List pro public List getReports(UUID executionId) { List reportIds = getReportIds(executionId); return reportIds.stream() - .map(reportRestService::getReport) + .map(reportRestClient::getReport) .toList(); } private List getReportIds(UUID executionId) { - return executionRepository.findById(executionId) + return processExecutionRepository.findById(executionId) .map(execution -> Optional.ofNullable(execution.getSteps()).orElse(List.of()).stream() .map(ProcessExecutionStepEntity::getReportId) .filter(java.util.Objects::nonNull) @@ -173,12 +178,12 @@ public List getResults(UUID executionId) { @Transactional(readOnly = true) public Optional getDebugInfos(UUID executionId) { - return executionRepository.findById(executionId) + return processExecutionRepository.findById(executionId) .map(ProcessExecutionEntity::getDebugFileLocation) .filter(Objects::nonNull) .map(debugFileLocation -> { try { - return s3RestService.downloadDirectoryAsZip(debugFileLocation); + return s3RestClient.downloadDirectoryAsZip(debugFileLocation); } catch (IOException e) { throw new PowsyblException("An error occurred while downloading debug files", e); } @@ -186,7 +191,7 @@ public Optional getDebugInfos(UUID executionId) { } private List getResultInfos(UUID executionId) { - return executionRepository.findById(executionId) + return processExecutionRepository.findById(executionId) .map(execution -> Optional.ofNullable(execution.getSteps()).orElse(List.of()).stream() .filter(step -> step.getResultId() != null) .map(step -> new ResultInfos(step.getResultId(), step.getResultType())) @@ -196,13 +201,13 @@ private List getResultInfos(UUID executionId) { @Transactional(readOnly = true) public List getLaunchedProcesses(ProcessType processType) { - return executionRepository.findByTypeAndStartedAtIsNotNullOrderByStartedAtDesc(processType.name()).stream() + return processExecutionRepository.findByTypeAndStartedAtIsNotNullOrderByStartedAtDesc(processType.name()).stream() .map(processExecutionMapper::toDto).toList(); } @Transactional(readOnly = true) public Optional> getStepsInfos(UUID executionId) { - Optional entity = executionRepository.findById(executionId); + Optional entity = processExecutionRepository.findById(executionId); if (entity.isPresent()) { return entity.map(execution -> Optional.ofNullable(execution.getSteps()).orElse(List.of()).stream() .map(processExecutionStepMapper::toDto) @@ -217,7 +222,7 @@ public boolean deleteExecution(UUID executionId) { List resultIds = new ArrayList<>(); List reportIds = new ArrayList<>(); - Optional executionEntity = executionRepository.findById(executionId); + Optional executionEntity = processExecutionRepository.findById(executionId); if (executionEntity.isPresent()) { ProcessExecutionEntity entity = executionEntity.get(); Optional.ofNullable(entity.getSteps()).orElse(List.of()).forEach(step -> { @@ -229,9 +234,9 @@ public boolean deleteExecution(UUID executionId) { } }); resultIds.forEach(resultService::deleteResult); - reportIds.forEach(reportRestService::deleteReport); + reportIds.forEach(reportRestClient::deleteReport); - executionRepository.delete(entity); + processExecutionRepository.delete(entity); return true; } diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultProvider.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultProvider.java similarity index 81% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultProvider.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultProvider.java index e66f2d0f..2411557e 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultProvider.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultProvider.java @@ -4,9 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.result; -import org.gridsuite.monitor.commons.ResultType; +import org.gridsuite.monitor.commons.types.result.ResultType; import java.util.UUID; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultService.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultService.java similarity index 89% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultService.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultService.java index 3e1bd22d..11d4ae4d 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultService.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/ResultService.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.result; -import org.gridsuite.monitor.commons.ResultInfos; -import org.gridsuite.monitor.commons.ResultType; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; import org.springframework.stereotype.Service; import java.util.List; diff --git a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProvider.java b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProvider.java similarity index 53% rename from monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProvider.java rename to monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProvider.java index 3cbfbd03..8cff095c 100644 --- a/monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProvider.java +++ b/monitor-server/src/main/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProvider.java @@ -4,9 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.result.providers; -import org.gridsuite.monitor.commons.ResultType; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.server.services.result.ResultProvider; +import org.gridsuite.monitor.server.clients.SecurityAnalysisRestClient; import org.springframework.stereotype.Service; import java.util.UUID; @@ -16,10 +18,10 @@ */ @Service public class SecurityAnalysisResultProvider implements ResultProvider { - private final SecurityAnalysisRestService securityAnalysisRestService; + private final SecurityAnalysisRestClient securityAnalysisRestClient; - public SecurityAnalysisResultProvider(SecurityAnalysisRestService securityAnalysisRestService) { - this.securityAnalysisRestService = securityAnalysisRestService; + public SecurityAnalysisResultProvider(SecurityAnalysisRestClient securityAnalysisRestClient) { + this.securityAnalysisRestClient = securityAnalysisRestClient; } @Override @@ -29,11 +31,11 @@ public ResultType getType() { @Override public String getResult(UUID resultId) { - return securityAnalysisRestService.getResult(resultId); + return securityAnalysisRestClient.getResult(resultId); } @Override public void deleteResult(UUID resultId) { - securityAnalysisRestService.deleteResult(resultId); + securityAnalysisRestClient.deleteResult(resultId); } } diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java index 8059178a..83232fbd 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java @@ -7,14 +7,26 @@ package org.gridsuite.monitor.server; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.commons.*; -import org.gridsuite.monitor.server.dto.ReportLog; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.dto.Severity; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.*; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.MessageType; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.server.clients.ReportRestClient; +import org.gridsuite.monitor.server.dto.report.ReportLog; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.dto.report.Severity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; +import org.gridsuite.monitor.server.messaging.ConsumerService; import org.gridsuite.monitor.server.repositories.ProcessConfigRepository; import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository; -import org.gridsuite.monitor.server.services.*; +import org.gridsuite.monitor.server.clients.S3RestClient; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; +import org.gridsuite.monitor.server.services.processexecution.ProcessExecutionService; +import org.gridsuite.monitor.server.services.result.ResultService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -50,7 +62,7 @@ class MonitorIntegrationTest { @Autowired - private MonitorService monitorService; + private ProcessExecutionService processExecutionService; @Autowired private ProcessConfigService configService; @@ -74,13 +86,13 @@ class MonitorIntegrationTest { private MockMvc mockMvc; @MockitoBean - private ReportRestService reportRestService; + private ReportRestClient reportRestClient; @MockitoBean private ResultService resultService; @MockitoBean - private S3RestService s3RestService; + private S3RestClient s3RestClient; private UUID caseUuid; @@ -103,7 +115,7 @@ void securityAnalysisProcessIT() throws Exception { UUID.randomUUID()); UUID processConfigId = configService.createProcessConfig(securityAnalysisConfig); - Optional executionId = monitorService.executeProcess(caseUuid, userId, processConfigId, false); + Optional executionId = processExecutionService.executeProcess(caseUuid, userId, processConfigId, false); // Verify message was published Message sentMessage = outputDestination.receive(1000, PROCESS_SA_RUN_DESTINATION); @@ -184,8 +196,8 @@ void securityAnalysisProcessIT() throws Exception { new ReportLog("message2", Severity.WARN, 2, UUID.randomUUID())), 100, 10); ReportPage reportPage1 = new ReportPage(2, List.of(new ReportLog("message3", Severity.ERROR, 3, UUID.randomUUID())), 200, 20); - when(reportRestService.getReport(reportId0)).thenReturn(reportPage0); - when(reportRestService.getReport(reportId1)).thenReturn(reportPage1); + when(reportRestClient.getReport(reportId0)).thenReturn(reportPage0); + when(reportRestClient.getReport(reportId1)).thenReturn(reportPage1); // Test the reports endpoint fetches correctly from database mockMvc.perform(get("/v1/executions/{executionId}/reports", executionId.get())) diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ReportRestServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/ReportRestClientTest.java similarity index 80% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/ReportRestServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/clients/ReportRestClientTest.java index 709e6c6a..6ffa1f47 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ReportRestServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/ReportRestClientTest.java @@ -4,13 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.server.dto.ReportLog; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.dto.Severity; +import org.gridsuite.monitor.server.dto.report.ReportLog; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.dto.report.Severity; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; @@ -32,11 +32,11 @@ /** * @author Franck Lecuyer */ -@RestClientTest(ReportRestService.class) -@ContextConfiguration(classes = {ReportRestService.class}) -class ReportRestServiceTest { +@RestClientTest(ReportRestClient.class) +@ContextConfiguration(classes = {ReportRestClient.class}) +class ReportRestClientTest { @Autowired - private ReportRestService reportRestService; + private ReportRestClient reportRestClient; @Autowired private MockRestServiceServer server; @@ -58,7 +58,7 @@ void getReport() throws JsonProcessingException { .contentType(MediaType.APPLICATION_JSON) .body(objectMapper.writeValueAsString(reportPage))); - ReportPage reportResult = reportRestService.getReport(reportId); + ReportPage reportResult = reportRestClient.getReport(reportId); assertThat(reportResult).usingRecursiveComparison().isEqualTo(reportPage); } @@ -70,7 +70,7 @@ void getReportFailed() { .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId + "/logs")) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> reportRestService.getReport(reportId)).isInstanceOf(RestClientException.class); + assertThatThrownBy(() -> reportRestClient.getReport(reportId)).isInstanceOf(RestClientException.class); } @Test @@ -81,7 +81,7 @@ void deleteReport() { .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId)) .andRespond(MockRestResponseCreators.withSuccess()); - assertThatNoException().isThrownBy(() -> reportRestService.deleteReport(reportId)); + assertThatNoException().isThrownBy(() -> reportRestClient.deleteReport(reportId)); } @Test @@ -92,6 +92,6 @@ void deleteReportFailed() { .andExpect(MockRestRequestMatchers.requestTo("http://report-server/v1/reports/" + reportId)) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> reportRestService.deleteReport(reportId)).isInstanceOf(RestClientException.class); + assertThatThrownBy(() -> reportRestClient.deleteReport(reportId)).isInstanceOf(RestClientException.class); } } diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/S3RestServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/S3RestClientTest.java similarity index 92% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/S3RestServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/clients/S3RestClientTest.java index fb1c8563..fec3d1da 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/S3RestServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/S3RestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,9 +31,9 @@ * @author Kevin Le Saulnier */ @ExtendWith(MockitoExtension.class) -class S3RestServiceTest { +class S3RestClientTest { @InjectMocks - private S3RestService s3RestService; + private S3RestClient s3RestClient; @Mock private S3Client s3Client; @@ -50,7 +50,7 @@ void buildZipWithMultipleEntries() throws Exception { "executionId1/debug/file2.txt", "content2" ); - byte[] zipBytes = s3RestService.buildZip( + byte[] zipBytes = s3RestClient.buildZip( "executionId1", keys, key -> new ByteArrayInputStream(fakeData.get(key).getBytes()) @@ -87,7 +87,7 @@ void getFilesFromS3DirectoryWithPagination() { .thenReturn(firstPage) .thenReturn(secondPage); - List keys = s3RestService.getFilesKeysInDirectory("debug/"); + List keys = s3RestClient.getFilesKeysInDirectory("debug/"); assertEquals(2, keys.size()); assertTrue(keys.contains("executionId1/debug/file1.txt")); @@ -118,7 +118,7 @@ void downloadS3DirectoryContentAsZip() throws Exception { ) )); - byte[] zipBytes = s3RestService.downloadDirectoryAsZip("executionId1"); + byte[] zipBytes = s3RestClient.downloadDirectoryAsZip("executionId1"); try (ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes))) { ZipEntry entry = zis.getNextEntry(); diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClientTest.java similarity index 84% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClientTest.java index 88d60037..f1882795 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisRestServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/clients/SecurityAnalysisRestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.clients; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -27,15 +27,15 @@ /** * @author Kevin Le Saulnier */ -@RestClientTest(SecurityAnalysisRestService.class) -@ContextConfiguration(classes = { SecurityAnalysisRestService.class }) -class SecurityAnalysisRestServiceTest { +@RestClientTest(SecurityAnalysisRestClient.class) +@ContextConfiguration(classes = { SecurityAnalysisRestClient.class }) +class SecurityAnalysisRestClientTest { private static final UUID RESULT_UUID = UUID.randomUUID(); private static final String RESULT_BODY = "{\"status\":\"OK\"}"; @Autowired - private SecurityAnalysisRestService securityAnalysisRestService; + private SecurityAnalysisRestClient securityAnalysisRestClient; @Autowired private MockRestServiceServer server; @@ -56,7 +56,7 @@ void getResult() { MediaType.APPLICATION_JSON )); - String result = securityAnalysisRestService.getResult(RESULT_UUID); + String result = securityAnalysisRestClient.getResult(RESULT_UUID); assertThat(result).isEqualTo(RESULT_BODY); } @@ -69,7 +69,7 @@ void getResultFailed() { )) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> securityAnalysisRestService.getResult(RESULT_UUID)) + assertThatThrownBy(() -> securityAnalysisRestClient.getResult(RESULT_UUID)) .isInstanceOf(RestClientException.class); } @@ -79,7 +79,7 @@ void deleteResult() { .andExpect(MockRestRequestMatchers.requestTo("http://security-analysis-server/v1/results?resultsUuids=" + RESULT_UUID)) .andRespond(MockRestResponseCreators.withSuccess()); - assertThatNoException().isThrownBy(() -> securityAnalysisRestService.deleteResult(RESULT_UUID)); + assertThatNoException().isThrownBy(() -> securityAnalysisRestClient.deleteResult(RESULT_UUID)); } @Test @@ -88,7 +88,7 @@ void deleteResultFailed() { .andExpect(MockRestRequestMatchers.requestTo("http://security-analysis-server/v1/results?resultsUuids=" + RESULT_UUID)) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> securityAnalysisRestService.deleteResult(RESULT_UUID)) + assertThatThrownBy(() -> securityAnalysisRestClient.deleteResult(RESULT_UUID)) .isInstanceOf(RestClientException.class); } } diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java index b2bd4d0b..817281b0 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java @@ -7,18 +7,18 @@ package org.gridsuite.monitor.server.controllers; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.commons.PersistedProcessConfig; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.commons.ProcessStatus; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.server.dto.ProcessExecution; -import org.gridsuite.monitor.server.dto.ReportLog; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.dto.Severity; -import org.gridsuite.monitor.server.services.MonitorService; -import org.gridsuite.monitor.server.services.ProcessConfigService; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.server.dto.processexecution.ProcessExecution; +import org.gridsuite.monitor.server.dto.report.ReportLog; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.dto.report.Severity; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; +import org.gridsuite.monitor.server.services.processexecution.ProcessExecutionService; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; @@ -41,9 +41,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** @@ -59,7 +57,7 @@ class MonitorControllerTest { private ObjectMapper objectMapper; @MockitoBean - private MonitorService monitorService; + private ProcessExecutionService processExecutionService; @MockitoBean private ProcessConfigService processConfigService; @@ -85,7 +83,7 @@ void executeProcessShouldReturnExecutionId(Boolean isDebug) throws Exception { boolean expectedDebugValue = Boolean.TRUE.equals(isDebug); when(processConfigService.getProcessConfig(processConfigUuid)).thenReturn(Optional.of(persistedProcessConfig)); - when(monitorService.executeProcess(any(UUID.class), any(String.class), any(UUID.class), eq(expectedDebugValue))) + when(processExecutionService.executeProcess(any(UUID.class), any(String.class), any(UUID.class), eq(expectedDebugValue))) .thenReturn(Optional.of(executionId)); MockHttpServletRequestBuilder request = post("/v1/execute") @@ -102,7 +100,7 @@ void executeProcessShouldReturnExecutionId(Boolean isDebug) throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$").value(executionId.toString())); - verify(monitorService).executeProcess(eq(caseUuid), any(String.class), any(UUID.class), eq(expectedDebugValue)); + verify(processExecutionService).executeProcess(eq(caseUuid), any(String.class), any(UUID.class), eq(expectedDebugValue)); } @Test @@ -110,7 +108,7 @@ void executeProcessWithConfigNotFoundShouldReturnError() throws Exception { UUID caseUuid = UUID.randomUUID(); UUID processConfigUuid = UUID.randomUUID(); - when(monitorService.executeProcess(caseUuid, "user1", processConfigUuid, false)).thenReturn(Optional.empty()); + when(processExecutionService.executeProcess(caseUuid, "user1", processConfigUuid, false)).thenReturn(Optional.empty()); MockHttpServletRequestBuilder request = post("/v1/execute") .param("caseUuid", caseUuid.toString()) @@ -120,7 +118,7 @@ void executeProcessWithConfigNotFoundShouldReturnError() throws Exception { mockMvc.perform(request) .andExpect(status().isNotFound()); - verify(monitorService).executeProcess(caseUuid, "user1", processConfigUuid, false); + verify(processExecutionService).executeProcess(caseUuid, "user1", processConfigUuid, false); } @Test @@ -132,7 +130,7 @@ void getExecutionReportsShouldReturnListOfReports() throws Exception { ReportPage reportPage1 = new ReportPage(1, reportLogs1, 100, 10); List reportLogs2 = List.of(new ReportLog("message3", Severity.ERROR, 3, UUID.randomUUID())); ReportPage reportPage2 = new ReportPage(2, reportLogs2, 200, 20); - when(monitorService.getReports(executionId)) + when(processExecutionService.getReports(executionId)) .thenReturn(List.of(reportPage1, reportPage2)); mockMvc.perform(get("/v1/executions/{executionId}/reports", executionId)) @@ -157,7 +155,7 @@ void getExecutionReportsShouldReturnListOfReports() throws Exception { .andExpect(jsonPath("$[1].totalElements").value(200)) .andExpect(jsonPath("$[1].totalPages").value(20)); - verify(monitorService).getReports(executionId); + verify(processExecutionService).getReports(executionId); } @Test @@ -165,7 +163,7 @@ void getExecutionResultsShouldReturnListOfResults() throws Exception { UUID executionId = UUID.randomUUID(); String result1 = "{\"result\": \"data1\"}"; String result2 = "{\"result\": \"data2\"}"; - when(monitorService.getResults(executionId)) + when(processExecutionService.getResults(executionId)) .thenReturn(List.of(result1, result2)); mockMvc.perform(get("/v1/executions/{executionId}/results", executionId)) @@ -175,7 +173,7 @@ void getExecutionResultsShouldReturnListOfResults() throws Exception { .andExpect(jsonPath("$[0]").value(result1)) .andExpect(jsonPath("$[1]").value(result2)); - verify(monitorService).getResults(executionId); + verify(processExecutionService).getResults(executionId); } @Test @@ -186,7 +184,7 @@ void getLaunchedProcesses() throws Exception { List processExecutionList = List.of(processExecution1, processExecution2, processExecution3); - when(monitorService.getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS)).thenReturn(processExecutionList); + when(processExecutionService.getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS)).thenReturn(processExecutionList); mockMvc.perform(get("/v1/executions?processType=SECURITY_ANALYSIS").accept(MediaType.APPLICATION_JSON_VALUE).header("userId", "user1,user2,user3")) .andExpect(status().isOk()) @@ -194,7 +192,7 @@ void getLaunchedProcesses() throws Exception { .andExpect(jsonPath("$", hasSize(3))) .andExpect(content().json(objectMapper.writeValueAsString(processExecutionList))); - verify(monitorService).getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS); + verify(processExecutionService).getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS); } @Test @@ -205,7 +203,7 @@ void getStepsInfos() throws Exception { ProcessExecutionStep processExecutionStep3 = new ProcessExecutionStep(UUID.randomUUID(), "runSA", 2, StepStatus.SCHEDULED, null, null, UUID.randomUUID(), null, null); List processExecutionStepList = List.of(processExecutionStep1, processExecutionStep2, processExecutionStep3); - when(monitorService.getStepsInfos(executionId)).thenReturn(Optional.of(processExecutionStepList)); + when(processExecutionService.getStepsInfos(executionId)).thenReturn(Optional.of(processExecutionStepList)); mockMvc.perform(get("/v1/executions/{executionId}/step-infos", executionId)) .andExpect(status().isOk()) @@ -213,42 +211,42 @@ void getStepsInfos() throws Exception { .andExpect(jsonPath("$", hasSize(3))) .andExpect(content().json(objectMapper.writeValueAsString(processExecutionStepList))); - verify(monitorService).getStepsInfos(executionId); + verify(processExecutionService).getStepsInfos(executionId); } @Test void getStepsInfosShouldReturn404WhenExecutionNotFound() throws Exception { UUID executionId = UUID.randomUUID(); - when(monitorService.getStepsInfos(executionId)).thenReturn(Optional.empty()); + when(processExecutionService.getStepsInfos(executionId)).thenReturn(Optional.empty()); mockMvc.perform(get("/v1/executions/{executionId}/step-infos", executionId)) .andExpect(status().isNotFound()); - verify(monitorService).getStepsInfos(executionId); + verify(processExecutionService).getStepsInfos(executionId); } @Test void deleteExecutionShouldReturnTrue() throws Exception { UUID executionId = UUID.randomUUID(); - when(monitorService.deleteExecution(executionId)) + when(processExecutionService.deleteExecution(executionId)) .thenReturn(Boolean.TRUE); mockMvc.perform(delete("/v1/executions/{executionId}", executionId)) .andExpect(status().isOk()); - verify(monitorService).deleteExecution(executionId); + verify(processExecutionService).deleteExecution(executionId); } @Test void deleteExecutionShouldReturnFalse() throws Exception { UUID executionId = UUID.randomUUID(); - when(monitorService.deleteExecution(executionId)) + when(processExecutionService.deleteExecution(executionId)) .thenReturn(Boolean.FALSE); mockMvc.perform(delete("/v1/executions/{executionId}", executionId)) .andExpect(status().isNotFound()); - verify(monitorService).deleteExecution(executionId); + verify(processExecutionService).deleteExecution(executionId); } @Test @@ -256,7 +254,7 @@ void getDebugFilesReturnsOK() throws Exception { UUID executionId = UUID.randomUUID(); byte[] zipContent = "dummy-zip-content".getBytes(); - when(monitorService.getDebugInfos(executionId)) + when(processExecutionService.getDebugInfos(executionId)) .thenReturn(Optional.of(zipContent)); mockMvc.perform(get("/v1/executions/{executionId}/debug-infos", executionId)) @@ -275,7 +273,7 @@ void getDebugFilesReturnsOK() throws Exception { @Test void getDebugFilesReturnsNotFound() throws Exception { - when(monitorService.getDebugInfos(any())).thenReturn(Optional.empty()); + when(processExecutionService.getDebugInfos(any())).thenReturn(Optional.empty()); mockMvc.perform(get("/v1/executions/{executionId}/debug-infos", UUID.randomUUID())) .andExpect(status().isNotFound()); diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java index a84ca061..2d5e0f0a 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java @@ -7,13 +7,13 @@ package org.gridsuite.monitor.server.controllers; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.commons.PersistedProcessConfig; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.server.dto.ProcessConfigComparison; -import org.gridsuite.monitor.server.dto.ProcessConfigFieldComparison; -import org.gridsuite.monitor.server.services.ProcessConfigService; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigComparison; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigFieldComparison; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapperTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapperTest.java similarity index 86% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapperTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapperTest.java index 41ac7d42..c61a1416 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapperTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processconfig/SecurityAnalysisConfigMapperTest.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.mapper; +package org.gridsuite.monitor.server.mappers.processconfig; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.server.entities.SecurityAnalysisConfigEntity; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.server.entities.processconfig.SecurityAnalysisConfigEntity; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapperTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapperTest.java similarity index 86% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapperTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapperTest.java index 82145fbc..30df1dd1 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/mapper/ProcessExecutionStepMapperTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/mappers/processexecution/ProcessExecutionStepMapperTest.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.mapper; +package org.gridsuite.monitor.server.mappers.processexecution; -import org.gridsuite.monitor.commons.ResultType; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.server.entities.ProcessExecutionStepEntity; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionStepEntity; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ConsumerServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/ConsumerServiceTest.java similarity index 77% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/ConsumerServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/ConsumerServiceTest.java index ffb86b88..3015778b 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ConsumerServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/ConsumerServiceTest.java @@ -4,11 +4,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.messaging; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.gridsuite.monitor.commons.*; +import org.gridsuite.monitor.commons.types.messaging.MessageType; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.server.services.processexecution.ProcessExecutionService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,7 +44,7 @@ class ConsumerServiceTest { @Mock - private MonitorService monitorService; + private ProcessExecutionService processExecutionService; private ObjectMapper objectMapper; private ConsumerService consumerService; @@ -47,7 +53,7 @@ class ConsumerServiceTest { void setUp() { objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); - consumerService = new ConsumerService(monitorService, objectMapper); + consumerService = new ConsumerService(processExecutionService, objectMapper); } @Test @@ -71,14 +77,14 @@ void consumeProcessExecutionStatusUpdateMessage() throws JsonProcessingException consumer.accept(message); - verify(monitorService).updateExecutionStatus( + verify(processExecutionService).updateExecutionStatus( executionId, ProcessStatus.RUNNING, "env-1", startedAt, completedAt ); - verify(monitorService, never()).updateStepStatus(any(), any()); + verify(processExecutionService, never()).updateStepStatus(any(), any()); } @Test @@ -95,8 +101,8 @@ void consumeMonitorUpdateThrowsOnInvalidJson() { .isInstanceOf(UncheckedIOException.class) .hasMessageContaining("Failed to parse payload as ProcessExecutionStatusUpdate"); - verify(monitorService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); - verify(monitorService, never()).updateStepStatus(any(), any()); + verify(processExecutionService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); + verify(processExecutionService, never()).updateStepStatus(any(), any()); } @Test @@ -111,10 +117,10 @@ void consumeMonitorUpdateStepsStatusesThrowsOnInvalidJson() { assertThatThrownBy(() -> consumer.accept(message)) .isInstanceOf(UncheckedIOException.class) - .hasMessageContaining("Failed to parse payload as java.util.List"); + .hasMessageContaining("Failed to parse payload as " + new TypeReference>() { }.getType().getTypeName()); - verify(monitorService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); - verify(monitorService, never()).updateStepsStatuses(any(), any()); + verify(processExecutionService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); + verify(processExecutionService, never()).updateStepsStatuses(any(), any()); } @Test @@ -136,8 +142,8 @@ void consumeProcessExecutionStepUpdateMessage() throws JsonProcessingException { consumer.accept(message); - verify(monitorService).updateStepStatus(eq(executionId), any(ProcessExecutionStep.class)); - verify(monitorService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); + verify(processExecutionService).updateStepStatus(eq(executionId), any(ProcessExecutionStep.class)); + verify(processExecutionService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); } @Test @@ -166,8 +172,8 @@ void consumeProcessExecutionStepsUpdateMessage() throws JsonProcessingException consumer.accept(message); - verify(monitorService).updateStepsStatuses(eq(executionId), any(List.class)); - verify(monitorService, never()).updateStepStatus(any(), any()); - verify(monitorService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); + verify(processExecutionService).updateStepsStatuses(eq(executionId), any(List.class)); + verify(processExecutionService, never()).updateStepStatus(any(), any()); + verify(processExecutionService, never()).updateExecutionStatus(any(), any(), any(), any(), any()); } } diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/NotificationServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/NotificationServiceTest.java similarity index 91% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/NotificationServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/NotificationServiceTest.java index e2a8d36f..319d8b36 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/NotificationServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/NotificationServiceTest.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.messaging; -import org.gridsuite.monitor.commons.ProcessRunMessage; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepositoryTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepositoryTest.java index ba1eb9f1..0dd1581e 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepositoryTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/repositories/ProcessExecutionRepositoryTest.java @@ -6,11 +6,11 @@ */ package org.gridsuite.monitor.server.repositories; -import org.gridsuite.monitor.commons.ProcessStatus; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; -import org.gridsuite.monitor.server.entities.ProcessExecutionStepEntity; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionStepEntity; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ProcessConfigServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java similarity index 96% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/ProcessConfigServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java index 5a144571..1ce851b4 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ProcessConfigServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java @@ -4,15 +4,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; - -import org.gridsuite.monitor.commons.PersistedProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.server.dto.ProcessConfigComparison; -import org.gridsuite.monitor.server.dto.ProcessConfigFieldComparison; -import org.gridsuite.monitor.server.entities.SecurityAnalysisConfigEntity; -import org.gridsuite.monitor.server.mapper.SecurityAnalysisConfigMapper; +package org.gridsuite.monitor.server.services.processconfig; + +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigComparison; +import org.gridsuite.monitor.server.dto.processconfig.ProcessConfigFieldComparison; +import org.gridsuite.monitor.server.entities.processconfig.SecurityAnalysisConfigEntity; +import org.gridsuite.monitor.server.mappers.processconfig.SecurityAnalysisConfigMapper; import org.gridsuite.monitor.server.repositories.ProcessConfigRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java similarity index 84% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java index e2066902..9360b82a 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java @@ -4,19 +4,31 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.processexecution; import com.powsybl.commons.PowsyblException; -import org.gridsuite.monitor.commons.*; -import org.gridsuite.monitor.server.dto.ProcessExecution; -import org.gridsuite.monitor.server.dto.ReportLog; -import org.gridsuite.monitor.server.dto.ReportPage; -import org.gridsuite.monitor.server.dto.Severity; -import org.gridsuite.monitor.server.entities.ProcessExecutionEntity; -import org.gridsuite.monitor.server.entities.ProcessExecutionStepEntity; -import org.gridsuite.monitor.server.mapper.ProcessExecutionMapper; -import org.gridsuite.monitor.server.mapper.ProcessExecutionStepMapper; +import org.gridsuite.monitor.server.dto.processconfig.PersistedProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.server.clients.ReportRestClient; +import org.gridsuite.monitor.server.dto.processexecution.ProcessExecution; +import org.gridsuite.monitor.server.dto.report.ReportLog; +import org.gridsuite.monitor.server.dto.report.ReportPage; +import org.gridsuite.monitor.server.dto.report.Severity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionEntity; +import org.gridsuite.monitor.server.entities.processexecution.ProcessExecutionStepEntity; +import org.gridsuite.monitor.server.mappers.processexecution.ProcessExecutionMapper; +import org.gridsuite.monitor.server.mappers.processexecution.ProcessExecutionStepMapper; +import org.gridsuite.monitor.server.messaging.NotificationService; import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository; +import org.gridsuite.monitor.server.clients.S3RestClient; +import org.gridsuite.monitor.server.services.processconfig.ProcessConfigService; +import org.gridsuite.monitor.server.services.result.ResultService; import org.gridsuite.monitor.server.utils.S3PathResolver; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,7 +55,7 @@ * @author Antoine Bouhours */ @ExtendWith({MockitoExtension.class}) -class MonitorServiceTest { +class ProcessExecutionServiceTest { @Mock private ProcessExecutionRepository executionRepository; @@ -55,13 +67,13 @@ class MonitorServiceTest { private ProcessConfigService processConfigService; @Mock - private ReportRestService reportRestService; + private ReportRestClient reportRestClient; @Mock private ResultService resultService; @Mock - private S3RestService s3RestService; + private S3RestClient s3RestClient; @Mock private S3PathResolver s3PathResolver; @@ -73,7 +85,7 @@ class MonitorServiceTest { private ProcessExecutionMapper processExecutionMapper = Mappers.getMapper(ProcessExecutionMapper.class); @InjectMocks - private MonitorService monitorService; + private ProcessExecutionService processExecutionService; private SecurityAnalysisConfig securityAnalysisConfig; private UUID caseUuid; @@ -98,7 +110,7 @@ void executeProcessCreateExecutionAndSendNotification() { when(s3PathResolver.toDebugLocation(eq(ProcessType.SECURITY_ANALYSIS.name()), any(UUID.class))).thenReturn(debugFileLocation); when(processConfigService.getProcessConfig(any(UUID.class))).thenReturn(Optional.of(new PersistedProcessConfig(UUID.randomUUID(), securityAnalysisConfig))); - Optional result = monitorService.executeProcess(caseUuid, userId, UUID.randomUUID(), true); + Optional result = processExecutionService.executeProcess(caseUuid, userId, UUID.randomUUID(), true); assertThat(result).isNotEmpty(); verify(processConfigService).getProcessConfig(any(UUID.class)); @@ -132,7 +144,7 @@ void updateExecutionStatusShouldUpdateStatusOnly() { .build(); when(executionRepository.findById(executionId)).thenReturn(Optional.of(execution)); - monitorService.updateExecutionStatus(executionId, ProcessStatus.RUNNING, null, null, null); + processExecutionService.updateExecutionStatus(executionId, ProcessStatus.RUNNING, null, null, null); verify(executionRepository).findById(executionId); assertThat(execution.getStatus()).isEqualTo(ProcessStatus.RUNNING); @@ -157,7 +169,7 @@ void updateExecutionStatusShouldUpdateAllFields() { Instant startedAt = Instant.now().minusSeconds(60); Instant completedAt = Instant.now(); - monitorService.updateExecutionStatus(executionId, ProcessStatus.COMPLETED, envName, startedAt, completedAt); + processExecutionService.updateExecutionStatus(executionId, ProcessStatus.COMPLETED, envName, startedAt, completedAt); verify(executionRepository).findById(executionId); assertThat(execution.getStatus()).isEqualTo(ProcessStatus.COMPLETED); @@ -171,7 +183,7 @@ void updateExecutionStatusShouldUpdateAllFields() { void updateExecutionStatusShouldHandleExecutionNotFound() { when(executionRepository.findById(executionId)).thenReturn(Optional.empty()); - monitorService.updateExecutionStatus(executionId, ProcessStatus.COMPLETED, "env", Instant.now(), Instant.now()); + processExecutionService.updateExecutionStatus(executionId, ProcessStatus.COMPLETED, "env", Instant.now(), Instant.now()); verify(executionRepository).findById(executionId); verify(executionRepository, never()).save(any()); @@ -202,7 +214,7 @@ void updateStepStatusShouldAddNewStep() { .startedAt(startedAt) .build(); - monitorService.updateStepStatus(executionId, processExecutionStep); + processExecutionService.updateStepStatus(executionId, processExecutionStep); verify(executionRepository).findById(executionId); assertThat(execution.getSteps()).hasSize(1); @@ -252,7 +264,7 @@ void updateStepStatusShouldUpdateExistingStep() { .completedAt(completedAt) .build(); - monitorService.updateStepStatus(executionId, updateDto); + processExecutionService.updateStepStatus(executionId, updateDto); verify(executionRepository).findById(executionId); assertThat(execution.getSteps()).hasSize(1); @@ -325,7 +337,7 @@ void updateStepsStatusesShouldUpdateExistingSteps() { .startedAt(startedAt2) .completedAt(completedAt2) .build(); - monitorService.updateStepsStatuses(executionId, List.of(updateDto1, updateDto2)); + processExecutionService.updateStepsStatuses(executionId, List.of(updateDto1, updateDto2)); verify(executionRepository).findById(executionId); assertThat(execution.getSteps()).hasSize(2); @@ -376,15 +388,15 @@ void getReportsShouldReturnReports() { new ReportLog("message2", Severity.WARN, 2, UUID.randomUUID())), 100, 10); ReportPage reportPage2 = new ReportPage(2, List.of(new ReportLog("message3", Severity.ERROR, 3, UUID.randomUUID())), 200, 20); - when(reportRestService.getReport(reportId1)).thenReturn(reportPage1); - when(reportRestService.getReport(reportId2)).thenReturn(reportPage2); + when(reportRestClient.getReport(reportId1)).thenReturn(reportPage1); + when(reportRestClient.getReport(reportId2)).thenReturn(reportPage2); - List result = monitorService.getReports(executionId); + List result = processExecutionService.getReports(executionId); assertThat(result).hasSize(2).containsExactly(reportPage1, reportPage2); verify(executionRepository).findById(executionId); - verify(reportRestService).getReport(reportId1); - verify(reportRestService).getReport(reportId2); + verify(reportRestClient).getReport(reportId1); + verify(reportRestClient).getReport(reportId2); } @Test @@ -416,7 +428,7 @@ void getResultsShouldReturnResults() { when(resultService.getResult(new ResultInfos(resultId2, ResultType.SECURITY_ANALYSIS))) .thenReturn(result2); - List results = monitorService.getResults(executionId); + List results = processExecutionService.getResults(executionId); assertThat(results).hasSize(2).containsExactly(result1, result2); verify(executionRepository).findById(executionId); @@ -463,7 +475,7 @@ void getLaunchedProcesses() { when(executionRepository.findByTypeAndStartedAtIsNotNullOrderByStartedAtDesc(ProcessType.SECURITY_ANALYSIS.name())).thenReturn(List.of(execution2, execution1)); - List result = monitorService.getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS); + List result = processExecutionService.getLaunchedProcesses(ProcessType.SECURITY_ANALYSIS); ProcessExecution processExecution1 = new ProcessExecution(execution1Uuid, ProcessType.SECURITY_ANALYSIS.name(), case1Uuid, config1Uuid, ProcessStatus.COMPLETED, "env1", scheduledAt1, startedAt1, completedAt1, "user1"); ProcessExecution processExecution2 = new ProcessExecution(execution2Uuid, ProcessType.SECURITY_ANALYSIS.name(), case2Uuid, config2Uuid, ProcessStatus.RUNNING, "env2", scheduledAt2, startedAt2, null, "user2"); @@ -487,7 +499,7 @@ void getStepsInfos() { when(executionRepository.findById(executionUuid)).thenReturn(Optional.of(execution)); - Optional> result = monitorService.getStepsInfos(executionUuid); + Optional> result = processExecutionService.getStepsInfos(executionUuid); ProcessExecutionStep processExecutionStep1 = new ProcessExecutionStep(stepId1, "loadNetwork", 0, StepStatus.RUNNING, null, null, null, startedAt1, null); ProcessExecutionStep processExecutionStep2 = new ProcessExecutionStep(stepId2, "applyModifs", 1, StepStatus.SCHEDULED, null, null, null, null, null); @@ -502,7 +514,7 @@ void getStepsInfosShouldReturnEmptyWhenExecutionNotFound() { UUID executionUuid = UUID.randomUUID(); when(executionRepository.findById(executionUuid)).thenReturn(Optional.empty()); - Optional> result = monitorService.getStepsInfos(executionUuid); + Optional> result = processExecutionService.getStepsInfos(executionUuid); assertThat(result).isEmpty(); verify(executionRepository).findById(executionUuid); @@ -518,7 +530,7 @@ void getStepsInfosShouldReturnEmptyListWhenNoSteps() { .build(); when(executionRepository.findById(executionUuid)).thenReturn(Optional.of(execution)); - Optional> result = monitorService.getStepsInfos(executionUuid); + Optional> result = processExecutionService.getStepsInfos(executionUuid); assertThat(result).isPresent(); assertThat(result.get()).isEmpty(); @@ -551,17 +563,17 @@ void deleteExecutionShouldDeleteResultsAndReports() { when(executionRepository.findById(executionId)).thenReturn(Optional.of(execution)); doNothing().when(executionRepository).delete(execution); - doNothing().when(reportRestService).deleteReport(reportId1); - doNothing().when(reportRestService).deleteReport(reportId2); + doNothing().when(reportRestClient).deleteReport(reportId1); + doNothing().when(reportRestClient).deleteReport(reportId2); doNothing().when(resultService).deleteResult(any(ResultInfos.class)); - boolean done = monitorService.deleteExecution(executionId); + boolean done = processExecutionService.deleteExecution(executionId); assertThat(done).isTrue(); verify(executionRepository).findById(executionId); verify(executionRepository).delete(execution); - verify(reportRestService).deleteReport(reportId1); - verify(reportRestService).deleteReport(reportId2); + verify(reportRestClient).deleteReport(reportId1); + verify(reportRestClient).deleteReport(reportId2); verify(resultService, times(1)).deleteResult(any(ResultInfos.class)); } @@ -569,12 +581,12 @@ void deleteExecutionShouldDeleteResultsAndReports() { void deleteExecutionShouldReturnFalseWhenExecutionNotFound() { when(executionRepository.findById(executionId)).thenReturn(Optional.empty()); - boolean done = monitorService.deleteExecution(executionId); + boolean done = processExecutionService.deleteExecution(executionId); assertThat(done).isFalse(); verify(executionRepository).findById(executionId); verifyNoMoreInteractions(executionRepository); - verifyNoInteractions(reportRestService); + verifyNoInteractions(reportRestClient); verifyNoInteractions(resultService); } @@ -585,27 +597,27 @@ void getExistingDebugInfo() throws Exception { byte[] expectedBytes = "zip-content".getBytes(); when(executionRepository.findById(executionId)).thenReturn(Optional.of(execution)); - when(s3RestService.downloadDirectoryAsZip("debug/file/location")).thenReturn(expectedBytes); + when(s3RestClient.downloadDirectoryAsZip("debug/file/location")).thenReturn(expectedBytes); - Optional result = monitorService.getDebugInfos(executionId); + Optional result = processExecutionService.getDebugInfos(executionId); assertThat(result).isPresent(); assertThat(expectedBytes).isEqualTo(result.get()); verify(executionRepository).findById(executionId); - verify(s3RestService).downloadDirectoryAsZip("debug/file/location"); + verify(s3RestClient).downloadDirectoryAsZip("debug/file/location"); } @Test void getNotExistingExecutionDebugInfo() { when(executionRepository.findById(executionId)).thenReturn(Optional.empty()); - Optional result = monitorService.getDebugInfos(executionId); + Optional result = processExecutionService.getDebugInfos(executionId); assertThat(result).isEmpty(); verify(executionRepository).findById(executionId); - verifyNoInteractions(s3RestService); + verifyNoInteractions(s3RestClient); } @Test @@ -615,17 +627,17 @@ void getExistingDebugInfoError() throws Exception { when(executionRepository.findById(executionId)).thenReturn(Optional.of(execution)); - when(s3RestService.downloadDirectoryAsZip("debug/file/location")).thenThrow(new IOException("S3 error")); + when(s3RestClient.downloadDirectoryAsZip("debug/file/location")).thenThrow(new IOException("S3 error")); PowsyblException exception = assertThrows( PowsyblException.class, - () -> monitorService.getDebugInfos(executionId) + () -> processExecutionService.getDebugInfos(executionId) ); assertThat(exception.getMessage()).contains("An error occurred while downloading debug files"); verify(executionRepository).findById(executionId); - verify(s3RestService).downloadDirectoryAsZip("debug/file/location"); + verify(s3RestClient).downloadDirectoryAsZip("debug/file/location"); } @Test @@ -634,11 +646,11 @@ void getExecutionWithoutDebugInfo() { when(executionRepository.findById(executionId)).thenReturn(Optional.of(execution)); - Optional result = monitorService.getDebugInfos(executionId); + Optional result = processExecutionService.getDebugInfos(executionId); assertThat(result).isEmpty(); verify(executionRepository).findById(executionId); - verifyNoInteractions(s3RestService); + verifyNoInteractions(s3RestClient); } } diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ResultServiceTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/ResultServiceTest.java similarity index 94% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/ResultServiceTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/ResultServiceTest.java index 4c617c5d..e4ad05f5 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/ResultServiceTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/ResultServiceTest.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.result; -import org.gridsuite.monitor.commons.ResultInfos; -import org.gridsuite.monitor.commons.ResultType; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProviderTest.java b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProviderTest.java similarity index 60% rename from monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProviderTest.java rename to monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProviderTest.java index 48cbb552..8103118c 100644 --- a/monitor-server/src/test/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProviderTest.java +++ b/monitor-server/src/test/java/org/gridsuite/monitor/server/services/result/providers/SecurityAnalysisResultProviderTest.java @@ -4,9 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.server.services; +package org.gridsuite.monitor.server.services.result.providers; -import org.gridsuite.monitor.commons.ResultType; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.server.clients.SecurityAnalysisRestClient; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -19,11 +20,11 @@ * @author Kevin Le Saulnier */ class SecurityAnalysisResultProviderTest { - private final SecurityAnalysisRestService securityAnalysisRestService = - Mockito.mock(SecurityAnalysisRestService.class); + private final SecurityAnalysisRestClient securityAnalysisRestClient = + Mockito.mock(SecurityAnalysisRestClient.class); private final SecurityAnalysisResultProvider provider = - new SecurityAnalysisResultProvider(securityAnalysisRestService); + new SecurityAnalysisResultProvider(securityAnalysisRestClient); @Test void getTypeShouldReturnSecurityAnalysis() { @@ -36,24 +37,24 @@ void getResultShouldDelegateToSecurityAnalysisService() { UUID id = UUID.randomUUID(); String expected = "result"; - when(securityAnalysisRestService.getResult(id)).thenReturn(expected); + when(securityAnalysisRestClient.getResult(id)).thenReturn(expected); String result = provider.getResult(id); assertThat(result).isEqualTo(expected); - verify(securityAnalysisRestService).getResult(id); - verifyNoMoreInteractions(securityAnalysisRestService); + verify(securityAnalysisRestClient).getResult(id); + verifyNoMoreInteractions(securityAnalysisRestClient); } @Test void deleteResultShouldDelegateToSecurityAnalysisService() { UUID id = UUID.randomUUID(); - doNothing().when(securityAnalysisRestService).deleteResult(id); + doNothing().when(securityAnalysisRestClient).deleteResult(id); provider.deleteResult(id); - verify(securityAnalysisRestService).deleteResult(id); - verifyNoMoreInteractions(securityAnalysisRestService); + verify(securityAnalysisRestClient).deleteResult(id); + verifyNoMoreInteractions(securityAnalysisRestClient); } } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClient.java similarity index 84% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClient.java index e8659f26..b386b10b 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClient.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.actions.dto.contingency.AbstractContingencyList; @@ -22,14 +22,14 @@ * @author Franck Lecuyer */ @Service -public class ActionsRestService { +public class ActionsRestClient { private static final String ACTIONS_SERVER_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient actionsServerRest; - public ActionsRestService(@Value("${gridsuite.services.actions-server.base-uri:http://actions-server/}") String actionsServerBaseUri, - RestClient.Builder restClientBuilder) { + public ActionsRestClient(@Value("${gridsuite.services.actions-server.base-uri:http://actions-server/}") String actionsServerBaseUri, + RestClient.Builder restClientBuilder) { this.actionsServerRest = restClientBuilder .baseUrl(actionsServerBaseUri + DELIMITER + ACTIONS_SERVER_API_VERSION) .build(); diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/FilterRestClient.java similarity index 81% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/FilterRestClient.java index 31d93f17..8d81cd2b 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/FilterRestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import org.gridsuite.actions.FilterProvider; import org.gridsuite.filter.AbstractFilter; @@ -20,14 +20,14 @@ * @author Franck Lecuyer */ @Service -public class FilterRestService implements FilterProvider { +public class FilterRestClient implements FilterProvider { private static final String FILTER_SERVER_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient restClient; - public FilterRestService(@Value("${gridsuite.services.filter-server.base-uri:http://filter-server/}") String filterServerBaseUri, - RestClient.Builder restClientBuilder) { + public FilterRestClient(@Value("${gridsuite.services.filter-server.base-uri:http://filter-server/}") String filterServerBaseUri, + RestClient.Builder restClientBuilder) { this.restClient = restClientBuilder .baseUrl(filterServerBaseUri + DELIMITER + FILTER_SERVER_API_VERSION) .build(); diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClient.java similarity index 92% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClient.java index 6d3303d0..fa918cad 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.powsybl.commons.PowsyblException; import org.gridsuite.monitor.worker.server.dto.parameters.loadflow.LoadFlowParametersInfos; @@ -18,12 +18,12 @@ * @author Franck Lecuyer */ @Service -public class LoadFlowRestService { +public class LoadFlowRestClient { static final String LOADFLOW_API_VERSION = "v1"; private final RestClient restClient; - public LoadFlowRestService( + public LoadFlowRestClient( RestClient.Builder restClientBuilder, @Value("${gridsuite.services.load-flow-server.base-uri:http://load-flow-server/}") String loadFlowServerBaseUri) { this.restClient = restClientBuilder diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClient.java similarity index 83% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClient.java index 1b1611ab..d789872d 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClient.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.modification.dto.ModificationInfos; @@ -21,14 +21,14 @@ * @author Franck Lecuyer */ @Service -public class NetworkModificationRestService { +public class NetworkModificationRestClient { private static final String NETWORK_MODIFICATION_SERVER_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient networkModificationServerRest; - public NetworkModificationRestService(@Value("${gridsuite.services.network-modification-server.base-uri:http://network-modification-server/}") String networkModificationServerBaseUri, - RestClient.Builder restClientBuilder) { + public NetworkModificationRestClient(@Value("${gridsuite.services.network-modification-server.base-uri:http://network-modification-server/}") String networkModificationServerBaseUri, + RestClient.Builder restClientBuilder) { this.networkModificationServerRest = restClientBuilder .baseUrl(networkModificationServerBaseUri + DELIMITER + NETWORK_MODIFICATION_SERVER_API_VERSION) .build(); diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ReportRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ReportRestClient.java similarity index 77% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ReportRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ReportRestClient.java index ce28efa6..7115d11a 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ReportRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/ReportRestClient.java @@ -4,9 +4,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; @@ -18,14 +18,14 @@ * @author Antoine Bouhours */ @Service -public class ReportRestService { +public class ReportRestClient { static final String REPORT_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient restClient; - public ReportRestService(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri, - RestClient.Builder restClientBuilder) { + public ReportRestClient(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri, + RestClient.Builder restClientBuilder) { this.restClient = restClientBuilder .baseUrl(reportServerBaseUri + DELIMITER + REPORT_API_VERSION + DELIMITER + "reports") .build(); diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3RestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/S3RestClient.java similarity index 90% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3RestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/S3RestClient.java index cf0278f3..d7f43faf 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3RestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/S3RestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import software.amazon.awssdk.core.exception.SdkException; import software.amazon.awssdk.core.sync.RequestBody; @@ -18,14 +18,14 @@ /** * @author Kevin Le Saulnier */ -public class S3RestService { +public class S3RestClient { public static final String METADATA_FILE_NAME = "file-name"; private final S3Client s3Client; private final String bucketName; - public S3RestService(S3Client s3Client, String bucketName) { + public S3RestClient(S3Client s3Client, String bucketName) { this.s3Client = s3Client; this.bucketName = bucketName; } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClient.java similarity index 93% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClient.java index 37835258..ced9488a 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClient.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.powsybl.security.SecurityAnalysisResult; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.SecurityAnalysisParametersValues; @@ -20,13 +20,13 @@ * @author Kevin Le Saulnier */ @Service -public class SecurityAnalysisRestService { +public class SecurityAnalysisRestClient { static final String SA_API_VERSION = "v1"; private static final String DELIMITER = "/"; private final RestClient restClient; - public SecurityAnalysisRestService( + public SecurityAnalysisRestClient( RestClient.Builder restClientBuilder, @Value("${gridsuite.services.security-analysis-server.base-uri:http://security-analysis-server/}") String securityAnalysisServerBaseUri) { this.restClient = restClientBuilder diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/config/S3Configuration.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/config/S3Configuration.java index b3f7051f..a761e846 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/config/S3Configuration.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/config/S3Configuration.java @@ -6,7 +6,7 @@ */ package org.gridsuite.monitor.worker.server.config; -import org.gridsuite.monitor.worker.server.services.S3RestService; +import org.gridsuite.monitor.worker.server.clients.S3RestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -28,8 +28,8 @@ public S3Configuration(@Value("${spring.cloud.aws.bucket:ws-bucket}") String buc @SuppressWarnings("checkstyle:MethodName") @Bean - public S3RestService s3RestService(S3Client s3Client) { + public S3RestClient s3RestService(S3Client s3Client) { LOGGER.info("Configuring S3RestService with bucket: {}", bucketName); - return new S3RestService(s3Client, bucketName); + return new S3RestClient(s3Client, bucketName); } } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcess.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcess.java deleted file mode 100644 index b87e532e..00000000 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcess.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.worker.server.core; - -import lombok.Getter; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.worker.server.services.StepExecutionService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collections; -import java.util.List; - -/** - * @author Antoine Bouhours - */ -@Getter -public abstract class AbstractProcess implements Process { - - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractProcess.class); - protected final ProcessType processType; - protected final StepExecutionService stepExecutionService; - - protected AbstractProcess( - ProcessType processType, - StepExecutionService stepExecutionService) { - this.processType = processType; - this.stepExecutionService = stepExecutionService; - } - - protected abstract List> defineSteps(); - - @Override - public List> getSteps() { - return Collections.unmodifiableList(defineSteps()); - } - - @Override - public void execute(ProcessExecutionContext context) { - List> steps = getSteps(); - boolean skipRemaining = false; - - for (int i = 0; i < steps.size(); i++) { - ProcessStep step = steps.get(i); - ProcessStepExecutionContext stepContext = context.createStepContext(step, i); - - if (skipRemaining) { - stepExecutionService.skipStep(stepContext, step); - continue; - } - - try { - stepExecutionService.executeStep(stepContext, step); - } catch (Exception e) { - handleStepFailure(context, step, e); - skipRemaining = true; - } - } - } - - protected void handleStepFailure(ProcessExecutionContext context, ProcessStep step, Exception e) { - //TODO better error handling - LOGGER.error("Execution id: {} - Step failed: {} - {}", context.getExecutionId(), step.getType(), e.getMessage()); - } -} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/Process.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/Process.java deleted file mode 100644 index 1dabfcca..00000000 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/Process.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.worker.server.core; - -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; - -import java.util.List; - -/** - * @author Antoine Bouhours - */ -public interface Process { - - ProcessType getProcessType(); - - void execute(ProcessExecutionContext context); - - List> getSteps(); -} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStep.java deleted file mode 100644 index 2dbe8158..00000000 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStep.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.worker.server.core; - -import org.gridsuite.monitor.commons.ProcessConfig; - -import java.util.UUID; - -/** - * @author Antoine Bouhours - */ -public interface ProcessStep { - - ProcessStepType getType(); - - UUID getId(); - - void execute(ProcessStepExecutionContext context); -} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContext.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContext.java similarity index 86% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContext.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContext.java index ff21d3d1..564fb57b 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContext.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContext.java @@ -4,12 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.context; import com.powsybl.iidm.network.Network; import lombok.Getter; import lombok.Setter; -import org.gridsuite.monitor.commons.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; import java.util.UUID; diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContext.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContext.java similarity index 86% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContext.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContext.java index 698832d3..42e3e03f 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContext.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContext.java @@ -4,15 +4,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.context; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; import lombok.Getter; import lombok.Setter; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ResultInfos; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; import java.time.Instant; import java.util.UUID; diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/messaging/Notificator.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/messaging/Notificator.java new file mode 100644 index 00000000..dec70ca6 --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/messaging/Notificator.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.messaging; + +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; + +import java.util.List; +import java.util.UUID; + +/** + * Used by the orchestrator to publish process execution updates (execution status and step statuses) + * to the monitor server (via messaging) + * + * @author Thang PHAM + */ +public interface Notificator { + + /** + * Publish an update about the overall process execution status. + * + * @param executionId the process execution identifier used to correlate all updates of the same run + * @param update the execution status update payload (status, timestamps, environment, etc.) + */ + void updateExecutionStatus(UUID executionId, ProcessExecutionStatusUpdate update); + + /** + * Publish a batch update containing the current statuses of all steps for an execution. + * + * @param executionId the process execution identifier used to correlate all updates of the same run + * @param steps the ordered list of step status snapshots to publish + */ + void updateStepsStatuses(UUID executionId, List steps); + + /** + * Publish an update for a single step status change (e.g. {@code RUNNING}, {@code COMPLETED}, + * {@code FAILED}, {@code SKIPPED}). + * + * @param executionId the process execution identifier used to correlate all updates of the same run + * @param step the step status snapshot to publish + */ + void updateStepStatus(UUID executionId, ProcessExecutionStep step); +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/ProcessExecutor.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/ProcessExecutor.java new file mode 100644 index 00000000..912c7571 --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/ProcessExecutor.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.orchestrator; + +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; + +/** + * Root orchestrator interface responsible for executing a {@code Process} run request. + * + * @author Thang PHAM + */ +public interface ProcessExecutor { + + /** + * Execute a process run described by the given message. + * + * @param runMessage run request + * @param concrete {@link ProcessConfig} type associated with the target {@code Process} + * @throws IllegalArgumentException if no process is registered for {@code runMessage.processType()} + * @throws RuntimeException if the process or one of its steps throws during execution (implementation should + * update execution status accordingly before propagating) + */ + void executeProcess(ProcessRunMessage runMessage); +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/StepExecutor.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/StepExecutor.java new file mode 100644 index 00000000..1a98f930 --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/orchestrator/StepExecutor.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.orchestrator; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; + +/** + * Child orchestrator interface responsible for executing a single {@link ProcessStep} within a process run. + * + * @author Thang PHAM + */ +public interface StepExecutor { + + /** + * Mark a step as skipped and publish the corresponding update. + * + * @param context step execution context + * @param step step definition being skipped + * @param concrete {@link ProcessConfig} type associated with the parent process + */ + void skipStep(ProcessStepExecutionContext context, ProcessStep step); + + /** + * Execute a step and publish step status updates around the execution. + * + * @param context step execution context + * @param step step definition to execute + * @param concrete {@link ProcessConfig} type associated with the parent process + * @throws RuntimeException any exception thrown by the step implementation is propagated after updating status + */ + void executeStep(ProcessStepExecutionContext context, ProcessStep step); +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcess.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcess.java new file mode 100644 index 00000000..19550e8d --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcess.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.process; + +import lombok.Getter; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; + +import java.util.Collections; +import java.util.List; + +/** + * @author Antoine Bouhours + */ +@Getter +public abstract class AbstractProcess implements Process { + + protected final ProcessType processType; + + protected AbstractProcess(ProcessType processType) { + this.processType = processType; + } + + protected abstract List> defineSteps(); + + @Override + public List> getSteps() { + return Collections.unmodifiableList(defineSteps()); + } +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcessStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcessStep.java similarity index 68% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcessStep.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcessStep.java index 2671026b..c55721a7 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/AbstractProcessStep.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/AbstractProcessStep.java @@ -4,10 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.process; import lombok.Getter; -import org.gridsuite.monitor.commons.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; import java.util.UUID; @@ -18,8 +18,14 @@ public abstract class AbstractProcessStep implements ProcessStep { private final ProcessStepType type; + private final UUID id; + /** + * Creates a step with the given type and a newly generated identifier. + * + * @param type step type (name is typically used in external status updates) + */ protected AbstractProcessStep(ProcessStepType type) { this.type = type; this.id = UUID.randomUUID(); diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/Process.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/Process.java new file mode 100644 index 00000000..00918334 --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/Process.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.process; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; + +import java.util.List; + +/** + * Definition of a runnable process. + *

+ * A {@code Process} is identified by a {@link ProcessType} and provides an ordered list of {@link ProcessStep}s + * to be orchestrated by {@code ProcessExecutor}. + * + * @param the concrete {@link ProcessConfig} type required by this process + * + * @author Antoine Bouhours + */ +public interface Process { + + /** + * The unique process type used to route execution requests to this implementation. + * + * @return the process type + */ + ProcessType getProcessType(); + + /** + * Defines the ordered list of steps that compose this process. + * + * @return ordered process steps + */ + List> getSteps(); +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStep.java new file mode 100644 index 00000000..8ac29951 --- /dev/null +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStep.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.process; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; + +import java.util.UUID; + +/** + * Definition of a single step within a {@link Process}. + * + * @param the concrete {@link ProcessConfig} type required by this step + * + * @author Antoine Bouhours + */ +public interface ProcessStep { + + /** + * The functional type of this step. + * + * @return the step type + */ + ProcessStepType getType(); + + /** + * Unique identifier of the step instance within a process definition. + * + * @return the step id + */ + UUID getId(); + + /** + * Executes the step business logic. + * + * @param context step execution context for the current run + * @throws RuntimeException any failure should be propagated; the orchestrator/step executor is responsible for + * translating it into monitoring status updates and deciding what to do next + */ + void execute(ProcessStepExecutionContext context); +} diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepType.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStepType.java similarity index 65% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepType.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStepType.java index e0c5a209..9965955e 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/ProcessStepType.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/core/process/ProcessStepType.java @@ -4,11 +4,19 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.process; /** + * Functional classification of a {@link ProcessStep}. + * * @author Antoine Bouhours */ public interface ProcessStepType { + + /** + * Identifier of the step type. + * + * @return the step type name + */ String getName(); } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/ReportInfos.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/report/ReportInfos.java similarity index 89% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/ReportInfos.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/report/ReportInfos.java index d12c59f7..f24296b4 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/ReportInfos.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/report/ReportInfos.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.dto; +package org.gridsuite.monitor.worker.server.dto.report; import com.powsybl.commons.report.ReportNode; diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ConsumerService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/ConsumerService.java similarity index 71% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ConsumerService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/ConsumerService.java index c13f4538..13fa59fb 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ConsumerService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/ConsumerService.java @@ -4,11 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.messaging; import lombok.RequiredArgsConstructor; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.orchestrator.ProcessExecutor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.Message; @@ -22,7 +23,7 @@ @RequiredArgsConstructor public class ConsumerService { - private final ProcessExecutionService executionService; + private final ProcessExecutor executionService; @Bean public Consumer>> consumeRun() { diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NotificationService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/NotificationService.java similarity index 83% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NotificationService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/NotificationService.java index 61b6c6e4..e85ace04 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NotificationService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/messaging/NotificationService.java @@ -4,11 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.messaging; -import org.gridsuite.monitor.commons.MessageType; -import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate; -import org.gridsuite.monitor.commons.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.messaging.MessageType; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.worker.server.core.messaging.Notificator; import org.springframework.cloud.stream.function.StreamBridge; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; @@ -21,7 +22,7 @@ * @author Antoine Bouhours */ @Service -public class NotificationService { +public class NotificationService implements Notificator { private final StreamBridge updatePublisher; private static final String PROCESS_UPDATE_BINDING = "publishMonitorUpdate-out-0"; @@ -46,6 +47,7 @@ private void sendMonitorUpdate( updatePublisher.send(PROCESS_UPDATE_BINDING, message); } + @Override public void updateExecutionStatus(UUID executionId, ProcessExecutionStatusUpdate processExecutionStatusUpdate) { sendMonitorUpdate( executionId, @@ -54,6 +56,7 @@ public void updateExecutionStatus(UUID executionId, ProcessExecutionStatusUpdate ); } + @Override public void updateStepStatus(UUID executionId, ProcessExecutionStep processExecutionStep) { sendMonitorUpdate( executionId, @@ -62,6 +65,7 @@ public void updateStepStatus(UUID executionId, ProcessExecutionStep processExecu ); } + @Override public void updateStepsStatuses(UUID executionId, List processExecutionSteps) { sendMonitorUpdate( executionId, diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionService.java similarity index 59% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionService.java index fa9f5c9b..f5adbae5 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionService.java @@ -4,18 +4,22 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; - -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.ProcessRunMessage; -import org.gridsuite.monitor.commons.ProcessStatus; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.worker.server.core.Process; -import org.gridsuite.monitor.worker.server.core.ProcessExecutionContext; -import org.gridsuite.monitor.worker.server.core.ProcessStep; +package org.gridsuite.monitor.worker.server.orchestrator; + +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.*; +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.context.ProcessExecutionContext; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.core.messaging.Notificator; +import org.gridsuite.monitor.worker.server.core.orchestrator.ProcessExecutor; +import org.gridsuite.monitor.worker.server.core.orchestrator.StepExecutor; +import org.gridsuite.monitor.worker.server.core.process.Process; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -30,21 +34,27 @@ * @author Antoine Bouhours */ @Service -public class ProcessExecutionService { +public class ProcessExecutionService implements ProcessExecutor { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProcessExecutionService.class); private final Map> processes; - private final NotificationService notificationService; + private final StepExecutor stepExecutor; + private final Notificator notificationService; private final String executionEnvName; public ProcessExecutionService(List> processList, - NotificationService notificationService, + StepExecutor stepExecutor, + Notificator notificationService, @Value("${worker.execution-env-name:default-env}") String executionEnvName) { this.processes = processList.stream() .collect(Collectors.toMap(Process::getProcessType, w -> w)); + this.stepExecutor = stepExecutor; this.notificationService = notificationService; this.executionEnvName = executionEnvName; } + @Override public void executeProcess(ProcessRunMessage runMessage) { @SuppressWarnings("unchecked") // safe: ProcessType uniquely maps to a Process with the matching ProcessConfig subtype Process process = (Process) processes.get(runMessage.processType()); @@ -84,10 +94,34 @@ private void initializeSteps(Process process, Proce private void executeSteps(Process process, ProcessExecutionContext context) { updateExecutionStatus(context.getExecutionId(), context.getExecutionEnvName(), ProcessStatus.RUNNING); - process.execute(context); + doExecuteSteps(process, context); updateExecutionStatus(context.getExecutionId(), context.getExecutionEnvName(), ProcessStatus.COMPLETED); } + private void doExecuteSteps(Process process, ProcessExecutionContext context) { + List> steps = process.getSteps(); + boolean skipRemaining = false; + + for (int i = 0; i < steps.size(); i++) { + ProcessStep step = steps.get(i); + ProcessStepExecutionContext stepContext = context.createStepContext(step, i); + + if (skipRemaining) { + stepExecutor.skipStep(stepContext, step); + continue; + } + + try { + stepExecutor.executeStep(stepContext, step); + } catch (Exception e) { + // TODO better error handling + LOGGER.error("Execution id: {} - Step failed: {} - {}", context.getExecutionId(), step.getType(), e.getMessage()); + updateExecutionStatus(context.getExecutionId(), context.getExecutionEnvName(), ProcessStatus.FAILED); + skipRemaining = true; + } + } + } + private void updateExecutionStatus(UUID executionId, String envName, ProcessStatus status) { ProcessExecutionStatusUpdate processExecutionStatusUpdate = new ProcessExecutionStatusUpdate( status, diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionService.java similarity index 69% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionService.java index 92c125e0..d8ed483e 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionService.java @@ -4,14 +4,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.orchestrator; import lombok.RequiredArgsConstructor; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.worker.server.core.ProcessStep; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.worker.server.clients.ReportRestClient; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.core.messaging.Notificator; +import org.gridsuite.monitor.worker.server.core.orchestrator.StepExecutor; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; import org.springframework.stereotype.Service; import java.time.Instant; @@ -21,12 +24,12 @@ */ @Service @RequiredArgsConstructor -public class StepExecutionService { +public class StepExecutionService implements StepExecutor { + private final Notificator notificationService; + private final ReportRestClient reportRestClient; - private final NotificationService notificationService; - private final ReportRestService reportRestService; - - public void skipStep(ProcessStepExecutionContext context, ProcessStep step) { + @Override + public void skipStep(ProcessStepExecutionContext context, ProcessStep step) { ProcessExecutionStep executionStep = ProcessExecutionStep.builder() .id(context.getStepExecutionId()) .stepType(step.getType().getName()) @@ -38,7 +41,8 @@ public void skipStep(ProcessStepExecutionContext context, ProcessStep step notificationService.updateStepStatus(context.getProcessExecutionId(), executionStep); } - public void executeStep(ProcessStepExecutionContext context, ProcessStep step) { + @Override + public void executeStep(ProcessStepExecutionContext context, ProcessStep step) { ProcessExecutionStep executionStep = ProcessExecutionStep.builder() .id(context.getStepExecutionId()) .stepType(step.getType().getName()) @@ -56,7 +60,7 @@ public void executeStep(ProcessStepExecutionContext context, ProcessStep s updateStepStatus(context, StepStatus.FAILED, step); throw e; } finally { - reportRestService.sendReport(context.getReportInfos()); + reportRestClient.sendReport(context.getReportInfos()); } } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStep.java similarity index 78% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStep.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStep.java index 45be4f5b..7c9d3d21 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStep.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStep.java @@ -4,17 +4,20 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.commons.steps; +package org.gridsuite.monitor.worker.server.process.commons.steps; import com.powsybl.commons.PowsyblException; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.modification.dto.ModificationInfos; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.worker.server.core.AbstractProcessStep; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; -import org.gridsuite.monitor.worker.server.services.*; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.clients.NetworkModificationRestClient; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.core.process.AbstractProcessStep; +import org.gridsuite.monitor.worker.server.services.FilterService; +import org.gridsuite.monitor.worker.server.services.NetworkModificationService; +import org.gridsuite.monitor.worker.server.services.S3Service; import org.gridsuite.monitor.worker.server.utils.S3PathResolver; import org.springframework.stereotype.Component; @@ -32,7 +35,7 @@ public class ApplyModificationsStep extends AbstractProcessStep { private final NetworkModificationService networkModificationService; - private final NetworkModificationRestService networkModificationRestService; + private final NetworkModificationRestClient networkModificationRestClient; private final S3Service s3Service; private final FilterService filterService; @@ -40,12 +43,12 @@ public class ApplyModificationsStep extends AbstractPro private static final String DEBUG_FILENAME_SUFFIX = ".xiidm"; public ApplyModificationsStep(NetworkModificationService networkModificationService, - NetworkModificationRestService networkModificationRestService, + NetworkModificationRestClient networkModificationRestClient, S3Service s3Service, FilterService filterService) { super(CommonStepType.APPLY_MODIFICATIONS); this.networkModificationService = networkModificationService; - this.networkModificationRestService = networkModificationRestService; + this.networkModificationRestClient = networkModificationRestClient; this.s3Service = s3Service; this.filterService = filterService; } @@ -80,7 +83,7 @@ private void exportUpdatedNetworkToS3(ProcessStepExecutionContext context) th } private void applyModifications(List modificationIds, Network network, ReportNode reportNode) { - List modificationInfos = networkModificationRestService.getModifications(modificationIds); + List modificationInfos = networkModificationRestClient.getModifications(modificationIds); networkModificationService.applyModifications(network, modificationInfos, reportNode, filterService); } } diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/CommonStepType.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/CommonStepType.java similarity index 81% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/CommonStepType.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/CommonStepType.java index aa14ad40..7448781f 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/CommonStepType.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/CommonStepType.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.commons.steps; +package org.gridsuite.monitor.worker.server.process.commons.steps; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.gridsuite.monitor.worker.server.core.ProcessStepType; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; /** * @author Antoine Bouhours diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStep.java similarity index 84% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStep.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStep.java index 0f8e06d4..de3d5dcc 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStep.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStep.java @@ -4,13 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.commons.steps; +package org.gridsuite.monitor.worker.server.process.commons.steps; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.worker.server.core.AbstractProcessStep; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.process.AbstractProcessStep; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; import org.gridsuite.monitor.worker.server.services.NetworkConversionService; import org.springframework.stereotype.Component; diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcess.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcess.java similarity index 63% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcess.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcess.java index 844af215..7f43b9bb 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcess.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcess.java @@ -4,16 +4,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.securityanalysis; +package org.gridsuite.monitor.worker.server.process.securityanalysis; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.worker.server.core.AbstractProcess; -import org.gridsuite.monitor.worker.server.core.ProcessStep; -import org.gridsuite.monitor.worker.server.processes.commons.steps.ApplyModificationsStep; -import org.gridsuite.monitor.worker.server.processes.commons.steps.LoadNetworkStep; -import org.gridsuite.monitor.worker.server.processes.securityanalysis.steps.SecurityAnalysisRunComputationStep; -import org.gridsuite.monitor.worker.server.services.StepExecutionService; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.worker.server.core.process.AbstractProcess; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.gridsuite.monitor.worker.server.process.commons.steps.ApplyModificationsStep; +import org.gridsuite.monitor.worker.server.process.commons.steps.LoadNetworkStep; +import org.gridsuite.monitor.worker.server.process.securityanalysis.steps.SecurityAnalysisRunComputationStep; import org.springframework.stereotype.Component; import java.util.List; @@ -29,11 +28,10 @@ public class SecurityAnalysisProcess extends AbstractProcess stepExecutionService, LoadNetworkStep loadNetworkStep, ApplyModificationsStep applyModificationsStep, SecurityAnalysisRunComputationStep runComputationStep) { - super(ProcessType.SECURITY_ANALYSIS, stepExecutionService); + super(ProcessType.SECURITY_ANALYSIS); this.loadNetworkStep = loadNetworkStep; this.applyModificationsStep = applyModificationsStep; this.runComputationStep = runComputationStep; diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisStepType.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisStepType.java similarity index 80% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisStepType.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisStepType.java index 2a493fb7..9eaeabe3 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisStepType.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisStepType.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.securityanalysis; +package org.gridsuite.monitor.worker.server.process.securityanalysis; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.gridsuite.monitor.worker.server.core.ProcessStepType; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; /** * @author Antoine Bouhours diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStep.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStep.java similarity index 76% rename from monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStep.java rename to monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStep.java index 244f3a02..1a800f5e 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStep.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStep.java @@ -4,23 +4,23 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.securityanalysis.steps; +package org.gridsuite.monitor.worker.server.process.securityanalysis.steps; import com.powsybl.commons.report.ReportNode; import com.powsybl.commons.report.TypedValue; import com.powsybl.security.SecurityAnalysis; import com.powsybl.security.SecurityAnalysisReport; import com.powsybl.security.SecurityAnalysisRunParameters; -import org.gridsuite.monitor.commons.ResultInfos; -import org.gridsuite.monitor.commons.ResultType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.worker.server.core.AbstractProcessStep; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.worker.server.core.process.AbstractProcessStep; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.SecurityAnalysisInputData; -import org.gridsuite.monitor.worker.server.processes.securityanalysis.SecurityAnalysisStepType; +import org.gridsuite.monitor.worker.server.process.securityanalysis.SecurityAnalysisStepType; +import org.gridsuite.monitor.worker.server.clients.SecurityAnalysisRestClient; import org.gridsuite.monitor.worker.server.report.MonitorWorkerServerReportResourceBundle; import org.gridsuite.monitor.worker.server.services.SecurityAnalysisParametersService; -import org.gridsuite.monitor.worker.server.services.SecurityAnalysisRestService; import org.springframework.stereotype.Component; import java.util.Objects; @@ -32,13 +32,13 @@ @Component public class SecurityAnalysisRunComputationStep extends AbstractProcessStep { - private final SecurityAnalysisRestService securityAnalysisRestService; + private final SecurityAnalysisRestClient securityAnalysisRestClient; private final SecurityAnalysisParametersService securityAnalysisParametersService; - public SecurityAnalysisRunComputationStep(SecurityAnalysisRestService securityAnalysisRestService, + public SecurityAnalysisRunComputationStep(SecurityAnalysisRestClient securityAnalysisRestClient, SecurityAnalysisParametersService securityAnalysisParametersService) { super(SecurityAnalysisStepType.RUN_SA_COMPUTATION); - this.securityAnalysisRestService = securityAnalysisRestService; + this.securityAnalysisRestClient = securityAnalysisRestClient; this.securityAnalysisParametersService = securityAnalysisParametersService; } @@ -58,7 +58,7 @@ public void execute(ProcessStepExecutionContext context) SecurityAnalysisReport saReport = SecurityAnalysis.run(context.getNetwork(), inputData.contingencies(), runParameters); ResultInfos resultInfos = new ResultInfos(UUID.randomUUID(), ResultType.SECURITY_ANALYSIS); - securityAnalysisRestService.saveResult(resultInfos.resultUUID(), saReport.getResult()); + securityAnalysisRestClient.saveResult(resultInfos.resultUUID(), saReport.getResult()); context.setResultInfos(resultInfos); } catch (Exception e) { reportNode.newReportNode() diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterService.java index 1e941eca..bdb68146 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/FilterService.java @@ -12,6 +12,7 @@ import org.gridsuite.modification.IFilterService; import org.gridsuite.modification.dto.FilterEquipments; import org.gridsuite.modification.dto.IdentifiableAttributes; +import org.gridsuite.monitor.worker.server.clients.FilterRestClient; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -27,14 +28,15 @@ */ @Service public class FilterService implements IFilterService { - private final FilterRestService filterRestService; + private final FilterRestClient filterRestClient; - public FilterService(FilterRestService filterRestService) { - this.filterRestService = filterRestService; + public FilterService(FilterRestClient filterRestClient) { + this.filterRestClient = filterRestClient; } + @Override public List getFilters(List filtersUuids) { - return filterRestService.getFilters(filtersUuids); + return filterRestClient.getFilters(filtersUuids); } public Stream exportFilters(List filtersUuids, Network network) { diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3Service.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3Service.java index 9d22f414..1f9a4fd6 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3Service.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/S3Service.java @@ -7,6 +7,7 @@ package org.gridsuite.monitor.worker.server.services; import org.apache.commons.io.FileUtils; +import org.gridsuite.monitor.worker.server.clients.S3RestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -29,10 +30,10 @@ @Service public class S3Service { private static final Logger LOGGER = LoggerFactory.getLogger(S3Service.class); - private final S3RestService s3RestService; + private final S3RestClient s3RestClient; - public S3Service(S3RestService s3RestService) { - this.s3RestService = s3RestService; + public S3Service(S3RestClient s3RestClient) { + this.s3RestClient = s3RestClient; } public void exportCompressedToS3(String s3Key, String fileNamePrefix, String fileNameSuffix, ThrowingConsumer writer) throws IOException { @@ -53,7 +54,7 @@ public void exportCompressedToS3(String s3Key, String fileNamePrefix, String fil in.transferTo(out); } - s3RestService.uploadFile(compressedDebugFile, s3Key, String.join("", fileNamePrefix, fileNameSuffix, ".gz")); + s3RestClient.uploadFile(compressedDebugFile, s3Key, String.join("", fileNamePrefix, fileNameSuffix, ".gz")); } finally { try { if (Files.exists(tempDir)) { diff --git a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java index 2ba315ea..390cb878 100644 --- a/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java +++ b/monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java @@ -12,6 +12,10 @@ import org.gridsuite.actions.ContingencyListEvaluator; import org.gridsuite.actions.dto.contingency.AbstractContingencyList; import org.gridsuite.actions.dto.evaluation.ContingencyInfos; +import org.gridsuite.monitor.worker.server.clients.ActionsRestClient; +import org.gridsuite.monitor.worker.server.clients.FilterRestClient; +import org.gridsuite.monitor.worker.server.clients.LoadFlowRestClient; +import org.gridsuite.monitor.worker.server.clients.SecurityAnalysisRestClient; import org.gridsuite.monitor.worker.server.dto.parameters.loadflow.LoadFlowParametersInfos; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.ContingencyListsInfos; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.IdNameInfos; @@ -29,24 +33,24 @@ */ @Service public class SecurityAnalysisParametersService { - private final SecurityAnalysisRestService securityAnalysisRestService; - private final LoadFlowRestService loadFlowRestService; - private final ActionsRestService actionsRestService; - private final FilterRestService filterRestService; + private final SecurityAnalysisRestClient securityAnalysisRestClient; + private final LoadFlowRestClient loadFlowRestClient; + private final ActionsRestClient actionsRestClient; + private final FilterRestClient filterRestClient; - public SecurityAnalysisParametersService(SecurityAnalysisRestService securityAnalysisRestService, - LoadFlowRestService loadFlowRestService, - ActionsRestService actionsRestService, - FilterRestService filterRestService) { - this.securityAnalysisRestService = securityAnalysisRestService; - this.loadFlowRestService = loadFlowRestService; - this.actionsRestService = actionsRestService; - this.filterRestService = filterRestService; + public SecurityAnalysisParametersService(SecurityAnalysisRestClient securityAnalysisRestClient, + LoadFlowRestClient loadFlowRestClient, + ActionsRestClient actionsRestClient, + FilterRestClient filterRestClient) { + this.securityAnalysisRestClient = securityAnalysisRestClient; + this.loadFlowRestClient = loadFlowRestClient; + this.actionsRestClient = actionsRestClient; + this.filterRestClient = filterRestClient; } public SecurityAnalysisInputData buildSecurityAnalysisInputData(UUID securityAnalysisParametersUuid, UUID loadflowParametersUuid, Network network) { - SecurityAnalysisParametersValues securityAnalysisParametersValues = securityAnalysisRestService.getParameters(securityAnalysisParametersUuid); - LoadFlowParametersInfos loadFlowParametersInfos = loadFlowRestService.getParameters(loadflowParametersUuid); + SecurityAnalysisParametersValues securityAnalysisParametersValues = securityAnalysisRestClient.getParameters(securityAnalysisParametersUuid); + LoadFlowParametersInfos loadFlowParametersInfos = loadFlowRestClient.getParameters(loadflowParametersUuid); SecurityAnalysisParameters securityAnalysisParameters = buildSecurityAnalysisParameters(loadFlowParametersInfos, securityAnalysisParametersValues); @@ -54,10 +58,10 @@ public SecurityAnalysisInputData buildSecurityAnalysisInputData(UUID securityAna List contingenciesListUuids = contingencyListInfos != null ? contingencyListInfos.stream().flatMap(contingencyListsInfos -> contingencyListsInfos.getContingencyLists().stream().map(IdNameInfos::getId)).toList() : List.of(); - List persistentContingencyLists = actionsRestService.getPersistentContingencyLists(contingenciesListUuids); + List persistentContingencyLists = actionsRestClient.getPersistentContingencyLists(contingenciesListUuids); List contingencyList = new ArrayList<>(); - ContingencyListEvaluator contingencyListEvaluator = new ContingencyListEvaluator(filterRestService); + ContingencyListEvaluator contingencyListEvaluator = new ContingencyListEvaluator(filterRestClient); persistentContingencyLists.forEach(persistentContingencyList -> { List contingencies = contingencyListEvaluator.evaluateContingencyList(persistentContingencyList, network) diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClientTest.java similarity index 89% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClientTest.java index 88f85c94..ac99ed28 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ActionsRestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -38,11 +38,11 @@ /** * @author Franck Lecuyer */ -@RestClientTest(ActionsRestService.class) -class ActionsRestServiceTest { +@RestClientTest(ActionsRestClient.class) +class ActionsRestClientTest { @Autowired - private ActionsRestService actionsRestService; + private ActionsRestClient actionsRestClient; @Autowired private MockRestServiceServer server; @@ -78,7 +78,7 @@ void getPersistentContingencyLists() throws JsonProcessingException { .contentType(MediaType.APPLICATION_JSON) .body(jsonResponse)); - List result = actionsRestService.getPersistentContingencyLists(requestUuids); + List result = actionsRestClient.getPersistentContingencyLists(requestUuids); assertThat(result).isNotNull(); assertThat(result).usingRecursiveComparison().isEqualTo(objectMapper.readValue(jsonResponse, new TypeReference>() { })); @@ -94,13 +94,13 @@ void getPersistentContingencyListsNotFound() throws JsonProcessingException { .andExpect(MockRestRequestMatchers.content().json(objectMapper.writeValueAsString(requestUuids))) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> actionsRestService.getPersistentContingencyLists(requestUuids)) + assertThatThrownBy(() -> actionsRestClient.getPersistentContingencyLists(requestUuids)) .isInstanceOf(HttpServerErrorException.InternalServerError.class); } @Test void getEmptyContingencies() { - List result = actionsRestService.getPersistentContingencyLists(List.of()); + List result = actionsRestClient.getPersistentContingencyLists(List.of()); assertThat(result).isEmpty(); } @@ -116,7 +116,7 @@ void getPersistentContingencyListsWithEmptyResponse() throws JsonProcessingExcep .contentType(MediaType.APPLICATION_JSON) .body(objectMapper.writeValueAsString(List.of()))); - List result = actionsRestService.getPersistentContingencyLists(requestUuids); + List result = actionsRestClient.getPersistentContingencyLists(requestUuids); assertThat(result).isEmpty(); } diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/FilterRestClientTest.java similarity index 92% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/FilterRestClientTest.java index b2ee2984..30270e6a 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/FilterRestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -43,10 +43,10 @@ /** * @author Franck Lecuyer */ -@RestClientTest(FilterRestService.class) -class FilterRestServiceTest { +@RestClientTest(FilterRestClient.class) +class FilterRestClientTest { @Autowired - private FilterRestService filterRestService; + private FilterRestClient filterRestClient; @Autowired private MockRestServiceServer server; @@ -83,7 +83,7 @@ void getFilters() throws JsonProcessingException { .contentType(MediaType.APPLICATION_JSON) .body(objectMapper.writeValueAsString(listFilters))); - List resultListFilters = filterRestService.getFilters(filterUuids); + List resultListFilters = filterRestClient.getFilters(filterUuids); assertThat(resultListFilters).usingRecursiveComparison().isEqualTo(listFilters); } @@ -94,7 +94,7 @@ void getFiltersNotFound() { .andRespond(MockRestResponseCreators.withServerError()); List filterUuids = List.of(FILTER_ERROR_UUID); - assertThatThrownBy(() -> filterRestService.getFilters(filterUuids)) + assertThatThrownBy(() -> filterRestClient.getFilters(filterUuids)) .isInstanceOf(HttpServerErrorException.InternalServerError.class); } } diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClientTest.java similarity index 88% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClientTest.java index b28f7c39..22da98ee 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/LoadFlowRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/LoadFlowRestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -28,10 +28,10 @@ /** * @author Franck Lecuyer */ -@RestClientTest(LoadFlowRestService.class) -class LoadFlowRestServiceTest { +@RestClientTest(LoadFlowRestClient.class) +class LoadFlowRestClientTest { @Autowired - private LoadFlowRestService loadFlowRestService; + private LoadFlowRestClient loadFlowRestClient; @Autowired private MockRestServiceServer server; @@ -60,7 +60,7 @@ void getParameters() throws JsonProcessingException { .contentType(MediaType.APPLICATION_JSON) .body(objectMapper.writeValueAsString(expectedParameters))); - LoadFlowParametersInfos result = loadFlowRestService.getParameters(PARAMETERS_UUID); + LoadFlowParametersInfos result = loadFlowRestClient.getParameters(PARAMETERS_UUID); assertThat(result).usingRecursiveComparison().isEqualTo(expectedParameters); } @@ -72,7 +72,7 @@ void getParametersNotFound() { "http://load-flow-server/v1/parameters/" + PARAMETERS_ERROR_UUID)) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> loadFlowRestService.getParameters(PARAMETERS_ERROR_UUID)) + assertThatThrownBy(() -> loadFlowRestClient.getParameters(PARAMETERS_ERROR_UUID)) .isInstanceOf(HttpServerErrorException.InternalServerError.class); } } diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClientTest.java similarity index 88% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClientTest.java index c5de88d4..7c344eb9 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,10 +32,10 @@ /** * @author Franck Lecuyer */ -@RestClientTest(NetworkModificationRestService.class) -class NetworkModificationRestServiceTest { +@RestClientTest(NetworkModificationRestClient.class) +class NetworkModificationRestClientTest { @Autowired - private NetworkModificationRestService networkModificationRestService; + private NetworkModificationRestClient networkModificationRestClient; @Autowired private MockRestServiceServer server; @@ -70,7 +70,7 @@ void getModifications() { throw new RuntimeException(e); } - List resultListModifications = networkModificationRestService.getModifications(List.of(MODIFICATION_1_UUID, MODIFICATION_2_UUID)); + List resultListModifications = networkModificationRestClient.getModifications(List.of(MODIFICATION_1_UUID, MODIFICATION_2_UUID)); assertThat(resultListModifications).usingRecursiveComparison().isEqualTo(modificationInfos); } @@ -81,12 +81,12 @@ void getModificationsNotFound() { .andRespond(MockRestResponseCreators.withServerError()); List modificationsUuids = List.of(MODIFICATION_ERROR_UUID); - assertThatThrownBy(() -> networkModificationRestService.getModifications(modificationsUuids)).isInstanceOf(HttpServerErrorException.InternalServerError.class); + assertThatThrownBy(() -> networkModificationRestClient.getModifications(modificationsUuids)).isInstanceOf(HttpServerErrorException.InternalServerError.class); } @Test void getEmptyModifications() { - List resultListModifications = networkModificationRestService.getModifications(List.of()); + List resultListModifications = networkModificationRestClient.getModifications(List.of()); assertThat(resultListModifications).isEmpty(); } } diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ReportRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ReportRestClientTest.java similarity index 92% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ReportRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ReportRestClientTest.java index c7c367b1..5d2a2729 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ReportRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/ReportRestClientTest.java @@ -4,13 +4,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.powsybl.commons.report.ReportNode; import org.gridsuite.monitor.worker.server.config.MonitorWorkerConfig; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -31,15 +31,15 @@ /** * @author Antoine Bouhours */ -@RestClientTest(ReportRestService.class) -@ContextConfiguration(classes = {MonitorWorkerConfig.class, ReportRestService.class}) -class ReportRestServiceTest { +@RestClientTest(ReportRestClient.class) +@ContextConfiguration(classes = {MonitorWorkerConfig.class, ReportRestClient.class}) +class ReportRestClientTest { private static final UUID REPORT_UUID = UUID.randomUUID(); private static final UUID REPORT_ERROR_UUID = UUID.randomUUID(); @Autowired - private ReportRestService reportRestService; + private ReportRestClient reportRestService; @Autowired private MockRestServiceServer server; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3RestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/S3RestClientTest.java similarity index 89% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3RestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/S3RestClientTest.java index 867108ea..abe5c56a 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3RestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/S3RestClientTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.clients; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,18 +32,18 @@ * @author Kevin Le Saulnier */ @ExtendWith(MockitoExtension.class) -class S3RestServiceTest { +class S3RestClientTest { @Mock S3Client s3Client; - S3RestService s3RestService; + S3RestClient s3RestClient; @TempDir Path testDir; @BeforeEach void setup() { - s3RestService = new S3RestService(s3Client, "my-bucket"); + s3RestClient = new S3RestClient(s3Client, "my-bucket"); } @Test @@ -51,7 +51,7 @@ void testUploadFileToS3() throws Exception { Path tempFile = Files.createTempFile(testDir, "test", ".txt"); Files.writeString(tempFile, "dataToUpload"); - s3RestService.uploadFile(tempFile, "testS3Key", "fileToUploadName"); + s3RestClient.uploadFile(tempFile, "testS3Key", "fileToUploadName"); ArgumentCaptor requestCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); @@ -79,7 +79,7 @@ void testUpdateFileToS3Error() throws Exception { .putObject(any(PutObjectRequest.class), any(RequestBody.class)); assertThatThrownBy(() -> - s3RestService.uploadFile(fileToUpload, "key", "file.txt") + s3RestClient.uploadFile(fileToUpload, "key", "file.txt") ) .isInstanceOf(IOException.class) .hasMessageContaining("Error occurred while uploading file to S3") diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClientTest.java similarity index 82% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClientTest.java index 9ca82cb3..92afa628 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/SecurityAnalysisRestClientTest.java @@ -1,4 +1,10 @@ -package org.gridsuite.monitor.worker.server.services; +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.clients; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -20,22 +26,21 @@ import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatNoException; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; /** * @author Kevin Le Saulnier */ -@RestClientTest(SecurityAnalysisRestService.class) -@ContextConfiguration(classes = {MonitorWorkerConfig.class, SecurityAnalysisRestService.class}) -class SecurityAnalysisRestServiceTest { +@RestClientTest(SecurityAnalysisRestClient.class) +@ContextConfiguration(classes = {MonitorWorkerConfig.class, SecurityAnalysisRestClient.class}) +class SecurityAnalysisRestClientTest { + private static final UUID RESULT_UUID = UUID.randomUUID(); private static final UUID PARAMETERS_UUID = UUID.randomUUID(); private static final UUID PARAMETERS_ERROR_UUID = UUID.randomUUID(); @Autowired - private SecurityAnalysisRestService securityAnalysisRestService; + private SecurityAnalysisRestClient securityAnalysisRestClient; @Autowired private MockRestServiceServer server; @@ -57,7 +62,7 @@ void saveResult() throws JsonProcessingException { .andExpect(MockRestRequestMatchers.content().json(objectMapper.writeValueAsString(result))) .andRespond(MockRestResponseCreators.withSuccess()); - assertThatNoException().isThrownBy(() -> securityAnalysisRestService.saveResult(RESULT_UUID, result)); + assertThatNoException().isThrownBy(() -> securityAnalysisRestClient.saveResult(RESULT_UUID, result)); } @Test @@ -67,7 +72,7 @@ void saveResultFailed() { .andExpect(MockRestRequestMatchers.requestTo("http://security-analysis-server/v1/results/" + RESULT_UUID)) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> securityAnalysisRestService.saveResult(RESULT_UUID, result)).isInstanceOf(RestClientException.class); + assertThatThrownBy(() -> securityAnalysisRestClient.saveResult(RESULT_UUID, result)).isInstanceOf(RestClientException.class); } @Test @@ -88,7 +93,7 @@ void getParameters() throws JsonProcessingException { .contentType(MediaType.APPLICATION_JSON) .body(objectMapper.writeValueAsString(expectedParameters))); - SecurityAnalysisParametersValues result = securityAnalysisRestService.getParameters(PARAMETERS_UUID); + SecurityAnalysisParametersValues result = securityAnalysisRestClient.getParameters(PARAMETERS_UUID); assertThat(result).usingRecursiveComparison().isEqualTo(expectedParameters); } @@ -101,7 +106,7 @@ void getParametersNotFound() { .andExpect(MockRestRequestMatchers.header("userId", "user1")) .andRespond(MockRestResponseCreators.withServerError()); - assertThatThrownBy(() -> securityAnalysisRestService.getParameters(PARAMETERS_ERROR_UUID)) + assertThatThrownBy(() -> securityAnalysisRestClient.getParameters(PARAMETERS_ERROR_UUID)) .isInstanceOf(HttpServerErrorException.InternalServerError.class); } } diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessTest.java deleted file mode 100644 index cfb5b9e6..00000000 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.worker.server.core; - -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.worker.server.services.StepExecutionService; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InOrder; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -/** - * @author Antoine Bouhours - */ -@ExtendWith(MockitoExtension.class) -class ProcessTest { - @Mock - private StepExecutionService stepExecutionService; - - @Mock - private ProcessExecutionContext processContext; - - private TestProcess process; - - @BeforeEach - void setUp() { - process = new TestProcess( - stepExecutionService); - } - - @Test - void executeShouldExecuteAllStepsSuccessfullyWhenNoErrors() { - ProcessStepExecutionContext stepContext1 = mock(ProcessStepExecutionContext.class); - ProcessStepExecutionContext stepContext2 = mock(ProcessStepExecutionContext.class); - ProcessStepExecutionContext stepContext3 = mock(ProcessStepExecutionContext.class); - - when(processContext.createStepContext(any(), anyInt())) - .thenReturn(stepContext1) - .thenReturn(stepContext2) - .thenReturn(stepContext3); - - process.execute(processContext); - - verify(stepExecutionService, times(3)).executeStep(any(), any()); - verify(stepExecutionService, never()).skipStep(any(), any()); - // Verify stepOrder is correctly set - InOrder inOrder = inOrder(processContext); - inOrder.verify(processContext).createStepContext(any(), eq(0)); - inOrder.verify(processContext).createStepContext(any(), eq(1)); - inOrder.verify(processContext).createStepContext(any(), eq(2)); - } - - @Test - void executeShouldSkipAllRemainingStepsWhenFirstStepFails() { - ProcessStepExecutionContext stepContext1 = mock(ProcessStepExecutionContext.class); - ProcessStepExecutionContext stepContext2 = mock(ProcessStepExecutionContext.class); - ProcessStepExecutionContext stepContext3 = mock(ProcessStepExecutionContext.class); - when(processContext.createStepContext(any(), anyInt())) - .thenReturn(stepContext1) - .thenReturn(stepContext2) - .thenReturn(stepContext3); - // Make the first step fail - doThrow(new RuntimeException("Network loading failed")) - .when(stepExecutionService).executeStep(eq(stepContext1), any()); - - process.execute(processContext); - - verify(stepExecutionService).executeStep(eq(stepContext1), any()); - verify(stepExecutionService).skipStep(eq(stepContext2), any()); - verify(stepExecutionService).skipStep(eq(stepContext3), any()); - verify(stepExecutionService, times(1)).executeStep(any(), any()); - verify(stepExecutionService, times(2)).skipStep(any(), any()); - // Verify stepOrder is correctly set - InOrder inOrder = inOrder(processContext); - inOrder.verify(processContext).createStepContext(any(), eq(0)); - inOrder.verify(processContext).createStepContext(any(), eq(1)); - inOrder.verify(processContext).createStepContext(any(), eq(2)); - } - - /** - * Mock implementation of AbstractProcess for testing purposes - */ - private static class TestProcess extends AbstractProcess { - - public TestProcess(StepExecutionService stepExecutionService) { - super(ProcessType.SECURITY_ANALYSIS, stepExecutionService); - } - - @Override - public List> defineSteps() { - // Return 3 dummy steps for testing - ProcessStep step1 = mock(ProcessStep.class); - ProcessStep step2 = mock(ProcessStep.class); - ProcessStep step3 = mock(ProcessStep.class); - - return List.of(step1, step2, step3); - } - } -} diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContextTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContextTest.java similarity index 91% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContextTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContextTest.java index fc4368a2..47ae5828 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessExecutionContextTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessExecutionContextTest.java @@ -4,10 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.context; import com.powsybl.iidm.network.Network; -import org.gridsuite.monitor.commons.ProcessConfig; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContextTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContextTest.java similarity index 92% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContextTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContextTest.java index 2dce111d..11bc9053 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/ProcessStepExecutionContextTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/context/ProcessStepExecutionContextTest.java @@ -4,11 +4,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.core; +package org.gridsuite.monitor.worker.server.core.context; import com.powsybl.iidm.network.Network; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ResultInfos; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.result.ResultInfos; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/process/ProcessTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/process/ProcessTest.java new file mode 100644 index 00000000..193da767 --- /dev/null +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/core/process/ProcessTest.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.core.process; + +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * @author Antoine Bouhours + */ +@ExtendWith(MockitoExtension.class) +class ProcessTest { + + @Test + void getStepsShouldReturnUnmodifiableListOfDefinedSteps() { + ProcessStep step1 = mock(ProcessStep.class); + ProcessStep step2 = mock(ProcessStep.class); + TestProcess process = new TestProcess(List.of(step1, step2)); + + List> steps = process.getSteps(); + + assertThat(steps).isUnmodifiable().containsExactly(step1, step2); + } + + private static class TestProcess extends AbstractProcess { + private final List> steps; + + TestProcess(List> steps) { + super(ProcessType.SECURITY_ANALYSIS); + this.steps = steps; + } + + @Override + public List> defineSteps() { + return steps; + } + } +} diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ConsumerServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/ConsumerServiceTest.java similarity index 84% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ConsumerServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/ConsumerServiceTest.java index 4c5b44ce..7e32a4ab 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ConsumerServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/ConsumerServiceTest.java @@ -4,10 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.messaging; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.worker.server.orchestrator.ProcessExecutionService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NotificationServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/NotificationServiceTest.java similarity index 92% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NotificationServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/NotificationServiceTest.java index 87bf06c7..f6368747 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NotificationServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/messaging/NotificationServiceTest.java @@ -4,11 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.messaging; -import org.gridsuite.monitor.commons.MessageType; -import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate; -import org.gridsuite.monitor.commons.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.messaging.MessageType; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStatusUpdate; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionServiceTest.java new file mode 100644 index 00000000..decca81c --- /dev/null +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/ProcessExecutionServiceTest.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.monitor.worker.server.orchestrator; + +import org.gridsuite.monitor.commons.types.messaging.ProcessRunMessage; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessStatus; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.worker.server.clients.ReportRestClient; +import org.gridsuite.monitor.worker.server.core.orchestrator.StepExecutor; +import org.gridsuite.monitor.worker.server.core.process.Process; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; +import org.gridsuite.monitor.worker.server.messaging.NotificationService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +/** + * @author Antoine Bouhours + */ +@ExtendWith(MockitoExtension.class) +class ProcessExecutionServiceTest { + @Mock + private NotificationService notificationService; + + @Mock + private Process process; + + @Mock + private ProcessConfig processConfig; + + @Mock + private ReportRestClient reportRestClient; + + private ProcessExecutionService processExecutionService; + + private static final String EXECUTION_ENV_NAME = "test-env"; + + @BeforeEach + void setUp() { + when(process.getProcessType()).thenReturn(ProcessType.SECURITY_ANALYSIS); + StepExecutor stepExecutor = new StepExecutionService(notificationService, reportRestClient); + processExecutionService = new ProcessExecutionService(List.of(process), stepExecutor, notificationService, EXECUTION_ENV_NAME); + } + + private static ProcessStep mockStep(UUID id, String typeName) { + ProcessStep step = mock(ProcessStep.class); + ProcessStepType type = mock(ProcessStepType.class); + when(step.getId()).thenReturn(id); + when(step.getType()).thenReturn(type); + when(type.getName()).thenReturn(typeName); + return step; + } + + @Test + void executeProcessShouldCompleteSuccessfullyWhenAllStepsSucceed() { + UUID executionId = UUID.randomUUID(); + UUID caseUuid = UUID.randomUUID(); + UUID step1Id = UUID.randomUUID(); + UUID step2Id = UUID.randomUUID(); + UUID step3Id = UUID.randomUUID(); + ProcessStep step1 = mockStep(step1Id, "STEP_1"); + ProcessStep step2 = mockStep(step2Id, "STEP_2"); + ProcessStep step3 = mockStep(step3Id, "STEP_3"); + when(processConfig.processType()).thenReturn(ProcessType.SECURITY_ANALYSIS); + when(process.getSteps()).thenReturn(List.of(step1, step2, step3)); + ProcessRunMessage runMessage = new ProcessRunMessage<>(executionId, caseUuid, processConfig, null); + + processExecutionService.executeProcess(runMessage); + + verify(notificationService).updateStepsStatuses(eq(executionId), argThat(steps -> + steps.size() == 3 && + steps.get(0).getStatus() == StepStatus.SCHEDULED && + steps.get(0).getId().equals(step1Id) && + steps.get(0).getStepType().equals("STEP_1") && + steps.get(0).getStepOrder() == 0 && + steps.get(1).getStatus() == StepStatus.SCHEDULED && + steps.get(1).getId().equals(step2Id) && + steps.get(1).getStepType().equals("STEP_2") && + steps.get(1).getStepOrder() == 1 && + steps.get(2).getStatus() == StepStatus.SCHEDULED && + steps.get(2).getId().equals(step3Id) && + steps.get(2).getStepType().equals("STEP_3") && + steps.get(2).getStepOrder() == 2 + )); + verify(step1).execute(any()); + verify(step2).execute(any()); + verify(step3).execute(any()); + InOrder inOrder = inOrder(notificationService); + inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> + update.getStatus() == ProcessStatus.RUNNING && + update.getExecutionEnvName().equals(EXECUTION_ENV_NAME) && + update.getCompletedAt() == null + )); + inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> + update.getStatus() == ProcessStatus.COMPLETED && + update.getExecutionEnvName().equals(EXECUTION_ENV_NAME) && + update.getCompletedAt() != null + )); + } + + @Test + void executeProcessShouldSkipRemainingStepsAndSendFailedStatusWhenFirstStepFails() { + UUID executionId = UUID.randomUUID(); + UUID caseUuid = UUID.randomUUID(); + ProcessStep step1 = mockStep(UUID.randomUUID(), "STEP_1"); + ProcessStep step2 = mockStep(UUID.randomUUID(), "STEP_2"); + ProcessStep step3 = mockStep(UUID.randomUUID(), "STEP_3"); + RuntimeException stepException = new RuntimeException("Step execution failed"); + doThrow(stepException).when(step1).execute(any()); + when(processConfig.processType()).thenReturn(ProcessType.SECURITY_ANALYSIS); + when(process.getSteps()).thenReturn(List.of(step1, step2, step3)); + ProcessRunMessage runMessage = new ProcessRunMessage<>(executionId, caseUuid, processConfig, null); + + processExecutionService.executeProcess(runMessage); + + verify(step1).execute(any()); + verify(step2, never()).execute(any()); + verify(step3, never()).execute(any()); + InOrder inOrder = inOrder(notificationService); + inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> + update.getStatus() == ProcessStatus.RUNNING + )); + inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> + update.getStatus() == ProcessStatus.FAILED && + update.getCompletedAt() != null + )); + } + + @Test + void executeProcessShouldThrowIllegalArgumentExceptionWhenProcessTypeNotFound() { + when(processConfig.processType()).thenReturn(null); + ProcessRunMessage runMessage = new ProcessRunMessage<>(UUID.randomUUID(), UUID.randomUUID(), processConfig, null); + + assertThatThrownBy(() -> processExecutionService.executeProcess(runMessage)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("No process found for type"); + verifyNoInteractions(notificationService); + } +} diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/StepExecutionServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionServiceTest.java similarity index 84% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/StepExecutionServiceTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionServiceTest.java index 688cdcea..5a79000a 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/StepExecutionServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionServiceTest.java @@ -4,16 +4,18 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.services; +package org.gridsuite.monitor.worker.server.orchestrator; import com.powsybl.commons.report.ReportNode; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessExecutionStep; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.worker.server.core.ProcessStep; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; -import org.gridsuite.monitor.worker.server.core.ProcessStepType; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.commons.types.messaging.ProcessExecutionStep; +import org.gridsuite.monitor.commons.types.processexecution.StepStatus; +import org.gridsuite.monitor.worker.server.clients.ReportRestClient; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.gridsuite.monitor.worker.server.core.process.ProcessStepType; +import org.gridsuite.monitor.worker.server.messaging.NotificationService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,7 +40,7 @@ class StepExecutionServiceTest { private NotificationService notificationService; @Mock - private ReportRestService reportRestService; + private ReportRestClient reportRestClient; @Mock private ProcessStep processStep; @@ -49,11 +51,11 @@ class StepExecutionServiceTest { @Mock private ReportNode reportNode; - private StepExecutionService stepExecutionService; + private StepExecutionService stepExecutionService; @BeforeEach void setUp() { - stepExecutionService = new StepExecutionService<>(notificationService, reportRestService); + stepExecutionService = new StepExecutionService(notificationService, reportRestClient); } @Test @@ -69,7 +71,7 @@ void executeStepShouldCompleteSuccessfullyWhenNoExceptionThrown() { stepExecutionService.executeStep(context, processStep); verify(processStep).execute(context); - verify(reportRestService).sendReport(any(ReportInfos.class)); + verify(reportRestClient).sendReport(any(ReportInfos.class)); verify(notificationService, times(2)).updateStepStatus(eq(executionId), any(ProcessExecutionStep.class)); InOrder inOrder = inOrder(notificationService); inOrder.verify(notificationService).updateStepStatus(eq(executionId), argThat(step -> @@ -110,7 +112,7 @@ void executeStepShouldSendFailedStatusWhenExceptionThrown() { step.getStatus() == StepStatus.FAILED && step.getCompletedAt() != null )); - verify(reportRestService).sendReport(any(ReportInfos.class)); + verify(reportRestClient).sendReport(any(ReportInfos.class)); } @Test @@ -125,7 +127,7 @@ void skipStepShouldSendSkippedStatusWithoutExecutingStep() { verify(processStep, never()).execute(any()); // Verify report was NOT sent on skip - verify(reportRestService, never()).sendReport(any(ReportInfos.class)); + verify(reportRestClient, never()).sendReport(any(ReportInfos.class)); verify(notificationService).updateStepStatus(eq(executionId), argThat(step -> step.getStatus() == StepStatus.SKIPPED && "SKIPPED_STEP".equals(step.getStepType()) && diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStepTest.java similarity index 82% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStepTest.java index bc583f9a..219562a9 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStepTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.commons.steps; +package org.gridsuite.monitor.worker.server.process.commons.steps; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; @@ -13,10 +13,13 @@ import org.gridsuite.modification.dto.LoadModificationInfos; import org.gridsuite.modification.dto.ModificationInfos; import org.gridsuite.modification.dto.OperationType; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; -import org.gridsuite.monitor.worker.server.services.*; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.clients.NetworkModificationRestClient; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; +import org.gridsuite.monitor.worker.server.services.FilterService; +import org.gridsuite.monitor.worker.server.services.NetworkModificationService; +import org.gridsuite.monitor.worker.server.services.S3Service; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -45,7 +48,7 @@ class ApplyModificationsStepTest { private NetworkModificationService networkModificationService; @Mock - private NetworkModificationRestService networkModificationRestService; + private NetworkModificationRestClient networkModificationRestClient; @Mock private FilterService filterService; @@ -66,7 +69,7 @@ class ApplyModificationsStepTest { @BeforeEach void setUp() { - applyModificationsStep = new ApplyModificationsStep<>(networkModificationService, networkModificationRestService, s3Service, filterService); + applyModificationsStep = new ApplyModificationsStep<>(networkModificationService, networkModificationRestClient, s3Service, filterService); when(config.modificationUuids()).thenReturn(List.of(MODIFICATION_UUID)); when(stepContext.getConfig()).thenReturn(config); ReportInfos reportInfos = new ReportInfos(REPORT_UUID, ReportNode.newRootReportNode() @@ -85,11 +88,11 @@ void executeApplyModifications() { Network network = EurostagTutorialExample1Factory.create(); when(stepContext.getNetwork()).thenReturn(network); - when(networkModificationRestService.getModifications(any(List.class))).thenReturn(modificationInfos); + when(networkModificationRestClient.getModifications(any(List.class))).thenReturn(modificationInfos); doNothing().when(networkModificationService).applyModifications(any(Network.class), any(List.class), any(ReportNode.class), any(FilterService.class)); applyModificationsStep.execute(stepContext); - verify(networkModificationRestService).getModifications(any(List.class)); + verify(networkModificationRestClient).getModifications(any(List.class)); verify(networkModificationService).applyModifications(any(Network.class), any(List.class), any(ReportNode.class), any(FilterService.class)); } @@ -102,7 +105,7 @@ void executeApplyModificationsDebugOn() throws IOException { Network network = mock(Network.class); when(stepContext.getNetwork()).thenReturn(network); - when(networkModificationRestService.getModifications(any(List.class))).thenReturn(modificationInfos); + when(networkModificationRestClient.getModifications(any(List.class))).thenReturn(modificationInfos); doNothing().when(networkModificationService).applyModifications(any(Network.class), any(List.class), any(ReportNode.class), any(FilterService.class)); // --- mock data specific to debug behaviour --- @@ -114,7 +117,7 @@ void executeApplyModificationsDebugOn() throws IOException { // -- execute method applyModificationsStep.execute(stepContext); - verify(networkModificationRestService).getModifications(any(List.class)); + verify(networkModificationRestClient).getModifications(any(List.class)); verify(networkModificationService).applyModifications(any(Network.class), any(List.class), any(ReportNode.class), any(FilterService.class)); // --- verify debug behaviour --- diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStepTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStepTest.java similarity index 90% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStepTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStepTest.java index 607f3339..d1b363a6 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/LoadNetworkStepTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/LoadNetworkStepTest.java @@ -4,14 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.commons.steps; +package org.gridsuite.monitor.worker.server.process.commons.steps; import com.powsybl.commons.report.ReportNode; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; +import org.gridsuite.monitor.commons.types.processconfig.ProcessConfig; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; import org.gridsuite.monitor.worker.server.services.NetworkConversionService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcessTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcessTest.java similarity index 70% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcessTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcessTest.java index e95f2977..aad1631b 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/SecurityAnalysisProcessTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/SecurityAnalysisProcessTest.java @@ -4,15 +4,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.securityanalysis; +package org.gridsuite.monitor.worker.server.process.securityanalysis; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.worker.server.core.ProcessStep; -import org.gridsuite.monitor.worker.server.processes.commons.steps.ApplyModificationsStep; -import org.gridsuite.monitor.worker.server.processes.commons.steps.LoadNetworkStep; -import org.gridsuite.monitor.worker.server.processes.securityanalysis.steps.SecurityAnalysisRunComputationStep; -import org.gridsuite.monitor.worker.server.services.StepExecutionService; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.commons.types.processexecution.ProcessType; +import org.gridsuite.monitor.worker.server.core.process.ProcessStep; +import org.gridsuite.monitor.worker.server.process.commons.steps.ApplyModificationsStep; +import org.gridsuite.monitor.worker.server.process.commons.steps.LoadNetworkStep; +import org.gridsuite.monitor.worker.server.process.securityanalysis.steps.SecurityAnalysisRunComputationStep; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,9 +28,6 @@ @ExtendWith(MockitoExtension.class) class SecurityAnalysisProcessTest { - @Mock - private StepExecutionService stepExecutionService; - @Mock private LoadNetworkStep loadNetworkStep; @@ -46,7 +42,6 @@ class SecurityAnalysisProcessTest { @BeforeEach void setUp() { process = new SecurityAnalysisProcess( - stepExecutionService, loadNetworkStep, applyModificationsStep, runComputationStep diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java similarity index 85% rename from monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java rename to monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java index d3669709..0ed153ce 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package org.gridsuite.monitor.worker.server.processes.securityanalysis.steps; +package org.gridsuite.monitor.worker.server.process.securityanalysis.steps; import com.powsybl.commons.report.ReportNode; import com.powsybl.contingency.Contingency; @@ -13,13 +13,13 @@ import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; import com.powsybl.security.SecurityAnalysisParameters; import com.powsybl.security.SecurityAnalysisResult; -import org.gridsuite.monitor.commons.ResultType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.worker.server.core.ProcessStepExecutionContext; -import org.gridsuite.monitor.worker.server.dto.ReportInfos; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.SecurityAnalysisInputData; +import org.gridsuite.monitor.worker.server.dto.report.ReportInfos; +import org.gridsuite.monitor.commons.types.result.ResultType; +import org.gridsuite.monitor.commons.types.processconfig.SecurityAnalysisConfig; +import org.gridsuite.monitor.worker.server.core.context.ProcessStepExecutionContext; +import org.gridsuite.monitor.worker.server.clients.SecurityAnalysisRestClient; import org.gridsuite.monitor.worker.server.services.SecurityAnalysisParametersService; -import org.gridsuite.monitor.worker.server.services.SecurityAnalysisRestService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -42,7 +42,7 @@ class SecurityAnalysisRunComputationStepTest { @Mock - private SecurityAnalysisRestService securityAnalysisRestService; + private SecurityAnalysisRestClient securityAnalysisRestClient; @Mock private SecurityAnalysisParametersService securityAnalysisParametersService; @@ -61,7 +61,7 @@ class SecurityAnalysisRunComputationStepTest { @BeforeEach void setUp() { - runComputationStep = new SecurityAnalysisRunComputationStep(securityAnalysisRestService, securityAnalysisParametersService); + runComputationStep = new SecurityAnalysisRunComputationStep(securityAnalysisRestClient, securityAnalysisParametersService); when(stepContext.getConfig()).thenReturn(config); when(config.securityAnalysisParametersUuid()).thenReturn(PARAMS_UUID); @@ -89,7 +89,7 @@ void executeRunSecurityAnalysis() { assertEquals("RUN_SA_COMPUTATION", stepType); verify(securityAnalysisParametersService).buildSecurityAnalysisInputData(PARAMS_UUID, LOADFLOW_PARAMS_UUID, network); - verify(securityAnalysisRestService).saveResult( + verify(securityAnalysisRestClient).saveResult( any(UUID.class), any(SecurityAnalysisResult.class) ); diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterServiceTest.java index aebf64a7..c86186bd 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/FilterServiceTest.java @@ -26,9 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; /** * @author Franck Lecuyer diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionServiceTest.java deleted file mode 100644 index cfd2721a..00000000 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ProcessExecutionServiceTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/** - * Copyright (c) 2026, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -package org.gridsuite.monitor.worker.server.services; - -import org.gridsuite.monitor.commons.ProcessConfig; -import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate; -import org.gridsuite.monitor.commons.ProcessRunMessage; -import org.gridsuite.monitor.commons.ProcessStatus; -import org.gridsuite.monitor.commons.ProcessType; -import org.gridsuite.monitor.commons.SecurityAnalysisConfig; -import org.gridsuite.monitor.commons.StepStatus; -import org.gridsuite.monitor.worker.server.core.Process; -import org.gridsuite.monitor.worker.server.core.ProcessExecutionContext; -import org.gridsuite.monitor.worker.server.processes.commons.steps.ApplyModificationsStep; -import org.gridsuite.monitor.worker.server.processes.commons.steps.LoadNetworkStep; -import org.gridsuite.monitor.worker.server.processes.securityanalysis.steps.SecurityAnalysisRunComputationStep; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InOrder; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -/** - * @author Antoine Bouhours - */ -@ExtendWith(MockitoExtension.class) -class ProcessExecutionServiceTest { - @Mock - private NotificationService notificationService; - - @Mock - private Process process; - - @Mock - private ProcessConfig processConfig; - - @Mock - private NetworkConversionService networkConversionService; - - @Mock - private NetworkModificationService networkModificationService; - - @Mock - private NetworkModificationRestService networkModificationRestService; - - @Mock - private FilterService filterService; - - @Mock - private S3Service s3Service; - - @Mock - private SecurityAnalysisRestService securityAnalysisRestService; - - @Mock - private SecurityAnalysisParametersService securityAnalysisParametersService; - - private ProcessExecutionService processExecutionService; - - private LoadNetworkStep loadNetworkStep; - - private ApplyModificationsStep applyModificationsStep; - - private SecurityAnalysisRunComputationStep runComputationStep; - - private static final String EXECUTION_ENV_NAME = "test-env"; - - @BeforeEach - void setUp() { - when(process.getProcessType()).thenReturn(ProcessType.SECURITY_ANALYSIS); - - List> processList = List.of(process); - processExecutionService = new ProcessExecutionService(processList, notificationService, EXECUTION_ENV_NAME); - - loadNetworkStep = new LoadNetworkStep<>(networkConversionService); - applyModificationsStep = new ApplyModificationsStep<>(networkModificationService, networkModificationRestService, s3Service, filterService); - runComputationStep = new SecurityAnalysisRunComputationStep(securityAnalysisRestService, securityAnalysisParametersService); - } - - @Test - void executeProcessShouldCompleteSuccessfullyWhenProcessExecutesWithoutError() { - UUID executionId = UUID.randomUUID(); - UUID caseUuid = UUID.randomUUID(); - when(processConfig.processType()).thenReturn(ProcessType.SECURITY_ANALYSIS); - doNothing().when(process).execute(any(ProcessExecutionContext.class)); - ProcessRunMessage runMessage = new ProcessRunMessage<>(executionId, caseUuid, processConfig, null); - when(process.getSteps()).thenReturn((List) List.of(loadNetworkStep, applyModificationsStep, runComputationStep)); - - processExecutionService.executeProcess(runMessage); - - verify(process, times(1)).getSteps(); - verify(notificationService, times(1)).updateStepsStatuses(eq(executionId), argThat(steps -> - steps.size() == 3 && - steps.get(0).getStatus() == StepStatus.SCHEDULED && - steps.get(0).getId().equals(loadNetworkStep.getId()) && - steps.get(0).getStepType().equals(loadNetworkStep.getType().getName()) && - steps.get(0).getStepOrder() == 0 && - steps.get(1).getStatus() == StepStatus.SCHEDULED && - steps.get(1).getId().equals(applyModificationsStep.getId()) && - steps.get(1).getStepType().equals(applyModificationsStep.getType().getName()) && - steps.get(1).getStepOrder() == 1 && - steps.get(2).getStatus() == StepStatus.SCHEDULED && - steps.get(2).getId().equals(runComputationStep.getId()) && - steps.get(2).getStepType().equals(runComputationStep.getType().getName()) && - steps.get(2).getStepOrder() == 2 - )); - - verify(process).execute(argThat(context -> - context.getExecutionId().equals(executionId) && - context.getCaseUuid().equals(caseUuid) && - context.getConfig().equals(processConfig) && - context.getExecutionEnvName().equals(EXECUTION_ENV_NAME) - )); - verify(notificationService, times(2)).updateExecutionStatus(eq(executionId), any(ProcessExecutionStatusUpdate.class)); - InOrder inOrder = inOrder(notificationService); - inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> - update.getStatus() == ProcessStatus.RUNNING && - update.getExecutionEnvName().equals(EXECUTION_ENV_NAME) && - update.getCompletedAt() == null - )); - inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> - update.getStatus() == ProcessStatus.COMPLETED && - update.getExecutionEnvName().equals(EXECUTION_ENV_NAME) && - update.getCompletedAt() != null - )); - } - - @Test - void executeProcessShouldSendFailedStatusWhenProcessThrowsException() { - UUID executionId = UUID.randomUUID(); - UUID caseUuid = UUID.randomUUID(); - when(processConfig.processType()).thenReturn(ProcessType.SECURITY_ANALYSIS); - RuntimeException processException = new RuntimeException("Process execution failed"); - doThrow(processException).when(process).execute(any(ProcessExecutionContext.class)); - ProcessRunMessage runMessage = new ProcessRunMessage<>(executionId, caseUuid, processConfig, null); - - assertThrows(RuntimeException.class, () -> processExecutionService.executeProcess(runMessage)); - - verify(process).execute(any(ProcessExecutionContext.class)); - verify(notificationService, times(2)).updateExecutionStatus(eq(executionId), any(ProcessExecutionStatusUpdate.class)); - InOrder inOrder = inOrder(notificationService); - inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> - update.getStatus() == ProcessStatus.RUNNING - )); - inOrder.verify(notificationService).updateExecutionStatus(eq(executionId), argThat(update -> - update.getStatus() == ProcessStatus.FAILED && - update.getCompletedAt() != null - )); - } - - @Test - void executeProcessShouldThrowIllegalArgumentExceptionWhenProcessTypeNotFound() { - when(processConfig.processType()).thenReturn(null); - ProcessRunMessage runMessage = new ProcessRunMessage<>(UUID.randomUUID(), UUID.randomUUID(), processConfig, null); - - assertThatThrownBy(() -> processExecutionService.executeProcess(runMessage)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("No process found for type"); - verify(process, never()).execute(any()); - verifyNoInteractions(notificationService); - } -} diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3ServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3ServiceTest.java index f0f2e7d2..c98c7fd7 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3ServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/S3ServiceTest.java @@ -8,6 +8,7 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.gridsuite.monitor.worker.server.clients.S3RestClient; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; @@ -36,7 +37,7 @@ @ExtendWith(MockitoExtension.class) class S3ServiceTest { @Mock - S3RestService s3RestService; + S3RestClient s3RestClient; @InjectMocks S3Service s3Service; @@ -64,14 +65,14 @@ void testPathIsCompressedBeforeUploading() throws Exception { Path uploaded = invocation.getArgument(0); Files.copy(uploaded, capturedCopy, StandardCopyOption.REPLACE_EXISTING); return null; - }).when(s3RestService) + }).when(s3RestClient) .uploadFile(any(Path.class), anyString(), anyString()); // --- Method invocation --- s3Service.exportCompressedToS3(s3Key, fileNamePrefix, fileNameSuffix, writer); // --- Assertions --- - verify(s3RestService).uploadFile(any(), eq(s3Key), eq(String.join("", fileNamePrefix, fileNameSuffix, ".gz"))); + verify(s3RestClient).uploadFile(any(), eq(s3Key), eq(String.join("", fileNamePrefix, fileNameSuffix, ".gz"))); try (InputStream in = new GZIPInputStream(Files.newInputStream(capturedCopy))) { String uncompressedContent = new String(in.readAllBytes(), UTF_8); assertThat(uncompressedContent).isNotNull(); @@ -99,7 +100,7 @@ void testTempFilesAreDeletedAfterExecution() throws Exception { // --- Assertions --- ArgumentCaptor compressedDebugFileToUploadCaptor = ArgumentCaptor.forClass(Path.class); - verify(s3RestService).uploadFile( + verify(s3RestClient).uploadFile( compressedDebugFileToUploadCaptor.capture(), eq(s3Key), eq(String.join("", fileNamePrefix, fileNameSuffix, ".gz")) diff --git a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersServiceTest.java b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersServiceTest.java index 441b13b0..1cce90a5 100644 --- a/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersServiceTest.java +++ b/monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersServiceTest.java @@ -13,6 +13,10 @@ import com.powsybl.loadflow.LoadFlowParameters; import org.gridsuite.actions.dto.contingency.AbstractContingencyList; import org.gridsuite.actions.dto.contingency.IdBasedContingencyList; +import org.gridsuite.monitor.worker.server.clients.ActionsRestClient; +import org.gridsuite.monitor.worker.server.clients.FilterRestClient; +import org.gridsuite.monitor.worker.server.clients.LoadFlowRestClient; +import org.gridsuite.monitor.worker.server.clients.SecurityAnalysisRestClient; import org.gridsuite.monitor.worker.server.dto.parameters.loadflow.LoadFlowParametersInfos; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.ContingencyListsInfos; import org.gridsuite.monitor.worker.server.dto.parameters.securityanalysis.IdNameInfos; @@ -40,22 +44,22 @@ @ExtendWith(MockitoExtension.class) class SecurityAnalysisParametersServiceTest { @Mock - private SecurityAnalysisRestService securityAnalysisRestService; + private SecurityAnalysisRestClient securityAnalysisRestClient; @Mock - private LoadFlowRestService loadFlowRestService; + private LoadFlowRestClient loadFlowRestClient; @Mock - private ActionsRestService actionsRestService; + private ActionsRestClient actionsRestClient; @Mock - private FilterRestService filterRestService; + private FilterRestClient filterRestClient; private SecurityAnalysisParametersService securityAnalysisParametersService; @BeforeEach void setUp() { - securityAnalysisParametersService = new SecurityAnalysisParametersService(securityAnalysisRestService, loadFlowRestService, actionsRestService, filterRestService); + securityAnalysisParametersService = new SecurityAnalysisParametersService(securityAnalysisRestClient, loadFlowRestClient, actionsRestClient, filterRestClient); } @Test @@ -86,9 +90,9 @@ void buildSecurityAnalysisInputData() { new IdentifierContingencyList("c1", List.of(new IdBasedNetworkElementIdentifier("GEN", "c1")))); List persistentContingencyList = List.of(idBasedContingencyList); - when(securityAnalysisRestService.getParameters(securityAnalysisParametersUuid)).thenReturn(securityAnalysisParametersValues); - when(loadFlowRestService.getParameters(loadflowParametersUuid)).thenReturn(loadFlowParametersInfos); - when(actionsRestService.getPersistentContingencyLists(contingencyListUuids)).thenReturn(persistentContingencyList); + when(securityAnalysisRestClient.getParameters(securityAnalysisParametersUuid)).thenReturn(securityAnalysisParametersValues); + when(loadFlowRestClient.getParameters(loadflowParametersUuid)).thenReturn(loadFlowParametersInfos); + when(actionsRestClient.getPersistentContingencyLists(contingencyListUuids)).thenReturn(persistentContingencyList); SecurityAnalysisInputData inputData = securityAnalysisParametersService.buildSecurityAnalysisInputData(securityAnalysisParametersUuid, loadflowParametersUuid, network); @@ -98,8 +102,8 @@ void buildSecurityAnalysisInputData() { assertThat(inputData.contingencies().get(0).getElements()).hasSize(1); assertThat(inputData.contingencies().get(0).getElements().get(0).getId()).isEqualTo("GEN"); - verify(securityAnalysisRestService, times(1)).getParameters(securityAnalysisParametersUuid); - verify(loadFlowRestService, times(1)).getParameters(loadflowParametersUuid); - verify(actionsRestService, times(1)).getPersistentContingencyLists(contingencyListUuids); + verify(securityAnalysisRestClient, times(1)).getParameters(securityAnalysisParametersUuid); + verify(loadFlowRestClient, times(1)).getParameters(loadflowParametersUuid); + verify(actionsRestClient, times(1)).getPersistentContingencyLists(contingencyListUuids); } }