diff --git a/extensions/jdbc/jdbc-db2/runtime/src/main/java/io/quarkus/jdbc/db2/runtime/DB2ServiceBindingConverter.java b/extensions/jdbc/jdbc-db2/runtime/src/main/java/io/quarkus/jdbc/db2/runtime/DB2ServiceBindingConverter.java index 85fb7cfcec8e6..3d182971e9775 100644 --- a/extensions/jdbc/jdbc-db2/runtime/src/main/java/io/quarkus/jdbc/db2/runtime/DB2ServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-db2/runtime/src/main/java/io/quarkus/jdbc/db2/runtime/DB2ServiceBindingConverter.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -12,6 +12,7 @@ public class DB2ServiceBindingConverter implements ServiceBindingConverter { @Override public Optional convert(List serviceBindings) { - return JdbcDatasourceUtil.convert(serviceBindings, "db2"); + return ServiceBinding.singleMatchingByType("db2", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Jdbc()); } } diff --git a/extensions/jdbc/jdbc-mariadb/runtime/src/main/java/io/quarkus/jdbc/mariadb/runtime/MariaDBServiceBindingConverter.java b/extensions/jdbc/jdbc-mariadb/runtime/src/main/java/io/quarkus/jdbc/mariadb/runtime/MariaDBServiceBindingConverter.java index e470fc358d971..79e35b678a1ef 100644 --- a/extensions/jdbc/jdbc-mariadb/runtime/src/main/java/io/quarkus/jdbc/mariadb/runtime/MariaDBServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-mariadb/runtime/src/main/java/io/quarkus/jdbc/mariadb/runtime/MariaDBServiceBindingConverter.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -12,6 +12,15 @@ public class MariaDBServiceBindingConverter implements ServiceBindingConverter { @Override public Optional convert(List serviceBindings) { - return JdbcDatasourceUtil.convert(serviceBindings, "mysql", "mariadb"); + return ServiceBinding.singleMatchingByType("mysql", serviceBindings) + .map(new MariaDBDatasourceServiceBindingConfigSourceFactory()); + } + + private static class MariaDBDatasourceServiceBindingConfigSourceFactory + extends DatasourceServiceBindingConfigSourceFactory.Jdbc { + @Override + protected String formatUrl(String urlFormat, String type, String host, String database, String portPart) { + return super.formatUrl(urlFormat, "mariadb", host, database, portPart); + } } } diff --git a/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/MsSQLServiceBindingConverter.java b/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/MsSQLServiceBindingConverter.java index fca6c6a2626a4..3581833b507ea 100644 --- a/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/MsSQLServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-mssql/runtime/src/main/java/io/quarkus/jdbc/mssql/runtime/MsSQLServiceBindingConverter.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -12,6 +12,7 @@ public class MsSQLServiceBindingConverter implements ServiceBindingConverter { @Override public Optional convert(List serviceBindings) { - return JdbcDatasourceUtil.convert(serviceBindings, "sqlserver"); + return ServiceBinding.singleMatchingByType("sqlserver", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Jdbc()); } } diff --git a/extensions/jdbc/jdbc-mysql/runtime/src/main/java/io/quarkus/jdbc/mysql/runtime/MySQLServiceBindingConverter.java b/extensions/jdbc/jdbc-mysql/runtime/src/main/java/io/quarkus/jdbc/mysql/runtime/MySQLServiceBindingConverter.java index d50d8b5bc2de8..a1d4c86dcce9f 100644 --- a/extensions/jdbc/jdbc-mysql/runtime/src/main/java/io/quarkus/jdbc/mysql/runtime/MySQLServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-mysql/runtime/src/main/java/io/quarkus/jdbc/mysql/runtime/MySQLServiceBindingConverter.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -12,6 +12,7 @@ public class MySQLServiceBindingConverter implements ServiceBindingConverter { @Override public Optional convert(List serviceBindings) { - return JdbcDatasourceUtil.convert(serviceBindings, "mysql"); + return ServiceBinding.singleMatchingByType("mysql", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Jdbc()); } } diff --git a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/OracleServiceBindingConverter.java b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/OracleServiceBindingConverter.java index 6c2188a7171ed..387ab63f67212 100644 --- a/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/OracleServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-oracle/runtime/src/main/java/io/quarkus/jdbc/oracle/runtime/OracleServiceBindingConverter.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -12,7 +12,8 @@ public class OracleServiceBindingConverter implements ServiceBindingConverter { @Override public Optional convert(List serviceBindings) { - return JdbcDatasourceUtil.convert(serviceBindings, "oracle"); + return ServiceBinding.singleMatchingByType("oracle", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Jdbc()); } } diff --git a/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/PostgreSQLServiceBindingConverter.java b/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/PostgreSQLServiceBindingConverter.java index b421da18bfa05..d3be6257fd5d3 100644 --- a/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/PostgreSQLServiceBindingConverter.java +++ b/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/PostgreSQLServiceBindingConverter.java @@ -1,7 +1,5 @@ package io.quarkus.jdbc.postgresql.runtime; -import static io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil.QUARKUS_DATASOURCE_JDBC_URL; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -11,7 +9,7 @@ import java.util.Map; import java.util.Optional; -import io.quarkus.kubernetes.service.binding.runtime.JdbcDatasourceUtil; +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; @@ -25,83 +23,89 @@ public class PostgreSQLServiceBindingConverter implements ServiceBindingConverte @Override public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType(BINDING_TYPE, serviceBindings) + .map(new PostgreSQLDatasourceServiceBindingConfigSourceFactory()); + } - Optional matchingByType = ServiceBinding.singleMatchingByType(BINDING_TYPE, serviceBindings); - if (!matchingByType.isPresent()) { - return Optional.empty(); - } - ServiceBinding binding = matchingByType.get(); - - Map properties = JdbcDatasourceUtil.getServiceBindingProperties(binding, BINDING_TYPE); - //process ssl params - //https://www.postgresql.org/docs/14/libpq-connect.html - StringBuilder sslparam = new StringBuilder(); - String sslmode = binding.getProperties().getOrDefault(SSL_MODE, ""); - String sslRootCert = binding.getProperties().getOrDefault(SSL_ROOT_CERT, ""); - if (!"".equals(sslmode)) { - sslparam.append(SSL_MODE).append("=").append(sslmode); - } - if (!"".equals(sslRootCert)) { + private static class PostgreSQLDatasourceServiceBindingConfigSourceFactory + extends DatasourceServiceBindingConfigSourceFactory.Jdbc { + + @Override + protected String formatUrl(String urlFormat, String type, String host, String database, String portPart) { + String result = super.formatUrl(urlFormat, type, host, database, portPart); + + Map sbProps = serviceBinding.getProperties(); + + //process ssl params + //https://www.postgresql.org/docs/14/libpq-connect.html + StringBuilder sslparam = new StringBuilder(); + String sslmode = sbProps.getOrDefault(SSL_MODE, ""); + String sslRootCert = sbProps.getOrDefault(SSL_ROOT_CERT, ""); if (!"".equals(sslmode)) { - sslparam.append("&"); + sslparam.append(SSL_MODE).append("=").append(sslmode); + } + if (!"".equals(sslRootCert)) { + if (!"".equals(sslmode)) { + sslparam.append("&"); + } + sslparam.append(SSL_ROOT_CERT).append("=") + .append(serviceBinding.getBindingDirectory()).append(FileSystems.getDefault().getSeparator()) + .append(sslRootCert); } - sslparam.append(SSL_ROOT_CERT).append("=") - .append(binding.getBindingDirectory()).append(FileSystems.getDefault().getSeparator()) - .append(sslRootCert); - } - //cockroachdb cloud uses options parameter to pass in the cluster routing-id - //https://www.cockroachlabs.com/docs/v21.2/connection-parameters#additional-connection-parameters - String options = binding.getProperties().getOrDefault(OPTIONS, ""); - String crdbOption = ""; - List postgreOptions = new ArrayList<>(); - if (!options.equals("")) { - String[] allOpts = options.split("&"); - for (String o : allOpts) { - String[] keyval = o.split("="); - if (keyval.length != 2 || keyval[0].length() == 0 || keyval[1].length() == 0) { - continue; + //cockroachdb cloud uses options parameter to pass in the cluster routing-id + //https://www.cockroachlabs.com/docs/v21.2/connection-parameters#additional-connection-parameters + String options = sbProps.getOrDefault(OPTIONS, ""); + String crdbOption = ""; + List postgreOptions = new ArrayList<>(); + if (!options.equals("")) { + String[] allOpts = options.split("&"); + for (String o : allOpts) { + String[] keyval = o.split("="); + if (keyval.length != 2 || keyval[0].length() == 0 || keyval[1].length() == 0) { + continue; + } + if (keyval[0].equals("--cluster")) { + crdbOption = keyval[0] + "=" + keyval[1]; + } else { + postgreOptions.add("-c " + keyval[0] + "=" + keyval[1]); + } } - if (keyval[0].equals("--cluster")) { - crdbOption = keyval[0] + "=" + keyval[1]; + } + + String combinedOptions = crdbOption; + if (postgreOptions.size() > 0) { + String otherOpts = String.join(" ", postgreOptions); + if (!combinedOptions.equals("")) { + combinedOptions = combinedOptions + " " + otherOpts; } else { - postgreOptions.add("-c " + keyval[0] + "=" + keyval[1]); + combinedOptions = otherOpts; } } - } - String combinedOptions = crdbOption; - if (postgreOptions.size() > 0) { - String otherOpts = String.join(" ", postgreOptions); - if (!combinedOptions.equals("")) { - combinedOptions = combinedOptions + " " + otherOpts; - } else { - combinedOptions = otherOpts; + try { + combinedOptions = combinedOptions.length() > 0 ? OPTIONS + "=" + encode(combinedOptions).replace("+", "%20") + : ""; + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException("failed to encode options params" + options, e); } - } - try { - combinedOptions = combinedOptions.length() > 0 ? OPTIONS + "=" + encode(combinedOptions).replace("+", "%20") : ""; - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException("failed to encode options params" + options, e); - } + if (sslparam.length() > 0 && !combinedOptions.equals("")) { + combinedOptions = sslparam + "&" + combinedOptions; + } else if (sslparam.length() > 0) { + combinedOptions = sslparam.toString(); + } - if (sslparam.length() > 0 && !combinedOptions.equals("")) { - combinedOptions = sslparam + "&" + combinedOptions; - } else if (sslparam.length() > 0) { - combinedOptions = sslparam.toString(); - } + if (!"".equals(combinedOptions)) { + //append sslmode and options to the URL + result += "?" + combinedOptions; + } - if (!"".equals(combinedOptions)) { - //append sslmode and options to the URL - properties.put(QUARKUS_DATASOURCE_JDBC_URL, - properties.get(QUARKUS_DATASOURCE_JDBC_URL) + "?" + combinedOptions); + return result; } - return Optional.of(new ServiceBindingConfigSource(BINDING_TYPE + "-k8s-service-binding-source", properties)); - } - - private String encode(String str) throws UnsupportedEncodingException { - return URLEncoder.encode(str, StandardCharsets.UTF_8.toString()); + private String encode(String str) throws UnsupportedEncodingException { + return URLEncoder.encode(str, StandardCharsets.UTF_8.toString()); + } } } diff --git a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java new file mode 100644 index 0000000000000..190e83426e53e --- /dev/null +++ b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java @@ -0,0 +1,82 @@ +package io.quarkus.kubernetes.service.binding.runtime; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import org.jboss.logging.Logger; + +public abstract class DatasourceServiceBindingConfigSourceFactory + implements Function { + + private static final Logger log = Logger.getLogger(DatasourceServiceBindingConfigSourceFactory.class); + + private final String configSourceNamePrefix; + private final String urlPropertyName; + private final String urlFormat; + protected ServiceBinding serviceBinding; + + private DatasourceServiceBindingConfigSourceFactory(String configSourceNamePrefix, String urlPropertyName, + String urlFormat) { + this.configSourceNamePrefix = configSourceNamePrefix; + this.urlPropertyName = urlPropertyName; + this.urlFormat = urlFormat; + } + + @Override + public final ServiceBindingConfigSource apply(ServiceBinding serviceBinding) { + this.serviceBinding = serviceBinding; + String name = configSourceNamePrefix + "-" + serviceBinding.getType() + "-k8s-service-binding-source"; + return new ServiceBindingConfigSource(name, getServiceBindingProperties()); + } + + private Map getServiceBindingProperties() { + Map properties = new HashMap<>(); + Map bindingProperties = serviceBinding.getProperties(); + + String username = bindingProperties.get("username"); + if (username != null) { + properties.put("quarkus.datasource.username", username); + } else { + log.debugf("Property 'username' was not found for datasource of type %s", serviceBinding.getType()); + } + String password = bindingProperties.get("password"); + if (password != null) { + properties.put("quarkus.datasource.password", password); + } else { + log.debugf("Property 'password' was not found for datasource of type %s", serviceBinding.getType()); + } + + String host = bindingProperties.get("host"); + String port = bindingProperties.get("port"); + String database = bindingProperties.get("database"); + if ((host != null) && (database != null)) { + String portPart = ""; + if (port != null) { + portPart = ":" + port; + } + properties.put(urlPropertyName, formatUrl(urlFormat, serviceBinding.getType(), host, database, portPart)); + } else { + log.debugf("One or more of 'host' or 'database' properties were not found for datasource of type %s", + serviceBinding.getType()); + } + + return properties; + } + + protected String formatUrl(String urlFormat, String type, String host, String database, String portPart) { + return String.format(urlFormat, type, host, portPart, database); + } + + public static class Jdbc extends DatasourceServiceBindingConfigSourceFactory { + public Jdbc() { + super("jdbc", "quarkus.datasource.jdbc.url", "jdbc:%s://%s%s/%s"); + } + } + + public static class Reactive extends DatasourceServiceBindingConfigSourceFactory { + public Reactive() { + super("reactive", "quarkus.datasource.reactive.url", "%s://%s%s/%s"); + } + } +} diff --git a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/JdbcDatasourceUtil.java b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/JdbcDatasourceUtil.java deleted file mode 100644 index a5b496c0bafaf..0000000000000 --- a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/JdbcDatasourceUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -package io.quarkus.kubernetes.service.binding.runtime; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.jboss.logging.Logger; - -/** - * This utility collects the conversion of Service types that correspond to JDBC data-sources - * into a single place as the code for all is the same. - * This inevitably results in datasource related logic being places inside this (otherwise) - * service binding agnostic module, but it's a small price to pay compared to the alternative - * of copying and pasting the same code for all JDBC data-sources. - */ -public class JdbcDatasourceUtil { - - private static final Logger log = Logger.getLogger(JdbcDatasourceUtil.class); - - public static final String QUARKUS_DATASOURCE_JDBC_URL = "quarkus.datasource.jdbc.url"; - private static final String QUARKUS_DATASOURCE_USERNAME = "quarkus.datasource.username"; - private static final String QUARKUS_DATASOURCE_PASSWORD = "quarkus.datasource.password"; - - public static Optional convert(List serviceBindings, String type) { - return convert(serviceBindings, type, type); - } - - public static Optional convert(List serviceBindings, String bindingType, - String urlType) { - Optional matchingByType = ServiceBinding.singleMatchingByType(bindingType, serviceBindings); - if (!matchingByType.isPresent()) { - return Optional.empty(); - } - - ServiceBinding binding = matchingByType.get(); - - return Optional.of(new ServiceBindingConfigSource(bindingType + "-k8s-service-binding-source", - getServiceBindingProperties(binding, urlType))); - } - - public static Map getServiceBindingProperties(ServiceBinding binding, String urlType) { - Map properties = new HashMap<>(); - - String username = binding.getProperties().get("username"); - if (username != null) { - properties.put(QUARKUS_DATASOURCE_USERNAME, username); - } else { - log.debug("Property 'username' was not found"); - } - String password = binding.getProperties().get("password"); - if (password != null) { - properties.put(QUARKUS_DATASOURCE_PASSWORD, password); - } else { - log.debug("Property 'password' was not found"); - } - String host = binding.getProperties().get("host"); - String port = binding.getProperties().get("port"); - String database = binding.getProperties().get("database"); - if ((host != null) && (database != null)) { - String portPart = ""; - if (port != null) { - portPart = ":" + port; - } - properties.put(QUARKUS_DATASOURCE_JDBC_URL, - String.format("jdbc:%s://%s%s/%s", urlType, host, portPart, database)); - } else { - log.debug("One or more of 'host' or 'database' properties were not found"); - } - - return properties; - } -} diff --git a/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java b/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java index cf1f721447f8e..ca2b618b18433 100644 --- a/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java +++ b/extensions/reactive-db2-client/deployment/src/main/java/io/quarkus/reactive/db2/client/deployment/ReactiveDB2ClientProcessor.java @@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.reactive.datasource.ReactiveDataSource; import io.quarkus.reactive.datasource.deployment.VertxPoolBuildItem; @@ -33,6 +34,7 @@ import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveBuildTimeConfig; import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveRuntimeConfig; import io.quarkus.reactive.db2.client.runtime.DB2PoolRecorder; +import io.quarkus.reactive.db2.client.runtime.DB2ServiceBindingConverter; import io.quarkus.reactive.db2.client.runtime.DataSourcesReactiveDB2Config; import io.quarkus.runtime.RuntimeValue; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; @@ -87,7 +89,13 @@ DevServicesDatasourceConfigurationHandlerBuildItem devDbHandler() { } @BuildStep - void registerServiceBinding(BuildProducer dbKind) { + void registerServiceBinding(Capabilities capabilities, BuildProducer serviceProvider, + BuildProducer dbKind) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + serviceProvider.produce( + new ServiceProviderBuildItem("io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter", + DB2ServiceBindingConverter.class.getName())); + } dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.DB2)); } diff --git a/extensions/reactive-db2-client/runtime/pom.xml b/extensions/reactive-db2-client/runtime/pom.xml index 599602810dc2e..256b7630fda95 100644 --- a/extensions/reactive-db2-client/runtime/pom.xml +++ b/extensions/reactive-db2-client/runtime/pom.xml @@ -37,6 +37,11 @@ quarkus-smallrye-health true + + io.quarkus + quarkus-kubernetes-service-binding + true + diff --git a/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2ServiceBindingConverter.java b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2ServiceBindingConverter.java new file mode 100644 index 0000000000000..df6d009336452 --- /dev/null +++ b/extensions/reactive-db2-client/runtime/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2ServiceBindingConverter.java @@ -0,0 +1,18 @@ +package io.quarkus.reactive.db2.client.runtime; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; + +public class DB2ServiceBindingConverter implements ServiceBindingConverter { + + @Override + public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType("db2", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Reactive()); + } +} diff --git a/extensions/reactive-db2-client/runtime/src/main/resources/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter b/extensions/reactive-db2-client/runtime/src/main/resources/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter new file mode 100644 index 0000000000000..7eb27d946df2e --- /dev/null +++ b/extensions/reactive-db2-client/runtime/src/main/resources/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter @@ -0,0 +1 @@ +io.quarkus.reactive.db2.client.runtime.DB2ServiceBindingConverter diff --git a/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java b/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java index 02a98ae5f3e0d..3482082072658 100644 --- a/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java +++ b/extensions/reactive-mssql-client/deployment/src/main/java/io/quarkus/reactive/mssql/client/deployment/ReactiveMSSQLClientProcessor.java @@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.reactive.datasource.ReactiveDataSource; import io.quarkus.reactive.datasource.deployment.VertxPoolBuildItem; @@ -34,6 +35,7 @@ import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveRuntimeConfig; import io.quarkus.reactive.mssql.client.runtime.DataSourcesReactiveMSSQLConfig; import io.quarkus.reactive.mssql.client.runtime.MSSQLPoolRecorder; +import io.quarkus.reactive.mssql.client.runtime.MsSQLServiceBindingConverter; import io.quarkus.runtime.RuntimeValue; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; import io.quarkus.vertx.core.deployment.EventLoopCountBuildItem; @@ -87,7 +89,13 @@ DevServicesDatasourceConfigurationHandlerBuildItem devDbHandler() { } @BuildStep - void registerServiceBinding(BuildProducer dbKind) { + void registerServiceBinding(Capabilities capabilities, BuildProducer serviceProvider, + BuildProducer dbKind) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + serviceProvider.produce( + new ServiceProviderBuildItem("io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter", + MsSQLServiceBindingConverter.class.getName())); + } dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.MSSQL)); } diff --git a/extensions/reactive-mssql-client/runtime/pom.xml b/extensions/reactive-mssql-client/runtime/pom.xml index 38033f34ccbb7..3f890d40af73c 100644 --- a/extensions/reactive-mssql-client/runtime/pom.xml +++ b/extensions/reactive-mssql-client/runtime/pom.xml @@ -41,6 +41,11 @@ quarkus-smallrye-health true + + io.quarkus + quarkus-kubernetes-service-binding + true + diff --git a/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MsSQLServiceBindingConverter.java b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MsSQLServiceBindingConverter.java new file mode 100644 index 0000000000000..8d89964443236 --- /dev/null +++ b/extensions/reactive-mssql-client/runtime/src/main/java/io/quarkus/reactive/mssql/client/runtime/MsSQLServiceBindingConverter.java @@ -0,0 +1,18 @@ +package io.quarkus.reactive.mssql.client.runtime; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; + +public class MsSQLServiceBindingConverter implements ServiceBindingConverter { + + @Override + public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType("sqlserver", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Reactive()); + } +} diff --git a/extensions/reactive-mssql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter b/extensions/reactive-mssql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter new file mode 100644 index 0000000000000..20b5810b94c9d --- /dev/null +++ b/extensions/reactive-mssql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter @@ -0,0 +1 @@ +io.quarkus.reactive.mssql.client.runtime.MsSQLServiceBindingConverter diff --git a/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java b/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java index 669f063c102c2..b763f424b52d3 100644 --- a/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java +++ b/extensions/reactive-mysql-client/deployment/src/main/java/io/quarkus/reactive/mysql/client/deployment/ReactiveMySQLClientProcessor.java @@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.reactive.datasource.ReactiveDataSource; import io.quarkus.reactive.datasource.deployment.VertxPoolBuildItem; @@ -34,6 +35,7 @@ import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveRuntimeConfig; import io.quarkus.reactive.mysql.client.runtime.DataSourcesReactiveMySQLConfig; import io.quarkus.reactive.mysql.client.runtime.MySQLPoolRecorder; +import io.quarkus.reactive.mysql.client.runtime.MySQLServiceBindingConverter; import io.quarkus.runtime.RuntimeValue; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; import io.quarkus.vertx.core.deployment.EventLoopCountBuildItem; @@ -87,7 +89,13 @@ DevServicesDatasourceConfigurationHandlerBuildItem devDbHandler() { } @BuildStep - void registerServiceBinding(BuildProducer dbKind) { + void registerServiceBinding(Capabilities capabilities, BuildProducer serviceProvider, + BuildProducer dbKind) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + serviceProvider.produce( + new ServiceProviderBuildItem("io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter", + MySQLServiceBindingConverter.class.getName())); + } dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.MYSQL)); } diff --git a/extensions/reactive-mysql-client/runtime/pom.xml b/extensions/reactive-mysql-client/runtime/pom.xml index 370bb59b33fb2..14097b8533586 100644 --- a/extensions/reactive-mysql-client/runtime/pom.xml +++ b/extensions/reactive-mysql-client/runtime/pom.xml @@ -57,6 +57,11 @@ quarkus-smallrye-health true + + io.quarkus + quarkus-kubernetes-service-binding + true + diff --git a/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLServiceBindingConverter.java b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLServiceBindingConverter.java new file mode 100644 index 0000000000000..3934b2465f201 --- /dev/null +++ b/extensions/reactive-mysql-client/runtime/src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLServiceBindingConverter.java @@ -0,0 +1,18 @@ +package io.quarkus.reactive.mysql.client.runtime; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; + +public class MySQLServiceBindingConverter implements ServiceBindingConverter { + + @Override + public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType("mysql", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Reactive()); + } +} diff --git a/extensions/reactive-mysql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter b/extensions/reactive-mysql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter new file mode 100644 index 0000000000000..95254a20846d6 --- /dev/null +++ b/extensions/reactive-mysql-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter @@ -0,0 +1 @@ +io.quarkus.reactive.mysql.client.runtime.MySQLServiceBindingConverter \ No newline at end of file diff --git a/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java b/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java index a2b4a784c1aac..cb5afbd310af4 100644 --- a/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java +++ b/extensions/reactive-oracle-client/deployment/src/main/java/io/quarkus/reactive/oracle/client/deployment/ReactiveOracleClientProcessor.java @@ -26,6 +26,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.reactive.datasource.ReactiveDataSource; import io.quarkus.reactive.datasource.deployment.VertxPoolBuildItem; @@ -34,6 +35,7 @@ import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveRuntimeConfig; import io.quarkus.reactive.oracle.client.runtime.DataSourcesReactiveOracleConfig; import io.quarkus.reactive.oracle.client.runtime.OraclePoolRecorder; +import io.quarkus.reactive.oracle.client.runtime.OracleServiceBindingConverter; import io.quarkus.runtime.RuntimeValue; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; import io.quarkus.vertx.core.deployment.EventLoopCountBuildItem; @@ -88,7 +90,13 @@ DevServicesDatasourceConfigurationHandlerBuildItem devDbHandler() { } @BuildStep - void registerServiceBinding(BuildProducer dbKind) { + void registerServiceBinding(Capabilities capabilities, BuildProducer serviceProvider, + BuildProducer dbKind) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + serviceProvider.produce( + new ServiceProviderBuildItem("io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter", + OracleServiceBindingConverter.class.getName())); + } dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.ORACLE)); } diff --git a/extensions/reactive-oracle-client/runtime/pom.xml b/extensions/reactive-oracle-client/runtime/pom.xml index 184738d940217..78f73e257325d 100644 --- a/extensions/reactive-oracle-client/runtime/pom.xml +++ b/extensions/reactive-oracle-client/runtime/pom.xml @@ -37,6 +37,11 @@ quarkus-smallrye-health true + + io.quarkus + quarkus-kubernetes-service-binding + true + diff --git a/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OracleServiceBindingConverter.java b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OracleServiceBindingConverter.java new file mode 100644 index 0000000000000..3879fedcd065f --- /dev/null +++ b/extensions/reactive-oracle-client/runtime/src/main/java/io/quarkus/reactive/oracle/client/runtime/OracleServiceBindingConverter.java @@ -0,0 +1,19 @@ +package io.quarkus.reactive.oracle.client.runtime; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; + +public class OracleServiceBindingConverter implements ServiceBindingConverter { + + @Override + public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType("oracle", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Reactive()); + } + +} diff --git a/extensions/reactive-oracle-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter b/extensions/reactive-oracle-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter new file mode 100644 index 0000000000000..c4dec05c0e776 --- /dev/null +++ b/extensions/reactive-oracle-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter @@ -0,0 +1 @@ +io.quarkus.reactive.oracle.client.runtime.OracleServiceBindingConverter diff --git a/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java b/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java index 980ca33e3d122..12463073eb480 100644 --- a/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java +++ b/extensions/reactive-pg-client/deployment/src/main/java/io/quarkus/reactive/pg/client/deployment/ReactivePgClientProcessor.java @@ -27,6 +27,7 @@ import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.reactive.datasource.ReactiveDataSource; import io.quarkus.reactive.datasource.deployment.VertxPoolBuildItem; @@ -35,6 +36,7 @@ import io.quarkus.reactive.datasource.runtime.DataSourcesReactiveRuntimeConfig; import io.quarkus.reactive.pg.client.runtime.DataSourcesReactivePostgreSQLConfig; import io.quarkus.reactive.pg.client.runtime.PgPoolRecorder; +import io.quarkus.reactive.pg.client.runtime.PostgreSQLServiceBindingConverter; import io.quarkus.runtime.RuntimeValue; import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem; import io.quarkus.vertx.core.deployment.EventLoopCountBuildItem; @@ -120,7 +122,13 @@ void addHealthCheck( } @BuildStep - void registerServiceBinding(BuildProducer dbKind) { + void registerServiceBinding(Capabilities capabilities, BuildProducer serviceProvider, + BuildProducer dbKind) { + if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { + serviceProvider.produce( + new ServiceProviderBuildItem("io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter", + PostgreSQLServiceBindingConverter.class.getName())); + } dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.POSTGRESQL)); } diff --git a/extensions/reactive-pg-client/runtime/pom.xml b/extensions/reactive-pg-client/runtime/pom.xml index 27243e341bdae..12193a160cc83 100644 --- a/extensions/reactive-pg-client/runtime/pom.xml +++ b/extensions/reactive-pg-client/runtime/pom.xml @@ -45,6 +45,11 @@ quarkus-smallrye-health true + + io.quarkus + quarkus-kubernetes-service-binding + true + diff --git a/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PostgreSQLServiceBindingConverter.java b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PostgreSQLServiceBindingConverter.java new file mode 100644 index 0000000000000..d65f83a3c092a --- /dev/null +++ b/extensions/reactive-pg-client/runtime/src/main/java/io/quarkus/reactive/pg/client/runtime/PostgreSQLServiceBindingConverter.java @@ -0,0 +1,18 @@ +package io.quarkus.reactive.pg.client.runtime; + +import java.util.List; +import java.util.Optional; + +import io.quarkus.kubernetes.service.binding.runtime.DatasourceServiceBindingConfigSourceFactory; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; +import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; + +public class PostgreSQLServiceBindingConverter implements ServiceBindingConverter { + + @Override + public Optional convert(List serviceBindings) { + return ServiceBinding.singleMatchingByType("postgresql", serviceBindings) + .map(new DatasourceServiceBindingConfigSourceFactory.Reactive()); + } +} diff --git a/extensions/reactive-pg-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter b/extensions/reactive-pg-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter new file mode 100644 index 0000000000000..ff0f7229229d7 --- /dev/null +++ b/extensions/reactive-pg-client/runtime/src/main/resources/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter @@ -0,0 +1 @@ +io.quarkus.reactive.pg.client.runtime.PostgreSQLServiceBindingConverter diff --git a/integration-tests/kubernetes-service-binding-reactive/pom.xml b/integration-tests/kubernetes-service-binding-reactive/pom.xml new file mode 100644 index 0000000000000..717f524b29056 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/pom.xml @@ -0,0 +1,294 @@ + + + 4.0.0 + + + quarkus-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + + kubernetes-service-binding-reactive + Quarkus - Integration Tests - Kubernetes Service Binding Reactive + + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-hibernate-reactive + + + io.quarkus + quarkus-reactive-pg-client + + + io.quarkus + quarkus-kubernetes-service-binding + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + io.quarkus + quarkus-resteasy-reactive-jackson-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-hibernate-reactive-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-reactive-pg-client-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-kubernetes-service-binding-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + src/main/resources + true + + + + + io.quarkus + quarkus-maven-plugin + ${project.version} + + + + build + + + + + + maven-surefire-plugin + + true + + + + maven-failsafe-plugin + + true + + + + + + + + test-postgresql + + + test-containers + + + + + + maven-surefire-plugin + + false + + + ${project.basedir}/src/test/resources/k8s-sb + + true + + + + + + maven-failsafe-plugin + + false + + + ${project.basedir}/src/test/resources/k8s-sb + + + + + + + + + + native + + + native + + + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + ${project.basedir}/src/test/resources/k8s-sb + + true + + + + + + + + + + + native + + + + + docker-postgresql + + + start-containers + + + + + + io.fabric8 + docker-maven-plugin + + + + ${postgres.image} + postgresql + + + quarkus_test + quarkus_test + quarkus_test + + + 5431:5432 + + + + mapped + + 5432 + + + + + + + + + true + + + + docker-start + compile + + stop + start + + + + docker-stop + post-integration-test + + stop + + + + + + org.codehaus.mojo + exec-maven-plugin + + + docker-prune + generate-resources + + exec + + + ${docker-prune.location} + + + + + + + + + diff --git a/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/Fruit.java b/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/Fruit.java new file mode 100644 index 0000000000000..9d60a9f3bb8ce --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/Fruit.java @@ -0,0 +1,48 @@ +package io.quarkus.it.k8ssb.jdbc; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.QueryHint; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; + +@Entity +@Table(name = "known_fruits") +@NamedQuery(name = "Fruits.findAll", query = "SELECT f FROM Fruit f ORDER BY f.name", hints = @QueryHint(name = "org.hibernate.cacheable", value = "true")) +public class Fruit { + + @Id + @SequenceGenerator(name = "fruitsSequence", sequenceName = "known_fruits_id_seq", allocationSize = 1, initialValue = 10) + @GeneratedValue(generator = "fruitsSequence") + private Integer id; + + @Column(length = 40, unique = true) + private String name; + + public Fruit() { + } + + public Fruit(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/FruitResource.java b/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/FruitResource.java new file mode 100644 index 0000000000000..bbd649163a981 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/main/java/io/quarkus/it/k8ssb/jdbc/FruitResource.java @@ -0,0 +1,27 @@ +package io.quarkus.it.k8ssb.jdbc; + +import java.util.List; + +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.hibernate.reactive.mutiny.Mutiny; + +import io.smallrye.mutiny.Uni; + +@Path("fruits") +public class FruitResource { + + @Inject + Mutiny.SessionFactory sf; + + @GET + @Produces("application/json") + @Consumes("application/json") + public Uni> get() { + return sf.withSession(session -> session.createNamedQuery("Fruits.findAll", Fruit.class).getResultList()); + } +} diff --git a/integration-tests/kubernetes-service-binding-reactive/src/main/resources/application.properties b/integration-tests/kubernetes-service-binding-reactive/src/main/resources/application.properties new file mode 100644 index 0000000000000..e464fbee4953c --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/main/resources/application.properties @@ -0,0 +1,3 @@ +quarkus.hibernate-orm.database.generation=drop-and-create +#quarkus.hibernate-orm.log.sql=true +quarkus.hibernate-orm.sql-load-script=import.sql diff --git a/integration-tests/kubernetes-service-binding-reactive/src/main/resources/import.sql b/integration-tests/kubernetes-service-binding-reactive/src/main/resources/import.sql new file mode 100644 index 0000000000000..18265f866e7ab --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/main/resources/import.sql @@ -0,0 +1,6 @@ +INSERT INTO known_fruits(id, name) +VALUES (1, 'Cherry'); +INSERT INTO known_fruits(id, name) +VALUES (2, 'Apple'); +INSERT INTO known_fruits(id, name) +VALUES (3, 'Banana'); diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointIT.java b/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointIT.java new file mode 100644 index 0000000000000..cc93ecd586b31 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointIT.java @@ -0,0 +1,7 @@ +package io.quarkus.it.k8ssb.jdbc; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class FruitsEndpointIT extends FruitsEndpointTest { +} diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointTest.java b/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointTest.java new file mode 100644 index 0000000000000..3f48e622bdbbb --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/java/io/quarkus/it/k8ssb/jdbc/FruitsEndpointTest.java @@ -0,0 +1,25 @@ +package io.quarkus.it.k8ssb.jdbc; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class FruitsEndpointTest { + + @Test + public void testListAllFruits() { + given() + .when().get("/fruits") + .then() + .statusCode(200) + .body( + containsString("Cherry"), + containsString("Apple"), + containsString("Banana")); + } + +} diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/database b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/database new file mode 100644 index 0000000000000..39cd31f5ffa44 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/database @@ -0,0 +1 @@ +quarkus_test diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/host b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/host new file mode 100644 index 0000000000000..2fbb50c4a8dc7 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/host @@ -0,0 +1 @@ +localhost diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/password b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/password new file mode 100644 index 0000000000000..39cd31f5ffa44 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/password @@ -0,0 +1 @@ +quarkus_test diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/port b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/port new file mode 100644 index 0000000000000..7e30bed39582f --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/port @@ -0,0 +1 @@ +5431 diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/type b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/type new file mode 100644 index 0000000000000..a02a1cc751d91 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/type @@ -0,0 +1 @@ +postgresql diff --git a/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/username b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/username new file mode 100644 index 0000000000000..39cd31f5ffa44 --- /dev/null +++ b/integration-tests/kubernetes-service-binding-reactive/src/test/resources/k8s-sb/fruit-db/username @@ -0,0 +1 @@ +quarkus_test diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 0c96ea94c8e07..b0dd7e8e269b9 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -234,6 +234,7 @@ kubernetes kubernetes-client kubernetes-service-binding-jdbc + kubernetes-service-binding-reactive openshift-client mongodb-client jackson