Skip to content

Lazy loading for operational limits groups #501

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

Merged
merged 45 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
be3673c
lazy loading for operational limits groups
EtienneLt Jan 24, 2025
ecff3ed
add one test
EtienneLt Feb 7, 2025
8260202
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Feb 28, 2025
f95cb54
clean code
EtienneLt Feb 28, 2025
e7743bf
add tests
EtienneLt Mar 10, 2025
4eb105b
more tests
EtienneLt Mar 10, 2025
5a5e619
fix
EtienneLt Mar 11, 2025
fdf260c
fix
EtienneLt Mar 14, 2025
df34543
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Mar 27, 2025
184d17b
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Apr 7, 2025
048c685
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Apr 23, 2025
c4f8453
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt May 14, 2025
d6ad7d7
review first part
EtienneLt May 15, 2025
b5b47c1
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt May 15, 2025
1f16582
review
EtienneLt May 15, 2025
4e2071d
try to fix
EtienneLt Jun 2, 2025
e735e98
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Jun 2, 2025
cdcff7f
add test and fix
EtienneLt Jun 2, 2025
4eb0322
add one test
EtienneLt Jun 2, 2025
eb45003
review
EtienneLt Jun 5, 2025
47a9069
fix test
EtienneLt Jun 5, 2025
e9298ce
change to record
EtienneLt Jun 5, 2025
3b0c96b
fix
EtienneLt Jun 6, 2025
8b4e250
fix
EtienneLt Jun 6, 2025
658f601
add tests
EtienneLt Jun 6, 2025
9540e4a
add tests
EtienneLt Jun 6, 2025
cb68741
fix
EtienneLt Jun 6, 2025
66d1fac
fix
EtienneLt Jun 11, 2025
69e3915
some review
EtienneLt Jun 11, 2025
8d7f4ca
fix
EtienneLt Jun 11, 2025
a3d7445
add commentaries for clarifications
EtienneLt Jun 20, 2025
b3be375
fix
EtienneLt Jun 20, 2025
99c9487
review
EtienneLt Jun 25, 2025
d449536
remove deserializer
EtienneLt Jun 25, 2025
35f00d3
fix
EtienneLt Jun 25, 2025
4812ac2
fix
EtienneLt Jun 25, 2025
b080754
checkstyle
EtienneLt Jun 25, 2025
2d0d549
Serde with jackson annotations
antoinebhs Jun 25, 2025
393c25d
remove operationalLimitsGroupIdentifier
EtienneLt Jun 25, 2025
cd8da73
fix logs on counting limits groups
EtienneLt Jun 25, 2025
8bb5130
review
EtienneLt Jun 26, 2025
acdf8ed
review
EtienneLt Jun 26, 2025
8945896
review
EtienneLt Jun 26, 2025
3c6c418
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Jun 26, 2025
bad85b8
Merge branch 'main' into lazy-loading-for-operational-limits-group
EtienneLt Jun 26, 2025
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 @@ -883,4 +883,22 @@ public Map<String, ExtensionAttributes> getAllExtensionsAttributesByIdentifiable
delegate.loadAllExtensionsAttributesByResourceType(networkUuid, variantNum, resourceType);
return delegate.getAllExtensionsAttributesByIdentifiableId(networkUuid, variantNum, resourceType, id);
}

@Override
public Optional<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, String operationalLimitGroupId, int side) {
delegate.loadAllOperationalLimitsGroupAttributesByResourceType(networkUuid, variantNum, resourceType);
return delegate.getOperationalLimitsGroupAttributes(networkUuid, variantNum, resourceType, branchId, operationalLimitGroupId, side);
}

@Override
public Optional<OperationalLimitsGroupAttributes> getSelectedOperationalLimitsGroupAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, String operationalLimitGroupId, int side) {
delegate.loadAllSelectedOperationalLimitsGroupAttributesByResourceType(networkUuid, variantNum, resourceType);
return delegate.getSelectedOperationalLimitsGroupAttributes(networkUuid, variantNum, resourceType, branchId, operationalLimitGroupId, side);
}

