allthingssecurity opened a new pull request, #29670: URL: https://github.com/apache/camel/pull/29670
# Description [CAMEL-26869](https://issues.apache.org/jira/browse/CAMEL-26869) When a `ClusteredRouteController` was stopped or shut down while the CamelContext kept running, `doStop` stopped its cluster service. By default the route controller looks up the cluster service of the CamelContext (`ClusterServiceHelper.mandatoryLookupService`), which others share: a route controller that replaces it (`setRouteController` does not stop the old one, so it is shut down by hand), the cluster route policies and the master consumers of the CamelContext. They all gave up their leadership, and nothing started the cluster service again until the CamelContext restarted. Found in the review of #29531 (CAMEL-26756), which kept this path as it was. Change: the route controller remembers in `doStart` whether it started the cluster service, and while the CamelContext runs it stops the service only if it started it and the service is not a service of the CamelContext (`context.hasService`). A cluster service set on the controller that nobody else started is still stopped when the controller stops, as before (`testControllerStoppedOnItsOwnStopsClusterService` and `testControllerShutdownOnItsOwnUnregistersListeners` pass unchanged). When the CamelContext stops, nothing changes: the cluster service is stopped once the routes have stopped (#29531). The 4.24 upgrade guide section of #29531 gets a paragraph: stopping the route controller alone no longer makes the node leave the cluster when the cluster service is the CamelContext's (as with Camel Main, Spring Boot and Quarkus) or was started by someone else; stop the cluster service itself for that. Not changed: when the CamelContext stops, the controller still stops its cluster service once the routes have stopped, also one it did not start (as #29531 does; with a service shared by the controllers of two CamelContexts, stopping one CamelContext stops it). Adjacent, pre-existing, for a follow-up JIRA I will offer: the route policy factory of a replaced controller stays on the CamelContext, so a route added later gets a second `ClusteredRoutePolicy` (double work, the leadership is the same). Tests, in `ClusteredRouteControllerStopTest`: - `testCamelContextClusterServiceNotStoppedWhenControllerStopsWhileCamelContextRuns`: a cluster service of the CamelContext keeps running when the controller stops; the CamelContext stops it. - `testOldControllerShutdownKeepsTheClusterServiceSharedWithTheNewController`: the controller is replaced and the old one shut down; the shared service keeps running. - `testClusterServiceStartedByOthersNotStoppedWhenControllerStops`: a cluster service the application started and set on the controller keeps running. Without the change the three fail. With it the camel-core cluster tests pass (64, 0 failures), the camel-file cluster tests too (16, 0 failures), and `ClusteredRouteControllerStopTest` passes 180/180 over 20 runs in one JVM. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it): [CAMEL-26869](https://issues.apache.org/jira/browse/CAMEL-26869). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built the core modules with the formatter and import-sort plugins and ran the tests named above. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
