Skip to content

Commit

Permalink
Merge pull request #597 from aureamunoz/include-sr-in-service-config
Browse files Browse the repository at this point in the history
Include Service Registar in service config
  • Loading branch information
aureamunoz committed Jun 26, 2023
2 parents 9ad8642 + d20670e commit 4ce88f2
Show file tree
Hide file tree
Showing 59 changed files with 884 additions and 319 deletions.
95 changes: 94 additions & 1 deletion api/revapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,101 @@
"code": "java.method.addedToInterface",
"new": "method java.util.Optional<java.lang.String> io.smallrye.stork.api.ServiceInstance::getPath()",
"justification": "New method to handle API gateways"
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method void io.smallrye.stork.api.Service::<init>(java.lang.String, io.smallrye.stork.api.LoadBalancer, io.smallrye.stork.api.ServiceDiscovery, boolean)",
"new": "method void io.smallrye.stork.api.Service::<init>(java.lang.String, io.smallrye.stork.api.LoadBalancer, io.smallrye.stork.api.ServiceDiscovery, io.smallrye.stork.api.ServiceRegistrar, boolean)",
"justification": "Service Registrar is now part of the Service"
},
{
"ignore": true,
"code": "java.method.addedToInterface",
"new": "method io.smallrye.stork.api.config.ConfigWithType io.smallrye.stork.api.config.ServiceConfig::serviceRegistrar()",
"justification": "Registrar included in the service configuration"
},
{
"ignore": true,
"code": "java.method.removed",
"old": "method java.util.List<io.smallrye.stork.api.config.ServiceRegistrarConfig> io.smallrye.stork.spi.config.ConfigProvider::getRegistrarConfigs()",
"justification": "Registrar configuration is now part of configs"
},
{
"ignore": true,
"code": "java.method.parameterTypeChanged",
"old": "parameter io.smallrye.stork.api.ServiceRegistrar<MetadataKeyType> io.smallrye.stork.spi.internal.ServiceRegistrarLoader<MetadataKeyType extends java.lang.Enum<MetadataKeyType> & io.smallrye.stork.api.MetadataKey>::createServiceRegistrar(===io.smallrye.stork.api.config.ServiceRegistrarConfig===, io.smallrye.stork.spi.StorkInfrastructure)",
"new": "parameter io.smallrye.stork.api.ServiceRegistrar<MetadataKeyType> io.smallrye.stork.spi.internal.ServiceRegistrarLoader<MetadataKeyType extends java.lang.Enum<MetadataKeyType> & io.smallrye.stork.api.MetadataKey>::createServiceRegistrar(===io.smallrye.stork.api.config.ConfigWithType===, io.smallrye.stork.spi.StorkInfrastructure)",
"parameterIndex": "0",
"justification": "Use the ConfigWithType more generic type for registrars."
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method io.smallrye.stork.api.ServiceRegistrar<MetadataKeyType> io.smallrye.stork.spi.internal.ServiceRegistrarLoader<MetadataKeyType extends java.lang.Enum<MetadataKeyType> & io.smallrye.stork.api.MetadataKey>::createServiceRegistrar(io.smallrye.stork.api.config.ServiceRegistrarConfig, io.smallrye.stork.spi.StorkInfrastructure)",
"new": "method io.smallrye.stork.api.ServiceRegistrar<MetadataKeyType> io.smallrye.stork.spi.internal.ServiceRegistrarLoader<MetadataKeyType extends java.lang.Enum<MetadataKeyType> & io.smallrye.stork.api.MetadataKey>::createServiceRegistrar(io.smallrye.stork.api.config.ConfigWithType, java.lang.String, io.smallrye.stork.spi.StorkInfrastructure)",
"justification": "Service name is not needed anymore. It is present at Service config level."
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method void io.smallrye.stork.test.TestConfigProvider::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>)",
"new": "method void io.smallrye.stork.test.TestConfigProvider::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>, boolean)",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method void io.smallrye.stork.test.TestConfigProvider::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>, boolean)",
"new": "method void io.smallrye.stork.test.TestConfigProvider::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>)",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.removed",
"old": "method void io.smallrye.stork.test.TestConfigProvider::addServiceRegistrarConfig(java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>)",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.removed",
"old": "method java.util.List<io.smallrye.stork.api.config.ServiceRegistrarConfig> io.smallrye.stork.test.TestConfigProvider::getRegistrarConfigs()",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method void io.smallrye.stork.test.TestConfigProviderBean::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>)",
"new": "method void io.smallrye.stork.test.TestConfigProviderBean::addServiceConfig(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.String>)",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.removed",
"old": "method void io.smallrye.stork.test.TestConfigProviderBean::addServiceRegistrarConfig(java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.String>)",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.removed",
"old": "method java.util.List<io.smallrye.stork.api.config.ServiceRegistrarConfig> io.smallrye.stork.test.TestConfigProviderBean::getRegistrarConfigs()",
"justification": "Registrars are now part of configs"
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method io.smallrye.stork.api.ServiceRegistrar<io.smallrye.stork.test.TestServiceRegistrarProvider.TestMetadata> io.smallrye.stork.test.TestServiceRegistrarProviderLoader::createServiceRegistrar(io.smallrye.stork.api.config.ServiceRegistrarConfig, io.smallrye.stork.spi.StorkInfrastructure)",
"new": "method io.smallrye.stork.api.ServiceRegistrar<io.smallrye.stork.test.TestServiceRegistrarProvider.TestMetadata> io.smallrye.stork.test.TestServiceRegistrarProviderLoader::createServiceRegistrar(io.smallrye.stork.api.config.ConfigWithType, java.lang.String, io.smallrye.stork.spi.StorkInfrastructure)",
"justification": "Use the ConfigWithType more generic type for registrars and service name."
},
{
"ignore": true,
"code": "java.method.numberOfParametersChanged",
"old": "method io.smallrye.stork.api.ServiceDefinition io.smallrye.stork.api.ServiceDefinition::of(io.smallrye.stork.api.config.ConfigWithType, io.smallrye.stork.api.config.ConfigWithType)",
"new": "method io.smallrye.stork.api.ServiceDefinition io.smallrye.stork.api.ServiceDefinition::of(io.smallrye.stork.api.config.ConfigWithType, io.smallrye.stork.api.config.ConfigWithType, io.smallrye.stork.api.config.ConfigWithType)",
"justification": "Registrar included."
}
]
]
}
}, {
"extension" : "revapi.reporter.json",
Expand Down
14 changes: 13 additions & 1 deletion api/src/main/java/io/smallrye/stork/api/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Service {
private final Semaphore instanceSelectionLock;
private final LoadBalancer loadBalancer;
private final ServiceDiscovery serviceDiscovery;
private final ServiceRegistrar serviceRegistrar;
private final String serviceName;

/**
Expand All @@ -24,12 +25,14 @@ public class Service {
* @param serviceName the name, must not be {@code null}, must not be blank
* @param loadBalancer the load balancer, can be {@code null}
* @param serviceDiscovery the service discovery, must not be {@code null}
* @param serviceRegistrar the service registrar, can be {@code null}
* @param requiresStrictRecording whether strict recording must be enabled
*/
public Service(String serviceName, LoadBalancer loadBalancer, ServiceDiscovery serviceDiscovery,
boolean requiresStrictRecording) {
ServiceRegistrar serviceRegistrar, boolean requiresStrictRecording) {
this.loadBalancer = loadBalancer;
this.serviceDiscovery = serviceDiscovery;
this.serviceRegistrar = serviceRegistrar;
this.serviceName = serviceName;
this.instanceSelectionLock = requiresStrictRecording ? new Semaphore(1) : null;
}
Expand Down Expand Up @@ -146,6 +149,15 @@ public ServiceDiscovery getServiceDiscovery() {
return serviceDiscovery;
}

/**
* Get the underlying service registrar
*
* @return service registrar
*/
public ServiceRegistrar getServiceRegistrar() {
return serviceRegistrar;
}

/**
* @return the service name.
*/
Expand Down
25 changes: 23 additions & 2 deletions api/src/main/java/io/smallrye/stork/api/ServiceDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
public class ServiceDefinition {
private final ConfigWithType loadBalancer;
private final ConfigWithType serviceDiscovery;
private final ConfigWithType serviceRegistrar;

private ServiceDefinition(ConfigWithType sd, ConfigWithType lb) {
private ServiceDefinition(ConfigWithType sd, ConfigWithType lb, ConfigWithType sr) {
serviceDiscovery = ParameterValidation.nonNull(sd, "service discovery config");
loadBalancer = lb;
serviceRegistrar = sr;
}

/**
Expand All @@ -30,10 +32,22 @@ public static ServiceDefinition of(ConfigWithType sd) {
*
* @param sd the service discovery config, must not be {@code null}
* @param lb the load balancer config, if {@code null}, round-robin is used.
* @param sr the service registrar config, must not be {@code null}
* @return the created service definition
*/
public static ServiceDefinition of(ConfigWithType sd, ConfigWithType lb, ConfigWithType sr) {
return new ServiceDefinition(sd, lb, sr);
}

/**
* Creates a new {@link ServiceDefinition} using the given {@link ConfigWithType} .
*
* @param sd the service discovery config, must not be {@code null}
* @param lb the load balancer config, if {@code null}, round-robin is used.
* @return the created service definition
*/
public static ServiceDefinition of(ConfigWithType sd, ConfigWithType lb) {
return new ServiceDefinition(sd, lb);
return new ServiceDefinition(sd, lb, null);
}

/**
Expand All @@ -49,4 +63,11 @@ public ConfigWithType getLoadBalancer() {
public ConfigWithType getServiceDiscovery() {
return serviceDiscovery;
}

/**
* @return the configured service discovery config.
*/
public ConfigWithType getServiceRegistrar() {
return serviceRegistrar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ default Uni<Void> registerServiceInstance(String serviceName, String ipAddress,
}

Uni<Void> registerServiceInstance(String serviceName, Metadata<MetadataKeyType> metadata, String ipAddress, int port);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.smallrye.stork.api.config;

/**
* Service configuration, wraps both (optional) LoadBalancer configuration and (required) ServiceDiscovery configuration
* Service configuration, wraps (optional) LoadBalancer configuration, (required) ServiceDiscovery configuration and (optional)
* ServiceRegistrar configuration
* for a single service
*/
public interface ServiceConfig {
Expand All @@ -25,6 +26,13 @@ public interface ServiceConfig {
*/
ConfigWithType serviceDiscovery();

/**
* ServiceRegistrar configuration for the service
*
* @return (required) service registrar configuration
*/
ConfigWithType serviceRegistrar();

/**
* Whether the communication should use a secure connection (e.g. HTTPS)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* <p>
* The type is used to determine service registrar.
* <p>
* Use {@code stork.service-registration.my-registration=my-service-registrar} to use the
* Use {@code stork.my-registration.service-registrar.type=my-service-registrar} to use the
* {@link ServiceRegistrarProvider} annotated with {@code @ServiceRegistrar("my-service-registrar")}
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.smallrye.stork.api.MetadataKey;
import io.smallrye.stork.api.ServiceRegistrar;

public interface ServiceRegistrarProvider<ConfigType, MetadataKeyType extends Enum<MetadataKeyType> & MetadataKey> {
ServiceRegistrar<MetadataKeyType> createServiceRegistrar(ConfigType config, String serviceRegistrarName,
public interface ServiceRegistrarProvider<T, MetadataKeyType extends Enum<MetadataKeyType> & MetadataKey> {
ServiceRegistrar<MetadataKeyType> createServiceRegistrar(T config, String serviceRegistrarName,
StorkInfrastructure infrastructure);
}
11 changes: 0 additions & 11 deletions api/src/main/java/io/smallrye/stork/spi/config/ConfigProvider.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.smallrye.stork.spi.config;

import java.util.Collections;
import java.util.List;

import io.smallrye.stork.api.config.ServiceConfig;
import io.smallrye.stork.api.config.ServiceRegistrarConfig;

/**
* Configuration provider for Service Discovery and Load Balancer
Expand All @@ -18,15 +16,6 @@ public interface ConfigProvider {
*/
List<ServiceConfig> getConfigs();

/**
* Get a list of service registrar configurations
*
* @return a list of configurations
*/
default List<ServiceRegistrarConfig> getRegistrarConfigs() {
return Collections.emptyList();
}

/**
* Priority of the configuration provider.
* A single ConfigProvider is used in an application, the one with the highest priority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ public class SimpleServiceConfig implements ServiceConfig {
private final String serviceName;

private final ConfigWithType loadBalancerConfig;
private final ConfigWithType ConfigWithType;
private final ConfigWithType serviceDiscoveryConfig;

private final ConfigWithType serviceRegistrarConfig;

private SimpleServiceConfig(String serviceName,
ConfigWithType loadBalancerConfig,
ConfigWithType ConfigWithType) {
ConfigWithType serviceDiscoveryConfig, ConfigWithType serviceRegistrarConfig) {
this.serviceName = serviceName;
this.loadBalancerConfig = loadBalancerConfig;
this.ConfigWithType = ConfigWithType;
this.serviceDiscoveryConfig = serviceDiscoveryConfig;
this.serviceRegistrarConfig = serviceRegistrarConfig;
}

@Override
Expand All @@ -37,7 +40,12 @@ public ConfigWithType loadBalancer() {

@Override
public ConfigWithType serviceDiscovery() {
return ConfigWithType;
return serviceDiscoveryConfig;
}

@Override
public ConfigWithType serviceRegistrar() {
return serviceRegistrarConfig;
}

/**
Expand All @@ -46,7 +54,9 @@ public ConfigWithType serviceDiscovery() {
public static class Builder {
String serviceName;
ConfigWithType loadBalancerConfig;
ConfigWithType configWithType;
ConfigWithType serviceDiscoveryConfig;

ConfigWithType serviceRegistrarConfig;
boolean secure;

/**
Expand All @@ -63,11 +73,22 @@ public Builder setLoadBalancer(ConfigWithType loadBalancer) {
/**
* Sets the service discovery config.
*
* @param serviceDiscovery the service discovery config
* @param serviceDiscoveryConfig the service discovery config
* @return the current builder
*/
public Builder setServiceDiscovery(ConfigWithType serviceDiscovery) {
configWithType = serviceDiscovery;
public Builder setServiceDiscovery(ConfigWithType serviceDiscoveryConfig) {
this.serviceDiscoveryConfig = serviceDiscoveryConfig;
return this;
}

/**
* Sets the service registrar config.
*
* @param serviceRegistrarConfig the service registrar config
* @return the current builder
*/
public Builder setServiceRegistrar(ConfigWithType serviceRegistrarConfig) {
this.serviceRegistrarConfig = serviceRegistrarConfig;
return this;
}

Expand Down Expand Up @@ -99,7 +120,7 @@ public Builder setSecure(boolean secure) {
* @return the built config
*/
public SimpleServiceConfig build() {
return new SimpleServiceConfig(serviceName, loadBalancerConfig, configWithType);
return new SimpleServiceConfig(serviceName, loadBalancerConfig, serviceDiscoveryConfig, serviceRegistrarConfig);
}
}

Expand Down Expand Up @@ -164,4 +185,34 @@ public Map<String, String> parameters() {
}
}

/**
* An implementation of {@link ConfigWithType} using an unmodifiable {@link Map} as backend to store
* the configuration.
*/
public static class SimpleServiceRegistrarConfig implements ConfigWithType {
private final String type;
private final Map<String, String> parameters;

/**
* Creates a new SimpleServiceRegistrarConfig.
*
* @param type the type
* @param parameters the configuration map
*/
public SimpleServiceRegistrarConfig(String type, Map<String, String> parameters) {
this.type = type;
this.parameters = parameters;
}

@Override
public String type() {
return type;
}

@Override
public Map<String, String> parameters() {
return parameters;
}
}

}
Loading

0 comments on commit 4ce88f2

Please sign in to comment.