allthingssecurity commented on PR #27751:
URL: https://github.com/apache/camel/pull/27751#issuecomment-6142685075
A late note, as this was merged before I posted it. I ran the tests below on
5ba69e5f6a4f; lines 384 and 390 of `RouteWatcherReloadStrategy` are the same on
main today, but I have not re-run them on main yet. I will re-check point 1 on
main and, if it reproduces there, open a JIRA with a fix.
Thanks, the split between the source resource and the templated route
resource makes sense, and the file-watch case
from the JIRA works for me, also across a failed reload, the restore, and
the fix.
Two points on `RouteWatcherReloadStrategy`:
**1. A reload of any file now removes all routes when the route template
does not come from a file**
(`RouteWatcherReloadStrategy.java:384`, together with
`removeRouteTemplates("*")` at `:390`).
Setup: the route template is defined in a Java `RouteBuilder` added to the
context (no resource), the `templatedRoute`
is in a watched YAML file, and a third file changes. Line 384 now collects
the YAML file with the `templatedRoute`,
but line 390 has removed the template and none of the sources brings it
back. The reload fails, the restore fails the
same way, and the context is left without routes. Saving again does not
help, as there is nothing to fix in the files.
```java
@Test
void javaTemplateYamlTemplatedRouteReloadOfAnotherFile() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
routeTemplate("greeting").templateParameter("greeting")
.from("direct:greet").setBody(constant("{{greeting}}"));
}
});
// uses.camel.yaml: templatedRoute routeTemplateRef "greeting", routeId
"greet"
// plain.camel.yaml: route "plain" (as in
RouteReloadTemplatedRouteSourceTest)
loadRoutes(ResourceHelper.resolveResource(context, "file:" + uses),
ResourceHelper.resolveResource(context, "file:" + plain));
Files.writeString(plain, plainRoute("plain changed"));
strategy.reloadFile(plain.toFile()); // what the file watcher calls
assertThat(strategy.getLastError()).isNull();
assertThat(context.createFluentProducerTemplate().to("direct:plain").request(String.class))
.isEqualTo("plain changed");
}
```
On this branch:
```
lastError=java.lang.IllegalArgumentException: Cannot find RouteTemplate with
id greeting failed=1 routes=[] templates=0
WARN RouteWatcherReloadStrategy - Reload failed and the previous routes
could not be restored due to:
Cannot find RouteTemplate with id greeting. The application runs without
routes until the file is fixed
```
On #27745 and on main the same test passes: `lastError=null routes=[plain]`.
The templated route is silently missing
there, which is the older problem, but the other routes keep running and the
edit is applied.
Possible fix: only remove the route templates that are loaded again (those
with a resource that is among the sources),
so a template added from Java survives the reload. As
`RouteBuilder.checkInitialized` now sets the resource on the
templates, a null resource tells them apart. A smaller guard would be to
collect `getTemplatedRouteResource()` only
when `getSourceResource()` is not null, which gives the previous behaviour
back for this case.
**2. A route template in a watched file that is used through `kamelet:` is
still not loaded again** (`:382`, the
`isCreatedByKamelet()` skip). Not introduced here, it fails the same on
main, but the description reads as if a file
holding only the `routeTemplate` is covered now.
```yaml
# templates.camel.yaml
- routeTemplate:
id: "greeting"
parameters:
- name: "greeting"
from:
uri: "kamelet:source"
steps:
- setBody:
constant: "{{greeting}}"
# uses.camel.yaml
- route:
id: caller
from:
uri: direct:start
steps:
- to: "kamelet:greeting?greeting=Hello"
```
Change `plain.camel.yaml` and reload it:
```
FailedToCreateRouteException: Failed to create route: caller at: >>>
to[kamelet:greeting?greeting=Hello] <<< ...
because: Failed to resolve endpoint: kamelet://greeting?greeting=Hello due
to:
java.io.FileNotFoundException: Resource not found:
classpath:kamelets/greeting.kamelet.yaml
routes=[] templates=0
```
The restore fails too, so no routes are left. As an experiment I also
collected the source resource of a Kamelet
route when its location starts with `file:` (added first, so the template is
there before the route that uses it),
and the test passes with that. Fine by me as a follow-up JIRA if you prefer
to keep this PR small.
_Claude Code on behalf of allthingssecurity_
--
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]