Skip to content

Commit 2520c06

Browse files
committed
Sync to the todo-backend QS; general tidying and updates
1 parent 194e6cd commit 2520c06

File tree

12 files changed

+186
-143
lines changed

12 files changed

+186
-143
lines changed

todo-jakarta-data/README-source.adoc

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
include::../shared-doc/attributes.adoc[]
22

3-
= todo-backend: quickstart for backend deployment on OpenShift
3+
= todo-jakata-data: quickstart for backend deployment on OpenShift
44
:toc: left
55
:icons: font
66
:idprefix:
77
:idseparator: -
88
:keywords: openshift,galleon,helm
99
:level: Intermediate
10-
:technologies: JPA, JAX-RS, OpenShift, Galleon
10+
:technologies: Jakarta Data, Jakarta REST, OpenShift, Galleon
1111
:openshift: true
1212
:archiveType: war
1313
:useHelmChartDir: true
@@ -17,11 +17,12 @@ include::../shared-doc/attributes.adoc[]
1717
:helmSetWildFlyArgumentPrefix: wildfly.
1818

1919
[abstract]
20-
The `todo-backend` quickstart demonstrates how to implement a backend that exposes a HTTP API with Jakarta RESTful Web Services
20+
The `todo-jakarta-data` quickstart demonstrates how to implement a backend that exposes a HTTP API with Jakarta RESTful Web Services
2121
to manage a list of ToDo which are persisted in a database with Jakarta Data.
22+
It is very similar to the `todo-backend` quickstart but uses Jakarta Data instead of Jakarta Persistence to handle interaction with the backend database.
2223

2324
ifndef::ProductRelease[]
24-
This quickstart shows how to setup a local deployment of this backend as well as a deployment on OpenShift to connect
25+
This quickstart shows how to set up a local deployment of this backend as well as a deployment on OpenShift to connect
2526
to a PostgreSQL database also hosted on OpenShift.
2627
endif::[]
2728
ifdef::ProductRelease[]
@@ -32,7 +33,7 @@ endif::[]
3233

3334
== What is it?
3435

35-
The `todo-backend` quickstart demonstrates how to implement a backend that exposes a HTTP API with `Jakarta REST`
36+
The `todo-jakarta-data` quickstart demonstrates how to implement a backend that exposes a HTTP API with `Jakarta REST`
3637
to manage a list of ToDo which are persisted in a database with `Jakarta Data`.
3738

3839
* The backend exposes a HTTP API to manage a list of todos that complies with the specs defined at https://todobackend.com/specs/index.html[todobackend.com].
@@ -48,6 +49,10 @@ ifdef::ProductRelease[]
4849
* It is deployed on OpenShift using the https://jbossas.github.io/eap-charts//[Helm Chart for {productName}].
4950
endif::[]
5051

52+
This quickstart
53+
is the same as the `todo-backend` quickstart, but uses `Jakarta Data` for its persistence layer, instead of `Jakarta Persistence`.
54+
To see the differences, compare this quickstart's `ToDoRepository` interface with the `ToDoDAO` interface and `ToDoDAOImpl` class in `todo-backend`.
55+
5156
// Link to the quickstart source
5257
include::../shared-doc/view-the-source.adoc[leveloffset=+1]
5358
// System Requirements
@@ -67,6 +72,7 @@ The layers are defined in the `pom.xml` file in the `<configuration>` section of
6772
----
6873
<layers>
6974
<layer>cloud-server</layer>
75+
<layer>jakarta-data</layer>
7076
<layer>postgresql-datasource</layer>
7177
</layers>
7278
----
@@ -80,13 +86,16 @@ The layers are defined in the `pom.xml` file in the `<configuration>` section of
8086
----
8187
<layers>
8288
<layer>cloud-server</layer>
89+
<layer>jakarta-data</layer>
8390
<layer>postgresql-datasource</layer>
8491
</layers>
8592
----
8693
endif::[]
8794

