This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 9e3bb40 Added native support for Kudu extension #1097 9e3bb40 is described below commit 9e3bb403252e84b9f82dff3f758fd01d871b74e8 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Thu Apr 16 10:45:48 2020 +0200 Added native support for Kudu extension #1097 --- .github/workflows/pr-build.yaml | 5 +- .../pages/list-of-camel-quarkus-extensions.adoc | 4 +- .../quarkus/component/kudu/it/KuduResource.java | 51 --------- extensions-jvm/pom.xml | 1 - .../kudu/deployment/pom.xml | 0 .../component/kudu/deployment/KuduProcessor.java | 18 +--- {extensions-jvm => extensions}/kudu/pom.xml | 1 - .../kudu/runtime/pom.xml | 0 .../main/resources/META-INF/quarkus-extension.yaml | 7 +- extensions/pom.xml | 1 + .../kudu}/pom.xml | 70 +++++++++++- .../kudu/it/KuduInfrastructureTestHelper.java | 85 +++++++++++++++ .../quarkus/component/kudu/it/KuduResource.java | 95 +++++++++++++++++ .../camel/quarkus/component/kudu/it/KuduRoute.java | 22 ++-- .../kudu/src/main/resources/application.properties | 18 ++++ .../kudu/src/main/resources/reflection-config.json | 10 ++ .../camel/quarkus/component/kudu/it/KuduIT.java | 18 +--- .../camel/quarkus/component/kudu/it/KuduTest.java | 95 +++++++++++++++++ .../component/kudu/it/KuduTestResource.java | 118 +++++++++++++++++++++ integration-tests/pom.xml | 1 + 20 files changed, 516 insertions(+), 104 deletions(-) diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index c1ceb75..a9412d6 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -110,7 +110,7 @@ jobs: strategy: fail-fast: false matrix: - category: [Core, Foundation, Platform, Messaging, Dataformats, Networking, SQL, Cloud, Misc, SAAS, Social, Validation, Memoryhog Dozer, Memoryhog Dataformat JSON, Memoryhog Infinispan, Memoryhog Olingo4, Memoryhog XML] + category: [Core, Foundation, Platform, Messaging, Dataformats, Networking, Database, Cloud, Misc, SAAS, Social, Validation, Memoryhog Dozer, Memoryhog Dataformat JSON, Memoryhog Infinispan, Memoryhog Olingo4, Memoryhog XML] include: - category: Cloud test-modules: > @@ -206,11 +206,12 @@ jobs: sap-netweaver servicenow slack - - category: SQL + - category: Database test-modules: > couchdb influxdb jdbc + kudu mongodb sql - category: Social diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 36a32d3..c1a7af4 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -410,8 +410,8 @@ Level | Since | Description Stable | 1.0.0-M6 | The Kubernetes Services component provides a producer to execute service operations and a consumer to consume service events. | link:https://camel.apache.org/components/latest/kudu-component.html[Kudu] (camel-quarkus-kudu) + -`kudu:host:port/tableName` | JVM + - Preview | 1.0.0-M6 | Represents a Kudu endpoint. A kudu endpoint allows you to interact with Apache Kudu, a free and open source column-oriented data store of the Apache Hadoop ecosystem. +`kudu:host:port/tableName` | Native + + Stable | 1.0.0-M6 | Represents a Kudu endpoint. A kudu endpoint allows you to interact with Apache Kudu, a free and open source column-oriented data store of the Apache Hadoop ecosystem. | link:https://camel.apache.org/components/latest/log-component.html[Log] (camel-quarkus-log) + `log:loggerName` | Native + diff --git a/extensions-jvm/kudu/integration-test/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java b/extensions-jvm/kudu/integration-test/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java deleted file mode 100644 index f07dfdb..0000000 --- a/extensions-jvm/kudu/integration-test/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.kudu.it; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.camel.CamelContext; -import org.jboss.logging.Logger; - -@Path("/kudu") -@ApplicationScoped -public class KuduResource { - - private static final Logger LOG = Logger.getLogger(KuduResource.class); - - private static final String COMPONENT_KUDU = "kudu"; - @Inject - CamelContext context; - - @Path("/load/component/kudu") - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response loadComponentKudu() throws Exception { - /* This is an autogenerated test */ - if (context.getComponent(COMPONENT_KUDU) != null) { - return Response.ok().build(); - } - LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_KUDU); - return Response.status(500, COMPONENT_KUDU + " could not be loaded from the Camel context").build(); - } -} diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml index afbd18c..d0e5d2e 100644 --- a/extensions-jvm/pom.xml +++ b/extensions-jvm/pom.xml @@ -58,7 +58,6 @@ <module>google-pubsub</module> <module>groovy</module> <module>grpc</module> - <module>kudu</module> <module>mongodb-gridfs</module> <module>nitrite</module> <module>ognl</module> diff --git a/extensions-jvm/kudu/deployment/pom.xml b/extensions/kudu/deployment/pom.xml similarity index 100% rename from extensions-jvm/kudu/deployment/pom.xml rename to extensions/kudu/deployment/pom.xml diff --git a/extensions-jvm/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java b/extensions/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java similarity index 62% rename from extensions-jvm/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java rename to extensions/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java index 5678d54..d130641 100644 --- a/extensions-jvm/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java +++ b/extensions/kudu/deployment/src/main/java/org/apache/camel/quarkus/component/kudu/deployment/KuduProcessor.java @@ -17,15 +17,10 @@ package org.apache.camel.quarkus.component.kudu.deployment; import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.ExecutionTime; -import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; -import io.quarkus.deployment.pkg.steps.NativeBuild; -import org.apache.camel.quarkus.core.JvmOnlyRecorder; -import org.jboss.logging.Logger; class KuduProcessor { - private static final Logger LOG = Logger.getLogger(KuduProcessor.class); private static final String FEATURE = "camel-kudu"; @@ -34,14 +29,9 @@ class KuduProcessor { return new FeatureBuildItem(FEATURE); } - /** - * Remove this once this extension starts supporting the native mode. - */ - @BuildStep(onlyIf = NativeBuild.class) - @Record(value = ExecutionTime.RUNTIME_INIT) - void warnJvmInNative(JvmOnlyRecorder recorder) { - JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time - recorder.warnJvmInNative(FEATURE); // warn at runtime + @BuildStep + ExtensionSslNativeSupportBuildItem activateSslNativeSupport() { + return new ExtensionSslNativeSupportBuildItem(FEATURE); } } diff --git a/extensions-jvm/kudu/pom.xml b/extensions/kudu/pom.xml similarity index 97% rename from extensions-jvm/kudu/pom.xml rename to extensions/kudu/pom.xml index aed5d9c..653a81a 100644 --- a/extensions-jvm/kudu/pom.xml +++ b/extensions/kudu/pom.xml @@ -33,6 +33,5 @@ <modules> <module>deployment</module> <module>runtime</module> - <module>integration-test</module> </modules> </project> diff --git a/extensions-jvm/kudu/runtime/pom.xml b/extensions/kudu/runtime/pom.xml similarity index 100% rename from extensions-jvm/kudu/runtime/pom.xml rename to extensions/kudu/runtime/pom.xml diff --git a/extensions-jvm/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml similarity index 75% rename from extensions-jvm/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml rename to extensions/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 0d556d2..7e9b1e3 100644 --- a/extensions-jvm/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/kudu/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -17,14 +17,13 @@ --- name: "Kudu" -description: "Represents a Kudu endpoint. A kudu endpoint allows you to interact with Apache Kudu, a free and open source column-oriented data store of the Apache Hadoop ecosystem." +description: "Offer interaction with Apache Kudu, a free and open source column-oriented data store of the Apache Hadoop ecosystem." metadata: - unlisted: true keywords: + - "camel" - "cloud" - "database" - "iot" - guide: "https://camel.apache.org/components/latest/kudu-component.html" + guide: "https://quarkus.io/guides/camel" categories: - "integration" - status: "preview" diff --git a/extensions/pom.xml b/extensions/pom.xml index b584348..cc8e207 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -98,6 +98,7 @@ <module>kafka</module> <module>kotlin</module> <module>kubernetes</module> + <module>kudu</module> <module>log</module> <module>lzf</module> <module>mail</module> diff --git a/extensions-jvm/kudu/integration-test/pom.xml b/integration-tests/kudu/pom.xml similarity index 57% rename from extensions-jvm/kudu/integration-test/pom.xml rename to integration-tests/kudu/pom.xml index c222513..8f25e57 100644 --- a/extensions-jvm/kudu/integration-test/pom.xml +++ b/integration-tests/kudu/pom.xml @@ -21,12 +21,12 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-kudu-parent</artifactId> + <artifactId>camel-quarkus-integration-tests</artifactId> <version>1.1.0-SNAPSHOT</version> </parent> - <artifactId>camel-quarkus-kudu-integration-test</artifactId> - <name>Camel Quarkus :: Kudu :: Integration Test</name> + <artifactId>camel-quarkus-integration-test-kudu</artifactId> + <name>Camel Quarkus :: Integration Test :: Kudu</name> <description>Integration tests for Camel Quarkus Kudu extension</description> <properties> @@ -39,14 +39,38 @@ <mvnd.builder.rule>camel-quarkus-kudu-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule> </properties> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-test</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-kudu</artifactId> </dependency> <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-resteasy</artifactId> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bean</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-commons-logging</artifactId> </dependency> <!-- test dependencies --> @@ -60,6 +84,13 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + + <!-- test dependencies - camel-quarkus --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-testcontainers-support</artifactId> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -77,4 +108,33 @@ </plugin> </plugins> </build> + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> diff --git a/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java new file mode 100644 index 0000000..cb45f8b --- /dev/null +++ b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduInfrastructureTestHelper.java @@ -0,0 +1,85 @@ +/* + * 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.kudu.it; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.InetAddress; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; + +import io.quarkus.runtime.StartupEvent; +import org.jboss.logging.Logger; + +/** + * In order to run Kudu integration tests, {@KuduResource}, {@code KuduTest} and {@code KuduIT} should have access to: + * 1) A Kudu master server needed to create a table and also to obtain the host/port of the associated tablet server + * 2) A Kudu tablet server needed to insert and scan records + * + * As such, one solution could be to use a custom setup where Kudu servers run on the same network than integration + * tests. Please note that Kudu servers are not able to run on Windows machine. + * Another solution could be to use the container based setup where Kudu servers are managed by + * {@code KuduTestResource}. + * + * A) How to run integration tests against a custom setup: + * Comment @Disabled and @DisabledOnNativeImage annotations from {@code KuduTest} and {@code KuduIT}. + * Install Kudu master and tablet servers on the same network than integration tests. + * Configure "camel.kudu.test.master.rpc-authority" in "application.properties", for instance: + * camel.kudu.test.master.rpc-authority=kudu-master-hostname:7051 + * Run integration tests with mvn clean integration-test -P native + * + * B) How to run integration tests against the container based setup when NOT running on top of OpenJDK 8: + * Comment @Disabled and @DisabledOnNativeImage annotations from {@code KuduTest} and {@code KuduIT}. + * Override the ip resolution of the host "kudu-tserver" to 127.0.0.1, e.g. by adding an entry in /etc/hosts file as + * below: + * 127.0.0.1 kudu-tserver + * Run integration tests with mvn clean integration-test -P native + * + * C) How to run integration tests against the container based setup when running on top of OpenJDK 8: + * Comment @Disabled and @DisabledOnNativeImage annotations from {@code KuduTest} and {@code KuduIT}. + * No extra setup is needed as {@code overrideKuduTabletServerResolutionInInetAddressCache} takes care of redirecting + * the Kudu tablet server traffic toward localhost + * Run integration tests with mvn clean integration-test -P native + */ +@ApplicationScoped +public class KuduInfrastructureTestHelper { + + private static final Logger LOG = Logger.getLogger(KuduInfrastructureTestHelper.class); + static final String KUDU_TABLET_SERVER_HOSTNAME = "kudu-tserver"; + public static final String KUDU_AUTHORITY_CONFIG_KEY = "camel.kudu.test.master.rpc-authority"; + + void onStart(@Observes StartupEvent ev) { + LOG.info("Attempting to override the kudu tablet server hostname resolution on application startup"); + KuduInfrastructureTestHelper.overrideTabletServerHostnameResolution(); + } + + public static void overrideTabletServerHostnameResolution() { + try { + Field field = InetAddress.class.getDeclaredField("addressCache"); + field.setAccessible(true); + Object addressCache = field.get(null); + + Method put = addressCache.getClass().getMethod("put", String.class, InetAddress[].class); + put.setAccessible(true); + put.invoke(addressCache, KUDU_TABLET_SERVER_HOSTNAME, (Object[]) InetAddress.getAllByName("localhost")); + } catch (Exception ex) { + final String msg = "Can't override the kudu tablet server hostname resolution when not running on top of OpenJDK 8"; + LOG.error(msg, ex); + } + } +} diff --git a/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java new file mode 100644 index 0000000..43fe826 --- /dev/null +++ b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduResource.java @@ -0,0 +1,95 @@ +/* + * 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.kudu.it; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.core.Response; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.kudu.KuduConstants; +import org.apache.kudu.ColumnSchema; +import org.apache.kudu.Schema; +import org.apache.kudu.Type; +import org.apache.kudu.client.CreateTableOptions; +import org.apache.kudu.client.KuduException; +import org.jboss.logging.Logger; + +@Path("/kudu") +@ApplicationScoped +public class KuduResource { + + private static final Logger LOG = Logger.getLogger(KuduResource.class); + + @Inject + CamelContext camelContext; + + @Inject + ProducerTemplate producerTemplate; + + @Path("/createTable") + @PUT + public Response createTable() { + LOG.info("Calling createTable"); + + final List<ColumnSchema> columns = new ArrayList<>(2); + columns.add(new ColumnSchema.ColumnSchemaBuilder("id", Type.STRING).key(true).build()); + columns.add(new ColumnSchema.ColumnSchemaBuilder("name", Type.STRING).build()); + + CreateTableOptions cto = new CreateTableOptions().setRangePartitionColumns(Arrays.asList("id")).setNumReplicas(1); + + final Map<String, Object> headers = new HashMap<>(); + headers.put(KuduConstants.CAMEL_KUDU_SCHEMA, new Schema(columns)); + headers.put(KuduConstants.CAMEL_KUDU_TABLE_OPTIONS, cto); + + producerTemplate.requestBodyAndHeaders("direct:create_table", null, headers); + + return Response.ok().build(); + } + + @Path("/insert") + @PUT + public Response insert() { + LOG.info("Calling insert"); + + Map<String, Object> row = new HashMap<>(); + row.put("id", "key1"); + row.put("name", "Samuel"); + + producerTemplate.requestBody("direct:insert", row); + + return Response.ok().build(); + } + + @Path("/scan") + @GET + public String scan() throws KuduException { + LOG.info("Calling scan"); + return producerTemplate.requestBody("direct:scan", (Object) null, String.class); + } + +} diff --git a/extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduRoute.java similarity index 57% copy from extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java copy to integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduRoute.java index c0cb41e..64e839d 100644 --- a/extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java +++ b/integration-tests/kudu/src/main/java/org/apache/camel/quarkus/component/kudu/it/KuduRoute.java @@ -16,19 +16,19 @@ */ package org.apache.camel.quarkus.component.kudu.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import org.apache.camel.builder.RouteBuilder; -@QuarkusTest -class KuduTest { +import static org.apache.camel.quarkus.component.kudu.it.KuduInfrastructureTestHelper.KUDU_AUTHORITY_CONFIG_KEY; - @Test - public void loadComponentKudu() { - /* A simple autogenerated test */ - RestAssured.get("/kudu/load/component/kudu") - .then() - .statusCode(200); +public class KuduRoute extends RouteBuilder { + + @Override + public void configure() { + final String kuduEndpointUriFormat = "kudu:{{" + KUDU_AUTHORITY_CONFIG_KEY + "}}/TestTable?operation=%s"; + + from("direct:create_table").toF(kuduEndpointUriFormat, "create_table"); + from("direct:insert").toF(kuduEndpointUriFormat, "insert"); + from("direct:scan").toF(kuduEndpointUriFormat, "scan").setBody(simple("${body[0][id]}/${body[0][name]}")); } } diff --git a/integration-tests/kudu/src/main/resources/application.properties b/integration-tests/kudu/src/main/resources/application.properties new file mode 100644 index 0000000..f7c39d5 --- /dev/null +++ b/integration-tests/kudu/src/main/resources/application.properties @@ -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. +## --------------------------------------------------------------------------- +# Needed for integration tests infrastructure purpose only, please have a look at KuduInfrastructureTestHelper +quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json \ No newline at end of file diff --git a/integration-tests/kudu/src/main/resources/reflection-config.json b/integration-tests/kudu/src/main/resources/reflection-config.json new file mode 100644 index 0000000..7281bba --- /dev/null +++ b/integration-tests/kudu/src/main/resources/reflection-config.json @@ -0,0 +1,10 @@ +[ + { + "name" : "java.net.InetAddress", + "allDeclaredFields" : true + }, + { + "name" : "java.net.InetAddress$Cache", + "allDeclaredMethods" : true + } +] \ No newline at end of file diff --git a/extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduIT.java similarity index 71% rename from extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java rename to integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduIT.java index c0cb41e..7cc22f6 100644 --- a/extensions-jvm/kudu/integration-test/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java +++ b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduIT.java @@ -16,19 +16,11 @@ */ package org.apache.camel.quarkus.component.kudu.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import io.quarkus.test.junit.DisabledOnNativeImage; +import io.quarkus.test.junit.NativeImageTest; -@QuarkusTest -class KuduTest { - - @Test - public void loadComponentKudu() { - /* A simple autogenerated test */ - RestAssured.get("/kudu/load/component/kudu") - .then() - .statusCode(200); - } +@NativeImageTest +@DisabledOnNativeImage("Manual setup could be needed, please look at KuduInfrastructureTestHelper") +class KuduIT extends KuduTest { } diff --git a/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java new file mode 100644 index 0000000..003d209 --- /dev/null +++ b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTest.java @@ -0,0 +1,95 @@ +/* + * 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.kudu.it; + +import java.util.List; +import java.util.Map; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.camel.component.kudu.KuduUtils; +import org.apache.kudu.client.KuduClient; +import org.apache.kudu.client.KuduException; +import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.logging.Logger; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import static org.apache.camel.quarkus.component.kudu.it.KuduInfrastructureTestHelper.KUDU_AUTHORITY_CONFIG_KEY; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@QuarkusTestResource(KuduTestResource.class) +@QuarkusTest +@TestMethodOrder(OrderAnnotation.class) +@Disabled("Manual setup could be needed, please look at KuduInfrastructureTestHelper") +class KuduTest { + + private static final Logger LOG = Logger.getLogger(KuduTest.class); + static String MASTER_RPC_AUTHORITY; + + @BeforeAll + static void setup() { + MASTER_RPC_AUTHORITY = ConfigProvider.getConfig().getValue(KUDU_AUTHORITY_CONFIG_KEY, String.class); + KuduInfrastructureTestHelper.overrideTabletServerHostnameResolution(); + } + + @Order(1) + @Test + public void createTableShouldSucceed() throws KuduException { + LOG.info("Calling createTableShouldSucceed"); + + KuduClient client = new KuduClient.KuduClientBuilder(MASTER_RPC_AUTHORITY).build(); + assertEquals(0, client.getTablesList().getTablesList().size()); + + RestAssured.put("/kudu/createTable").then().statusCode(200); + + assertEquals(1, client.getTablesList().getTablesList().size()); + } + + @Order(2) + @Test + public void insertShouldSucceed() throws KuduException { + LOG.info("Calling insertShouldSucceed"); + + RestAssured.put("/kudu/insert").then().statusCode(200); + + KuduClient client = new KuduClient.KuduClientBuilder(MASTER_RPC_AUTHORITY).build(); + + List<Map<String, Object>> records = KuduUtils.doScan("TestTable", client); + assertEquals(1, records.size()); + Map<String, Object> record = records.get(0); + assertNotNull(record); + assertEquals("key1", record.get("id")); + assertEquals("Samuel", record.get("name")); + } + + @Order(3) + @Test + public void scanShouldSucceed() { + LOG.info("Calling scanShouldSucceed"); + + String record = RestAssured.get("/kudu/scan").then().statusCode(200).extract().asString(); + assertEquals("key1/Samuel", record); + } + +} diff --git a/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTestResource.java b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTestResource.java new file mode 100644 index 0000000..2155467 --- /dev/null +++ b/integration-tests/kudu/src/test/java/org/apache/camel/quarkus/component/kudu/it/KuduTestResource.java @@ -0,0 +1,118 @@ +/* + * 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.kudu.it; + +import java.util.Map; +import java.util.function.Consumer; + +import com.github.dockerjava.api.command.CreateContainerCmd; +import com.github.dockerjava.api.model.ExposedPort; +import com.github.dockerjava.api.model.HostConfig; +import com.github.dockerjava.api.model.Ports; +import org.apache.camel.quarkus.testcontainers.ContainerResourceLifecycleManager; +import org.apache.camel.util.CollectionHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.TestcontainersConfiguration; + +import static org.apache.camel.quarkus.component.kudu.it.KuduInfrastructureTestHelper.KUDU_AUTHORITY_CONFIG_KEY; + +public class KuduTestResource implements ContainerResourceLifecycleManager { + private static final Logger LOG = LoggerFactory.getLogger(KuduTestResource.class); + private static final int KUDU_MASTER_RPC_PORT = 7051; + private static final int KUDU_MASTER_HTTP_PORT = 8051; + private static final int KUDU_TABLET_RPC_PORT = 7050; + private static final int KUDU_TABLET_HTTP_PORT = 8050; + private static final String KUDU_IMAGE = "apache/kudu:1.9.0"; + private static final String KUDU_MASTER_NETWORK_ALIAS = "kudu-master"; + private static final String KUDU_TABLET_NETWORK_ALIAS = KuduInfrastructureTestHelper.KUDU_TABLET_SERVER_HOSTNAME; + + private GenericContainer masterContainer, tabletContainer; + + @Override + public Map<String, String> start() { + LOG.info(TestcontainersConfiguration.getInstance().toString()); + + try { + Network kuduNetwork = Network.newNetwork(); + + // Setup the Kudu master server container + masterContainer = new GenericContainer(KUDU_IMAGE).withCommand("master") + .withExposedPorts(KUDU_MASTER_RPC_PORT, KUDU_MASTER_HTTP_PORT).withNetwork(kuduNetwork) + .withNetworkAliases(KUDU_MASTER_NETWORK_ALIAS); + masterContainer = masterContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort()); + masterContainer.start(); + + // Force host name and port, so that the tablet container is accessible from KuduResource, KuduTest and KuduIT. + Consumer<CreateContainerCmd> consumer = cmd -> { + Ports portBindings = new Ports(); + portBindings.bind(ExposedPort.tcp(KUDU_TABLET_RPC_PORT), Ports.Binding.bindPort(KUDU_TABLET_RPC_PORT)); + portBindings.bind(ExposedPort.tcp(KUDU_TABLET_HTTP_PORT), Ports.Binding.bindPort(KUDU_TABLET_HTTP_PORT)); + HostConfig hostConfig = HostConfig.newHostConfig().withPortBindings(portBindings) + .withNetworkMode(kuduNetwork.getId()); + cmd.withHostName(KUDU_TABLET_NETWORK_ALIAS).withHostConfig(hostConfig); + }; + + // Setup the Kudu tablet server container + tabletContainer = new GenericContainer(KUDU_IMAGE).withCommand("tserver") + .withEnv("KUDU_MASTERS", KUDU_MASTER_NETWORK_ALIAS) + .withExposedPorts(KUDU_TABLET_RPC_PORT, KUDU_TABLET_HTTP_PORT).withNetwork(kuduNetwork) + .withNetworkAliases(KUDU_TABLET_NETWORK_ALIAS).withCreateContainerCmdModifier(consumer); + tabletContainer = tabletContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort()); + tabletContainer.start(); + + // Print interesting Kudu servers connectivity information + final String masterRpcAuthority = masterContainer.getContainerIpAddress() + ":" + + masterContainer.getMappedPort(KUDU_MASTER_RPC_PORT); + LOG.info("Kudu master RPC accessible at " + masterRpcAuthority); + final String masterHttpAuthority = masterContainer.getContainerIpAddress() + ":" + + masterContainer.getMappedPort(KUDU_MASTER_HTTP_PORT); + LOG.info("Kudu master HTTP accessible at " + masterHttpAuthority); + final String tServerRpcAuthority = tabletContainer.getContainerIpAddress() + ":" + + tabletContainer.getMappedPort(KUDU_TABLET_RPC_PORT); + LOG.info("Kudu tablet server RPC accessible at " + tServerRpcAuthority); + final String tServerHttpAuthority = tabletContainer.getContainerIpAddress() + ":" + + tabletContainer.getMappedPort(KUDU_TABLET_HTTP_PORT); + LOG.info("Kudu tablet server HTTP accessible at " + tServerHttpAuthority); + + return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY, masterRpcAuthority); + } catch (Exception ex) { + LOG.error("Issue starting KuduTestResource, please have a look at KuduInfrastructureTestHelper", ex); + return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY, + "Please_have_a_look_at_KuduInfrastructureTestHelper"); + } + } + + @Override + public void stop() { + try { + if (masterContainer != null) { + masterContainer.stop(); + } + if (tabletContainer != null) { + tabletContainer.stop(); + } + } catch (Exception ex) { + LOG.error("An issue occured while stopping the KuduTestResource", ex); + } + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index aa94ba1..0ce8a4b 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -91,6 +91,7 @@ <module>jsonpath</module> <module>kafka</module> <module>kubernetes</module> + <module>kudu</module> <module>mail</module> <module>messaging</module> <module>microprofile</module>