refactor computations parameters#996
Conversation
Signed-off-by: Abdelsalem <abdelsalem.hedhili@rte-france.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR consolidates computation parameter handling by introducing a unified ChangesComputation Parameter Consolidation
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@src/main/java/org/gridsuite/study/server/service/ComputationParametersService.java`:
- Around line 210-211: The call to userAdminService.getUserProfile when
computing UserProfileInfos can throw and currently will abort the method instead
of falling back; wrap the lookup in a try-catch around the invocation of
userAdminService.getUserProfile and on any exception set userProfileInfos to
null (and optionally log the exception) so profileParameterId computed from
profileParameterGetter remains null and the existing default/create-update
fallback path using parameters continues to execute; update the block where
UserProfileInfos, userAdminService.getUserProfile, profileParameterGetter and
profileParameterId are used to implement this safe-lookup behavior.
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2831-2845: The call to setComputationParameters for dynamic
simulation parameters must also invalidate downstream Dynamic Margin Calculation
(DMC) results and emit its status update; modify the invocation that currently
passes List.of(this::invalidateDynamicSimulationStatusOnAllNodes,
this::invalidateDynamicSecurityAnalysisStatusOnAllNodes) and the two
notification types (NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS) to also
include the DMC invalidation callback (e.g.,
this::invalidateDynamicMarginCalculationStatusOnAllNodes) and the DMC
notification constant (e.g.,
NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS); apply the
same change to the other setComputationParameters call that handles dynamic
security analysis parameters so both parameter setters clear and notify Dynamic
Margin Calculation status via the appropriate invalidate method and notification
type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 79fabab0-4687-4ad6-875f-6aa3f15ebd47
📒 Files selected for processing (15)
src/main/java/org/gridsuite/study/server/dto/computation/ComputationsParameters.javasrc/main/java/org/gridsuite/study/server/service/ComputationParametersService.javasrc/main/java/org/gridsuite/study/server/service/ConsumerService.javasrc/main/java/org/gridsuite/study/server/service/LoadFlowService.javasrc/main/java/org/gridsuite/study/server/service/PccMinService.javasrc/main/java/org/gridsuite/study/server/service/SecurityAnalysisService.javasrc/main/java/org/gridsuite/study/server/service/SensitivityAnalysisService.javasrc/main/java/org/gridsuite/study/server/service/StateEstimationService.javasrc/main/java/org/gridsuite/study/server/service/StudyService.javasrc/main/java/org/gridsuite/study/server/service/VoltageInitService.javasrc/main/java/org/gridsuite/study/server/service/common/ComputationParameters.javasrc/main/java/org/gridsuite/study/server/service/dynamicmargincalculation/DynamicMarginCalculationService.javasrc/main/java/org/gridsuite/study/server/service/dynamicsecurityanalysis/DynamicSecurityAnalysisService.javasrc/main/java/org/gridsuite/study/server/service/dynamicsimulation/DynamicSimulationService.javasrc/main/java/org/gridsuite/study/server/service/shortcircuit/ShortCircuitService.java
| UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null; | ||
| UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos); |
There was a problem hiding this comment.
Handle user-profile lookup failures before fallback.
Line 210 calls an external service (userAdminService.getUserProfile) without a guard. If it throws, the method exits instead of falling back to default/create-update behavior.
💡 Proposed fix
- UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null;
+ UserProfileInfos userProfileInfos = null;
+ if (parameters == null) {
+ try {
+ userProfileInfos = userAdminService.getUserProfile(userId);
+ } catch (Exception e) {
+ userProfileIssue = true;
+ LOGGER.error("Could not retrieve user/profile '{}'. Using default parameters", userId, e);
+ }
+ }
UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| UserProfileInfos userProfileInfos = parameters == null ? userAdminService.getUserProfile(userId) : null; | |
| UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos); | |
| UserProfileInfos userProfileInfos = null; | |
| if (parameters == null) { | |
| try { | |
| userProfileInfos = userAdminService.getUserProfile(userId); | |
| } catch (Exception e) { | |
| userProfileIssue = true; | |
| LOGGER.error("Could not retrieve user/profile '{}'. Using default parameters", userId, e); | |
| } | |
| } | |
| UUID profileParameterId = userProfileInfos == null ? null : profileParameterGetter.apply(userProfileInfos); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/main/java/org/gridsuite/study/server/service/ComputationParametersService.java`
around lines 210 - 211, The call to userAdminService.getUserProfile when
computing UserProfileInfos can throw and currently will abort the method instead
of falling back; wrap the lookup in a try-catch around the invocation of
userAdminService.getUserProfile and on any exception set userProfileInfos to
null (and optionally log the exception) so profileParameterId computed from
profileParameterGetter remains null and the existing default/create-update
fallback path using parameters continues to execute; update the block where
UserProfileInfos, userAdminService.getUserProfile, profileParameterGetter and
profileParameterId are used to implement this safe-lookup behavior.
| return setComputationParameters( | ||
| studyUuid, | ||
| dsParameter, | ||
| userId, | ||
| StudyEntity::getDynamicSimulationParametersUuid, | ||
| StudyEntity::setDynamicSimulationParametersUuid, | ||
| UserProfileInfos::getDynamicSimulationParameterId, | ||
| dynamicSimulationService, | ||
| dynamicSimulationService::createParameters, | ||
| dynamicSimulationService::updateParameters, | ||
| DYNAMIC_SIMULATION, | ||
| List.of(this::invalidateDynamicSimulationStatusOnAllNodes, this::invalidateDynamicSecurityAnalysisStatusOnAllNodes), | ||
| NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS, | ||
| NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS | ||
| ); |
There was a problem hiding this comment.
Invalidate dynamic margin calculation when its upstream dynamic parameters change.
handleDynamicMarginCalculationRequest(...) reads both the dynamic simulation and dynamic security analysis parameter UUIDs, but neither setter invalidates existing dynamic margin calculation results or emits its status update. After either parameter changes, stale DMC results can still appear valid in the UI.
Proposed fix
public boolean setDynamicSimulationParameters(UUID studyUuid, String dsParameter, String userId) {
return setComputationParameters(
studyUuid,
dsParameter,
userId,
StudyEntity::getDynamicSimulationParametersUuid,
StudyEntity::setDynamicSimulationParametersUuid,
UserProfileInfos::getDynamicSimulationParameterId,
dynamicSimulationService,
dynamicSimulationService::createParameters,
dynamicSimulationService::updateParameters,
DYNAMIC_SIMULATION,
- List.of(this::invalidateDynamicSimulationStatusOnAllNodes, this::invalidateDynamicSecurityAnalysisStatusOnAllNodes),
+ List.of(
+ this::invalidateDynamicSimulationStatusOnAllNodes,
+ this::invalidateDynamicSecurityAnalysisStatusOnAllNodes,
+ this::invalidateDynamicMarginCalculationStatusOnAllNodes
+ ),
NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
- NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS
+ NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS,
+ NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS
);
} public boolean setDynamicSecurityAnalysisParameters(UUID studyUuid, String dsaParameter, String userId) {
return setComputationParameters(
studyUuid,
dsaParameter,
userId,
StudyEntity::getDynamicSecurityAnalysisParametersUuid,
StudyEntity::setDynamicSecurityAnalysisParametersUuid,
UserProfileInfos::getDynamicSecurityAnalysisParameterId,
dynamicSecurityAnalysisService,
dynamicSecurityAnalysisService::createParameters,
dynamicSecurityAnalysisService::updateParameters,
DYNAMIC_SECURITY_ANALYSIS,
- List.of(this::invalidateDynamicSecurityAnalysisStatusOnAllNodes),
- NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS
+ List.of(
+ this::invalidateDynamicSecurityAnalysisStatusOnAllNodes,
+ this::invalidateDynamicMarginCalculationStatusOnAllNodes
+ ),
+ NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS,
+ NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS
);
}Also applies to: 2959-2972
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 2831 - 2845, The call to setComputationParameters for dynamic simulation
parameters must also invalidate downstream Dynamic Margin Calculation (DMC)
results and emit its status update; modify the invocation that currently passes
List.of(this::invalidateDynamicSimulationStatusOnAllNodes,
this::invalidateDynamicSecurityAnalysisStatusOnAllNodes) and the two
notification types (NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS,
NotificationService.UPDATE_TYPE_DYNAMIC_SECURITY_ANALYSIS_STATUS) to also
include the DMC invalidation callback (e.g.,
this::invalidateDynamicMarginCalculationStatusOnAllNodes) and the DMC
notification constant (e.g.,
NotificationService.UPDATE_TYPE_DYNAMIC_MARGIN_CALCULATION_STATUS); apply the
same change to the other setComputationParameters call that handles dynamic
security analysis parameters so both parameter setters clear and notify Dynamic
Margin Calculation status via the appropriate invalidate method and notification
type.
No description provided.