You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/07/30 09:15:00 UTC

[camel-k-runtime] branch kamelets-claus created (now a61c3cd)

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

davsclaus pushed a change to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git.


      at a61c3cd  Regen

This branch includes the following new commits:

     new 93e5273  kamelets: create a camel-kamelet component #375
     new 3c0a33a  Merge remote-tracking branch 'origin/github-375-kamelets' into kamelets-claus
     new 18f15c8  kamelets: polished #375
     new 164b741  kamelets: create a camel-kamelet component #375
     new 2084696  kamelets: create a camel-kamelet component #375
     new 30579b4  kamelets: create a camel-kamelet component #375
     new d0a49e1  Fixed properties test to use correct way of main configurations
     new a61c3cd  Regen

The 8 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-k-runtime] 02/08: Merge remote-tracking branch 'origin/github-375-kamelets' into kamelets-claus

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 3c0a33ab163a7c08357d2674739a87300dd2e042
Merge: de44ec5 93e5273
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 30 11:06:09 2020 +0200

    Merge remote-tracking branch 'origin/github-375-kamelets' into kamelets-claus

 .../apache/camel/k/main/ApplicationRuntime.java    |  31 ++--
 camel-k-runtime-bom/pom.xml                        |   5 +
 camel-kamelet/pom.xml                              | 137 +++++++++++++++++
 .../kamelet/KameletComponentConfigurer.java        |  55 +++++++
 .../kamelet/KameletEndpointConfigurer.java         |  68 +++++++++
 .../services/org/apache/camel/component/kamelet    |   2 +
 .../org/apache/camel/configurer/kamelet-component  |   2 +
 .../org/apache/camel/configurer/kamelet-endpoint   |   2 +
 .../apache/camel/component/kamelet/kamelet.json    |  38 +++++
 .../apache/camel/component/kamelet/Kamelet.java    |  30 ++++
 .../camel/component/kamelet/KameletComponent.java  | 107 +++++++++++++
 .../camel/component/kamelet/KameletEndpoint.java   | 169 +++++++++++++++++++++
 .../camel/component/kamelet/KameletTest.java       |  74 +++++++++
 camel-kamelet/src/test/resources/log4j2-test.xml   |  37 +++++
 pom.xml                                            |   8 +-
 15 files changed, 748 insertions(+), 17 deletions(-)



[camel-k-runtime] 08/08: Regen

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit a61c3cd8021ba041b44ccf0474f5e3188ef7876b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 30 11:14:27 2020 +0200

    Regen
---
 .../generated/resources/org/apache/camel/component/knative/knative.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json b/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json
index 5d81d06..4954d47 100644
--- a/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json
+++ b/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json
@@ -11,7 +11,7 @@
     "supportLevel": "Preview",
     "groupId": "org.apache.camel.k",
     "artifactId": "camel-knative",
-    "version": "1.4.1-SNAPSHOT",
+    "version": "1.5.0-SNAPSHOT",
     "scheme": "knative",
     "extendsScheme": "",
     "syntax": "knative:type\/name",


[camel-k-runtime] 06/08: kamelets: create a camel-kamelet component #375

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 30579b435c113ca41b207cb17d718efad2c7938a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 30 10:39:27 2020 +0200

    kamelets: create a camel-kamelet component #375
---
 .../java/org/apache/camel/component/kamelet/KameletComponent.java     | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
index 6088410..83898a2 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
@@ -43,8 +43,10 @@ public class KameletComponent extends DefaultComponent {
         super(context);
     }
 
-    private volatile RouteTemplateEventNotifier notifier;
+    // use as temporary to keep track of created kamelet endpoints during startup as we need to defer
+    // create routes from templates until camel context has finished loading all routes and whatnot
     private final List<KameletEndpoint> endpoints = new ArrayList<>();
