This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push:
new 26ffee5 Add more EIPS to YAML DSL (#303)
26ffee5 is described below
commit 26ffee5348ee79e0192575a1afc4c62ebb8b8a58
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Apr 17 10:39:44 2020 +0200
Add more EIPS to YAML DSL (#303)
---
camel-k-loader-yaml/README.adoc | 7 +-
.../k/loader/yaml/parser/DoTryStepParser.java | 110 +++++++++++++
.../camel/k/loader/yaml/parser/DoTryTest.groovy | 171 +++++++++++++++++++++
3 files changed, 284 insertions(+), 4 deletions(-)
diff --git a/camel-k-loader-yaml/README.adoc b/camel-k-loader-yaml/README.adoc
index 8566e7c..1956eba 100644
--- a/camel-k-loader-yaml/README.adoc
+++ b/camel-k-loader-yaml/README.adoc
@@ -2,10 +2,7 @@
This artifact provides a YAML based DSL for Apache Camel and Apache Camel K.
-[WARNING]
-====
-Experimental
-====
+The YAML DSL is current in preview support level.
== Defining a route
@@ -161,10 +158,12 @@ In case you want to use the data-format's default
settings, you need to place an
- To
- To Dynamic
- Transform
+- Try Catch Finally
- Unmarshal
- Validate
- Wire Tap
+The Try Catch Finally EIP currently only support specifying one `do-catch`
clause.
== Extending the DSL
diff --git
a/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/DoTryStepParser.java
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/DoTryStepParser.java
new file mode 100644
index 0000000..96c55c4
--- /dev/null
+++
b/camel-k-loader-yaml/camel-k-loader-yaml-common/src/main/java/org/apache/camel/k/loader/yaml/parser/DoTryStepParser.java
@@ -0,0 +1,110 @@
+/*
+ * 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.k.loader.yaml.parser;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonAlias;
+import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.k.loader.yaml.model.Step;
+import org.apache.camel.model.CatchDefinition;
+import org.apache.camel.model.FinallyDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.TryDefinition;
+import org.apache.camel.model.WhenDefinition;
+import org.apache.camel.reifier.CatchReifier;
+import org.apache.camel.reifier.FinallyReifier;
+import org.apache.camel.reifier.TryReifier;
+
+@YAMLStepParser("do-try")
+public class DoTryStepParser implements ProcessorStepParser {
+ @Override
+ public ProcessorDefinition<?> toProcessor(Context context) {
+ DoTryDefinition definition = context.node(DoTryDefinition.class);
+
+ ProcessorDefinition<?> processor = StepParserSupport.convertSteps(
+ context,
+ definition.delegate,
+ definition.steps
+ );
+
+ if (definition.doCatch != null) {
+ StepParserSupport.convertSteps(
+ context,
+ definition.doCatch,
+ definition.doCatch.steps
+ );
+
+ CatchDefinition cd = new CatchDefinition();
+ cd.setExceptions(definition.doCatch.getExceptions());
+ cd.setOutputs(definition.doCatch.getOutputs());
+ // doCatch.when
+ if (definition.doCatch.when != null) {
+ StepParserSupport.convertSteps(
+ context,
+ cd.onWhen(definition.doCatch.when.getExpression()),
+ definition.doCatch.when.steps
+ );
+ cd.setOnWhen(definition.doCatch.when);
+ }
+
+ processor.addOutput(cd);
+ }
+
+ if (definition.doFinally != null) {
+ StepParserSupport.convertSteps(
+ context,
+ definition.doFinally,
+ definition.doFinally.steps
+ );
+
+ FinallyDefinition fd = new FinallyDefinition();
+ fd.setOutputs(definition.doFinally.getOutputs());
+ processor.addOutput(fd);
+ }
+
+ return processor;
+ }
+
+ @YAMLNodeDefinition(reifiers = TryReifier.class)
+ public static final class DoTryDefinition {
+ public TryDefinition delegate = new TryDefinition();
+ public List<Step> steps;
+ @JsonAlias({"do-catch"})
+ public DoCatchDefinition doCatch;
+ @JsonAlias({"do-finally"})
+ public DoFinallyDefinition doFinally;
+ }
+
+ @YAMLNodeDefinition(reifiers = CatchReifier.class)
+ public static final class DoCatchDefinition extends CatchDefinition {
+ @JsonAlias({"when"})
+ public When when;
+ public List<Step> steps;
+
+ public static final class When extends WhenDefinition implements
HasExpression {
+ public List<Step> steps;
+ }
+ }
+
+ @YAMLNodeDefinition(reifiers = FinallyReifier.class)
+ public static final class DoFinallyDefinition extends FinallyDefinition {
+ public List<Step> steps;
+ }
+}
+
diff --git
a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/DoTryTest.groovy
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/DoTryTest.groovy
new file mode 100644
index 0000000..0d2e8c9
--- /dev/null
+++
b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/DoTryTest.groovy
@@ -0,0 +1,171 @@
+/*
+ * 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.k.loader.yaml.parser
+
+import org.apache.camel.k.loader.yaml.TestSupport
+import org.apache.camel.model.TryDefinition
+
+class DoTryTest extends TestSupport {
+
+ def "definition doCatch"() {
+ given:
+ def stepContext = stepContext('''
+ steps:
+ - to:
+ uri: "log:when-a"
+ - to:
+ uri: "log:when-b"
+ do-catch:
+ exceptions:
+ - "java.io.FileNotFoundException"
+ - "java.io.IOException"
+ steps:
+ - to:
+ uri: "log:io-error"
+ ''')
+ when:
+ def processor = new DoTryStepParser().toProcessor(stepContext)
+ then:
+ with(processor, TryDefinition) {
+ outputs.size() == 3
+ catchClauses.size() == 1
+ catchClauses[0].outputs.size() == 1
+ catchClauses[0].exceptions.size() == 2
+ finallyClause == null
+ }
+ }
+
+ def "definition doCatchOnWhen"() {
+ given:
+ def stepContext = stepContext('''
+ steps:
+ - to:
+ uri: "log:when-a"
+ - to:
+ uri: "log:when-b"
+ do-catch:
+ exceptions:
+ - "java.io.FileNotFoundException"
+ - "java.io.IOException"
+ when:
+ simple: "${body.size()} == 1"
+ steps:
+ - to:
+ uri: "log:io-error"
+ ''')
+ when:
+ def processor = new DoTryStepParser().toProcessor(stepContext)
+ then:
+ with(processor, TryDefinition) {
+ outputs.size() == 3
+ catchClauses.size() == 1
+ catchClauses[0].outputs.size() == 1
+ catchClauses[0].exceptions.size() == 2
+ finallyClause == null
+ }
+ }
+
+ def "definition doCatchOnWhenFinally"() {
+ given:
+ def stepContext = stepContext('''
+ steps:
+ - to:
+ uri: "log:when-a"
+ - to:
+ uri: "log:when-b"
+ do-catch:
+ exceptions:
+ - "java.io.FileNotFoundException"
+ - "java.io.IOException"
+ when:
+ simple: "${body.size()} == 1"
+ steps:
+ - to:
+ uri: "log:io-error"
+ do-finally:
+ steps:
+ - to:
+ uri: "log:finally"
+ ''')
+ when:
+ def processor = new DoTryStepParser().toProcessor(stepContext)
+ then:
+ with(processor, TryDefinition) {
+ outputs.size() == 4
+ catchClauses.size() == 1
+ catchClauses[0].outputs.size() == 1
+ catchClauses[0].exceptions.size() == 2
+ finallyClause.outputs.size() == 1
+ }
+ }
+
+ def "definition doCatchFinally"() {
+ given:
+ def stepContext = stepContext('''
+ steps:
+ - to:
+ uri: "log:when-a"
+ - to:
+ uri: "log:when-b"
+ do-catch:
+ exceptions:
+ - "java.io.FileNotFoundException"
+ - "java.io.IOException"
+ steps:
+ - to:
+ uri: "log:io-error"
+ do-finally:
+ steps:
+ - to:
+ uri: "log:finally"
+ ''')
+ when:
+ def processor = new DoTryStepParser().toProcessor(stepContext)
+ then:
+ with(processor, TryDefinition) {
+ outputs.size() == 4
+ catchClauses.size() == 1
+ catchClauses[0].outputs.size() == 1
+ catchClauses[0].exceptions.size() == 2
+ finallyClause.outputs.size() == 1
+ }
+ }
+
+ def "definition doFinally"() {
+ given:
+ def stepContext = stepContext('''
+ steps:
+ - to:
+ uri: "log:when-a"
+ - to:
+ uri: "log:when-b"
+ do-finally:
+ steps:
+ - to:
+ uri: "log:finally"
+ ''')
+ when:
+ def processor = new DoTryStepParser().toProcessor(stepContext)
+ then:
+ with(processor, TryDefinition) {
+ outputs.size() == 3
+ catchClauses.size() == 0
+ finallyClause.outputs.size() == 1
+ }
+ }
+
+}