Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade quarkus to 3.15 #5488

Merged
merged 6 commits into from
Nov 14, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.apicurio.registry.services;

import io.apicurio.registry.storage.impl.sql.RegistryDatabaseKind;
import io.smallrye.config.ConfigSourceInterceptor;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigValue;
import jakarta.annotation.Priority;

@Priority(100)
public class DatabaseConfigInterceptor implements ConfigSourceInterceptor {

@Override
public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
ConfigValue storageKind = context.proceed("apicurio.storage.sql.kind");
RegistryDatabaseKind databaseKind = RegistryDatabaseKind.valueOf(storageKind.getValue());

switch (name) {
case "quarkus.datasource.postgresql.active" -> {
if (databaseKind.equals(RegistryDatabaseKind.postgresql)) {
return ConfigValue.builder().withName(name).withValue("true").build();
} else {
return ConfigValue.builder().withName(name).withValue("false").build();
}
}
case "quarkus.datasource.mssql.active" -> {
if (databaseKind.equals(RegistryDatabaseKind.mssql)) {
return ConfigValue.builder().withName(name).withValue("true").build();
} else {
return ConfigValue.builder().withName(name).withValue("false").build();
}
}
case "quarkus.datasource.mysql.active" -> {
if (databaseKind.equals(RegistryDatabaseKind.mysql)) {
return ConfigValue.builder().withName(name).withValue("true").build();
} else {
return ConfigValue.builder().withName(name).withValue("false").build();
}
}
case "quarkus.datasource.h2.active" -> {
if (databaseKind.equals(RegistryDatabaseKind.h2)) {
return ConfigValue.builder().withName(name).withValue("true").build();
} else {
return ConfigValue.builder().withName(name).withValue("false").build();
}
}
}

return context.proceed(name);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.apicurio.registry.services;

import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.LaunchMode;
import org.eclipse.microprofile.config.spi.ConfigSource;

import java.util.HashMap;
Expand All @@ -21,7 +21,7 @@ public synchronized Map<String, String> getProperties() {
properties = new HashMap<>();
String prefix = System.getenv("REGISTRY_PROPERTIES_PREFIX");
if (prefix != null) {
String profile = ProfileManager.getLaunchMode().getProfileKey();
String profile = LaunchMode.current().getProfileKey();
String profilePrefix = "%" + profile + ".";
Map<String, String> envMap = System.getenv();
for (Map.Entry<String, String> entry : envMap.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.apicurio.registry.storage.impl.sql.jdb.HandleImpl;
import org.slf4j.Logger;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -34,7 +35,10 @@ public <R, X extends Exception> R withHandle(HandleCallback<R, X> callback) thro
try {
// Create a new handle if necessary. Increment the "level" if a handle already exists.
if (state.handle == null) {
state.handle = new HandleImpl(dataSource.getConnection());
Connection connection = dataSource.getConnection();
// We must disable autocommit since we're managing the transactions ourselves.
connection.setAutoCommit(false);
state.handle = new HandleImpl(connection);
state.level = 0;
} else {
state.level++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.validation.ValidationException;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -2905,7 +2904,6 @@ public GroupSearchResultsDto searchGroups(Set<SearchFilter> filters, OrderBy ord
}

@Override
@Transactional
public ContentWrapperDto getContentByReference(ArtifactReferenceDto reference) {
try {
var meta = getArtifactVersionMetaData(reference.getGroupId(), reference.getArtifactId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.apicurio.registry.storage.impl.sql;

import io.agroal.api.AgroalDataSource;
import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration.TransactionIsolation;
import io.agroal.api.configuration.AgroalConnectionPoolConfiguration.TransactionRequirement;
import io.agroal.api.configuration.supplier.AgroalPropertiesReader;
import io.apicurio.common.apps.config.Info;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand All @@ -13,8 +10,6 @@
import org.slf4j.Logger;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class RegistryDatasourceProducer {

Expand All @@ -25,29 +20,21 @@ public class RegistryDatasourceProducer {
@Info(category = "storage", description = "Application datasource database type", availableSince = "3.0.0")
String databaseType;

@ConfigProperty(name = "apicurio.datasource.url", defaultValue = "jdbc:h2:mem:registry_db")
@Info(category = "storage", description = "Application datasource jdbc url", availableSince = "3.0.0")
String jdbcUrl;

@ConfigProperty(name = "apicurio.datasource.username", defaultValue = "sa")
@Info(category = "storage", description = "Application datasource username", availableSince = "3.0.0")
String username;

@ConfigProperty(name = "apicurio.datasource.password", defaultValue = "sa")
@Info(category = "storage", description = "Application datasource password", availableSince = "3.0.0")
String password;
@Inject
@Named("h2")
AgroalDataSource h2Datasource;

@ConfigProperty(name = "apicurio.datasource.jdbc.initial-size", defaultValue = "20")
@Info(category = "storage", description = "Application datasource pool initial size", availableSince = "3.0.0")
String initialSize;
@Inject
@Named("postgresql")
AgroalDataSource postgresqlDatasource;

@ConfigProperty(name = "apicurio.datasource.jdbc.min-size", defaultValue = "20")
@Info(category = "storage", description = "Application datasource pool minimum size", availableSince = "3.0.0")
String minSize;
@Inject
@Named("mysql")
AgroalDataSource mysqlDatasource;

@ConfigProperty(name = "apicurio.datasource.jdbc.max-size", defaultValue = "100")
@Info(category = "storage", description = "Application datasource pool maximum size", availableSince = "3.0.0")
String maxSize;
@Inject
@Named("mssql")
AgroalDataSource mssqlDatasource;

@Produces
@ApplicationScoped
Expand All @@ -57,30 +44,24 @@ public AgroalDataSource produceDatasource() throws SQLException {

final RegistryDatabaseKind databaseKind = RegistryDatabaseKind.valueOf(databaseType);

Map<String, String> props = new HashMap<>();

props.put(AgroalPropertiesReader.MAX_SIZE, maxSize);
props.put(AgroalPropertiesReader.MIN_SIZE, minSize);
props.put(AgroalPropertiesReader.INITIAL_SIZE, initialSize);
props.put(AgroalPropertiesReader.JDBC_URL, jdbcUrl);
props.put(AgroalPropertiesReader.PRINCIPAL, username);
props.put(AgroalPropertiesReader.CREDENTIAL, password);
props.put(AgroalPropertiesReader.PROVIDER_CLASS_NAME, databaseKind.getDriverClassName());

/*
* We need to disable auto-commit to have proper transaction rollback, otherwise the data may be in an
* inconsistent state (e.g. partial deletes), or operations would not be rolled back on exception.
*/
props.put(AgroalPropertiesReader.AUTO_COMMIT, "false");
props.put(AgroalPropertiesReader.TRANSACTION_ISOLATION, TransactionIsolation.READ_COMMITTED.name());
props.put(AgroalPropertiesReader.TRANSACTION_REQUIREMENT, TransactionRequirement.WARN.name());
props.put(AgroalPropertiesReader.FLUSH_ON_CLOSE, "true");

AgroalDataSource datasource = AgroalDataSource
.from(new AgroalPropertiesReader().readProperties(props).get());

log.info("Using {} SQL storage.", databaseType);

return datasource;
switch (databaseKind) {
case h2 -> {
return h2Datasource;
}
case postgresql -> {
return postgresqlDatasource;
}
case mysql -> {
return mysqlDatasource;
}
case mssql -> {
return mssqlDatasource;
}
default -> throw new IllegalStateException(
String.format("unrecognized database type: %s", databaseKind.name()));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.apicurio.registry.storage.RegistryStorage;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;

/**
* An in-memory SQL implementation of the {@link RegistryStorage} interface.
Expand Down Expand Up @@ -40,7 +39,6 @@ public void restoreFromSnapshot(String snapshotLocation) {
.bind(0, snapshotLocation).execute());
}

@Transactional
public void executeSqlStatement(String sqlStatement) {
handleFactory.withHandle(handle -> handle.createUpdate(sqlStatement).execute());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.apicurio.registry.services.DatabaseConfigInterceptor
41 changes: 39 additions & 2 deletions app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ quarkus.native.additional-build-args=--initialize-at-run-time=org.apache.kafka.c
--allow-incomplete-classpath

# Package
quarkus.package.type=legacy-jar
quarkus.package.jar.type=legacy-jar
quarkus.index-dependency.jaxrs.group-id=jakarta.ws.rs
quarkus.index-dependency.jaxrs.artifact-id=jakarta.ws.rs-api

Expand Down Expand Up @@ -162,13 +162,50 @@ apicurio.import.work-dir=${java.io.tmpdir}

## SQL Storage
apicurio.storage.sql.kind=h2
apicurio.sql.init=true

apicurio.datasource.url=jdbc:h2:mem:db_${quarkus.uuid}
apicurio.datasource.username=sa
apicurio.datasource.password=sa
apicurio.datasource.jdbc.initial-size=20
apicurio.datasource.jdbc.min-size=20
apicurio.datasource.jdbc.max-size=100
apicurio.sql.init=true

## H2
quarkus.datasource.h2.db-kind=h2
quarkus.datasource.h2.jdbc.url=${apicurio.datasource.url}
quarkus.datasource.h2.username=${apicurio.datasource.username}
quarkus.datasource.h2.password=${apicurio.datasource.password}
quarkus.datasource.h2.jdbc.initial-size=${apicurio.datasource.jdbc.initial-size}
quarkus.datasource.h2.jdbc.min-size=${apicurio.datasource.jdbc.min-size}
quarkus.datasource.h2.jdbc.max-size=${apicurio.datasource.jdbc.max-size}

## Postgresql
quarkus.datasource.postgresql.db-kind=postgresql
quarkus.datasource.postgresql.jdbc.url=${apicurio.datasource.url}
quarkus.datasource.postgresql.username=${apicurio.datasource.username}
quarkus.datasource.postgresql.password=${apicurio.datasource.password}
quarkus.datasource.postgresql.jdbc.initial-size=${apicurio.datasource.jdbc.initial-size}
quarkus.datasource.postgresql.jdbc.min-size=${apicurio.datasource.jdbc.min-size}
quarkus.datasource.postgresql.jdbc.max-size=${apicurio.datasource.jdbc.max-size}

## Mysql
quarkus.datasource.mysql.db-kind=mysql
quarkus.datasource.mysql.jdbc.url=${apicurio.datasource.url}
quarkus.datasource.mysql.username=${apicurio.datasource.username}
quarkus.datasource.mysql.password=${apicurio.datasource.password}
quarkus.datasource.mysql.jdbc.initial-size=${apicurio.datasource.jdbc.initial-size}
quarkus.datasource.mysql.jdbc.min-size=${apicurio.datasource.jdbc.min-size}
quarkus.datasource.mysql.jdbc.max-size=${apicurio.datasource.jdbc.max-size}

## Mssql
quarkus.datasource.mssql.db-kind=mssql
quarkus.datasource.mssql.jdbc.url=${apicurio.datasource.url}
quarkus.datasource.mssql.username=${apicurio.datasource.username}
quarkus.datasource.mssql.password=${apicurio.datasource.password}
quarkus.datasource.mssql.jdbc.initial-size=${apicurio.datasource.jdbc.initial-size}
quarkus.datasource.mssql.jdbc.min-size=${apicurio.datasource.jdbc.min-size}
quarkus.datasource.mssql.jdbc.max-size=${apicurio.datasource.jdbc.max-size}

## Kafka SQL storage
apicurio.kafkasql.bootstrap.servers=localhost:9092
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MssqlTestProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("apicurio.storage.sql.kind", "mssql");
return Map.of("apicurio.storage.sql.kind", "mssql");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MysqlTestProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("apicurio.storage.sql.kind", "mysql");
return Map.of("apicurio.storage.sql.kind", "mysql");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PostgresqlTestProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("apicurio.storage.sql.kind", "postgresql");
return Map.of("apicurio.storage.sql.kind", "postgresql");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,11 @@ The following {registry} configuration options are available for each component
|
|
|Kafka sql storage bootstrap servers
|`apicurio.kafkasql.consumer.group-prefix`
|`string`
|`apicurio-`
|
|Kafka sql storage prefix for consumer group name
|`apicurio.kafkasql.consumer.poll.timeout`
|`integer`
|`5000`
Expand Down
4 changes: 0 additions & 4 deletions examples/confluent-serdes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
<name>Confluent</name>
<url>https://packages.confluent.io/maven/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.apicurio.registry.operator.api.v1.status;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -39,7 +38,7 @@ public class Conditions implements KubernetesResource {
@Required()
@JsonPropertyDescription("lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.")
@JsonSetter(nulls = Nulls.SKIP)
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
@SchemaFrom(type = String.class)
private Instant lastTransitionTime;

Expand Down
Loading
Loading