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 2022/10/14 12:02:41 UTC

[camel-kamelets] branch headers-doc created (now 8b84ce0b)

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

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


      at 8b84ce0b Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet

This branch includes the following new commits:

     new 3a11a263 Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet
     new 8b84ce0b Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel-kamelets] 02/02: Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8b84ce0b652c61614538444bd1ce59cdef90d0eb
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Oct 14 13:58:54 2022 +0200

    Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 library/camel-kamelets-catalog/pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/library/camel-kamelets-catalog/pom.xml b/library/camel-kamelets-catalog/pom.xml
index 5cccffdf..6954a939 100644
--- a/library/camel-kamelets-catalog/pom.xml
+++ b/library/camel-kamelets-catalog/pom.xml
@@ -115,13 +115,13 @@
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-tooling-model</artifactId>
-            <version>3.19.0</version>
+            <version>${camel.version}</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-catalog</artifactId>
-            <version>3.19.0</version>
+            <version>${camel.version}</version>
             <scope>compile</scope>
         </dependency>
 


[camel-kamelets] 01/02: Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3a11a263c4b49effede764f32ae2c71f51687087
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Oct 14 13:53:17 2022 +0200

    Added a Catalog Method showing the supported headers (specific for consumer, producer and common) for a Kamelet
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 library/camel-kamelets-catalog/pom.xml             | 12 ++++
 .../camel/kamelets/catalog/KameletsCatalog.java    | 64 ++++++++++++++++++----
 .../catalog/model/KameletPrefixSchemeEnum.java     | 44 +++++++++++++++
 .../kamelets/catalog/KameletsCatalogTest.java      | 13 +++++
 4 files changed, 121 insertions(+), 12 deletions(-)

