You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/04/19 14:34:45 UTC

[camel-kamelets] branch master updated: Fix #145: allow kamelets of type action and doc

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git


The following commit(s) were added to refs/heads/master by this push:
     new a45e8e6  Fix #145: allow kamelets of type action and doc
a45e8e6 is described below

commit a45e8e65ecf536231218bbe1caf2f776c16f4e54
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Mon Apr 19 15:40:26 2021 +0200

    Fix #145: allow kamelets of type action and doc
---
 README.md                               |  3 ++-
 docs/generator/generator.go             | 38 +++++++++++++++++++++++++--------
 docs/modules/ROOT/pages/pdf-action.adoc |  9 +++++++-
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 759abe8..8187fca 100644
--- a/README.md
+++ b/README.md
@@ -21,12 +21,13 @@ Kamelets **MUST** be provided in the *Kubernetes YAML* format, i.e. they **MUST*
 
 The file name of each Kamelet **MUST** follow this specific pattern: `<kamelet-name>.kamelet.yaml`. The `<kamelet-name>` **MUST** match field `metadata` -> `name` inside the Kamelet YAML.
 
-For the time being, we'll accept only two kind of Kamelets:
+For the time being, we'll accept only these kinds of Kamelets:
 
 - **Sources**: Kamelets producing data that can be forwarded to any chosen destination. In the Camel jargon, a source can be used consumer-side.
 Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=source`.
 - **Sinks**: Kamelets that accept data with a specific datashape and forward it to an external system. In the Camel jargon, a sink can be used producer-side.
 Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=sink`.
+- **Actions**: Kamelets that can be used as intermediate steps as they both accept and produce data, applying transformations to it or changing the behavior of the whole integration flow (e.g. using enterprise integration patterns). Kamelets belonging to this category **MUST** be marked with label: `camel.apache.org/kamelet.type=action`.
 
 All Kamelets **MUST** provide a value for label `camel.apache.org/kamelet.type`.
 
diff --git a/docs/generator/generator.go b/docs/generator/generator.go
index 37bb9d0..1fefed3 100644
--- a/docs/generator/generator.go
+++ b/docs/generator/generator.go
@@ -77,7 +77,7 @@ func saveImage(k camel.Kamelet, out string) string {
 }
 
 func produceDoc(k camel.Kamelet, out string, image string) {
-	docFile := filepath.Join(out, "pages", k.Name + ".adoc")
+	docFile := filepath.Join(out, "pages", k.Name+".adoc")
 
 	content := "// THIS FILE IS AUTOMATICALLY GENERATED: DO NOT EDIT\n"
 	content += "= " + image + " " + k.Spec.Definition.Title + "\n"
@@ -118,7 +118,7 @@ func produceDoc(k camel.Kamelet, out string, image string) {
 		content += `[width="100%",cols="2,^2,3,^2,^2,^3",options="header"]` + "\n"
 		content += "|===\n"
 		content += tableLine("Property", "Name", "Description", "Type", "Default", "Example")
-		
+
 		for _, key := range keys {
 			prop := k.Spec.Definition.Properties[key]
 			name := key
@@ -159,7 +159,11 @@ func produceDoc(k camel.Kamelet, out string, image string) {
 		content += fmt.Sprintf("=== Knative %s\n", strings.Title(tp))
 		content += "\n"
 
-		content += fmt.Sprintf("The `%s` Kamelet can be used as Knative %s by binding it to a Knative object.\n", k.Name, tp)
+		if tp != "action" {
+			content += fmt.Sprintf("The `%s` Kamelet can be used as Knative %s by binding it to a Knative object.\n", k.Name, tp)
+		} else {
+			content += fmt.Sprintf("The `%s` Kamelet can be used as intermediate step in a binding.\n", k.Name)
+		}
 		content += "\n"
 
 		sampleConfig := make([]string, 0)
@@ -200,12 +204,28 @@ func produceDoc(k camel.Kamelet, out string, image string) {
       apiVersion: messaging.knative.dev/v1
       name: mychannel
 `
-
-		sourceRef := kameletRef
-		sinkRef := knativeRef
-		if tp == "sink" {
+		var sourceRef string
+		var sinkRef string
+		var steps string
+
+		switch tp {
+		case "source":
+			sourceRef = kameletRef
+			sinkRef = knativeRef
+		case "sink":
 			sourceRef = knativeRef
 			sinkRef = kameletRef
+		case "action":
+			sourceRef = `    ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
+      name: timer-source
+    properties:
+      message: "Hello"`
+			sinkRef = knativeRef
+			steps = fmt.Sprintf(`
+  steps:
+  -%s`, kameletRef[3:])
 		}
 
 		binding := fmt.Sprintf(`apiVersion: camel.apache.org/v1alpha1
@@ -214,9 +234,9 @@ metadata:
   name: %s-binding
 spec:
   source:
-%s  sink:
+%s%s  sink:
 %s
-`, k.Name, sourceRef, sinkRef)
+`, k.Name, sourceRef, steps, sinkRef)
 
 		content += fmt.Sprintf(".%s-binding.yaml\n", k.Name)
 		content += "[source,yaml]\n"
diff --git a/docs/modules/ROOT/pages/pdf-action.adoc b/docs/modules/ROOT/pages/pdf-action.adoc
index 08bb9ee..b55f5a5 100644
--- a/docs/modules/ROOT/pages/pdf-action.adoc
+++ b/docs/modules/ROOT/pages/pdf-action.adoc
@@ -24,7 +24,7 @@ This section summarizes how the `pdf-action` can be used in various contexts.
 
 === Knative Action
 
-The `pdf-action` Kamelet can be used as Knative action by binding it to a Knative object.
+The `pdf-action` Kamelet can be used as intermediate step in a binding.
 
 .pdf-action-binding.yaml
 [source,yaml]
@@ -38,6 +38,13 @@ spec:
     ref:
       kind: Kamelet
       apiVersion: camel.apache.org/v1alpha1
+      name: timer-source
+    properties:
+      message: "Hello"
+  steps:
+  - ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
       name: pdf-action
   sink:
     ref: