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

[camel-k] branch master updated: Adding JVM runtime

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d7cefab  Adding JVM runtime
d7cefab is described below

commit d7cefabcf222635e691e5e715fbae5916372d9a2
Author: nferraro <ni...@gmail.com>
AuthorDate: Fri Sep 7 11:30:22 2018 +0200

    Adding JVM runtime
---
 pkg/build/local/local_builder.go                   |  2 +-
 runtime/jvm/.gitignore                             |  5 +++
 runtime/jvm/pom.xml                                | 38 ++++++++++++++++
 .../java/org/apache/camel/k/jvm/Application.java   | 18 ++++++++
 .../main/java/org/apache/camel/k/jvm/Runner.java   | 26 +++++++++++
 runtime/jvm/src/main/resources/log4j2.properties   |  7 +++
 .../org/apache/camel/k/jvm/ApplicationTest.java    | 15 +++++++
 .../test/java/org/apache/camel/k/jvm/MyRoutes.java | 11 +++++
 runtime/pom.xml                                    | 52 ++++++++++++++++++++++
 9 files changed, 173 insertions(+), 1 deletion(-)

diff --git a/pkg/build/local/local_builder.go b/pkg/build/local/local_builder.go
index 02bacf1..bb79ce8 100644
--- a/pkg/build/local/local_builder.go
+++ b/pkg/build/local/local_builder.go
@@ -426,7 +426,7 @@ func (b *localBuilder) createMavenStructure(buildDir string, source build.BuildS
 
 func (b *localBuilder) createEnvFile() string {
 	return `
-JAVA_MAIN_CLASS=me.nicolaferraro.kamel.Application
+JAVA_MAIN_CLASS=org.apache.camel.k.jvm.Application
 KAMEL_CLASS=kamel.Routes
 `
 }
diff --git a/runtime/jvm/.gitignore b/runtime/jvm/.gitignore
new file mode 100644
index 0000000..dd8baff
--- /dev/null
+++ b/runtime/jvm/.gitignore
@@ -0,0 +1,5 @@
+.idea
+.project
+.metadata
+target
+*.iml
diff --git a/runtime/jvm/pom.xml b/runtime/jvm/pom.xml
new file mode 100644
index 0000000..27cfe06
--- /dev/null
+++ b/runtime/jvm/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>0.0.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-k-runtime-jvm</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>${log4j2.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java
new file mode 100644
index 0000000..ad7c54a
--- /dev/null
+++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Application.java
@@ -0,0 +1,18 @@
+package org.apache.camel.k.jvm;
+
+public class Application {
+
+    public static final String ENV_KAMEL_CLASS = "KAMEL_CLASS";
+
+    public static void main(String[] args) throws Exception {
+
+        String clsName = System.getenv(ENV_KAMEL_CLASS);
+        if (clsName == null || clsName.trim().length() == 0) {
+            throw new IllegalStateException("No valid class found in " + ENV_KAMEL_CLASS + " environment variable");
+        }
+
+        Runner runner = new Runner();
+        runner.run(clsName);
+    }
+
+}
diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Runner.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Runner.java
new file mode 100644
index 0000000..7b1a58c
--- /dev/null
+++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Runner.java
@@ -0,0 +1,26 @@
+package org.apache.camel.k.jvm;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+
+import java.util.Objects;
+
+public class Runner {
+
+    public void run(String className) throws Exception {
+        Objects.requireNonNull(className, "className must be present");
+
+        Class<?> cls = Class.forName(className);
+        Object instance = cls.newInstance();
+        if (!RouteBuilder.class.isInstance(instance)) {
+            throw new IllegalStateException("The class provided (" + className + ") is not a org.apache.camel.builder.RouteBuilder");
+        }
+
+        RouteBuilder builder = (RouteBuilder) instance;
+
+        Main main = new Main();
+        main.addRouteBuilder(builder);
+        main.run();
+    }
+
+}
diff --git a/runtime/jvm/src/main/resources/log4j2.properties b/runtime/jvm/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..9d5f10e
--- /dev/null
+++ b/runtime/jvm/src/main/resources/log4j2.properties
@@ -0,0 +1,7 @@
+appender.console.type = Console
+appender.console.name = console
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
+
+rootLogger.level = INFO
+rootLogger.appenderRef.stdout.ref = console
\ No newline at end of file
diff --git a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/ApplicationTest.java b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/ApplicationTest.java
new file mode 100644
index 0000000..39c6c7d
--- /dev/null
+++ b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/ApplicationTest.java
@@ -0,0 +1,15 @@
+package org.apache.camel.k.jvm;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ApplicationTest {
+
+    @Test
+    @Ignore
+    public void applicationTest() throws Exception {
+        Runner runner = new Runner();
+        runner.run(MyRoutes.class.getCanonicalName());
+    }
+
+}
diff --git a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/MyRoutes.java b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/MyRoutes.java
new file mode 100644
index 0000000..c92f35a
--- /dev/null
+++ b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/MyRoutes.java
@@ -0,0 +1,11 @@
+package org.apache.camel.k.jvm;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyRoutes extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        from("timer:tick")
+                .to("log:info");
+    }
+}
\ No newline at end of file
diff --git a/runtime/pom.xml b/runtime/pom.xml
new file mode 100644
index 0000000..3987857
--- /dev/null
+++ b/runtime/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.camel.k</groupId>
+    <artifactId>camel-k-runtime-parent</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+
+        <camel.version>2.22.0</camel.version>
+        <junit.version>4.12</junit.version>
+        <log4j2.version>2.11.0</log4j2.version>
+        <slf4j.version>1.7.25</slf4j.version>
+
+        <fabric8-maven-plugin.version>3.5.40</fabric8-maven-plugin.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-bom</artifactId>
+                <version>${camel.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>io.fabric8</groupId>
+                    <artifactId>fabric8-maven-plugin</artifactId>
+                    <version>${fabric8-maven-plugin.version}</version>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+
+    <modules>
+        <module>jvm</module>
+    </modules>
+    
+</project>
\ No newline at end of file