Federico Mariani created CAMEL-25492:
----------------------------------------

             Summary: camel-yaml-io - YAML route dump writes top-level 
onCompletion, intercept, interceptFrom and interceptSendToEndpoint into the 
steps of each route
                 Key: CAMEL-25492
                 URL: https://issues.apache.org/jira/browse/CAMEL-25492
             Project: Camel
          Issue Type: Bug
          Components: camel-jbang, camel-yaml-dsl
    Affects Versions: 4.22.1
            Reporter: Federico Mariani


{{camel validate normalize}} (the YAML route dump, 
{{camel.main.dumpRoutes=yaml}}) writes a top-level {{onCompletion}}, 
{{interceptFrom}}, {{intercept}} or {{interceptSendToEndpoint}} into the steps 
of each route it applies to. The YAML DSL schema has none of them among the 
steps of a route (route scoped cross-cutting EIPs are not supported in YAML, 
see CAMEL-25207), so a valid file becomes invalid. The scope also changes from 
"all routes of the file" to a copy per route.

h3. Reproduction (Camel CLI 4.22.1)

{code:yaml|title=in.yaml}
- onCompletion:
    steps:
      - log:
          message: "done"
- interceptFrom:
    uri: "direct*"
    steps:
      - log:
          message: "intercepted"
- route:
    id: myRoute
    from:
      uri: direct:start
      steps:
        - log:
            message: "Hello"
{code}

{{camel validate yaml in.yaml}}: Validation success. {{camel validate normalize 
in.yaml --output=out.yaml}}:

{code:yaml|title=out.yaml}
- route:
    id: myRoute
    from:
      uri: direct
      parameters:
        name: start
      steps:
        - interceptFrom:
            uri: direct*
            steps:
              - log:
                  message: intercepted
        - onCompletion:
            steps:
              - log:
                  message: done
        - log:
            message: Hello
{code}

{noformat}
$ camel validate yaml out.yaml
Validation error detected (errors:2)
        File: out.yaml
                /0/route/from/steps/0: property 'interceptFrom' is not defined 
in the schema and the schema does not allow additional properties
                /0/route/from/steps/1: property 'onCompletion' is not defined 
in the schema and the schema does not allow additional properties
{noformat}

With several routes, the {{onCompletion}} is copied into each route 
({{interceptFrom}} into each route whose endpoint matches its uri).

In 4.22.1 a top-level {{intercept}} and {{interceptSendToEndpoint}} are dropped 
from the output instead (the 4.22.x YAML writer does not write them). On main 
(4.23.0-SNAPSHOT, after CAMEL-25255) they are written as steps of each route as 
well:

{code:yaml}
      steps:
        - interceptSendToEndpoint:
            uri: log*
            steps:
              - log:
                  message: sending
        - intercept:
            steps:
              - log:
                  message: intercept
        - to: ...
{code}

h3. Cause

When a route is prepared, {{RouteDefinitionHelper.prepareRoute}} 
({{initInterceptors}}, {{initOnCompletions}}) adds the context scoped 
interceptors and onCompletions (the top-level ones of the file, and those of 
the route configurations that apply) to the outputs of the route. 
{{LwModelToYAMLDumper}} (core/camel-yaml-io) writes all route outputs as steps.

This is the same cause as CAMEL-25490, which fixes it for {{onException}} only: 
there the context scoped ones are marked with {{routeScoped=false}}. 
{{InterceptDefinition}}, {{InterceptFromDefinition}} and 
{{InterceptSendToEndpointDefinition}} have no such marker, and a top-level 
{{onCompletion}} loaded by the YAML DSL keeps {{routeScoped=true}} (only 
{{RoutesDefinition.onCompletion()}} of the Java DSL sets it to false), so the 
dumper cannot tell them from route scoped ones (Java DSL 
{{from(...).onCompletion()}}). A fix needs a marker set when they are merged 
into the route (or the dumper to get the {{RoutesDefinition}} lists of the 
source), and then the same treatment as CAMEL-25490: leave them out of the 
steps and write them once as top-level entries (or not at all when they come 
from a routeConfiguration).




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to