Skip to content

Commit 81798f1

Browse files
authored
Production readiness for Persistence (#1707)
Production readiness for Persistence (#1707)
1 parent 721614a commit 81798f1

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkProductionReadinessChecks.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@
2626
import java.nio.file.Path;
2727
import org.apache.polaris.core.config.ProductionReadinessCheck;
2828
import org.apache.polaris.core.config.ProductionReadinessCheck.Error;
29+
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132

3233
@ApplicationScoped
3334
public class EclipseLinkProductionReadinessChecks {
34-
3535
private static final Logger LOGGER =
3636
LoggerFactory.getLogger(EclipseLinkProductionReadinessChecks.class);
3737

3838
@Produces
39-
public ProductionReadinessCheck checkJdbcUrl(EclipseLinkConfiguration eclipseLinkConfiguration) {
39+
public ProductionReadinessCheck checkEclipseLink(
40+
MetaStoreManagerFactory metaStoreManagerFactory,
41+
EclipseLinkConfiguration eclipseLinkConfiguration) {
42+
// This check should only be applicable when persistence uses EclipseLink.
43+
if (!(metaStoreManagerFactory instanceof EclipseLinkPolarisMetaStoreManagerFactory)) {
44+
return ProductionReadinessCheck.OK;
45+
}
46+
4047
try {
4148
var confFile = eclipseLinkConfiguration.configurationFile().map(Path::toString).orElse(null);
4249
var persistenceUnitName =

extension/persistence/relational-jdbc/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies {
3636
implementation(libs.smallrye.common.annotation) // @Identifier
3737

3838
testImplementation(libs.mockito.junit.jupiter)
39-
4039
testImplementation(libs.h2)
4140
testImplementation(testFixtures(project(":polaris-core")))
4241
}

extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,19 @@ private void initializeForRealm(
108108
metaStoreManagerMap.put(realmContext.getRealmIdentifier(), metaStoreManager);
109109
}
110110

111+
protected DatabaseType getDatabaseType() throws SQLException {
112+
try (Connection connection = dataSource.get().getConnection()) {
113+
String productName = connection.getMetaData().getDatabaseProductName();
114+
return DatabaseType.fromDisplayName(productName);
115+
}
116+
}
117+
111118
private DatasourceOperations getDatasourceOperations(boolean isBootstrap) {
112119
DatasourceOperations databaseOperations =
113120
new DatasourceOperations(dataSource.get(), relationalJdbcConfiguration);
114121
if (isBootstrap) {
115122
try {
116-
DatabaseType databaseType;
117-
try (Connection connection = dataSource.get().getConnection()) {
118-
String productName = connection.getMetaData().getDatabaseProductName();
119-
databaseType = DatabaseType.fromDisplayName(productName);
120-
}
123+
DatabaseType databaseType = getDatabaseType();
121124
databaseOperations.executeScript(
122125
String.format("%s/schema-v1.sql", databaseType.getDisplayName()));
123126
} catch (SQLException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.polaris.extension.persistence.relational.jdbc;
21+
22+
import jakarta.enterprise.context.ApplicationScoped;
23+
import jakarta.enterprise.inject.Produces;
24+
import java.sql.SQLException;
25+
import org.apache.polaris.core.config.ProductionReadinessCheck;
26+
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
27+
28+
@ApplicationScoped
29+
public class RelationalJdbcProductionReadinessChecks {
30+
@Produces
31+
public ProductionReadinessCheck checkRelationalJdbc(
32+
MetaStoreManagerFactory metaStoreManagerFactory) {
33+
// This check should only be applicable when persistence uses RelationalJdbc.
34+
if (!(metaStoreManagerFactory
35+
instanceof JdbcMetaStoreManagerFactory jdbcMetaStoreManagerFactory)) {
36+
return ProductionReadinessCheck.OK;
37+
}
38+
39+
try {
40+
if (jdbcMetaStoreManagerFactory.getDatabaseType().equals(DatabaseType.H2)) {
41+
return ProductionReadinessCheck.of(
42+
ProductionReadinessCheck.Error.of(
43+
"The current persistence (jdbc:h2) is intended for tests only.",
44+
"quarkus.datasource.jdbc.url"));
45+
}
46+
} catch (SQLException e) {
47+
return ProductionReadinessCheck.of(
48+
ProductionReadinessCheck.Error.of(
49+
"Misconfigured JDBC datasource", "quarkus.datasource.jdbc.url"));
50+
}
51+
return ProductionReadinessCheck.OK;
52+
}
53+
}

0 commit comments

Comments
 (0)