Skip to content

Commit

Permalink
Add a request param to target one of the 3 security-analysis-server e…
Browse files Browse the repository at this point in the history
…ndpoints (#454)

Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
klesaulnier authored Oct 20, 2023
1 parent afd33a1 commit c8f95e4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.gridsuite.study.server.networkmodificationtree.dto.RootNode;
import org.gridsuite.study.server.dto.dynamicsimulation.event.EventInfos;
import org.gridsuite.study.server.service.*;
import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType;
import org.springframework.data.domain.Pageable;
import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService;
import org.gridsuite.study.server.service.shortcircuit.ShortcircuitAnalysisType;
Expand Down Expand Up @@ -777,9 +778,10 @@ public ResponseEntity<UUID> runSecurityAnalysis(@Parameter(description = "studyU
@ApiResponse(responseCode = "404", description = "The security analysis has not been found")})
public ResponseEntity<String> getSecurityAnalysisResult(@Parameter(description = "study UUID") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Limit types") @RequestParam(name = "limitType", required = false) List<String> limitTypes) {
@Parameter(description = "Limit types") @RequestParam(name = "limitType", required = false) List<String> limitTypes,
@Parameter(description = "result type") @RequestParam(name = "resultType") SecurityAnalysisResultType resultType) {
List<String> nonNullLimitTypes = limitTypes != null ? limitTypes : Collections.emptyList();
String result = securityAnalysisService.getSecurityAnalysisResult(nodeUuid, nonNullLimitTypes);
String result = securityAnalysisService.getSecurityAnalysisResult(nodeUuid, resultType, nonNullLimitTypes);
return result != null ? ResponseEntity.ok().body(result) :
ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gridsuite.study.server.dto.SecurityAnalysisParametersValues;
import org.gridsuite.study.server.dto.SecurityAnalysisStatus;
import org.gridsuite.study.server.repository.SecurityAnalysisParametersEntity;
import org.gridsuite.study.server.service.securityanalysis.SecurityAnalysisResultType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -62,14 +63,14 @@ public class SecurityAnalysisService {

@Autowired
public SecurityAnalysisService(RemoteServicesProperties remoteServicesProperties,
NetworkModificationTreeService networkModificationTreeService,
ObjectMapper objectMapper) {
NetworkModificationTreeService networkModificationTreeService,
ObjectMapper objectMapper) {
this.securityAnalysisServerBaseUri = remoteServicesProperties.getServiceUri("security-analysis-server");
this.networkModificationTreeService = networkModificationTreeService;
this.objectMapper = objectMapper;
}

public String getSecurityAnalysisResult(UUID nodeUuid, List<String> limitTypes) {
public String getSecurityAnalysisResult(UUID nodeUuid, SecurityAnalysisResultType resultType, List<String> limitTypes) {
Objects.requireNonNull(limitTypes);
String result;
Optional<UUID> resultUuidOpt = networkModificationTreeService.getSecurityAnalysisResultUuid(nodeUuid);
Expand All @@ -78,7 +79,7 @@ public String getSecurityAnalysisResult(UUID nodeUuid, List<String> limitTypes)
return null;
}

String path = UriComponentsBuilder.fromPath(DELIMITER + SECURITY_ANALYSIS_API_VERSION + "/results/{resultUuid}")
String path = UriComponentsBuilder.fromPath(DELIMITER + SECURITY_ANALYSIS_API_VERSION + "/results/{resultUuid}/" + getPathFromResultType(resultType))
.queryParam("limitType", limitTypes).buildAndExpand(resultUuidOpt.get()).toUriString();
try {
result = restTemplate.getForObject(securityAnalysisServerBaseUri + path, String.class);
Expand All @@ -93,6 +94,14 @@ public String getSecurityAnalysisResult(UUID nodeUuid, List<String> limitTypes)
return result;
}

private String getPathFromResultType(SecurityAnalysisResultType resultType) {
return switch (resultType) {
case NMK_CONTINGENCIES -> "nmk-contingencies-result";
case NMK_LIMIT_VIOLATIONS -> "nmk-constraints-result";
case N -> "n-result";
};
}

public UUID runSecurityAnalysis(UUID networkUuid, UUID reportUuid, UUID nodeUuid, String variantId, String provider, List<String> contingencyListNames, SecurityAnalysisParametersInfos securityAnalysisParameters,
String receiver) {
var uriComponentsBuilder = UriComponentsBuilder
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1461,17 +1461,16 @@ private void invalidateBuild(UUID studyUuid, UUID nodeUuid, boolean invalidateOn
}

CompletableFuture<Void> executeInParallel = CompletableFuture.allOf(
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getReportUuids().forEach(reportService::deleteReport)), // TODO delete all with one request only
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getLoadFlowResultUuids().forEach(loadflowService::deleteLoadFlowResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getSecurityAnalysisResultUuids().forEach(securityAnalysisService::deleteSaResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getSensitivityAnalysisResultUuids().forEach(sensitivityAnalysisService::deleteSensitivityAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getShortCircuitAnalysisResultUuids().forEach(shortCircuitService::deleteShortCircuitAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getOneBusShortCircuitAnalysisResultUuids().forEach(shortCircuitService::deleteShortCircuitAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getVoltageInitResultUuids().forEach(voltageInitService::deleteVoltageInitResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getDynamicSimulationResultUuids().forEach(dynamicSimulationService::deleteResult)),
studyServerExecutionService.runAsync(() -> networkStoreService.deleteVariants(invalidateNodeInfos.getNetworkUuid(), invalidateNodeInfos.getVariantIds()))
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getReportUuids().forEach(reportService::deleteReport)), // TODO delete all with one request only
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getLoadFlowResultUuids().forEach(loadflowService::deleteLoadFlowResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getSecurityAnalysisResultUuids().forEach(securityAnalysisService::deleteSaResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getSensitivityAnalysisResultUuids().forEach(sensitivityAnalysisService::deleteSensitivityAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getShortCircuitAnalysisResultUuids().forEach(shortCircuitService::deleteShortCircuitAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getOneBusShortCircuitAnalysisResultUuids().forEach(shortCircuitService::deleteShortCircuitAnalysisResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getVoltageInitResultUuids().forEach(voltageInitService::deleteVoltageInitResult)),
studyServerExecutionService.runAsync(() -> invalidateNodeInfos.getDynamicSimulationResultUuids().forEach(dynamicSimulationService::deleteResult)),
studyServerExecutionService.runAsync(() -> networkStoreService.deleteVariants(invalidateNodeInfos.getNetworkUuid(), invalidateNodeInfos.getVariantIds()))
);

try {
executeInParallel.get();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2023, 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.study.server.service.securityanalysis;
/**
* @author Kevin Le Saulnier <kevin.lesaulnier at rte-france.com>
*/

public enum SecurityAnalysisResultType {
N,
NMK_CONTINGENCIES,
NMK_LIMIT_VIOLATIONS
}
Loading

0 comments on commit c8f95e4

Please sign in to comment.