Skip to content

Handle errors when getting modifications#61

Open
FranckLecuyer wants to merge 29 commits intomainfrom
handle_errors_when_getting_modifications
Open

Handle errors when getting modifications#61
FranckLecuyer wants to merge 29 commits intomainfrom
handle_errors_when_getting_modifications

Conversation

@FranckLecuyer
Copy link
Contributor

@FranckLecuyer FranckLecuyer commented Mar 4, 2026

PR Summary

Launch an security analysis process, using an existing config uuid

based on PR : #58
to be merged together with PR : gridsuite/network-modification-server#775

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
…onfig

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

# Conflicts:
#	monitor-commons/src/main/java/org/gridsuite/monitor/commons/SecurityAnalysisConfig.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/entities/SecurityAnalysisConfigEntity.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapper.java
#	monitor-server/src/main/resources/db/changelog/db.changelog-master.yaml
#	monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java
#	monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
…config_uuid

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

# Conflicts:
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Don't set startedAt and completedAt for skipped step

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Add process config id in the process execution entity

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds DTO NetworkModificationsWithMissingInfo and updates REST service, processing step, tests, and resources to return/consume this wrapper; processing now reports and fails when network composite modifications are missing before applying modifications.

Changes

Cohort / File(s) Summary
New DTO
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/dto/NetworkModificationsWithMissingInfo.java
Adds public record NetworkModificationsWithMissingInfo(List<ModificationInfos> networkModifications, List<UUID> missingCompositeModifications).
Service API
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java
getModifications return type changed to NetworkModificationsWithMissingInfo; endpoint path updated to network-modifications-with-missing-info; empty response now returns an empty wrapper.
Processing Step
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStep.java
Consumes NetworkModificationsWithMissingInfo; if missingCompositeModifications non-empty, creates an error report node (monitor.worker.server.modifications.error) with uuids, sets severity ERROR, then throws PowsyblException; otherwise proceeds with networkModifications().
Localization
monitor-worker-server/src/main/resources/org/gridsuite/monitor/worker/server/reports.properties
Adds key monitor.worker.server.modifications.error = Some network composite modifications are missing : ${uuids}.
Tests
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java, monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java
Tests updated to use NetworkModificationsWithMissingInfo, added cases for missing modifications and empty UUID lists, adjusted mocks and assertions to inspect wrapped fields.
Minor edits / Cleanup
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java, monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java, .../StepExecutionServiceTest.java
Whitespace/formatting and removal of startedAt/completedAt on skipped steps; small test verification additions.

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Apply as ApplyModificationsStep
    participant REST as NetworkModificationRestService
    participant Report as ReportService

    Client->>Apply: execute(context)
    Apply->>REST: getModifications(modificationUuids)
    REST-->>Apply: NetworkModificationsWithMissingInfo

    alt missingCompositeModifications non-empty
        Apply->>Report: createReportNode("monitor.worker.server.modifications.error", uuids)
        Report-->>Apply: reportNode
        Apply->>Apply: throw PowsyblException
        Apply-->>Client: Exception
    else no missing composites
        Apply->>Apply: applyModifications(networkModifications)
        Apply-->>Client: Success
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • antoinebhs
  • TheMaskedTurtle
  • klesaulnier

Poem

🐇 I wrapped the mods in neat little rows,
A missing UUID made my whiskers go,
I hopped to report with a thump and a cheer,
An error arose, the message was clear,
Then I munched a carrot and disappeared.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description mentions launching a security analysis process with existing config UUID and references related PRs, but does not clearly explain the actual changes in this PR regarding error handling for missing modifications. Clarify the description to explicitly explain that this PR adds error handling for missing composite modifications when fetching network modifications, and how it integrates with the referenced PRs.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Handle errors when getting modifications' directly reflects the main changes: adding error handling for missing composite modifications when retrieving network modifications, including null checks, exception throwing, and error reporting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

@FranckLecuyer FranckLecuyer changed the base branch from launch_process_using_config_uuid to main March 4, 2026 14:03
@FranckLecuyer FranckLecuyer changed the base branch from main to launch_process_using_config_uuid March 4, 2026 14:05
…config_uuid

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

# Conflicts:
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
…' into handle_errors_when_getting_modifications

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

# Conflicts:
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java
Base automatically changed from launch_process_using_config_uuid to main March 12, 2026 08:55
…tting_modifications

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

# Conflicts:
#	monitor-commons/src/main/java/org/gridsuite/monitor/commons/SecurityAnalysisConfig.java
#	monitor-commons/src/main/java/org/gridsuite/monitor/commons/steps/AbstractStepExecutor.java
#	monitor-commons/src/test/java/org/gridsuite/monitor/commons/steps/StepExecutorTest.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/ProcessExecutionMapper.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/mapper/SecurityAnalysisConfigMapper.java
#	monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java
#	monitor-server/src/main/resources/db/changelog/changesets/changelog_20260227T101113Z.xml
#	monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java
#	monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java
#	monitor-server/src/test/java/org/gridsuite/monitor/server/services/MonitorServiceTest.java
#	monitor-server/src/test/java/org/gridsuite/monitor/server/services/ProcessConfigServiceTest.java
#	monitor-worker-server/pom.xml
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStep.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStep.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/ActionsRestService.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestService.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/StepExecutionService.java
#	monitor-worker-server/src/main/resources/org/gridsuite/monitor/worker/server/reports.properties
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/securityanalysis/steps/SecurityAnalysisRunComputationStepTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/ActionsRestServiceTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisRestServiceTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/StepExecutionServiceTest.java
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
coderabbitai[bot]