8895
The `cloud-server` layer provides everything needed to run the backend on OpenShift. This also includes access to
89-
Jakarta EE APIs such as CDI, JAX-RS, JPA, etc. These two layers comes from the {productName} feature pack provided in the
96+
Jakarta EE APIs such as CDI, Jakarta REST, etc, along with the Hibernate support used by Jakarta Data.
97+
The `jakarta-data` layer provides the Jakarta Data API.
98+
These two layers come from the {productName} feature pack provided in the
9099
{productName} S2I builder image.
91100

92101
ifndef::ProductRelease[]
@@ -105,6 +114,33 @@ The Git repository for this feature pack is hosted at https://github.com/jbossas
105114
It provides JDBC drivers and datasources for different databases but for this quickstart, we will only need the `postgresql-datasource`.
106115
endif::[]
107116

117+
=== Generation of the Jakarta Data Repository implementation
118+
119+
A key feature of Jakarta Data is it does not require application developers to write detailed code to write from and write to the backend database.
120+
Developers just need declare their entities (using Jakarta Persistence annotations like `@Entity`) and then write an repository interface that describes the desired persistence operations, using the Jakarta Data annotations.
121+
It is then up to the Jakarta Data implementation to generate an implementation of that interface.
122+
123+
WildFly's implementation of Jakarta Data, Hibernate Data Repositories, generates that implementation at application build time using an annotation processor run as part of compilation of the application.
124+
125+
This is handled in the project `pom.xml` by configuring the `maven-compiler-plugin`:
126+
127+
[source,xml]
128+
----
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-compiler-plugin</artifactId>
132+
<configuration>
133+
<annotationProcessorPaths>
134+
<path>
135+
<groupId>org.hibernate.orm</groupId>
136+
<artifactId>hibernate-jpamodelgen</artifactId>
137+
<version>${version.org.hibernate.jpamodelgen}</version>
138+
</path>
139+
</annotationProcessorPaths>
140+
</configuration>
141+
</plugin>
142+
----
143+
108144
=== Connection to the PostgreSQL database
109145

110146
ifndef::ProductRelease[]
@@ -117,11 +153,11 @@ is provided by the `org.jboss.eap:eap-datasources-galleon-pack` feature pack.
117153
endif::[]
118154

119155
By default, it exposes a single datasource.
120-
In the backend, the name of this datasource is `ToDoRepository` and is specified in the `persistence.xml` to configure JPA:
156+
In the backend, the name of this datasource is `ToDoRepository` and is specified in the `persistence.xml` to configure Hibernate:
121157

122158
[source,xml]
123159
----
124-
<persistence-unit name="primary">
160+
<persistence-unit name="ToDos">
125161
<jta-data-source>java:jboss/datasources/ToDos</jta-data-source>
126162
</persistence-unit>
127163
----
@@ -157,8 +193,6 @@ This script is executed at build time and will provide the following HTTP header
157193
By default, the backend accepts requests from any origin (`*`). This is only simplicity. It is possible to restrict
158194
the allowed origin using the environment variable `CORS_ORIGIN` at runtime.
159195

160-
ifndef::ProductRelease[]
161-
162196
== Run the Backend Locally
163197

164198
=== Package the Backend
@@ -167,7 +201,7 @@ The backend is packaged and deployed on a provisioned server:
167201

168202
[source,options="nowrap"]
169203
----
170-
$ mvn clean package -Pprovisioned-server
204+
$ mvn clean package
171205
----
172206

173207
=== Run a Local PostgreSQL Database
@@ -196,20 +230,24 @@ The backend is running, and we can use the HTTP API to manage a list of todos:
196230
[source,options="nowrap"]
197231
----
198232
# get a list of todos
199-
$ curl http://localhost:8080
233+
$ curl http://localhost:8080/todo-jakarta-data
200234
[]
201235
202236
# create a todo with the title "This is my first todo item!"
203237
$ curl -X POST -H "Content-Type: application/json" -d '{"title": "This is my first todo item!"}' http://localhost:8080
204238
{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}%
205239
206240
# get a list of todos with the one that was just created
207-
$ curl http://localhost:8080
241+
$ curl http://localhost:8080/todo-jakarta-data
208242
[{"completed":false,"id":1,"order":0,"title":"This is my first todo item!","url":"https://localhost:8080/1"}]
209243
----
210244

