This is an automated email from the ASF dual-hosted git repository.
tsato pushed a commit to branch release-1.8.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit d92643a0101b959abae9794baf0ad00725e6c4ea
Author: Adriano Machado <unknown>
AuthorDate: Fri May 27 18:20:25 2022 -0400
Detect wire tap EIP endpoints
---
examples/wiretap/README.md | 3 +++
examples/wiretap/WireTap.java | 36 +++++++++++++++++++++++++++
pkg/util/source/inspector.go | 2 ++
pkg/util/source/inspector_groovy.go | 2 ++
pkg/util/source/inspector_groovy_test.go | 9 +++++++
pkg/util/source/inspector_java_script.go | 2 ++
pkg/util/source/inspector_java_script_test.go | 9 +++++++
pkg/util/source/inspector_java_source.go | 1 +
pkg/util/source/inspector_java_source_test.go | 9 +++++++
pkg/util/source/inspector_kotlin.go | 1 +
pkg/util/source/inspector_kotlin_test.go | 9 +++++++
pkg/util/source/inspector_xml.go | 2 +-
pkg/util/source/inspector_xml_test.go | 13 ++++++++++
pkg/util/source/inspector_yaml.go | 2 +-
pkg/util/source/inspector_yaml_test.go | 36 +++++++++++++++++++++++++++
15 files changed, 134 insertions(+), 2 deletions(-)
diff --git a/examples/wiretap/README.md b/examples/wiretap/README.md
new file mode 100644
index 000000000..daed2a363
--- /dev/null
+++ b/examples/wiretap/README.md
@@ -0,0 +1,3 @@
+# Camel K WireTap example
+
+Find useful examples about how use a "WireTap" EIP in a Camel K integration.
diff --git a/examples/wiretap/WireTap.java b/examples/wiretap/WireTap.java
new file mode 100644
index 000000000..556b524d5
--- /dev/null
+++ b/examples/wiretap/WireTap.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+// To run this integrations use:
+//
+// kamel run WireTap.java --dev
+//
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class WireTap extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("timer:tick")
+ .wireTap("direct:tap")
+ .log("Hello from the timer!");
+
+ from("direct:tap")
+ .log("Hello from the tap!");
+ }
+}
diff --git a/pkg/util/source/inspector.go b/pkg/util/source/inspector.go
index 197ac7cb0..110598e2b 100644
--- a/pkg/util/source/inspector.go
+++ b/pkg/util/source/inspector.go
@@ -40,9 +40,11 @@ var (
singleQuotedTo =
regexp.MustCompile(`\.to\s*\(\s*'([a-zA-Z0-9-]+:[^']+)'`)
singleQuotedToD =
regexp.MustCompile(`\.toD\s*\(\s*'([a-zA-Z0-9-]+:[^']+)'`)
singleQuotedToF =
regexp.MustCompile(`\.toF\s*\(\s*'([a-zA-Z0-9-]+:[^']+)'`)
+ singleQuotedWireTap =
regexp.MustCompile(`\.wireTap\s*\(\s*'([a-zA-Z0-9-]+:[^']+)'`)
doubleQuotedTo =
regexp.MustCompile(`\.to\s*\(\s*"([a-zA-Z0-9-]+:[^"]+)"`)
doubleQuotedToD =
regexp.MustCompile(`\.toD\s*\(\s*"([a-zA-Z0-9-]+:[^"]+)"`)
doubleQuotedToF =
regexp.MustCompile(`\.toF\s*\(\s*"([a-zA-Z0-9-]+:[^"]+)"`)
+ doubleQuotedWireTap =
regexp.MustCompile(`\.wireTap\s*\(\s*"([a-zA-Z0-9-]+:[^"]+)"`)
languageRegexp =
regexp.MustCompile(`language\s*\(\s*["|']([a-zA-Z0-9-]+[^"|']+)["|']\s*,.*\)`)
camelTypeRegexp =
regexp.MustCompile(`.*(org.apache.camel.*Component|DataFormat|Language)`)
jsonLibraryRegexp = regexp.MustCompile(`.*JsonLibrary\.Jackson.*`)
diff --git a/pkg/util/source/inspector_groovy.go
b/pkg/util/source/inspector_groovy.go
index 318107862..686814084 100644
--- a/pkg/util/source/inspector_groovy.go
+++ b/pkg/util/source/inspector_groovy.go
@@ -42,6 +42,8 @@ func (i GroovyInspector) Extract(source v1.SourceSpec, meta
*Metadata) error {
doubleQuotedToD,
singleQuotedToF,
doubleQuotedToF,
+ singleQuotedWireTap,
+ doubleQuotedWireTap,
)
meta.FromURIs = append(meta.FromURIs, from...)
diff --git a/pkg/util/source/inspector_groovy_test.go
b/pkg/util/source/inspector_groovy_test.go
index 7f091f3b8..d0d2a5e80 100644
--- a/pkg/util/source/inspector_groovy_test.go
+++ b/pkg/util/source/inspector_groovy_test.go
@@ -48,6 +48,11 @@ from("direct:start")
.to('kamelet:foo/bar?baz=test')
`
+const GroovyWireTapEipSingleQuote = `
+from("direct:start")
+ .wireTap('kamelet:foo/bar?baz=test')
+`
+
func TestGroovyKamelet(t *testing.T) {
tc := []struct {
source string
@@ -69,6 +74,10 @@ func TestGroovyKamelet(t *testing.T) {
source: GroovyKameletEndpointSingleQuote,
kamelets: []string{"foo/bar"},
},
+ {
+ source: GroovyWireTapEipSingleQuote,
+ kamelets: []string{"foo/bar"},
+ },
}
for i := range tc {
diff --git a/pkg/util/source/inspector_java_script.go
b/pkg/util/source/inspector_java_script.go
index d8679e0c9..ebcbe37bb 100644
--- a/pkg/util/source/inspector_java_script.go
+++ b/pkg/util/source/inspector_java_script.go
@@ -42,6 +42,8 @@ func (i JavaScriptInspector) Extract(source v1.SourceSpec,
meta *Metadata) error
doubleQuotedToD,
singleQuotedToF,
doubleQuotedToF,
+ singleQuotedWireTap,
+ doubleQuotedWireTap,
)
meta.FromURIs = append(meta.FromURIs, from...)
diff --git a/pkg/util/source/inspector_java_script_test.go
b/pkg/util/source/inspector_java_script_test.go
index f9e1634a6..3ed09d928 100644
--- a/pkg/util/source/inspector_java_script_test.go
+++ b/pkg/util/source/inspector_java_script_test.go
@@ -37,6 +37,11 @@ from("direct:start")
.to("kamelet:foo/bar?baz=test")
`
+const JavaScriptWireTapEipSingleQuote = `
+from("direct:start")
+ .wireTap('kamelet:foo/bar?baz=test')
+`
+
func TestJavaScriptKamelet(t *testing.T) {
tc := []struct {
source string
@@ -50,6 +55,10 @@ func TestJavaScriptKamelet(t *testing.T) {
source: JavaScriptKameletEndpoint,
kamelets: []string{"foo/bar"},
},
+ {
+ source: JavaScriptWireTapEipSingleQuote,
+ kamelets: []string{"foo/bar"},
+ },
}
for i := range tc {
diff --git a/pkg/util/source/inspector_java_source.go
b/pkg/util/source/inspector_java_source.go
index 80981e74b..00a9f391f 100644
--- a/pkg/util/source/inspector_java_source.go
+++ b/pkg/util/source/inspector_java_source.go
@@ -37,6 +37,7 @@ func (i JavaSourceInspector) Extract(source v1.SourceSpec,
meta *Metadata) error
doubleQuotedTo,
doubleQuotedToD,
doubleQuotedToF,
+ doubleQuotedWireTap,
)
meta.FromURIs = append(meta.FromURIs, from...)
diff --git a/pkg/util/source/inspector_java_source_test.go
b/pkg/util/source/inspector_java_source_test.go
index 353643130..af1a8e3af 100644
--- a/pkg/util/source/inspector_java_source_test.go
+++ b/pkg/util/source/inspector_java_source_test.go
@@ -37,6 +37,11 @@ from("direct:start")
.to("kamelet:foo/bar?baz=test")
`
+const JavaSourceWireTapEip = `
+from("direct:start")
+ .wireTap("kamelet:foo/bar?baz=test")
+`
+
func TestJavaSourceKamelet(t *testing.T) {
tc := []struct {
source string
@@ -50,6 +55,10 @@ func TestJavaSourceKamelet(t *testing.T) {
source: JavaSourceKameletEndpoint,
kamelets: []string{"foo/bar"},
},
+ {
+ source: JavaSourceWireTapEip,
+ kamelets: []string{"foo/bar"},
+ },
}
for i := range tc {
diff --git a/pkg/util/source/inspector_kotlin.go
b/pkg/util/source/inspector_kotlin.go
index b2485c29b..753d0dbbf 100644
--- a/pkg/util/source/inspector_kotlin.go
+++ b/pkg/util/source/inspector_kotlin.go
@@ -37,6 +37,7 @@ func (i KotlinInspector) Extract(source v1.SourceSpec, meta
*Metadata) error {
doubleQuotedTo,
doubleQuotedToD,
doubleQuotedToF,
+ doubleQuotedWireTap,
)
meta.FromURIs = append(meta.FromURIs, from...)
diff --git a/pkg/util/source/inspector_kotlin_test.go
b/pkg/util/source/inspector_kotlin_test.go
index d94ee7fd9..1b08fe2b3 100644
--- a/pkg/util/source/inspector_kotlin_test.go
+++ b/pkg/util/source/inspector_kotlin_test.go
@@ -37,6 +37,11 @@ from("direct:start")
.to("kamelet:foo/bar?baz=test")
`
+const KotlinWireTapEip = `
+from("direct:start")
+ .wireTap("kamelet:foo/bar?baz=test")
+`
+
func TestKotlinKamelet(t *testing.T) {
tc := []struct {
source string
@@ -50,6 +55,10 @@ func TestKotlinKamelet(t *testing.T) {
source: KotlinKameletEndpoint,
kamelets: []string{"foo/bar"},
},
+ {
+ source: KotlinWireTapEip,
+ kamelets: []string{"foo/bar"},
+ },
}
for i := range tc {
diff --git a/pkg/util/source/inspector_xml.go b/pkg/util/source/inspector_xml.go
index 18c48277c..51baaee24 100644
--- a/pkg/util/source/inspector_xml.go
+++ b/pkg/util/source/inspector_xml.go
@@ -62,7 +62,7 @@ func (i XMLInspector) Extract(source v1.SourceSpec, meta
*Metadata) error {
meta.FromURIs =
append(meta.FromURIs, a.Value)
}
}
- case "to", "toD", "toF":
+ case "to", "toD", "toF", "wireTap":
for _, a := range se.Attr {
if a.Name.Local == "uri" {
meta.ToURIs =
append(meta.ToURIs, a.Value)
diff --git a/pkg/util/source/inspector_xml_test.go
b/pkg/util/source/inspector_xml_test.go
index 52445e820..8552a84b7 100644
--- a/pkg/util/source/inspector_xml_test.go
+++ b/pkg/util/source/inspector_xml_test.go
@@ -46,6 +46,15 @@ const XMLKameletEndpoint = `
</camelContext>
`
+const XMLWireTapEndpoint = `
+<camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <wireTap uri="kamelet:foo/bar?baz=test"/>
+ </route>
+</camelContext>
+`
+
func TestXMLKamelet(t *testing.T) {
tc := []struct {
source string
@@ -59,6 +68,10 @@ func TestXMLKamelet(t *testing.T) {
source: XMLKameletEndpoint,
kamelets: []string{"foo/bar"},
},
+ {
+ source: XMLWireTapEndpoint,
+ kamelets: []string{"foo/bar"},
+ },
}
for i := range tc {
diff --git a/pkg/util/source/inspector_yaml.go
b/pkg/util/source/inspector_yaml.go
index bf2bc6122..2f0ed3745 100644
--- a/pkg/util/source/inspector_yaml.go
+++ b/pkg/util/source/inspector_yaml.go
@@ -161,7 +161,7 @@ func (i YAMLInspector) parseStep(key string, content
interface{}, meta *Metadata
switch key {
case "from":
meta.FromURIs = append(meta.FromURIs, maybeURI)
- case "to", "to-d":
+ case "to", "to-d", "toD", "wire-tap", "wireTap":
meta.ToURIs = append(meta.ToURIs, maybeURI)
}
}
diff --git a/pkg/util/source/inspector_yaml_test.go
b/pkg/util/source/inspector_yaml_test.go
index 88d77d5ba..1a85b1fd5 100644
--- a/pkg/util/source/inspector_yaml_test.go
+++ b/pkg/util/source/inspector_yaml_test.go
@@ -83,6 +83,26 @@ const YAMLInDepthChannel = `
uri: knative:endpoint/service
`
+const YAMLWireTapKnativeEIP = `
+- from:
+ uri: knative:channel/mychannel
+ parameters:
+ period: "1000"
+ steps:
+ - wireTap:
+ uri: knative:channel/mychannel
+`
+
+const YAMLWireTapJmsEIP = `
+- from:
+ uri: knative:channel/mychannel
+ parameters:
+ period: "1000"
+ steps:
+ - wireTap:
+ uri: jms:queue:foo
+`
+
func TestYAMLDependencies(t *testing.T) {
tests := []struct {
name string
@@ -125,6 +145,22 @@ func TestYAMLDependencies(t *testing.T) {
`mvn:org.apache.camel.k:camel-k-knative-consumer`,
},
},
+ {
+ name: "wire-tap-knative",
+ source: YAMLWireTapKnativeEIP,
+ dependencies: []string{
+
`mvn:org.apache.camel.k:camel-k-knative-producer`,
+
`mvn:org.apache.camel.k:camel-k-knative-consumer`,
+ },
+ },
+ {
+ name: "wire-tap-jms",
+ source: YAMLWireTapJmsEIP,
+ dependencies: []string{
+
`mvn:org.apache.camel.k:camel-k-knative-consumer`,
+ `camel:jms`,
+ },
+ },
}
for i := range tests {
test := tests[i]