Federico Mariani created CAMEL-25555:
----------------------------------------
Summary: camel-jbang - camel validate normalize --output <dir>
should write one file per input file, so a top-level onException keeps its scope
Key: CAMEL-25555
URL: https://issues.apache.org/jira/browse/CAMEL-25555
Project: Camel
Issue Type: Improvement
Components: camel-jbang
Reporter: Federico Mariani
When {{camel validate normalize}} is given several route files and an output
directory, it still merges all the routes into one {{normalized.yaml}} (only
Kamelets are written to a file of their own). Since CAMEL-25490 a top-level
{{onException}} is dumped as a top-level element before the first route, so in
the merged file it applies to the routes of *all* the input files, while in the
source it applied only to the routes of its own file.
h3. Example (main, 4.23.0-SNAPSHOT; same on 4.22.2-SNAPSHOT)
{code:yaml|title=a.yaml}
- route:
id: fromA
from:
uri: timer:a
steps:
- log:
message: "A"
{code}
{code:yaml|title=b.yaml}
- onException:
exception:
- java.lang.Exception
handled:
constant: "true"
steps:
- log:
message: "B failed"
- route:
id: fromB
from:
uri: timer:b
steps:
- log:
message: "B"
{code}
{{camel validate normalize a.yaml b.yaml --output=out/}} writes
{{out/normalized.yaml}} with the {{onException}} of {{b.yaml}} first, then the
routes {{fromA}} and {{fromB}}. Loading it, the {{onException}} of {{b.yaml}}
now also handles the errors of {{fromA}}. If {{a.yaml}} and {{b.yaml}} both
have a top-level {{onException}} for the same exception, they get the same
{{ExceptionPolicyKey}} and the last one wins, so the routes of {{a.yaml}}
silently get the handler of {{b.yaml}}.
The dump strategy logs a WARN for this ({{DefaultDumpRoutesStrategy}}, added in
CAMEL-25490), but {{camel validate normalize}} runs with the dump log turned
off, so the user does not see it.
h3. Proposal
When {{--output}} is a directory, write one normalized file per input file (as
is already done for Kamelets, and as {{camel.main.dumpRoutesOutput}} does when
it is a directory: one file per resource), keeping each file's name. That keeps
the scope of each top-level {{onException}} exactly. With a single output file
(or no {{--output}}), keep merging, and print a warning from the command when a
top-level {{onException}} of one file ends up applying to the routes of other
files.
Points to decide:
* the file names in the output directory when two inputs share a name in
different directories;
* what goes into each file for elements that are not tied to a resource (beans,
data formats, rests, route configurations loaded from another file).
Related: CAMEL-25490 (discussed in the review of
[#27609|https://github.com/apache/camel/pull/27609]).
_Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)