diff --git a/camel-quarkus/.dockerignore b/camel-quarkus-kubernetes/.dockerignore similarity index 100% rename from camel-quarkus/.dockerignore rename to camel-quarkus-kubernetes/.dockerignore diff --git a/camel-quarkus/README.md b/camel-quarkus-kubernetes/README.md similarity index 96% rename from camel-quarkus/README.md rename to camel-quarkus-kubernetes/README.md index f094c35..6ea3f1a 100644 --- a/camel-quarkus/README.md +++ b/camel-quarkus-kubernetes/README.md @@ -47,7 +47,7 @@ java -javaagent:target/quarkus-app/lib/main/org.jolokia.jolokia-agent-jvm-2.0.1- ## How to deploy it to Kubernetes/OpenShift -This example is intended to be used by deploying to a Kubernetes/OpenShift cluster. +This example is intended to be used by deploying to a Kubernetes/OpenShift cluster. An [alternative example](https://github.com/hawtio/hawtio-online-examples/camel-quarkus-openshift) is available should the target cluster be OpenShift. To deploy it to a cluster, firstly change the container image parameters in [pom.xml](pom.xml) to fit your development environment. (The default image name is `quay.io/hawtio/hawtio-online-example-camel-quarkus:latest`, which should be pushed to the `hawtio` organisation on [Quay.io](https://quay.io/).) @@ -80,9 +80,9 @@ $ stern -oraw hawtio-online-example-camel-quarkus + hawtio-online-example-camel-quarkus-77f7bf4948-74hmb › hawtio-online-example-camel-quarkus I> No access restrictor found, access to any MBean is allowed Jolokia: Agent started with URL https://172.17.45.52:8778/jolokia/ - _____________________________________ + _____________________________________ < Hawtio Online Camel Quarkus Example > - ------------------------------------- + ------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ diff --git a/camel-quarkus/pom.xml b/camel-quarkus-kubernetes/pom.xml similarity index 97% rename from camel-quarkus/pom.xml rename to camel-quarkus-kubernetes/pom.xml index 16de25d..4cd6a60 100644 --- a/camel-quarkus/pom.xml +++ b/camel-quarkus-kubernetes/pom.xml @@ -8,9 +8,9 @@ 1.0.0 - hawtio-online-example-camel-quarkus - Hawtio Online Camel Quarkus Example - Hawtio Online :: Sample Camel Quarkus 3.x application + hawtio-online-example-camel-quarkus-kube + Kubernetes Hawtio Online Camel Quarkus Example + Hawtio Online :: Sample Kubernetes Camel Quarkus 3.x application true diff --git a/camel-quarkus/src/main/java/io/hawt/online/example/quarkus/SampleCamelRoute.java b/camel-quarkus-kubernetes/src/main/java/io/hawt/online/example/quarkus/SampleCamelRoute.java similarity index 100% rename from camel-quarkus/src/main/java/io/hawt/online/example/quarkus/SampleCamelRoute.java rename to camel-quarkus-kubernetes/src/main/java/io/hawt/online/example/quarkus/SampleCamelRoute.java diff --git a/camel-quarkus/src/main/resources/application.properties b/camel-quarkus-kubernetes/src/main/resources/application.properties similarity index 100% rename from camel-quarkus/src/main/resources/application.properties rename to camel-quarkus-kubernetes/src/main/resources/application.properties diff --git a/camel-quarkus/src/main/resources/default_banner.txt b/camel-quarkus-kubernetes/src/main/resources/default_banner.txt similarity index 100% rename from camel-quarkus/src/main/resources/default_banner.txt rename to camel-quarkus-kubernetes/src/main/resources/default_banner.txt diff --git a/camel-quarkus-openshift/.dockerignore b/camel-quarkus-openshift/.dockerignore new file mode 100644 index 0000000..94810d0 --- /dev/null +++ b/camel-quarkus-openshift/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-app/* \ No newline at end of file diff --git a/camel-quarkus-openshift/README.md b/camel-quarkus-openshift/README.md new file mode 100644 index 0000000..aae9e7f --- /dev/null +++ b/camel-quarkus-openshift/README.md @@ -0,0 +1,93 @@ +# Hawtio-Enabled Camel Quarkus Example for OpenShift + +This sample application shows how to make it _hawtio-enabled_ with Camel Quarkus. Once deployed on OpenShift, it will be discovered by Hawtio Online. + +## Highlights + +- [pom.xml](pom.xml) + +This project uses the Quarkus [OpenShift](https://quarkus.io/guides/deploying-to-openshift) extension to build a container image and deploy it to an OpenShift cluster. Should the target cluster be a different version of Kubernetes then an [alternative example](https://github.com/hawtio/hawtio-online-examples/camel-quarkus-openshift) is available. + +The most important part in terms of the _hawtio-enabled_ configuration is defined in the `` section. To make it _hawtio-enabled_, the Jolokia agent must be attached to the application with HTTPS and SSL client authentication configured. The client principal should match those the Hawtio Online instance provides (the default is `hawtio-online.hawtio.svc`). + +```xml + + https + * + 8778 + true + /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + cn=hawtio-online.hawtio.svc + true + false + +``` + +## How to run locally + +Run in development mode with: + +```console +mvn compile quarkus:dev +``` + +Or build the project and execute the runnable JAR: + +```console +mvn package && java -jar target/quarkus-app/quarkus-run.jar +``` + +### Running with Jolokia agent locally + +You can run this example with Jolokia JVM agent locally as follows: + +```console +java -javaagent:target/quarkus-app/lib/main/org.jolokia.jolokia-agent-jvm-2.0.1-javaagent.jar -jar target/quarkus-app/quarkus-run.jar +``` + +## How to deploy it to OpenShift + +This example is intended to be used by deploying to an OpenShift cluster. + +To deploy it to a cluster, ensure that the console has access to the OpenShift cluster by logging into it. Then execute the following: + +```console +mvn clean package -Dquarkus.kubernetes.deploy=true +``` +After deployment is successful and the pod has started, the application log can be seen on the cluster like this: + +```console +$ oc log hawtio-online-example-camel-quarkus-os-xxxxxxxxx-xxxxx +INFO exec -a "java" java -XX:MaxRAMPercentage=80.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -javaagent:lib/main/org.jolokia.jolokia-agent-jvm-2.1.0-javaagent.jar=protocol=https,host=*,port=8778,useSslClientAuthentication=true,caCert=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt,clientPrincipal.1=cn=hawtio-online.hawtio.svc,extendedClientCheck=true,discoveryEnabled=false -cp "." -jar /deployments/quarkus-run.jar +INFO running in /deployments +I> No access restrictor found, access to any MBean is allowed +Jolokia: Agent started with URL https://10.217.0.156:8778/jolokia/ +__ ____ __ _____ ___ __ ____ ______ + --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ + -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ +--\___\_\____/_/ |_/_/|_/_/|_|\____/___/ +2024-09-12 13:37:27,570 INFO [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) Apache Camel Quarkus 3.14.0 is starting +2024-09-12 13:37:27,628 INFO [org.apa.cam.mai.MainSupport] (main) Apache Camel (Main) 4.7.0 is starting +2024-09-12 13:37:27,740 INFO [org.apa.cam.mai.BaseMainSupport] (main) Auto-configuration summary +2024-09-12 13:37:27,741 INFO [org.apa.cam.mai.BaseMainSupport] (main) [MicroProfilePropertiesSource] camel.context.name=SampleCamel +2024-09-12 13:37:27,848 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Detected: camel-debug JAR (Enabling Camel Debugging) +2024-09-12 13:37:27,994 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 4.7.0 (SampleCamel) is starting +2024-09-12 13:37:28,801 INFO [org.apa.cam.com.qua.QuartzComponent] (main) Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX +2024-09-12 13:37:28,869 INFO [org.apa.cam.com.qua.QuartzEndpoint] (main) Job Camel_SampleCamel.cron (cron=0/10 * * * * ?, triggerType=CronTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is 2024-09-12T13:37:30.000+0000 +2024-09-12 13:37:28,992 INFO [org.apa.cam.com.qua.QuartzEndpoint] (main) Job Camel_SampleCamel.simple (cron=null, triggerType=SimpleTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is 2024-09-12T13:37:28.987+0000 +2024-09-12 13:37:29,140 INFO [org.apa.cam.mai.BaseMainSupport] (main) Property-placeholders summary +2024-09-12 13:37:29,140 INFO [org.apa.cam.mai.BaseMainSupport] (main) [MicroProfilePropertiesSource] quartz.cron=0/10 * * * * ? +2024-09-12 13:37:29,140 INFO [org.apa.cam.mai.BaseMainSupport] (main) [MicroProfilePropertiesSource] quartz.repeatInterval=10000 +2024-09-12 13:37:29,141 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (total:2) +2024-09-12 13:37:29,141 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started cron (quartz://cron) +2024-09-12 13:37:29,141 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Started simple (quartz://simple) +2024-09-12 13:37:29,142 INFO [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 4.7.0 (SampleCamel) started in 1s147ms (build:0ms init:0ms start:1s147ms) +2024-09-12 13:37:29,142 INFO [org.apa.cam.imp.deb.DefaultBacklogDebugger] (main) Enabling Camel debugger +2024-09-12 13:37:29,143 INFO [org.apa.cam.com.qua.QuartzComponent] (main) Starting Quartz scheduler: org.quartz.impl.StdScheduler@44af588b +Hello Camel! - simple +2024-09-12 13:37:29,211 INFO [org.apa.cam.imp.deb.DebuggerJmxConnectorService] (Camel (camel-1) thread #1 - DebuggerJMXConnector) Debugger JMXConnector listening at: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel +Hello Camel! - cron +Hello Camel! - simple +Hello Camel! - cron +Hello Camel! - simple +``` diff --git a/camel-quarkus-openshift/pom.xml b/camel-quarkus-openshift/pom.xml new file mode 100644 index 0000000..2b08a33 --- /dev/null +++ b/camel-quarkus-openshift/pom.xml @@ -0,0 +1,220 @@ + + + 4.0.0 + + + io.hawt.online.examples + hawtio-online-examples + 1.0.0 + + + hawtio-online-example-camel-quarkus-os + OpenShift Hawtio Online Camel Quarkus Example + Hawtio Online :: Sample OpenShift Camel Quarkus 3.x application + + + true + + + + + https + * + 8778 + true + /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt + cn=hawtio-online.hawtio.svc + true + false + + + + + + io.quarkus.platform + quarkus-bom + ${quarkus-version} + pom + import + + + io.quarkus.platform + quarkus-camel-bom + ${quarkus-version} + pom + import + + + + + + + io.quarkus + quarkus-openshift + + + org.apache.camel.quarkus + camel-quarkus-quartz + + + org.apache.camel.quarkus + camel-quarkus-stream + + + org.apache.camel.quarkus + camel-quarkus-mock + + + io.quarkus + quarkus-arc + + + + + org.apache.camel.quarkus + camel-quarkus-management + + + + + org.apache.camel.quarkus + camel-quarkus-jaxb + + + + + org.apache.camel.quarkus + camel-quarkus-debug + + + + + org.jolokia + jolokia-agent-jvm + ${jolokia-version} + javaagent + + + + io.quarkus + quarkus-junit5 + test + + + + + + + src/main/resources + true + + + + + + io.quarkus.platform + quarkus-maven-plugin + ${quarkus-version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + maven-compiler-plugin + + true + + + + maven-surefire-plugin + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + + + maven-antrun-plugin + + + native-mode-not-supported + validate + + run + + + + + + + + + + + + + + + diff --git a/camel-quarkus-openshift/src/main/docker/Dockerfile.jvm b/camel-quarkus-openshift/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..7a8342f --- /dev/null +++ b/camel-quarkus-openshift/src/main/docker/Dockerfile.jvm @@ -0,0 +1,97 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/quarkus-helloworld-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-helloworld-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-helloworld-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi8/openjdk-17:1.20 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/camel-quarkus-openshift/src/main/java/org/hawtio/SampleCamelRoute.java b/camel-quarkus-openshift/src/main/java/org/hawtio/SampleCamelRoute.java new file mode 100644 index 0000000..a6f62b8 --- /dev/null +++ b/camel-quarkus-openshift/src/main/java/org/hawtio/SampleCamelRoute.java @@ -0,0 +1,21 @@ +package org.hawtio; + +import jakarta.enterprise.context.ApplicationScoped; +import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + +@ApplicationScoped +public class SampleCamelRoute extends EndpointRouteBuilder { + + @Override + public void configure() { + from(quartz("cron").cron("{{quartz.cron}}")).routeId("cron") + .setBody().constant("Hello Camel! - cron") + .to(stream("out")) + .to(mock("result")); + + from("quartz:simple?trigger.repeatInterval={{quartz.repeatInterval}}").routeId("simple") + .setBody().constant("Hello Camel! - simple") + .to(stream("out")) + .to(mock("result")); + } +} diff --git a/camel-quarkus-openshift/src/main/resources/application.properties b/camel-quarkus-openshift/src/main/resources/application.properties new file mode 100644 index 0000000..20d373c --- /dev/null +++ b/camel-quarkus-openshift/src/main/resources/application.properties @@ -0,0 +1,28 @@ +quarkus.openshift.build-strategy=docker +quarkus.openshift.route.expose=true + +# Enable the jolokia java-agent on the quarkus application +quarkus.openshift.env.vars.JAVA_OPTS_APPEND=-javaagent:lib/main/org.jolokia.jolokia-agent-jvm-${jolokia-version}-javaagent.jar=protocol=${jolokia.protocol}\,host=${jolokia.host}\,port=${jolokia.port}\,useSslClientAuthentication=${jolokia.useSslClientAuthentication}\,caCert=${jolokia.caCert}\,clientPrincipal.1=${jolokia.clientPrincipal.1}\,extendedClientCheck=${jolokia.extendedClientCheck}\,discoveryEnabled=${jolokia.discoveryEnabled} + +# Define the jolokia port on the container for hawtio access +quarkus.openshift.ports.jolokia.container-port=${jolokia.port} +quarkus.openshift.ports.jolokia.protocol=TCP + +#quarkus.log.min-level = TRACE +quarkus.log.category."io.quarkus".level = WARN +quarkus.log.category."io.undertow".level = WARN +quarkus.log.category."org.apache.camel".level = INFO + +# Camel +camel.context.name = SampleCamel + +# Enable the Camel plugin Trace tab +#camel.main.tracing = true +#camel.main.backlogTracing = true +#camel.main.useBreadcrumb = true + +# Enable the Camel plugin Debug tab even in non-development environment +quarkus.camel.debug.enabled = true + +quartz.cron = 0/10 * * * * ? +quartz.repeatInterval = 10000 diff --git a/pom.xml b/pom.xml index ddb14ae..225af6d 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,8 @@ - camel-quarkus + camel-quarkus-kubernetes + camel-quarkus-openshift camel-springboot