+    private volatile RouteTemplateEventNotifier notifier;
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {


[camel-k-runtime] 01/08: kamelets: create a camel-kamelet component #375

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 93e52730402a545fd73d662c75b597dd52431441
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sun Jul 19 15:16:36 2020 +0200

    kamelets: create a camel-kamelet component #375
---
 .../apache/camel/k/main/ApplicationRuntime.java    |  31 ++--
 camel-k-runtime-bom/pom.xml                        |   5 +
 camel-kamelet/pom.xml                              | 137 +++++++++++++++++
 .../kamelet/KameletComponentConfigurer.java        |  55 +++++++
 .../kamelet/KameletEndpointConfigurer.java         |  68 +++++++++
 .../services/org/apache/camel/component/kamelet    |   2 +
 .../org/apache/camel/configurer/kamelet-component  |   2 +
 .../org/apache/camel/configurer/kamelet-endpoint   |   2 +
 .../apache/camel/component/kamelet/kamelet.json    |  38 +++++
 .../apache/camel/component/kamelet/Kamelet.java    |  30 ++++
 .../camel/component/kamelet/KameletComponent.java  | 107 +++++++++++++
 .../camel/component/kamelet/KameletEndpoint.java   | 169 +++++++++++++++++++++
 .../camel/component/kamelet/KameletTest.java       |  74 +++++++++
 camel-kamelet/src/test/resources/log4j2-test.xml   |  37 +++++
 pom.xml                                            |   8 +-
 15 files changed, 748 insertions(+), 17 deletions(-)

diff --git a/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java
index fc67377..7d68d0e 100644
--- a/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java
+++ b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java
@@ -34,6 +34,7 @@ import org.apache.camel.k.support.PropertiesSupport;
 import org.apache.camel.main.BaseMainSupport;
 import org.apache.camel.main.MainSupport;
 import org.apache.camel.main.RoutesCollector;
+import org.apache.camel.model.RouteTemplatesDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
 import org.apache.camel.spi.HasId;
@@ -202,14 +203,13 @@ public final class ApplicationRuntime implements Runtime {
         @Override
         protected void doStart() throws Exception {
             super.doStart();
-            if (getCamelContext() != null) {
-                try {
-                    // if we were veto started then mark as completed
-                    getCamelContext().start();
-                } finally {
-                    if (getCamelContext().isVetoStarted()) {
-                        completed();
-                    }
+
+            try {
+                // if we were veto started then mark as completed
+                getCamelContext().start();
+            } finally {
+                if (getCamelContext().isVetoStarted()) {
+                    completed();
                 }
             }
         }
@@ -217,18 +217,12 @@ public final class ApplicationRuntime implements Runtime {
         @Override
         protected void doStop() throws Exception {
             super.doStop();
-            if (getCamelContext() != null) {
-                getCamelContext().stop();
-            }
+            getCamelContext().stop();
         }
 
         @Override
         protected ProducerTemplate findOrCreateCamelTemplate() {
-            if (getCamelContext() != null) {
-                return getCamelContext().createProducerTemplate();
-            } else {
-                return null;
-            }
+            return getCamelContext().createProducerTemplate();
         }
     }
 
@@ -244,6 +238,11 @@ public final class ApplicationRuntime implements Runtime {
         }
 
         @Override
+        public List<RouteTemplatesDefinition> collectXmlRouteTemplatesFromDirectory(CamelContext camelContext, String directory) throws Exception {
+            return Collections.emptyList();
+        }
+
+        @Override
         public List<RestsDefinition> collectXmlRestsFromDirectory(CamelContext camelContext, String directory) throws Exception {
             return Collections.emptyList();
         }
diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml
index c8697ad..2e23f29 100644
--- a/camel-k-runtime-bom/pom.xml
+++ b/camel-k-runtime-bom/pom.xml
@@ -131,6 +131,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.camel.k</groupId>
+                <artifactId>camel-kamelet</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.camel.k</groupId>
                 <artifactId>camel-k-maven-plugin</artifactId>
                 <version>${project.version}</version>
             </dependency>
diff --git a/camel-kamelet/pom.xml b/camel-kamelet/pom.xml
new file mode 100644
index 0000000..33e09c3
--- /dev/null
+++ b/camel-kamelet/pom.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.camel.k</groupId>
+        <artifactId>camel-k-runtime-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-kamelet</artifactId>
+
+    <dependencies>
+
+        <!-- ****************************** -->
+        <!--                                -->
+        <!-- RUNTIME                        -->
+        <!--                                -->
+        <!-- ****************************** -->
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core-engine</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-direct</artifactId>
+        </dependency>
+
+        <!-- ****************************** -->
+        <!--                                -->
+        <!-- TESTS                          -->
+        <!--                                -->
+        <!-- ****************************** -->
+
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core-languages</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-timer</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-log</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.jboss.jandex</groupId>
+                <artifactId>jandex-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>make-index</id>
+                        <goals>
+                            <goal>jandex</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-component-maven-plugin</artifactId>
+                <version>${camel.version}</version>
+                <executions>
+                    <execution>
+                        <id>generate</id>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                        <phase>process-classes</phase>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>${build-helper-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                            <goal>add-resource</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>src/generated/java</source>
+                            </sources>
+                            <resources>
+                                <resource>
+                                    <directory>src/generated/resources</directory>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java b/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
new file mode 100644
index 0000000..a0a384d
--- /dev/null
+++ b/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java
@@ -0,0 +1,55 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.kamelet;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class KameletComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+    @Override
+    public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+        KameletComponent target = (KameletComponent) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "basicpropertybinding":
+        case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true;
+        case "bridgeerrorhandler":
+        case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true;
+        case "lazystartproducer":
+        case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Map<String, Object> getAllOptions(Object target) {
+        Map<String, Object> answer = new CaseInsensitiveMap();
+        answer.put("basicPropertyBinding", boolean.class);
+        answer.put("bridgeErrorHandler", boolean.class);
+        answer.put("lazyStartProducer", boolean.class);
+        return answer;
+    }
+
+    @Override
+    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+        KameletComponent target = (KameletComponent) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "basicpropertybinding":
+        case "basicPropertyBinding": return target.isBasicPropertyBinding();
+        case "bridgeerrorhandler":
+        case "bridgeErrorHandler": return target.isBridgeErrorHandler();
+        case "lazystartproducer":
+        case "lazyStartProducer": return target.isLazyStartProducer();
+        default: return null;
+        }
+    }
+}
+
diff --git a/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java b/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
new file mode 100644
index 0000000..bb99f63
--- /dev/null
+++ b/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java
@@ -0,0 +1,68 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.kamelet;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.GeneratedPropertyConfigurer;
+import org.apache.camel.spi.PropertyConfigurerGetter;
+import org.apache.camel.util.CaseInsensitiveMap;
+import org.apache.camel.support.component.PropertyConfigurerSupport;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class KameletEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+
+    @Override
+    public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
+        KameletEndpoint target = (KameletEndpoint) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "basicpropertybinding":
+        case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true;
+        case "bridgeerrorhandler":
+        case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true;
+        case "exceptionhandler":
+        case "exceptionHandler": target.setExceptionHandler(property(camelContext, org.apache.camel.spi.ExceptionHandler.class, value)); return true;
+        case "exchangepattern":
+        case "exchangePattern": target.setExchangePattern(property(camelContext, org.apache.camel.ExchangePattern.class, value)); return true;
+        case "lazystartproducer":
+        case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
+        case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Map<String, Object> getAllOptions(Object target) {
+        Map<String, Object> answer = new CaseInsensitiveMap();
+        answer.put("basicPropertyBinding", boolean.class);
+        answer.put("bridgeErrorHandler", boolean.class);
+        answer.put("exceptionHandler", org.apache.camel.spi.ExceptionHandler.class);
+        answer.put("exchangePattern", org.apache.camel.ExchangePattern.class);
+        answer.put("lazyStartProducer", boolean.class);
+        answer.put("synchronous", boolean.class);
+        return answer;
+    }
+
+    @Override
+    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+        KameletEndpoint target = (KameletEndpoint) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "basicpropertybinding":
+        case "basicPropertyBinding": return target.isBasicPropertyBinding();
+        case "bridgeerrorhandler":
+        case "bridgeErrorHandler": return target.isBridgeErrorHandler();
+        case "exceptionhandler":
+        case "exceptionHandler": return target.getExceptionHandler();
+        case "exchangepattern":
+        case "exchangePattern": return target.getExchangePattern();
+        case "lazystartproducer":
+        case "lazyStartProducer": return target.isLazyStartProducer();
+        case "synchronous": return target.isSynchronous();
+        default: return null;
+        }
+    }
+}
+
diff --git a/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/component/kamelet b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/component/kamelet
new file mode 100644
index 0000000..be8044e
--- /dev/null
+++ b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/component/kamelet
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.kamelet.KameletComponent
diff --git a/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-component b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-component
new file mode 100644
index 0000000..88d3725
--- /dev/null
+++ b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-component
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.kamelet.KameletComponentConfigurer
diff --git a/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-endpoint b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-endpoint
new file mode 100644
index 0000000..17182a5
--- /dev/null
+++ b/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/kamelet-endpoint
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.kamelet.KameletEndpointConfigurer
diff --git a/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json b/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json
new file mode 100644
index 0000000..93ef496
--- /dev/null
+++ b/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json
@@ -0,0 +1,38 @@
+{
+  "component": {
+    "kind": "component",
+    "name": "kamelet",
+    "title": "Kamelet",
+    "description": "The Apache Software Foundation provides support for the Apache community of open-source software projects.\n    The Apache projects are characterized by a collaborative, consensus based development process, an open and\n    pragmatic software license, and a desire to create high quality software that leads the way in its field.\n    We consider ourselves not simply a group of projects sharing a server, but rather a community of developers\n    and users.",
+    "deprecated": false,
+    "firstVersion": "3.5.0",
+    "label": "camel-k",
+    "javaType": "org.apache.camel.component.kamelet.KameletComponent",
+    "supportLevel": "Preview",
+    "groupId": "org.apache.camel.k",
+    "artifactId": "camel-kamelet",
+    "version": "1.5.0-SNAPSHOT",
+    "scheme": "kamelet",
+    "extendsScheme": "",
+    "syntax": "kamelet:templateId\/routeId",
+    "async": false,
+    "consumerOnly": false,
+    "producerOnly": false,
+    "lenientProperties": false
+  },
+  "componentProperties": {
+    "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by [...]
+    "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...]
+    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }
+  },
+  "properties": {
+    "templateId": { "kind": "path", "displayName": "Template Id", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "The Route Template ID" },
+    "routeId": { "kind": "path", "displayName": "Route Id", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "description": "The Route ID. Default value notice: The ID will be auto-generated if not provided" },
+    "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled b [...]
+    "exceptionHandler": { "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with [...]
+    "exchangePattern": { "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." },
+    "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the  [...]
+    "basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
+    "synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "false", "description": "Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported)." }
+  }
+}
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
new file mode 100644
index 0000000..043f44e
--- /dev/null
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java
@@ -0,0 +1,30 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.function.Predicate;
+
+public final class Kamelet {
+    public static final String SCHEME = "kamelet";
+
+    private Kamelet() {
+    }
+
+    public static Predicate<String> startsWith(String prefix) {
+        return item -> item.startsWith(prefix);
+    }
+}
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
new file mode 100644
index 0000000..f5c6f6e
--- /dev/null
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
@@ -0,0 +1,107 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.util.StringHelper;
+
+@Component(Kamelet.SCHEME)
+public class KameletComponent extends DefaultComponent {
+    public KameletComponent() {
+        this(null);
+    }
+
+    public KameletComponent(CamelContext context) {
+        super(context);
+    }
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+        final String templateId = extractTemplateId(remaining);
+        final String routeId = extractRouteId(remaining);
+
+        //
+        // The properties for the kamelets are determined by global properties
+        // and local endpoint parametes,
+        //
+        // Global parameters are loaded in the following order:
+        //
+        //   camel.kamelet." + templateId
+        //   camel.kamelet." + templateId + "." routeId
+        //
+        Map<String, Object> kameletProperties = extractKameletProperties(templateId, routeId);
+        kameletProperties.putAll(parameters);
+        kameletProperties.putIfAbsent("templateId", templateId);
+        kameletProperties.putIfAbsent("routeId", routeId);
+
+        // Remaining parameter should be related to the route and to avoid the
+        // parameters validation to fail, we need to clear the parameters map.
+        parameters.clear();
+
+        KameletEndpoint endpoint = new KameletEndpoint(uri, this, templateId, routeId, kameletProperties);
+
+        // No parameters are expected here.
+        setProperties(endpoint, parameters);
+
+        return endpoint;
+    }
+
+    private String extractTemplateId(String remaining) {
+        String answer = StringHelper.before(remaining, "/");
+        if (answer == null) {
+            answer = remaining;
+        }
+
+        return answer;
+    }
+
+    private String extractRouteId(String remaining) {
+        String answer = StringHelper.after(remaining, "/");
+        if (answer == null) {
+            answer = extractTemplateId(remaining) + "-" + getCamelContext().getUuidGenerator().generateUuid();
+        }
+
+        return answer;
+    }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, Object> extractKameletProperties(String... elements) {
+        Map<String, Object> properties = new HashMap<>();
+        String prefix = "camel.kamelet.";
+
+        for (String element: elements) {
+            if (element == null) {
+                continue;
+            }
+
+            prefix = prefix + element + ".";
+
+            properties.putAll(
+                (Map)getCamelContext().getPropertiesComponent().loadProperties(Kamelet.startsWith(prefix))
+            );
+
+        }
+
+        return properties;
+    }
+}
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
new file mode 100644
index 0000000..22cd543
--- /dev/null
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
@@ -0,0 +1,169 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultProducer;
+import org.apache.camel.support.service.ServiceHelper;
+
+@UriEndpoint(
+    firstVersion = "3.5.0",
+    scheme = "kamelet",
+    syntax = "kamelet:templateId/routeId",
+    title = "Kamelet",
+    label = "camel-k")
+public class KameletEndpoint extends DefaultEndpoint {
+    @Metadata(required = true)
+    @UriPath(description = "The Route Template ID")
+    private final String templateId;
+
+    @Metadata(required = false)
+    @UriPath(description = "The Route ID", defaultValueNote = "The ID will be auto-generated if not provided")
+    private final String routeId;
+
+    private final Map<String, Object> kameletProperties;
+    private final String kameletUri;
+
+    public KameletEndpoint(
+            String uri,
+            KameletComponent component,
+            String templateId,
+            String routeId,
+            Map<String, Object> kameletProperties) {
+
+        super(uri, component);
+
+        this.templateId = templateId;
+        this.routeId = routeId;
+        this.kameletProperties = kameletProperties;
+        this.kameletUri = "direct:" + routeId;
+    }
+
+    public String getTemplateId() {
+        return templateId;
+    }
+
+    public String getRouteId() {
+        return routeId;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return new KameletProducer();
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        Consumer answer = new KemeletConsumer(processor);
+        configureConsumer(answer);
+
+        return answer;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        try {
+            // Add a route to the camel context from the given template
+            // TODO: add validation (requires: https://issues.apache.org/jira/browse/CAMEL-15312)
+            getCamelContext().addRouteFromTemplate(routeId, templateId, kameletProperties);
+        } catch (Exception e) {
+            throw new IllegalArgumentException(e);
+        }
+
+        super.doStart();
+    }
+
+    // *********************************
+    //
+    // Helpers
+    //
+    // *********************************
+
+    private class KemeletConsumer extends DefaultConsumer {
+        private volatile Endpoint endpoint;
+        private volatile Consumer consumer;
+
+        public KemeletConsumer(Processor processor) {
+            super(KameletEndpoint.this, processor);
+        }
+
+        @Override
+        protected void doStart() throws Exception {
+            endpoint = getCamelContext().getEndpoint(kameletUri);
+            consumer = endpoint.createConsumer(getProcessor());
+
+            ServiceHelper.startService(endpoint);
+            ServiceHelper.startService(consumer);
+
+            super.doStart();
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            ServiceHelper.stopService(endpoint);
+            ServiceHelper.stopService(consumer);
+
+            super.doStop();
+        }
+    }
+
+    private class KameletProducer extends DefaultProducer {
+        private volatile Endpoint endpoint;
+        private volatile Producer producer;
+
+        public KameletProducer() {
+            super(KameletEndpoint.this);
+        }
+
+        @Override
+        public void process(Exchange exchange) throws Exception {
+            if (producer != null) {
+                producer.process(exchange);
+            }
+        }
+
+        @Override
+        protected void doStart() throws Exception {
+            endpoint = getCamelContext().getEndpoint(kameletUri);
+            producer = endpoint.createProducer();
+
+            ServiceHelper.startService(endpoint);
+            ServiceHelper.startService(producer);
+
+            super.doStart();
+        }
+
+        @Override
+        protected void doStop() throws Exception {
+            ServiceHelper.stopService(endpoint);
+            ServiceHelper.stopService(producer);
+
+            super.doStop();
+        }
+    }
+}
\ No newline at end of file
diff --git a/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java
new file mode 100644
index 0000000..8f95084
--- /dev/null
+++ b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.UUID;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KameletTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(KameletTest.class);
+
+    @Test
+    public void test() throws Exception {
+        String body = UUID.randomUUID().toString();
+
+        CamelContext context = new DefaultCamelContext();
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("setBody")
+                    .templateParameter("bodyValue")
+                    .from("direct:{{routeId}}")
+                    .setBody().constant("{{bodyValue}}");
+            }
+        });
+
+        /*
+        context.addRouteFromTemplate("setBody")
+            .routeId("test")
+            .parameter("routeId", "test")
+            .parameter("bodyValue", body)
+            .build();
+         */
+
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // routes
+                from("direct:template")
+                    .to("kamelet:setBody/test?bodyValue=bv")
+                    .to("log:1");
+            }
+        });
+
+        context.start();
+
+        assertThat(
+            context.createFluentProducerTemplate().to("direct:template").withBody("test").request(String.class)
+        ).isEqualTo(body);
+
+        context.stop();
+    }
+}
diff --git a/camel-kamelet/src/test/resources/log4j2-test.xml b/camel-kamelet/src/test/resources/log4j2-test.xml
new file mode 100644
index 0000000..486a0f0
--- /dev/null
+++ b/camel-kamelet/src/test/resources/log4j2-test.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<Configuration status="INFO">
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c{1} - %msg%n"/>
+    </Console>
+    <Null name="NONE"/>
+  </Appenders>
+
+  <Loggers>
+    <Root level="INFO">
+      <!--
+      <AppenderRef ref="STDOUT"/>
+      -->
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3318067..d37d9a3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,7 +38,7 @@
         <maven.compiler.source>11</maven.compiler.source>
         <maven.compiler.target>11</maven.compiler.target>
 
