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>
📝 WalkthroughWalkthroughController and service APIs were changed to pass a UUID reference for dynamic simulation parameters instead of a JSON payload and provider header; client HTTP calls switched from POST-with-body to GET-with-UUID-in-path; run/result contexts and tests updated to use the UUID field. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller
participant ParametersService
participant WorkerService
participant DynamicSimulationClient
Client->>Controller: POST /run?dynamicSimulationParametersUuid=<uuid>&...
Controller->>ParametersService: createRunContext(..., dynamicSimulationParametersUuid, ...)
ParametersService-->>Controller: RunContext (with dynamicSimulationParametersUuid)
Controller->>WorkerService: submit job / start run (RunContext)
WorkerService->>DynamicSimulationClient: getParametersValues(dynamicSimulationParametersUuid, networkUuid, variant)
DynamicSimulationClient->>DynamicSimulationClient: HTTP GET /{uuid}/values?networkUuid=...&variant=...
DynamicSimulationClient-->>WorkerService: DynamicSimulationParametersValues
WorkerService->>WorkerService: build dynamicModel, dynawoParameters, enrich RunContext
WorkerService-->>Controller: run started / job id
Controller-->>Client: 200 OK (no body) / job id
🚥 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.
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.java (1)
232-235: Assert that invalidating an unknown UUID does not create a row.Lines 232-235 only verify the 200 response. They would still pass if
updateStatus(...)accidentally upserted a missing result toNOT_DONE, which is the regression this PR is trying to avoid.Suggested test hardening
- // invalidate status for unknown result => 200 (same as delete) - mockMvc.perform(put("/v1/results/invalidate-status") - .param("resultUuid", UUID.randomUUID().toString())) - .andExpect(status().isOk()); + UUID unknownResultUuid = UUID.randomUUID(); + // invalidate status for unknown result => 200 (same as delete) + mockMvc.perform(put("/v1/results/invalidate-status") + .param("resultUuid", unknownResultUuid.toString())) + .andExpect(status().isOk()); + assertResultStatus(unknownResultUuid, null);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.java` around lines 232 - 235, The test only checks for a 200 response but must also assert that calling the invalidate-status endpoint with an unknown UUID does not create a new Result row; after performing the PUT to /v1/results/invalidate-status in DynamicMarginCalculationControllerTest, capture the random UUID used and verify via the repository used by the controller (e.g., ResultRepository or the DAO backing updateStatus(...)) that no entity exists for that UUID (or that repository.count() is unchanged) — update the test to fetch the repository bean, record pre-call state, perform mockMvc.perform(...), then assert repository.findById(randomUuid).isEmpty() (or assert count unchanged) to ensure no upsert occurred.
🤖 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/controller/DynamicMarginCalculationController.java`:
- Line 63: The controller method in DynamicMarginCalculationController currently
declares the dynamicSimulationParametersUuid parameter with `@RequestParam` (which
defaults to required=true) causing 400s when omitted; change the annotation on
the UUID parameter named dynamicSimulationParametersUuid to
`@RequestParam`(required = false) and ensure downstream code in ParametersService
or the handler method (the controller method referencing
dynamicSimulationParametersUuid) properly handles a null UUID as the optional
replacement for the old DS payload.
---
Nitpick comments:
In
`@src/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.java`:
- Around line 232-235: The test only checks for a 200 response but must also
assert that calling the invalidate-status endpoint with an unknown UUID does not
create a new Result row; after performing the PUT to
/v1/results/invalidate-status in DynamicMarginCalculationControllerTest, capture
the random UUID used and verify via the repository used by the controller (e.g.,
ResultRepository or the DAO backing updateStatus(...)) that no entity exists for
that UUID (or that repository.count() is unchanged) — update the test to fetch
the repository bean, record pre-call state, perform mockMvc.perform(...), then
assert repository.findById(randomUuid).isEmpty() (or assert count unchanged) to
ensure no upsert occurred.
🪄 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: 6aae3fb8-34f8-4b71-a038-3b41381745d9
📒 Files selected for processing (2)
src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.javasrc/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.java
| @RequestParam(name = REPORT_TYPE_HEADER, required = false, defaultValue = "DynamicMarginCalculation") String reportType, | ||
| @RequestParam(name = HEADER_PROVIDER, required = false) String provider, | ||
| @RequestParam(name = HEADER_DEBUG, required = false, defaultValue = "false") boolean debug, | ||
| @RequestParam(name = "dynamicSimulationParametersUuid") UUID dynamicSimulationParametersUuid, |
There was a problem hiding this comment.
dynamicSimulationParametersUuid became mandatory here.
Line 63 uses plain @RequestParam, which defaults to required=true. That means callers now get a 400 before ParametersService runs whenever this UUID is omitted. If this field is meant to remain the optional replacement for the old DS payload, mark it required = false.
Suggested fix
- `@RequestParam`(name = "dynamicSimulationParametersUuid") UUID dynamicSimulationParametersUuid,
+ `@RequestParam`(name = "dynamicSimulationParametersUuid", required = false) UUID dynamicSimulationParametersUuid,📝 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.
| @RequestParam(name = "dynamicSimulationParametersUuid") UUID dynamicSimulationParametersUuid, | |
| `@RequestParam`(name = "dynamicSimulationParametersUuid", required = false) UUID dynamicSimulationParametersUuid, |
🤖 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`
at line 63, The controller method in DynamicMarginCalculationController
currently declares the dynamicSimulationParametersUuid parameter with
`@RequestParam` (which defaults to required=true) causing 400s when omitted;
change the annotation on the UUID parameter named
dynamicSimulationParametersUuid to `@RequestParam`(required = false) and ensure
downstream code in ParametersService or the handler method (the controller
method referencing dynamicSimulationParametersUuid) properly handles a null UUID
as the optional replacement for the old DS payload.
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
|



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