From 154f37ab26cee4f7cb198e930ce50c76e5720476 Mon Sep 17 00:00:00 2001 From: ikulaga Date: Wed, 11 Sep 2024 22:25:22 +0500 Subject: [PATCH] camel-python language extension --- catalog/pom.xml | 13 ++ docs/antora.yml | 2 +- .../ROOT/examples/languages/python.yml | 13 ++ docs/modules/ROOT/nav.adoc | 1 + .../pages/reference/extensions/python.adoc | 45 +++++++ extensions/pom.xml | 1 + extensions/python/deployment/pom.xml | 67 +++++++++++ .../PythonCompiledExpressionBuildItem.java | 40 +++++++ .../python/deployment/PythonProcessor.java | 102 ++++++++++++++++ extensions/python/pom.xml | 39 ++++++ extensions/python/runtime/pom.xml | 106 +++++++++++++++++ .../python/PythonExpressionRecorder.java | 39 ++++++ .../resources/META-INF/quarkus-extension.yaml | 34 ++++++ integration-tests/pom.xml | 1 + integration-tests/python/pom.xml | 112 ++++++++++++++++++ .../component/python/it/PythonResource.java | 78 ++++++++++++ .../component/python/it/PythonRoutes.java | 48 ++++++++ .../python/src/main/resources/script.py | 18 +++ .../quarkus/component/python/it/PythonIT.java | 24 ++++ .../component/python/it/PythonTest.java | 79 ++++++++++++ poms/bom/pom.xml | 15 +++ .../src/main/generated/flattened-full-pom.xml | 15 +++ .../main/generated/flattened-reduced-pom.xml | 15 +++ .../flattened-reduced-verbose-pom.xml | 15 +++ tooling/scripts/test-categories.yaml | 1 + 25 files changed, 922 insertions(+), 1 deletion(-) create mode 100644 docs/modules/ROOT/examples/languages/python.yml create mode 100644 docs/modules/ROOT/pages/reference/extensions/python.adoc create mode 100644 extensions/python/deployment/pom.xml create mode 100644 extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonCompiledExpressionBuildItem.java create mode 100644 extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonProcessor.java create mode 100644 extensions/python/pom.xml create mode 100644 extensions/python/runtime/pom.xml create mode 100644 extensions/python/runtime/src/main/java/org/apache/camel/quarkus/component/python/PythonExpressionRecorder.java create mode 100644 extensions/python/runtime/src/main/resources/META-INF/quarkus-extension.yaml create mode 100644 integration-tests/python/pom.xml create mode 100644 integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonResource.java create mode 100644 integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonRoutes.java create mode 100644 integration-tests/python/src/main/resources/script.py create mode 100644 integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonIT.java create mode 100644 integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonTest.java diff --git a/catalog/pom.xml b/catalog/pom.xml index 7abd52b0614c..d5a56b1e8200 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -3113,6 +3113,19 @@ + + org.apache.camel.quarkus + camel-quarkus-python + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-qdrant diff --git a/docs/antora.yml b/docs/antora.yml index 71f1cfe0ef8e..396c280d2427 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -34,7 +34,7 @@ asciidoc: quarkus-version: 3.13.0 # replace ${quarkus.version} graalvm-version: 23.1.2 # replace ${graalvm.version} graalvm-docs-version: jdk21 # replace ${graalvm-docs.version} - mapstruct-version: 1.5.5.Final # replace ${mapstruct.version} + mapstruct-version: 1.6.0 # replace ${mapstruct.version} min-maven-version: 3.8.2 # replace ${min-maven-version} target-maven-version: 3.9.8 # replace ${target-maven-version} diff --git a/docs/modules/ROOT/examples/languages/python.yml b/docs/modules/ROOT/examples/languages/python.yml new file mode 100644 index 000000000000..dbc4b4e704a5 --- /dev/null +++ b/docs/modules/ROOT/examples/languages/python.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-python +cqArtifactIdBase: python +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.14.0 +cqNativeSince: 3.14.0 +cqCamelPartName: python +cqCamelPartTitle: Python +cqCamelPartDescription: Evaluates a Python expression. +cqExtensionPageTitle: Python diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 6da7470cc05a..d8076785fc77 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -247,6 +247,7 @@ *** xref:reference/extensions/jackson-protobuf.adoc[Protobuf Jackson] *** xref:reference/extensions/pubnub.adoc[PubNub] *** xref:reference/extensions/pulsar.adoc[Pulsar] +*** xref:reference/extensions/python.adoc[Python] *** xref:reference/extensions/qdrant.adoc[Qdrant] *** xref:reference/extensions/quartz.adoc[Quartz] *** xref:reference/extensions/quickfix.adoc[QuickFix] diff --git a/docs/modules/ROOT/pages/reference/extensions/python.adoc b/docs/modules/ROOT/pages/reference/extensions/python.adoc new file mode 100644 index 000000000000..236633415a78 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/python.adoc @@ -0,0 +1,45 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-python"] += Python +:linkattrs: +:cq-artifact-id: camel-quarkus-python +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Evaluates a Python expression. +:cq-deprecated: false +:cq-jvm-since: 3.14.0 +:cq-native-since: 3.14.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.14.0## [.badge-key]##Native since##[.badge-supported]##3.14.0## +endif::[] + +Evaluates a Python expression. + +[id="extensions-python-whats-inside"] +== What's inside + +* xref:{cq-camel-components}:languages:python-language.adoc[Python language] + +Please refer to the above link for usage and configuration details. + +[id="extensions-python-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-python[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- + + org.apache.camel.quarkus + camel-quarkus-python + +---- +ifeval::[{doc-show-user-guide-link} == true] +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. +endif::[] diff --git a/extensions/pom.xml b/extensions/pom.xml index 88d4bf0b14c7..cb8b717993c9 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -210,6 +210,7 @@ platform-http protobuf pubnub + python qdrant quartz qute diff --git a/extensions/python/deployment/pom.xml b/extensions/python/deployment/pom.xml new file mode 100644 index 000000000000..b5833caa819a --- /dev/null +++ b/extensions/python/deployment/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-python-parent + 3.14.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-python-deployment + Camel Quarkus :: Python :: Deployment + + + + org.apache.camel.quarkus + camel-quarkus-core-deployment + + + org.apache.camel.quarkus + camel-quarkus-python + + + org.apache.camel.quarkus + camel-quarkus-support-language-deployment + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + diff --git a/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonCompiledExpressionBuildItem.java b/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonCompiledExpressionBuildItem.java new file mode 100644 index 000000000000..dcaa3181b3b5 --- /dev/null +++ b/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonCompiledExpressionBuildItem.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.deployment; + +import io.quarkus.builder.item.MultiBuildItem; +import org.python.core.PyCode; + +public final class PythonCompiledExpressionBuildItem extends MultiBuildItem { + + private final String sourceCode; + + private final PyCode compiledCode; + + public PythonCompiledExpressionBuildItem(String sourceCode, PyCode compiledCode) { + this.sourceCode = sourceCode; + this.compiledCode = compiledCode; + } + + public String getSourceCode() { + return sourceCode; + } + + public PyCode getCompiledCode() { + return compiledCode; + } +} diff --git a/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonProcessor.java b/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonProcessor.java new file mode 100644 index 000000000000..4cdc4fa2a373 --- /dev/null +++ b/extensions/python/deployment/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonProcessor.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.deployment; + +import java.util.List; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.ExecutionTime; +import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; +import io.quarkus.runtime.RuntimeValue; +import org.apache.camel.ExpressionIllegalSyntaxException; +import org.apache.camel.language.python.PythonLanguage; +import org.apache.camel.quarkus.component.python.PythonExpressionRecorder; +import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem; +import org.apache.camel.quarkus.support.language.deployment.ExpressionBuildItem; +import org.apache.camel.quarkus.support.language.deployment.ExpressionExtractionResultBuildItem; +import org.apache.camel.quarkus.support.language.deployment.ScriptBuildItem; +import org.python.core.PyCode; +import org.python.util.PythonInterpreter; + +class PythonProcessor { + + private static final String FEATURE = "camel-python"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) + void compileExpressions(ExpressionExtractionResultBuildItem result, + List expressions, + List scripts, + BuildProducer producer) { + if (result.isSuccess()) { + List pythonExpressions = expressions.stream() + .filter(exp -> "python".equals(exp.getLanguage())).toList(); + List pythonScripts = scripts.stream() + .filter(exp -> "python".equals(exp.getLanguage())).toList(); + if (pythonExpressions.isEmpty() && pythonScripts.isEmpty()) { + return; + } + + try (PythonInterpreter compiler = new PythonInterpreter()) { + for (ExpressionBuildItem pythonExpression : pythonExpressions) { + producer.produce(createPythonExpressionBuildItem(compiler, pythonExpression.getExpression())); + } + for (ScriptBuildItem pythonScript : pythonScripts) { + producer.produce(createPythonExpressionBuildItem(compiler, pythonScript.getLoadedContent())); + } + } + } + } + + @Record(ExecutionTime.STATIC_INIT) + @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) + CamelBeanBuildItem configureLanguage( + PythonExpressionRecorder recorder, + ExpressionExtractionResultBuildItem result, + List sources) { + + if (result.isSuccess() && !sources.isEmpty()) { + RuntimeValue builder = recorder.languageBuilder(); + for (PythonCompiledExpressionBuildItem source : sources) { + recorder.addScript( + builder, + source.getSourceCode(), + source.getCompiledCode()); + } + final RuntimeValue language = recorder.languageNewInstance(builder); + return new CamelBeanBuildItem("python", PythonLanguage.class.getName(), language); + } + return null; + } + + private PythonCompiledExpressionBuildItem createPythonExpressionBuildItem(PythonInterpreter compiler, String expression) { + PyCode compiledExpression; + try { + compiledExpression = compiler.compile(expression); + } catch (Exception e) { + throw new ExpressionIllegalSyntaxException(expression, e); + } + return new PythonCompiledExpressionBuildItem(expression, compiledExpression); + } +} diff --git a/extensions/python/pom.xml b/extensions/python/pom.xml new file mode 100644 index 000000000000..a24b6d3f939f --- /dev/null +++ b/extensions/python/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-extensions + 3.14.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-python-parent + Camel Quarkus :: Python + pom + + + deployment + runtime + + diff --git a/extensions/python/runtime/pom.xml b/extensions/python/runtime/pom.xml new file mode 100644 index 000000000000..dad80de6b7c3 --- /dev/null +++ b/extensions/python/runtime/pom.xml @@ -0,0 +1,106 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-python-parent + 3.14.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-python + Camel Quarkus :: Python :: Runtime + Evaluates a Python expression. + + + 3.14.0 + 3.14.0 + python + + + + + org.apache.camel.quarkus + camel-quarkus-core + + + org.apache.camel.quarkus + camel-quarkus-support-language + + + org.apache.camel + camel-python + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + + + + full + + + !quickly + + + + + + org.apache.camel.quarkus + camel-quarkus-maven-plugin + + + update-extension-doc-page + + update-extension-doc-page + + process-classes + + + + + + + + diff --git a/extensions/python/runtime/src/main/java/org/apache/camel/quarkus/component/python/PythonExpressionRecorder.java b/extensions/python/runtime/src/main/java/org/apache/camel/quarkus/component/python/PythonExpressionRecorder.java new file mode 100644 index 000000000000..67b4e598712c --- /dev/null +++ b/extensions/python/runtime/src/main/java/org/apache/camel/quarkus/component/python/PythonExpressionRecorder.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.language.python.PythonLanguage; +import org.python.core.PyCode; + +@Recorder +public class PythonExpressionRecorder { + + public RuntimeValue languageBuilder() { + return new RuntimeValue<>(new PythonLanguage.Builder()); + } + + @SuppressWarnings("unchecked") + public void addScript(RuntimeValue builder, String script, PyCode compiledScript) { + builder.getValue().addScript(script, compiledScript); + } + + public RuntimeValue languageNewInstance(RuntimeValue builder) { + return new RuntimeValue<>(builder.getValue().build()); + } +} diff --git a/extensions/python/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/python/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 000000000000..c0b0d93a72dd --- /dev/null +++ b/extensions/python/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,34 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel Python" +description: "Evaluates a Python expression" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + keywords: + - "python" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/python.html" + categories: + - "integration" + status: + - "stable" diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index be12657f09f2..6949425c2fb8 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -199,6 +199,7 @@ platform-http-proxy-ssl protobuf pubnub + python qdrant quartz quartz-clustered diff --git a/integration-tests/python/pom.xml b/integration-tests/python/pom.xml new file mode 100644 index 000000000000..6c16cb235c5e --- /dev/null +++ b/integration-tests/python/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-build-parent-it + 3.14.0-SNAPSHOT + ../../poms/build-parent-it/pom.xml + + + camel-quarkus-integration-test-python + Camel Quarkus :: Integration Tests :: Python + Integration tests for Camel Quarkus Python extension + + + + org.apache.camel.quarkus + camel-quarkus-python + + + io.quarkus + quarkus-resteasy + + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + native + + + native + + + + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + virtualDependencies + + + !noVirtualDependencies + + + + + + org.apache.camel.quarkus + camel-quarkus-python-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + diff --git a/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonResource.java b/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonResource.java new file mode 100644 index 000000000000..12154dcd179a --- /dev/null +++ b/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonResource.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.it; + +import java.util.AbstractMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.UriInfo; +import org.apache.camel.ProducerTemplate; + +@Path("/python") +@ApplicationScoped +public class PythonResource { + + @Inject + ProducerTemplate producerTemplate; + + @POST + @Path("/hello") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String hello(String message) { + return producerTemplate.requestBody("direct:pythonHello", message, String.class); + } + + @POST + @Path("/multiplyByTwo") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String hi(String message) { + return producerTemplate.requestBody("direct:pythonMultiplyByTwo", message, String.class); + } + + @POST + @Path("/predicate") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String predicate(String message) { + return producerTemplate.requestBody("direct:predicate", Integer.valueOf(message), String.class); + } + + @Path("/route/{route}") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String route(String statement, @PathParam("route") String route, @Context UriInfo uriInfo) { + final Map headers = uriInfo.getQueryParameters().entrySet().stream() + .map(e -> new AbstractMap.SimpleImmutableEntry(e.getKey(), e.getValue().get(0))) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + return producerTemplate.requestBodyAndHeaders("direct:" + route, statement, headers, String.class); + } + +} diff --git a/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonRoutes.java b/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonRoutes.java new file mode 100644 index 000000000000..2f7c87ffc2fe --- /dev/null +++ b/integration-tests/python/src/main/java/org/apache/camel/quarkus/component/python/it/PythonRoutes.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.it; + +import org.apache.camel.builder.RouteBuilder; + +public class PythonRoutes extends RouteBuilder { + + @Override + public void configure() { + + routeTemplate("pythonMultiplyByTwoTemplate") + .templateBean("myPython", "python", "resource:classpath:script.py") + .from("kamelet:source") + .to("bean:{{myPython}}"); + + from("direct:pythonMultiplyByTwo") + .kamelet("pythonMultiplyByTwoTemplate"); + + from("direct:pythonHello") + .transform().python("\"Hello \" + str(body) + \" from Python!\""); + from("direct:predicate") + .choice() + .when().python("body / 2 > 10") + .setBody().constant("High").endChoice() + .otherwise() + .setBody().constant("Low").endChoice(); + + from("direct:scriptPython") + .script() + .python("exchange.getMessage().setBody('Hello ' + str(exchange.getMessage().getBody()) + ' from Python!')"); + + } +} diff --git a/integration-tests/python/src/main/resources/script.py b/integration-tests/python/src/main/resources/script.py new file mode 100644 index 000000000000..193f253d912f --- /dev/null +++ b/integration-tests/python/src/main/resources/script.py @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +"The result is " + str(body * 2) \ No newline at end of file diff --git a/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonIT.java b/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonIT.java new file mode 100644 index 000000000000..40c941de62c3 --- /dev/null +++ b/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonIT.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class PythonIT extends PythonTest { + +} diff --git a/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonTest.java b/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonTest.java new file mode 100644 index 000000000000..e2b730fce0c2 --- /dev/null +++ b/integration-tests/python/src/test/java/org/apache/camel/quarkus/component/python/it/PythonTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.quarkus.component.python.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.hamcrest.CoreMatchers; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; + +@QuarkusTest +class PythonTest { + + @Test + void pythonHello() { + RestAssured.given() + .body("Will Smith") + .post("/python/hello") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hello Will Smith from Python!")); + } + + @Test + void pythonMultiplyByTwo() { + RestAssured.given() + .body(32767) + .post("/python/multiplyByTwo") + .then() + .statusCode(200) + .body(CoreMatchers.is("The result is 65534")); + } + + @Test + void pythonHigh() { + RestAssured.given() + .body("45") + .post("/python/predicate") + .then() + .statusCode(200) + .body(CoreMatchers.is("High")); + } + + @Test + void pythonLow() { + RestAssured.given() + .body("13") + .post("/python/predicate") + .then() + .statusCode(200) + .body(CoreMatchers.is("Low")); + } + + @Test + void script() { + RestAssured.given() + .contentType(ContentType.TEXT) + .body(32767) + .post("/python/route/scriptPython") + .then() + .statusCode(200) + .body(Matchers.is("Hello 32767 from Python!")); + } +} diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 43c42f3f2305..05b61efb968f 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -2289,6 +2289,11 @@ + + org.apache.camel + camel-python + ${camel.version} + org.apache.camel camel-qdrant @@ -5270,6 +5275,16 @@ camel-quarkus-pulsar-deployment ${camel-quarkus.version} + + org.apache.camel.quarkus + camel-quarkus-python + ${camel-quarkus.version} + + + org.apache.camel.quarkus + camel-quarkus-python-deployment + ${camel-quarkus.version} + org.apache.camel.quarkus camel-quarkus-qdrant diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index d1fe941f675c..d6332b695791 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -2226,6 +2226,11 @@ + + org.apache.camel + camel-python + 4.8.0-SNAPSHOT + org.apache.camel camel-qdrant @@ -5195,6 +5200,16 @@ camel-quarkus-pulsar-deployment 3.14.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-python + 3.14.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-python-deployment + 3.14.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-qdrant diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index d62e379f5a35..eed0b79dc516 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -2226,6 +2226,11 @@ + + org.apache.camel + camel-python + 4.8.0-SNAPSHOT + org.apache.camel camel-qdrant @@ -5195,6 +5200,16 @@ camel-quarkus-pulsar-deployment 3.14.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-python + 3.14.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-python-deployment + 3.14.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-qdrant diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 08edc09b4351..4a01fe4d62d7 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -2226,6 +2226,11 @@ + + org.apache.camel + camel-python + 4.8.0-SNAPSHOT + org.apache.camel camel-qdrant @@ -5195,6 +5200,16 @@ camel-quarkus-pulsar-deployment 3.14.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-python + 3.14.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-python-deployment + 3.14.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-qdrant diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 99a8eebcf1ee..70743b17bd61 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -182,6 +182,7 @@ group-10: - microprofile-health - platform-http-proxy - platform-http-proxy-ssl + - python - swift group-11: - compression-grouped