Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@Getter
@Setter
public class DeleteNodeInfos {
private List<UUID> removedNodeUuids = new ArrayList<>();

private List<UUID> modificationGroupUuids = new ArrayList<>();

private List<UUID> reportUuids = new ArrayList<>();
Expand All @@ -46,6 +48,10 @@ public class DeleteNodeInfos {

private List<UUID> stateEstimationResultUuids = new ArrayList<>();

public void addRemovedNodeUuid(UUID removedNodeUuid) {
removedNodeUuids.add(removedNodeUuid);
}

public void addModificationGroupUuid(UUID modificationGroupUuid) {
modificationGroupUuids.add(modificationGroupUuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ public void deleteLoadFlowResults(List<UUID> resultsUuids) {
deleteCalculationResults(resultsUuids, DELIMITER + LOADFLOW_API_VERSION + "/results", restTemplate, loadFlowServerBaseUri);
}

public void deleteAllLoadFlowResults() {
deleteLoadFlowResults(null);
}

public Integer getLoadFlowResultsCount() {
String path = UriComponentsBuilder
.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/supervision/results-count").toUriString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,10 @@ public void moveStudySubtree(UUID parentNodeToMoveUuid, UUID anchorNodeUuid) {

@Transactional
// TODO test if studyUuid exist and have a node <nodeId>
public List<UUID> doDeleteNode(UUID nodeId, boolean deleteChildren, DeleteNodeInfos deleteNodeInfos) {
List<UUID> removedNodes = new ArrayList<>();
public void doDeleteNode(UUID nodeId, boolean deleteChildren, DeleteNodeInfos deleteNodeInfos) {
UUID studyId = self.getStudyUuidForNodeId(nodeId);
deleteNodes(nodeId, deleteChildren, false, removedNodes, deleteNodeInfos);
notificationService.emitNodesDeleted(studyId, removedNodes, deleteChildren);
return removedNodes;
deleteNodes(nodeId, deleteChildren, false, deleteNodeInfos);
notificationService.emitNodesDeleted(studyId, deleteNodeInfos.getRemovedNodeUuids(), deleteChildren);
}

@Transactional
Expand Down Expand Up @@ -314,7 +312,7 @@ private void stashNodes(UUID id, boolean stashChildren, List<UUID> stashedNodes,
});
}

private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoot, List<UUID> removedNodes, DeleteNodeInfos deleteNodeInfos) {
private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoot, DeleteNodeInfos deleteNodeInfos) {
Optional<NodeEntity> optNodeToDelete = nodesRepository.findById(id);
optNodeToDelete.ifPresent(nodeToDelete -> {
/* root cannot be deleted by accident */
Expand All @@ -332,9 +330,9 @@ private void deleteNodes(UUID id, boolean deleteChildren, boolean allowDeleteRoo
getChildren(id).forEach(node -> node.setParentNode(nodeToDelete.getParentNode()));
} else {
getChildren(id)
.forEach(child -> deleteNodes(child.getIdNode(), true, false, removedNodes, deleteNodeInfos));
.forEach(child -> deleteNodes(child.getIdNode(), true, false, deleteNodeInfos));
}
removedNodes.add(id);
deleteNodeInfos.addRemovedNodeUuid(id);
if (nodeToDelete.getType() == NodeType.ROOT) {
rootNodeInfoRepository.deleteById(id);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,20 @@ public void updateRootNetworkNode(UUID nodeUuid, UUID rootNetworkUuid, RootNetwo
}
}

public Stream<CompletableFuture<Void>> getDeleteRootNetworkNodeInfosFutures(List<RootNetworkNodeInfo> rootNetworkNodeInfo) {
return Stream.of(
studyServerExecutionService.runAsync(() -> reportService.deleteReports(rootNetworkNodeInfo.stream().map(this::getReportUuids).flatMap(Collection::stream).toList())),
studyServerExecutionService.runAsync(() -> loadFlowService.deleteLoadFlowResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getLoadFlowResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> securityAnalysisService.deleteSecurityAnalysisResults(rootNetworkNodeInfo.stream()
public void deleteRootNetworkNodeRemoteInfos(List<RootNetworkNodeInfo> rootNetworkNodeInfo) {
CompletableFuture.allOf(
studyServerExecutionService.runAsyncAndComplete(() -> reportService.deleteReports(rootNetworkNodeInfo.stream().map(this::getReportUuids).flatMap(Collection::stream).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> loadFlowService.deleteLoadFlowResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getLoadFlowResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> securityAnalysisService.deleteSecurityAnalysisResults(rootNetworkNodeInfo.stream()
.map(RootNetworkNodeInfo::getSecurityAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> sensitivityAnalysisService.deleteSensitivityAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getSensitivityAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> nonEvacuatedEnergyService.deleteNonEvacuatedEnergyResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getNonEvacuatedEnergyResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> shortCircuitService.deleteShortCircuitAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getShortCircuitAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> shortCircuitService.deleteShortCircuitAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getOneBusShortCircuitAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> voltageInitService.deleteVoltageInitResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getVoltageInitResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> dynamicSimulationService.deleteResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getDynamicSimulationResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> dynamicSecurityAnalysisService.deleteResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getDynamicSecurityAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsync(() -> stateEstimationService.deleteStateEstimationResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getStateEstimationResultUuid).filter(Objects::nonNull).toList()))
studyServerExecutionService.runAsyncAndComplete(() -> sensitivityAnalysisService.deleteSensitivityAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getSensitivityAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> nonEvacuatedEnergyService.deleteNonEvacuatedEnergyResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getNonEvacuatedEnergyResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> shortCircuitService.deleteShortCircuitAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getShortCircuitAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> shortCircuitService.deleteShortCircuitAnalysisResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getOneBusShortCircuitAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> voltageInitService.deleteVoltageInitResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getVoltageInitResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> dynamicSimulationService.deleteResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getDynamicSimulationResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> dynamicSecurityAnalysisService.deleteResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getDynamicSecurityAnalysisResultUuid).filter(Objects::nonNull).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> stateEstimationService.deleteStateEstimationResults(rootNetworkNodeInfo.stream().map(RootNetworkNodeInfo::getStateEstimationResultUuid).filter(Objects::nonNull).toList()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,35 +235,22 @@ public void deleteRootNetworks(StudyEntity studyEntity, Stream<UUID> rootNetwork
}

public void deleteRootNetworks(StudyEntity studyEntity, List<RootNetworkInfos> rootNetworksInfos) {
CompletableFuture<Void> executeInParallel = CompletableFuture.allOf(
getDeleteRootNetworkInfosFutures(rootNetworksInfos).toArray(CompletableFuture[]::new)
);

try {
executeInParallel.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new StudyException(DELETE_ROOT_NETWORK_FAILED, e.getMessage());
} catch (Exception e) {
throw new StudyException(DELETE_ROOT_NETWORK_FAILED, e.getMessage());
}
deleteRootNetworkRemoteInfos(rootNetworksInfos);

studyEntity.deleteRootNetworks(rootNetworksInfos.stream().map(RootNetworkInfos::getId).collect(Collectors.toSet()));
}

public Stream<CompletableFuture<Void>> getDeleteRootNetworkInfosFutures(List<RootNetworkInfos> rootNetworkInfos) {
return Stream
.concat(
// delete remote data ids set in root network
Stream.of(
studyServerExecutionService.runAsync(() -> reportService.deleteReports(rootNetworkInfos.stream().map(RootNetworkInfos::getReportUuid).toList())),
studyServerExecutionService.runAsync(() -> rootNetworkInfos.stream().map(rni -> rni.getNetworkInfos().getNetworkUuid()).filter(Objects::nonNull).forEach(equipmentInfosService::deleteEquipmentIndexes)),
studyServerExecutionService.runAsync(() -> rootNetworkInfos.stream().map(rni -> rni.getNetworkInfos().getNetworkUuid()).filter(Objects::nonNull).forEach(networkStoreService::deleteNetwork)),
studyServerExecutionService.runAsync(() -> rootNetworkInfos.stream().map(rni -> rni.getCaseInfos().getCaseUuid()).filter(Objects::nonNull).forEach(caseService::deleteCase))
),
// delete remote data ids set in root network node infos
rootNetworkNodeInfoService.getDeleteRootNetworkNodeInfosFutures(rootNetworkInfos.stream().map(RootNetworkInfos::getRootNetworkNodeInfos).filter(Objects::nonNull).flatMap(Collection::stream).toList())
);
public void deleteRootNetworkRemoteInfos(List<RootNetworkInfos> rootNetworkInfos) {
CompletableFuture.allOf(
// delete remote data ids set in root network
studyServerExecutionService.runAsyncAndComplete(() -> reportService.deleteReports(rootNetworkInfos.stream().map(RootNetworkInfos::getReportUuid).toList())),
studyServerExecutionService.runAsyncAndComplete(() -> rootNetworkInfos.stream().map(rni -> rni.getNetworkInfos().getNetworkUuid()).filter(Objects::nonNull).forEach(equipmentInfosService::deleteEquipmentIndexes)),
studyServerExecutionService.runAsyncAndComplete(() -> rootNetworkInfos.stream().map(rni -> rni.getNetworkInfos().getNetworkUuid()).filter(Objects::nonNull).forEach(networkStoreService::deleteNetwork)),
studyServerExecutionService.runAsyncAndComplete(() -> rootNetworkInfos.stream().map(rni -> rni.getCaseInfos().getCaseUuid()).filter(Objects::nonNull).forEach(caseService::deleteCase))
);

// delete remote data ids set in root network node infos
rootNetworkNodeInfoService.deleteRootNetworkNodeRemoteInfos(rootNetworkInfos.stream().map(RootNetworkInfos::getRootNetworkNodeInfos).filter(Objects::nonNull).flatMap(Collection::stream).toList());
}

public Optional<RootNetworkRequestEntity> getRootNetworkRequest(UUID rootNetworkUuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
Expand All @@ -18,6 +20,8 @@
@Service
public class StudyServerExecutionService {

private static final Logger LOGGER = LoggerFactory.getLogger(StudyServerExecutionService.class);

private ExecutorService executorService;

@PostConstruct
Expand All @@ -33,4 +37,14 @@ private void preDestroy() {
public CompletableFuture<Void> runAsync(Runnable runnable) {
return CompletableFuture.runAsync(runnable, executorService);
}

public CompletableFuture<Void> runAsyncAndComplete(Runnable runnable) {
return CompletableFuture.runAsync(runnable, executorService).whenCompleteAsync((r, t) -> logAsyncError(t));
}

private void logAsyncError(Throwable e) {
if (LOGGER.isErrorEnabled() && e != null) {
LOGGER.error(e.toString(), e);
}
}
}
Loading