-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KOGITO-8351] - Introduce Camel Add-On for Serverless Workflow (#2689)
* [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
1 parent
c490763
commit 48e9066
Showing
39 changed files
with
1,503 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
78 changes: 78 additions & 0 deletions
78
...ain/java/org/kie/kogito/addons/quarkus/camel/deployment/CamelFunctionStaticValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...n/java/org/kie/kogito/addons/quarkus/camel/deployment/CamelWorkItemFunctionNamespace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...rc/main/java/org/kie/kogito/addons/quarkus/camel/deployment/CamelWorkItemTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ava/org/kie/kogito/addons/quarkus/camel/deployment/KogitoAddonsQuarkusCamelProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/org.kie.kogito.serverless.workflow.parser.FunctionNamespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.kie.kogito.addons.quarkus.camel.deployment.CamelWorkItemFunctionNamespace |
1 change: 1 addition & 0 deletions
1
...resources/META-INF/services/org.kie.kogito.serverless.workflow.parser.FunctionTypeHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.kie.kogito.addons.quarkus.camel.deployment.CamelWorkItemTypeHandler |
Oops, something went wrong.