diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java index 8a0dc51..8860ca2 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java @@ -42,7 +42,7 @@ public class CloudFoundryDiscoveryClientConfiguration { @Bean @ConditionalOnBean(CloudFoundryDiscoveryClient.class) public CloudFoundryHeartbeatSender cloudFoundryHeartbeatSender( - CloudFoundryDiscoveryClient client) { + CloudFoundryDiscoveryClient client) { return new CloudFoundryHeartbeatSender(client); } @@ -67,21 +67,22 @@ public class CloudFoundryDiscoveryClientConfiguration { @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true") @ConditionalOnMissingBean(DiscoveryClient.class) public SimpleDnsBasedDiscoveryClient discoveryClient( - ObjectProvider provider) { + ObjectProvider provider, + CloudFoundryDiscoveryProperties properties) { ServiceIdToHostnameConverter converter = provider.getIfAvailable(); - return converter == null ? new SimpleDnsBasedDiscoveryClient() - : new SimpleDnsBasedDiscoveryClient(converter); + return converter == null ? new SimpleDnsBasedDiscoveryClient(properties) + : new SimpleDnsBasedDiscoveryClient(properties, converter); } @Bean @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false", matchIfMissing = true) @ConditionalOnMissingBean(DiscoveryClient.class) - public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf, - CloudFoundryService svc, - CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) { - return new CloudFoundryAppServiceDiscoveryClient(cf, svc, - cloudFoundryDiscoveryProperties); + public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient( + CloudFoundryOperations cf, CloudFoundryService svc, + CloudFoundryDiscoveryProperties properties) { + return new CloudFoundryAppServiceDiscoveryClient(cf, svc, properties); } + } } diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java index 315b791..d70ce81 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryProperties.java @@ -17,6 +17,7 @@ package org.springframework.cloud.cloudfoundry.discovery; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.style.ToStringCreator; /** * @author Josh Long @@ -46,6 +47,11 @@ public class CloudFoundryDiscoveryProperties { */ private int order = 0; + /** + * Default internal domain when configured to use Native DNS service discovery. + */ + private String internalDomain = "apps.internal"; + public boolean isEnabled() { return this.enabled; } @@ -78,12 +84,25 @@ public class CloudFoundryDiscoveryProperties { this.order = order; } + public String getInternalDomain() { + return this.internalDomain; + } + + public void setInternalDomain(String internalDomain) { + this.internalDomain = internalDomain; + } + @Override public String toString() { - return "CloudFoundryDiscoveryProperties{" + "enabled=" + this.enabled - + ", heartbeatFrequency=" + this.heartbeatFrequency - + ", defaultServerPort=" + this.defaultServerPort + ", order=" - + this.order + '}'; + // @formatter:off + return new ToStringCreator(this) + .append("enabled", enabled) + .append("heartbeatFrequency", heartbeatFrequency) + .append("defaultServerPort", defaultServerPort) + .append("order", order) + .append("internalDomain", internalDomain) + .toString(); + // @formatter:on } } diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java index dd0f542..8ad2e08 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/SimpleDnsBasedDiscoveryClient.java @@ -34,27 +34,24 @@ import org.springframework.cloud.client.discovery.DiscoveryClient; * Discovery. * * @author Toshiaki Maki - * * @see Polyglot * Service Discovery for Container Networking in Cloud Foundry */ public class SimpleDnsBasedDiscoveryClient implements DiscoveryClient { - public static final String INTERNAL_DOMAIN = "apps.internal"; - private final Logger log = LoggerFactory + + private static final Logger log = LoggerFactory .getLogger(SimpleDnsBasedDiscoveryClient.class); + private final ServiceIdToHostnameConverter serviceIdToHostnameConverter; - private static final ServiceIdToHostnameConverter DEFAULT_CONVERTER = serviceId -> serviceId - + "." + INTERNAL_DOMAIN; - - public SimpleDnsBasedDiscoveryClient( + public SimpleDnsBasedDiscoveryClient(CloudFoundryDiscoveryProperties properties, ServiceIdToHostnameConverter serviceIdToHostnameConverter) { this.serviceIdToHostnameConverter = serviceIdToHostnameConverter; } - public SimpleDnsBasedDiscoveryClient() { - this(DEFAULT_CONVERTER); + public SimpleDnsBasedDiscoveryClient(CloudFoundryDiscoveryProperties properties) { + this(properties, serviceId -> serviceId + "." + properties.getInternalDomain()); } @Override @@ -91,6 +88,9 @@ public class SimpleDnsBasedDiscoveryClient implements DiscoveryClient { @FunctionalInterface public interface ServiceIdToHostnameConverter { + String toHostname(String serviceId); + } + }