@Override
public List<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributesForBranchSide(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, int side) {
delegate.loadAllOperationalLimitsGroupAttributesByResourceType(networkUuid, variantNum, resourceType);
return delegate.getOperationalLimitsGroupAttributesForBranchSide(networkUuid, variantNum, resourceType, branchId, side);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/
package com.powsybl.network.store.client;

import com.powsybl.network.store.model.Attributes;
import com.powsybl.network.store.model.ExtensionAttributes;
import com.powsybl.network.store.model.IdentifiableAttributes;
import com.powsybl.network.store.model.Resource;
import com.powsybl.network.store.model.*;
import org.springframework.core.ParameterizedTypeReference;

import java.util.List;
Expand All @@ -31,6 +28,12 @@ public interface RestClient {
*/
Optional<ExtensionAttributes> getOneExtensionAttributes(String url, Object... uriVariables);

/**
* Retrieves one operational limit group attributes from the server.
* @return {@link OperationalLimitsGroupAttributes} which is a subset of a branch resource there is a list each side of a branch.
*/
Optional<OperationalLimitsGroupAttributes> getOneOperationalLimitsGroupAttributes(String url, Object... uriVariables);

<T extends IdentifiableAttributes> List<Resource<T>> getAll(String target, String url, Object... uriVariables);

<T extends Attributes> void updateAll(String url, List<Resource<T>> resources, Object... uriVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public Optional<ExtensionAttributes> getOneExtensionAttributes(String url, Objec
}, uriVariables);
}

@Override
public Optional<OperationalLimitsGroupAttributes> getOneOperationalLimitsGroupAttributes(String url, Object... uriVariables) {
return getOneDocument(url, new ParameterizedTypeReference<OperationalLimitsGroupAttributesTopLevelDocument>() {
}, uriVariables);
}

private <T, D extends AbstractTopLevelDocument<T>> Optional<T> getOneDocument(String url, ParameterizedTypeReference<D> parameterizedTypeReference, Object... uriVariables) {
ResponseEntity<D> response = getDocument(url, parameterizedTypeReference, uriVariables);
if (response.getStatusCode() == HttpStatus.OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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

/**
Expand Down Expand Up @@ -168,6 +169,39 @@ private static Map<String, ExtensionAttributes> filterRawExtensionAttributes(Map
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private Optional<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributes(String urlTemplate, Object... uriVariables) {
logGetOperationalLimitsGroupAttributesUrl(urlTemplate, uriVariables);
Stopwatch stopwatch = Stopwatch.createStarted();
Optional<OperationalLimitsGroupAttributes> operationalLimitsGroupAttributes = restClient.getOneOperationalLimitsGroupAttributes(urlTemplate, uriVariables);
stopwatch.stop();
logGetOperationalLimitsGroupAttributesTime(operationalLimitsGroupAttributes.isPresent() ? 1 : 0, stopwatch.elapsed(TimeUnit.MILLISECONDS));

return operationalLimitsGroupAttributes;
}

private List<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributesForBranch(String urlTemplate, Object... uriVariables) {
logGetOperationalLimitsGroupAttributesUrl(urlTemplate, uriVariables);
Stopwatch stopwatch = Stopwatch.createStarted();
List<OperationalLimitsGroupAttributes> operationalLimitsGroupAttributesList = restClient.get(urlTemplate, new ParameterizedTypeReference<>() { }, uriVariables);
stopwatch.stop();
logGetOperationalLimitsGroupAttributesTime(operationalLimitsGroupAttributesList.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));

return operationalLimitsGroupAttributesList;
}

private Map<String, Map<Integer, Map<String, OperationalLimitsGroupAttributes>>> getOperationalLimitsGroupAttributesNestedMap(String urlTemplate, Object... uriVariables) {
logGetOperationalLimitsGroupAttributesUrl(urlTemplate, uriVariables);
Stopwatch stopwatch = Stopwatch.createStarted();
Map<String, Map<Integer, Map<String, OperationalLimitsGroupAttributes>>> operationalLimitsGroupAttributes = restClient.get(urlTemplate, new ParameterizedTypeReference<>() { }, uriVariables);
stopwatch.stop();
AtomicLong loadedAttributesCount = new AtomicLong();
operationalLimitsGroupAttributes.values().forEach(map1 ->
map1.values().forEach(map2 -> loadedAttributesCount.addAndGet(map2.size())));
logGetOperationalLimitsGroupAttributesTime(loadedAttributesCount.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS));

return operationalLimitsGroupAttributes;
}

private static void logGetExtensionAttributesUrl(String urlTemplate, Object... uriVariables) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Loading extension attributes {}", UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables));
Expand All @@ -182,6 +216,16 @@ private static void logGetExtensionAttributesTime(long loadedAttributesCount, lo
}
}

private static void logGetOperationalLimitsGroupAttributesUrl(String urlTemplate, Object... uriVariables) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Loading operational limits group attributes {}", UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables));
}
}

private static void logGetOperationalLimitsGroupAttributesTime(long loadedAttributesCount, long timeElapsed) {
LOGGER.info("{} operational limits group attributes loaded in {} ms", loadedAttributesCount, timeElapsed);
}

private <T extends IdentifiableAttributes> void updatePartition(String target, String url, AttributeFilter attributeFilter, List<Resource<T>> resources, Object[] uriVariables) {
if (attributeFilter == null) {
if (LOGGER.isInfoEnabled()) {
Expand Down Expand Up @@ -981,4 +1025,33 @@ public Map<String, Map<String, ExtensionAttributes>> getAllExtensionsAttributesB
public void removeExtensionAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String identifiableId, String extensionName) {
restClient.delete("/networks/{networkUuid}/{variantNum}/identifiables/{identifiableId}/extensions/{extensionName}", networkUuid, variantNum, identifiableId, extensionName);
}

@Override
public Optional<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, String operationalLimitsGroupId, int side) {
return getOperationalLimitsGroupAttributes("/networks/{networkUuid}/{variantNum}/branch/{branchId}/types/{resourceType}/operationalLimitsGroup/{operationalLimitsGroupId}/side/{side}",
networkUuid, variantNum, branchId, resourceType, operationalLimitsGroupId, side);
}

@Override
public Optional<OperationalLimitsGroupAttributes> getSelectedOperationalLimitsGroupAttributes(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, String operationalLimitsGroupId, int side) {
return getOperationalLimitsGroupAttributes(networkUuid, variantNum, resourceType, branchId, operationalLimitsGroupId, side);
}

@Override
public List<OperationalLimitsGroupAttributes> getOperationalLimitsGroupAttributesForBranchSide(UUID networkUuid, int variantNum, ResourceType resourceType, String branchId, int side) {
return getOperationalLimitsGroupAttributesForBranch("/networks/{networkUuid}/{variantNum}/branch/{branchId}/types/{resourceType}/side/{side}/operationalLimitsGroup",
networkUuid, variantNum, branchId, resourceType, side);
}

@Override
public Map<String, Map<Integer, Map<String, OperationalLimitsGroupAttributes>>> getAllOperationalLimitsGroupAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) {
return getOperationalLimitsGroupAttributesNestedMap("/networks/{networkUuid}/{variantNum}/branch/types/{resourceType}/operationalLimitsGroup",
networkUuid, variantNum, resourceType);
}

@Override
public Map<String, Map<Integer, Map<String, OperationalLimitsGroupAttributes>>> getAllSelectedOperationalLimitsGroupAttributesByResourceType(UUID networkUuid, int variantNum, ResourceType resourceType) {
return getOperationalLimitsGroupAttributesNestedMap("/networks/{networkUuid}/{variantNum}/branch/types/{resourceType}/operationalLimitsGroup/selected",
networkUuid, variantNum, resourceType);
}
}
Loading