Skip to content

Add notification for process update + Add getExecution endpoint#99

Open
carojeandat wants to merge 3 commits into
mainfrom
caroline/add-notification
Open

Add notification for process update + Add getExecution endpoint#99
carojeandat wants to merge 3 commits into
mainfrom
caroline/add-notification

Conversation

@carojeandat

Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@carojeandat, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19ca387a-4bf2-4f19-8f78-abfd9e1bac86

📥 Commits

Reviewing files that changed from the base of the PR and between 0a10d73 and 7861a68.

📒 Files selected for processing (2)
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java
📝 Walkthrough

Walkthrough

Adds a GET /executions/{executionId} endpoint and supporting service/repository lookup. Refactors sendProcessUpdatedMessage to accept a payload and MessageType, and updates status-update consumption to publish the notification after execution status changes.

Changes

Execution retrieval and notification refactor

Layer / File(s) Summary
Repository-level execution lookup
.../ProcessExecutionTxService.java, .../ProcessExecutionTxServiceTest.java
Adds getExecution(UUID) mapping entity to DTO via processExecutionMapper, with tests for found/not-found cases.
Service-level delegation and notification cleanup
.../ProcessExecutionService.java, .../ProcessExecutionServiceTest.java
Adds getExecution(UUID) delegating to the tx service; removes the "process updated" notification call from executeProcess; adds/updates tests accordingly.
New GET endpoint
.../MonitorController.java, .../MonitorControllerTest.java
Adds GET /executions/{executionId} returning 200 with ProcessExecution or 404 when absent, with tests for both cases.
Generic notification sender
.../NotificationService.java, .../NotificationServiceTest.java
Refactors sendProcessUpdatedMessage into a generic <T> method taking executionId, MessageType, and payload, setting updateType and processExecutionId headers instead of a fixed update type and processType header.
Wiring notifications into status updates
.../ConsumerService.java, .../ConsumerServiceTest.java
Adds NotificationService dependency to ConsumerService; handleExecutionStatusUpdate now calls sendProcessUpdatedMessage after updating status; tests validate invocation and non-invocation on parse failure.

Suggested reviewers: antoinebhs, FranckLecuyer

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is related but only contains a template placeholder and no concrete details about the changes. Replace the placeholder with a brief summary of the new notification flow and the getExecution endpoint.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately highlights the two main changes: process update notifications and the new getExecution endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java (1)

294-315: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer a real ProcessExecution instance over mocking the record.

ProcessExecution is a record (implicitly final) with plain data fields and no behavior, so mocking it via Mockito.mock relies on Mockito's inline mock maker (default only since Mockito 5) and yields an instance whose accessors all return null unless stubbed. assertThat(result).contains(processExecution) here only proves reference identity, not that the mapped/returned value has meaningful field data — weaker coverage than the sibling ProcessExecutionTxServiceTest tests which build a real ProcessExecution via constructor/builder.

♻️ Suggested fix
     `@Test`
     void getExecutionReturnsExecution() {
-        ProcessExecution processExecution = Mockito.mock(ProcessExecution.class);
+        ProcessExecution processExecution = ProcessExecution.builder()
+            .id(executionId)
+            .type(ProcessType.SECURITY_ANALYSIS.name())
+            .caseUuid(caseUuid)
+            .processConfigId(UUID.randomUUID())
+            .status(ProcessStatus.COMPLETED)
+            .executionEnvName("env1")
+            .userId(userId)
+            .build();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java`
around lines 294 - 315, The test `getExecutionReturnsExecution` is mocking
`ProcessExecution`, but this record should be exercised as a real data object
instead of a Mockito mock. Update the test in `ProcessExecutionServiceTest` to
construct a concrete `ProcessExecution` instance with representative fields,
then assert that `processExecutionService.getExecution(...)` returns that same
value via `processExecutionTxService.getExecution(...)`. Keep the existing
`getExecutionNotFoundReturnsEmpty` case unchanged.
monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java (1)

218-232: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer a real ProcessExecution instance over mocking the record for the 200 test.

Same concern as in ProcessExecutionServiceTest: ProcessExecution is a record; mocking it produces an instance with all-null accessor values. The JSON body assertion (content().json(objectMapper.writeValueAsString(processExecution))) will trivially match since both sides serialize the exact same (mostly-null) mock, so the test doesn't validate real field serialization. Sibling tests like getLaunchedProcesses (line 197) construct real ProcessExecution instances for meaningful JSON assertions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java`
around lines 218 - 232, The 200-response test for getExecution currently mocks
ProcessExecution, which makes the JSON assertion meaningless because the record
serializes to mostly null values. Update getExecutionShouldReturn in
MonitorControllerTest to build a real ProcessExecution instance, similar to
getLaunchedProcesses, and keep stubbing
processExecutionService.getExecution(executionId) to return that instance so the
response body assertion validates actual field serialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java`:
- Around line 82-89: Update the OpenAPI documentation on
MonitorController#getExecution so it matches the actual behavior: the endpoint
already returns ResponseEntity.notFound().build() when
processExecutionService.getExecution(executionId) is empty, so add a documented
404 response alongside the existing 200 ApiResponse, following the pattern used
by getExecutionReports and getExecutionResults.

In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java`:
- Around line 58-71: The notification publish in
ConsumerService.handleExecutionStatusUpdate is currently uncaught, so a failure
in notificationService.sendProcessUpdatedMessage can escape the consumer
callback after processExecutionService.updateExecutionStatus has already
succeeded. Wrap the sendProcessUpdatedMessage call in localized error handling
(or otherwise isolate it) so broker/publish failures are logged and do not
trigger requeueing or duplicate processing of the already-applied execution
status update.

---

Nitpick comments:
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java`:
- Around line 218-232: The 200-response test for getExecution currently mocks
ProcessExecution, which makes the JSON assertion meaningless because the record
serializes to mostly null values. Update getExecutionShouldReturn in
MonitorControllerTest to build a real ProcessExecution instance, similar to
getLaunchedProcesses, and keep stubbing
processExecutionService.getExecution(executionId) to return that instance so the
response body assertion validates actual field serialization.

In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java`:
- Around line 294-315: The test `getExecutionReturnsExecution` is mocking
`ProcessExecution`, but this record should be exercised as a real data object
instead of a Mockito mock. Update the test in `ProcessExecutionServiceTest` to
construct a concrete `ProcessExecution` instance with representative fields,
then assert that `processExecutionService.getExecution(...)` returns that same
value via `processExecutionTxService.getExecution(...)`. Keep the existing
`getExecutionNotFoundReturnsEmpty` case unchanged.
🪄 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: ecdd56ab-96d3-43cd-aad1-7193291b34b9

📥 Commits

Reviewing files that changed from the base of the PR and between 565c882 and f33c196.

📒 Files selected for processing (10)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/NotificationService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionService.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionTxService.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/MonitorControllerTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/ConsumerServiceTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/messaging/NotificationServiceTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionServiceTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processexecution/ProcessExecutionTxServiceTest.java

Comment on lines 58 to 71
switch (messageType) {
case EXECUTION_STATUS_UPDATE -> handleExecutionStatusUpdate(executionId, message);
case EXECUTION_STATUS_UPDATE -> handleExecutionStatusUpdate(executionId, message, messageType);
case STEP_STATUS_UPDATE -> handleStepStatusUpdate(executionId, message);
case STEPS_STATUSES_UPDATE -> handleStepsStatusesUpdate(executionId, message);
default -> LOGGER.warn("Unknown message type: {}", messageType);
}
};
}