211-
:extraStartParams: -DPOSTGRESQL_DATABASE=todos -DPOSTGRESQL_SERVICE_HOST=localhost -DPOSTGRESQL_SERVICE_PORT=5432 -DPOSTGRESQL_USER=todos -DPOSTGRESQL_PASSWORD=mysecretpassword -DPOSTGRESQL_DATASOURCE=ToDos
212-
include::../shared-doc/run-integration-tests-with-provisioned-server.adoc[leveloffset=+1]
245+
Please note that the quickstart includes integration tests, which may be executed using the following command:
246+
247+
[source,subs="attributes+",options="nowrap"]
248+
----
249+
$ mvn verify -Pintegration-testing
250+
----
213251

214252
//===========================================================
215253
// Openshift - START
@@ -239,7 +277,5 @@ endif::[]
239277
This quickstart shows how the datasource feature pack provided by {productName} simplifies the deployment
240278
of a {productName} Jakarta EE backend on OpenShift to connect to an external database and exposes an HTTP API.
241279
242-
ifndef::ProductRelease[]
243280
The use of a Server Provisioned deployment makes it seamless to move from a local deployment for development to a
244-
deployment on cloud platforms such as OpenShift and Kubernetes.
245-
endif::[]
281+
deployment on cloud platforms such as OpenShift and Kubernetes.

todo-jakarta-data/additional-readme-cloud.adoc

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,34 @@ For {additional-readme-cloud-platform}, we rely on secrets so that the credentia
2020
deploy:
2121
env:
2222
- name: POSTGRESQL_PASSWORD
23-
valueFrom:
24-
secretKeyRef:
25-
key: database-password
26-
name: todo-backend-db
23+
- name: POSTGRESQL_DATABASE
24+
valueFrom:
25+
configMapKeyRef:
26+
name: postgres-configmap
27+
key: POSTGRES_PASSWORD
2728
----
2829

29-
When the application is deployed, the value for the `POSTGRESQL_PASSWORD` will be taken from the key `database-password`
30-
in the secret `todo-backend-db`.
30+
When the application is deployed, the value for the `POSTGRESQL_PASSWORD` will be taken from the key `POSTGRES_PASSWORD`
31+
in the secret `postgres-configmap`.
3132

3233
ifdef::additional-readme-openshift[]
3334
== Use the todobackend Web Frontend
3435

35-
Once the backend is deployed on {additional-readme-cloud-platform}, it can be accessed from the route `todo-backend`.
36+
Once the backend is deployed on {additional-readme-cloud-platform}, it can be accessed from the route `todo-jakarta-data`.
3637
Let's find the host that we can use to connect to this backend:
3738

3839
[source,options="nowrap"]
3940
----
40-
$ oc get route todo-backend -o jsonpath="{.spec.host}"
41-
todo-backend-jmesnil1-dev.apps.sandbox.x8i5.p1.openshiftapps.com
41+
$ oc get route todo-jakarta-data -o jsonpath="{.spec.host}"
42+
todo-jakarta-data-jmesnil1-dev.apps.sandbox.x8i5.p1.openshiftapps.com
4243
----
4344

4445
This value will be different for every installation of the backend.
4546

46-
[WARNING]
47-
====
48-
Make sure to prepend the host with `https://` to be able to connect to the backend from the ToDo Backend Specs or Client.
49-
The host must also be publicly accessible.
50-
====
47+
To be able to connect to the backend from the ToDo Backend Specs or Client, then prepend the host with `https://`, and append the relative web context `/todo-jakarta-data`. For the previous example host this would be `https://todo-jakarta-data-jmesnil1-dev.apps.sandbox.x8i5.p1.openshiftapps.com/todo-jakarta-data`.
5148

5249
We can verify that this application is properly working as a ToDo Backend by running its https://todobackend.com/specs/index.html[specs] on it.
5350

54-
5551
Once all tests passed, we can use the https://todobackend.com/client/index.html[todobackend client] to have a Web application connected to the backend.
5652

