Skip to content

Commit

Permalink
Switch to smallrye's @ConfigMapping system
Browse files Browse the repository at this point in the history
Resolves #81
  • Loading branch information
turing85 committed Oct 18, 2023
1 parent 9989098 commit 49d6f32
Show file tree
Hide file tree
Showing 32 changed files with 478 additions and 723 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jboss.logging.Logger;

import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.artemis.core.runtime.ArtemisBuildTimeConfig;
import io.quarkus.artemis.core.runtime.ArtemisBuildTimeConfigs;
import io.quarkus.artemis.core.runtime.ArtemisCoreRecorder;
import io.quarkus.artemis.core.runtime.ArtemisRuntimeConfigs;
Expand Down Expand Up @@ -77,7 +76,7 @@ NativeImageConfigBuildItem config() {
ArtemisBootstrappedBuildItem build(
CombinedIndexBuildItem indexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
ShadowRunTimeConfigs shadowRunTimeConfigs,
ShadowRuntimeConfigs shadowRunTimeConfigs,
ArtemisBuildTimeConfigs buildTimeConfigs) {
Collection<ClassInfo> connectorFactories = indexBuildItem.getIndex()
.getAllKnownImplementors(DotName.createSimple(ConnectorFactory.class.getName()));
Expand All @@ -90,12 +89,12 @@ ArtemisBootstrappedBuildItem build(
addBuiltinReflectiveBuildItems(reflectiveClass, BUILTIN_LOADBALANCING_POLICIES);
HashSet<String> names = new HashSet<>(shadowRunTimeConfigs.getNames());
HashSet<String> disabled = new HashSet<>();
for (var entry : buildTimeConfigs.getAllConfigs().entrySet()) {
for (var entry : buildTimeConfigs.configs().entrySet()) {
if (entry.getValue().isDisabled()) {
disabled.add(entry.getKey());
}
}
names.addAll(buildTimeConfigs.getAllConfigs().keySet());
names.addAll(buildTimeConfigs.getNames());
names.removeAll(disabled);
return new ArtemisBootstrappedBuildItem(names);
}
Expand All @@ -106,7 +105,7 @@ ArtemisBootstrappedBuildItem build(
ArtemisCoreConfiguredBuildItem configure(
ArtemisCoreRecorder recorder,
ArtemisRuntimeConfigs runtimeConfigs,
ShadowRunTimeConfigs shadowRunTimeConfigs,
ShadowRuntimeConfigs shadowRunTimeConfigs,
ArtemisBuildTimeConfigs buildTimeConfigs,
ArtemisBootstrappedBuildItem bootstrap,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer,
Expand All @@ -121,7 +120,7 @@ ArtemisCoreConfiguredBuildItem configure(
boolean isSoleServerLocator = bootstrap.getConfigurationNames().size() == 1;
for (String name : bootstrap.getConfigurationNames()) {
if (!shadowRunTimeConfigs.getNames().contains(name)
&& buildTimeConfigs.getAllConfigs().getOrDefault(name, new ArtemisBuildTimeConfig()).isEmpty()) {
&& buildTimeConfigs.configs().get(name).isEmpty()) {
continue;
}
Supplier<ServerLocator> supplier = recorder.getServerLocatorSupplier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public List<DevServicesResultBuildItem> startArtemisDevService(
DockerStatusBuildItem dockerStatusBuildItem,
LaunchModeBuildItem launchMode,
ArtemisBootstrappedBuildItem bootstrap,
ShadowRunTimeConfigs shadowRunTimeConfigs,
ShadowRuntimeConfigs shadowRunTimeConfigs,
ArtemisBuildTimeConfigs buildConfigs,
List<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
Expand All @@ -72,8 +72,7 @@ public List<DevServicesResultBuildItem> startArtemisDevService(
GlobalDevServicesConfig devServicesConfig) {
ArrayList<DevServicesResultBuildItem> results = new ArrayList<>();
for (String name : bootstrap.getConfigurationNames()) {
ArtemisBuildTimeConfig buildTimeConfig = buildConfigs.getAllConfigs().getOrDefault(name,
new ArtemisBuildTimeConfig());
ArtemisBuildTimeConfig buildTimeConfig = buildConfigs.configs().get(name);
boolean isUrlEmpty = shadowRunTimeConfigs.isUrlEmpty(name);
if (!shadowRunTimeConfigs.getNames().contains(name) && buildTimeConfig.isEmpty()) {
LOGGER.debugf(
Expand Down Expand Up @@ -120,29 +119,28 @@ private static DevServicesResultBuildItem start(
cfgs.clear();
}

StartupLogCompressor compressor = new StartupLogCompressor(
(launchMode.isTest() ? "(test) " : "") + "ActiveMQ Artemis Dev Services Starting:",
consoleInstalledBuildItem, loggingSetupBuildItem);
if (configuration != null) {
try {
// devServices
RunningDevService service = startArtemis(
name,
dockerStatusBuildItem,
configuration,
launchMode,
devServicesConfig.timeout);
if (service != null) {
devServices.put(name, service);
}
if (devServices.get(name) == null) {
try (StartupLogCompressor compressor = new StartupLogCompressor(
(launchMode.isTest() ? "(test) " : "") + "ActiveMQ Artemis Dev Services Starting:",
consoleInstalledBuildItem, loggingSetupBuildItem)) {
try {
// devServices
RunningDevService service = startArtemis(
name,
dockerStatusBuildItem,
configuration,
launchMode,
devServicesConfig.timeout);
if (service != null) {
devServices.put(name, service);
}
if (devServices.get(name) == null) {
compressor.closeAndDumpCaptured();
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
} else {
compressor.close();
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
}

Expand Down Expand Up @@ -287,7 +285,7 @@ private static final class ArtemisDevServiceCfg {

public ArtemisDevServiceCfg(ArtemisBuildTimeConfig config, String name, boolean isUrlEmpty) {
ArtemisDevServicesBuildTimeConfig devServicesConfig = config.getDevservices();
this.devServicesEnabled = devServicesConfig.enabled.orElse(isUrlEmpty);
this.devServicesEnabled = devServicesConfig.enabled().orElse(isUrlEmpty);
this.imageName = devServicesConfig.getImageName();
this.fixedExposedPort = devServicesConfig.getPort();
this.shared = devServicesConfig.isShared();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;

/**
* This class is a build-time mirror/shadow of {@link io.quarkus.artemis.core.runtime.ArtemisRuntimeConfig} to make the
Expand All @@ -15,27 +14,52 @@
* {@link jakarta.jms.ConnectionFactory} beans. Most importantly, we only query the presence of keys and/or values,
* we do not access values, since they could change at runtime.
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@ConfigGroup
public class ShadowRuntimeConfig {
@ConfigItem(generateDocumentation = false)
protected Optional<String> url = Optional.empty();
public interface ShadowRuntimeConfig {
/**
* Artemis connection url
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@Deprecated(since = "3.1.3")
Optional<String> url();

@ConfigItem(generateDocumentation = false)
protected Optional<String> username = Optional.empty();
/**
* Username for authentication, only used with JMS
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@Deprecated(since = "3.1.3")
Optional<String> username();

@ConfigItem(generateDocumentation = false)
protected Optional<String> password = Optional.empty();
/**
* Password for authentication, only used with JMS
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@Deprecated(since = "3.1.3")
Optional<String> password();

boolean isUrlEmpty() {
return url.isEmpty();
/**
* Whether this particular data source should be excluded from the health check if
* the general health check for data sources is enabled.
* <p>
* By default, the health check includes all configured data sources (if it is enabled).
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@Deprecated(since = "3.1.3")
Optional<Boolean> healthExclude();

default boolean isUrlEmpty() {
return url().isEmpty();
}

public boolean isEmpty() {
return url.isEmpty() && username.isEmpty() && password.isEmpty();
default boolean isEmpty() {
return url().isEmpty() && username().isEmpty() && password().isEmpty() && healthExclude().isEmpty();
}

public boolean isPresent() {
default boolean isPresent() {
return !isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.quarkus.artemis.core.deployment;

import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import io.quarkus.artemis.core.runtime.ArtemisUtil;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefaults;
import io.smallrye.config.WithName;
import io.smallrye.config.WithParentName;
import io.smallrye.config.WithUnnamedKey;

/**
* This class is a build-time mirror/shadow of {@link io.quarkus.artemis.core.runtime.ArtemisRuntimeConfigs} to make the
* configuration properties accessible at build-time.
*
* <p>
* We use this configuration to access the configuration structure, and to extract the names of configurations
* present at build-time, so we can create the {@link org.apache.activemq.artemis.api.core.client.ServerLocator} /
* {@link jakarta.jms.ConnectionFactory} beans. Most importantly, we only query the presence of keys and/or values,
* we do not access values, since they could change at runtime.
*/
@ConfigMapping(prefix = "quarkus.artemis")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface ShadowRuntimeConfigs {
/**
* Configurations
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@WithParentName
@WithUnnamedKey(ArtemisUtil.DEFAULT_CONFIG_NAME)
@WithDefaults
@Deprecated(since = "3.1.3")
Map<String, ShadowRuntimeConfig> configs();

/**
* Whether configurations ({@link org.apache.activemq.artemis.api.core.client.ServerLocator}s in case of the
* {@code artemis-core} extension, {@link jakarta.jms.ConnectionFactory}s in case of the
* {@code artemis-jms} extension) should be included in the health check. Defaults to {@code true} if not set.
*
* @deprecated since 3.1.3, to suppress doc generation
*/
@Deprecated(since = "3.1.3")
@WithName("health.external.enabled")
Optional<Boolean> healthExternalEnabled();

default boolean isUrlEmpty(String name) {
return configs().get(name).isUrlEmpty();
}

default Set<String> getNames() {
HashSet<String> names = new HashSet<>();
for (var entry : configs().entrySet()) {
if (entry.getValue().isPresent()) {
names.add(entry.getKey());
}
}
return names;
}

default boolean isEmpty() {
Boolean hasNoConfig = configs().values().stream()
.map(ShadowRuntimeConfig::isEmpty)
.reduce(true, Boolean::logicalAnd);
return hasNoConfig && healthExternalEnabled().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.artemis.core.deployment.ArtemisBootstrappedBuildItem;
import io.quarkus.artemis.core.deployment.ArtemisJmsBuildItem;
import io.quarkus.artemis.core.deployment.ShadowRunTimeConfigs;
import io.quarkus.artemis.core.deployment.ShadowRuntimeConfigs;
import io.quarkus.artemis.core.runtime.ArtemisBuildTimeConfig;
import io.quarkus.artemis.core.runtime.ArtemisBuildTimeConfigs;
import io.quarkus.artemis.core.runtime.ArtemisUtil;
Expand All @@ -24,15 +24,14 @@
import io.quarkus.deployment.annotations.Record;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class ArtemisHealthProcessor {
@SuppressWarnings("unused")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
ArtemisHealthSupportBuildItem healthSupport(
Capabilities capabilities,
ArtemisBootstrappedBuildItem bootstrap,
ShadowRunTimeConfigs shadowRunTimeConfigs,
ShadowRuntimeConfigs shadowRunTimeConfigs,
ArtemisBuildTimeConfigs buildTimeConfigs,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer,
ArtemisHealthSupportRecorder recorder) {
Expand All @@ -52,22 +51,20 @@ ArtemisHealthSupportBuildItem healthSupport(

private static Set<String> processConfigs(
Set<String> names,
ShadowRunTimeConfigs shadowRunTimeConfigs,
ShadowRuntimeConfigs shadowRunTimeConfigs,
ArtemisBuildTimeConfigs buildTimeConfigs) {
Set<String> excluded = new HashSet<>();
Map<String, ArtemisBuildTimeConfig> allBuildTimeConfigs = Optional.ofNullable(buildTimeConfigs.getAllConfigs())
.orElse(Map.of());
Map<String, ArtemisBuildTimeConfig> allBuildTimeConfigs = buildTimeConfigs.configs();
for (String name : names) {
ArtemisBuildTimeConfig buildTimeConfig = allBuildTimeConfigs.getOrDefault(name, new ArtemisBuildTimeConfig());
if ((ArtemisUtil.isDefault(name) && !shadowRunTimeConfigs.getNames().contains(name) && buildTimeConfig.isEmpty())
|| buildTimeConfig.isHealthExclude()) {
ArtemisBuildTimeConfig buildTimeConfig = allBuildTimeConfigs.get(name);
if ((ArtemisUtil.isDefault(name) && !shadowRunTimeConfigs.getNames().contains(name) && buildTimeConfig.isEmpty())) {
excluded.add(name);
}
}
return excluded;
}

@SuppressWarnings("unused")
@SuppressWarnings({ "OptionalUsedAsFieldOrParameterType", "unused" })
@BuildStep
HealthBuildItem healthChecks(
Capabilities capabilities,
Expand Down
Loading

0 comments on commit 49d6f32

Please sign in to comment.