You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/11/26 10:43:06 UTC
[camel-k-runtime] 10/18: YAML: add support for Resequence EIP
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
commit 882799a8730861e1830b4e588d01ee56cab66cd3
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Nov 24 16:44:46 2019 +0100
YAML: add support for Resequence EIP
---
.../k/loader/yaml/parser/ResequenceStepParser.java | 75 +++++++++++++++++++
.../k/loader/yaml/parser/ResequenceTest.groovy | 83 ++++++++++++++++++++++
2 files changed, 158 insertions(+)
diff --git a/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/ResequenceStepParser.java b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/ResequenceStepParser.java
new file mode 100644
index 0000000..400fffe
--- /dev/null
+++ b/camel-k-loader-yaml/src/main/java/org/apache/camel/k/loader/yaml/parser/ResequenceStepParser.java
@@ -0,0 +1,75 @@
+/*
+ * 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 com.fasterxml.jackson.annotation.JsonIgnore;
+import org.apache.camel.Expression;
+import org.apache.camel.k.annotation.yaml.YAMLStepParser;
+import org.apache.camel.k.loader.yaml.model.Step;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ResequenceDefinition;
+import org.apache.camel.model.config.BatchResequencerConfig;
+import org.apache.camel.model.config.StreamResequencerConfig;
+import org.apache.camel.reifier.ProcessorReifier;
+import org.apache.camel.reifier.ResequenceReifier;
+
+@YAMLStepParser("resequence")
+public class ResequenceStepParser implements ProcessorStepParser {
+ static {
+ ProcessorReifier.registerReifier(Definition.class, ResequenceReifier::new);
+ }
+
+ @Override
+ public ProcessorDefinition<?> toProcessor(Context context) {
+ Definition definition = context.node(Definition.class);
+
+ return StepParserSupport.convertSteps(
+ context,
+ definition,
+ definition.steps
+ );
+ }
+
+ public static final class Definition extends ResequenceDefinition implements HasExpression, Step.Definition {
+ public List<Step> steps;
+
+ @JsonIgnore
+ public void setExpression(Expression expression) {
+ super.setExpression(expression);
+ }
+
+ @JsonAlias("batch-config")
+ public void setBatchConfig(BatchResequencerConfig config) {
+ if (getResequencerConfig() != null) {
+ throw new IllegalArgumentException("And resequencer config has already been set");
+ }
+ setResequencerConfig(config);
+ }
+
+ @JsonAlias("stream-config")
+ public void setStreamConfig(StreamResequencerConfig config) {
+ if (getResequencerConfig() != null) {
+ throw new IllegalArgumentException("And resequencer config has already been set");
+ }
+ setResequencerConfig(config);
+ }
+ }
+}
+
diff --git a/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ResequenceTest.groovy b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ResequenceTest.groovy
new file mode 100644
index 0000000..78b4c7a
--- /dev/null
+++ b/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/parser/ResequenceTest.groovy
@@ -0,0 +1,83 @@
+/*
+ * 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.ResequenceDefinition
+import org.apache.camel.model.config.StreamResequencerConfig
+import org.apache.camel.model.language.SimpleExpression
+
+class ResequenceTest extends TestSupport {
+
+ def "definition with expression"() {
+ given:
+ def stepContext = stepContext('''
+ simple: "${in.header.seqnum}"
+ stream-config:
+ capacity: 5000
+ timeout: 4000
+ steps:
+ - to: "direct:a"
+ - to: "direct:b"
+ ''')
+ when:
+ def processor = new ResequenceStepParser().toProcessor(stepContext)
+ then:
+ with (processor, ResequenceDefinition) {
+ with (expression, SimpleExpression) {
+ language == 'simple'
+ expression == '${in.header.seqnum}'
+ }
+ with (streamConfig, StreamResequencerConfig) {
+ capacity == 5000
+ timeout == 4000
+ }
+
+ outputs.size() == 2
+ }
+ }
+
+ def "definition with expression block"() {
+ given:
+ def stepContext = stepContext('''
+ expression:
+ simple: "${in.header.seqnum}"
+ stream-config:
+ capacity: 5000
+ timeout: 4000
+ steps:
+ - to: "direct:a"
+ - to: "direct:b"
+ ''')
+ when:
+ def processor = new ResequenceStepParser().toProcessor(stepContext)
+ then:
+ with (processor, ResequenceDefinition) {
+ with (expression, SimpleExpression) {
+ language == 'simple'
+ expression == '${in.header.seqnum}'
+ }
+ with (streamConfig, StreamResequencerConfig) {
+ capacity == 5000
+ timeout == 4000
+ }
+
+ outputs.size() == 2
+ }
+ }
+
+}