Skip to content

Commit

Permalink
Move Config to interfaces in order to make registrars optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
aureamunoz committed Jul 6, 2023
1 parent e5b8679 commit 50daf7f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package io.quarkus.stork;

import java.util.Optional;

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

@ConfigGroup
public class ServiceConfiguration {
public interface ServiceConfiguration {
/**
* ServiceDiscovery configuration for the service
*/
@ConfigItem
public StorkServiceDiscoveryConfiguration serviceDiscovery;
StorkServiceDiscoveryConfiguration serviceDiscovery();

/**
* LoadBalancer configuration for the service
*/
@ConfigItem
public StorkLoadBalancerConfiguration loadBalancer;
StorkLoadBalancerConfiguration loadBalancer();

/**
* ServiceRegistrar configuration for the service
*/
@ConfigItem
public StorkServiceRegistrarConfiguration serviceRegistrar;
Optional<StorkServiceRegistrarConfiguration> serviceRegistrar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ public class StorkConfigUtil {

public static List<ServiceConfig> toStorkServiceConfig(StorkConfiguration storkConfiguration) {
List<ServiceConfig> storkServicesConfigs = new ArrayList<>();
Set<String> servicesConfigs = storkConfiguration.serviceConfiguration.keySet();
Set<String> servicesConfigs = storkConfiguration.serviceConfiguration().keySet();
SimpleServiceConfig.Builder builder = new SimpleServiceConfig.Builder();
for (String serviceName : servicesConfigs) {
builder.setServiceName(serviceName);
ServiceConfiguration serviceConfiguration = storkConfiguration.serviceConfiguration.get(serviceName);
ServiceConfiguration serviceConfiguration = storkConfiguration.serviceConfiguration().get(serviceName);
SimpleServiceConfig.SimpleServiceDiscoveryConfig storkServiceDiscoveryConfig = new SimpleServiceConfig.SimpleServiceDiscoveryConfig(
serviceConfiguration.serviceDiscovery.type, serviceConfiguration.serviceDiscovery.params);
serviceConfiguration.serviceDiscovery().type(), serviceConfiguration.serviceDiscovery().params());
builder = builder.setServiceDiscovery(storkServiceDiscoveryConfig);
SimpleServiceConfig.SimpleLoadBalancerConfig loadBalancerConfig = new SimpleServiceConfig.SimpleLoadBalancerConfig(
serviceConfiguration.loadBalancer.type, serviceConfiguration.loadBalancer.parameters);
serviceConfiguration.loadBalancer().type(), serviceConfiguration.loadBalancer().parameters());
builder.setLoadBalancer(loadBalancerConfig);
SimpleServiceConfig.SimpleServiceRegistrarConfig serviceRegistrarConfig = new SimpleServiceConfig.SimpleServiceRegistrarConfig(
serviceConfiguration.serviceRegistrar.type, serviceConfiguration.serviceRegistrar.parameters);
builder.setServiceRegistrar(serviceRegistrarConfig);
if (serviceConfiguration.serviceRegistrar().isPresent()) {
SimpleServiceConfig.SimpleServiceRegistrarConfig serviceRegistrarConfig = new SimpleServiceConfig.SimpleServiceRegistrarConfig(
serviceConfiguration.serviceRegistrar().get().type(),
serviceConfiguration.serviceRegistrar().get().parameters());
builder.setServiceRegistrar(serviceRegistrarConfig);
}
storkServicesConfigs.add(builder.build());
}
return storkServicesConfigs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
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.WithParentName;

/**
* Stork configuration root.
*/
@ConfigMapping(prefix = "quarkus.stork")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public class StorkConfiguration {
public interface StorkConfiguration {

/**
* ServiceDiscovery configuration for the service
* Configuration for the service
*/
@ConfigItem(name = ConfigItem.PARENT)
@WithParentName
@ConfigDocSection
@ConfigDocMapKey("service-name")
public Map<String, ServiceConfiguration> serviceConfiguration;
Map<String, ServiceConfiguration> serviceConfiguration();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
import java.util.Map;

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

@ConfigGroup
public class StorkLoadBalancerConfiguration {
public interface StorkLoadBalancerConfiguration {

/**
* Configures load balancer type, e.g. "round-robin".
* A LoadBalancerProvider for the type has to be available
*
*/
@ConfigItem(defaultValue = "round-robin")
public String type;
@WithDefault(value = "round-robin")
String type();

/**
* Load Balancer parameters.
* Check the documentation of the selected load balancer type for available parameters
*
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> parameters;
@WithParentName
Map<String, String> parameters();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import java.util.Map;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithParentName;

@ConfigGroup
public class StorkServiceDiscoveryConfiguration {
public interface StorkServiceDiscoveryConfiguration {

/**
* Configures the service discovery type, e.g. "consul".
* ServiceDiscoveryProvider for the type has to be available
*
*/
@ConfigItem
public String type;
String type();

/**
* ServiceDiscovery parameters.
* Check the documentation of the selected service discovery type for available parameters.
*
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> params;
@WithParentName
Map<String, String> params();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
import java.util.Map;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.smallrye.config.WithParentName;

@ConfigGroup
public class StorkServiceRegistrarConfiguration {
public interface StorkServiceRegistrarConfiguration {

/**
* Configures service registrar type, e.g. "consul".
* A ServiceRegistrarProvider for the type has to be available
*
*/
@ConfigItem
public String type;
String type();

/**
* Service Registrar parameters.
* Check the documentation of the selected registrar type for available parameters
*
*/
@ConfigItem(name = ConfigItem.PARENT)
public Map<String, String> parameters;
// @ConfigItem(name = ConfigItem.PARENT)
@WithParentName
Map<String, String> parameters();

}

0 comments on commit 50daf7f

Please sign in to comment.