You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/06/27 15:24:31 UTC
[camel] branch camel-3.20.x updated: CAMEL-19509: camel-yaml-dsl - Add support for kamelet binding with no sink
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.20.x by this push:
new 0ef44cd8904 CAMEL-19509: camel-yaml-dsl - Add support for kamelet binding with no sink
0ef44cd8904 is described below
commit 0ef44cd89040388b3c5ad39b1cdd4e1e4ce4f4b9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 27 17:19:49 2023 +0200
CAMEL-19509: camel-yaml-dsl - Add support for kamelet binding with no sink
---
.../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 31 +++--
.../camel/dsl/yaml/KameletBindingLoaderTest.groovy | 36 +++++
.../resources/kamelets/log-action.kamelet.yaml | 149 +++++++++++++++++++++
3 files changed, 202 insertions(+), 14 deletions(-)
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
index facba8fe411..d98b13df1e2 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java
@@ -679,7 +679,7 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
// and map those to Camel route definitions
MappingNode source = asMappingNode(nodeAt(root, "/spec/source"));
MappingNode sink = asMappingNode(nodeAt(root, "/spec/sink"));
- if (source != null && sink != null) {
+ if (source != null) {
int line = -1;
if (source.getStartMark().isPresent()) {
line = source.getStartMark().get().getLine();
@@ -731,20 +731,23 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
}
}
- // sink is at the end (mandatory)
- line = -1;
- if (sink.getStartMark().isPresent()) {
- line = sink.getStartMark().get().getLine();
- }
- uri = extractCamelEndpointUri(sink);
- ToDefinition to = new ToDefinition(uri);
- route.addOutput(to);
+ if (sink != null) {
- // enrich model with line number
- if (line != -1) {
- to.setLineNumber(line);
- if (ctx != null) {
- to.setLocation(ctx.getResource().getLocation());
+ // sink is at the end (mandatory)
+ line = -1;
+ if (sink.getStartMark().isPresent()) {
+ line = sink.getStartMark().get().getLine();
+ }
+ uri = extractCamelEndpointUri(sink);
+ ToDefinition to = new ToDefinition(uri);
+ route.addOutput(to);
+
+ // enrich model with line number
+ if (line != -1) {
+ to.setLineNumber(line);
+ if (ctx != null) {
+ to.setLocation(ctx.getResource().getLocation());
+ }
}
}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
index 8a339e14ac9..77f99c1c6e7 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderTest.groovy
@@ -621,4 +621,40 @@ class KameletBindingLoaderTest extends YamlTestSupport {
context.resolvePropertyPlaceholders("{{MY_ENV}}") == "cheese"
}
+ def "kamelet binding no sink"() {
+ when:
+ loadBindings('''
+ apiVersion: camel.apache.org/v1alpha1
+ kind: KameletBinding
+ metadata:
+ name: timer-event-source
+ spec:
+ source:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: timer-source
+ properties:
+ message: "Hello world!"
+ steps:
+ - ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: log-action
+ ''')
+ then:
+ context.routeDefinitions.size() == 3
+
+ with (context.routeDefinitions[0]) {
+ routeId == 'timer-event-source'
+ input.endpointUri == 'kamelet:timer-source?message=Hello+world%21'
+ input.lineNumber == 7
+ outputs.size() == 1
+ with (outputs[0], KameletDefinition) {
+ name == 'log-action'
+ lineNumber == 14
+ }
+ }
+ }
+
}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/log-action.kamelet.yaml b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/log-action.kamelet.yaml
new file mode 100644
index 00000000000..7f4f7ef73fe
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/log-action.kamelet.yaml
@@ -0,0 +1,149 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+ name: log-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "main-SNAPSHOT"
+ camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE2LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodH [...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Logging"
+ camel.apache.org/kamelet.namespace: "Logging"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+spec:
+ definition:
+ title: "Log Action"
+ description: |-
+ Logs all data that flows between source and sink, useful for debugging purposes.
+ type: object
+ properties:
+ loggerName:
+ title: Logger Name
+ description: Name of the logging category to use
+ type: string
+ default: "log-action"
+ level:
+ title: Log Level
+ description: Logging level to use
+ type: string
+ default: "INFO"
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:select:TRACE'
+ - 'urn:alm:descriptor:com.tectonic.ui:select:DEBUG'
+ - 'urn:alm:descriptor:com.tectonic.ui:select:INFO'
+ - 'urn:alm:descriptor:com.tectonic.ui:select:WARN'
+ - 'urn:alm:descriptor:com.tectonic.ui:select:ERROR'
+ - 'urn:alm:descriptor:com.tectonic.ui:select:OFF'
+ logMask:
+ title: Log Mask
+ description: Mask sensitive information like password or passphrase in the log
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ marker:
+ title: Marker
+ description: An optional Marker name to use
+ type: string
+ multiline:
+ title: Multiline
+ description: If enabled then each information is outputted on a newline
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showAllProperties:
+ title: Show All Properties
+ description: Show all of the exchange properties (both internal and custom)
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showBody:
+ title: Show Body
+ description: Show the message body
+ type: boolean
+ default: true
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showBodyType:
+ title: Show Body Type
+ description: Show the body Java type
+ type: boolean
+ default: true
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showExchangePattern:
+ title: Show Exchange Pattern
+ description: Shows the Message Exchange Pattern (or MEP for short)
+ type: boolean
+ default: true
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showHeaders:
+ title: Show Headers
+ description: Show the headers received
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showProperties:
+ title: Show Properties
+ description: Show the exchange properties (only custom). Use showAllProperties to show both internal and custom properties.
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showStreams:
+ title: Show Streams
+ description: Show the stream bodies (they may not be available in following steps)
+ type: boolean
+ default: false
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ showCachedStreams:
+ title: Show Cached Streams
+ description: Whether Camel should show cached stream bodies or not.
+ type: boolean
+ default: true
+ x-descriptors:
+ - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
+ dependencies:
+ - "camel:kamelet"
+ - "camel:log"
+ template:
+ from:
+ uri: "kamelet:source"
+ steps:
+ - to:
+ uri: "log:{{loggerName}}"
+ parameters:
+ level: "{{?level}}"
+ logMask: "{{?logMask}}"
+ marker: "{{?marker}}"
+ multiline: "{{?multiline}}"
+ showAllProperties: "{{?showAllProperties}}"
+ showBody: "{{?showBody}}"
+ showBodyType: "{{?showBodyType}}"
+ showExchangePattern: "{{?showExchangePattern}}"
+ showHeaders: "{{?showHeaders}}"
+ showProperties: "{{?showProperties}}"
+ showStreams: "{{?showStreams}}"
+ showCachedStreams: "{{?showCachedStreams}}"
\ No newline at end of file