Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,37 @@

import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL;

import io.smallrye.common.annotation.Identifier;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Produces;
import java.io.IOException;
import java.nio.file.Path;
import org.apache.polaris.core.config.ProductionReadinessCheck;
import org.apache.polaris.core.config.ProductionReadinessCheck.Error;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApplicationScoped
public class EclipseLinkProductionReadinessChecks {

private static final Logger LOGGER =
LoggerFactory.getLogger(EclipseLinkProductionReadinessChecks.class);

@Produces
public ProductionReadinessCheck checkJdbcUrl(EclipseLinkConfiguration eclipseLinkConfiguration) {
public ProductionReadinessCheck checkEclipseLink(
@ConfigProperty(name = "polaris.persistence.type") String persistenceType,
@Any Instance<MetaStoreManagerFactory> metaStoreManagerFactories,
EclipseLinkConfiguration eclipseLinkConfiguration) {
// This check should only be applicable when persistence uses EclipseLink.
MetaStoreManagerFactory metaStoreManagerFactory =
metaStoreManagerFactories.select(Identifier.Literal.of(persistenceType)).get();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to .select() here? The usual producer should normally yield a value if we just declared MetaStoreManagerFactory for injection, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because both @Inject as a member of this class as well as using @Any Instance and then doing .get() letter was giving ambigous bean, I wonder if these checks run before the bean is actually created from QuarkusProducers, this is the only approach worked for me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, this WFM :)

  @Produces
  public ProductionReadinessCheck checkJdbcUrl(EclipseLinkConfiguration eclipseLinkConfiguration,
  MetaStoreManagerFactory f) {
    System.out.println("AAA: " + f.getClass());
[...]

Output: AAA: class org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory_ClientProxy

@singhpk234 singhpk234 May 29, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ I didn't try just passing it in the parameter without an Annotation. i though like anyother producer it would need one, I can confirm your suggestion works, though any explanation why even with @Produces annotation we don;t need any annotation ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quarkus CDI is able to figure out bean dependencies. When a producer method is needed for a bean, its inputs are automatically injected, I suppose.

if (!(metaStoreManagerFactory instanceof EclipseLinkPolarisMetaStoreManagerFactory)) {
return ProductionReadinessCheck.OK;
}

try {
var confFile = eclipseLinkConfiguration.configurationFile().map(Path::toString).orElse(null);
var persistenceUnitName =
Expand Down
1 change: 1 addition & 0 deletions extension/persistence/relational-jdbc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
compileOnly(libs.jakarta.inject.api)

implementation(libs.smallrye.common.annotation) // @Identifier
compileOnly(libs.microprofile.config.api) // @ConfigMapping

testImplementation(libs.mockito.junit.jupiter)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.polaris.extension.persistence.relational.jdbc;

import io.smallrye.common.annotation.Identifier;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Produces;
import java.util.Optional;
import org.apache.polaris.core.config.ProductionReadinessCheck;
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
public class RelationalJdbcProductionReadinessChecks {
@Produces
public ProductionReadinessCheck checkRelationalJdbc(
@ConfigProperty(name = "quarkus.datasource.jdbc.url") Optional<String> jdbcUrl,
@ConfigProperty(name = "polaris.persistence.type") String persistenceType,
@Any Instance<MetaStoreManagerFactory> metaStoreManagerFactories) {
// This check should only be applicable when persistence uses RelationalJdbc.
if (!(metaStoreManagerFactories.select(Identifier.Literal.of(persistenceType)).get()
instanceof JdbcMetaStoreManagerFactory)) {
return ProductionReadinessCheck.OK;
}

if (jdbcUrl.isPresent() && jdbcUrl.get().startsWith("jdbc:h2")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be more reliable, plus it's in sync with actual persistence usage:

The EclipseLink side is good to merge, IMHO, so if you prefer we could move this to a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not mind adding this: JdbcMetaStoreManagerFactory.getDatabaseType()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, tbh i think the h2 check is fine, though one thing i realized doing this will also check the connection is properly made to the DB and if its not then we simply fail early that your DB is misconfigured correct it !

let me make the change should be small IMHO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about connections. Although, I would not fail the startup in that case, maybe just produce a warning check?

@dimas-b dimas-b May 29, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, connection checks should be part of the "readiness" check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, though i prefer failing as without persistence we can't use the application at all, let me know if you feel strongly otherwise.

return ProductionReadinessCheck.of(
ProductionReadinessCheck.Error.of(
"The current persistence (jdbc:h2) is intended for tests only.",
"quarkus.datasource.jdbc.url"));
}
return ProductionReadinessCheck.OK;
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ junit-bom = { module = "org.junit:junit-bom", version = "5.12.2" }
logback-classic = { module = "ch.qos.logback:logback-classic", version = "1.5.18" }
micrometer-bom = { module = "io.micrometer:micrometer-bom", version = "1.15.0" }
microprofile-fault-tolerance-api = { module = "org.eclipse.microprofile.fault-tolerance:microprofile-fault-tolerance-api", version = "4.1.2" }
microprofile-config-api = {module = "org.eclipse.microprofile.config:microprofile-config-api", version = "3.0.3"}
mockito-core = { module = "org.mockito:mockito-core", version = "5.18.0" }
mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version = "5.18.0" }
opentelemetry-bom = { module = "io.opentelemetry:opentelemetry-bom", version = "1.50.0" }
Expand Down
1 change: 1 addition & 0 deletions quarkus/server/distribution/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ License: Apache License 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt
Group: org.eclipse.microprofile.config Name: microprofile-config-api Version: 3.1
Group: org.eclipse.microprofile.context-propagation Name: microprofile-context-propagation-api Version: 1.3
Group: org.eclipse.microprofile.fault-tolerance Name: microprofile-fault-tolerance-api Version: 4.1.1
Group: org.eclipse.microprofile.config Name: microprofile-config-api Version: 3.0.3
Group: org.eclipse.microprofile.health Name: microprofile-health-api Version: 4.0.1
Group: org.eclipse.microprofile.jwt Name: microprofile-jwt-auth-api Version: 2.1
Group: org.eclipse.microprofile.reactive-streams-operators Name: microprofile-reactive-streams-operators-api Version: 3.0.1
Expand Down