This comment was marked as outdated.

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
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.

🧹 Nitpick comments (1)
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java (1)

102-119: Consider asserting the specific exception type.

The mocks are now properly set up (addressing previous feedback). However, the production code throws PowsyblException (as seen in ApplyModificationsStep.java line 94), but the test asserts RuntimeException.class. While this works because PowsyblException extends RuntimeException, using the specific type provides better test precision and ensures other runtime exceptions aren't inadvertently caught.

♻️ Proposed fix for more precise assertion
-        assertThrows(RuntimeException.class, () -> applyModificationsStep.execute(stepContext));
+        assertThrows(PowsyblException.class, () -> applyModificationsStep.execute(stepContext));

Add the import:

import com.powsybl.commons.PowsyblException;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java`
around lines 102 - 119, Change the test to assert the specific PowsyblException
instead of RuntimeException: in ApplyModificationsStepTest (method
executeApplyModificationsFailWhenModificationsAreMissing) replace
assertThrows(RuntimeException.class, ...) with
assertThrows(PowsyblException.class, ...) and add the import
com.powsybl.commons.PowsyblException; this aligns the test with the actual
exception thrown by ApplyModificationsStep (PowsyblException).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java`:
- Around line 102-119: Change the test to assert the specific PowsyblException
instead of RuntimeException: in ApplyModificationsStepTest (method
executeApplyModificationsFailWhenModificationsAreMissing) replace
assertThrows(RuntimeException.class, ...) with
assertThrows(PowsyblException.class, ...) and add the import
com.powsybl.commons.PowsyblException; this aligns the test with the actual
exception thrown by ApplyModificationsStep (PowsyblException).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9611a4fb-9959-4409-8826-b085c9b2002e

📥 Commits

Reviewing files that changed from the base of the PR and between ddc3801 and 60a59a3.

📒 Files selected for processing (1)
  • monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/processes/commons/steps/ApplyModificationsStepTest.java

coderabbitai[bot]

This comment was marked as outdated.

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
@FranckLecuyer FranckLecuyer force-pushed the handle_errors_when_getting_modifications branch from f84ea7c to a5fdbb7 Compare March 12, 2026 13:04
coderabbitai[bot]

This comment was marked as outdated.

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Copy link
Contributor

@antoinebhs antoinebhs left a comment

Choose a reason for hiding this comment

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

I'm not sure to understand why we need this complexity?
On main, we know the ID we want:
networkModificationRestService.getModifications(modificationIds);
and the ID we get List modificationInfos.getUuid()
Why can't we deduce the missing modifications ?

@@ -32,8 +32,6 @@ public void skipStep(ProcessStepExecutionContext<?> context, ProcessStep<?> step
.stepType(step.getType().getName())
.stepOrder(context.getStepOrder())
.status(StepStatus.SKIPPED)
.startedAt(context.getStartedAt())
.completedAt(Instant.now())
Copy link
Contributor

Choose a reason for hiding this comment

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

this helped to keep track of when it failed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to keep it to avoid null values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

FranckLecuyer and others added 2 commits March 18, 2026 10:16
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
coderabbitai[bot]

This comment was marked as outdated.

FranckLecuyer and others added 3 commits March 19, 2026 10:35
…_modifications

# Conflicts:
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStep.java
#	monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/SecurityAnalysisParametersService.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/clients/NetworkModificationRestClientTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/orchestrator/StepExecutionServiceTest.java
#	monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/process/commons/steps/ApplyModificationsStepTest.java
Copy link
Contributor

@antoinebhs antoinebhs left a comment

Choose a reason for hiding this comment

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

Some maybe to discuss? let me know

@@ -0,0 +1,18 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

to put in the right subpackage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -32,8 +32,6 @@ public void skipStep(ProcessStepExecutionContext<?> context, ProcessStep<?> step
.stepType(step.getType().getName())
.stepOrder(context.getStepOrder())
.status(StepStatus.SKIPPED)
.startedAt(context.getStartedAt())
.completedAt(Instant.now())
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to keep it to avoid null values?

networkModificationService.applyModifications(network, modificationInfos, reportNode, filterService);
NetworkModificationsWithMissingInfo networkModificationsWithMissingInfo = networkModificationRestClient.getModifications(modificationIds);
if (networkModificationsWithMissingInfo == null) {
throw new PowsyblException("Failed to retrieve network modifications");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't be null because it's an empty list in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

.withUntypedValue("uuids", missingUuids)
.withSeverity(TypedValue.ERROR_SEVERITY)
.add();
throw new PowsyblException("Some network composite modifications are missing !!");
Copy link
Contributor

Choose a reason for hiding this comment

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

!! to remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

when(context.getProcessExecutionId()).thenReturn(executionId);
when(context.getStepExecutionId()).thenReturn(UUID.randomUUID());
when(context.getStartedAt()).thenReturn(java.time.Instant.now());
when(context.getStepOrder()).thenReturn(stepOrder);
Copy link
Contributor

Choose a reason for hiding this comment

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

to keep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@sonarqubecloud
Copy link

when(stepContext.getReportInfos()).thenReturn(reportInfos);
when(networkModificationRestClient.getModifications(any(List.class))).thenReturn(networkModificationsWithMissingInfo);

assertThrows(RuntimeException.class, () -> applyModificationsStep.execute(stepContext));
Copy link
Contributor

Choose a reason for hiding this comment

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

Check that it's a powsybl exception with the correct message?

Comment on lines +108 to +109
String stepType = applyModificationsStep.getType().getName();
assertEquals("APPLY_MODIFICATIONS", stepType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Already tested?

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