Commit 614ec44c by Spencer Gibb

update sidecare enabled property, make eureka portion of config conditional on…

update sidecare enabled property, make eureka portion of config conditional on eureka on classpath so other DiscoveryClient impls can use it.
parent d7898297
...@@ -16,42 +16,53 @@ ...@@ -16,42 +16,53 @@
package org.springframework.cloud.netflix.sidecar; package org.springframework.cloud.netflix.sidecar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.netflix.discovery.EurekaClientConfig;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnProperty(value = "sidecar.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "spring.cloud.netflix.sidecar.enabled", matchIfMissing = true)
public class SidecarConfiguration { public class SidecarConfiguration {
@Value("${server.port:${SERVER_PORT:${PORT:8080}}}")
private int serverPort = 8080;
@Bean @Bean
public SidecarProperties sidecarProperties() { public SidecarProperties sidecarProperties() {
return new SidecarProperties(); return new SidecarProperties();
} }
@Bean @Configuration
public EurekaInstanceConfigBean eurekaInstanceConfigBean() { @ConditionalOnClass(EurekaClientConfig.class)
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(); protected static class EurekaInstanceConfigBeanConfiguration {
int port = sidecarProperties().getPort(); @Autowired
config.setNonSecurePort(port); private SidecarProperties sidecarProperties;
String scheme = config.getSecurePortEnabled() ? "https" : "http";
config.setStatusPageUrl(scheme + "://" + config.getHostname() + ":" @Value("${server.port:${SERVER_PORT:${PORT:8080}}}")
+ this.serverPort + config.getStatusPageUrlPath()); private int serverPort = 8080;
config.setHealthCheckUrl(scheme + "://" + config.getHostname() + ":"
+ this.serverPort + config.getHealthCheckUrlPath()); @Bean
config.setHomePageUrl(scheme + "://" + config.getHostname() + ":" + port public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
+ config.getHomePageUrlPath()); EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
return config; int port = sidecarProperties.getPort();
config.setNonSecurePort(port);
String scheme = config.getSecurePortEnabled() ? "https" : "http";
config.setStatusPageUrl(scheme + "://" + config.getHostname() + ":"
+ this.serverPort + config.getStatusPageUrlPath());
config.setHealthCheckUrl(scheme + "://" + config.getHostname() + ":"
+ this.serverPort + config.getHealthCheckUrlPath());
config.setHomePageUrl(scheme + "://" + config.getHostname() + ":" + port
+ config.getHomePageUrlPath());
return config;
}
} }
@Bean @Bean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment