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 2021/11/19 15:33:11 UTC

[camel] branch main updated (7412eb4 -> 2faf0e5)

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

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 7412eb4  Sync again
     new f342b67  CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader
     new 2faf0e5  CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader

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.


Summary of changes:
 .../modules/ROOT/pages/camel-jbang.adoc            | 32 ++++++++-----
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 53 ++++++++++++++++------
 dsl/camel-kamelet-main/pom.xml                     |  7 +++
 .../java/org/apache/camel/main/KameletMain.java    | 23 ++++++----
 .../apache/camel/main/KameletMainGithubTest.java   | 27 ++++-------
 .../org/apache/camel/main/KameletMainTest.java     | 19 ++++----
 .../src/test/resources/log4j2.properties           |  4 +-
 .../src/test/resources/my-route.yaml               | 11 ++++-
 8 files changed, 116 insertions(+), 60 deletions(-)
 copy catalog/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyRouteEmptyUriTest.java => dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainGithubTest.java (62%)
 copy components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerHelperTest.java => dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java (67%)
 copy {components/camel-ahc-ws => dsl/camel-kamelet-main}/src/test/resources/log4j2.properties (93%)
 copy components/camel-undertow-spring-security/src/main/resources/META-INF/services/org.apache.camel.component.undertow.spi.UndertowSecurityProvider => dsl/camel-kamelet-main/src/test/resources/my-route.yaml (81%)

[camel] 01/02: CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f342b67d0313eac9fc9cae576161442a23538d18
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Nov 19 16:28:02 2021 +0100

    CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader
---
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 53 ++++++++++++++++------
 dsl/camel-kamelet-main/pom.xml                     |  7 +++
 .../java/org/apache/camel/main/KameletMain.java    | 23 ++++++----
 .../apache/camel/main/KameletMainGithubTest.java   | 35 ++++++++++++++
 .../org/apache/camel/main/KameletMainTest.java     | 34 ++++++++++++++
 .../src/test/resources/log4j2.properties           | 28 ++++++++++++
 .../src/test/resources/my-route.yaml               | 27 +++++++++++
 7 files changed, 186 insertions(+), 21 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 1330c3f..fc0b072 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.dsl.jbang.core.common.RuntimeUtil;
 import org.apache.camel.main.KameletMain;
+import org.apache.camel.support.ResourceHelper;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Option;
 import picocli.CommandLine.Parameters;
@@ -38,7 +39,7 @@ class Run implements Callable<Integer> {
 
     //CHECKSTYLE:OFF
     @Option(names = { "-h", "--help" }, usageHelp = true, description = "Display the help and sub-commands")
-    private boolean helpRequested = false;
+    private boolean helpRequested;
     //CHECKSTYLE:ON
 
     @Option(names = { "--debug-level" }, defaultValue = "info", description = "Default debug level")
@@ -53,6 +54,10 @@ class Run implements Callable<Integer> {
     @Option(names = { "--reload" }, description = "Enables live reload when source file is changed (saved)")
     private boolean reload;
 
+    @Option(names = { "--file-lock" },
+            description = "Whether to create a temporary file lock, which upon deleting triggers this process to terminate")
+    private boolean fileLock;
+
     class ShutdownRoute extends RouteBuilder {
         private File lockFile;
 
@@ -99,25 +104,47 @@ class Run implements Callable<Integer> {
             System.setProperty("camel.main.durationMaxMessages", String.valueOf(maxMessages));
         }
 
-        System.setProperty("camel.main.routes-include-pattern", "file:" + binding);
-        System.setProperty("camel.main.routes-reload-enabled", reload ? "true" : "false");
-        System.setProperty("camel.main.routes-reload-directory", ".");
-        System.setProperty("camel.main.routes-reload-pattern", binding);
-
         RuntimeUtil.configureLog(debugLevel);
 
-        File bindingFile = new File(binding);
-        if (!bindingFile.exists()) {
-            System.err.println("The binding file does not exist");
+        KameletMain main = new KameletMain() {
+            @Override
+            protected void configureInitialProperties() {
+                addInitialProperty("camel.component.kamelet.location", "classpath:/kamelets,github:apache:camel-kamelets");
+                // turn off lightweight if we have routes reload enabled
+                addInitialProperty("camel.main.lightweight", reload ? "false" : "true");
+                // shutdown quickly
+                addInitialProperty("camel.main.shutdown-timeout", "5");
+            }
+        };
+
+        // special route to trigger shutdown on watch file delete
+        if (fileLock) {
+            // TODO: use another way
+            main.configure().addRoutesBuilder(new ShutdownRoute(createLockFile()));
+        }
 
-            return 1;
+        if (!ResourceHelper.hasScheme(binding) && !binding.startsWith("github:")) {
+            binding = "file:" + binding;
         }
+        main.addInitialProperty("camel.main.routes-include-pattern", binding);
+
+        if (binding.startsWith("file:")) {
+            // check if file exist
+            File bindingFile = new File(binding.substring(5));
+            if (!bindingFile.exists() && !bindingFile.isFile()) {
+                System.err.println("The binding file does not exist");
+                return 1;
+            }
 
-        System.out.println("Starting Camel JBang!");
-        KameletMain main = new KameletMain();
+            // we can only reload if file based
+            main.addInitialProperty("camel.main.routes-reload-enabled", reload ? "true" : "false");
+            main.addInitialProperty("camel.main.routes-reload-directory", ".");
+            main.addInitialProperty("camel.main.routes-reload-pattern", binding);
+        }
 
-        main.configure().addRoutesBuilder(new ShutdownRoute(createLockFile()));
+        System.out.println("Starting Camel JBang!  ZZZ");
         main.start();
+
         context = main.getCamelContext();
 
         main.run();
diff --git a/dsl/camel-kamelet-main/pom.xml b/dsl/camel-kamelet-main/pom.xml
index 1041be3..cf7bd5c 100644
--- a/dsl/camel-kamelet-main/pom.xml
+++ b/dsl/camel-kamelet-main/pom.xml
@@ -83,6 +83,13 @@
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-engine</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
 </project>
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 854c5f8..3274e80 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -147,14 +147,7 @@ public class KameletMain extends MainCommandLineSupport {
         answer.setApplicationContextClassLoader(kameletClassLoader);
         answer.setRegistry(registry);
 
-        addInitialProperty("camel.component.kamelet.location", "classpath:/kamelets,github:apache:camel-kamelets");
-        addInitialProperty("camel.main.routes-reload-enabled", "true");
-        addInitialProperty("camel.main.routes-reload-directory", "src/main/resources");
-        addInitialProperty("camel.main.routes-reload-pattern", "camel/*.yaml");
-        // turn off lightweight as we have routes reload enabled
-        addInitialProperty("camel.main.lightweight", "false");
-        // shutdown quickly
-        addInitialProperty("camel.main.shutdown-timeout", "5");
+        configureInitialProperties();
 
         if (download) {
             try {
@@ -171,4 +164,18 @@ public class KameletMain extends MainCommandLineSupport {
         return answer;
     }
 
+    /**
+     * Sets initial properties that are specific to camel-kamelet-main
+     */
+    protected void configureInitialProperties() {
+        addInitialProperty("camel.component.kamelet.location", "classpath:/kamelets,github:apache:camel-kamelets");
+        addInitialProperty("camel.main.routes-reload-enabled", "true");
+        addInitialProperty("camel.main.routes-reload-directory", "src/main/resources");
+        addInitialProperty("camel.main.routes-reload-pattern", "camel/*.yaml");
+        // turn off lightweight as we have routes reload enabled
+        addInitialProperty("camel.main.lightweight", "false");
+        // shutdown quickly
+        addInitialProperty("camel.main.shutdown-timeout", "5");
+    }
+
 }
diff --git a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainGithubTest.java b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainGithubTest.java
new file mode 100644
index 0000000..d62e2e9
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainGithubTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.main;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled("Manual test")
+public class KameletMainGithubTest {
+
+    @Test
+    public void testKameletMain() throws Exception {
+        KameletMain main = new KameletMain();
+        main.setDownload(true);
+        main.configure().withDurationMaxSeconds(10);
+//        main.configure().withRoutesIncludePattern("github:apache:camel-k:examples/languages/routes.yaml");
+        main.configure().withRoutesIncludePattern("github:apache:camel-examples:examples/main-yaml/src/main/resources/my-route.yaml");
+
+        main.run();
+    }
+}
diff --git a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java
new file mode 100644
index 0000000..c3c163b
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.main;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled("Manual test")
+public class KameletMainTest {
+
+    @Test
+    public void testKameletMain() throws Exception {
+        KameletMain main = new KameletMain();
+        main.setDownload(true);
+        main.configure().withDurationMaxSeconds(5);
+        main.configure().withRoutesIncludePattern("file:src/test/resources/my-route.yaml");
+
+        main.run();
+    }
+}
diff --git a/dsl/camel-kamelet-main/src/test/resources/log4j2.properties b/dsl/camel-kamelet-main/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..ceb0f20
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/test/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-kamelet-main-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = out
diff --git a/dsl/camel-kamelet-main/src/test/resources/my-route.yaml b/dsl/camel-kamelet-main/src/test/resources/my-route.yaml
new file mode 100644
index 0000000..03909be
--- /dev/null
+++ b/dsl/camel-kamelet-main/src/test/resources/my-route.yaml
@@ -0,0 +1,27 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- from:
+    uri: "timer:tick"
+    parameters:
+      period: "1000"
+    steps:
+      - set-body:
+          constant: "Hello Yaml !!!"
+      - transform:
+          simple: "${body.toUpperCase()}"
+      - to: "log:info"
\ No newline at end of file

[camel] 02/02: CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2faf0e5f00b30ec4ec030af42e7d8faab5d01960
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Nov 19 16:32:13 2021 +0100

    CAMEL-17210: camel-jbang - Allow to run a file loaded via github resource loader
---
 .../modules/ROOT/pages/camel-jbang.adoc            | 32 ++++++++++++++--------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
index d85cdaa..84344c3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang.adoc
@@ -4,7 +4,7 @@ A JBang-based Camel app for searching for kamelets, components, languages, runni
 
 The `camel-jbang` is available from *Camel 3.12* and newer versions.
 
-When running Camel JBang, it is possible to set the Camel version to use. For instance, to run the commands with the version 3.13.0, define the `camel.jbang.version` property in the command line.
+When running Camel JBang, it is possible to set the Camel version to use. For instance, to run the commands with the version 3.14.0, define the `camel.jbang.version` property in the command line.
 
 == Using Camel JBang
 
@@ -25,7 +25,7 @@ You can specify which Camel version to run as shown:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel [command]
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel [command]
 ----
 
 === Search
@@ -34,21 +34,21 @@ You can use the CLI to search for kamelets, components, languages and miscelaneo
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel search --help
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel search --help
 ----
 
 For example, to search for kamelets named `jms`, you can use:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel search kamelets --search-term=jms
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel search kamelets --search-term=jms
 ----
 
 To list all the kamelets, just run the command without any search term:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel search kamelets
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel search kamelets
 ----
 
 
@@ -80,7 +80,7 @@ To bootstrap the Kamelet run:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel  init kamelet --bootstrap
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel  init kamelet --bootstrap
 ----
 
 This will create a sub-directory called `work` in the current directory with a properties file named `init-template.properties` inside it.
@@ -91,7 +91,7 @@ After you have filled the values, you can generate the Kamelet using:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel init kamelet --properties-path work/init-template.properties
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel init kamelet --properties-path work/init-template.properties
 ----
 
 Running this command will create a new file in the `work` directory. The name of the generated file is determined by the `kameletMetadataName` property in the properties file. As such, parsing the default properties file would generate a file named `my-sample-sink.kamelet.yaml` in the directory.
@@ -107,7 +107,7 @@ To execute this feature run:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel init binding --destination /path/to/destination/directory/ --kamelet sftp-source
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel init binding --destination /path/to/destination/directory/ --kamelet sftp-source
 ----
 
 This will create a new sample YAML binding file that can be modified and used in Camel K.
@@ -116,7 +116,7 @@ You can also generate bindings that can be run by CamelJBang or Camel Core, but
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel init binding --destination /path/to/destination/directory/ --kamelet sftp-source --project core
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel init binding --destination /path/to/destination/directory/ --kamelet sftp-source --project core
 ----
 
 
@@ -148,7 +148,7 @@ Execute the following command to run this route:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel run jms-amqp-10-sink-binding.yaml
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel run jms-amqp-10-sink-binding.yaml
 ----
 
 NOTE: it is necessary to have a AMQP 1.0 broker, such as Apache Artemis, running locally and listening on port 61616. Adjust the route accordingly if using a different address for the broker.
@@ -160,11 +160,21 @@ using the `--reload` options as shown:
 
 [source,bash]
 ----
-jbang -Dcamel.jbang.version=3.13.0 CamelJBang@apache/camel run jms-amqp-10-sink-binding.yaml --reload
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel run jms-amqp-10-sink-binding.yaml --reload
 ----
 
 Then while the Camel application is running, you can update the YAML route and update when saving.
 
+=== Running routes hosted on GitHub
+
+You can run a route that is hosted on GitHub using Camels xref:components:others:resourceresolver-github.adoc[github] resource loader.
+
+For example to run one of the Camel K examples you can do:
+
+[source,bash]
+----
+jbang -Dcamel.jbang.version=3.14.0 CamelJBang@apache/camel run run github:apache:camel-k:examples/languages/routes.yaml
+----
 
 == Installation