diff --git a/library/camel-kamelets-catalog/pom.xml b/library/camel-kamelets-catalog/pom.xml
index f13550ba..5cccffdf 100644
--- a/library/camel-kamelets-catalog/pom.xml
+++ b/library/camel-kamelets-catalog/pom.xml
@@ -112,6 +112,18 @@
             <scope>test</scope>
             <version>${junit.jupiter.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-tooling-model</artifactId>
+            <version>3.19.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-catalog</artifactId>
+            <version>3.19.0</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 </project>
diff --git a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java
index f298b56f..25eb47a5 100644
--- a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java
+++ b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/KameletsCatalog.java
@@ -18,12 +18,7 @@ package org.apache.camel.kamelets.catalog;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -34,8 +29,13 @@ import io.fabric8.camelk.v1alpha1.JSONSchemaProps;
 import io.github.classgraph.ClassGraph;
 import io.github.classgraph.Resource;
 import io.github.classgraph.ScanResult;
+import org.apache.camel.catalog.DefaultCamelCatalog;
 import org.apache.camel.kamelets.catalog.model.KameletAnnotationsNames;
 import org.apache.camel.kamelets.catalog.model.KameletLabelNames;
+import org.apache.camel.kamelets.catalog.model.KameletPrefixSchemeEnum;
+import org.apache.camel.kamelets.catalog.model.KameletTypeEnum;
+import org.apache.camel.tooling.model.ComponentModel;
+import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,6 +48,7 @@ public class KameletsCatalog {
 
     private final Map<String, Kamelet> kameletModels;
     private final List<String> kameletNames;
+    private final DefaultCamelCatalog cc = new DefaultCamelCatalog();
 
     public KameletsCatalog() {
         kameletModels = initCatalog();
@@ -65,9 +66,9 @@ public class KameletsCatalog {
                     Kamelet kamelet = MAPPER.readValue(is, Kamelet.class);
 
                     LOG.debug("Loading kamelet from: {}, path: {}, name: {}",
-                        resource.getClasspathElementFile(),
-                        resource.getPath(),
-                        name);
+                            resource.getClasspathElementFile(),
+                            resource.getPath(),
+                            name);
 
                     kameletModels.put(name, kamelet);
                 } catch (IOException e) {
@@ -123,7 +124,7 @@ public class KameletsCatalog {
     public JSONSchemaProps getKameletDefinition(String name) {
         Kamelet kamelet = kameletModels.get(name);
         if (kamelet != null) {
-                return kamelet.getSpec().getDefinition();
+            return kamelet.getSpec().getDefinition();
         } else {
             return null;
         }
@@ -161,9 +162,9 @@ public class KameletsCatalog {
 
     public void getAllKameletDependencies() {
         Map<String, Kamelet> treeMap = new TreeMap<>(kameletModels);
-        for (Map.Entry<String, Kamelet> entry: treeMap.entrySet()) {
+        for (Map.Entry<String, Kamelet> entry : treeMap.entrySet()) {
             StringBuilder builder = new StringBuilder();
-            for (String dep: entry.getValue().getSpec().getDependencies()) {
+            for (String dep : entry.getValue().getSpec().getDependencies()) {
                 builder.append(dep + System.lineSeparator());
             }
             System.out.println(entry.getKey());
@@ -181,4 +182,43 @@ public class KameletsCatalog {
             return null;
         }
     }
+
+    public List<ComponentModel.EndpointHeaderModel> getKameletSupportedHeaders(String name) {
+        List<ComponentModel.EndpointHeaderModel> resultingHeaders = new ArrayList<>();
+        Kamelet local = kameletModels.get(name);
+        if (ObjectHelper.isNotEmpty(local)) {
+            String camelType = determineCamelType(local);
+            String kameletName = local.getMetadata().getName();
+            int lastIndex = kameletName.lastIndexOf("-");
+            String prefixName = local.getMetadata().getName().substring(0, lastIndex);
+            String schemeName = enumValue(prefixName);
+            if (schemeName != null) {
+                List<ComponentModel.EndpointHeaderModel> headers = cc.componentModel(schemeName).getEndpointHeaders();
+                for (ComponentModel.EndpointHeaderModel e : headers) {
+                    if (ObjectHelper.isEmpty(e.getLabel()) || e.getLabel().equalsIgnoreCase(camelType)) {
+                        resultingHeaders.add(e);
+                    }
+                }
+            }
+        }
+        return resultingHeaders;
+    }
+
+    private String enumValue(String prefix) {
+        for (KameletPrefixSchemeEnum c : KameletPrefixSchemeEnum.values()) {
+            if (c.prefix.equals(prefix)) return c.label;
+        }
+        return null;
+    }
+
+    private String determineCamelType(Kamelet local) {
+        String camelType;
+        String kameletType = local.getMetadata().getLabels().get(KameletLabelNames.KAMELET_LABEL_TYPE);
+        if (kameletType.equalsIgnoreCase(KameletTypeEnum.SINK.type())) {
+            camelType = "producer";
+        } else {
+            camelType = "consumer";
+        }
+        return camelType;
+    }
 }
diff --git a/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletPrefixSchemeEnum.java b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletPrefixSchemeEnum.java
new file mode 100644
index 00000000..3ba37dbc
--- /dev/null
+++ b/library/camel-kamelets-catalog/src/main/java/org/apache/camel/kamelets/catalog/model/KameletPrefixSchemeEnum.java
@@ -0,0 +1,44 @@
+/*
+ * 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.kamelets.catalog.model;
+
+public enum KameletPrefixSchemeEnum {
+    aws_cloudwatch("aws-cloudwatch","aws2-cw"),
+    aws_ddb("aws-ddb","aws2-ddb"),
+    aws_ddb_streams("aws-ddb","aws2-ddbstream"),
+    aws_ec2("aws-ec2","aws2-ec2"),
+    aws_eventbridge("aws-eventbridge","aws2-eventbridge"),
+    aws_lambda("aws-lambda","aws2-lambda"),
+    aws_redshift("aws-redshift","sql"),
+    aws_s3("aws-s3","aws2-s3"),
+    aws_secrets_manager("aws-secrets-manager","aws-secrets-manager"),
+    aws_ses("aws-ses","aws2-ses"),
+    aws_sns("aws-sns","aws2-sns"),
+    aws_sns_fifo("aws-sns-fifo","aws2-sns"),
+    aws_sqs("aws-sqs","aws2-sqs"),
+    aws_sqs_batch("aws-sqs-batch","aws2-sqs"),
+    aws_sqs_fifo("aws-sqs-fifo","aws2-sqs"),
+    azure_eventhubs("azure-eventhubs","azure-eventhubs");
+
+    public final String label;
+    public final String prefix;
+
+    private KameletPrefixSchemeEnum(String prefix, String label) {
+        this.prefix = prefix;
+        this.label = label;
+    }
+}
diff --git a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java
index 19811879..8613e978 100644
--- a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java
+++ b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/KameletsCatalogTest.java
@@ -20,6 +20,7 @@ import io.fabric8.camelk.v1alpha1.Kamelet;
 import io.fabric8.camelk.v1alpha1.JSONSchemaProps;
 import io.github.classgraph.ClassGraph;
 import org.apache.camel.kamelets.catalog.model.KameletTypeEnum;
+import org.apache.camel.tooling.model.ComponentModel;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
@@ -124,4 +125,16 @@ public class KameletsCatalogTest {
     void testAllKameletDependencies() throws Exception {
         catalog.getAllKameletDependencies();
     }
+
+    @Test
+    void testSupportedHeaders() throws Exception {
+        List<ComponentModel.EndpointHeaderModel> headersSource = catalog.getKameletSupportedHeaders("aws-s3-source");
+        assertEquals(18, headersSource.size());
+        List<ComponentModel.EndpointHeaderModel> headersSink = catalog.getKameletSupportedHeaders("aws-s3-sink");
+        assertEquals(25, headersSink.size());
+        List<ComponentModel.EndpointHeaderModel> headerNotExistent = catalog.getKameletSupportedHeaders("aws-not-exists");
+        assertEquals(0, headerNotExistent.size());
+        List<ComponentModel.EndpointHeaderModel> headersAzureSink = catalog.getKameletSupportedHeaders("azure-eventhubs-sink");
+        assertEquals(2, headersAzureSink.size());
+    }
 }