Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root network deletion #643

Merged
merged 18 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -33,6 +33,7 @@ protected ResponseEntity<Object> handleStudyException(StudyException exception)
case ELEMENT_NOT_FOUND,
STUDY_NOT_FOUND,
NODE_NOT_FOUND,
ROOTNETWORK_NOT_FOUND,
SlimaneAmar marked this conversation as resolved.
Show resolved Hide resolved
SECURITY_ANALYSIS_NOT_FOUND,
SENSITIVITY_ANALYSIS_NOT_FOUND,
SHORT_CIRCUIT_ANALYSIS_NOT_FOUND,
Expand Down
96 changes: 45 additions & 51 deletions src/main/java/org/gridsuite/study/server/StudyController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum Type {
DELETE_EQUIPMENT_FAILED,
DELETE_NODE_FAILED,
DELETE_STUDY_FAILED,
DELETE_ROOT_NETWORK_FAILED,
CREATE_NETWORK_MODIFICATION_FAILED,
UPDATE_NETWORK_MODIFICATION_FAILED,
DELETE_NETWORK_MODIFICATION_FAILED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ResponseEntity<List<UUID>> getOrphanIndexedEquipments() {
@Operation(summary = "delete indexed equipments and tombstoned equipments for the given networkUuid")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given networkUuid have been deleted")})
public ResponseEntity<Long> deleteNetworkUuidIndexedEquipmentsAndTombstoned(@PathVariable("networkUuid") UUID networkUuid) {
studyService.deleteEquipmentIndexes(networkUuid);
equipmentInfosService.deleteEquipmentIndexes(networkUuid);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
@Getter
public class DeleteStudyInfos {

private List<UUID> networkUuids;

private List<UUID> caseUuids;

private List<RootNetworkNodeInfo> rootNetworkNodeInfos;

private List<UUID> reportsUuids;
private List<RootNetworkInfos> rootNetworkInfosList;

private List<UUID> modificationGroupUuids;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.gridsuite.study.server.dto.elasticsearch.BasicEquipmentInfos;
import org.gridsuite.study.server.dto.elasticsearch.EquipmentInfos;
import org.gridsuite.study.server.dto.elasticsearch.TombstonedEquipmentInfos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.client.elc.*;
Expand All @@ -28,6 +30,8 @@
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import static java.util.Map.entry;
Expand All @@ -41,6 +45,8 @@
@Service
public class EquipmentInfosService {

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

public enum FieldSelector {
NAME, ID
}
Expand Down Expand Up @@ -238,6 +244,13 @@ public void deleteAllByNetworkUuid(@NonNull UUID networkUuid) {

}

public void deleteEquipmentIndexes(UUID networkUuid) {
AtomicReference<Long> startTime = new AtomicReference<>();
startTime.set(System.nanoTime());
deleteAllByNetworkUuid(networkUuid);
LOGGER.trace("Indexes deletion for network '{}' : {} seconds", networkUuid, TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get()));
}

public static String escapeLucene(String s) {
StringBuilder sb = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

import jakarta.persistence.*;
import lombok.*;
import org.gridsuite.study.server.dto.CaseInfos;
import org.gridsuite.study.server.dto.NetworkInfos;
import org.gridsuite.study.server.dto.RootNetworkInfos;
import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity;
import org.gridsuite.study.server.repository.StudyEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

/**
* @author Le Saulnier Kevin <lesaulnier.kevin at rte-france.com>
Expand Down Expand Up @@ -71,4 +75,20 @@ public void addRootNetworkNodeInfo(RootNetworkNodeInfoEntity rootNetworkNodeInfo
rootNetworkNodeInfoEntity.setRootNetwork(this);
rootNetworkNodeInfos.add(rootNetworkNodeInfoEntity);
}

public RootNetworkInfos toDto() {
RootNetworkInfos.RootNetworkInfosBuilder rootNetworkInfosBuilder = RootNetworkInfos.builder();
rootNetworkInfosBuilder.id(this.id)
.networkInfos(new NetworkInfos(this.networkUuid, this.networkId))
.importParameters(this.importParameters)
.caseInfos(new CaseInfos(this.caseUuid, this.caseName, this.caseFormat))
.reportUuid(this.reportUuid)
.build();

if (this.rootNetworkNodeInfos != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to initialize with empty list et remove test
private List<RootNetworkNodeInfoEntity> rootNetworkNodeInfos = new ArrayList<>();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to do it but it's breaking tests, causing NPE when calling "addRootNetworkNodeInfo"

rootNetworkInfosBuilder.rootNetworkNodeInfos(this.rootNetworkNodeInfos.stream().map(RootNetworkNodeInfoEntity::toDto).collect(Collectors.toList()));
}

return rootNetworkInfosBuilder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public interface RootNetworkRepository extends JpaRepository<RootNetworkEntity,

@EntityGraph(attributePaths = {"importParameters"}, type = EntityGraph.EntityGraphType.LOAD)
Optional<RootNetworkEntity> findWithImportParametersById(UUID rootNetworkUuid);

@EntityGraph(attributePaths = {"rootNetworkNodeInfos"}, type = EntityGraph.EntityGraphType.LOAD)
Optional<RootNetworkEntity> findWithRootNetworkNodeInfosById(UUID rootNetworkUuid);

boolean existsByIdAndStudyId(UUID studyUuid, UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,18 @@ public class LoadFlowService extends AbstractComputationService {
private static final String PARAMETERS_URI = "/parameters/{parametersUuid}";
private final ObjectMapper objectMapper;
private final RestTemplate restTemplate;
private final NetworkModificationTreeService networkModificationTreeService;
private final RootNetworkService rootNetworkService;
private String loadFlowServerBaseUri;

@Autowired
public LoadFlowService(RemoteServicesProperties remoteServicesProperties,
NetworkModificationTreeService networkModificationTreeService,
ObjectMapper objectMapper,
RestTemplate restTemplate,
RootNetworkService rootNetworkService) {
RestTemplate restTemplate) {
this.loadFlowServerBaseUri = remoteServicesProperties.getServiceUri("loadflow-server");
this.networkModificationTreeService = networkModificationTreeService;
this.objectMapper = objectMapper;
this.restTemplate = restTemplate;
this.rootNetworkService = rootNetworkService;
}

public UUID runLoadFlow(UUID nodeUuid, UUID rootNetworkUuid, UUID parametersUuid, UUID reportUuid, String userId, Float limitReduction) {
UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid);
String variantId = getVariantId(nodeUuid, rootNetworkUuid);

public UUID runLoadFlow(UUID nodeUuid, UUID rootNetworkUuid, UUID networkUuid, String variantId, UUID parametersUuid, UUID reportUuid, String userId, Float limitReduction) {
String receiver;
try {
receiver = URLEncoder.encode(objectMapper.writeValueAsString(new NodeReceiver(nodeUuid, rootNetworkUuid)), StandardCharsets.UTF_8);
Expand Down Expand Up @@ -121,9 +112,8 @@ public Integer getLoadFlowResultsCount() {
return restTemplate.getForObject(loadFlowServerBaseUri + path, Integer.class);
}

public String getLoadFlowResultOrStatus(UUID nodeUuid, UUID rootNetworkUuid, String filters, Sort sort, String suffix) {
public String getLoadFlowResultOrStatus(UUID resultUuid, String filters, Sort sort, String suffix) {
String result;
UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.LOAD_FLOW);

if (resultUuid == null) {
return null;
Expand All @@ -149,20 +139,19 @@ public String getLoadFlowResultOrStatus(UUID nodeUuid, UUID rootNetworkUuid, Str
return result;
}

public String getLoadFlowResult(UUID nodeUuid, UUID rootNetworkUuid, String filters, Sort sort) {
return getLoadFlowResultOrStatus(nodeUuid, rootNetworkUuid, filters, sort, "");
public String getLoadFlowResult(UUID resultUuid, String filters, Sort sort) {
return getLoadFlowResultOrStatus(resultUuid, filters, sort, "");
}

public String getLoadFlowStatus(UUID nodeUuid, UUID rootNetworkUuid) {
return getLoadFlowResultOrStatus(nodeUuid, rootNetworkUuid, null, null, "/status");
public String getLoadFlowStatus(UUID resultUuid) {
return getLoadFlowResultOrStatus(resultUuid, null, null, "/status");
}

public void stopLoadFlow(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId) {
public void stopLoadFlow(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, UUID resultUuid, String userId) {
Objects.requireNonNull(studyUuid);
Objects.requireNonNull(nodeUuid);
Objects.requireNonNull(userId);

UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.LOAD_FLOW);
if (resultUuid == null) {
return;
}
Expand Down Expand Up @@ -194,24 +183,19 @@ public void invalidateLoadFlowStatus(List<UUID> uuids) {
}
}

private String getVariantId(UUID nodeUuid, UUID rootNetworkUuid) {
return networkModificationTreeService.getVariantId(nodeUuid, rootNetworkUuid);
}

public void setLoadFlowServerBaseUri(String loadFlowServerBaseUri) {
this.loadFlowServerBaseUri = loadFlowServerBaseUri;
}

public void assertLoadFlowNotRunning(UUID nodeUuid, UUID rootNetworkUuid) {
String scs = getLoadFlowStatus(nodeUuid, rootNetworkUuid);
public void assertLoadFlowNotRunning(UUID resultUuid) {
String scs = getLoadFlowStatus(resultUuid);
if (LoadFlowStatus.RUNNING.name().equals(scs)) {
throw new StudyException(LOADFLOW_RUNNING);
}
}

public List<LimitViolationInfos> getLimitViolations(UUID nodeUuid, UUID rootNetworkUuid, String filters, String globalFilters, Sort sort, UUID networkUuid, String variantId) {
public List<LimitViolationInfos> getLimitViolations(UUID resultUuid, String filters, String globalFilters, Sort sort, UUID networkUuid, String variantId) {
List<LimitViolationInfos> result = new ArrayList<>();
UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.LOAD_FLOW);

if (resultUuid != null) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(DELIMITER + LOADFLOW_API_VERSION + "/results/{resultUuid}/limit-violations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,15 +635,6 @@ public List<NodeEntity> getAllNodes(UUID studyUuid) {
return nodesRepository.findAllByStudyId(studyUuid);
}

public UUID getComputationResultUuid(UUID nodeUuid, UUID rootNetworkUuid, ComputationType computationType) {
Optional<NodeEntity> nodeEntity = nodesRepository.findById(nodeUuid);
if (nodeEntity.isEmpty() || nodeEntity.get().getType().equals(NodeType.ROOT)) {
return null;
}

return rootNetworkNodeInfoService.getComputationResultUuid(nodeUuid, rootNetworkUuid, computationType);
}

private UUID getModificationReportUuid(UUID nodeUuid, UUID rootNetworkUuid, UUID nodeToBuildUuid) {
return self.getModificationReports(nodeToBuildUuid, rootNetworkUuid).getOrDefault(nodeUuid, UUID.randomUUID());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.apache.commons.lang3.StringUtils;
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.StudyException;
import org.gridsuite.study.server.dto.ComputationType;
import org.gridsuite.study.server.dto.NodeReceiver;
import org.gridsuite.study.server.dto.nonevacuatedenergy.NonEvacuatedEnergyContingencies;
import org.gridsuite.study.server.dto.nonevacuatedenergy.NonEvacuatedEnergyGeneratorCappingsByType;
Expand Down Expand Up @@ -75,15 +74,11 @@ public class NonEvacuatedEnergyService {

private final ObjectMapper objectMapper;

private final NetworkModificationTreeService networkModificationTreeService;

@Autowired
NonEvacuatedEnergyService(RemoteServicesProperties remoteServicesProperties,
NetworkModificationTreeService networkModificationTreeService,
ObjectMapper objectMapper,
RestTemplate restTemplate) {
this.sensitivityAnalysisServerBaseUri = remoteServicesProperties.getServiceUri("sensitivity-analysis-server");
this.networkModificationTreeService = networkModificationTreeService;
this.objectMapper = objectMapper;
this.restTemplate = restTemplate;
}
Expand All @@ -92,8 +87,8 @@ public void setSensitivityAnalysisServerBaseUri(String sensitivityAnalysisServer
this.sensitivityAnalysisServerBaseUri = sensitivityAnalysisServerBaseUri + DELIMITER;
}

public void assertNonEvacuatedEnergyNotRunning(UUID nodeUuid, UUID rootNetworkUuid) {
String nonEvacuatedEnergyStatus = getNonEvacuatedEnergyStatus(nodeUuid, rootNetworkUuid);
public void assertNonEvacuatedEnergyNotRunning(UUID resultUuid) {
String nonEvacuatedEnergyStatus = getNonEvacuatedEnergyStatus(resultUuid);
if (NonEvacuatedEnergyStatus.RUNNING.name().equals(nonEvacuatedEnergyStatus)) {
throw new StudyException(NON_EVACUATED_ENERGY_RUNNING);
}
Expand Down Expand Up @@ -139,9 +134,8 @@ public UUID runNonEvacuatedEnergy(UUID nodeUuid, UUID rootNetworkUuid, UUID netw
return restTemplate.exchange(sensitivityAnalysisServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody();
}

public String getNonEvacuatedEnergyResult(UUID nodeUuid, UUID rootNetworkUuid) {
public String getNonEvacuatedEnergyResult(UUID resultUuid) {
String result;
UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.NON_EVACUATED_ENERGY_ANALYSIS);
if (resultUuid == null) {
return null;
}
Expand All @@ -162,9 +156,8 @@ public String getNonEvacuatedEnergyResult(UUID nodeUuid, UUID rootNetworkUuid) {
return result;
}

public String getNonEvacuatedEnergyStatus(UUID nodeUuid, UUID rootNetworkUuid) {
public String getNonEvacuatedEnergyStatus(UUID resultUuid) {
String result;
UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.NON_EVACUATED_ENERGY_ANALYSIS);

if (resultUuid == null) {
return null;
Expand All @@ -183,11 +176,10 @@ public String getNonEvacuatedEnergyStatus(UUID nodeUuid, UUID rootNetworkUuid) {
return result;
}

public void stopNonEvacuatedEnergy(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId) {
public void stopNonEvacuatedEnergy(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, UUID resultUuid, String userId) {
Objects.requireNonNull(studyUuid);
Objects.requireNonNull(nodeUuid);

UUID resultUuid = networkModificationTreeService.getComputationResultUuid(nodeUuid, rootNetworkUuid, ComputationType.NON_EVACUATED_ENERGY_ANALYSIS);
if (resultUuid == null) {
return;
}
Expand Down
Loading
Loading