Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main branch with Apache main branch #41

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ A Serverless Workflow service that works as a Github bot application, which reac

* [on Quarkus](serverless-workflow-examples/serverless-workflow-github-showcase)

## Serverless Workflow Correlation

* [on Quarkus (JDBC)](serverless-workflow-examples/serverless-workflow-correlation-quarkus)
* [on Quarkus (MongoDB)](serverless-workflow-examples/serverless-workflow-correlation-mongodb-quarkus)


## Other Misc Examples

- Onboarding example combining 1 process and two decision services: see [README.md](kogito-quarkus-examples/onboarding-example/README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.kie.kogito.addons.k8s.LocalEndpointDiscovery;
import org.kie.kogito.addons.quarkus.k8s.workitems.QuarkusDiscoveredEndpointCaller;
import org.kie.kogito.examples.onboarding.DecisionTaskWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;

import jakarta.annotation.PostConstruct;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
package org.kie.kogito.examples.onboarding;

import java.util.Map;
import java.util.Optional;

import org.kie.kogito.addons.quarkus.k8s.workitems.QuarkusDiscoveredEndpointCaller;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;

import jakarta.ws.rs.HttpMethod;

public class DecisionTaskWorkItemHandler implements KogitoWorkItemHandler {
public class DecisionTaskWorkItemHandler extends DefaultKogitoWorkItemHandler {

private QuarkusDiscoveredEndpointCaller endpointCaller;

Expand All @@ -36,14 +39,9 @@ public DecisionTaskWorkItemHandler(QuarkusDiscoveredEndpointCaller endpointCalle
}

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
Map<String, Object> results = endpointCaller.discoverAndCall(workItem, System.getenv("NAMESPACE"), "Decision", HttpMethod.POST);
manager.completeWorkItem(workItem.getStringId(), results);
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {

return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.kie.kogito.examples;

import org.kie.kogito.examples.test.RecordedOutputWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;

public class WorkItemHandlerConfig extends BaseWorkItemHandlerConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import org.junit.jupiter.api.Test;
import org.kie.kogito.examples.test.RecordedOutputWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.process.ProcessConfig;
import org.kie.kogito.testcontainers.quarkus.InfinispanQuarkusTestResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;

public class RecordedOutputWorkItemHandler implements KogitoWorkItemHandler {
public class RecordedOutputWorkItemHandler extends DefaultKogitoWorkItemHandler {

private Map<String, Function<KogitoWorkItem, Map<String, Object>>> recorded = new HashMap<>();

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
Map<String, Object> results = recorded.remove(workItem.getParameter("TaskName")).apply(workItem);

manager.completeWorkItem(workItem.getStringId(), results);
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {

return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

public void record(String name, Function<KogitoWorkItem, Map<String, Object>> item) {
Expand Down
2 changes: 2 additions & 0 deletions kogito-quarkus-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<module>process-error-handling</module>
<module>process-incubation-api-quarkus</module>
<module>process-infinispan-persistence-quarkus</module>
<module>process-instance-migration-quarkus</module>
<module>process-kafka-avro-multi-quarkus</module>
<module>process-kafka-multi-quarkus</module>
<module>process-kafka-persistence-quarkus</module>
Expand Down Expand Up @@ -140,6 +141,7 @@
<module>pmml-quarkus-example</module>
<module>process-business-rules-quarkus</module>
<module>process-infinispan-persistence-quarkus</module>
<module>process-instance-migration-quarkus</module>
<module>process-kafka-persistence-quarkus</module>
<module>process-kafka-quickstart-quarkus</module>
<module>process-knative-quickstart-quarkus</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.kie.api.runtime.process.ProcessWorkItemHandlerException;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.KogitoWorkItem;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemHandler;
import org.kie.kogito.internal.process.workitem.KogitoWorkItemManager;
import org.kie.kogito.internal.process.workitem.WorkItemTransition;
import org.kie.kogito.process.workitems.impl.DefaultKogitoWorkItemHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CustomTaskWorkItemHandler implements KogitoWorkItemHandler {
public class CustomTaskWorkItemHandler extends DefaultKogitoWorkItemHandler {

private static final Logger LOG = LoggerFactory.getLogger(CustomTaskWorkItemHandler.class);

@Override
public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
public Optional<WorkItemTransition> activateWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workItem, WorkItemTransition transition) {
LOG.debug("start");
LOG.debug("Passed parameters:");

Expand All @@ -51,15 +54,22 @@ public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manag
if (input.matches("(RETRY|COMPLETE|RETHROW)")) {
handleError(input);
} else if (input.contentEquals("ABORT")) {
manager.abortWorkItem(workItem.getStringId());
return Optional.of(handler.abortTransition(workItem.getPhaseStatus()));
} else {
// Don’t forget to finish the work item otherwise the process
// will be active infinitely and never will pass the flow
// to the next node.
manager.completeWorkItem(workItem.getStringId(), results);
return Optional.of(handler.completeTransition(workItem.getPhaseStatus(), results));
}

LOG.debug("end");
return Optional.empty();
}

@Override
public Optional<WorkItemTransition> abortWorkItemHandler(KogitoWorkItemManager manager, KogitoWorkItemHandler handler, KogitoWorkItem workitem, WorkItemTransition transition) {
LOG.debug("ABORT!");
return Optional.empty();
}

private void handleError(String strategy) {
Expand All @@ -68,9 +78,4 @@ private void handleError(String strategy) {
new IllegalStateException(strategy + " strategy test"));
}

@Override
public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) {
LOG.debug("ABORT!");
manager.abortWorkItem(workItem.getStringId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ echo "Kogito Image version: ${KOGITO_VERSION}"
echo "KOGITO_VERSION=${KOGITO_VERSION}" > ".env"
echo "COMPOSE_PROFILES='${PROFILE}'" >> ".env"

if [ "$(uname)" == "Darwin" ]; then
if [ "$(uname)" = "Darwin" ]; then
echo "DOCKER_GATEWAY_HOST=kubernetes.docker.internal" >> ".env"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
elif [ "$(expr substr $(uname -s) 1 5)" = "Linux" ]; then
echo "DOCKER_GATEWAY_HOST=172.17.0.1" >> ".env"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@
<artifactId>kogito-addons-quarkus-data-index-postgresql</artifactId>
</dependency>

<!-- Data Index Persistence -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-postgresql</artifactId>
</dependency>

<!-- Jobs Service -->
<dependency>
<groupId>org.kie</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ 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
kie.flyway.enabled=true

kogito.persistence.type=jdbc
quarkus.datasource.db-kind=postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,47 @@ version: "3"

services:
postgres-compose:
image: postgres:13.4-alpine3.14
image: postgres:16.1-alpine3.19
container_name: postgres
environment:
POSTGRES_PASSWORD: pass
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
volumes:
- ./sql:/docker-entrypoint-initdb.d/
healthcheck:
test: [ "CMD", "pg_isready", "-q", "-d", "kogito", "-U", "kogito-user" ]
timeout: 45s
interval: 10s
retries: 50
networks:
- postgres-compose-network
container_name: postgres-container

pgadmin-compose:
image: dpage/pgadmin4:5.0
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: pass
image: dpage/pgadmin4:8.2
container_name: pgadmin
ports:
- 8055:80
depends_on:
- postgres-compose
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: [email protected]
PGADMIN_DEFAULT_PASSWORD: pass
PGADMIN_CONFIG_SERVER_MODE: "False"
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: "False"
GUNICORN_ACCESS_LOGFILE: "/dev/null"
networks:
- postgres-compose-network
container_name: pgadmin-container

networks:
postgres-compose-network:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
postgres:5432:kogito:kogito-user:kogito-pass
postgres:5432:postgres:kogito-user:kogito-pass
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE ROLE "kogito-user" WITH
CREATEDB
CREATEROLE
NOREPLICATION
ENCRYPTED PASSWORD 'md54adb613a8ffdd707e032c918d791e2e5';
PASSWORD 'kogito-pass';

CREATE DATABASE kogito
WITH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ quarkus.datasource.db-kind=postgresql
%prod.quarkus.datasource.username=kogito-user
%prod.quarkus.datasource.password=kogito-pass
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/kogito
quarkus.flyway.migrate-at-start=true

kie.flyway.enabled=true

%dev.quarkus.kogito.devservices.enabled=false
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
package org.acme.travels.config;

import org.acme.travels.usertasks.CustomHumanTaskLifeCycle;
import org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler;
import org.acme.travels.usertasks.CustomHumanTaskWorkItemHandler;
import org.kie.kogito.process.impl.DefaultWorkItemHandlerConfig;

import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -37,6 +36,6 @@
@ApplicationScoped
public class CustomWorkItemHandlerConfig extends DefaultWorkItemHandlerConfig {
{
register("Human Task", new HumanTaskWorkItemHandler(new CustomHumanTaskLifeCycle()));
register("Human Task", new CustomHumanTaskWorkItemHandler());
}
}
Loading
Loading