-        <camel.version>3.4.0</camel.version>
+        <camel.version>3.5.0-SNAPSHOT</camel.version>
         <camel-quarkus.version>1.0.0-CR3</camel-quarkus.version>
         <catalog.version>${camel.version}</catalog.version>
         <junit.version>5.6.2</junit.version>
@@ -236,6 +236,7 @@
         <module>tooling</module>
 
         <module>camel-knative</module>
+        <module>camel-kamelet</module>
 
         <module>camel-k-runtime-core</module>
         <module>camel-k-main</module>
@@ -337,6 +338,11 @@
                 <artifactId>camel-knative-http</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.camel.k</groupId>
+                <artifactId>camel-kamelet</artifactId>
+                <version>${project.version}</version>
+            </dependency>
 
             <!-- runtime -->
             <dependency>


[camel-k-runtime] 03/08: kamelets: polished #375

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 18f15c8ae87ce3f9101dfacad958dd5efcc416e9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jul 29 16:54:00 2020 +0200

    kamelets: polished #375
---
 camel-kamelet/pom.xml                              |  2 +-
 .../camel/component/kamelet/KameletEndpoint.java   | 35 ++++++++++------------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/camel-kamelet/pom.xml b/camel-kamelet/pom.xml
index 33e09c3..7083b87 100644
--- a/camel-kamelet/pom.xml
+++ b/camel-kamelet/pom.xml
@@ -43,7 +43,7 @@
 
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core-engine</artifactId>
+            <artifactId>camel-support</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
index 22cd543..d3f0eac 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.kamelet;
 
 import java.util.Map;
 
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProducer;
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -26,9 +28,9 @@ import org.apache.camel.Producer;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.DefaultAsyncProducer;
 import org.apache.camel.support.DefaultConsumer;
 import org.apache.camel.support.DefaultEndpoint;
