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

   Fixes [CAMEL-25619](https://issues.apache.org/jira/browse/CAMEL-25619), the 
follow-up of CAMEL-25616 (reported in the comments of #27751).
   
   The dev mode route reload (`RouteWatcherReloadStrategy`) removed all route 
templates with `removeRouteTemplates("*")` and loaded the route files again. 
Two cases broke:
   
   1. **A route template defined in Java** (a `RouteBuilder` added to the 
context, no resource) was removed and nothing added it back. Since CAMEL-25616 
the file with its `templatedRoute` was not loaded again either (so the reload 
no longer fails), but the templated route was missing after a reload of another 
file.
   2. **A route template in a watched file that is only used through 
`kamelet:`** (no `templatedRoute`) was not loaded again, as a route from a 
Kamelet has no source of its own. The route calling `kamelet:greeting` failed 
with `Resource not found: classpath:kamelets/greeting.kamelet.yaml` on a reload 
of another file, and the restore of the previous routes (CAMEL-24860) failed 
the same way, leaving no routes.
   
   ### Fix
   
   - New `CamelContext.removeRouteTemplatesFromResources(String pattern)` 
(`@since 4.24`): removes only the route templates loaded from a resource and 
keeps those without one. `DefaultCamelContext` filters the model's route 
templates by their resource; `SimpleCamelContext` throws 
`UnsupportedOperationException` like its `removeRouteTemplates`. A plain 
`removeRouteTemplates("*")` is not enough here: route templates are not 
replaced when added again, so a kept template from a file would be duplicated. 
The reload and the restore path use the new method, so a route template from 
Java is kept, and the file with the templated route is now loaded again (the 
CAMEL-25616 guard is removed).
   - The source of a route created by a Kamelet is loaded again when it is a 
`file:` (the file with its route template). A Kamelet from the classpath, such 
as from a Kamelet catalog, is still loaded again by the kamelet component when 
it is used.
   - The files with route templates (the sources of the routes created from a 
route template) are loaded before the other files, in the reload and in the 
restore (where the failed file comes back from memory at the end), so the route 
template is there when a route that uses it through `kamelet:` is created, also 
when it is the changed file.
   - Upgrade guide 4.24: the new `CamelContext` method.
   
   ### Tests (camel-yaml-dsl)
   
   All five new tests fail on main and pass with the fix:
   
   - 
`RouteReloadTemplatedRouteSourceTest.reloadOfAnotherFileWithTheRouteTemplateFromJava`:
 now also checks the templated route `greet` runs after the reload (it was 
missing).
   - 
`RouteReloadTemplatedRouteSourceTest.failedReloadWithTheRouteTemplateFromJavaRestoresTheTemplatedRoute`:
 a failed reload restores the templated route.
   - `RouteReloadKameletTemplateFileTest` (new): a reload of another file keeps 
the route that uses the Kamelet; a change of the route template file is used by 
that route; a failed reload restores it.
   
   Also ran: the `RouteReload*`, `Kamelet*` and `*Template*` tests of 
camel-yaml-dsl (72), the `*Reload*`, `*RouteTemplate*` and `*TemplatedRoute*` 
tests of camel-core (154), the whole camel-kamelet module (161), and the 
`*Reload*` tests of camel-main (12; `MainPropertiesReloadBeansTest` flaked once 
and passed again, also 3 times on its own; it does not involve route templates).
   
   _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