Skip to content

Commit

Permalink
Make camel-springboot hawtio-enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Nov 23, 2023
1 parent 490e786 commit 7eb5ff2
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 88 deletions.
121 changes: 94 additions & 27 deletions camel-springboot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,116 @@

This sample application shows how to make it hawtio-enabled with Camel Spring Boot. Once deployed on OpenShift/Kubernetes, it will be discovered by Hawtio Online.

## How to run
## Highlights

Run with:
- [pom.xml](pom.xml)

mvn spring-boot:run
This project uses JKube [kubernetes-maven-plugin](https://eclipse.dev/jkube/docs/kubernetes-maven-plugin/) to build a container image and deploy it to a Kubernetes/OpenShift cluster. JKube supports Jolokia out of the box and the default base image already includes Jolokia agent.

Hawtio is exposed at the [Actuator](https://docs.spring.io/spring-boot/docs/latest/reference/html/production-ready-endpoints.html) management port configured using
`management.server.port` in `application.properties`. Browse Hawtio via the following URL: http://localhost:10001/actuator/hawtio/index.html
All you need to make the application _hawtio-enabled_ is to define additional environment variables to the deployment resource to fine-tune the Jolokia agent options. By default, JKube plugin sets up a Jolokia agent with HTTPS and SSL client authentication enabled. The only necessary configurations are the client principal that matches the Hawtio Online instance (the default is `hawtio-online.hawtio.svc`) and the CA cert to specify `service-ca.crt` instead of the default `ca.crt`.

The actual application is running on port 10000 (`server.port` in `application.properties`).
```xml
<configuration>
<resources>
<env>
<AB_JOLOKIA_AUTH_OPENSHIFT>cn=hawtio-online.hawtio.svc</AB_JOLOKIA_AUTH_OPENSHIFT>
<AB_JOLOKIA_OPTS>caCert=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt</AB_JOLOKIA_OPTS>
</env>
</resources>
</configuration>
```

## Alternative configurations
## How to run locally

### Alternative management endpoint base paths
If your preference is to avoid running Hawtio under the `/actuator` path, you can set the `management.endpoints.web.base-path` property in `application.properties`:
Run with:

```
management.endpoints.web.base-path=/
```console
mvn spring-boot:run
```

Hawtio will then be available at http://localhost:10001/hawtio/index.html.
## How to deploy it to Kubernetes/OpenShift

### Alternative hawtio endpoint paths
This example is intended to be used by deploying to a Kubernetes/OpenShift cluster.

You can also customize the endpoint path of the Hawtio actuator endpoint by setting the `management.endpoints.web.path-mapping.hawtio` property in `application.properties`:
To deploy it to a cluster, firstly change the container image name in [pom.xml](pom.xml) to fit your development environment. (The default image name is `quay.io/hawtio/hawtio-online-example-camel-springboot:latest`, which should be pushed to the `hawtio` organisation on [Quay.io](https://quay.io/).)

```
management.endpoints.web.path-mapping.hawtio=hawtio/console
```xml
<jkube.generator.name>quay.io/hawtio/%a:latest</jkube.generator.name>
```

### Alternative ports & context paths
Alternative ports and context path configurations can be tested by changing the following properties in `application.properties`:
Then build the project and container image:

```console
mvn package k8s:build
```
server.port=10000
server.servlet.context-path=/sample-app
management.port=10000
management.server.servlet.context-path=/management

and push the image to the container registry so that Kubernetes/OpenShift can pull it at deployment:

```console
mvn k8s:push
```

Using the above configuration, the server will use port 10000 and the custom context path `sample-app`.
The Actuator management endpoints and Hawtio will also run on port 10000 using the custom management context path `management`.
The URLs for accessing the application and Hawtio are as follows:
To deploy it to Kubernetes/OpenShift:

- Application: http://localhost:10000/sample-app/
- Hawtio: http://localhost:10000/sample-app/management/actuator/hawtio
```console
mvn k8s:resource k8s:deploy
```

After deployment is successful and the pod has started, the application log can be seen on the cluster like this:

```console
$ hawtio-online-example-camel-springboot
+ hawtio-online-example-camel-springboot-7f578548d6-s27j4 › spring-boot
Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec java -javaagent:/usr/share/java/jolokia-jvm-agent/jolokia-jvm.jar=config=/opt/jboss/container/jolokia/etc/jolokia.properties -javaagent:/usr/share/java/prometheus-jmx-exporter/jmx_prometheus_javaagent.jar=9779:/opt/jboss/container/prometheus/etc/jmx-exporter-config.yaml -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:+ExitOnOutOfMemoryError -cp ".:/deployments/*" org.springframework.boot.loader.JarLauncher
_________________________________________
< Hawtio Online Camel Spring Boot Example >
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

I> No access restrictor found, access to any MBean is allowed
Jolokia: Agent started with URL https://172.17.11.234:8778/jolokia/
2023-11-23T03:51:12.505Z INFO 1 --- [ main] i.h.o.e.s.SampleSpringBootService : Starting SampleSpringBootService using Java 17.0.9 with PID 1 (/deployments/BOOT-INF/classes started by jboss in /deployments)
2023-11-23T03:51:12.512Z INFO 1 --- [ main] i.h.o.e.s.SampleSpringBootService : No active profile set, falling back to 1 default profile: "default"
2023-11-23T03:51:15.938Z INFO 1 --- [ main] o.a.c.i.e.DefaultCamelContextExtension : Detected: camel-debug JAR (Enabling Camel Debugging)
2023-11-23T03:51:17.021Z INFO 1 --- [ main] org.xnio : XNIO version 3.8.8.Final
2023-11-23T03:51:17.037Z INFO 1 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.8.8.Final
2023-11-23T03:51:17.077Z INFO 1 --- [ main] org.jboss.threads : JBoss Threads version 3.5.0.Final
2023-11-23T03:51:17.502Z INFO 1 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.1.0 (SampleCamelSpringBoot) is starting
2023-11-23T03:51:17.582Z INFO 1 --- [ main] o.a.c.component.quartz.QuartzComponent : Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX
2023-11-23T03:51:17.617Z INFO 1 --- [ main] org.quartz.impl.StdSchedulerFactory : Using default implementation for ThreadExecutor
2023-11-23T03:51:17.621Z INFO 1 --- [ main] org.quartz.simpl.SimpleThreadPool : Job execution threads will use class loader of thread: main
2023-11-23T03:51:17.632Z INFO 1 --- [ main] org.quartz.core.SchedulerSignalerImpl : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2023-11-23T03:51:17.633Z INFO 1 --- [ main] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.2 created.
2023-11-23T03:51:17.633Z INFO 1 --- [ main] org.quartz.simpl.RAMJobStore : RAMJobStore initialized.
2023-11-23T03:51:17.638Z INFO 1 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.2) 'DefaultQuartzScheduler-SampleCamelSpringBoot' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

2023-11-23T03:51:17.638Z INFO 1 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'DefaultQuartzScheduler-SampleCamelSpringBoot' initialized from an externally provided properties instance.
2023-11-23T03:51:17.638Z INFO 1 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.2
2023-11-23T03:51:17.651Z INFO 1 --- [ main] o.a.c.component.quartz.QuartzEndpoint : Job Camel_SampleCamelSpringBoot.cron (cron=0/10 * * * * ?, triggerType=CronTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is 2023-11-23T03:51:20.000+0000
2023-11-23T03:51:17.688Z INFO 1 --- [ main] o.a.c.component.quartz.QuartzEndpoint : Job Camel_SampleCamelSpringBoot.simple (cron=null, triggerType=SimpleTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is 2023-11-23T03:51:17.685+0000
2023-11-23T03:51:17.733Z INFO 1 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Routes startup (started:2)
2023-11-23T03:51:17.733Z INFO 1 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Started cron (quartz://cron)
2023-11-23T03:51:17.733Z INFO 1 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Started simple (quartz://simple)
2023-11-23T03:51:17.733Z INFO 1 --- [ main] o.a.c.impl.engine.AbstractCamelContext : Apache Camel 4.1.0 (SampleCamelSpringBoot) started in 230ms (build:0ms init:0ms start:230ms)
2023-11-23T03:51:17.735Z INFO 1 --- [ main] o.a.camel.impl.debugger.BacklogDebugger : Enabling Camel debugger
2023-11-23T03:51:17.735Z INFO 1 --- [ main] o.a.c.component.quartz.QuartzComponent : Starting Quartz scheduler: org.quartz.impl.StdScheduler@72b53f27
2023-11-23T03:51:17.740Z INFO 1 --- [ main] org.quartz.core.QuartzScheduler : Scheduler DefaultQuartzScheduler-SampleCamelSpringBoot_$_NON_CLUSTERED started.
2023-11-23T03:51:17.744Z INFO 1 --- [ main] i.h.o.e.s.SampleSpringBootService : Started SampleSpringBootService in 6.646 seconds (process running for 7.617)
Hello Camel! - simple
2023-11-23T03:51:17.788Z INFO 1 --- [melJMXConnector] o.a.c.c.debug.JmxConnectorService : JMX Connector thread started and listening at: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel
Hello Camel! - cron
Hello Camel! - simple
Hello Camel! - cron
Hello Camel! - simple
```
6 changes: 0 additions & 6 deletions camel-springboot/jmx-exporter.yml

This file was deleted.

50 changes: 22 additions & 28 deletions camel-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<name>Hawtio Online Camel Spring Boot Example</name>
<description>Hawtio Online :: Sample Camel Spring Boot 3.x application</description>

<properties>
<jkube.generator.name>quay.io/hawtio/%a:latest</jkube.generator.name>
<!-- Use Jib in order not to depend on docker nor podman -->
<jkube.build.strategy>jib</jkube.build.strategy>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -105,12 +111,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<configuration>
<mainClass>io.hawt.online.example.springboot.SampleSpringBootService</mainClass>
<jvmArguments>
-javaagent:./target/dependency/jmx_prometheus_javaagent.jar=10002:./jmx-exporter.yml
</jvmArguments>
</configuration>
<executions>
<execution>
<goals>
Expand All @@ -119,30 +119,24 @@
</execution>
</executions>
</plugin>

<!-- Downloads the Prometheus JMX exporter Java agent -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<version>${kubernetes-maven-plugin-version}</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.prometheus.jmx</groupId>
<artifactId>jmx_prometheus_javaagent</artifactId>
<version>${prometheus-jmx-exporter-version}</version>
<type>jar</type>
<destFileName>jmx_prometheus_javaagent.jar</destFileName>
</artifactItem>
</artifactItems>
<resources>
<env>
<!--
By default, JKube plugin sets up a Jolokia agent with HTTPS and
SSL client authentication enabled. The only necessary configurations
are the client principal that matches the Hawtio Online instance
(the default is `hawtio-online.hawtio.svc`) and the CA cert to
specify `service-ca.crt` instead of the default `ca.crt`.
-->
<AB_JOLOKIA_AUTH_OPENSHIFT>cn=hawtio-online.hawtio.svc</AB_JOLOKIA_AUTH_OPENSHIFT>
<AB_JOLOKIA_OPTS>caCert=/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt</AB_JOLOKIA_OPTS>
</env>
</resources>
</configuration>
</plugin>
</plugins>
Expand Down
28 changes: 1 addition & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
<jolokia-version>2.0.0-M4</jolokia-version>
<prometheus-jmx-exporter-version>0.20.0</prometheus-jmx-exporter-version>

<kubernetes-maven-plugin-version>1.15.0</kubernetes-maven-plugin-version>
<maven-antrun-plugin-version>3.1.0</maven-antrun-plugin-version>
<maven-clean-plugin-version>3.0.0</maven-clean-plugin-version>
<maven-compiler-plugin-version>3.11.0</maven-compiler-plugin-version>
<maven-dependency-plugin-version>3.6.1</maven-dependency-plugin-version>
<maven-failsafe-plugin-version>3.2.2</maven-failsafe-plugin-version>
<maven-release-plugin-version>3.0.1</maven-release-plugin-version>
<maven-resources-plugin-version>2.6</maven-resources-plugin-version>
<maven-surefire-plugin-version>3.2.2</maven-surefire-plugin-version>
</properties>

Expand All @@ -51,7 +49,6 @@
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin-version}</version>
</plugin>
Expand All @@ -63,37 +60,14 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin-version}</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin-version}</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin-version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin-version}</version>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin-version}</version>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-plugin-version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down

0 comments on commit 7eb5ff2

Please sign in to comment.