This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch bind
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/bind by this push:
new 47b37dc CAMEL-17261: camel-yaml-dsl - Add support for loading Camel K
KameletBinding file. WIP.
47b37dc is described below
commit 47b37dcdd5a4339c2a489203fb1a1a31c545eb02
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Dec 4 23:39:10 2021 +0100
CAMEL-17261: camel-yaml-dsl - Add support for loading Camel K
KameletBinding file. WIP.
---
.../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 31 ++++++++----
.../camel/dsl/yaml/KameletBindingLoaderTest.groovy | 55 +++++++++++++++++++++-
2 files changed, 75 insertions(+), 11 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 e186fb4..e61092b 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
@@ -151,15 +151,16 @@ public class YamlRoutesBuilderLoader extends
YamlRoutesBuilderLoaderSupport {
private static Object preConfigureNode(Node root) throws Exception {
Object target = root;
- // check if the yaml is a camel-k yaml with embedded routes (called
flow(s))
+ // check if the yaml is a camel-k yaml with embedded binding/routes
(called flow(s))
if (Objects.equals(root.getNodeType(), NodeType.MAPPING)) {
final MappingNode mn = YamlDeserializerSupport.asMappingNode(root);
- boolean camelk = anyTupleMatches(mn.getValue(), "apiVersion",
"camel.apache.org/v1") &&
+ // camel-k: integration
+ boolean integration = anyTupleMatches(mn.getValue(), "apiVersion",
"camel.apache.org/v1") &&
anyTupleMatches(mn.getValue(), "kind", "Integration");
- // kamelet binding are still at v1alpha1
+ // camel-k: kamelet binding are still at v1alpha1
boolean binding = anyTupleMatches(mn.getValue(), "apiVersion",
"camel.apache.org/v1alpha1") &&
anyTupleMatches(mn.getValue(), "kind", "KameletBinding");
- if (camelk) {
+ if (integration) {
Node routes = nodeAt(root, "/spec/flows");
if (routes == null) {
routes = nodeAt(root, "/spec/flow");
@@ -168,13 +169,23 @@ public class YamlRoutesBuilderLoader extends
YamlRoutesBuilderLoaderSupport {
target = routes;
}
} else if (binding) {
- MappingNode source = asMappingNode(nodeAt(root,
"/spec/source/ref"));
- MappingNode sink = asMappingNode(nodeAt(root,
"/spec/sink/ref"));
+ // kamelet binding is a bit more complex, so grab the source
and sink
+ // 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) {
- boolean sourceKamelet = anyTupleMatches(source.getValue(),
"kind", "Kamelet");
- boolean sinkKamelet = anyTupleMatches(sink.getValue(),
"kind", "Kamelet");
- String from = extractTupleValue(source.getValue(), "name");
- String to = extractTupleValue(sink.getValue(), "name");
+ Node sourceRef = nodeAt(source, "/ref");
+ if (sourceRef != null) {
+ source = asMappingNode(sourceRef);
+ }
+ Node sinkRef = nodeAt(sink, "/ref");
+ if (sinkRef != null) {
+ sink = asMappingNode(sinkRef);
+ }
+ boolean sourceKamelet = sourceRef != null &&
anyTupleMatches(source.getValue(), "kind", "Kamelet");
+ boolean sinkKamelet = sinkRef != null &&
anyTupleMatches(sink.getValue(), "kind", "Kamelet");
+ String from = extractTupleValue(source.getValue(),
sourceKamelet ? "name" : "uri");
+ String to = extractTupleValue(sink.getValue(), sinkKamelet
? "name" : "uri");
if (sourceKamelet) {
from = "kamelet:" + from;
}
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 f1fdb83..b975b12 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
@@ -25,7 +25,7 @@ class KameletBindingLoaderTest extends YamlTestSupport {
context.start()
}
- def "kamelet binding"() {
+ def "kamelet binding from kamelet to kamelet"() {
when:
loadBindings('''
apiVersion: camel.apache.org/v1alpha1
@@ -58,4 +58,57 @@ class KameletBindingLoaderTest extends YamlTestSupport {
}
}
+ def "kamelet binding from uri to kamelet"() {
+ when:
+ loadBindings('''
+ apiVersion: camel.apache.org/v1alpha1
+ kind: KameletBinding
+ metadata:
+ name: timer-event-source
+ spec:
+ source:
+ uri: timer:foo
+ sink:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: log-sink
+ ''')
+ then:
+ context.routeDefinitions.size() == 2
+
+ with (context.routeDefinitions[0]) {
+ input.endpointUri == 'timer:foo'
+ outputs.size() == 1
+ with (outputs[0], ToDefinition) {
+ endpointUri == 'kamelet:log-sink'
+ }
+ }
+ }
+
+ def "kamelet binding from uri to uri"() {
+ when:
+ loadBindings('''
+ apiVersion: camel.apache.org/v1alpha1
+ kind: KameletBinding
+ metadata:
+ name: timer-event-source
+ spec:
+ source:
+ uri: timer:foo
+ sink:
+ uri: log:bar
+ ''')
+ then:
+ context.routeDefinitions.size() == 1
+
+ with (context.routeDefinitions[0]) {
+ input.endpointUri == 'timer:foo'
+ outputs.size() == 1
+ with (outputs[0], ToDefinition) {
+ endpointUri == 'log:bar'
+ }
+ }
+ }
+
}