Browse Source

updated sidecar so the health and info urls go to sidecar, but homepage and non-secure-port go to local app

pull/6/head
Spencer Gibb 10 years ago
parent
commit
198cb5997b
  1. 5
      spring-cloud-netflix-sidecar/pom.xml
  2. 2
      spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/LocalApplicationHealthIndicator.java
  3. 20
      spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java
  4. 4
      spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarProperties.java
  5. 15
      spring-cloud-netflix-sidecar/src/test/resources/application.yml

5
spring-cloud-netflix-sidecar/pom.xml

@ -73,5 +73,10 @@ @@ -73,5 +73,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

2
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/LocalApplicationHealthIndicator.java

@ -19,7 +19,7 @@ public class LocalApplicationHealthIndicator extends AbstractHealthIndicator { @@ -19,7 +19,7 @@ public class LocalApplicationHealthIndicator extends AbstractHealthIndicator {
@SuppressWarnings("unchecked")
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
URI uri = properties.getLocalHealthUri();
URI uri = properties.getHealthUri();
if (uri == null) {
builder.up();
return;

20
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
package org.springframework.cloud.netflix.sidecar;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -12,12 +14,30 @@ import org.springframework.context.annotation.Configuration; @@ -12,12 +14,30 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties
@ConditionalOnExpression("${sidecar.enabled:true}")
public class SidecarConfiguration {
@Value("${server.port:${SERVER_PORT:${PORT:8080}}}")
private int serverPort = 8080;
@Bean
public SidecarProperties sidecarProperties() {
return new SidecarProperties();
}
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
int port = sidecarProperties().getPort();
config.setNonSecurePort(port);
String scheme = config.getSecurePortEnabled()? "https" : "http";
config.setStatusPageUrl(scheme + "://" + config.getHostname() + ":" + serverPort + config.getStatusPageUrlPath());
config.setHealthCheckUrl(scheme + "://" + config.getHostname() + ":" + serverPort + config.getHealthCheckUrlPath());
config.setHomePageUrl(scheme + "://" + config.getHostname() + ":" + port + config.getHomePageUrlPath());
return config;
}
@Bean
public LocalApplicationHealthIndicator localApplicationHealthIndicator() {
return new LocalApplicationHealthIndicator();

4
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarProperties.java

@ -11,5 +11,7 @@ import java.net.URI; @@ -11,5 +11,7 @@ import java.net.URI;
@Data
@ConfigurationProperties("sidecar")
public class SidecarProperties {
private URI localHealthUri;
private URI healthUri;
private URI homePageUri;
private int port;
}

15
spring-cloud-netflix-sidecar/src/test/resources/application.yml

@ -5,7 +5,20 @@ spring: @@ -5,7 +5,20 @@ spring:
name: sidecarTest
sidecar:
local-health-uri: http://localhost:8081/health
port: 8000
health-uri: http://localhost:8000/src/test/resources/health.json
eureka:
instance:
app-group-name: mysidecargroup
endpoints:
refresh:
enabled: true
shutdown:
enabled: true
health:
sensitive: false
zuul:
proxy:

Loading…
Cancel
Save