-import org.apache.camel.support.DefaultProducer;
 import org.apache.camel.support.service.ServiceHelper;
 
 @UriEndpoint(
@@ -81,7 +83,6 @@ public class KameletEndpoint extends DefaultEndpoint {
     public Consumer createConsumer(Processor processor) throws Exception {
         Consumer answer = new KemeletConsumer(processor);
         configureConsumer(answer);
-
         return answer;
     }
 
@@ -117,52 +118,46 @@ public class KameletEndpoint extends DefaultEndpoint {
             endpoint = getCamelContext().getEndpoint(kameletUri);
             consumer = endpoint.createConsumer(getProcessor());
 
-            ServiceHelper.startService(endpoint);
-            ServiceHelper.startService(consumer);
-
+            ServiceHelper.startService(endpoint, consumer);
             super.doStart();
         }
 
         @Override
         protected void doStop() throws Exception {
-            ServiceHelper.stopService(endpoint);
-            ServiceHelper.stopService(consumer);
-
+            ServiceHelper.stopService(consumer, endpoint);
             super.doStop();
         }
     }
 
-    private class KameletProducer extends DefaultProducer {
+    private class KameletProducer extends DefaultAsyncProducer {
         private volatile Endpoint endpoint;
-        private volatile Producer producer;
+        private volatile AsyncProducer producer;
 
         public KameletProducer() {
             super(KameletEndpoint.this);
         }
 
         @Override
-        public void process(Exchange exchange) throws Exception {
+        public boolean process(Exchange exchange, AsyncCallback callback) {
             if (producer != null) {
-                producer.process(exchange);
+                return producer.process(exchange, callback);
+            } else {
+                callback.done(true);
+                return true;
             }
         }
 
         @Override
         protected void doStart() throws Exception {
             endpoint = getCamelContext().getEndpoint(kameletUri);
-            producer = endpoint.createProducer();
-
-            ServiceHelper.startService(endpoint);
-            ServiceHelper.startService(producer);
-
+            producer = endpoint.createAsyncProducer();
+            ServiceHelper.startService(endpoint, producer);
             super.doStart();
         }
 
         @Override
         protected void doStop() throws Exception {
-            ServiceHelper.stopService(endpoint);
-            ServiceHelper.stopService(producer);
-
+            ServiceHelper.stopService(producer, endpoint);
             super.doStop();
         }
     }


[camel-k-runtime] 05/08: kamelets: create a camel-kamelet component #375

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 2084696ce2da589a94d526721fdc4834da08ff10
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 30 10:33:15 2020 +0200

    kamelets: create a camel-kamelet component #375
---
 .../camel/component/kamelet/KameletComponent.java  | 87 ++++++++++++++++++++++
 .../camel/component/kamelet/KameletEndpoint.java   | 40 +++-------
 .../kamelet/KameletAddAfterCamelStartedTest.java   | 76 +++++++++++++++++++
 3 files changed, 174 insertions(+), 29 deletions(-)

diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
index 05a8abc..6088410 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
@@ -16,13 +16,21 @@
  */
 package org.apache.camel.component.kamelet;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.util.StringHelper;
 
 @Component(Kamelet.SCHEME)
@@ -35,6 +43,9 @@ public class KameletComponent extends DefaultComponent {
         super(context);
     }
 
+    private volatile RouteTemplateEventNotifier notifier;
+    private final List<KameletEndpoint> endpoints = new ArrayList<>();
+
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         final String templateId = extractTemplateId(remaining);
@@ -104,4 +115,80 @@ public class KameletComponent extends DefaultComponent {
 
         return properties;
     }
+
+    @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+
+        if (!getCamelContext().isRunAllowed()) {
+            // setup event listener which must be started to get triggered during initialization of camel context
+            notifier = new RouteTemplateEventNotifier(this);
+            ServiceHelper.startService(notifier);
+            getCamelContext().getManagementStrategy().addEventNotifier(notifier);
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (notifier != null) {
+            ServiceHelper.stopService(notifier);
+            getCamelContext().getManagementStrategy().removeEventNotifier(notifier);
+            notifier = null;
+        }
+        super.doStop();
+    }
+
+    void onEndpointAdd(KameletEndpoint endpoint) {
+        if (notifier == null) {
+            try {
+                addRouteFromTemplate(endpoint);
+            } catch (Exception e) {
+                throw RuntimeCamelException.wrapRuntimeException(e);
+            }
+        } else {
+            // remember endpoints as we defer adding routes for them till later
+            this.endpoints.add(endpoint);
+        }
+    }
+
+    void addRouteFromTemplate(KameletEndpoint endpoint) throws Exception {
+        ModelCamelContext context = endpoint.getCamelContext().adapt(ModelCamelContext.class);
+        String id = context.addRouteFromTemplate(endpoint.getRouteId(), endpoint.getTemplateId(), endpoint.getKameletProperties());
+        RouteDefinition def = context.getRouteDefinition(id);
+        if (!def.isPrepared()) {
+            List<RouteDefinition> list = new ArrayList<>(1);
+            list.add(def);
+            context.startRouteDefinitions(list);
+        }
+    }
+
+    private static class RouteTemplateEventNotifier extends EventNotifierSupport {
+
+        private final KameletComponent component;
+
+        public RouteTemplateEventNotifier(KameletComponent component) {
+            this.component = component;
+        }
+
+        @Override
+        public void notify(CamelEvent event) throws Exception {
+            for (KameletEndpoint endpoint : component.endpoints) {
+                component.addRouteFromTemplate(endpoint);
+            }
+            component.endpoints.clear();
+            // we were only needed during initializing/starting up camel, so remove after use
+            ServiceHelper.stopService(this);
+            component.getCamelContext().getManagementStrategy().removeEventNotifier(this);
+            component.notifier = null;
+        }
+
+        @Override
+        public boolean isEnabled(CamelEvent event) {
+            // we only care about this event during startup as its triggered when
+            // all route and route template definitions have been added and prepared
+            // so this allows us to hook into the right moment
+            return event instanceof CamelEvent.CamelContextInitializedEvent;
+        }
+
+    }
 }
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
index 4300ea6..7609647 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.component.kamelet;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.AsyncCallback;
@@ -27,18 +25,12 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import org.apache.camel.impl.event.CamelContextInitializedEvent;
-import org.apache.camel.model.ModelCamelContext;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.spi.CamelEvent;
-import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.support.DefaultAsyncProducer;
 import org.apache.camel.support.DefaultConsumer;
 import org.apache.camel.support.DefaultEndpoint;
-import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.support.service.ServiceHelper;
 
 @UriEndpoint(
@@ -74,6 +66,11 @@ public class KameletEndpoint extends DefaultEndpoint {
         this.kameletUri = "direct:" + routeId;
     }
 
+    @Override
+    public KameletComponent getComponent() {
+        return (KameletComponent) super.getComponent();
+    }
+
     public String getTemplateId() {
         return templateId;
     }
@@ -82,6 +79,10 @@ public class KameletEndpoint extends DefaultEndpoint {
         return routeId;
     }
 
+    public Map<String, Object> getKameletProperties() {
+        return kameletProperties;
+    }
+
     @Override
     public Producer createProducer() throws Exception {
         return new KameletProducer();
@@ -97,27 +98,8 @@ public class KameletEndpoint extends DefaultEndpoint {
     @Override
     protected void doInit() throws Exception {
         super.doInit();
-
-        // TODO: lets find a nicer way to do this
-        EventNotifier notifier = new EventNotifierSupport() {
-            @Override
-            public void notify(CamelEvent event) throws Exception {
-                String id = getCamelContext().addRouteFromTemplate(routeId, templateId, kameletProperties);
-                List<RouteDefinition> list = new ArrayList<>(1);
-                list.add(getCamelContext().adapt(ModelCamelContext.class).getRouteDefinition(id));
-                getCamelContext().adapt(ModelCamelContext.class).startRouteDefinitions(list);
-                // no longer needed so we can remove ourselves
-                getCamelContext().getManagementStrategy().removeEventNotifier(this);
-            }
-
-            @Override
-            public boolean isEnabled(CamelEvent event) {
-                return event instanceof CamelContextInitializedEvent;
-            }
-        };
-
-        ServiceHelper.startService(notifier);
-        getCamelContext().getManagementStrategy().addEventNotifier(notifier);
+        // only need to add during init phase
+        getComponent().onEndpointAdd(this);
     }
 
     // *********************************
diff --git a/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAddAfterCamelStartedTest.java b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAddAfterCamelStartedTest.java
new file mode 100644
index 0000000..fdc9dc6
--- /dev/null
+++ b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletAddAfterCamelStartedTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.component.kamelet;
+
+import java.util.UUID;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class KameletAddAfterCamelStartedTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(KameletAddAfterCamelStartedTest.class);
+
+    @Test
+    public void test() throws Exception {
+        String body = UUID.randomUUID().toString();
+
+        CamelContext context = new DefaultCamelContext();
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                routeTemplate("setBody")
+                    .templateParameter("bodyValue")
+                    .from("direct:{{routeId}}")
+                    .setBody().constant("{{bodyValue}}");
+            }
+        });
+
+        /*
+        context.addRouteFromTemplate("setBody")
+            .routeId("test")
+            .parameter("routeId", "test")
+            .parameter("bodyValue", body)
+            .build();
+         */
+
+        // start camel here and add routes with kamelts later
+        context.start();
+
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // routes
+                from("direct:template")
+                    .toF("kamelet:setBody/test?bodyValue=%s", body)
+                    .to("log:1");
+            }
+        });
+
+        assertThat(
+            context.createFluentProducerTemplate().to("direct:template").withBody("test").request(String.class)
+        ).isEqualTo(body);
+
+        context.stop();
+    }
+}


