Skip to content

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

Open
thangqp wants to merge 2 commits intomainfrom
ds_move_params_to_computing_server
Open

Adaptation to moving Dynamic Simulation Params to Dynamic Simulation server#16
thangqp wants to merge 2 commits intomainfrom
ds_move_params_to_computing_server

Conversation

@thangqp
Copy link
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

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Controller Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/controller/DynamicMarginCalculationController.java
Removed @RequestParam provider and @RequestBody dynamicSimulationParametersJson parameters, replacing them with @RequestParam dynamicSimulationParametersUuid UUID parameter.
Service Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/ParametersService.java, src/main/java/org/gridsuite/dynamicmargincalculation/server/service/DynamicMarginCalculationWorkerService.java
Updated createRunContext method signature to accept UUID dynamicSimulationParametersUuid instead of provider and dynamicSimulationParametersJson; simplified provider selection logic to derive from run context parameters rather than explicit parameter.
Client Layer
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/client/DynamicSimulationClient.java
Changed getParametersValues from HTTP POST with JSON body to HTTP GET with UUID in path; modified method signature to accept UUID dynamicSimulationParametersUuid instead of JSON string.
Domain Models
src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationRunContext.java, src/main/java/org/gridsuite/dynamicmargincalculation/server/service/contexts/DynamicMarginCalculationResultContext.java
Replaced dynamicSimulationParametersJson field with dynamicSimulationParametersUuid (type changed from String to UUID); updated message header handling to pass UUID reference instead of compressed JSON.
Test Updates
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
Updated mock expectations and test requests to use dynamicSimulationParametersUuid request parameter; changed WireMock stubbing from POST to GET; removed JSON body content and Content-Type matching.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 accurately summarizes the main change: adapting communication to use Dynamic Simulation parameter UUIDs instead of JSON payloads, consistent with the server-to-server migration described throughout the changeset.
Description check ✅ Passed The pull request description accurately describes the changeset: replacing DS Params JSON with DS Params UUID for inter-server communication and removing the provider parameter.

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

@sonarqubecloud
Copy link

Copy link

@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

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.

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.

1 participant