Skip to content

Commit

Permalink
KOGITO 4541: Move quickstart code as extended usecases to current spr…
Browse files Browse the repository at this point in the history
…ingboot examples (apache#659)

* KOGITO-4541: Added process-usertasks-springboot-with-console example

* KOGITO-4541: Added process-usertasks-with-security-oidc-springboot-with-console example

* KOGITO-4958: Add Spring Boot Actuator as default dependency

* removed opcional from spring-kafka dep and mvnw scripts
  • Loading branch information
nmirasch authored May 1, 2021
1 parent 77b5db4 commit 92aaef5
Show file tree
Hide file tree
Showing 68 changed files with 5,503 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@
<module>process-usertasks-quarkus-with-console</module>
<module>process-usertasks-springboot</module>
<module>process-usertasks-timer-quarkus-with-console</module>
<module>process-usertasks-springboot-with-console</module>
<module>process-usertasks-with-security-oidc-quarkus</module>
<module>process-usertasks-with-security-oidc-quarkus-with-console</module>
<module>process-usertasks-with-security-oidc-springboot</module>
<module>process-usertasks-with-security-oidc-springboot-with-console</module>
<module>process-usertasks-with-security-quarkus</module>
<module>process-usertasks-with-security-springboot</module>
<module>rules-quarkus-helloworld</module>
Expand Down
210 changes: 210 additions & 0 deletions process-usertasks-springboot-with-console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Process user task orchestration

## Description

A quickstart project shows very typical user task orchestration. It comes with two tasks assigned
to human actors via groups assignments - `managers`. So essentially anyone who is a member of that
group can act on the tasks. Though this example applies four eye principle which essentially means
that user who approved first task cannot approve second one. So there must be always at least two
distinct manager involved.

This example shows

* working with user tasks
* four eye principle with user tasks


<p align="center"><img width=75% height=50% src="docs/images/process.png"></p>

* Diagram Properties (top)
<p align="center"><img src="docs/images/diagramProperties.png"></p>

* Diagram Properties (bottom)
<p align="center"><img src="docs/images/diagramProperties3.png"></p>

* First Line Approval (top)
<p align="center"><img src="docs/images/firstLineApprovalUserTask.png"></p>

* First Line Approval (bottom)
<p align="center"><img src="docs/images/firstLineApprovalUserTask2.png"></p>

* First Line Approval (Assignments)
<p align="center"><img src="docs/images/firstLineApprovalUserTaskAssignments.png"></p>

* Second Line Approval
<p align="center"><img src="docs/images/secondLineApprovalUserTask.png"></p>

* Second Line Approval (Assignments)
<p align="center"><img src="docs/images/secondLineApprovalUserTaskAssignments.png"></p>

## Build and run

### Prerequisites

You will need:
- Java 11+ installed
- Environment variable JAVA_HOME set accordingly
- Maven 3.6.2+ installed
### Starting the Kogito and 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.

<p align="center"><img width=75% height=50% src="docs/images/services.png"></p>

You should start all the services before you execute any of the **Approvals** example, to do that please execute:

For Linux and MacOS:

1. Open a Terminal
2. Go to the process-usertasks-springboot-with-console folder at kogito-examples

```bash
cd <path_to_process-usertasks-springboot-with-console>/docker-compose
```

3. Run the ```startServices.sh``` script

```bash
sh ./startServices.sh
```

Once all services bootstrap, the following ports will be assigned on your local machine:

- Infinispan: 11222
- Kafka: 9092
- Data Index: 8180
- Management Console: 8280
- Task Console: 8380

> **_NOTE:_** This step requires the project to be compiled, please consider running a ```mvn clean compile``` command on the project root before running the ```startServices.sh``` script for the first time or any time you modify the project.
Once started you can simply stop all services by executing the ```docker-compose stop```.

All created containers can be removed by executing the ```docker-compose rm```.


### Compile and Run in Local Dev Mode

```sh
mvn clean compile spring-boot:run
```


### Package and Run using uberjar

```sh
mvn clean package
```

To run the generated native executable, generated in `target/`, execute

```sh
java -jar target/process-usertasks-springboot.jar
```

### OpenAPI (Swagger) documentation
[Specification at swagger.io](https://swagger.io/docs/specification/about/)

You can take a look at the [OpenAPI definition](http://localhost:8080/v3/api-docs) - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available [Swagger UI](https://editor.swagger.io).

In addition, various clients to interact with this service can be easily generated using this OpenAPI definition.


### Submit a request to start new approval

To make use of this application it is as simple as putting a sending request to `http://localhost:8080/approvals` with following content

```json
{
"traveller" : {
"firstName" : "John",
"lastName" : "Doe",
"email" : "jon.doe@example.com",
"nationality" : "American",
"address" : {
"street" : "main street",
"city" : "Boston",
"zipCode" : "10005",
"country" : "US" }
}
}
```

Complete curl command can be found below:

```sh
curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"traveller" : { "firstName" : "John", "lastName" : "Doe", "email" : "jon.doe@example.com", "nationality" : "American","address" : { "street" : "main street", "city" : "Boston", "zipCode" : "10005", "country" : "US" }}}' http://localhost:8080/approvals
```

### Show active process instances at Kogito Management Console

To access the Kogito Management Console open your browser and navigate to ``http://localhost:8280``.

<p align="center">
<img width=75% src="docs/images/MC_list1.png">
</p>

> **_NOTE:_** For more information about how to work with Kogito Management Console, please refer to the [Kogito Management Console Documentation](https://docs.jboss.org/kogito/release/latest/html_single/#con-management-console_kogito-developing-process-services) page.
Check the process instance details to see where is the execution path

<p align="center">
<img width=75% src="docs/images/MC_details1.png">
</p>

### Execute 'First Line approval' task at Kogito Task Console

To access the Kogito Task Console open your browser and navigate to ``http://localhost:8380`` and you should be redirected to the **Task Inbox**.
Ensure you are logged as a user with role manager to be able to see the First Line approval.

To be able to run the process, we need to create two Test users at Task Console, for testing purposes. Both users
have to belong to group `managers`.
<p align="center">
<img width=75% src="docs/images/AddTestUsers.png">
</p>

Then change to one of the new created users.

<p align="center">
<img width=75% src="docs/images/TC_list1.png">
</p>

> **_NOTE:_** For more information about how to work with Kogito Task Console, please refer to the [Kogito Task Console Documentation](https://docs.jboss.org/kogito/release/latest/html_single/#con-task-console_kogito-developing-process-services) page.
Access to 'First Line approval' task and complete

<p align="center">
<img width=75% src="docs/images/TC_FirstLine.png">
</p>

Check the process instance details at Kogito Management Console to see the execution path reflects the completed task

<p align="center">
<img width=75% src="docs/images/MC_details2.png">
</p>

### Execute 'Second Line approval' task at Kogito Task Console

Access the Kogito Task Console and ensure you are logged as a user with role managers different from the one
executed the First Line approval to be able to see the Second Line approval
following the second eye principle.

<p align="center">
<img width=75% src="docs/images/TC_list2.png">
</p>

Access to 'Second Line approval' task and complete

<p align="center">
<img width=75% src="docs/images/TC_SecondLine.png">
</p>

Check the process instance details at Kogito Management Console, and verify the execution path is reflected in the diagram.

<p align="center">
<img width=75% src="docs/images/MC_details3.png">
</p>

## Deploying with Kogito Operator

In the [`operator`](operator) directory you'll find the custom resources needed to deploy this example on OpenShift with the [Kogito Operator](https://docs.jboss.org/kogito/release/latest/html_single/#chap_kogito-deploying-on-openshift).
50 changes: 50 additions & 0 deletions process-usertasks-springboot-with-console/docker-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## 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:
- Infinispan
- Kafka
- Kogito Data Index
- Kogito Management Console
- Kogito Task Console

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 required services

Before you execute the **Hiring** example, start all the services by following these steps:

For Linux and MacOS:

./startServices.sh

For Windows:

Create a .env file with the content containing the version of the Kogito images you would like to run, example:

KOGITO_VERSION=1.0.0

Then run

docker-compose up

Once all services bootstrap, the following ports will be assigned on your local machine:
- Infinispan: 11222
- Kafka: 9092
- Data Index: 8180
- Management Console: 8280
- Task Console: 8380

### Stopping and removing volume data

To stop all services, simply run:

docker-compose stop

It is also recommended to remove any of stopped containers by running:

docker-compose rm

For more details please check the Docker Compose documentation.

docker-compose --help
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
version: '2.1'

services:

infinispan:
image: infinispan/server:11.0.4.Final
container_name: infinispan
ports:
- 11222:11222
command: "/opt/infinispan/bin/server.sh -c infinispan-demo.xml"
volumes:
- ./infinispan/infinispan.xml:/opt/infinispan/server/conf/infinispan-demo.xml:z
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:11222/rest/v2/cache-managers/default/health/status" ]
interval: 1s
timeout: 30s
retries: 50

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"

data-index:
container_name: data-index
image: quay.io/kiegroup/kogito-data-index-infinispan:${KOGITO_VERSION}
ports:
- "8180:8080"
depends_on:
kafka:
condition: service_started
infinispan:
condition: service_healthy
volumes:
- ./persistence/:/home/kogito/data/protobufs/
environment:
QUARKUS_INFINISPAN_CLIENT_SERVER_LIST: infinispan:11222
KAFKA_BOOTSTRAP_SERVERS: kafka:29092
KOGITO_DATA_INDEX_PROPS: -Dkogito.protobuf.folder=/home/kogito/data/protobufs/

management-console:
container_name: management-console
image: quay.io/kiegroup/kogito-management-console:${KOGITO_VERSION}
ports:
- 8280:8080
depends_on:
data-index:
condition: service_started
volumes:
- ./svg/:/home/kogito/data/svg/
environment:
KOGITO_DATAINDEX_HTTP_URL: http://${DOCKER_GATEWAY_HOST}:8180
KOGITO_MANAGEMENT_CONSOLE_PROPS: -Dkogito.svg.folder.path=/home/kogito/data/svg

task-console:
container_name: task-console
image: quay.io/kiegroup/kogito-task-console:${KOGITO_VERSION}
ports:
- 8380:8080
depends_on:
data-index:
condition: service_started
environment:
KOGITO_TASK_CONSOLE_PROPS: -Dkogito.test.user-system.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<infinispan xmlns='urn:infinispan:config:10.0' xsi:schemaLocation='urn:infinispan:config:10.0 http://www.infinispan.org/schemas/infinispan-config-10.0.xsd urn:infinispan:server:10.0 http://www.infinispan.org/schemas/infinispan-server-10.0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<cache-container name="default"/>
<server xmlns='urn:infinispan:server:10.0'>
<interfaces>
<interface name='public'>
<inet-address value='${infinispan.bind.address:0.0.0.0}'/>
</interface>
</interfaces>
<socket-bindings default-interface='public' port-offset='0'>
<socket-binding name='default' port='11222'/>
</socket-bindings>
<security>
<security-realms>
<security-realm name='default'>
<properties-realm groups-attribute='Roles'>
<user-properties path='users.properties' relative-to='infinispan.server.config.path'/>
<group-properties path='groups.properties' relative-to='infinispan.server.config.path'/>
</properties-realm>
</security-realm>
</security-realms>
</security>
<endpoints socket-binding='default' security-realm='default'>
<hotrod-connector name="hotrod"/>
<rest-connector name="rest"/>
</endpoints>
</server>
</infinispan>
Loading

0 comments on commit 92aaef5

Please sign in to comment.