Open Liberty
Run a warehouse-location API on Open Liberty: a kernel-slim UBI image, MicroProfile Health on port 9080, and a Deployment on OpenShift.
JBoss EAP served a catalog of SKU names. This lab is the next question a picker asks: which warehouse holds the SKU. The runtime is Open Liberty on the IBM Container Registry image, Java 21, UBI minimal. The pod is a Deployment. Probes call MicroProfile Health on the HTTP port.
The quantities and the reorder rule stay in the Spring Boot and Quarkus services. This process only answers a location.
Prerequisites
- JDK 21 and Maven
- Podman or Docker
- OpenShift 4.x and
oc. The cluster can pullicr.io/appcafe/open-liberty(no registry login)
Step 1: The application
mkdir locations && cd locations
mkdir -p src/main/java/com/comptech/locations src/main/webapp/WEB-INF src/main/liberty/config
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.comptech</groupId>
<artifactId>locations</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.finalName>locations</project.build.finalName>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.health</groupId>
<artifactId>microprofile-health-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>3.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
src/main/webapp/WEB-INF/beans.xml turns the WAR into a bean archive so injection works:
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" bean-discovery-mode="annotated"/>
src/main/java/com/comptech/locations/Api.java sets the root. The resource is Locations.java, and it is public.
package com.comptech.locations;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
@ApplicationPath("/")
public class Api extends Application {}
package com.comptech.locations;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.Map;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;
@Path("/locations")
@ApplicationScoped
public class Locations {
private static final Map<String, String> BIN = Map.of(
"SRV-RACK", "A-14", "GPU-NODE", "C-02", "TOR-SW", "B-07");
@Inject @ConfigProperty(name = "warehouse", defaultValue = "")
String warehouse;
@GET @Path("/{sku}") @Produces(MediaType.APPLICATION_JSON)
public Response get(@PathParam("sku") String sku) {
String bin = BIN.get(sku);
if (bin == null) return Response.status(Response.Status.NOT_FOUND).build();
return Response.ok("{\"sku\":\"" + sku + "\",\"warehouse\":\"" + warehouse + "\",\"bin\":\"" + bin + "\"}").build();
}
}
@Readiness
@ApplicationScoped
class WarehouseCheck implements HealthCheck {
@Inject @ConfigProperty(name = "warehouse", defaultValue = "")
String warehouse;
public HealthCheckResponse call() {
return HealthCheckResponse.named("warehouse").status(!warehouse.isBlank()).build();
}
}
warehouse comes from the environment variable WAREHOUSE. MicroProfile Config maps that name on its own. WarehouseCheck is in Locations.java. Both injections default to empty, so a missing variable still starts the server. An empty value fails readiness and leaves liveness alone, the same split as the Quarkus lab. Live and started are the server's own checks.
src/main/liberty/config/server.xml:
<server>
<featureManager>
<feature>restfulWS-3.1</feature>
<feature>jsonb-3.0</feature>
<feature>cdi-4.0</feature>
<feature>mpConfig-3.1</feature>
<feature>mpHealth-4.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="-1"/>
<webApplication location="locations.war" contextRoot="/"/>
</server>
httpsPort="-1" keeps TLS off inside the pod. The OpenShift Route terminates TLS. Turn HTTPS back on before this server is reachable as anything other than a cluster-local port, and point the probes at that port.
Step 2: Image
The kernel-slim tag starts small. features.sh installs the features named in server.xml. configure.sh caches the server so the pod does not do that work on every start. The image user is 1001, group 0, which is what the restricted policy expects.
Containerfile:
FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal
COPY --chown=1001:0 src/main/liberty/config/server.xml /config/
RUN features.sh
COPY --chown=1001:0 target/locations.war /config/apps/
RUN configure.sh
mvn -B package
podman build -t locations:1 -f Containerfile .
podman run --rm -p 9080:9080 -e WAREHOUSE=lab locations:1
curl -s localhost:9080/locations/GPU-NODE
# {"sku":"GPU-NODE","warehouse":"lab","bin":"C-02"}
curl -s localhost:9080/health/live
curl -s localhost:9080/health/ready
curl -s localhost:9080/health/started
Stop the container. Run it again without WAREHOUSE: /health/live stays UP and /health/ready goes DOWN.
Step 3: Deploy
oc new-project locations
oc new-build --binary --strategy=docker --name=locations --dockerfile-path=Containerfile
oc start-build locations --from-dir=. --follow
oc create configmap locations-config --from-literal=warehouse=dhk-1
deploy/locations.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: locations
spec:
replicas: 2
selector:
matchLabels: { app: locations }
template:
metadata:
labels: { app: locations }
spec:
containers:
- name: locations
image: image-registry.openshift-image-registry.svc:5000/locations/locations:latest
ports: [{ containerPort: 9080 }]
env:
- name: WAREHOUSE
valueFrom: { configMapKeyRef: { name: locations-config, key: warehouse } }
startupProbe:
httpGet: { path: /health/started, port: 9080 }
failureThreshold: 30
periodSeconds: 2
readinessProbe:
httpGet: { path: /health/ready, port: 9080 }
periodSeconds: 10
livenessProbe:
httpGet: { path: /health/live, port: 9080 }
periodSeconds: 10
resources:
requests: { cpu: 100m, memory: 256Mi }
limits: { memory: 512Mi }
---
apiVersion: v1
kind: Service
metadata: { name: locations }
spec:
selector: { app: locations }
ports: [{ port: 80, targetPort: 9080 }]
---
apiVersion: route.openshift.io/v1
kind: Route
metadata: { name: locations }
spec:
to: { kind: Service, name: locations }
tls: { termination: edge, insecureEdgeTerminationPolicy: Redirect }
oc apply -f deploy/locations.yaml
oc rollout status deployment/locations
HOST=$(oc get route locations -o jsonpath='{.spec.host}')
curl -sk "https://$HOST/locations/SRV-RACK"
curl -sk "https://$HOST/health/ready"
Clear the warehouse. oc set env rolls out pods with the variable removed. Those pods stay Running, drop out of the Service, and liveness leaves them alone. oc apply puts the ConfigMap reference back.
oc set env deployment/locations WAREHOUSE-
oc get pods
oc apply -f deploy/locations.yaml
oc rollout status deployment/locations
The Open Liberty Operator (OpenLibertyApplication) wraps this Deployment and can set the same three probes under spec.probes. The YAML above is the object the operator would create. File-based checks write /output/health/ready (and live and started) once you set checkInterval on mpHealth. That path needs mpHealth 4.0, which this server.xml already enables, and Liberty 25.0.0.6 or newer. The probes in this lab stay on HTTP.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
features.sh fails |
A feature name is not in this image | Read the script output; keep the five features above |
| Ready never comes up | WAREHOUSE is empty |
oc exec deploy/locations -- printenv WAREHOUSE |
| Injection error at start | WAR is not a bean archive | WEB-INF/beans.xml with bean-discovery-mode="annotated" |
HTTP 404 on /health/ready |
mpHealth-4.0 missing from server.xml |
Add the feature and rebuild |
Clean up
oc delete project locations
What's next
Tomcat serves a bin label from the same SKUs, on JBoss Web Server. JBoss EAP is the catalog these locations belong to. Container builds is the Buildah build this Containerfile went through.