Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ iceberg = "1.10.1" # Ensure to update the iceberg version in regtests to keep re
immutables = "2.12.1"
jmh = "1.37"
picocli = "4.7.7"
quarkus = "3.30.8"
quarkus = "3.31.2"
scala212 = "2.12.19"
swagger = "1.6.16"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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.persistence.nosql.quarkus.backend;

import io.smallrye.config.ConfigSourceContext;
import io.smallrye.config.ConfigSourceFactory;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.polaris.persistence.nosql.mongodb.MongoDbBackendFactory;
import org.eclipse.microprofile.config.spi.ConfigSource;

/**
* This config source factory is used to activate the Quarkus-MongoDB driver when the MongoDB NoSQL
* database backend is used, and otherwise disable the Quarkus-MongoDB driver.
*
* <p>The Quarkus configuration {@code quarkus.mongodb.active}, defaults to {@code true}, got added
* via Quarkus 3.31.0.
*
* <p>Having a Quarkus-Mongo driver active means that it will be considered during the readiness and
* health checks. In other words, the default of {@code true} <em>breaks</em> non-MongoDB version
* store types.
*/
public class MongoDBConfigSourceFactory implements ConfigSourceFactory {
@Override
public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context) {
return List.of(
new ConfigSource() {
static final String ACTIVE_PROPERTY = "quarkus.mongodb.active";
static final Set<String> PROPERTY_NAMES = Set.of(ACTIVE_PROPERTY);

private String activeValue() {
var persistenceType = context.getValue("polaris.persistence.type");
if (persistenceType == null || !"nosql".equalsIgnoreCase(persistenceType.getValue())) {
return "false";
}

var backendType = context.getValue("polaris.persistence.nosql.backend");
return backendType != null
&& MongoDbBackendFactory.NAME.equalsIgnoreCase(backendType.getValue())
? "true"
: "false";
}

@Override
public Map<String, String> getProperties() {
return Map.of(ACTIVE_PROPERTY, activeValue());
}

@Override
public int getOrdinal() {
// allows overriding the value in config files, system properties and environment
// variables
return 150;
}

@Override
public Set<String> getPropertyNames() {
return PROPERTY_NAMES;
}

@Override
public String getValue(String propertyName) {
if (ACTIVE_PROPERTY.equals(propertyName)) {
return activeValue();
}
return null;
}

@Override
public String getName() {
return "MongoDB-active config provider";
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package org.apache.polaris.persistence.nosql.quarkus.backend;

import com.mongodb.client.MongoClient;
import io.quarkus.arc.Arc;
import io.quarkus.mongodb.runtime.MongoClientBeanUtil;
import io.quarkus.mongodb.runtime.MongoClients;
import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import org.apache.polaris.persistence.nosql.api.backend.Backend;
import org.apache.polaris.persistence.nosql.mongodb.MongoDbBackendConfig;
Expand All @@ -36,11 +34,11 @@ class MongoDbBackendBuilder implements BackendBuilder {
@ConfigProperty(name = "quarkus.mongodb.database", defaultValue = "polaris")
String databaseName;

@Inject Instance<MongoClient> mongoClientInstance;

@Override
public Backend buildBackend() {
MongoClients mongoClients = Arc.container().instance(MongoClients.class).get();
MongoClient client =
mongoClients.createMongoClient(MongoClientBeanUtil.DEFAULT_MONGOCLIENT_NAME);
MongoClient client = mongoClientInstance.get();

var config = new MongoDbBackendConfig(databaseName, client, true, false);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# 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.
#

org.apache.polaris.persistence.nosql.quarkus.backend.MongoDBConfigSourceFactory
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
*/
package org.apache.polaris.service.test;

import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.extension.ExtensionContext;

public class DefaultTestEnvironmentResolver implements TestEnvironmentResolver {

private final int localPort = Integer.getInteger("quarkus.http.port");
private final int localManagementPort = Integer.getInteger("quarkus.management.port");

/** Resolves the TestEnvironment to point to the local Quarkus Application instance. */
@Override
public TestEnvironment resolveTestEnvironment(ExtensionContext extensionContext) {
var quarkusManagementPort =
ConfigProvider.getConfig().getConfigValue("quarkus.management.port");
var localManagementPort = Integer.parseInt(quarkusManagementPort.getValue());
var quarkusHttpPort = ConfigProvider.getConfig().getConfigValue("quarkus.http.port");
var localPort = Integer.parseInt(quarkusHttpPort.getValue());

return new TestEnvironment(
String.format("http://localhost:%d/", localPort),
String.format("http://localhost:%d/", localManagementPort));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.vertx.http.HttpServer;
import jakarta.inject.Inject;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.Response;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.polaris.service.it.env.PolarisApiEndpoints;
import org.apache.polaris.service.it.env.PolarisClient;
Expand Down Expand Up @@ -57,16 +57,14 @@ public Map<String, String> getConfigOverrides() {
private static final String CLIENT_ID = "client1";
private static final String CLIENT_SECRET = "secret1";

private static final URI baseUri =
URI.create(
"http://localhost:"
+ Objects.requireNonNull(
Integer.getInteger("quarkus.http.test-port"),
"System property not set correctly: quarkus.http.test-port"));
@SuppressWarnings("CdiInjectionPointsInspection")
@Inject
HttpServer httpServer;

private Response request(Map<String, String> headers) {
try (PolarisClient client =
PolarisClient.polarisClient(new PolarisApiEndpoints(baseUri, REALM, headers))) {
PolarisClient.polarisClient(
new PolarisApiEndpoints(httpServer.getLocalBaseUri(), REALM, headers))) {
return client
.catalogApiPlain()
.request("v1/oauth/tokens")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package org.apache.polaris.service.it;

import java.net.URI;
import java.util.Objects;
import org.apache.polaris.service.it.env.ClientCredentials;
import org.apache.polaris.service.it.env.ClientPrincipal;
import org.apache.polaris.service.it.env.Server;
import org.apache.polaris.service.it.ext.PolarisServerManager;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.extension.ExtensionContext;

public class ServerManager implements PolarisServerManager {
Expand Down Expand Up @@ -51,9 +51,8 @@ public void close() {
};
}

private static Integer getQuarkusTestPort() {
return Objects.requireNonNull(
Integer.getInteger("quarkus.http.test-port"),
"System property not set correctly: quarkus.http.test-port");
private static int getQuarkusTestPort() {
var quarkusHttpPort = ConfigProvider.getConfig().getConfigValue("quarkus.http.port");
return Integer.parseInt(quarkusHttpPort.getValue());
}
}