Skip to content

Commit

Permalink
[KOGITO-9555] Moving resource to addon
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Jul 11, 2023
1 parent 65ba3d8 commit a3054eb
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 9 deletions.
22 changes: 22 additions & 0 deletions kogito-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,28 @@
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions-deployment</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
Expand Down
52 changes: 52 additions & 0 deletions quarkus/addons/process-definitions/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-process-definitions-deployment</artifactId>
<name>Kogito Add-On Process Definitions - Deployment</name>
<dependencies>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-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,36 @@
/*
* 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.process.management.deployment;

import org.kie.kogito.quarkus.addons.common.deployment.KogitoCapability;
import org.kie.kogito.quarkus.addons.common.deployment.OneOfCapabilityKogitoAddOnProcessor;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

class ProcessDefinitionsProcessor extends OneOfCapabilityKogitoAddOnProcessor {

private static final String FEATURE = "kogito-addon-process-definitions-extension";

ProcessDefinitionsProcessor() {
super(KogitoCapability.SERVERLESS_WORKFLOW);
}

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}
21 changes: 21 additions & 0 deletions quarkus/addons/process-definitions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kogito-addons-quarkus-parent</artifactId>
<groupId>org.kie.kogito</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>kogito-addons-quarkus-process-definitions-parent</artifactId>
<name>Kogito Add-On Process Deployment - Parent</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>

</project>
78 changes: 78 additions & 0 deletions quarkus/addons/process-definitions/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-process-definitions-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>kogito-addons-quarkus-process-definitions</artifactId>
<name>Kogito Add-On Process Definitions</name>
<description>Allow deploying process definitions for Quarkus</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-serverless-workflow-executor-core</artifactId>
</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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment>
<capabilities>
<provides>org.kie.kogito.addons.process.definitions</provides>
</capabilities>
</configuration>
</execution>
</executions>
</plugin>
<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
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.serverless.workflow;
package org.kie.kogito.process.definitions;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -29,12 +29,15 @@
import javax.ws.rs.core.Response;

import org.kie.kogito.serverless.workflow.executor.StaticWorkflowApplication;
import org.kie.kogito.serverless.workflow.models.JsonNodeModel;
import org.kie.kogito.serverless.workflow.models.JsonNodeModelInput;
import org.kie.kogito.serverless.workflow.utils.ServerlessWorkflowUtils;
import org.kie.kogito.serverless.workflow.utils.WorkflowFormat;

import com.fasterxml.jackson.databind.node.NullNode;

@Path("/")
public class KogitoGenericResource {
public class ProcessDefinitionsResource {

private StaticWorkflowApplication application;

Expand All @@ -53,13 +56,16 @@ void cleanup() {
@Consumes(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response executeProcess(@PathParam("id") String processId, JsonNodeModelInput input) {
return Response.status(200).entity(
application.execute(application.findProcessById(processId).orElseThrow(() -> new IllegalArgumentException("Cannot find process id " + processId)), input.toModel())).build();
return Response.status(201).entity(
application.execute(application.findProcessById(processId).orElseThrow(() -> new IllegalArgumentException("Cannot find process id " + processId)),
input != null ? input.toModel() : new JsonNodeModel(NullNode.instance)))
.build();
}

@POST
@Consumes(MediaType.TEXT_PLAIN)
@Path("{id}/upload")
@Produces(MediaType.TEXT_PLAIN)
@Path("{id}/definition")
public Response uploadProcess(@PathParam("id") String processId, String content) throws IOException {
application.process(ServerlessWorkflowUtils.getWorkflow(new StringReader(content), content.startsWith("{") ? WorkflowFormat.JSON : WorkflowFormat.YAML));
return Response.ok().build();
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process-definitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Kogito Add-On Process Defintions
description: Kogito Process Definitions REST API
metadata:
keywords:
- kogito
- process
- serverless workflow
categories:
- "business-automation"
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.process.definitions;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

@QuarkusTest
public class ProcessDefinitionsResourceTest {

@Test
void testAddDefinition() throws IOException {
given()
.contentType(ContentType.TEXT)
.accept(ContentType.TEXT)
.body(new String(Thread.currentThread().getContextClassLoader().getResource("helloworld.sw.json").openStream().readAllBytes())).when()
.post("/helloworld/definition")
.then()
.statusCode(200);

given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.when()
.post("/helloworld")
.then()
.statusCode(201)
.body("workflowdata.result", containsString("Hello World!"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "helloworld",
"version": "1.0",
"name": "Hello World Workflow",
"description": "Inject Hello World",
"start": "Hello State",
"states":[
{
"name":"Hello State",
"type":"inject",
"data": {
"result": "Hello World!"
},
"end": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- %l lowers performance -->
<!--<pattern>%d [%t] %-5p %l%n %m%n</pattern>-->
<pattern>%d [%t|%C] %-5p %m%n</pattern>
</encoder>
</appender>

<logger name="org.kie" level="info" />

<root level="info">
<appender-ref ref="consoleAppender" />
</root>

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-serverless-workflow-executor-core</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
Expand Down

0 comments on commit a3054eb

Please sign in to comment.