davsclaus opened a new pull request, #27751: URL: https://github.com/apache/camel/pull/27751
_Claude Code on behalf of davsclaus_ Fixes [CAMEL-25598](https://issues.apache.org/jira/browse/CAMEL-25598). **Stacked on #27745 (CAMEL-25554)**: a reload needs that change to create the templated routes again. Retarget to `main` once #27745 is merged. ### Problem A route created from a route template (or Kamelet) did not record which files it comes from: * `Route.getSourceResource()` was null, although `Route.getSourceLocation()` points at the template's file and line. The debugger and message history consoles showed no code for these routes. * The file that declares a `templatedRoute` was not recorded anywhere. * `RouteWatcherReloadStrategy` (file watch, `removeAllRoutes=true`) works out which files to load again from the source resources of the running routes. When another file changed, a file holding only `templatedRoute` entries, or only the `routeTemplate`, was not loaded again: the templated routes were gone, or the reload failed with `Cannot find RouteTemplate` and the previous routes were restored. ### Change The two files are kept apart, as they answer different questions: the source resource is where the route's code is (its line numbers are there), the templated route resource is the file that has to be loaded again to get the route back. * `DefaultModel`: a route from a template gets the template's resource as its source resource, and a route from a `templatedRoute` the resource of the `templatedRoute` (`RouteDefinition.templatedRouteResource`, model-only). Both are set after the route is prepared, as preparing it set the resource of the (temporary) route collection, which is null. * `RouteBuilder`: route templates and templated routes created in `configure()` get the builder's resource (the Java DSL created them before the resource was set on their collections). * API: `NamedRoute` and `Route` get `getRouteTemplateId()` and `getTemplatedRouteResource()` (default methods, `@since 4.24`). `DefaultRoute` keeps both from the definition, as the route model is cleared once the route is created. * For tools (CLI, MCP, TUI), not only the reloader: JMX `ManagedRouteMBean` gets `RouteTemplateId` and `TemplatedRouteSource`, and the route dev console `routeTemplateId` and `templatedRouteSource` (JSON and text). Catalog metadata regenerated. * `RouteWatcherReloadStrategy` collects the source resource and the templated route resource of the running routes. Kamelet routes are skipped: their template often comes from the classpath, and they are created again with their parent route. * Upgrade guide (4.24): `getSourceResource()` is no longer null for routes from route templates / Kamelets. ### Tests * `RouteReloadTemplatedRouteSourceTest` (yaml-dsl): the route records its template id, source and templated route resource; a file-watch reload of a third file keeps the templated route (template in one file, `templatedRoute` in another). * `ManagedRouteTemplatedRouteSourceTest` (JMX) and `RouteDevConsoleTemplatedRouteTest` (route console, JSON and text). Ran: camel-yaml-dsl (479), camel-management (563, full), camel-console (245), camel-kamelet (94), camel-core template/reload/source-location/dump/kamelet tests (306), camel-main reload/template tests, `LwJavaParserSecurityTest`, and a full `mvn clean install -DskipTests`. ### Follow-ups (not in this PR) * `camel get route` could show the templated route source; the TUI Routes/Source tabs could jump to the `templatedRoute`; the MCP runtime route tools could return both fields. * A route template file with no route created from it is still not collected by a file-watch reload of another file (the reload removes all templates). 🤖 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]
