Skip to content

Commit

Permalink
Merge pull request #650 from loicmathieu/feat/config-mapping
Browse files Browse the repository at this point in the history
Switch to Config Mapping
  • Loading branch information
loicmathieu authored Aug 21, 2024
2 parents 95fa341 + cf593c8 commit f21e8ae
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 236 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package io.quarkiverse.googlecloudservices.bigtable.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

/**
* Root configuration class for Bigtable that operates at build time.
* This class provides a nested structure for configuration, including
* a separate group for the development service configuration.
*/
@ConfigRoot(name = "google.cloud.bigtable", phase = ConfigPhase.BUILD_TIME)
public class BigtableBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.google.cloud.bigtable")
@ConfigRoot
public interface BigtableBuildTimeConfig {

/**
* Configuration for the Bigtable dev service.
* These settings will be used when Bigtable service is being configured
* for development purposes.
*/
@ConfigItem
public BigtableDevServiceConfig devservice;
BigtableDevServiceConfig devservice();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* Configuration group for the Bigtable dev service. This class holds all the configuration properties
Expand All @@ -13,32 +14,32 @@
* <p>
*
* <pre>
* quarkus.google.cloud.bigtable.deservice.enabled = true
* quarkus.google.cloud.bigtable.deservice.image-name = gcr.io/google.com/cloudsdktool/google-cloud-cli # optional
* quarkus.google.cloud.bigtable.deservice.emulatorPort = 9000 # optional
* quarkus.google.cloud.bigtable.devservice.enabled = true
* quarkus.google.cloud.bigtable.devservice.image-name = gcr.io/google.com/cloudsdktool/google-cloud-cli # optional
* quarkus.google.cloud.bigtable.devservice.emulatorPort = 9000 # optional
* </pre>
*/
@ConfigMapping(prefix = "quarkus.google.cloud.bigtable.devservice")
@ConfigGroup
public class BigtableDevServiceConfig {
public interface BigtableDevServiceConfig {

/**
* Indicates whether the Bigtable service should be enabled or not.
* The default value is 'false'.
*/
@ConfigItem(defaultValue = "false")
public boolean enabled;
@WithDefault("false")
boolean enabled();

/**
* Sets the Docker image name for the Google Cloud SDK.
* This image is used to emulate the Bigtable service in the development environment.
* The default value is 'gcr.io/google.com/cloudsdktool/google-cloud-cli'.
*/
@ConfigItem(defaultValue = "gcr.io/google.com/cloudsdktool/google-cloud-cli")
public String imageName;
@WithDefault("gcr.io/google.com/cloudsdktool/google-cloud-cli")
String imageName();

/**
* Specifies the emulatorPort on which the Bigtable service should run in the development environment.
*/
@ConfigItem
public Optional<Integer> emulatorPort = Optional.empty();
Optional<Integer> emulatorPort();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI
LoggingSetupBuildItem loggingSetupBuildItem,
GlobalDevServicesConfig globalDevServicesConfig) {
// If dev service is running and config has changed, stop the service
if (devService != null && !buildTimeConfig.devservice.equals(config)) {
if (devService != null && !buildTimeConfig.devservice().equals(config)) {
stopContainer();
} else if (devService != null) {
return devService.toBuildItem();
Expand All @@ -60,7 +60,7 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI

// Try starting the container if conditions are met
try {
devService = startContainerIfAvailable(dockerStatusBuildItem, buildTimeConfig.devservice,
devService = startContainerIfAvailable(dockerStatusBuildItem, buildTimeConfig.devservice(),
globalDevServicesConfig.timeout);
} catch (Throwable t) {
LOGGER.warn("Unable to start Bigtable dev service", t);
Expand All @@ -85,13 +85,13 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI
private DevServicesResultBuildItem.RunningDevService startContainerIfAvailable(DockerStatusBuildItem dockerStatusBuildItem,
BigtableDevServiceConfig config,
Optional<Duration> timeout) {
if (!config.enabled) {
if (!config.enabled()) {
// Bigtable service explicitly disabled
LOGGER.debug("Not starting Dev Services for Bigtable as it has been disabled in the config");
return null;
}

if (!dockerStatusBuildItem.isDockerAvailable()) {
if (!dockerStatusBuildItem.isContainerRuntimeAvailable()) {
LOGGER.warn("Not starting devservice because docker is not available");
return null;
}
Expand All @@ -112,8 +112,8 @@ private DevServicesResultBuildItem.RunningDevService startContainer(DockerStatus
Optional<Duration> timeout) {
// Create and configure Bigtable emulator container
BigtableEmulatorContainer emulatorContainer = new QuarkusBigtableContainer(
DockerImageName.parse(config.imageName).asCompatibleSubstituteFor("gcr.io/google.com/cloudsdktool/cloud-sdk"),
config.emulatorPort.orElse(null));
DockerImageName.parse(config.imageName()).asCompatibleSubstituteFor("gcr.io/google.com/cloudsdktool/cloud-sdk"),
config.emulatorPort().orElse(null));

// Set container startup timeout if provided
timeout.ifPresent(emulatorContainer::withStartupTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AdditionalBeanBuildItem producer() {

@BuildStep
public void setupFirebaseAuth(BuildProducer<AdditionalBeanBuildItem> additionalBeans, FirebaseAuthConfiguration config) {
if (!config.enabled) {
if (!config.enabled()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.quarkiverse.googlecloudservices.firebase.admin.deployment.authentication;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(name = "google.cloud.firebase.auth", phase = ConfigPhase.BUILD_TIME)
public class FirebaseAuthConfiguration {
@ConfigMapping(prefix = "quarkus.google.cloud.firebase.auth")
@ConfigRoot
public interface FirebaseAuthConfiguration {

/**
* Enable or disable Firebase authentication.
*/
@ConfigItem(defaultValue = "false")
public boolean enabled;
@WithDefault("false")
boolean enabled();
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package io.quarkiverse.googlecloudservices.firestore.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

/**
* Root configuration class for Firestore that operates at build time.
* This class provides a nested structure for configuration, including
* a separate group for the development service configuration.
*/
@ConfigRoot(name = "google.cloud.firestore", phase = ConfigPhase.BUILD_TIME)
public class FirestoreBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.google.cloud.firestore")
@ConfigRoot
public interface FirestoreBuildTimeConfig {

/**
* Configuration for the Firestore dev service.
* These settings will be used when Firestore service is being configured
* for development purposes.
*/
@ConfigItem
public FirestoreDevServiceConfig devservice;
FirestoreDevServiceConfig devservice();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* Configuration group for the Firestore dev service. This class holds all the configuration properties
Expand All @@ -13,32 +14,32 @@
* <p>
*
* <pre>
* quarkus.firestore-dev-service.enabled = true
* quarkus.firestore-dev-service.image-name = gcr.io/google.com/cloudsdktool/google-cloud-cli # optional
* quarkus.firestore-dev-service.emulatorPort = 8080 # optional
* quarkus.google.cloud.firestore.devservice.enabled = true
* quarkus.google.cloud.firestore.devservice.image-name = gcr.io/google.com/cloudsdktool/google-cloud-cli # optional
* quarkus.google.cloud.firestore.devservice.emulatorPort = 8080 # optional
* </pre>
*/
@ConfigMapping(prefix = "quarkus.google.cloud.firestore.devservice")
@ConfigGroup
public class FirestoreDevServiceConfig {
public interface FirestoreDevServiceConfig {

/**
* Indicates whether the Firestore service should be enabled or not.
* The default value is 'false'.
*/
@ConfigItem(defaultValue = "false")
public boolean enabled;
@WithDefault("false")
boolean enabled();

/**
* Sets the Docker image name for the Google Cloud SDK.
* This image is used to emulate the Firestore service in the development environment.
* The default value is 'gcr.io/google.com/cloudsdktool/google-cloud-cli'.
*/
@ConfigItem(defaultValue = "gcr.io/google.com/cloudsdktool/google-cloud-cli")
public String imageName;
@WithDefault("gcr.io/google.com/cloudsdktool/google-cloud-cli")
String imageName();

/**
* Specifies the emulatorPort on which the Firestore service should run in the development environment.
*/
@ConfigItem
public Optional<Integer> emulatorPort = Optional.empty();
Optional<Integer> emulatorPort();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI
LoggingSetupBuildItem loggingSetupBuildItem,
GlobalDevServicesConfig globalDevServicesConfig) {
// If dev service is running and config has changed, stop the service
if (devService != null && !buildTimeConfig.devservice.equals(config)) {
if (devService != null && !buildTimeConfig.devservice().equals(config)) {
stopContainer();
} else if (devService != null) {
return devService.toBuildItem();
Expand All @@ -56,7 +56,7 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI

// Try starting the container if conditions are met
try {
devService = startContainerIfAvailable(dockerStatusBuildItem, buildTimeConfig.devservice,
devService = startContainerIfAvailable(dockerStatusBuildItem, buildTimeConfig.devservice(),
globalDevServicesConfig.timeout);
} catch (Throwable t) {
LOGGER.warn("Unable to start Firestore dev service", t);
Expand All @@ -81,13 +81,13 @@ public DevServicesResultBuildItem start(DockerStatusBuildItem dockerStatusBuildI
private DevServicesResultBuildItem.RunningDevService startContainerIfAvailable(DockerStatusBuildItem dockerStatusBuildItem,
FirestoreDevServiceConfig config,
Optional<Duration> timeout) {
if (!config.enabled) {
if (!config.enabled()) {
// Firestore service explicitly disabled
LOGGER.debug("Not starting Dev Services for Firestore as it has been disabled in the config");
return null;
}

if (!dockerStatusBuildItem.isDockerAvailable()) {
if (!dockerStatusBuildItem.isContainerRuntimeAvailable()) {
LOGGER.warn("Not starting devservice because docker is not available");
return null;
}
Expand All @@ -108,8 +108,8 @@ private DevServicesResultBuildItem.RunningDevService startContainer(DockerStatus
Optional<Duration> timeout) {
// Create and configure Firestore emulator container
FirestoreEmulatorContainer emulatorContainer = new QuarkusFirestoreContainer(
DockerImageName.parse(config.imageName).asCompatibleSubstituteFor("gcr.io/google.com/cloudsdktool/cloud-sdk"),
config.emulatorPort.orElse(null));
DockerImageName.parse(config.imageName()).asCompatibleSubstituteFor("gcr.io/google.com/cloudsdktool/cloud-sdk"),
config.emulatorPort().orElse(null));

// Set container startup timeout if provided
timeout.ifPresent(emulatorContainer::withStartupTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,71 @@
import java.util.OptionalDouble;
import java.util.OptionalInt;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(name = "google.cloud.firestore", phase = ConfigPhase.RUN_TIME)
public class FirestoreConfiguration {
@ConfigMapping(prefix = "quarkus.google.cloud.firestore")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface FirestoreConfiguration {
/**
* Overrides the default service host.
* This is most commonly used for development or testing activities with a local Google Cloud Firestore emulator instance.
*/
@ConfigItem
public Optional<String> hostOverride;
Optional<String> hostOverride();

/**
* Controls the retry settings for Firestore requests.
*/
@ConfigItem
public Optional<RetryConfiguration> retry;
Optional<RetryConfiguration> retry();

/**
* The firestore database identifier.
* It not set, the default will be used.
*/
@ConfigItem
public Optional<String> databaseId;
Optional<String> databaseId();

@ConfigGroup
public static class RetryConfiguration {
interface RetryConfiguration {

/**
* Total timeout for all retries.
*/
@ConfigItem
public Optional<Duration> totalTimeout;
Optional<Duration> totalTimeout();

/**
* Delay before the first retry.
*/
@ConfigItem
public Optional<Duration> initialRetryDelay;
Optional<Duration> initialRetryDelay();

/**
* Controls the rate of change of the delay. Next retry is multiplied by this factor.
*/
@ConfigItem
public OptionalDouble retryDelayMultiplier;
OptionalDouble retryDelayMultiplier();

/**
* Limits the maximum retry delay.
*/
@ConfigItem
public Optional<Duration> maxRetryDelay;
Optional<Duration> maxRetryDelay();

/**
* Determines the maximum number of attempts. When number of attempts reach this limit they stop retrying.
*/
@ConfigItem
public OptionalInt maxAttempts;
OptionalInt maxAttempts();

/**
* Timeout for the initial RPC.
*/
@ConfigItem
public Optional<Duration> initialRpcTimeout;
Optional<Duration> initialRpcTimeout();

/**
* Controls the rate of change of the RPC timeout. Next timeout is multiplied by this factor.
*/
@ConfigItem
public OptionalDouble rpcTimeoutMultiplier;
OptionalDouble rpcTimeoutMultiplier();

/**
* Limits the maximum RPC timeout.
*/
@ConfigItem
public Optional<Duration> maxRpcTimeout;
Optional<Duration> maxRpcTimeout();
}

}
Loading

0 comments on commit f21e8ae

Please sign in to comment.