-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KOGITO-7766 - Add Data Index Addon example using PostgreSQL persisten…
…ce (#1532) * KOGITO-7766 - Add Data Index Addon example using PostgreSQL persistence * Apply suggestions from code review Co-authored-by: nmirasch <[email protected]> * Review container image build command * Disable knative devservice * Apply suggestions from code review Co-authored-by: Tristan Radisson <[email protected]> Co-authored-by: nmirasch <[email protected]> Co-authored-by: Tristan Radisson <[email protected]>
- Loading branch information
1 parent
9a13d5a
commit 616721a
Showing
11 changed files
with
694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
serverless-workflow-examples/serverless-workflow-data-index-quarkus/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Kogito Serverless Workflow - Data Index Example | ||
|
||
## Description | ||
|
||
This example contains a simple workflow service that demonstrates how to use Data Index Addon as part of the Kogito runtime. | ||
A callback is a state that invokes an action and waits for an event (an event that will be eventually fired by the external service notified by the action), so this example needs an event broker. | ||
This example consists of a callback state that waits for an event arriving on the `wait` channel. Its action is to publish an event on the `resume` channel. The event published on the `resume` channel is modified and republished into the `wait` channel by `PrintService`, which simulates an external service. | ||
The service is described using JSON format as defined in the | ||
[CNCF Serverless Workflow specification](https://github.com/serverlessworkflow/specification). | ||
|
||
## Infrastructure requirements | ||
|
||
### Kafka | ||
|
||
This quickstart requires an Apache Kafka to be available and by default expects it to be on default port and localhost. | ||
|
||
* Install and Startup Kafka Server / Zookeeper | ||
|
||
https://kafka.apache.org/quickstart | ||
|
||
To publish and consume the event, the topic `move` is used. | ||
|
||
Optionally and for convenience, a docker-compose [configuration file](docker-compose/docker-compose.yml) is | ||
provided in the path [docker-compose/](docker-compose/), where you can just run the command from there: | ||
|
||
```sh | ||
docker-compose up | ||
``` | ||
|
||
In this way a container for Kafka will be started on port 9092. | ||
|
||
### PostgreSQL | ||
|
||
This example also requires persistence with a PostgreSQL server. | ||
|
||
The configuration for setting up the connection can be found in [applications.properties](src/main/resources/application.properties) file, which | ||
follows the Quarkus JDBC settings, for more information please check [JDBC Configuration Reference](https://quarkus.io/guides/datasource#jdbc-configuration). | ||
|
||
Optionally and for convenience, a docker-compose [configuration file](docker-compose/docker-compose.yml) is | ||
provided in the path [docker-compose/](docker-compose/), where you can just run the command from there: | ||
|
||
```sh | ||
docker-compose up | ||
``` | ||
|
||
In this way a container for PostgreSQL will be started on port 5432. | ||
|
||
## Installing and Running | ||
|
||
### Prerequisites | ||
|
||
You will need: | ||
- Java 11+ installed | ||
- Environment variable JAVA_HOME set accordingly | ||
- Maven 3.8.1+ installed | ||
- Docker and Docker Compose to run the required example infrastructure. | ||
|
||
When using native image compilation, you will also need: | ||
- GraalVM 22.2+ installed | ||
- Environment variable GRAALVM_HOME set accordingly | ||
- GraalVM native image needs as well native-image extension: https://www.graalvm.org/reference-manual/native-image/ | ||
- Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too, please refer to GraalVM installation documentation for more details. | ||
|
||
NOTE: Quarkus provides a way of creating a native Linux executable without GraalVM installed, leveraging a container runtime such as Docker or Podman. More details in https://quarkus.io/guides/building-native-image#container-runtime | ||
|
||
### Compile and Run in Local Dev Mode | ||
|
||
```sh | ||
mvn clean package quarkus:dev | ||
``` | ||
|
||
### Start infrastructure services | ||
|
||
You should start all the services before you execute any of the **Data Index** example. To do that please execute: | ||
|
||
```sh | ||
mvn clean package -Dcontainer | ||
``` | ||
|
||
For Linux and MacOS: | ||
|
||
1. Open a Terminal | ||
2. Go to docker-compose folder | ||
3. Run ```docker-compose up``` | ||
|
||
```bash | ||
cd docker-compose && docker-compose up | ||
``` | ||
|
||
TIP: If you get a `permission denied` error while creating the postgresql container, consider using SELinux context. | ||
Update the following line: | ||
```yaml | ||
- ./sql:/docker-entrypoint-initdb.d | ||
``` | ||
to | ||
```yaml | ||
- ./sql:/docker-entrypoint-initdb.d:Z | ||
``` | ||
Once all services bootstrap, the following ports will be assigned on your local machine: | ||
- PostgreSQL: 5432 | ||
- Kafka: 9092 | ||
- PgAdmin: 8055 | ||
- serverless-workflow-service: 8080 | ||
> **_NOTE:_** This step requires the project to be compiled, please consider running a ```mvn clean package -Dcontainer``` command on the project root before running the ```docker-compose up``` for the first time or any time you modify the project. | ||
|
||
Once started you can simply stop all services by executing the ```docker-compose -f docker-compose.yml stop```. | ||
|
||
All created containers can be removed by executing the ```docker-compose -f docker-compose.yml rm```. | ||
|
||
|
||
### Compile and Run using Local Native Image | ||
Note that this requires GRAALVM_HOME to point to a valid GraalVM installation | ||
|
||
```sh | ||
mvn clean package -Dnative | ||
``` | ||
|
||
To run the generated native executable, generated in `target/`, execute | ||
|
||
```sh | ||
./target/serverless-workflow-callback-quarkus-{version}-runner | ||
``` | ||
|
||
### Submit a request | ||
|
||
The service based on the JSON workflow definition can be access by sending a request to http://localhost:8080/callback | ||
|
||
Complete curl command can be found below: | ||
|
||
```sh | ||
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/callback | ||
``` | ||
|
||
|
||
After a while (note that to you need give time for event to be consumed) you should see the log message printed in quarkus: | ||
|
||
```text | ||
Workflow data {"move":"This is the initial data in the model and has been modified by the event publisher"} | ||
``` | ||
|
||
### Query process details in Data Index | ||
|
||
Data Index GraphQL UI is available at http://localhost:8080/q/graphql-ui/ |
81 changes: 81 additions & 0 deletions
81
...orkflow-examples/serverless-workflow-data-index-quarkus/docker-compose/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
version: '2.1' | ||
|
||
services: | ||
postgres: | ||
container_name: postgres | ||
image: postgres:13.4-alpine3.14 | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./sql:/docker-entrypoint-initdb.d:Z | ||
healthcheck: | ||
test: [ "CMD", "pg_isready", "-q", "-d", "kogito", "-U", "kogito-user" ] | ||
timeout: 45s | ||
interval: 10s | ||
retries: 50 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
|
||
pgadmin-compose: | ||
image: dpage/pgadmin4:5.0 | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: [email protected] | ||
PGADMIN_DEFAULT_PASSWORD: pass | ||
ports: | ||
- 8055:80 | ||
depends_on: | ||
- postgres | ||
container_name: pgadmin-container | ||
|
||
zookeeper: | ||
container_name: zookeeper | ||
image: strimzi/kafka:0.20.1-kafka-2.6.0 | ||
command: [ | ||
"sh", "-c", | ||
"bin/zookeeper-server-start.sh config/zookeeper.properties" | ||
] | ||
ports: | ||
- "2181:2181" | ||
environment: | ||
LOG_DIR: "/tmp/logs" | ||
|
||
kafka: | ||
image: strimzi/kafka:0.20.1-kafka-2.6.0 | ||
container_name: kafka | ||
command: [ | ||
"sh", "-c", | ||
"bin/kafka-server-start.sh config/server.properties --override inter.broker.listener.name=$${KAFKA_INTER_BROKER_LISTENER_NAME} --override listener.security.protocol.map=$${KAFKA_LISTENER_SECURITY_PROTOCOL_MAP} --override listeners=$${KAFKA_LISTENERS} --override advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override zookeeper.connect=$${KAFKA_ZOOKEEPER_CONNECT}" | ||
] | ||
depends_on: | ||
- zookeeper | ||
ports: | ||
- "9092:9092" | ||
environment: | ||
KAFKA_BROKER_ID: 0 | ||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
KAFKA_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://kafka:9092 | ||
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:29092,EXTERNAL://localhost:9092 | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT | ||
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL | ||
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true" | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
LOG_DIR: "/tmp/logs" | ||
|
||
serverless-workflow-service: | ||
container_name: serverless-workflow-service | ||
image: dev.local/${USER}/serverless-workflow-data-index-quarkus:1.0-SNAPSHOT | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
kafka: | ||
condition: service_started | ||
postgres: | ||
condition: service_healthy | ||
environment: | ||
QUARKUS_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgres:5432/kogito" | ||
QUARKUS_DATASOURCE_USERNAME: kogito-user | ||
QUARKUS_DATASOURCE_PASSWORD: kogito-pass | ||
QUARKUS_DATASOURCE_DB_KIND: postgresql | ||
KAFKA_BOOTSTRAP_SERVERS: kafka:29092 | ||
KOGITO_SERVICE_URL: http://localhost:8080 |
20 changes: 20 additions & 0 deletions
20
...less-workflow-examples/serverless-workflow-data-index-quarkus/docker-compose/sql/init.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE ROLE "kogito-user" WITH | ||
LOGIN | ||
SUPERUSER | ||
INHERIT | ||
CREATEDB | ||
CREATEROLE | ||
NOREPLICATION | ||
PASSWORD 'kogito-pass'; | ||
|
||
CREATE DATABASE kogito | ||
WITH | ||
OWNER = "kogito-user" | ||
ENCODING = 'UTF8' | ||
LC_COLLATE = 'en_US.utf8' | ||
LC_CTYPE = 'en_US.utf8' | ||
TABLESPACE = pg_default | ||
CONNECTION LIMIT = -1; | ||
|
||
GRANT ALL PRIVILEGES ON DATABASE kogito TO "kogito-user"; | ||
GRANT ALL PRIVILEGES ON DATABASE kogito TO postgres; |
Oops, something went wrong.