From cbbd178a5c5609aa2fbc9a96fc4a8bc49b0648cf Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 22 Dec 2015 11:05:42 +0100 Subject: [PATCH] [#3] WIP on Eureka first --- .../scripts/runDockerAcceptanceTests.sh | 3 ++- .../SleuthBreweryAcceptanceSpec.groovy | 3 +-- .../src/main/resources/bootstrap-eureka.yaml | 12 ++++++++++++ .../src/main/resources/bootstrap-eureka.yaml | 6 ++++++ build.gradle | 4 +++- config-server/build.gradle | 1 + .../configserver/EurekaConfiguration.java | 11 +++++++++++ .../src/main/resources/application-eureka.yaml | 12 ++++++++++++ config-server/src/main/resources/application.yml | 2 ++ docker-compose-EUREKA.sh | 10 +++++++++- docker-compose-EUREKA.yml | 16 ++++------------ eureka/src/main/resources/bootstrap.yml | 8 +++++++- .../src/main/resources/bootstrap-eureka.yaml | 6 ++++++ .../src/main/resources/bootstrap-eureka.yaml | 6 ++++++ .../src/main/resources/bootstrap-eureka.yaml | 6 ++++++ zuul/src/main/resources/bootstrap-eureka.yaml | 6 ++++++ 16 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 aggregating/src/main/resources/bootstrap-eureka.yaml create mode 100644 bottling/src/main/resources/bootstrap-eureka.yaml create mode 100644 config-server/src/main/java/io/spring/cloud/samples/brewery/configserver/EurekaConfiguration.java create mode 100644 config-server/src/main/resources/application-eureka.yaml create mode 100644 ingredients/src/main/resources/bootstrap-eureka.yaml create mode 100644 maturing/src/main/resources/bootstrap-eureka.yaml create mode 100644 presenting/src/main/resources/bootstrap-eureka.yaml create mode 100644 zuul/src/main/resources/bootstrap-eureka.yaml diff --git a/acceptance-tests/scripts/runDockerAcceptanceTests.sh b/acceptance-tests/scripts/runDockerAcceptanceTests.sh index fb96a454..c29c780f 100755 --- a/acceptance-tests/scripts/runDockerAcceptanceTests.sh +++ b/acceptance-tests/scripts/runDockerAcceptanceTests.sh @@ -132,10 +132,11 @@ if [[ "${TESTS_PASSED}" == "yes" ]] ; then exit 0 else echo -e "\n\nTests failed..." + NUMBER_OF_LINES_TO_LOG=500 docker ps | sed -n '1!p' > /tmp/containers.txt while read field1 field2 field3; do echo -e "\n\nContainer name [$field2] with id [$field1] logs: \n\n" - docker logs -t $field1 + docker logs --tail=$NUMBER_OF_LINES_TO_LOG -t $field1 done < /tmp/containers.txt exit 1 fi diff --git a/acceptance-tests/src/test/groovy/io/spring/cloud/samples/brewery/acceptance/SleuthBreweryAcceptanceSpec.groovy b/acceptance-tests/src/test/groovy/io/spring/cloud/samples/brewery/acceptance/SleuthBreweryAcceptanceSpec.groovy index f39f3523..d543c132 100644 --- a/acceptance-tests/src/test/groovy/io/spring/cloud/samples/brewery/acceptance/SleuthBreweryAcceptanceSpec.groovy +++ b/acceptance-tests/src/test/groovy/io/spring/cloud/samples/brewery/acceptance/SleuthBreweryAcceptanceSpec.groovy @@ -36,8 +36,7 @@ class SleuthBreweryAcceptanceSpec extends AbstractBreweryAcceptanceSpec { and: 'entry will be present in Zipkin' entry_for_trace_id_is_present_in_Zipkin(referenceProcessId) where: - // will add FEIGN once REST_TEMPLATE tests stabilize - communicationType << [CommunicationType.REST_TEMPLATE] + communicationType << [CommunicationType.REST_TEMPLATE, CommunicationType.FEIGN] referenceProcessId = new JdkIdGenerator().generateId().toString() } diff --git a/aggregating/src/main/resources/bootstrap-eureka.yaml b/aggregating/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..f359f530 --- /dev/null +++ b/aggregating/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,12 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true + serviceId: configserverrr +eureka: + instance: + leaseRenewalIntervalInSeconds: 10 + client: + registryFetchIntervalSeconds: 5 \ No newline at end of file diff --git a/bottling/src/main/resources/bootstrap-eureka.yaml b/bottling/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..6abfaf2d --- /dev/null +++ b/bottling/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,6 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true \ No newline at end of file diff --git a/build.gradle b/build.gradle index 513d34cd..36103b15 100644 --- a/build.gradle +++ b/build.gradle @@ -149,6 +149,8 @@ configure(subprojects - techProjects) { compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" + compile "org.springframework.boot:spring-boot-starter-aop" + compile 'org.springframework.retry:spring-retry' compile "org.springframework:spring-context-support" compile 'com.fasterxml.jackson.core:jackson-databind' if (!whatToTest('CONSUL') && !whatToTest('EUREKA')) { @@ -171,7 +173,7 @@ configure(subprojects - techProjects) { } wrapper { - gradleVersion '2.9' + gradleVersion '2.10' } bootRun { diff --git a/config-server/build.gradle b/config-server/build.gradle index fd3fede6..74d46933 100644 --- a/config-server/build.gradle +++ b/config-server/build.gradle @@ -1,5 +1,6 @@ dependencies { compile "org.springframework.cloud:spring-cloud-config-server" + if (whatToTest('EUREKA')) { compile "org.springframework.cloud:spring-cloud-starter-eureka" } } createDockerTaskWithPort(8888) \ No newline at end of file diff --git a/config-server/src/main/java/io/spring/cloud/samples/brewery/configserver/EurekaConfiguration.java b/config-server/src/main/java/io/spring/cloud/samples/brewery/configserver/EurekaConfiguration.java new file mode 100644 index 00000000..3beef7f9 --- /dev/null +++ b/config-server/src/main/java/io/spring/cloud/samples/brewery/configserver/EurekaConfiguration.java @@ -0,0 +1,11 @@ +package io.spring.cloud.samples.brewery.configserver; + +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration +@Profile("eureka") +@EnableDiscoveryClient +public class EurekaConfiguration { +} diff --git a/config-server/src/main/resources/application-eureka.yaml b/config-server/src/main/resources/application-eureka.yaml new file mode 100644 index 00000000..d68bacb0 --- /dev/null +++ b/config-server/src/main/resources/application-eureka.yaml @@ -0,0 +1,12 @@ +eureka: + client: + registerWithEureka: true + fetchRegistry: true + serviceUrl: + defaultZone: http://discovery:8761/eureka/ + instance: + preferIpAddress: true + +ribbon: + eureka: + enabled: true \ No newline at end of file diff --git a/config-server/src/main/resources/application.yml b/config-server/src/main/resources/application.yml index 45ebe88f..49a352c2 100644 --- a/config-server/src/main/resources/application.yml +++ b/config-server/src/main/resources/application.yml @@ -13,5 +13,7 @@ spring: git: uri: https://github.com/spring-cloud-samples/brewery.git searchPaths: git-props + application: + name: configserverrr spring.zipkin.enabled: false \ No newline at end of file diff --git a/docker-compose-EUREKA.sh b/docker-compose-EUREKA.sh index 0b4ed6af..a74d1094 100755 --- a/docker-compose-EUREKA.sh +++ b/docker-compose-EUREKA.sh @@ -24,13 +24,21 @@ PORT_TO_CHECK=8888 docker-compose -f $dockerComposeFile up -d configserver -echo "Waiting for the Config Server app to boot for [$(( WAIT_TIME * RETRIES ))] seconds" +echo -e "\n\nWaiting for the Config Server app to boot for [$(( WAIT_TIME * RETRIES ))] seconds" for i in $( seq 1 "${RETRIES}" ); do sleep "${WAIT_TIME}" curl -m 5 "${HEALTH_HOST}:${PORT_TO_CHECK}/health" && READY_FOR_TESTS="yes" && break echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds" done +echo -e "\n\nChecking for the presence of config server in Service Discovery for [$(( WAIT_TIME * RETRIES ))] seconds" +for i in $( seq 1 "${RETRIES}" ); do + sleep "${WAIT_TIME}" + curl -m 5 http://localhost:8888/health | grep "\"services\":\[\"configserverrr\"\]" && READY_FOR_TESTS="yes" && break + echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds" +done + + if [[ "${READY_FOR_TESTS}" == "no" ]] ; then echo "Config server failed to start..." exit 1 diff --git a/docker-compose-EUREKA.yml b/docker-compose-EUREKA.yml index be951173..cd82fd07 100644 --- a/docker-compose-EUREKA.yml +++ b/docker-compose-EUREKA.yml @@ -2,10 +2,8 @@ aggregating: build: aggregating/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9992:9992 @@ -13,10 +11,8 @@ maturing: build: maturing/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9993:9993 @@ -24,10 +20,8 @@ bottling: build: bottling/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9994:9994 @@ -35,10 +29,8 @@ presenting: build: presenting/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9991:9991 @@ -46,10 +38,8 @@ zuul: build: zuul/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9995:9995 @@ -57,15 +47,17 @@ ingredients: build: ingredients/build/docker environment: spring.profiles.active: eureka - spring.cloud.config.uri: http://configserver:8888 links: - discovery - - configserver ports: - 9996:9996 configserver: build: config-server/build/docker + environment: + spring.profiles.active: eureka + links: + - discovery ports: - 8888:8888 diff --git a/eureka/src/main/resources/bootstrap.yml b/eureka/src/main/resources/bootstrap.yml index b81b4825..4e3c521b 100644 --- a/eureka/src/main/resources/bootstrap.yml +++ b/eureka/src/main/resources/bootstrap.yml @@ -1,3 +1,9 @@ spring: application: - name: discovery \ No newline at end of file + name: discovery + +eureka: + instance: + leaseRenewalIntervalInSeconds: 10 + client: + registryFetchIntervalSeconds: 5 \ No newline at end of file diff --git a/ingredients/src/main/resources/bootstrap-eureka.yaml b/ingredients/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..6abfaf2d --- /dev/null +++ b/ingredients/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,6 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true \ No newline at end of file diff --git a/maturing/src/main/resources/bootstrap-eureka.yaml b/maturing/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..6abfaf2d --- /dev/null +++ b/maturing/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,6 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true \ No newline at end of file diff --git a/presenting/src/main/resources/bootstrap-eureka.yaml b/presenting/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..6abfaf2d --- /dev/null +++ b/presenting/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,6 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true \ No newline at end of file diff --git a/zuul/src/main/resources/bootstrap-eureka.yaml b/zuul/src/main/resources/bootstrap-eureka.yaml new file mode 100644 index 00000000..6abfaf2d --- /dev/null +++ b/zuul/src/main/resources/bootstrap-eureka.yaml @@ -0,0 +1,6 @@ +#spring.cloud.config.failFast: true +spring: + cloud: + config: + discovery: + enabled: true \ No newline at end of file