diff --git a/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java b/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java index fc0a4a1f76..8642a55948 100644 --- a/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java +++ b/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java @@ -26,7 +26,7 @@ import org.kie.kogito.testcontainers.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; @@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT { private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId(); @Container - public static DockerComposeContainer environment; + public static ComposeContainer environment; static { try { - environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) - .withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("prometheus_1", PROMETHEUS_PORT, + environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) + .withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("prometheus-1", PROMETHEUS_PORT, Wait.forHttp("/api/v1/targets") .forResponsePredicate(x -> x.contains("\"health\":\"up\"")) .withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER)) + .withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER)) .withPull(false) - .withLocalCompose(true) - //See https://github.com/testcontainers/testcontainers-java/issues/4565 - .withOptions("--compatibility"); + .withLocalCompose(true); } catch (URISyntaxException e) { throw new RuntimeException(e); } diff --git a/kogito-quarkus-examples/flexible-process-quarkus/src/main/resources/service-desk.bpmn b/kogito-quarkus-examples/flexible-process-quarkus/src/main/resources/service-desk.bpmn index 7065f168ef..264cf721c3 100644 --- a/kogito-quarkus-examples/flexible-process-quarkus/src/main/resources/service-desk.bpmn +++ b/kogito-quarkus-examples/flexible-process-quarkus/src/main/resources/service-desk.bpmn @@ -1,4 +1,5 @@ - + + @@ -499,11 +500,13 @@ + _AD768963-CBF7-4269-9D43-51FE0D5D2556_TaskNameInputX _AD768963-CBF7-4269-9D43-51FE0D5D2556_SkippableInputX + _AD768963-CBF7-4269-9D43-51FE0D5D2556_GroupIdInputX _AD768963-CBF7-4269-9D43-51FE0D5D2556_evaluationOutputX @@ -524,6 +527,13 @@ + + _AD768963-CBF7-4269-9D43-51FE0D5D2556_GroupIdInputX + + + + + _AD768963-CBF7-4269-9D43-51FE0D5D2556_evaluationOutputX evaluation diff --git a/kogito-quarkus-examples/flexible-process-quarkus/src/test/java/org/kie/kogito/flexible/example/quarkus/ServiceDeskProcessTest.java b/kogito-quarkus-examples/flexible-process-quarkus/src/test/java/org/kie/kogito/flexible/example/quarkus/ServiceDeskProcessTest.java index 768afb787c..a5f39fc5cf 100644 --- a/kogito-quarkus-examples/flexible-process-quarkus/src/test/java/org/kie/kogito/flexible/example/quarkus/ServiceDeskProcessTest.java +++ b/kogito-quarkus-examples/flexible-process-quarkus/src/test/java/org/kie/kogito/flexible/example/quarkus/ServiceDeskProcessTest.java @@ -94,6 +94,7 @@ private void addSupportComment(String id) { String location = given() .basePath(BASE_PATH) .contentType(ContentType.JSON) + .queryParam("group", "support") .when() .post("/{id}/ReceiveSupportComment", id) .then() @@ -125,9 +126,11 @@ private void addSupportComment(String id) { private void addCustomerComment(String id) { String location = given() - .basePath(BASE_PATH + "/" + id).contentType(ContentType.JSON) + .basePath(BASE_PATH) + .contentType(ContentType.JSON) + .queryParam("group", "customer") .when() - .post("/ReceiveCustomerComment") + .post("/{id}/ReceiveCustomerComment", id) .then() .statusCode(201) .header("Location", notNullValue()) @@ -156,16 +159,23 @@ private void addCustomerComment(String id) { } private void resolveCase(String id) { - given().basePath(BASE_PATH + "/" + id).contentType(ContentType.JSON).when().post("/Resolve_Case").then() - .statusCode(200).body("supportCase.state", is(State.RESOLVED.name())); + given() + .basePath(BASE_PATH) + .contentType(ContentType.JSON) + .when() + .post("/{id}/Resolve_Case", id) + .then() + .statusCode(200) + .body("supportCase.state", is(State.RESOLVED.name())); } private void sendQuestionnaire(String id) { String taskId = given() - .basePath(BASE_PATH + "/" + id) + .basePath(BASE_PATH) .contentType(ContentType.JSON) + .queryParam("group", "customer") .when() - .get("/tasks") + .get("/{id}/tasks", id) .then() .statusCode(200) .body("size()", is(1)) @@ -177,13 +187,13 @@ private void sendQuestionnaire(String id) { params.put("evaluation", 10); given() - .basePath(BASE_PATH + "/" + id) + .basePath(BASE_PATH) .queryParam("user", "Paco") .queryParam("group", "customer") .contentType(ContentType.JSON) .when() .body(params) - .post("/Questionnaire/" + taskId) + .post("/{id}/Questionnaire/{taskId}/", id, taskId) .then() .statusCode(200) .body("supportCase.state", is(State.CLOSED.name())) diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/README.md b/kogito-quarkus-examples/process-instance-migration-quarkus/README.md new file mode 100644 index 0000000000..9f12a1b6a1 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/README.md @@ -0,0 +1,286 @@ +# Process Instance Migration (PIM) example + +## Description + +This example showcases the Process Instance Migration (PIM) functionality. This feature can be used to migrate +active process instances from one process definition (v1) to another (v2). + +This example is using the *Compact Architecture* that is based on simplified communication among the different +*Kogito* services without the need of events (Kafka/HTTP) between them. Note that this design choice is unrelated +to the Process Instance Migration functionality. + +## The test processes + +### The original BPMN Process + +
+
+ Simple Process Diagram +
Simple Process Diagram
+
+
+ +The process follows a very basic design with two script tasks and a catching signal event in between to act as a wait state. + +
+
+ Modified Process Diagram +
Modified Process Diagram
+
+
+ +The modified version of this simple process has own additional script task **after** the wait state. + + +## Running the example +### Prerequisites + +* Java 17+ installed +* Environment variable JAVA_HOME set accordingly +* Maven 3.9.3+ installed +* Docker and Docker Compose to run the required example infrastructure. + +And when using native image compilation, you will also need: +- GraalVM 20.3+ 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. + +### Infrastructure Services + +This quickstart provides a docker compose template that starts all the required services. This setup ensures that all services are connected with a default configuration. + +- PostgreSQL: 5432 +- PgAdmin: 8055 +- Kogito Process Instance Migration Service: 8080 + +To help bootstraping the Infrastructure Services, the example provides the `startServices.sh` script inside the *docker-compose* +folder. + +> **_NOTE_**: the docker compose template requires using _extra_hosts_ to allow the services use the host network, this may +> carry some issues if you are using a **podman** version older than **4.7**. + +### Building & Running the example + +To build the example, on a Terminal, run the following command: +```shell +mvn clean package -Pcontainer +``` +This will build the example quarkus application and create a Docker image that will be started in the `docker-compose` template. + +To execute the full example (including consoles), open a Terminal and run the following command inside the `docker-compose` folder: + +```shell +sh startServices.sh +``` + +Additionally, if you want to start only the example and the minimal Infrastructure Services (PostgreSQL, Data-Index and Jobs Service), +you can run the same `startServices.sh` script but passing the `example` argument + +```shell +sh startServices.sh example +``` + +> **_NOTE:_** starting the Infrastructure Services, please consider running a ```mvn clean package -Pcontainer``` +> command on the project root before running the ```startServices.sh``` script for the first time or any time you modify the project. + +### Running the example in Development mode + +To run the example in Development mode, just run the following command in a Terminal: + +```shell +mvn clean package quarkus:dev -Pdevelopment +``` + +The Development Mode will embed all the needed Infrastructure Services (PostgreSQL, Data-Index & Jobs Service) and won't +require any extra step. + +The `development` profile includes the **Runtime Tools Quarkus Extension** that exposes a new section in the **Quarkus Dev-UI** +unifying the **Management Console** & **Task Console** functionalities. **Quarkus Dev-UI** is available at http://localhost:8080/q/dev + +> **_NOTE:_** For more information about how to work with Kogito Runtime Tools Quarkus Extension, please refer to the [Kogito Documentation](https://docs.kogito.kie.org/latest/html_single/#con-runtime-tools-dev-ui_kogito-developing-process-services) page. + +### Executing an instance of the Simple Process + +Once the service is up and running you can start an instance of the **Simple** process by a sending request to `http://localhost:8080/simple`. + + +In a Terminal you can execute this curl command to start a **Simple** process: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/simple -d '{}' +``` + +If everything went well you may get a response like: +```json +{ + "id": "b97efe7d-dc9b-4da8-8b3e-6100f8d8b045" +} +``` + +In the console of the example container you should see the following log message: +``` +Started process e4bf4948-1f56-4ee3-9f2c-5010aaf50701 [simple, v1.0] +``` + +To finish this process instance, execute the following command, using the process instance id previously returned, to send a signal: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/simple/e4bf4948-1f56-4ee3-9f2c-5010aaf50701/continue -d '{}' +``` + +In the console of the example container you should see the following log message: +``` +Ending process e4bf4948-1f56-4ee3-9f2c-5010aaf50701 [simple, v1.0] +``` + +### Using PIM to migrate a process instance from the Simple Process to the Modified Process + +In a Terminal, start another instance of the **Simple** process: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/simple -d '{}' +``` + +Note the new process instance id that is returned by the engine: +```json +{ + "id": "2a507f63-9db1-4d15-b64c-9e14f922d470" +} +``` + +Using the Management API, the following two endpoints can be used to migrate active process instances: +* `/management/processes/{processId}/migrate`: Use this endpoint to migrate **all** active process instances of a given `processId` to a new target process definition +* `/management/processes/{processId}/instances/{processInstanceId}/migrate`: Use this endpoint to migrate a specific process instance of a given `processId` to a new target process definition + +In a Terminal, invoke the Management API to migrate the newly created process instance: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/management/processes/simple/migrate -d '{ + "targetProcessId": "modified", + "targetProcessVersion": "1.0" +}' +``` + +The response will contain information about the migration: +```json +{ + "message":"All intances migrated", + "numberOfProcessInstanceMigrated":1 +} +``` + +Alternatively, use the following endpoint to migrate just a single process instance: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/management/processes/simple/instances/2a507f63-9db1-4d15-b64c-9e14f922d470/migrate -d '{ + "targetProcessId": "modified", + "targetProcessVersion": "1.0" +}' +``` + + +Note that the invocation of the `migrate` endpoint is the first step of the PIM functionality. It flags the selected process instance(s) as migrated to the defined target process definition. The second step of the migration will happen the next time the process instance is unmarshalled. This would be the case when the process instance is triggered to continue its execution. If you want to test whether this unmarshalling step is successful after the migration, the following PUT call can be used without triggering the execution of the process instance: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X PUT http://localhost:8080/modified/2a507f63-9db1-4d15-b64c-9e14f922d470 -d '{}' +``` + +If successful, this call will just return the processInstanceId of the process instance. + + +To finish this process instance, execute the following command, using the process instance id previously returned, to send a signal against the endpoint of the **Modified** process: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/modified/2a507f63-9db1-4d15-b64c-9e14f922d470/continue -d '{}' +``` + +In the console of the example container you should see the following log messages: +``` +Executing added node +Ending process 2a507f63-9db1-4d15-b64c-9e14f922d470 [modified, v1.0] +``` + +### Using PIM to migrate a process instance from the Simple Process to the Addedtask Process with a migration plan + +In the first migration example, the **Modified** process contained an added node after the current wait state. The wait state itself was unchanged in both process definitions, using the same internal node id. Therefore, no additional information had to be provided for the migration to be successful. + +Consider another modification of the original **Simple** process, this time adding a Human Task node **before** the Catching Signal Event: + +
+
+ Addedtask Process Diagram +
Addedtask Process Diagram
+
+
+ +With this change, the BPMN representation has changed in a way that the Catching Signal Event now has a different nodeId: + +**[src/main/resources/simple.bpmn](src/main/resources/simple.bpmn)** +```xml + +``` + +**[src/main/resources/addedtask.bpmn](src/main/resources/addedtask.bpmn)** +```xml + +``` + +In order to migrate process instances between process definitions with such changes, we need to provide a Migration Plan File (extension *.mpf). This file defines the migration plan with all required node mappings: + +**[src/main/resources/META-INF/migration-plan/addedtask_migration.mpf](src/main/resources/META-INF/migration-plan/addedtask_migration.mpf)** +```json +{ + "name" : "simple to addedtask migration", + "processMigrationPlan" : { + "sourceProcessDefinition" : { + "processId" : "simple", + "processVersion" : "1.0" + }, + "targetProcessDefinition" : { + "processId" : "addedtask", + "processVersion" : "1.0" + }, + "nodeInstanceMigrationPlan" : [ + { + "sourceNodeId" : "_8430CA7E-8CC6-4C2C-9664-6B5BBD5E36CB", + "targetNodeId" : "_1D65864A-96AF-44FC-92CE-2073B9FBA7D0" + } + ] + } +} +``` + +Now that we have this migration plan deployed with our new process, we can test the Process Instance Migration with the same steps as before. + +In a Terminal, start another instance of the **Simple** process: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/simple -d '{}' +``` + +Note the new process instance id that is returned by the engine: +```json +{ + "id": "29ec3980-9f0f-4b92-8a2d-394ffdb477e3" +} +``` + +In a Terminal, invoke the Management API to migrate the newly created process instance: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/management/processes/simple/migrate -d '{ + "targetProcessId": "addedtask", + "targetProcessVersion": "1.0" +}' +``` + +The response will contain information about the migration: +```json +{ + "message":"All intances migrated", + "numberOfProcessInstanceMigrated":1 +} +``` + +To finish this process instance, execute the following command, using the process instance id previously returned, to send a signal against the endpoint of the **Addedtask** process: +```bash +curl -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://localhost:8080/addedtask/29ec3980-9f0f-4b92-8a2d-394ffdb477e3/continue -d '{}' +``` + +In the console of the example container you should see the following log messages: +``` +Ending process 29ec3980-9f0f-4b92-8a2d-394ffdb477e3 [addedtask, v1.0] +``` + diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/.gitignore b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/.gitignore new file mode 100644 index 0000000000..b6632dbda5 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/.gitignore @@ -0,0 +1,3 @@ +.env +svg/ +persistence/ \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/README.md b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/README.md new file mode 100644 index 0000000000..de3b959186 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/README.md @@ -0,0 +1,47 @@ +# Kogito and Infrastructure services + +To allow a quick setup of all services required to run this demo, we provide a docker compose template that starts the following services: +- Postgresql +- PgAdmin +- Kogito Process Instance Migration Service (Only available if the example has been compiled using the `container` mvn profile eg: ```mvn clean package -Pcontainer```) + +The docker compose template provides three profiles to enable starting only the set of services you want to use. The profiles are: +- **infra**: Starts only the minimal infrastructure to run the example (Postgresql, pgadmin) +- **example**: Starts the services in *infra* profile and the Kogito Example Service. Requires the example to be compiled using the `container` mvn profile eg: ```mvn clean package -Pcontainer```. + +> NOTE: In order to use it, please ensure you have Docker Compose installed on your machine, otherwise follow the instructions available +in [here](https://docs.docker.com/compose/install/). + +## Starting the services + +Use the `startServices.sh` passing the docker profile you want to use as an argument. If no profile is provided the script will default to **full**. + +Eg: +```shell +sh startServices.sh example +``` + +Once the services are started (depending on the profile), the following ports will be assigned on your local machine: +- Postgresql: 5432 +- PgAdmin: 8055 +- Kogito Process Instance Migration Service: 8080 + +## Stopping and removing volume data + +To stop all services, simply run: + +```shell +docker compose stop +``` +or + +```shell +docker compose down +``` +to stop the services and remove the containers. + +For more details please check the Docker Compose documentation. + +```shell +docker-compose --help +``` diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/docker-compose.yml b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/docker-compose.yml new file mode 100644 index 0000000000..a4addff8c7 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/docker-compose.yml @@ -0,0 +1,64 @@ +version: '3' + +services: + postgres: + container_name: postgres + image: postgres:16.1-alpine3.19 + profiles: [ "infra", "example", "full" ] + 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: + container_name: pgadmin + image: dpage/pgadmin4:8.2 + profiles: [ "infra", "example", "full" ] + ports: + - 8055:80 + depends_on: + - postgres + volumes: + - ./pgadmin/servers.json:/pgadmin4/servers.json + - ./pgadmin/pgpass:/pgadmin4/pgpass + entrypoint: > + /bin/sh -c " + cp -f /pgadmin4/pgpass /var/lib/pgadmin/; + chmod 600 /var/lib/pgadmin/pgpass; + /entrypoint.sh + " + environment: + PGADMIN_DEFAULT_EMAIL: user@kogito.org + PGADMIN_DEFAULT_PASSWORD: pass + PGADMIN_CONFIG_SERVER_MODE: 'False' + PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False' + GUNICORN_ACCESS_LOGFILE: '/dev/null' + + kogito-process-instance-migration-service: + container_name: kogito-process-instance-migration-service + image: dev.local/${USER}/kogito-process-instance-migration-service:1.0-SNAPSHOT + profiles: ["example", "full"] + ports: + - "8080:8080" + depends_on: + - postgres + environment: + QUARKUS_HTTP_CORS_ORIGINS: "/.*/" + QUARKUS_DATASOURCE_JDBC_URL: "jdbc:postgresql://postgres:5432/kogito" + QUARKUS_DATASOURCE_REACTIVE_URL: "postgresql://postgres:5432/kogito" + QUARKUS_DATASOURCE_USERNAME: kogito-user + QUARKUS_DATASOURCE_PASSWORD: kogito-pass + QUARKUS_DATASOURCE_DB_KIND: postgresql + KOGITO_JOBS_SERVICE_URL: http://${DOCKER_GATEWAY_HOST}:8080 + KOGITO_SERVICE_URL: http://${DOCKER_GATEWAY_HOST}:8080 + KOGITO_DATAINDEX_HTTP_URL: http://${DOCKER_GATEWAY_HOST}:8080 + extra_hosts: + - "${DOCKER_GATEWAY_HOST}:host-gateway" diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/pgpass b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/pgpass new file mode 100644 index 0000000000..11a6f7c601 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/pgpass @@ -0,0 +1,3 @@ +postgres:5432:kogito:kogito-user:kogito-pass +postgres:5432:keycloak:kogito-user:kogito-pass +postgres:5432:postgres:kogito-user:kogito-pass \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/servers.json b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/servers.json new file mode 100644 index 0000000000..a112980d55 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/pgadmin/servers.json @@ -0,0 +1,14 @@ +{ + "Servers": { + "1": { + "Name": "kogito", + "Group": "Servers", + "Host": "postgres", + "Port": 5432, + "MaintenanceDB": "kogito", + "Username": "kogito-user", + "SSLMode": "disable", + "PassFile": "/var/lib/pgadmin/pgpass" + } + } +} \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/sql/init.sql b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/sql/init.sql new file mode 100644 index 0000000000..3097ad7d8c --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/sql/init.sql @@ -0,0 +1,22 @@ +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 postgres TO "kogito-user"; +GRANT ALL PRIVILEGES ON DATABASE kogito TO "kogito-user"; +GRANT ALL PRIVILEGES ON DATABASE kogito TO postgres; diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/startServices.sh b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/startServices.sh new file mode 100755 index 0000000000..8b0c6f4348 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/docker-compose/startServices.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +PROFILE="example" + +echo "Script requires your Kogito Example to be compiled" + +PROJECT_VERSION=$(cd ../ && mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + +echo "Project version: ${PROJECT_VERSION}" + +if [[ $PROJECT_VERSION == *SNAPSHOT ]]; +then + KOGITO_VERSION="latest" +else + KOGITO_VERSION=${PROJECT_VERSION%.*} +fi + +if [ -n "$1" ]; then + if [[ ("$1" == "infra") || ("$1" == "example")]]; + then + PROFILE="$1" + else + echo "Unknown docker profile '$1'. The supported profiles are:" + echo "* 'infra': Use this profile to start only the minimum infrastructure to run the example (postgresql, data-index & jobs-service)." + echo "* 'example': Use this profile to start the example infrastructure and the kogito-example service. Requires the example to be compiled using the 'container' profile (-Pcontainer)" + exit 1; + fi +fi + +echo "Kogito Image version: ${KOGITO_VERSION}" +echo "KOGITO_VERSION=${KOGITO_VERSION}" > ".env" +echo "COMPOSE_PROFILES='${PROFILE}'" >> ".env" + +if [ "$(uname)" == "Darwin" ]; then + echo "DOCKER_GATEWAY_HOST=kubernetes.docker.internal" >> ".env" +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + echo "DOCKER_GATEWAY_HOST=172.17.0.1" >> ".env" +fi + +docker compose up \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/addedtask.png b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/addedtask.png new file mode 100644 index 0000000000..5745ce1575 Binary files /dev/null and b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/addedtask.png differ diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/modified.png b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/modified.png new file mode 100644 index 0000000000..e6c32497a2 Binary files /dev/null and b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/modified.png differ diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/simple.png b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/simple.png new file mode 100644 index 0000000000..99d556dfaa Binary files /dev/null and b/kogito-quarkus-examples/process-instance-migration-quarkus/docs/images/simple.png differ diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/pom.xml b/kogito-quarkus-examples/process-instance-migration-quarkus/pom.xml new file mode 100644 index 0000000000..6fc1e97550 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/pom.xml @@ -0,0 +1,220 @@ + + + + 4.0.0 + + org.kie.kogito.examples + kogito-quarkus-examples + 999-SNAPSHOT + + process-instance-migration-quarkus + Kogito Example :: Process Instance Migration Quarkus + Process Instance Migration example - Quarkus + + 3.8.4 + quarkus-bom + io.quarkus + 3.8.4 + org.kie.kogito + kogito-bom + kogito-apps-bom + 999-SNAPSHOT + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + ${kogito.bom.group-id} + ${kogito.bom.artifact-id} + ${version.org.kie.kogito} + pom + import + + + ${kogito.bom.group-id} + ${kogito-apps.bom.artifact-id} + ${version.org.kie.kogito} + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-smallrye-health + + + + org.jbpm + jbpm-with-drools-quarkus + + + + org.jbpm + jbpm-quarkus + + + + org.kie + kie-addons-quarkus-process-management + + + org.kie + kogito-addons-quarkus-jobs-management + + + org.kie + kie-addons-quarkus-process-svg + + + org.kie + kie-addons-quarkus-source-files + + + + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-agroal + + + org.kie + kie-addons-quarkus-persistence-jdbc + + + + + org.kie + kogito-addons-quarkus-data-index-postgresql + + + + + org.kie + kogito-addons-quarkus-data-index-persistence-postgresql + + + + + org.kie + kogito-addons-quarkus-jobs + + + org.kie.kogito + jobs-service-postgresql-common + + + + + org.kie + kogito-addons-quarkus-data-audit-jpa + + + org.kie + kogito-addons-quarkus-data-audit + + + + + container + + container + + + + io.quarkus + quarkus-container-image-jib + + + + + development + + dev + + + + + ${project.artifactId} + + + maven-compiler-plugin + ${version.compiler.plugin} + + ${maven.compiler.release} + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + maven-failsafe-plugin + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + integration-test + verify + + + + + + + diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/META-INF/migration-plan/addedtask_migration.mpf b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/META-INF/migration-plan/addedtask_migration.mpf new file mode 100644 index 0000000000..bffd88c47a --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/META-INF/migration-plan/addedtask_migration.mpf @@ -0,0 +1,19 @@ +{ + "name" : "simple to addedtask migration", + "processMigrationPlan" : { + "sourceProcessDefinition" : { + "processId" : "simple", + "processVersion" : "1.0" + }, + "targetProcessDefinition" : { + "processId" : "addedtask", + "processVersion" : "1.0" + }, + "nodeInstanceMigrationPlan" : [ + { + "sourceNodeId" : "_8430CA7E-8CC6-4C2C-9664-6B5BBD5E36CB", + "targetNodeId" : "_1D65864A-96AF-44FC-92CE-2073B9FBA7D0" + } + ] + } +} diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/addedtask.bpmn b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/addedtask.bpmn new file mode 100644 index 0000000000..67688a3787 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/addedtask.bpmn @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _D0E6CA53-1ECE-4F8D-AAF0-829B30A2719F + _2DFFEEA8-CA22-4076-A703-DB36A6471775 + + + + + + + + + _916690AE-8B09-4FA5-BF0D-8638E01A7472 + _D0E6CA53-1ECE-4F8D-AAF0-829B30A2719F + + + + + _74EA6719-7F99-48CD-A98E-17D422668B87_TaskNameInputX + _74EA6719-7F99-48CD-A98E-17D422668B87_SkippableInputX + + + + _74EA6719-7F99-48CD-A98E-17D422668B87_TaskNameInputX + + + + + + + _74EA6719-7F99-48CD-A98E-17D422668B87_SkippableInputX + + + + + + + + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + + + + + + + + _2DFFEEA8-CA22-4076-A703-DB36A6471775 + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + System.out.println("Ending process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + + + + + + _C7A1A566-057F-4A80-B654-61270F82F365 + _916690AE-8B09-4FA5-BF0D-8638E01A7472 + System.out.println("Started process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + _C7A1A566-057F-4A80-B654-61270F82F365 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _4YtTwNp2EDyug9043TBvzA + _4YtTwNp2EDyug9043TBvzA + + \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/application.properties b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/application.properties new file mode 100644 index 0000000000..077d6091e0 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/application.properties @@ -0,0 +1,49 @@ +# Packaging +#quarkus.package.type=fast-jar + +#https://quarkus.io/guides/openapi-swaggerui +quarkus.http.cors=true +quarkus.smallrye-openapi.path=/docs/openapi.json +quarkus.swagger-ui.always-include=true +quarkus.kogito.data-index.graphql.ui.always-include=true +quarkus.http.test-port=0 + +# Kogito-service +kogito.service.url=http://localhost:8080 + +#Job-service +kogito.jobs-service.url=http://localhost:8080 + +# to be reachable from the container running job-service +kogito.dataindex.http.url=http://localhost:8080 +kogito.dataindex.ws.url=ws://localhost:8080 + +# run create tables scripts +quarkus.flyway.migrate-at-start=true +quarkus.flyway.baseline-on-migrate=true +quarkus.flyway.baseline-version=0.0 +quarkus.flyway.locations=classpath:/db/migration,classpath:/db/jobs-service,classpath:/db/data-audit/postgresql +quarkus.flyway.table=FLYWAY_RUNTIME_SERVICE + +kogito.persistence.type=jdbc +quarkus.datasource.db-kind=postgresql +%prod.quarkus.datasource.username=kogito-user +%prod.quarkus.datasource.password=kogito-pass +%prod.quarkus.datasource.jdbc.url=${QUARKUS_DATASOURCE_JDBC_URL:jdbc:postgresql://localhost:5432/kogito} +%prod.quarkus.datasource.reactive.url=${QUARKUS_DATASOURCE_REACTIVE_URL:postgresql://localhost:5432/kogito} + +quarkus.native.native-image-xmx=8g + +# profile to pack this example into a container, to use it execute activate the maven container profile, -Pcontainer +%container.quarkus.container-image.build=true +%container.quarkus.container-image.push=false +%container.quarkus.container-image.group=${USER} +%container.quarkus.container-image.registry=dev.local +%container.quarkus.container-image.tag=1.0-SNAPSHOT +%container.quarkus.container-image.name=kogito-process-instance-migration-service + +%dev.quarkus.kogito.devservices.enabled=true +%dev.kogito.users.jdoe.groups=admin,HR,IT + +# Disabling OIDC +quarkus.oidc.enabled=false \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/modified.bpmn b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/modified.bpmn new file mode 100644 index 0000000000..530941a900 --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/modified.bpmn @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _C9EA1F49-3940-4EBF-9493-7D36839FCD16 + _B7675247-EA61-4BFC-9103-1AFF3E8E25ED + System.out.println("Executing added node"); + + + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + + + + + + + + _B7675247-EA61-4BFC-9103-1AFF3E8E25ED + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + System.out.println("Ending process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + _D77BDF48-2A9F-4032-9BE5-AC111F59EE88 + _C9EA1F49-3940-4EBF-9493-7D36839FCD16 + + + + + + + + + _C7A1A566-057F-4A80-B654-61270F82F365 + _D77BDF48-2A9F-4032-9BE5-AC111F59EE88 + System.out.println("Started process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + _C7A1A566-057F-4A80-B654-61270F82F365 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _hNupoNpwEDyMua5P8aJUyQ + _hNupoNpwEDyMua5P8aJUyQ + + \ No newline at end of file diff --git a/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/simple.bpmn b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/simple.bpmn new file mode 100644 index 0000000000..685f2afb7b --- /dev/null +++ b/kogito-quarkus-examples/process-instance-migration-quarkus/src/main/resources/simple.bpmn @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + + + + + + + + _7B3EEFD3-98FD-4AF7-9038-E66015F565B9 + _FA3E1FF8-4894-47DA-90EB-DAB27BD7E925 + System.out.println("Ending process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + _D77BDF48-2A9F-4032-9BE5-AC111F59EE88 + _7B3EEFD3-98FD-4AF7-9038-E66015F565B9 + + + + + + + + + _C7A1A566-057F-4A80-B654-61270F82F365 + _D77BDF48-2A9F-4032-9BE5-AC111F59EE88 + System.out.println("Started process " + kcontext.getProcessInstance().getId() + " [" + kcontext.getProcessInstance().getProcessName() + ", v" + kcontext.getProcessInstance().getProcessVersion() + "]"); + + + _C7A1A566-057F-4A80-B654-61270F82F365 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _hNcVwNpwEDykP42egfgpsw + _hNcVwNpwEDykP42egfgpsw + + \ No newline at end of file diff --git a/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java b/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java index 5832a8f472..13355cfddb 100644 --- a/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java +++ b/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java @@ -18,20 +18,28 @@ */ package org.kie.kogito.quarkus.outbox; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.kogito.test.quarkus.kafka.KafkaTestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import com.jayway.jsonpath.JsonPath; @@ -42,7 +50,8 @@ import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertTrue; -//@Testcontainers +@Testcontainers +@Disabled public class OutboxIT { private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class); @@ -55,8 +64,8 @@ public class OutboxIT { private static final int KAFKA_PORT = 9092; private static final int DEBEZIUM_PORT = 8083; - //@Container - private static DockerComposeContainer COMPOSE; + @Container + private static ComposeContainer COMPOSE; private int kogitoPort; private int debeziumPort; @@ -64,34 +73,33 @@ public class OutboxIT { private KafkaTestClient kafkaClient; - static { - // Path path = Paths.get("../../docker-compose.yml"); - // if (!path.toFile().exists()) { - // path = Paths.get("docker-compose.yml"); - // } - // COMPOSE = new DockerComposeContainer(path.toFile()); - // COMPOSE.withPull(false); - // COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); - // COMPOSE.withExposedService("kogito", KOGITO_PORT); - // COMPOSE.withExposedService("kafka", KAFKA_PORT); - // COMPOSE.withExposedService("connect", DEBEZIUM_PORT); - // COMPOSE.withLogConsumer("kafka", logger()); - // COMPOSE.withLogConsumer("connect", logger()); - // COMPOSE.withLogConsumer("sidecar", logger()); - // COMPOSE.withLogConsumer("kogito", logger()); - // COMPOSE.waitingFor("kafka", Wait.forListeningPort()); - // COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); - // COMPOSE.waitingFor("kogito", Wait.forListeningPort()); - // COMPOSE.withLocalCompose(true); - // //See https://github.com/testcontainers/testcontainers-java/issues/4565 - // COMPOSE.withOptions("--compatibility"); + @BeforeAll + static void init() { + Path path = Paths.get("../../docker-compose.yml"); + if (!path.toFile().exists()) { + path = Paths.get("docker-compose.yml"); + } + COMPOSE = new ComposeContainer(path.toFile()); + COMPOSE.withPull(false); + COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); + COMPOSE.withExposedService("kogito", KOGITO_PORT); + COMPOSE.withExposedService("kafka", KAFKA_PORT); + COMPOSE.withExposedService("connect", DEBEZIUM_PORT); + COMPOSE.withLogConsumer("kafka", logger()); + COMPOSE.withLogConsumer("connect", logger()); + COMPOSE.withLogConsumer("sidecar", logger()); + COMPOSE.withLogConsumer("kogito", logger()); + COMPOSE.waitingFor("kafka", Wait.forListeningPort()); + COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); + COMPOSE.waitingFor("kogito", Wait.forListeningPort()); + COMPOSE.withLocalCompose(true); } private static Consumer logger() { return new Slf4jLogConsumer(LOGGER); } - //@BeforeEach + @BeforeEach void setup() { kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT); debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT); @@ -99,7 +107,7 @@ void setup() { kafkaClient = new KafkaTestClient("localhost:" + kafkaPort); } - //@AfterEach + @AfterEach void close() { if (kafkaClient != null) { kafkaClient.shutdown(); @@ -107,7 +115,6 @@ void close() { } @Test - @Disabled public void testSendProcessEvents() throws InterruptedException { // Check Debezium (Kafka, MongoDB) readiness await().ignoreExceptions() diff --git a/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java b/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java index 871de1ab3d..5fa6e2289c 100644 --- a/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java +++ b/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java @@ -26,7 +26,7 @@ import org.kie.kogito.testcontainers.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; @@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT { private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId(); @Container - public static DockerComposeContainer environment; + public static ComposeContainer environment; static { try { - environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) - .withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("prometheus_1", PROMETHEUS_PORT, + environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) + .withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("prometheus-1", PROMETHEUS_PORT, Wait.forHttp("/api/v1/targets") .forResponsePredicate(x -> x.contains("\"health\":\"up\"")) .withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER)) + .withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER)) .withPull(false) - .withLocalCompose(true) - //See https://github.com/testcontainers/testcontainers-java/issues/4565 - .withOptions("--compatibility"); + .withLocalCompose(true); } catch (URISyntaxException e) { throw new RuntimeException(e); } diff --git a/kogito-springboot-examples/flexible-process-springboot/src/main/resources/service-desk.bpmn b/kogito-springboot-examples/flexible-process-springboot/src/main/resources/service-desk.bpmn index 30e28de5b9..264cf721c3 100644 --- a/kogito-springboot-examples/flexible-process-springboot/src/main/resources/service-desk.bpmn +++ b/kogito-springboot-examples/flexible-process-springboot/src/main/resources/service-desk.bpmn @@ -1,4 +1,5 @@ - + + @@ -499,11 +500,13 @@ + _AD768963-CBF7-4269-9D43-51FE0D5D2556_TaskNameInputX _AD768963-CBF7-4269-9D43-51FE0D5D2556_SkippableInputX + _AD768963-CBF7-4269-9D43-51FE0D5D2556_GroupIdInputX _AD768963-CBF7-4269-9D43-51FE0D5D2556_evaluationOutputX @@ -524,6 +527,13 @@ + + _AD768963-CBF7-4269-9D43-51FE0D5D2556_GroupIdInputX + + + + + _AD768963-CBF7-4269-9D43-51FE0D5D2556_evaluationOutputX evaluation @@ -902,4 +912,4 @@ _fswpMKJxEDiZN4UVlvQdCA _fswpMKJxEDiZN4UVlvQdCA - + \ No newline at end of file diff --git a/kogito-springboot-examples/flexible-process-springboot/src/test/java/org/kie/kogito/flexible/example/springboot/ServiceDeskProcessTest.java b/kogito-springboot-examples/flexible-process-springboot/src/test/java/org/kie/kogito/flexible/example/springboot/ServiceDeskProcessTest.java index ab8be3b91e..d0f5da8495 100644 --- a/kogito-springboot-examples/flexible-process-springboot/src/test/java/org/kie/kogito/flexible/example/springboot/ServiceDeskProcessTest.java +++ b/kogito-springboot-examples/flexible-process-springboot/src/test/java/org/kie/kogito/flexible/example/springboot/ServiceDeskProcessTest.java @@ -109,6 +109,8 @@ private void addSupportComment(String id) { String location = given() .basePath(BASE_PATH) .contentType(ContentType.JSON) + .queryParam("user", "kelly") + .queryParam("group", "support") .when() .post("/{id}/ReceiveSupportComment", id) .then() @@ -140,9 +142,12 @@ private void addSupportComment(String id) { private void addCustomerComment(String id) { String location = given() - .basePath(BASE_PATH + "/" + id).contentType(ContentType.JSON) + .basePath(BASE_PATH) + .contentType(ContentType.JSON) + .queryParam("user", "Paco") + .queryParam("group", "customer") .when() - .post("/ReceiveCustomerComment") + .post("/{id}/ReceiveCustomerComment", id) .then() .statusCode(201) .header("Location", notNullValue()) @@ -171,17 +176,25 @@ private void addCustomerComment(String id) { } private void resolveCase(String id) { - given().basePath(BASE_PATH + "/" + id).contentType(ContentType.JSON).when().post("/Resolve_Case").then() - .statusCode(200).body("supportCase.state", is(State.RESOLVED.name())); + given() + .basePath(BASE_PATH) + .contentType(ContentType.JSON) + .when() + .post("/{id}/Resolve_Case", id) + .then() + .statusCode(200) + .body("supportCase.state", is(State.RESOLVED.name())); } @SuppressWarnings("unchecked") private void sendQuestionnaire(String id) { String taskId = given() - .basePath(BASE_PATH + "/" + id) + .basePath(BASE_PATH) .contentType(ContentType.JSON) + .queryParam("user", "Paco") + .queryParam("group", "customer") .when() - .get("/tasks") + .get("/{id}/tasks", id) .then() .statusCode(200) .body("size()", is(1)) @@ -195,13 +208,13 @@ private void sendQuestionnaire(String id) { params.put("evaluation", 10); given() - .basePath(BASE_PATH + "/" + id) + .basePath(BASE_PATH) .queryParam("user", "Paco") .queryParam("group", "customer") .contentType(ContentType.JSON) .when() .body(params) - .post("/Questionnaire/" + taskId) + .post("/{id}/Questionnaire/{taskId}", id, taskId) .then() .statusCode(200) .body("supportCase.state", is(State.CLOSED.name())) diff --git a/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java b/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java index 1379657c3d..455d64c24c 100644 --- a/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java +++ b/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java @@ -18,20 +18,28 @@ */ package org.kie.kogito.springboot.outbox; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.kogito.test.springboot.kafka.KafkaTestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import com.jayway.jsonpath.JsonPath; @@ -42,7 +50,8 @@ import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertTrue; -//@Testcontainers +@Testcontainers +@Disabled public class OutboxIT { private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class); @@ -55,8 +64,8 @@ public class OutboxIT { private static final int KAFKA_PORT = 9092; private static final int DEBEZIUM_PORT = 8083; - //@Container - private static DockerComposeContainer COMPOSE; + @Container + private static ComposeContainer COMPOSE; private int kogitoPort; private int debeziumPort; @@ -64,34 +73,33 @@ public class OutboxIT { private KafkaTestClient kafkaClient; - static { - // Path path = Paths.get("../../docker-compose.yml"); - // if (!path.toFile().exists()) { - // path = Paths.get("docker-compose.yml"); - // } - // COMPOSE = new DockerComposeContainer<>(path.toFile()); - // COMPOSE.withPull(false); - // COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); - // COMPOSE.withExposedService("kogito", KOGITO_PORT); - // COMPOSE.withExposedService("kafka", KAFKA_PORT); - // COMPOSE.withExposedService("connect", DEBEZIUM_PORT); - // COMPOSE.withLogConsumer("kafka", logger()); - // COMPOSE.withLogConsumer("connect", logger()); - // COMPOSE.withLogConsumer("sidecar", logger()); - // COMPOSE.withLogConsumer("kogito", logger()); - // COMPOSE.waitingFor("kafka", Wait.forListeningPort()); - // COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); - // COMPOSE.waitingFor("kogito", Wait.forListeningPort()); - // COMPOSE.withLocalCompose(true); - // //See https://github.com/testcontainers/testcontainers-java/issues/4565 - // COMPOSE.withOptions("--compatibility"); + @BeforeAll + static void init() { + Path path = Paths.get("../../docker-compose.yml"); + if (!path.toFile().exists()) { + path = Paths.get("docker-compose.yml"); + } + COMPOSE = new ComposeContainer(path.toFile()); + COMPOSE.withPull(false); + COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); + COMPOSE.withExposedService("kogito", KOGITO_PORT); + COMPOSE.withExposedService("kafka", KAFKA_PORT); + COMPOSE.withExposedService("connect", DEBEZIUM_PORT); + COMPOSE.withLogConsumer("kafka", logger()); + COMPOSE.withLogConsumer("connect", logger()); + COMPOSE.withLogConsumer("sidecar", logger()); + COMPOSE.withLogConsumer("kogito", logger()); + COMPOSE.waitingFor("kafka", Wait.forListeningPort()); + COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); + COMPOSE.waitingFor("kogito", Wait.forListeningPort()); + COMPOSE.withLocalCompose(true); } private static Consumer logger() { return new Slf4jLogConsumer(LOGGER); } - // @BeforeEach + @BeforeEach void setup() { kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT); debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT); @@ -99,7 +107,7 @@ void setup() { kafkaClient = new KafkaTestClient("localhost:" + kafkaPort); } - // @AfterEach + @AfterEach void close() { if (kafkaClient != null) { kafkaClient.shutdown(); @@ -107,7 +115,6 @@ void close() { } @Test - @Disabled public void testSendProcessEvents() throws InterruptedException { // Check Debezium (Kafka, MongoDB) readiness await().ignoreExceptions() diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md b/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md index 612799da95..47b7aa2cac 100644 --- a/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/README.md @@ -6,10 +6,11 @@ This example contains a simple workflow service that illustrate error handling. The service is described using JSON format as defined in the [CNCF Serverless Workflow specification](https://github.com/serverlessworkflow/specification). -The workflow check if the number is odd or even and print a message indicating that. -The main feature of this demo is that if the number is odd, an exception is thrown, and it is the exception error handling the one that sets the odd message. +The workflow consists of a Java service that determines if a provided number is odd or even, followed by a call to a REST service to publish any even number. The main feature of this demo is to show different ways of exception handling within a workflow. In the Java service, if the number is odd, an exception is thrown, and it is the exception error handling the one that sets the odd message. If the REST service call returns a 400 response, the exception error handling mechanism causes the workflow to follow an error path instead of propagating this exception to the caller. -Hence, this workflow expects JSON input containing a natural number. This number is passed using a service operation to `EvenService` java class. If the number is even, the workflow moves to the next defined state, injecting "even" `numberType`. But if the number is odd, the class throws an `IllegalArgumentException`. This exception is handled and redirected to odd inject node by using [inline workflow error handling](https://github.com/serverlessworkflow/specification/blob/main/specification.md#Workflow-Error-Handling). This basically consists on adding `onErrors` field, where the expected exception is specified in `code` and the target state (a node injecting "odd" `numberType`) in `transition`. Finally, both execution paths finish on the same node, which prints the calculated `eventType`. +Hence, this workflow expects JSON input containing a natural number. This number is passed using a service operation to `EvenService` java class. If the number is even, the workflow moves to the next defined state, injecting "even" `numberType`. But if the number is odd, the class throws an `IllegalArgumentException`. This exception is handled and redirected to odd inject node by using [inline workflow error handling](https://github.com/serverlessworkflow/specification/blob/main/specification.md#Workflow-Error-Handling). This basically consists on adding `onErrors` field, where the expected exception is specified in `code` and the target state (a node injecting "odd" `numberType`) in `transition`. Both execution paths then finish on the same node, which prints the calculated `numberType`. + +In the next step, the workflow calls the `PublishRestService` via REST. This service evaluates the `numberType` from the previous step and either returns with a successful response if the number is `even`, or with a failure response (HTTP status code 400) if the number is `odd`. The failure event is handled as the action node contains an `onError` definition. The referenced error is defined as `"code": "HTTP:400"`. If this exception is encountered, the workflow execution continues on an error path that prints out the failure. As per 0.8 version of the specification, there is no standard way to set a process in error. To do that, users can use a custom metadata key called `errorMessage` which will contain either the error message to be associated to the process instance or an expression that returns the error message to associated to the process instance. In addition to the workflow described before, this example includes a file called `errorWithMEtadata.sw.json` that illustrate the usage of such metadata. @@ -103,4 +104,5 @@ In Quarkus you should see the log message printed: ```text odd +Fail to publish result ``` diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/EvenService.java b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/EvenService.java index 1130ba4cf9..45abeb607f 100644 --- a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/EvenService.java +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/EvenService.java @@ -28,11 +28,4 @@ public void isEven(int number) { throw new IllegalArgumentException("Odd situation"); } } - - public void isSquare(int number) { - double sqrt = Math.sqrt(number); - if (sqrt == Math.round(sqrt)) { - throw new RuntimeException("Number has a perfect square"); - } - } } diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/PublishRestService.java b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/PublishRestService.java new file mode 100644 index 0000000000..ec96c03802 --- /dev/null +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/java/org/kie/kogito/examples/PublishRestService.java @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kie.kogito.examples; + +import jakarta.annotation.PostConstruct; +import jakarta.ws.rs.POST; +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 jakarta.ws.rs.core.Response.Status; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Path("/publish") +@Produces(MediaType.APPLICATION_JSON) +public class PublishRestService { + + private ObjectMapper objectMapper; + private static final Logger logger = LoggerFactory.getLogger(PublishRestService.class); + + @PostConstruct + void init() { + objectMapper = new ObjectMapper(); + } + + @Path("/{type}/{number}") + @POST + public Response publishEvenNumber(@PathParam("type") String type, @PathParam("number") int number) { + logger.info("Publish type " + type + " number " + number); + // check if the input number is even + if (!"even".equals(type)) { + return Response.status(Status.BAD_REQUEST).entity(objectMapper.createObjectNode().put("error", "Perfect square assessment not supported for odd numbers by this service")).build(); + } + return Response.ok().entity(objectMapper.createObjectNode().put("perfect", isPerfectSquare(number))).build(); + } + + private boolean isPerfectSquare(int number) { + double sqrt = Math.sqrt(number); + return (sqrt == Math.round(sqrt)); + } + +} diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/application.properties b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/application.properties index 835a80df6b..b66b53d5e6 100644 --- a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/application.properties +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/application.properties @@ -19,6 +19,9 @@ # Packaging # quarkus.package.type=fast-jar + +kogito.sw.functions.publishPerfectSquare.host=localhost +kogito.sw.functions.publishPerfectSquare.port=8081 quarkus.native.native-image-xmx=8g # profile to pack this example into a container, to use it execute activate the maven container profile, -Dcontainer @@ -26,4 +29,4 @@ quarkus.native.native-image-xmx=8g %container.quarkus.container-image.push=false %container.quarkus.container-image.group=${USER} %container.quarkus.container-image.registry=dev.local -%container.quarkus.container-image.tag=1.0-SNAPSHOT \ No newline at end of file +%container.quarkus.container-image.tag=1.0-SNAPSHOT diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/error.sw.json b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/error.sw.json index 08d18c80b4..7ce064f4c3 100644 --- a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/error.sw.json +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/main/resources/error.sw.json @@ -8,7 +8,11 @@ "errors": [ { "name": "odd number", - "code": "java.lang.RuntimeException" + "code": "Odd situation" + }, + { + "name": "bad request", + "code": "HTTP:400" } ], "functions": [ @@ -18,9 +22,9 @@ "operation": "service:java:org.kie.kogito.examples.EvenService::isEven" }, { - "name": "isSqr", + "name": "publishPerfectSquare", "type": "custom", - "operation": "service:java:org.kie.kogito.examples.EvenService::isSquare" + "operation": "rest:post:/publish/{type}/{number}" }, { "name": "printMessage", @@ -41,15 +45,6 @@ "number": "$.number" } } - }, - { - "name": "checkSqrAction", - "functionRef": { - "refName": "isSqr", - "arguments": { - "number": "$.number" - } - } } ], "transition": "even", @@ -66,7 +61,7 @@ "data": { "numberType": "even" }, - "transition": "finish" + "transition": "print" }, { "name": "odd", @@ -74,10 +69,10 @@ "data": { "numberType": "odd" }, - "transition": "finish" + "transition": "print" }, { - "name": "finish", + "name": "print", "type": "operation", "actions": [ { @@ -90,6 +85,53 @@ } } ], + "transition": "publish" + }, + { + "name": "publish", + "type": "operation", + "actions": [ + { + "name": "publishAction", + "functionRef" : { + "refName": "publishPerfectSquare", + "arguments": { + "type": "$.numberType", + "number": "$.number" + } + } + } + ], + "end": true, + "onErrors": [ + { + "errorRef": "bad request", + "transition": "setError" + } + ] + }, + { + "name": "setError", + "type": "inject", + "data": { + "errormessage": "Fail to publish result" + }, + "transition": "reportError" + }, + { + "name": "reportError", + "type": "operation", + "actions": [ + { + "name": "printAction", + "functionRef": { + "refName": "printMessage", + "arguments": { + "message": "errormessage" + } + } + } + ], "end": true } ] diff --git a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java index 099437d6c3..6fec4c0dc6 100644 --- a/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java +++ b/serverless-workflow-examples/serverless-workflow-error-quarkus/src/test/java/org/kie/kogito/examples/ErrorRestIT.java @@ -46,7 +46,7 @@ public void testErrorRest() { .post("/error") .then() .statusCode(201) - .body("workflowdata.numberType", is("odd")); + .body("workflowdata.numberType", is("even")); given() .contentType(ContentType.JSON) .accept(ContentType.JSON) diff --git a/serverless-workflow-examples/serverless-workflow-oauth2-orchestration-quarkus/acme-financial-service/src/main/resources/application.properties b/serverless-workflow-examples/serverless-workflow-oauth2-orchestration-quarkus/acme-financial-service/src/main/resources/application.properties index b2e303fe3e..74c22f13c7 100644 --- a/serverless-workflow-examples/serverless-workflow-oauth2-orchestration-quarkus/acme-financial-service/src/main/resources/application.properties +++ b/serverless-workflow-examples/serverless-workflow-oauth2-orchestration-quarkus/acme-financial-service/src/main/resources/application.properties @@ -19,6 +19,7 @@ quarkus.http.port=8483 quarkus.native.native-image-xmx=8g +quarkus.devservices.timeout=2m quarkus.swagger-ui.always-include=true