5753
[NOTE]
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
apiVersion: v2
2-
name: todo-backend-chart
3-
description: A Helm chart to deploy a WildFly todo-backend application and its Postgresql database
2+
name: todo-jakarta-data-chart
3+
description: A Helm chart to deploy a WildFly todo-jakarta-data application and its Postgresql database
44
type: application
55
version: 1.0.0
6-
appVersion: 31.0.0.Final
76
dependencies:
8-
- name: postgresql
9-
repository: https://charts.bitnami.com/bitnami
10-
version: 13.1.5
117
- name: wildfly
128
repository: http://docs.wildfly.org/wildfly-charts/
13-
version: 2.3.2
9+
version: 2.3.2
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: postgres-configmap
5+
labels:
6+
app: postgres
7+
data:
8+
POSTGRES_DB: {{ .Values.db.database }}
9+
POSTGRES_USER: {{ .Values.db.username }}
10+
POSTGRES_PASSWORD: {{ .Values.db.password }}
11+
PGDATA: /var/lib/postgresql/data/pgdata
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: todo-jakarta-data-postgresql
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: todo-jakarta-data-postgresql
10+
template:
11+
metadata:
12+
labels:
13+
app: todo-jakarta-data-postgresql
14+
spec:
15+
containers:
16+
- name: postgres
17+
image: postgres:17
18+
ports:
19+
- containerPort: 5432
20+
name: postgres
21+
envFrom:
22+
- configMapRef:
23+
name: postgres-configmap
24+
volumeMounts:
25+
- name: pgdata
26+
mountPath: /var/lib/postgresql/data
27+
volumes:
28+
- name: pgdata
29+
emptyDir: {}
30+
---
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
name: todo-jakarta-data-postgresql
35+
spec:
36+
ports:
37+
- port: 5432
38+
targetPort: postgres
39+
selector:
40+
app: todo-jakarta-data-postgresql

todo-jakarta-data/charts/values.yaml

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22
# This is a YAML-formatted file.
33
# Declare variables to be passed into your templates.
44

5-
postgresql:
6-
auth:
7-
username: todos-db
8-
password: todos-db
9-
database: todos-db
10-
architecture: "standalone"
11-
primary:
12-
podSecurityContext:
13-
enabled: false
14-
fsGroup: "auto"
15-
containerSecurityContext:
16-
enabled: false
17-
runAsUser: "auto"
18-
runAsGroup: ""
19-
5+
db:
6+
username: todos-db
7+
password: todos-db
8+
database: todos-db
209

2110
wildfly:
2211
build:
@@ -28,15 +17,24 @@ wildfly:
2817
env:
2918
# Env vars to connect to PostgreSQL DB
3019
- name: POSTGRESQL_DATABASE
31-
value: todos-db
20+
valueFrom:
21+
configMapKeyRef:
22+
name: postgres-configmap
23+
key: POSTGRES_DB
3224
- name: POSTGRESQL_USER
33-
value: todos-db
25+
valueFrom:
26+
configMapKeyRef:
27+
name: postgres-configmap
28+
key: POSTGRES_USER
3429
- name: POSTGRESQL_PASSWORD
35-
value: todos-db
30+
valueFrom:
31+
configMapKeyRef:
32+
name: postgres-configmap
33+
key: POSTGRES_PASSWORD
3634
- name: POSTGRESQL_DATASOURCE
37-
value: ToDoRepository
35+
value: ToDos
3836
- name: POSTGRESQL_SERVICE_HOST
39-
value: todo-backend-postgresql
37+
value: todo-jakarta-data-postgresql
4038
- name: POSTGRESQL_SERVICE_PORT
4139
value: "5432"
4240
# Env to avoid OOME
@@ -46,8 +44,7 @@ wildfly:
4644
value: "96"
4745
initContainers:
4846
- name: check-db-ready
49-
image: postgres:9.6.5
50-
command: [ 'sh', '-c',
51-
'until pg_isready -h todo-backend-postgresql -p 5432;
52-
do echo waiting for database; sleep 2; done;' ]
53-
47+
image: busybox:1.36
48+
command: ['sh', '-c',
49+
'until nc -z -v -w 2 todo-backend-postgresql 5432;
50+
do echo "waiting for database"; sleep 2; done;']

0 commit comments

Comments
 (0)