This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 65d9ed1dce2446d5d26013f15f20818319de7e6b Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Dec 7 07:58:51 2021 +0100 CAMEL-17261: camel-yaml-dsl - Add support for loading Camel K KameletBinding file. WIP. --- .../camel/dsl/yaml/YamlRoutesBuilderLoader.java | 14 +++++ .../camel/dsl/yaml/KameletBindingLoaderTest.groovy | 5 +- .../resources/kamelets/error-handler.kamelet.yaml | 73 ++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 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 fa7ca59..2bd9348 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 @@ -36,6 +36,7 @@ import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.model.rest.VerbDefinition; import org.apache.camel.spi.CamelContextCustomizer; import org.apache.camel.spi.annotations.RoutesLoader; +import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.util.URISupport; import org.snakeyaml.engine.v2.nodes.MappingNode; import org.snakeyaml.engine.v2.nodes.Node; @@ -236,6 +237,19 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport { String ehName = asText(nt.getKeyNode()); if ("dead-letter-channel".equals(ehName)) { DeadLetterChannelBuilder dlcb = new DeadLetterChannelBuilder(); + + // endpoint + MappingNode endpoint = asMappingNode(nodeAt(nt.getValueNode(), "/endpoint")); + String dlq = extractCamelEndpointUri(endpoint); + dlcb.setDeadLetterUri(dlq); + + // properties (TODO: via reflection - need builder) + MappingNode prop = asMappingNode(nodeAt(nt.getValueNode(), "/parameters")); + Map<String, Object> params = asMap(prop); + if (params != null) { + IntrospectionSupport.setProperties(getCamelContext(), getCamelContext().getTypeConverter(), dlcb, params); + } + route.errorHandler(dlcb); } } 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 d80319e..b2f6c81 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 @@ -24,7 +24,7 @@ class KameletBindingLoaderTest extends YamlTestSupport { def doSetup() { context.start() } - +/* def "kamelet binding from kamelet to kamelet"() { when: loadBindings(''' @@ -244,6 +244,7 @@ class KameletBindingLoaderTest extends YamlTestSupport { when: // stub kafka for testing as it requires to setup connection to a real kafka broker + context.removeComponent("kafka") context.addComponent("kafka", context.getComponent("stub")) loadBindings(''' @@ -277,7 +278,7 @@ class KameletBindingLoaderTest extends YamlTestSupport { } } } - +*/ def "kamelet binding with error handler"() { when: diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/error-handler.kamelet.yaml b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/error-handler.kamelet.yaml new file mode 100644 index 0000000..7fcd6bd --- /dev/null +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/resources/kamelets/error-handler.kamelet.yaml @@ -0,0 +1,73 @@ +# --------------------------------------------------------------------------- +# 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: error-handler +spec: + definition: + title: "DLC and Log" + description: "Push an event to a kafka topic and log an error message" + required: + - kafka-brokers + - kafka-topic + - kafka-service-account-id + - kafka-service-account-secret + - log-message + properties: + kafka-brokers: + title: Kafka Brokers + description: the bootstrap server + type: string + example: "xyz-ins--rplssqfz-yyyyyyy-crojg.bf2.kafka.my-clud-service.com:443" + kafka-topic: + title: Kafka Topic + description: the DLC topic + type: string + example: "my-dlc" + kafka-service-account-id: + title: Service Account ID + description: the SA to use + type: string + example: "srvc-acct-xxxxxx-519b-453f-9f68-yyyyyyyyy" + kafka-service-account-secret: + title: Service Account Secret + description: the SA secrete to use + type: string + example: "xxxxxxxxx-46c7-4c6c-a753-yyyyyyyyyyyyyyy" + log-message: + title: Message + description: A message warning to log + type: string + example: "error while checking the source" + flow: + from: + uri: kamelet:source + steps: + # First step: send to the DLC for future processing + - to: + uri: kafka:{{kafka-topic}} + parameters: + brokers: "{{kafka-brokers}}" + security-protocol: SASL_SSL + sasl-mechanism: PLAIN + sasl-jaas-config: "org.apache.kafka.common.security.plain.PlainLoginModule required username={{kafka-service-account-id}} password={{kafka-service-account-secret}};" + # Log an error message to notify about the failure + - set-body: + constant: "{{log-message}} - worry not, the event is stored in the DLC" + - to: "log:error-sink"