davsclaus opened a new pull request, #31338:
URL: https://github.com/apache/camel/pull/31338

   ## What was wrong
   
   On route reload, `DefaultRoutesLoader.doUpdateRoutes` updates the route 
configurations of a changed file with 
`RouteConfigurationBuilder.updateRouteConfigurationsToCamelContext`. That 
method only removed and re-added the configurations whose ids are in the new 
version of the file. So:
   
   - a route configuration removed from a file stayed in the model, also with 
the default `removeAllRoutes=true`, and the reloaded routes still merged it;
   - `RouteWatcherReloadStrategy` skips a deleted file (`Files.exists`), so the 
route configurations of a deleted file stayed too.
   
   ## What changed
   
   - New `CamelContext.removeRouteConfigurationsFromResources(String pattern)` 
(`@since 4.25`), the counterpart of `removeRouteTemplatesFromResources` 
(CAMEL-25619). It removes the route configurations whose resource location 
matches the pattern, and keeps those without a resource (Java 
`RouteConfigurationBuilder` added to the context). `DefaultCamelContext` 
removes them from the model list by identity, so global (id-less) 
configurations are removed too, independent of CAMEL-28096. 
`SimpleCamelContext` throws `UnsupportedOperationException`, as for the 
template variant. No other `CamelContext` implementation in the repo needs a 
change.
   - `RouteConfigurationBuilder` and `EndpointRouteConfigurationBuilder` set 
the builder's resource on each route configuration that has none. Before, XML 
files with a `<routeConfiguration>` root and Java builders did not get one; 
YAML already did.
   - On update, both builders first remove every route configuration of the 
builder's resource, also when the file now declares none, and then add the new 
ones as before.
   - `RouteWatcherReloadStrategy.onRouteReload` removes the route 
configurations of a passed resource whose file is deleted. It does this with 
both `removeAllRoutes=true` and `false`.
   - Running routes are not refreshed. A route that keeps running 
(`removeAllRoutes=false`) keeps the route configuration it was created with 
until its own file is reloaded. Refreshing those routes is CAMEL-25142.
   
   Known gap: `RouteOnDemandReloadStrategy` passes only the files that still 
exist, so it never sees a deleted configuration-only file. Its configurations 
then stay, as before. A configuration removed from a file that still exists is 
handled.
   
   The pattern is matched against the resource location as the loader saw it. 
The watcher passes `file:<path>` the same way the routes are loaded from the 
watched folder.
   
   ## Interaction with #31334 (CAMEL-28096)
   
   Both PRs touch `DefaultModel`, in different methods, and both add an entry 
at the end of the 4.25 upgrade guide. Whichever merges second rebases. The two 
fixes are independent: this PR removes by identity and resource, and #31334 
fixes the id lookup that turns global configurations into named ones.
   
   ## Tests
   
   - `RoutesConfigurationFromResourcesTest` (camel-core):
     - route configurations get the builder's resource;
     - the new method removes those of one resource (including the global one) 
and keeps the others and the Java ones; `*` removes all from resources;
     - a builder update drops the configurations its resource no longer 
declares, including when it declares none.
   - `RouteReloadRouteConfigurationTest` (camel-yaml-dsl), file based with 
`@TempDir`, the strategy driven by hand as in the other `RouteReload*Test`. The 
reload is synchronous, so no Awaitility is needed. Cases:
     - reloading the same file keeps its configurations once;
     - a configuration removed from a file, with `removeAllRoutes=true` and 
`false`;
     - a deleted configuration file, with `removeAllRoutes=true` and `false`.
   
     All 5 fail without the fix.
   - Ran, all green:
     - camel-core: `RoutesConfiguration*`, `RouteConfiguration*`, 
`RouteWatcher*`, `FileWatcher*`, `*Reload*`, `*RouteTemplate*`, 
`ErrorHandlingAcrossRoutesTest`, `RouteChecksumTest` (239 tests);
     - camel-yaml-dsl: `RouteConfiguration*`, `RouteReload*`, `*YamlDump*`, 
`*Kamelet*` (118 tests);
     - camel-xml-io-dsl: route configuration and reload tests;
     - camel-java-io: `LwJavaParserSecurityTest` (the new builder helper is 
private);
     - camel-management: `ManagedRouteUpdateRouteFromXmlTest`.
   
   ## Upgrade guide
   
   Entry in the 4.25 upgrade guide: a route reload now removes the route 
configurations a file no longer declares, or those of a deleted file. It also 
mentions the new `CamelContext` method.
   
   Fixes https://issues.apache.org/jira/browse/CAMEL-28101
   
   _Claude Code on behalf of davsclaus_
   
   🤖 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]

Reply via email to