Skip to content

Commit

Permalink
KOGITO-8979 - Data Index MongoDB persistence addon
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianonicolai committed Sep 1, 2023
1 parent 9abfcbd commit 0c90f96
Show file tree
Hide file tree
Showing 20 changed files with 683 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@

package org.kie.kogito.addons.quarkus.data.index.persistence.deployment;

import org.jboss.jandex.DotName;
import org.jboss.jandex.Type;
import org.kie.kogito.quarkus.addons.common.deployment.KogitoCapability;
import org.kie.kogito.quarkus.addons.common.deployment.OneOfCapabilityKogitoAddOnProcessor;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;

public abstract class AbstractKogitoAddonsQuarkusDataIndexPersistenceProcessor extends OneOfCapabilityKogitoAddOnProcessor {

AbstractKogitoAddonsQuarkusDataIndexPersistenceProcessor() {
super(KogitoCapability.SERVERLESS_WORKFLOW, KogitoCapability.PROCESSES);
}

protected void reflectiveHierarchy(Class<?> clazz, BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass) {
DotName dotName = DotName.createSimple(clazz.getName());
Type type = Type.create(dotName, Type.Kind.CLASS);
reflectiveHierarchyClass.produce(new ReflectiveHierarchyBuildItem.Builder().type(type).build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb-deployment</artifactId>
<name>Kogito Apps :: Kogito Addons Quarkus Data Index Persistence MongoDB :: Deployment</name>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client-deployment</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${version.io.quarkus}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 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.addons.quarkus.data.index.persistence.deployment;

import org.kie.kogito.index.mongodb.model.ProcessDefinitionEntity;
import org.kie.kogito.index.mongodb.model.ProcessInstanceEntity;
import org.kie.kogito.index.mongodb.model.UserTaskInstanceEntity;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild;

public class MongoDataIndexPersistenceProcessor extends AbstractKogitoAddonsQuarkusDataIndexPersistenceProcessor {

private static final String FEATURE = "kogito-addons-quarkus-data-index-persistence-mongodb";

@BuildStep
public FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
public void mongoNativeResources(BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass) {
reflectiveHierarchy(ProcessDefinitionEntity.class, reflectiveHierarchyClass);
reflectiveHierarchy(ProcessInstanceEntity.class, reflectiveHierarchyClass);
reflectiveHierarchy(UserTaskInstanceEntity.class, reflectiveHierarchyClass);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-data-index-mongodb-persistence-integration-tests-process</artifactId>
<name>Kogito Apps :: Kogito Addons Quarkus Data Index Persistence MongoDB :: Integration Tests :: Process</name>

<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-processes</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-persistence-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-test-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-data-index-persistence-mongodb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${version.io.quarkus}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
<failsafe.include>**/*IT.java</failsafe.include>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kogito.persistence.type=mongodb

# MongoDB
quarkus.mongodb.database=kogito

quarkus.devservices.enabled=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:bpsim="http://www.bpsim.org/schemas/1.0" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:drools="http://www.jboss.org/drools" xmlns:xsi="xsi" id="_hT2oIPJzEDuE8tm0q8uK_w" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd http://www.omg.org/spec/DD/20100524/DC DC.xsd http://www.omg.org/spec/DD/20100524/DI DI.xsd " exporter="jBPM Process Modeler" exporterVersion="2.0" targetNamespace="http://www.omg.org/bpmn20">
<bpmn2:collaboration id="_4326C578-FDBD-4F8C-BAB8-5C9CFE867882" name="Default Collaboration">
<bpmn2:participant id="_B70F49F9-D9BE-4BCD-A095-2601433AD6F7" name="Pool Participant" processRef="hello"/>
</bpmn2:collaboration>
<bpmn2:process id="hello" drools:packageName="com.example" drools:version="1.0" drools:adHoc="false" name="hello" isExecutable="true" processType="Public">
<bpmn2:sequenceFlow id="_9FD38FF8-A530-41E7-8EA0-E1F71353CBB3" sourceRef="_C3F8BD7A-55E5-4513-8C0D-5576F8099167" targetRef="_B3241ACF-97BE-443B-A49F-964AB3DD006C"/>
<bpmn2:endEvent id="_B3241ACF-97BE-443B-A49F-964AB3DD006C">
<bpmn2:incoming>_9FD38FF8-A530-41E7-8EA0-E1F71353CBB3</bpmn2:incoming>
</bpmn2:endEvent>
<bpmn2:startEvent id="_C3F8BD7A-55E5-4513-8C0D-5576F8099167">
<bpmn2:outgoing>_9FD38FF8-A530-41E7-8EA0-E1F71353CBB3</bpmn2:outgoing>
</bpmn2:startEvent>
</bpmn2:process>
<bpmndi:BPMNDiagram>
<bpmndi:BPMNPlane bpmnElement="hello">
<bpmndi:BPMNShape id="shape__C3F8BD7A-55E5-4513-8C0D-5576F8099167" bpmnElement="_C3F8BD7A-55E5-4513-8C0D-5576F8099167">
<dc:Bounds height="56" width="56" x="321" y="287"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="shape__B3241ACF-97BE-443B-A49F-964AB3DD006C" bpmnElement="_B3241ACF-97BE-443B-A49F-964AB3DD006C">
<dc:Bounds height="56" width="56" x="457" y="287"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="edge_shape__C3F8BD7A-55E5-4513-8C0D-5576F8099167_to_shape__B3241ACF-97BE-443B-A49F-964AB3DD006C" bpmnElement="_9FD38FF8-A530-41E7-8EA0-E1F71353CBB3">
<di:waypoint x="349" y="315"/>
<di:waypoint x="485" y="315"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmn2:relationship type="BPSimData">
<bpmn2:extensionElements>
<bpsim:BPSimData>
<bpsim:Scenario id="default" name="Simulationscenario">
<bpsim:ScenarioParameters/>
<bpsim:ElementParameters elementRef="_C3F8BD7A-55E5-4513-8C0D-5576F8099167">
<bpsim:TimeParameters>
<bpsim:ProcessingTime>
<bpsim:NormalDistribution mean="0" standardDeviation="0"/>
</bpsim:ProcessingTime>
</bpsim:TimeParameters>
</bpsim:ElementParameters>
</bpsim:Scenario>
</bpsim:BPSimData>
</bpmn2:extensionElements>
<bpmn2:source>_hT2oIPJzEDuE8tm0q8uK_w</bpmn2:source>
<bpmn2:target>_hT2oIPJzEDuE8tm0q8uK_w</bpmn2:target>
</bpmn2:relationship>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2023 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.addons.quarkus.data.index.it;

import org.junit.jupiter.api.Test;
import org.kie.kogito.index.test.quarkus.http.DataIndexMongoDBHttpQuarkusTestResource;
import org.kie.kogito.test.quarkus.QuarkusTestProperty;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.kie.kogito.index.test.Constants.KOGITO_DATA_INDEX_SERVICE_URL;

@QuarkusIntegrationTest
@QuarkusTestResource(DataIndexMongoDBHttpQuarkusTestResource.class)
class MongoQuarkusAddonDataIndexPersistenceIT {

static {
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}

@QuarkusTestProperty(name = KOGITO_DATA_INDEX_SERVICE_URL)
String dataIndex;

@Test
void testDataIndexAddon() {
given().contentType(ContentType.JSON)
.baseUri(dataIndex)
.body("{ \"query\" : \"{ProcessInstances{ id } }\" }")
.when().post("/graphql")
.then().statusCode(200)
.body("data.ProcessInstances.size()", is(greaterThanOrEqualTo(0)));

String processInstanceId = given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.post("/hello")
.then()
.statusCode(201)
.body("id", is(notNullValue()))
.extract().path("id");

given().contentType(ContentType.JSON)
.baseUri(dataIndex)
.body("{ \"query\" : \"{ProcessInstances(where: { id: {equal: \\\"" + processInstanceId + "\\\"}}){ id, state } }\" }")
.when().post("/graphql")
.then().statusCode(200)
.body("data.ProcessInstances.size()", is(1))
.body("data.ProcessInstances[0].id", is(processInstanceId))
.body("data.ProcessInstances[0].state", is("COMPLETED"));
}

@Test
void testGraphQL() {
given().contentType(ContentType.HTML)
.when().get("/graphql")
.then().statusCode(404);
}

@Test
void testGraphQLUI() {
given().contentType(ContentType.HTML)
.when().get("/q/graphql-ui/")
.then().statusCode(404);
}

}
Loading

0 comments on commit 0c90f96

Please sign in to comment.