From 3a0909368cc10e41ef9f6a444cbb6e70bd499a37 Mon Sep 17 00:00:00 2001 From: Sandip Gahlot Date: Wed, 28 Jul 2021 10:11:36 -0400 Subject: [PATCH] DBAAS-42: Added support for MongoDB service binding by reading the given mandatory/optional properties (+ tests) and making the correct connection string DBAAS-42: Using correct property for quarkus mongodb connection string. Removed MockitoExtension --- extensions/mongodb-client/deployment/pom.xml | 2 +- .../deployment/MongoClientProcessor.java | 15 +- extensions/mongodb-client/runtime/pom.xml | 19 +- .../runtime/MongoServiceBindingConverter.java | 140 ++++++++++++ ...ce.binding.runtime.ServiceBindingConverter | 1 + .../MongoServiceBindingConverterTest.java | 213 ++++++++++++++++++ .../org.mockito.plugins.MockMaker | 1 + .../service-binding/all-props/database | 1 + .../resources/service-binding/all-props/host | 1 + .../service-binding/all-props/password | 1 + .../resources/service-binding/all-props/port | 1 + .../service-binding/all-props/provider | 1 + .../resources/service-binding/all-props/type | 1 + .../service-binding/all-props/username | 1 + .../service-binding/no-port/database | 1 + .../resources/service-binding/no-port/host | 1 + .../service-binding/no-port/password | 1 + .../service-binding/no-port/provider | 1 + .../resources/service-binding/no-port/type | 1 + .../service-binding/no-port/username | 1 + .../service-binding/no-user/database | 1 + .../resources/service-binding/no-user/host | 1 + .../resources/service-binding/no-user/port | 1 + .../service-binding/no-user/provider | 1 + .../resources/service-binding/no-user/type | 1 + 25 files changed, 406 insertions(+), 3 deletions(-) create mode 100644 extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoServiceBindingConverter.java create mode 100644 extensions/mongodb-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter create mode 100644 extensions/mongodb-client/runtime/src/test/java/io/quarkus/mongodb/runtime/MongoServiceBindingConverterTest.java create mode 100644 extensions/mongodb-client/runtime/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/database create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/host create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/password create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/port create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/provider create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/type create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/all-props/username create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/database create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/host create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/password create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/provider create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/type create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-port/username create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-user/database create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-user/host create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-user/port create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-user/provider create mode 100644 extensions/mongodb-client/runtime/src/test/resources/service-binding/no-user/type diff --git a/extensions/mongodb-client/deployment/pom.xml b/extensions/mongodb-client/deployment/pom.xml index 9def469e33a9f..926c3f95a13c1 100644 --- a/extensions/mongodb-client/deployment/pom.xml +++ b/extensions/mongodb-client/deployment/pom.xml @@ -123,4 +123,4 @@ - + \ No newline at end of file diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java index 3eb4fd9546eb4..700c5173ce642 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientProcessor.java @@ -51,6 +51,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.SslNativeConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.metrics.MetricsCapabilityBuildItem; import io.quarkus.mongodb.MongoClientName; import io.quarkus.mongodb.reactive.ReactiveMongoClient; @@ -58,6 +59,7 @@ import io.quarkus.mongodb.runtime.MongoClientRecorder; import io.quarkus.mongodb.runtime.MongoClientSupport; import io.quarkus.mongodb.runtime.MongoClients; +import io.quarkus.mongodb.runtime.MongoServiceBindingConverter; import io.quarkus.mongodb.runtime.MongodbConfig; import io.quarkus.runtime.metrics.MetricsFactory; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; @@ -69,6 +71,8 @@ public class MongoClientProcessor { private static final DotName MONGO_CLIENT = DotName.createSimple(MongoClient.class.getName()); private static final DotName REACTIVE_MONGO_CLIENT = DotName.createSimple(ReactiveMongoClient.class.getName()); + private static final String SERVICE_BINDING_INTERFACE_NAME = "io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter"; + @BuildStep AdditionalIndexedClassesBuildItem includeBsonTypesToIndex() { return new AdditionalIndexedClassesBuildItem( @@ -371,4 +375,13 @@ HealthBuildItem addHealthCheck(MongoClientBuildTimeConfig buildTimeConfig) { return new HealthBuildItem("io.quarkus.mongodb.health.MongoHealthCheck", buildTimeConfig.healthEnabled); } -} + + @BuildStep + void registerServiceBinding(Capabilities capabilities, BuildProducer buildProducer) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + buildProducer.produce( + new ServiceProviderBuildItem(SERVICE_BINDING_INTERFACE_NAME, + MongoServiceBindingConverter.class.getName())); + } + } +} \ No newline at end of file diff --git a/extensions/mongodb-client/runtime/pom.xml b/extensions/mongodb-client/runtime/pom.xml index 06c4edf05a1ae..47534584f7d90 100644 --- a/extensions/mongodb-client/runtime/pom.xml +++ b/extensions/mongodb-client/runtime/pom.xml @@ -44,6 +44,11 @@ org.mongodb mongodb-crypt + + io.quarkus + quarkus-kubernetes-service-binding + true + @@ -100,6 +105,18 @@ awaitility test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + +