Adaptation to moving Dynamic Simulation Params to Dynamic Simulation server#16
Adaptation to moving Dynamic Simulation Params to Dynamic Simulation server#16
Conversation
…server Signed-off-by: Thang PHAM <phamthang37@gmail.com>
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
📝 WalkthroughWalkthroughThis PR refactors dynamic simulation parameters handling throughout the application, shifting from passing JSON strings and provider headers to using UUID references. The change affects the controller's request interface, service layer method signatures, client HTTP communication, and domain model representations. Changes
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java (1)
57-67:⚠️ Potential issue | 🟠 MajorAvoid breaking the existing
v1run API in place.Line 64 makes
dynamicSimulationParametersUuidmandatory and removes the legacy body input on the same/v1/networks/{networkUuid}/runroute. Existing callers that still post the JSON payload will now fail with 400 even though the API version did not change. Please keep a compatibility shim for one release or expose this as a new versioned contract.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java` around lines 57 - 67, The run(...) controller method currently makes dynamicSimulationParametersUuid mandatory and removes the legacy JSON body, breaking existing callers; modify the DynamicMarginCalculationController.run method to accept both modes: make `@RequestParam`("dynamicSimulationParametersUuid") optional (required=false) and detect when it's absent to parse/validate the legacy request body (e.g., a DTO previously used) before proceeding, or provide a clear compatibility shim branch that maps the legacy body fields into the new parameter objects; ensure the method preserves the same route (/v1/networks/{networkUuid}/run) behavior and only returns 400 for truly invalid input, keeping backward compatibility for one release.
🧹 Nitpick comments (1)
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java (1)
100-102: Consider usingStringUtils.defaultIfBlank()for more robust provider fallback.
Optional.ofNullable()handlesnullbut not empty or blank strings. IfgetProvider()returns an empty string (which the entity allows perDynamicMarginCalculationParametersEntity'sassignAttributes), it won't fall back todefaultProviderand will fail the provider check at line 105.Proposed fix
// set provider for run context - String providerToUse = Optional.ofNullable(runContext.getParameters().getProvider()).orElse(defaultProvider); + String providerToUse = StringUtils.defaultIfBlank(runContext.getParameters().getProvider(), defaultProvider); runContext.setProvider(providerToUse);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java` around lines 100 - 102, The current fallback uses Optional.ofNullable(...) which doesn't treat empty or blank provider strings as missing; update the provider selection in ParametersService (the block where providerToUse is computed before runContext.setProvider) to use StringUtils.defaultIfBlank(runContext.getParameters().getProvider(), defaultProvider) so empty/blank values fall back to defaultProvider, and add the org.apache.commons.lang3.StringUtils import if missing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.java`:
- Around line 73-77: The code unconditionally reads
HEADER_DYNAMIC_SIMULATION_PARAMETERS_UUID and sets
runContext.setDynamicSimulationParametersUuid, which will break already-enqueued
messages that lack that header; add a backward-compatible fallback in
DynamicMarginCalculationResultContext: when getNonNullHeader(headers,
HEADER_DYNAMIC_SIMULATION_PARAMETERS_UUID) is missing or empty, attempt to
extract dynamicSimulationParametersUuid from the message payload (e.g., parse
the JSON body used by preRun for a "dynamicSimulationParametersUuid" field) and
only set runContext.setDynamicSimulationParametersUuid when found, otherwise
leave it null and log a warning for telemetry so older messages can still be
processed; keep getNonNullHeader and existing path as primary, but implement
this safe legacy-read path around UUID.fromString to avoid throwing for missing
headers.
---
Outside diff comments:
In
`@src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java`:
- Around line 57-67: The run(...) controller method currently makes
dynamicSimulationParametersUuid mandatory and removes the legacy JSON body,
breaking existing callers; modify the DynamicMarginCalculationController.run
method to accept both modes: make
`@RequestParam`("dynamicSimulationParametersUuid") optional (required=false) and
detect when it's absent to parse/validate the legacy request body (e.g., a DTO
previously used) before proceeding, or provide a clear compatibility shim branch
that maps the legacy body fields into the new parameter objects; ensure the
method preserves the same route (/v1/networks/{networkUuid}/run) behavior and
only returns 400 for truly invalid input, keeping backward compatibility for one
release.
---
Nitpick comments:
In
`@src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java`:
- Around line 100-102: The current fallback uses Optional.ofNullable(...) which
doesn't treat empty or blank provider strings as missing; update the provider
selection in ParametersService (the block where providerToUse is computed before
runContext.setProvider) to use
StringUtils.defaultIfBlank(runContext.getParameters().getProvider(),
defaultProvider) so empty/blank values fall back to defaultProvider, and add the
org.apache.commons.lang3.StringUtils import if missing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 67dfbfe1-593a-430b-9f6c-b47374ea2697
📒 Files selected for processing (9)
src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.javasrc/main/java/org/gridsuite/dynamicmargincalculation/server/service/DynamicMarginCalculationWorkerService.javasrc/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.javasrc/main/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClient.javasrc/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.javasrc/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationRunContext.javasrc/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerIEEE14Test.javasrc/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.javasrc/test/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClientTest.java
| // specific headers | ||
| UUID dynamicSecurityAnalysisParametersUuid = UUID.fromString(getNonNullHeader(headers, HEADER_DYNAMIC_SECURITY_ANALYSIS_PARAMETERS_UUID)); | ||
| runContext.setDynamicSecurityAnalysisParametersUuid(dynamicSecurityAnalysisParametersUuid); | ||
| // TODO : using directly uuid after moving dynamic simulation parameters to its server | ||
| String compressedJson = headers.get(HEADER_DYNAMIC_SIMULATION_PARAMETERS_JSON_UUID).toString(); | ||
| runContext.setDynamicSimulationParametersJson(GZipUtils.decompress(compressedJson)); | ||
| UUID dynamicSimulationParametersUuid = UUID.fromString(getNonNullHeader(headers, HEADER_DYNAMIC_SIMULATION_PARAMETERS_UUID)); | ||
| runContext.setDynamicSimulationParametersUuid(dynamicSimulationParametersUuid); |
There was a problem hiding this comment.
Keep a transition path for already-enqueued run messages.
Lines 76-77 assume every queued message now carries dynamicSimulationParametersUuid. Messages published by the previous version only carried the JSON payload, so after rollout those in-flight computations will fail before the worker even reaches preRun. Please either keep a temporary legacy read path or make draining the run queue a hard deploy prerequisite.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.java`
around lines 73 - 77, The code unconditionally reads
HEADER_DYNAMIC_SIMULATION_PARAMETERS_UUID and sets
runContext.setDynamicSimulationParametersUuid, which will break already-enqueued
messages that lack that header; add a backward-compatible fallback in
DynamicMarginCalculationResultContext: when getNonNullHeader(headers,
HEADER_DYNAMIC_SIMULATION_PARAMETERS_UUID) is missing or empty, attempt to
extract dynamicSimulationParametersUuid from the message payload (e.g., parse
the JSON body used by preRun for a "dynamicSimulationParametersUuid" field) and
only set runContext.setDynamicSimulationParametersUuid when found, otherwise
leave it null and log a warning for telemetry so older messages can still be
processed; keep getNonNullHeader and existing path as primary, but implement
this safe legacy-read path around UUID.fromString to avoid throwing for missing
headers.



PR Summary
providerfrom run request's paramsAdaptation following to the related PR: gridsuite/dynamic-simulation-server#167