private void handleExecutionStatusUpdate(UUID executionId, Message<String> message) {
private void handleExecutionStatusUpdate(UUID executionId, Message<String> message, MessageType messageType) {
ProcessExecutionStatusUpdate payload = parsePayload(message.getPayload(), ProcessExecutionStatusUpdate.class);
processExecutionService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt());
notificationService.sendProcessUpdatedMessage(executionId, messageType, payload);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Unhandled notification failure can block/duplicate message processing.

sendProcessUpdatedMessage runs with no error handling right after updateExecutionStatus. If the publish fails (e.g. broker unavailable), the exception propagates out of the consumer callback, likely causing the inbound message to be requeued/retried — reprocessing (duplicating) the already-applied status update and potentially stalling this queue if the failure persists.

🛡️ Suggested fix to isolate notification failures
     private void handleExecutionStatusUpdate(UUID executionId, Message<String> message, MessageType messageType) {
         ProcessExecutionStatusUpdate payload = parsePayload(message.getPayload(), ProcessExecutionStatusUpdate.class);
         processExecutionService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt());
-        notificationService.sendProcessUpdatedMessage(executionId, messageType, payload);
+        try {
+            notificationService.sendProcessUpdatedMessage(executionId, messageType, payload);
+        } catch (Exception e) {
+            LOGGER.warn("Failed to send process updated notification for execution {}", executionId, e);
+        }
     }
📝 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
switch (messageType) {
case EXECUTION_STATUS_UPDATE -> handleExecutionStatusUpdate(executionId, message);
case EXECUTION_STATUS_UPDATE -> handleExecutionStatusUpdate(executionId, message, messageType);
case STEP_STATUS_UPDATE -> handleStepStatusUpdate(executionId, message);
case STEPS_STATUSES_UPDATE -> handleStepsStatusesUpdate(executionId, message);
default -> LOGGER.warn("Unknown message type: {}", messageType);
}
};
}
private void handleExecutionStatusUpdate(UUID executionId, Message<String> message) {
private void handleExecutionStatusUpdate(UUID executionId, Message<String> message, MessageType messageType) {
ProcessExecutionStatusUpdate payload = parsePayload(message.getPayload(), ProcessExecutionStatusUpdate.class);
processExecutionService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt());
notificationService.sendProcessUpdatedMessage(executionId, messageType, payload);
}
switch (messageType) {
case EXECUTION_STATUS_UPDATE -> handleExecutionStatusUpdate(executionId, message, messageType);
case STEP_STATUS_UPDATE -> handleStepStatusUpdate(executionId, message);
case STEPS_STATUSES_UPDATE -> handleStepsStatusesUpdate(executionId, message);
default -> LOGGER.warn("Unknown message type: {}", messageType);
}
};
}
private void handleExecutionStatusUpdate(UUID executionId, Message<String> message, MessageType messageType) {
ProcessExecutionStatusUpdate payload = parsePayload(message.getPayload(), ProcessExecutionStatusUpdate.class);
processExecutionService.updateExecutionStatus(executionId, payload.getStatus(), payload.getExecutionEnvName(), payload.getStartedAt(), payload.getCompletedAt());
try {
notificationService.sendProcessUpdatedMessage(executionId, messageType, payload);
} catch (Exception e) {
LOGGER.warn("Failed to send process updated notification for execution {}", executionId, e);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/messaging/ConsumerService.java`
around lines 58 - 71, The notification publish in
ConsumerService.handleExecutionStatusUpdate is currently uncaught, so a failure
in notificationService.sendProcessUpdatedMessage can escape the consumer
callback after processExecutionService.updateExecutionStatus has already
succeeded. Wrap the sendProcessUpdatedMessage call in localized error handling
(or otherwise isolate it) so broker/publish failures are logged and do not
trigger requeueing or duplicate processing of the already-applied execution
status update.

Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
Signed-off-by: Caroline Jeandat <caroline.jeandat@rte-france.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

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