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/08/30 07:53:02 UTC
[camel] branch camel-4.0.x updated: CAMEL-19805: Support IntegrationSpec as part of Pipe/KameletBinding resources (#11236) (#11238)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.0.x by this push:
new 72b7f72d2f2 CAMEL-19805: Support IntegrationSpec as part of Pipe/KameletBinding resources (#11236) (#11238)
72b7f72d2f2 is described below
commit 72b7f72d2f297293afdd75225138669dfee47bfb
Author: Christoph Deppisch <cd...@redhat.com>
AuthorDate: Wed Aug 30 09:52:56 2023 +0200
CAMEL-19805: Support IntegrationSpec as part of Pipe/KameletBinding resources (#11236) (#11238)
- Enhance YAML DSL to support Integration specification as part of a pipe/binding
- Integration spec adds configuration, traits and dependencies to the pipe/binding
---
.../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 33 +++++++--
.../KameletBindingLoaderIntegrationSpecTest.groovy | 86 ++++++++++++++++++++++
.../dsl/yaml/PipeLoaderIntegrationSpecTest.groovy | 86 ++++++++++++++++++++++
3 files changed, 198 insertions(+), 7 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 ed2883dd982..a3239d737ae 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
@@ -318,31 +318,44 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
* Camel K Integration file
*/
private Object preConfigureIntegration(Node root, YamlDeserializationContext ctx, Object target, boolean preParse) {
+ Node spec = nodeAt(root, "/spec");
+ if (spec != null) {
+ return preConfigureIntegrationSpec(spec, ctx, target, preParse);
+ } else {
+ return new ArrayList<>();
+ }
+ }
+
+ /**
+ * Camel K Integration spec
+ */
+ private List<Object> preConfigureIntegrationSpec(
+ Node root, YamlDeserializationContext ctx, Object target, boolean preParse) {
// when in pre-parse phase then we only want to gather spec/dependencies,spec/configuration,spec/traits
List<Object> answer = new ArrayList<>();
// if there are dependencies then include them first
- Node deps = nodeAt(root, "/spec/dependencies");
+ Node deps = nodeAt(root, "/dependencies");
if (deps != null) {
var dep = preConfigureDependencies(deps);
answer.add(dep);
}
// if there are configurations then include them early
- Node configuration = nodeAt(root, "/spec/configuration");
+ Node configuration = nodeAt(root, "/configuration");
if (configuration != null) {
var list = preConfigureConfiguration(ctx.getResource(), configuration);
answer.addAll(list);
}
// if there are trait configuration then include them early
- configuration = nodeAt(root, "/spec/traits/camel");
+ configuration = nodeAt(root, "/traits/camel");
if (configuration != null) {
var list = preConfigureTraitConfiguration(ctx.getResource(), configuration);
answer.addAll(list);
}
// if there are trait environment then include them early
- configuration = nodeAt(root, "/spec/traits/environment");
+ configuration = nodeAt(root, "/traits/environment");
if (configuration != null) {
var list = preConfigureTraitEnvironment(ctx.getResource(), configuration);
answer.addAll(list);
@@ -350,15 +363,15 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
if (!preParse) {
// if there are sources then include them before routes
- Node sources = nodeAt(root, "/spec/sources");
+ Node sources = nodeAt(root, "/sources");
if (sources != null) {
var list = preConfigureSources(sources);
answer.addAll(list);
}
// add routes last
- Node routes = nodeAt(root, "/spec/flows");
+ Node routes = nodeAt(root, "/flows");
if (routes == null) {
- routes = nodeAt(root, "/spec/flow");
+ routes = nodeAt(root, "/flow");
}
if (routes != null) {
// routes should be an array
@@ -623,6 +636,12 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport {
}
}
+ // Pipe may hold an integration spec
+ Node integration = nodeAt(root, "/spec/integration");
+ if (integration != null) {
+ answer.addAll(preConfigureIntegrationSpec(integration, ctx, target, preParse));
+ }
+
if (!preParse) {
// start with a route
final RouteDefinition route = new RouteDefinition();
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
new file mode 100644
index 00000000000..886060e24ad
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/KameletBindingLoaderIntegrationSpecTest.groovy
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+package org.apache.camel.dsl.yaml
+
+import org.apache.camel.dsl.yaml.support.YamlTestSupport
+import org.apache.camel.spi.DependencyStrategy
+
+class KameletBindingLoaderIntegrationSpecTest extends YamlTestSupport {
+
+ var Set<String> deps = new LinkedHashSet<>()
+
+ @Override
+ def doSetup() {
+ context.registry.bind("myDep", new DependencyStrategy() {
+ @Override
+ void onDependency(String dependency) {
+ deps.add(dependency);
+ }
+ })
+
+ context.start()
+ }
+
+ def "binding with integration spec"() {
+ when:
+ loadBindings('''
+ apiVersion: camel.apache.org/v1alpha1
+ kind: KameletBinding
+ metadata:
+ name: timer-event-source
+ spec:
+ integration:
+ dependencies:
+ - "camel:cloudevents"
+ traits:
+ camel:
+ configuration:
+ properties:
+ - "foo=howdy"
+ - "bar=123"
+ environment:
+ configuration:
+ vars:
+ - "MY_ENV=cheese"
+ source:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: timer-source
+ properties:
+ message: "Hello world!"
+ sink:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: log-sink
+ ''')
+ then:
+ context.routeDefinitions.size() == 3
+
+ context.resolvePropertyPlaceholders("{{foo}}") == "howdy"
+ context.resolvePropertyPlaceholders("{{bar}}") == "123"
+ context.resolvePropertyPlaceholders("{{MY_ENV}}") == "cheese"
+
+ with(deps) {
+ deps.contains("camel:core")
+ deps.contains("camel:kamelet")
+ deps.contains("camel:cloudevents")
+ }
+ }
+
+}
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
new file mode 100644
index 00000000000..327f43cfbb3
--- /dev/null
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/PipeLoaderIntegrationSpecTest.groovy
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+package org.apache.camel.dsl.yaml
+
+import org.apache.camel.dsl.yaml.support.YamlTestSupport
+import org.apache.camel.spi.DependencyStrategy
+
+class PipeLoaderIntegrationSpecTest extends YamlTestSupport {
+
+ var Set<String> deps = new LinkedHashSet<>()
+
+ @Override
+ def doSetup() {
+ context.registry.bind("myDep", new DependencyStrategy() {
+ @Override
+ void onDependency(String dependency) {
+ deps.add(dependency);
+ }
+ })
+
+ context.start()
+ }
+
+ def "Pipe with integration spec"() {
+ when:
+ loadBindings('''
+ apiVersion: camel.apache.org/v1
+ kind: Pipe
+ metadata:
+ name: timer-event-source
+ spec:
+ integration:
+ dependencies:
+ - "camel:cloudevents"
+ traits:
+ camel:
+ configuration:
+ properties:
+ - "foo=howdy"
+ - "bar=123"
+ environment:
+ configuration:
+ vars:
+ - "MY_ENV=cheese"
+ source:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: timer-source
+ properties:
+ message: "Hello world!"
+ sink:
+ ref:
+ kind: Kamelet
+ apiVersion: camel.apache.org/v1
+ name: log-sink
+ ''')
+ then:
+ context.routeDefinitions.size() == 3
+
+ context.resolvePropertyPlaceholders("{{foo}}") == "howdy"
+ context.resolvePropertyPlaceholders("{{bar}}") == "123"
+ context.resolvePropertyPlaceholders("{{MY_ENV}}") == "cheese"
+
+ with(deps) {
+ deps.contains("camel:core")
+ deps.contains("camel:kamelet")
+ deps.contains("camel:cloudevents")
+ }
+ }
+
+}