[camel-k-runtime] 07/08: Fixed properties test to use correct way of main configurations

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit d0a49e1d359561953a61e9642d7f017d1ffa5ac3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jul 30 10:54:54 2020 +0200

    Fixed properties test to use correct way of main configurations
---
 .../src/test/java/org/apache/camel/k/main/PropertiesTest.java  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java
index 90d5260..7349b84 100644
--- a/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java
+++ b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java
@@ -122,11 +122,11 @@ public class PropertiesTest {
     @Test
     public void testContextConfiguration() throws Exception {
         Properties properties = new Properties();
-        properties.setProperty("camel.context.message-history", "false");
-        properties.setProperty("camel.context.load-type-converters", "false");
-        properties.setProperty("camel.context.stream-caching-strategy.spool-threshold", "100");
-        properties.setProperty("camel.context.rest-configuration.component", "servlet");
-        properties.setProperty("camel.context.rest-configuration.context-path", "/my/path");
+        properties.setProperty("camel.main.message-history", "false");
+        properties.setProperty("camel.main.load-type-converters", "false");
+        properties.setProperty("camel.main.stream-caching-spool-threshold", "100");
+        properties.setProperty("camel.rest.component", "servlet");
+        properties.setProperty("camel.rest.context-path", "/my/path");
 
         ApplicationRuntime runtime = new ApplicationRuntime();
         runtime.setProperties(properties);


[camel-k-runtime] 04/08: kamelets: create a camel-kamelet component #375

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

davsclaus pushed a commit to branch kamelets-claus
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit 164b741fe46808cbabdfdfda67f6d06975339403
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jul 29 17:54:25 2020 +0200

    kamelets: create a camel-kamelet component #375
---
 camel-kamelet/pom.xml                              |  2 +-
 .../camel/component/kamelet/KameletComponent.java  |  2 +-
 .../camel/component/kamelet/KameletEndpoint.java   | 39 +++++++++++++++++-----
 .../camel/component/kamelet/KameletTest.java       |  2 +-
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/camel-kamelet/pom.xml b/camel-kamelet/pom.xml
index 7083b87..33e09c3 100644
--- a/camel-kamelet/pom.xml
+++ b/camel-kamelet/pom.xml
@@ -43,7 +43,7 @@
 
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-support</artifactId>
+            <artifactId>camel-core-engine</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
index f5c6f6e..05a8abc 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java
@@ -42,7 +42,7 @@ public class KameletComponent extends DefaultComponent {
 
         //
         // The properties for the kamelets are determined by global properties
-        // and local endpoint parametes,
+        // and local endpoint parameters,
         //
         // Global parameters are loaded in the following order:
         //
diff --git a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
index d3f0eac..4300ea6 100644
--- a/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
+++ b/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.kamelet;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.AsyncCallback;
@@ -25,12 +27,18 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.impl.event.CamelContextInitializedEvent;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.support.DefaultAsyncProducer;
 import org.apache.camel.support.DefaultConsumer;
 import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.EventNotifierSupport;
 import org.apache.camel.support.service.ServiceHelper;
 
 @UriEndpoint(
@@ -87,16 +95,29 @@ public class KameletEndpoint extends DefaultEndpoint {
     }
 
     @Override
-    protected void doStart() throws Exception {
-        try {
-            // Add a route to the camel context from the given template
-            // TODO: add validation (requires: https://issues.apache.org/jira/browse/CAMEL-15312)
-            getCamelContext().addRouteFromTemplate(routeId, templateId, kameletProperties);
-        } catch (Exception e) {
-            throw new IllegalArgumentException(e);
-        }
+    protected void doInit() throws Exception {
+        super.doInit();
+
+        // TODO: lets find a nicer way to do this
+        EventNotifier notifier = new EventNotifierSupport() {
+            @Override
+            public void notify(CamelEvent event) throws Exception {
+                String id = getCamelContext().addRouteFromTemplate(routeId, templateId, kameletProperties);
+                List<RouteDefinition> list = new ArrayList<>(1);
+                list.add(getCamelContext().adapt(ModelCamelContext.class).getRouteDefinition(id));
+                getCamelContext().adapt(ModelCamelContext.class).startRouteDefinitions(list);
+                // no longer needed so we can remove ourselves
+                getCamelContext().getManagementStrategy().removeEventNotifier(this);
+            }
+
+            @Override
+            public boolean isEnabled(CamelEvent event) {
+                return event instanceof CamelContextInitializedEvent;
+            }
+        };
 
-        super.doStart();
+        ServiceHelper.startService(notifier);
+        getCamelContext().getManagementStrategy().addEventNotifier(notifier);
     }
 
     // *********************************
diff --git a/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java
index 8f95084..32634a0 100644
--- a/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java
+++ b/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletTest.java
@@ -58,7 +58,7 @@ public class KameletTest {
             public void configure() throws Exception {
                 // routes
                 from("direct:template")
-                    .to("kamelet:setBody/test?bodyValue=bv")
+                    .toF("kamelet:setBody/test?bodyValue=%s", body)
                     .to("log:1");
             }
         });