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

   ## What was wrong
   
   `DefaultModel.getRouteConfigurationDefinition(id)` called 
`idOrCreate(NodeIdFactory)` on every route configuration while searching. That 
gave each global route configuration (one without an id) a generated id such as 
`routesConfiguration1`, so:
   
   - any lookup by id, also of an id that does not exist, made the global 
configurations non-global: routes added afterwards without a 
`routeConfigurationId` silently lost the global onException, intercept, 
onCompletion and error handler;
   - `removeRouteConfiguration` of a global configuration removed nothing (the 
"first id-less configuration" fallback could never match);
   - `RouteConfigurationBuilder.updateRouteConfigurationsToCamelContext`, used 
by `DefaultRoutesLoader.updateRoutes` on every route reload, goes through the 
same lookup: reloading a file with a named configuration stripped the global 
configurations from the routes added after the reload, and reloading a global 
configuration left the old copy in the list under a generated id (one more per 
reload), still matching routes with `routeConfigurationId="*"` or a pattern.
   
   ## What changed
   
   - `getRouteConfigurationDefinition(id)` compares the ids as they are 
(null-safe), without assigning one. `null` finds the first global 
configuration; an unknown id returns `null`.
   - `removeRouteConfiguration(def)` (now under the model lock) removes the 
same instance, or else the configuration it replaces: the one with the same id, 
or for a global configuration the global one from the same resource (so 
reloading one file does not remove the global configuration of another file).
   - Javadoc of both methods in `Model`.
   
   I checked the other callers: no other code (JMX, dev consoles, dumpers, 
camel-main, camel-jbang) calls `idOrCreate` on a route configuration or uses 
this lookup, apart from the two route configuration builders' update methods.
   
   ## Tests
   
   New `RoutesConfigurationGlobalUpdateTest` (camel-core), all 6 fail before 
the fix:
   - a lookup does not change a global configuration, and a route added 
afterwards still uses it;
   - removing a global configuration, by instance and by another id-less 
instance, removes it;
   - updating a global configuration twice replaces it (the list size stays 1) 
and new routes use the latest;
   - with two global configurations from different resources, updating one 
replaces only that one;
   - updating a named configuration next to a global one keeps the global one 
for the routes added afterwards.
   
   Ran: camel-core `RoutesConfiguration*Test`, `RouteConfiguration*Test`, 
`RouteWatcher*Test`, `FileWatcher*Test`, `*Reload*Test`, 
`ErrorHandlingAcrossRoutesTest`, `RouteChecksumTest` (133 tests); 
camel-yaml-dsl `RouteConfiguration*`, `*YamlDump*`, `*Reload*` (72); 
camel-xml-io-dsl route configuration tests; camel-management 
`ManagedRouteUpdateRouteFromXmlTest`. All green.
   
   ## Upgrade guide
   
   Entry in the 4.25 upgrade guide: global route configurations are now 
replaced and removed on update/reload, and a lookup of an unknown id returns 
`null`.
   
   Fixes https://issues.apache.org/jira/browse/CAMEL-28096
   
   _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