Skip to content

Adaptation to moving Dynamic Simulation Params to Dynamic Simulation server#16

Merged
thangqp merged 4 commits intomainfrom
ds_move_params_to_computing_server
Apr 2, 2026
Merged

Adaptation to moving Dynamic Simulation Params to Dynamic Simulation server#16
thangqp merged 4 commits intomainfrom
ds_move_params_to_computing_server

Conversation

@thangqp
Copy link
Copy Markdown
Collaborator

@thangqp thangqp commented Mar 19, 2026

PR Summary

  • Communicating between servers by DS Params Uuid instead of DS Params Json
  • Remove provider from run request's params

Adaptation following to the related PR: gridsuite/dynamic-simulation-server#167

thangqp added 2 commits March 19, 2026 09:07
…server

Signed-off-by: Thang PHAM <phamthang37@gmail.com>
Signed-off-by: Thang PHAM <phamthang37@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Controller 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

Cohort / File(s) Summary
Controller Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java
Replaced provider request param and dynamicSimulationParametersJson request body with a single @RequestParam dynamicSimulationParametersUuid (UUID). Changed run(...) signature and invalidateStatus(...) return type to ResponseEntity<Void> (removed 404 behavior).
Service Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java, src/main/java/org/gridsuite/dynamicmargincalculation/server/service/DynamicMarginCalculationWorkerService.java
createRunContext(...) signature updated to accept UUID dynamicSimulationParametersUuid and to set it on the run context; provider resolution simplified to derive from run context parameters. WorkerService.preRun now calls getParametersValues with the UUID from run context.
Client Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClient.java
getParametersValues signature changed to accept UUID dynamicSimulationParametersUuid; HTTP call changed from POST with JSON body to GET on /{dynamicSimulationParametersUuid}/values, returning deserialized DynamicSimulationParametersValues.
Run / Result Contexts
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationRunContext.java, src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.java
Replaced dynamicSimulationParametersJson (String) with dynamicSimulationParametersUuid (UUID) in run context; result context header handling changed to read/emit UUID header instead of compressed JSON; removed GZip usage.
Tests
src/test/java/.../DynamicMarginCalculationControllerIEEE14Test.java, src/test/java/.../DynamicMarginCalculationControllerTest.java, src/test/java/.../DynamicSimulationClientTest.java
Updated tests to pass dynamicSimulationParametersUuid param and mock getParametersValues with the UUID; WireMock stubs changed from POST to GET and path includes UUID; removed JSON request bodies and Content-Type assertions.

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
Loading
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adapting to moving Dynamic Simulation parameters to the Dynamic Simulation server, which is the central theme of the refactoring across all modified files.
Description check ✅ Passed The description is directly related to the changeset, covering the two key aspects: communicating by UUID instead of JSON and removing provider from request parameters.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 | 🟠 Major

Avoid breaking the existing v1 run API in place.

Line 64 makes dynamicSimulationParametersUuid mandatory and removes the legacy body input on the same /v1/networks/{networkUuid}/run route. 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 using StringUtils.defaultIfBlank() for more robust provider fallback.

Optional.ofNullable() handles null but not empty or blank strings. If getProvider() returns an empty string (which the entity allows per DynamicMarginCalculationParametersEntity's assignAttributes), it won't fall back to defaultProvider and 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e3805d and b062ea7.

📒 Files selected for processing (9)
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/service/DynamicMarginCalculationWorkerService.java
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClient.java
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.java
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationRunContext.java
  • src/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerIEEE14Test.java
  • src/test/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationControllerTest.java
  • src/test/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClientTest.java

Comment on lines 73 to +77
// 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 to NOT_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

📥 Commits

Reviewing files that changed from the base of the PR and between b062ea7 and 89ab554.

📒 Files selected for processing (2)
  • src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java
  • src/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,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Suggested change
@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>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@thangqp thangqp merged commit c7ccf9a into main Apr 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants