Skip to content

Commit

Permalink
[KOGITO-8351] - Introduce Camel Add-On for Serverless Workflow (#2689)
Browse files Browse the repository at this point in the history
* [KOGITO-8351] - Introduce Camel Add-On for Serverless Workflow

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Fixing typos

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Fix integration-tests dependency to -deployment module

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Fix Sonar issues

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Small code improvements

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Add random ports to test cases

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Partially incorporating javi's review

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* enforcing camel producer interface in buildtime

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Refactoring to consider the new validateArgs method

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Align with validateArgs interface

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Camel doesn't need to unmarshal to Json anymore

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Incorporate Tristan's comments

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

* Remove unnecessary Camel versions

Signed-off-by: Ricardo Zanini <zanini@redhat.com>

Signed-off-by: Ricardo Zanini <zanini@redhat.com>
  • Loading branch information
ricardozanini committed Dec 21, 2022
1 parent c490763 commit 48e9066
Show file tree
Hide file tree
Showing 39 changed files with 1,503 additions and 0 deletions.
34 changes: 34 additions & 0 deletions kogito-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,40 @@
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel</artifactId>
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel-deployment</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel-deployment</artifactId>
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
Expand Down
2 changes: 2 additions & 0 deletions kogito-build/kogito-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<version.io.vertx>4.3.5</version.io.vertx>
<version.io.grpc>1.51.0</version.io.grpc>

<version.io.quarkus.camel>2.15.0</version.io.quarkus.camel>

<version.io.swagger.parser.v3>2.0.26</version.io.swagger.parser.v3>

<version.org.apache.commons>3.12.0</version.org.apache.commons>
Expand Down
66 changes: 66 additions & 0 deletions quarkus/addons/camel/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>kogito-addons-quarkus-camel-parent</artifactId>
<groupId>org.kie.kogito</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Kogito :: Add-Ons :: Quarkus :: Camel :: Deployment</name>
<description>Kogito Quarkus Camel Integration with Serverless Workflow</description>
<artifactId>kogito-addons-quarkus-camel-deployment</artifactId>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-camel</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-quarkus-serverless-workflow-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</artifactId>
<version>${version.io.quarkus.camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-yaml-dsl-deployment</artifactId>
<version>${version.io.quarkus.camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-xml-io-dsl-deployment</artifactId>
<version>${version.io.quarkus.camel}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</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,78 @@
/*
* Copyright 2022 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.camel.deployment;

import org.kie.kogito.addons.quarkus.camel.runtime.CamelConstants;

import com.fasterxml.jackson.databind.JsonNode;

import io.serverlessworkflow.api.functions.FunctionRef;

/**
* Static validation for Workflow DSL in build time.
*/
public final class CamelFunctionStaticValidator {

private CamelFunctionStaticValidator() {
}

/**
* Validation for the Function Reference
*
* @throws IllegalArgumentException if the there's more than one argument in the function call
*/
public static void validateFunctionRef(final FunctionRef ref) {
if (ref.getArguments() == null) {
return;
}
switch (ref.getArguments().size()) {
case 0:
return;
case 1:
verifyBodyArguments(ref);
break;
case 2:
verifyBodyArguments(ref);
verifyHeaderArguments(ref);
break;
default:
throw new IllegalArgumentException(
"Camel functions only support 'body', 'header', or no arguments. Please review the function '" + ref.getRefName() + "' arguments: \n" + ref.getArguments().asText());
}
}

private static void verifyHeaderArguments(final FunctionRef ref) {
final JsonNode headers = ref.getArguments().get(CamelConstants.HEADERS);
if (headers == null) {
throw new IllegalArgumentException(
"Camel functions only support 'body', 'header', or no arguments. Please review the arguments for the function '" + ref.getRefName() + "': \n" + ref.getArguments().asText());
}
if (!headers.isObject() && !headers.isTextual()) {
throw new IllegalArgumentException(
"Camel functions headers arguments must be a valid expression or a key/value object. "
+ "Please review the arguments for the function '" + ref.getRefName() + "': \n"
+ headers.asText());
}
}

private static void verifyBodyArguments(final FunctionRef ref) {
if (ref.getArguments().get(CamelConstants.BODY) == null) {
throw new IllegalArgumentException(
"No body arguments found in the function reference. Please review the function '" + ref.getRefName() + "' arguments to include a '\"body\": {}' argument.");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 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.camel.deployment;

import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
import org.jbpm.ruleflow.core.factory.WorkItemNodeFactory;
import org.kie.kogito.addons.quarkus.camel.runtime.CamelConstants;
import org.kie.kogito.serverless.workflow.functions.WorkItemFunctionNamespace;
import org.kie.kogito.serverless.workflow.parser.ParserContext;

import io.serverlessworkflow.api.Workflow;
import io.serverlessworkflow.api.functions.FunctionRef;

import static org.kie.kogito.addons.quarkus.camel.runtime.CamelCustomWorkItemHandler.NAME;
import static org.kie.kogito.addons.quarkus.camel.runtime.CamelCustomWorkItemHandler.OPERATION;
import static org.kie.kogito.serverless.workflow.parser.FunctionNamespaceFactory.getFunctionName;

/**
* Implementation of the custom Camel Namespace Function Reference
*/
public class CamelWorkItemFunctionNamespace extends WorkItemFunctionNamespace {

@Override
protected <T extends RuleFlowNodeContainerFactory<T, ?>> WorkItemNodeFactory<T> fillWorkItemHandler(Workflow workflow, ParserContext parserContext, WorkItemNodeFactory<T> workItemNodeFactory,
FunctionRef functionRef) {
return workItemNodeFactory.workName(NAME).metaData(OPERATION, getFunctionName(functionRef));
}

@Override
protected void validateArgs(FunctionRef ref) {
super.validateArgs(ref);
}

@Override
public String namespace() {
return CamelConstants.NAMESPACE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2022 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.camel.deployment;

import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
import org.jbpm.ruleflow.core.factory.WorkItemNodeFactory;
import org.kie.kogito.addons.quarkus.camel.runtime.CamelConstants;
import org.kie.kogito.serverless.workflow.parser.ParserContext;
import org.kie.kogito.serverless.workflow.parser.types.WorkItemTypeHandler;

import io.serverlessworkflow.api.Workflow;
import io.serverlessworkflow.api.functions.FunctionDefinition;
import io.serverlessworkflow.api.functions.FunctionRef;

import static org.kie.kogito.addons.quarkus.camel.runtime.CamelCustomWorkItemHandler.NAME;
import static org.kie.kogito.addons.quarkus.camel.runtime.CamelCustomWorkItemHandler.OPERATION;
import static org.kie.kogito.serverless.workflow.parser.FunctionTypeHandlerFactory.trimCustomOperation;

/**
* Implementation for the custom Camel Function Definition
*/
public class CamelWorkItemTypeHandler extends WorkItemTypeHandler {

@Override
protected <T extends RuleFlowNodeContainerFactory<T, ?>> WorkItemNodeFactory<T> fillWorkItemHandler(Workflow workflow, ParserContext context, WorkItemNodeFactory<T> node,
FunctionDefinition functionDef) {
return node.workName(NAME).metaData(OPERATION, trimCustomOperation(functionDef));
}

@Override
protected void validateArgs(FunctionRef ref) {
CamelFunctionStaticValidator.validateFunctionRef(ref);
}

@Override
public String type() {
return CamelConstants.NAMESPACE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2022 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.camel.deployment;

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

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

public class KogitoAddonsQuarkusCamelProcessor extends RequireCapabilityKogitoAddOnProcessor {

private static final String FEATURE = "kogito-addons-quarkus-camel";

public KogitoAddonsQuarkusCamelProcessor() {
super(KogitoCapability.SERVERLESS_WORKFLOW);
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.kie.kogito.addons.quarkus.camel.deployment.CamelWorkItemFunctionNamespace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.kie.kogito.addons.quarkus.camel.deployment.CamelWorkItemTypeHandler

0 comments on commit 48e9066

Please sign in to comment.