├── .java-version ├── docs ├── src │ └── main │ │ ├── asciidoc │ │ ├── sagan-boot.adoc │ │ ├── images │ │ │ ├── Hystrix.png │ │ │ ├── HystrixGraph.png │ │ │ ├── HystrixFallback.png │ │ │ └── RequestLatency.png │ │ ├── README.adoc │ │ └── sagan-index.adoc │ │ └── antora │ │ └── resources │ │ └── antora-resources │ │ └── antora.yml ├── modules │ └── ROOT │ │ ├── pages │ │ ├── index.adoc │ │ ├── configprops.adoc │ │ ├── _attributes.adoc │ │ ├── intro.adoc │ │ └── appendix.adoc │ │ ├── assets │ │ └── images │ │ │ ├── Hystrix.png │ │ │ ├── HystrixGraph.png │ │ │ ├── HystrixFallback.png │ │ │ └── RequestLatency.png │ │ └── nav.adoc ├── package.json ├── antora.yml ├── antora-playbook.yml └── pom.xml ├── .github ├── dco.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── ISSUE_TEMPLATE.md ├── workflows │ ├── deploy-docs.yml │ └── maven.yml ├── dependabot.yml └── CONTRIBUTING.md ├── .mvn ├── jvm.config ├── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties └── maven.config ├── spring-cloud-netflix-eureka-server └── src │ ├── main │ ├── resources │ │ ├── eureka │ │ │ └── server.properties │ │ ├── static │ │ │ └── eureka │ │ │ │ ├── images │ │ │ │ ├── 404-icon.png │ │ │ │ ├── homepage-bg.jpg │ │ │ │ ├── platform-bg.png │ │ │ │ ├── platform-spring-xd.png │ │ │ │ ├── spring-logo-eureka.png │ │ │ │ └── spring-logo-eureka-mobile.png │ │ │ │ └── fonts │ │ │ │ ├── montserrat-webfont.eot │ │ │ │ ├── montserrat-webfont.ttf │ │ │ │ ├── montserrat-webfont.woff │ │ │ │ ├── varela_round-webfont.eot │ │ │ │ ├── varela_round-webfont.ttf │ │ │ │ └── varela_round-webfont.woff │ │ ├── META-INF │ │ │ ├── additional-spring-configuration-metadata.json │ │ │ └── spring │ │ │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ │ └── templates │ │ │ └── eureka │ │ │ ├── header.ftlh │ │ │ ├── navbar.ftlh │ │ │ └── lastn.ftlh │ ├── wro │ │ ├── wro.properties │ │ ├── wro.xml │ │ ├── responsive.css │ │ ├── header.css │ │ ├── typography.css │ │ └── main.css │ └── java │ │ └── org │ │ └── springframework │ │ └── cloud │ │ └── netflix │ │ └── eureka │ │ └── server │ │ ├── metrics │ │ ├── EurekaInstanceTagsProvider.java │ │ ├── DefaultEurekaInstanceTagsProvider.java │ │ └── EurekaInstanceMetricsAutoConfiguration.java │ │ ├── event │ │ ├── EurekaServerStartedEvent.java │ │ ├── EurekaRegistryAvailableEvent.java │ │ ├── EurekaInstanceCanceledEvent.java │ │ ├── EurekaInstanceRegisteredEvent.java │ │ └── EurekaInstanceRenewedEvent.java │ │ ├── EurekaServerMarkerConfiguration.java │ │ ├── ReplicationClientAdditionalFilters.java │ │ ├── EnableEurekaServer.java │ │ ├── EurekaDashboardProperties.java │ │ ├── EurekaProperties.java │ │ ├── InstanceRegistryProperties.java │ │ └── EurekaServerJerseyClientAutoConfiguration.java │ └── test │ ├── resources │ └── application.properties │ └── java │ └── org │ └── springframework │ └── cloud │ └── netflix │ └── eureka │ └── server │ ├── EurekaInstanceFixture.java │ ├── EurekaServerInitializerConfigurationTest.java │ ├── ApplicationDashboardDisabledTests.java │ ├── EurekaServerRefreshDisabledTests.java │ ├── ApplicationDashboardPathTests.java │ └── EurekaCustomPeerNodesTests.java ├── .sdkmanrc ├── spring-cloud-netflix-eureka-client └── src │ ├── test │ ├── resources │ │ ├── application.yml │ │ └── bootstrapper.yaml │ └── java │ │ └── org │ │ └── springframework │ │ └── cloud │ │ └── netflix │ │ └── eureka │ │ ├── sample │ │ ├── ApplicationTests.java │ │ └── RefreshEurekaSampleApplication.java │ │ ├── support │ │ └── ZoneUtilsTests.java │ │ ├── EurekaServiceInstanceTests.java │ │ ├── config │ │ ├── JerseyOptionalArgsConfigurationApplicationTests.java │ │ ├── EurekaConfigServerBootstrapConfigurationRestClientTests.java │ │ ├── EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests.java │ │ ├── JerseyClientOptionalArgsConfigurationTests.java │ │ ├── ConfigRefreshTests.java │ │ ├── EurekaHttpClientsOptionalArgsConfigurationTests.java │ │ ├── EurekaConfigServerBootstrapConfigurationWebClientTests.java │ │ ├── EurekaClientConfigServerAutoConfigurationTests.java │ │ └── EurekaConfigServerBootstrapConfigurationRestClientIntegrationTests.java │ │ ├── EurekaClientAutoConfigurationRandomPortTests.java │ │ ├── EurekaDiscoveryClientTests.java │ │ ├── http │ │ ├── RestClientTransportClientFactoryTests.java │ │ └── WebClientEurekaHttpClientTests.java │ │ ├── healthcheck │ │ └── EurekaHealthCheckTests.java │ │ ├── InstanceInfoFactoryTests.java │ │ ├── ConditionalOnRefreshScopeTests.java │ │ └── loadbalancer │ │ └── EurekaLoadBalancerClientConfigurationTests.java │ └── main │ ├── resources │ └── META-INF │ │ ├── spring │ │ ├── aot.factories │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ │ ├── spring.factories │ │ └── additional-spring-configuration-metadata.json │ └── java │ └── org │ └── springframework │ └── cloud │ └── netflix │ └── eureka │ ├── config │ ├── EurekaTlsProperties.java │ ├── EurekaClientConfigServerAutoConfiguration.java │ └── HostnameBasedUrlRandomizer.java │ ├── CloudEurekaInstanceConfig.java │ ├── EurekaConstants.java │ ├── metadata │ ├── ManagementMetadataProvider.java │ └── ManagementMetadata.java │ ├── http │ ├── WebClientDiscoveryClientOptionalArgs.java │ ├── EurekaApplications.java │ ├── EurekaClientHttpRequestFactorySupplier.java │ ├── NotFoundHttpResponse.java │ ├── RestClientDiscoveryClientOptionalArgs.java │ ├── WebClientTransportClientFactories.java │ └── RestClientTransportClientFactories.java │ ├── support │ └── ZoneUtils.java │ ├── loadbalancer │ ├── EurekaLoadBalancerProperties.java │ └── LoadBalancerEurekaAutoConfiguration.java │ ├── reactive │ └── EurekaReactiveDiscoveryClient.java │ ├── TimeoutProperties.java │ ├── EurekaDiscoveryClient.java │ └── EurekaServiceInstance.java ├── scripts ├── compileOnly.sh └── runAcceptanceTests.sh ├── .editorconfig ├── .gitignore ├── src └── checkstyle │ └── checkstyle-suppressions.xml ├── spring-cloud-netflix-eureka-client-tls-tests └── src │ └── test │ └── java │ └── org │ └── springframework │ └── cloud │ └── netflix │ └── eureka │ ├── EurekaClientSuite.java │ ├── EurekaServerRunner.java │ ├── KeyAndCert.java │ └── EurekaClientTests.java ├── spring-cloud-starter-netflix-eureka-server └── pom.xml ├── .settings.xml └── spring-cloud-starter-netflix-eureka-client └── pom.xml /.java-version: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /docs/src/main/asciidoc/sagan-boot.adoc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/dco.yml: -------------------------------------------------------------------------------- 1 | require: 2 | members: false -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/index.adoc: -------------------------------------------------------------------------------- 1 | include::intro.adoc[] -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/eureka/server.properties: -------------------------------------------------------------------------------- 1 | server.servlet.encoding.force=false 2 | 3 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.sdkmanrc: -------------------------------------------------------------------------------- 1 | # Enable auto-env through the sdkman_auto_env config 2 | # Add key=value pairs of SDKs to use below 3 | java=17.0.1-tem 4 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local 2 | -P spring 3 | -------------------------------------------------------------------------------- /docs/src/main/asciidoc/images/Hystrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/src/main/asciidoc/images/Hystrix.png -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/Hystrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/modules/ROOT/assets/images/Hystrix.png -------------------------------------------------------------------------------- /docs/src/main/asciidoc/images/HystrixGraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/src/main/asciidoc/images/HystrixGraph.png -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/HystrixGraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/modules/ROOT/assets/images/HystrixGraph.png -------------------------------------------------------------------------------- /docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[Introduction] 2 | * xref:spring-cloud-netflix.adoc[] 3 | * xref:appendix.adoc[] 4 | ** xref:configprops.adoc[] 5 | 6 | -------------------------------------------------------------------------------- /docs/src/main/asciidoc/images/HystrixFallback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/src/main/asciidoc/images/HystrixFallback.png -------------------------------------------------------------------------------- /docs/src/main/asciidoc/images/RequestLatency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/src/main/asciidoc/images/RequestLatency.png -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/HystrixFallback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/modules/ROOT/assets/images/HystrixFallback.png -------------------------------------------------------------------------------- /docs/modules/ROOT/assets/images/RequestLatency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/docs/modules/ROOT/assets/images/RequestLatency.png -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | security: 3 | basic: 4 | enabled: false 5 | user: 6 | name: test 7 | password: test -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/wro.properties: -------------------------------------------------------------------------------- 1 | #List of preProcessors 2 | preProcessors=cssImport 3 | 4 | #List of postProcessors 5 | postProcessors=jsMin -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/aot.factories: -------------------------------------------------------------------------------- 1 | org.springframework.aot.hint.RuntimeHintsRegistrar=\ 2 | org.springframework.cloud.netflix.eureka.EurekaClientHints -------------------------------------------------------------------------------- /scripts/compileOnly.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | 5 | (cd spring-cloud-netflix-hystrix-contract && ../mvnw clean install -B -Pdocs -DskipTests) 6 | ./mvnw clean install -B -Pdocs -DskipTests -fae 7 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/configprops.adoc: -------------------------------------------------------------------------------- 1 | [[configuration-properties]] 2 | = Configuration Properties 3 | 4 | Below you can find a list of configuration properties. 5 | 6 | include::partial$_configprops.adoc[] 7 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/404-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/404-icon.png -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/homepage-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/homepage-bg.jpg -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/platform-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/platform-bg.png -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.eot -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.ttf -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/montserrat-webfont.woff -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/platform-spring-xd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/platform-spring-xd.png -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/spring-logo-eureka.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/spring-logo-eureka.png -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.eot -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.ttf -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/fonts/varela_round-webfont.woff -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/spring-logo-eureka-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/HEAD/spring-cloud-netflix-eureka-server/src/main/resources/static/eureka/images/spring-logo-eureka-mobile.png -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/_attributes.adoc: -------------------------------------------------------------------------------- 1 | :doctype: book 2 | :idprefix: 3 | :idseparator: - 4 | :tabsize: 4 5 | :numbered: 6 | :sectanchors: 7 | :sectnums: 8 | :icons: font 9 | :hide-uri-scheme: 10 | :docinfo: shared,private 11 | 12 | :sc-ext: java 13 | :project-full-name: Spring Cloud Netflix 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root=true 2 | 3 | [*.java] 4 | indent_style = tab 5 | indent_size = 4 6 | continuation_indent_size = 8 7 | 8 | [*.groovy] 9 | indent_style = tab 10 | indent_size = 4 11 | continuation_indent_size = 8 12 | 13 | [*.xml] 14 | indent_style = tab 15 | indent_size = 4 16 | continuation_indent_size = 8 -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8761 2 | spring.application.name=eureka 3 | eureka.client.registerWithEureka=false 4 | eureka.client.fetchRegistry=false 5 | logging.level.org.springframework.web.client=DEBUG 6 | logging.level.com.netflix.discovery=DEBUG 7 | 8 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "antora": "3.2.0-alpha.11", 4 | "@antora/atlas-extension": "1.0.0-alpha.5", 5 | "@antora/collector-extension": "1.0.2", 6 | "@asciidoctor/tabs": "1.0.0-beta.6", 7 | "@springio/antora-extensions": "1.14.7", 8 | "@springio/asciidoctor-extensions": "1.0.0-alpha.17" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/resources/bootstrapper.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | config: 3 | import: "optional:configserver:" 4 | cloud: 5 | config: 6 | enabled: true 7 | discovery: 8 | service-id: eureka-configserver 9 | enabled: true 10 | service-registry: 11 | auto-registration: 12 | enabled: false -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.cloud.bootstrap.BootstrapConfiguration=\ 2 | org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapConfiguration 3 | 4 | org.springframework.boot.bootstrap.BootstrapRegistryInitializer=\ 5 | org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapper 6 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "eureka.server.metrics.enabled", 5 | "type": "java.lang.Boolean", 6 | "defaultValue": "false", 7 | "description": "Indicates whether the metrics should be enabled for eureka instances." 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/wro.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | webjar:bootstrap/5.1.3/dist/css/bootstrap.min.css 4 | file:@.project.basedir.@/src/main/wro/main.css 5 | webjar:jquery/3.6.0/jquery.min.js 6 | webjar:bootstrap/5.1.3/dist/js/bootstrap.min.js 7 | 8 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration 2 | org.springframework.cloud.netflix.eureka.server.EurekaServerJerseyClientAutoConfiguration 3 | org.springframework.cloud.netflix.eureka.server.metrics.EurekaInstanceMetricsAutoConfiguration 4 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/intro.adoc: -------------------------------------------------------------------------------- 1 | [[introduction]] 2 | = Spring Cloud Netflix 3 | 4 | This project provides Netflix OSS integrations for Spring Boot apps through autoconfiguration 5 | and binding to the Spring Environment and other Spring programming model idioms. With a few 6 | simple annotations you can quickly enable and configure the common patterns inside your 7 | application and build large distributed systems with battle-tested Netflix components. The 8 | patterns provided include Service Discovery (Eureka). 9 | 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: waiting-for-triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | Please provide details of the problem, including the version of Spring Cloud that you 12 | are using. 13 | 14 | **Sample** 15 | If possible, please provide a test case or sample application that reproduces 16 | the problem. This makes it much easier for us to diagnose the problem and to verify that 17 | we have fixed it. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /application.yml 2 | /application.properties 3 | asciidoctor.css 4 | *~ 5 | #* 6 | *# 7 | .#* 8 | .classpath 9 | .project 10 | .settings/ 11 | .settings 12 | .springBeans 13 | target/ 14 | bin/ 15 | _site/ 16 | .idea 17 | *.iml 18 | *.ipr 19 | *.iws 20 | .factorypath 21 | *.log 22 | .shelf 23 | *.swp 24 | *.swo 25 | /spring-cloud-release-tools*.jar 26 | antrun 27 | .vscode/ 28 | .flattened-pom.xml 29 | node 30 | node_modules 31 | build 32 | _configprops.adoc 33 | _spans.adoc 34 | _metrics.adoc 35 | _conventions.adoc 36 | /package.json 37 | package-lock.json 38 | -------------------------------------------------------------------------------- /docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: cloud-netflix 2 | version: true 3 | title: Spring Cloud Netflix 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | ext: 7 | collector: 8 | run: 9 | command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests -DdisableConfigurationProperties 10 | local: true 11 | scan: 12 | dir: ./target/classes/antora-resources/ 13 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration 2 | org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration 3 | org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration 4 | org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration 5 | org.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration 6 | org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/appendix.adoc: -------------------------------------------------------------------------------- 1 | :numbered!: 2 | [appendix] 3 | [[common-application-properties]] 4 | = Common application properties 5 | :page-section-summary-toc: 1 6 | 7 | 8 | Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches. 9 | This appendix provides a list of common Spring Cloud Netflix properties and references to the underlying classes that consume them. 10 | 11 | NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list. 12 | Also, you can define your own properties. 13 | 14 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/responsive.css: -------------------------------------------------------------------------------- 1 | @media (max-width: 768px) { 2 | .navbar a.navbar-brand { 3 | background: url("../images/spring-logo-eureka-mobile.png") 0 center no-repeat; 4 | } 5 | .homepage-billboard .homepage-subtitle { 6 | font-size: 21px; 7 | line-height: 21px; 8 | } 9 | .navbar a.navbar-brand span { 10 | display: none; 11 | } 12 | .navbar { 13 | border-top-width: 0; 14 | } 15 | .xd-container { 16 | margin-top: 20px; 17 | margin-bottom: 30px; 18 | } 19 | .index-page--subtitle { 20 | margin-top: 10px; 21 | margin-bottom: 30px; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /scripts/runAcceptanceTests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | 5 | mkdir -p target 6 | 7 | SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/3.1.x/runAcceptanceTests.sh" 8 | AT_WHAT_TO_TEST="EUREKA" 9 | 10 | cd target 11 | 12 | curl "${SCRIPT_URL}" --output runAcceptanceTests.sh 13 | 14 | chmod +x runAcceptanceTests.sh 15 | 16 | echo "Killing all running apps" 17 | ./runAcceptanceTests.sh -t "${AT_WHAT_TO_TEST}" --killnow 18 | 19 | ./runAcceptanceTests.sh -t "${AT_WHAT_TO_TEST}" --killattheend 20 | 21 | SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/tests/main/scripts/runTests.sh" 22 | 23 | curl "${SCRIPT_URL}" --output runIntegrationTests.sh 24 | 25 | chmod +x runIntegrationTests.sh 26 | 27 | ./runIntegrationTests.sh 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 21 | -------------------------------------------------------------------------------- /docs/antora-playbook.yml: -------------------------------------------------------------------------------- 1 | antora: 2 | extensions: 3 | - require: '@springio/antora-extensions' 4 | root_component_name: 'cloud-netflix' 5 | site: 6 | title: Spring Cloud Netflix 7 | url: https://docs.spring.io/spring-cloud-netflix/reference/ 8 | content: 9 | sources: 10 | - url: ./.. 11 | branches: HEAD 12 | start_path: docs 13 | worktrees: true 14 | asciidoc: 15 | attributes: 16 | page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud 17 | page-pagination: '' 18 | hide-uri-scheme: '@' 19 | tabs-sync-option: '@' 20 | chomp: 'all' 21 | extensions: 22 | - '@asciidoctor/tabs' 23 | - '@springio/asciidoctor-extensions' 24 | sourcemap: true 25 | urls: 26 | latest_version_segment: '' 27 | runtime: 28 | log: 29 | failure_level: warn 30 | format: pretty 31 | ui: 32 | bundle: 33 | url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.15/ui-bundle.zip 34 | -------------------------------------------------------------------------------- /docs/src/main/antora/resources/antora-resources/antora.yml: -------------------------------------------------------------------------------- 1 | version: @antora-component.version@ 2 | prerelease: @antora-component.prerelease@ 3 | 4 | asciidoc: 5 | attributes: 6 | attribute-missing: 'warn' 7 | chomp: 'all' 8 | project-root: @maven.multiModuleProjectDirectory@ 9 | github-repo: @docs.main@ 10 | github-raw: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ 11 | github-code: https://github.com/spring-cloud/@docs.main@/tree/@github-tag@ 12 | github-issues: https://github.com/spring-cloud/@docs.main@/issues/ 13 | github-wiki: https://github.com/spring-cloud/@docs.main@/wiki 14 | spring-cloud-version: @project.version@ 15 | github-tag: @github-tag@ 16 | version-type: @version-type@ 17 | docs-url: https://docs.spring.io/@docs.main@/docs/@project.version@ 18 | raw-docs-url: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ 19 | project-version: @project.version@ 20 | project-name: @docs.main@ 21 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/templates/eureka/header.ftlh: -------------------------------------------------------------------------------- 1 | <#import "/spring.ftl" as spring /> 2 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip 18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar 19 | -------------------------------------------------------------------------------- /.github/workflows/deploy-docs.yml: -------------------------------------------------------------------------------- 1 | name: Deploy Docs 2 | on: 3 | push: 4 | branches-ignore: [ gh-pages ] 5 | tags: '**' 6 | repository_dispatch: 7 | types: request-build-reference # legacy 8 | #schedule: 9 | #- cron: '0 10 * * *' # Once per day at 10am UTC 10 | workflow_dispatch: 11 | permissions: 12 | actions: write 13 | jobs: 14 | build: 15 | runs-on: ubuntu-latest 16 | # if: github.repository_owner == 'spring-cloud' 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v6 20 | with: 21 | ref: docs-build 22 | fetch-depth: 1 23 | - name: Dispatch (partial build) 24 | if: github.ref_type == 'branch' 25 | env: 26 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }} 28 | - name: Dispatch (full build) 29 | if: github.ref_type == 'tag' 30 | env: 31 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) 33 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaTlsProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.springframework.cloud.configuration.TlsProperties; 20 | 21 | /** 22 | * Eureka client TLS properties. 23 | */ 24 | 25 | public class EurekaTlsProperties extends TlsProperties { 26 | 27 | /** 28 | * Prefix for Eureka client TLS properties. 29 | */ 30 | public static final String PREFIX = "eureka.client.tls"; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceTagsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.metrics; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import io.micrometer.core.instrument.Tags; 21 | 22 | /** 23 | * Provides {@link Tags} for Eureka instance metrics. 24 | * 25 | * @author Wonchul Heo 26 | * @since 4.1.2 27 | */ 28 | public interface EurekaInstanceTagsProvider { 29 | 30 | Tags eurekaInstanceTags(InstanceInfo instanceInfo); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/CloudEurekaInstanceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import com.netflix.appinfo.EurekaInstanceConfig; 20 | import com.netflix.appinfo.InstanceInfo; 21 | 22 | /** 23 | * @author Spencer Gibb 24 | */ 25 | public interface CloudEurekaInstanceConfig extends EurekaInstanceConfig { 26 | 27 | void setNonSecurePort(int port); 28 | 29 | void setSecurePort(int securePort); 30 | 31 | InstanceInfo.InstanceStatus getInitialStatus(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | /** 20 | * Class containing Eureka-specific constants. 21 | * 22 | * @author Spencer Gibb 23 | */ 24 | public final class EurekaConstants { 25 | 26 | /** 27 | * Default Eureka prefix. 28 | */ 29 | public static final String DEFAULT_PREFIX = "/eureka"; 30 | 31 | private EurekaConstants() { 32 | throw new AssertionError("Must not instantiate constant utility class"); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/ManagementMetadataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.metadata; 18 | 19 | import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; 20 | 21 | /** 22 | * Provider for Eureka-specific management metadata. 23 | * 24 | * @author Anastasiia Smirnova 25 | */ 26 | public interface ManagementMetadataProvider { 27 | 28 | ManagementMetadata get(EurekaInstanceConfigBean instance, int serverPort, String serverContextPath, 29 | String managementContextPath, Integer managementPort); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.sample; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.test.context.SpringBootTest; 22 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 23 | import org.springframework.test.annotation.DirtiesContext; 24 | 25 | @SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) 26 | @DirtiesContext 27 | class ApplicationTests { 28 | 29 | @Test 30 | void contextLoads() { 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientDiscoveryClientOptionalArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.function.Supplier; 20 | 21 | import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; 22 | 23 | import org.springframework.web.reactive.function.client.WebClient; 24 | 25 | /** 26 | * @author Daniel Lavoie 27 | * @author Haytham Mohamed 28 | */ 29 | public class WebClientDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs { 30 | 31 | public WebClientDiscoveryClientOptionalArgs(Supplier builder) { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaServerStartedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.event; 18 | 19 | import com.netflix.eureka.EurekaServerConfig; 20 | 21 | import org.springframework.context.ApplicationEvent; 22 | 23 | /** 24 | * @author Dave Syer 25 | */ 26 | @SuppressWarnings("serial") 27 | public class EurekaServerStartedEvent extends ApplicationEvent { 28 | 29 | /** 30 | * @param eurekaServerConfig {@link EurekaServerConfig} event source 31 | */ 32 | public EurekaServerStartedEvent(EurekaServerConfig eurekaServerConfig) { 33 | super(eurekaServerConfig); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaRegistryAvailableEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.event; 18 | 19 | import com.netflix.eureka.EurekaServerConfig; 20 | 21 | import org.springframework.context.ApplicationEvent; 22 | 23 | /** 24 | * @author Dave Syer 25 | */ 26 | @SuppressWarnings("serial") 27 | public class EurekaRegistryAvailableEvent extends ApplicationEvent { 28 | 29 | /** 30 | * @param eurekaServerConfig {@link EurekaServerConfig} event source 31 | */ 32 | public EurekaRegistryAvailableEvent(EurekaServerConfig eurekaServerConfig) { 33 | super(eurekaServerConfig); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/support/ZoneUtilsTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.support; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | 23 | /** 24 | * @author Ryan Baxter 25 | * 26 | */ 27 | class ZoneUtilsTests { 28 | 29 | @Test 30 | void extractApproximateZoneTest() { 31 | assertThat("foo".equals(ZoneUtils.extractApproximateZone("foo"))).isTrue(); 32 | assertThat("bar".equals(ZoneUtils.extractApproximateZone("foo.bar"))).isTrue(); 33 | assertThat("world.foo.bar".equals(ZoneUtils.extractApproximateZone("hello.world.foo.bar"))).isTrue(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/checkstyle/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 21 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerMarkerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | /** 23 | * Responsible for adding in a marker bean to activate 24 | * {@link EurekaServerAutoConfiguration}. 25 | * 26 | * @author Biju Kunjummen 27 | */ 28 | @Configuration(proxyBeanMethods = false) 29 | public class EurekaServerMarkerConfiguration { 30 | 31 | @Bean 32 | public Marker eurekaServerMarkerBean() { 33 | return new Marker(); 34 | } 35 | 36 | class Marker { 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /docs/src/main/asciidoc/README.adoc: -------------------------------------------------------------------------------- 1 | 2 | image::https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml/badge.svg?branch=main&style=svg["Build",link="https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml"] 3 | 4 | image:https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main/graph/badge.svg["Codecov", link="https://app.codecov.io/gh/spring-cloud/spring-cloud-netflix/tree/main"] 5 | 6 | 7 | [[features]] 8 | == Features 9 | 10 | * Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans 11 | * Service Discovery: an embedded Eureka server can be created with declarative Java configuration 12 | 13 | 14 | [[building]] 15 | == Building 16 | 17 | include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[] 18 | 19 | NOTE: To build the module `spring-cloud-netflix-hystrix-contract` along with the entire Netflix project run the 20 | `build.sh` script in the `scripts` directory. 21 | 22 | [[contributing]] 23 | == Contributing 24 | 25 | include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing-docs.adoc[] 26 | 27 | [[license]] 28 | == License 29 | 30 | The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here]. 31 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstanceTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import org.assertj.core.api.Assertions; 21 | import org.junit.jupiter.api.Test; 22 | 23 | class EurekaServiceInstanceTests { 24 | 25 | @Test 26 | void getSchemeReturnsNonNull() { 27 | InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder() 28 | .setAppName("test") 29 | .setHostName("myhost") 30 | .setPort(8080) 31 | .build(); 32 | EurekaServiceInstance instance = new EurekaServiceInstance(instanceInfo); 33 | Assertions.assertThat(instance.getScheme()).isEqualTo("http"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "defaultValue": true, 5 | "name": "eureka.client.healthcheck.enabled", 6 | "description": "Enables the Eureka health check handler.", 7 | "type": "java.lang.Boolean" 8 | }, 9 | { 10 | "defaultValue": true, 11 | "name": "eureka.client.refresh.enable", 12 | "description": "Determines whether the EurekaClient instance can be refreshed or not(If disabled none of the Eureka client properties will be refreshable).", 13 | "type": "java.lang.Boolean" 14 | }, 15 | { 16 | "defaultValue": false, 17 | "name": "eureka.client.webclient.enabled", 18 | "description": "Enables the use of WebClient for Eureka HTTP Client.", 19 | "type": "java.lang.Boolean" 20 | }, 21 | { 22 | "defaultValue": true, 23 | "name": "eureka.client.jersey.enabled", 24 | "description": "Enables the use of JerseyClient for Eureka HTTP Client.", 25 | "type": "java.lang.Boolean" 26 | }, 27 | { 28 | "defaultValue": 1, 29 | "name": "eureka.instance.metadata-map.weight", 30 | "description": "The weight of service instance for weighted load balancing.", 31 | "type": "java.lang.Integer", 32 | "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/ReplicationClientAdditionalFilters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Collection; 20 | import java.util.LinkedHashSet; 21 | 22 | import jakarta.ws.rs.client.ClientRequestFilter; 23 | 24 | /** 25 | * @author Yuxin Bai 26 | */ 27 | public class ReplicationClientAdditionalFilters { 28 | 29 | private final Collection filters; 30 | 31 | public ReplicationClientAdditionalFilters(Collection filters) { 32 | this.filters = new LinkedHashSet<>(filters); 33 | } 34 | 35 | public Collection getFilters() { 36 | return this.filters; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/DefaultEurekaInstanceTagsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.metrics; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import io.micrometer.core.instrument.Tag; 21 | import io.micrometer.core.instrument.Tags; 22 | 23 | /** 24 | * Default implementation for {@link EurekaInstanceTagsProvider}. 25 | * 26 | * @author Wonchul Heo 27 | * @since 4.1.2 28 | */ 29 | class DefaultEurekaInstanceTagsProvider implements EurekaInstanceTagsProvider { 30 | 31 | @Override 32 | public Tags eurekaInstanceTags(InstanceInfo instanceInfo) { 33 | return Tags.of(Tag.of("application", instanceInfo.getAppName()), 34 | Tag.of("status", instanceInfo.getStatus().name())); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import org.junit.platform.suite.api.SelectClasses; 20 | import org.junit.platform.suite.api.Suite; 21 | 22 | /** 23 | * We need to use a suite cause we need to first run all the Eureka Servers, then close 24 | * all of them. We can't run one EurekaServer, close it and then run another one, cause 25 | * Eureka is using static executor services that are shutdown when we close a context. 26 | * That means that when the new context starts we will fail cause the executor service is 27 | * already shutdown. 28 | */ 29 | @SelectClasses({ EurekaClientTests.class, RestClientEurekaClientTests.class }) 30 | @Suite 31 | public class EurekaClientSuite { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-cloud-starter-netflix-eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.springframework.cloud 5 | spring-cloud-netflix 6 | 5.0.1-SNAPSHOT 7 | 8 | spring-cloud-starter-netflix-eureka-server 9 | Spring Cloud Starter Netflix Eureka Server 10 | Spring Cloud Starter Netflix Eureka Server 11 | https://projects.spring.io/spring-cloud 12 | 13 | Pivotal Software, Inc. 14 | https://www.spring.io 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-netflix-eureka-server 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-loadbalancer 28 | 29 | 30 | 31 | org.glassfish.jaxb 32 | jaxb-runtime 33 | 34 | 35 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EnableEurekaServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import org.springframework.context.annotation.Import; 26 | 27 | /** 28 | * Annotation to activate Eureka Server related configuration. 29 | * {@link EurekaServerAutoConfiguration} 30 | * 31 | * @author Dave Syer 32 | * @author Biju Kunjummen 33 | * 34 | */ 35 | 36 | @Target(ElementType.TYPE) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | @Import(EurekaServerMarkerConfiguration.class) 40 | public @interface EnableEurekaServer { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/header.css: -------------------------------------------------------------------------------- 1 | .navbar { 2 | border-top: 4px solid #6db33f; 3 | background-color: #34302d; 4 | margin: 0; 5 | padding: 0; 6 | border-bottom: 0; 7 | border-left: 0; 8 | border-right: 0; 9 | } 10 | .navbar a.navbar-brand { 11 | background: url("../images/spring-logo-eureka.png") -1px -1px no-repeat; 12 | margin: 12px 0 6px; 13 | width: 300px; 14 | height: 46px; 15 | display: inline-block; 16 | text-decoration: none; 17 | padding: 0; 18 | } 19 | .navbar a.navbar-brand span { 20 | display: block; 21 | width: 300px; 22 | height: 46px; 23 | background: url("../images/spring-logo-eureka.png") -1px -48px no-repeat; 24 | opacity: 0; 25 | transition: opacity 0.12s ease-in-out; 26 | -moz-transition: opacity 0.12s ease-in-out; 27 | -webkit-transition: opacity 0.12s ease-in-out; 28 | } 29 | .navbar a:hover.navbar-brand span { 30 | opacity: 1; 31 | } 32 | .nav-link, .navbar-text { 33 | color: #34302d; 34 | font-family: "montserratregular", sans-serif; 35 | text-shadow: none; 36 | font-size: 14px; 37 | padding: 28px 20px; 38 | transition: all 0.15s; 39 | -moz-transition: all 0.15s; 40 | -webkit-transition: all 0.15s; 41 | } 42 | .navbar .nav-link:link { 43 | color: #f1f1f1; 44 | text-transform: uppercase; 45 | } 46 | .navbar .nav-item .nav-link:hover { 47 | color: #f1f1f1; 48 | background-color: #6db33f; 49 | } 50 | .navbar-toggler { 51 | color: #f1f1f1; 52 | border-width: 0; 53 | } 54 | table { 55 | border-color: #34302D; 56 | } 57 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/support/ZoneUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.support; 18 | 19 | import org.springframework.util.StringUtils; 20 | 21 | /** 22 | * Utility class for dealing with zones. 23 | * 24 | * @author Ryan Baxter 25 | * 26 | */ 27 | public final class ZoneUtils { 28 | 29 | private ZoneUtils() { 30 | throw new AssertionError("Must not instantiate utility class."); 31 | } 32 | 33 | /** 34 | * Approximates Eureka zones from a host name. This method approximates the zone to be 35 | * everything after the first "." in the host name. 36 | * @param host The host name to extract the host name from 37 | * @return The approximate zone 38 | */ 39 | public static String extractApproximateZone(String host) { 40 | String[] split = StringUtils.split(host, "."); 41 | return split == null ? host : split[1]; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/RefreshEurekaSampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.sample; 18 | 19 | import com.netflix.discovery.EurekaClient; 20 | 21 | import org.springframework.boot.SpringBootConfiguration; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.cloud.netflix.eureka.CloudEurekaClient; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | import static org.mockito.Mockito.mock; 28 | 29 | /** 30 | * @author Ryan Baxter 31 | */ 32 | @SpringBootConfiguration(proxyBeanMethods = false) 33 | @EnableAutoConfiguration 34 | @RestController 35 | public class RefreshEurekaSampleApplication { 36 | 37 | @Bean 38 | public EurekaClient getClient() { 39 | return mock(CloudEurekaClient.class); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Build 5 | 6 | on: 7 | push: 8 | branches: [ main, 4.3.x, 4.2.x ] 9 | pull_request: 10 | branches: [ main, 4.3.x, 4.2.x ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v6 19 | - name: Set up JDK 20 | uses: actions/setup-java@v5 21 | with: 22 | distribution: 'temurin' 23 | java-version: '17' 24 | - name: Cache local Maven repository 25 | uses: actions/cache@v5 26 | with: 27 | path: ~/.m2/repository 28 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 29 | restore-keys: | 30 | ${{ runner.os }}-maven- 31 | - name: Build with Maven 32 | run: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn 33 | - name: Publish Test Report 34 | uses: mikepenz/action-junit-report@v6 35 | if: always() # always run even if the previous step fails 36 | with: 37 | report_paths: '**/surefire-reports/TEST-*.xml' 38 | - name: Archive code coverage results 39 | uses: actions/upload-artifact@v6 40 | with: 41 | name: surefire-reports 42 | path: '**/surefire-reports/*' 43 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/typography.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'varela_roundregular'; 3 | src: url('../fonts/varela_round-webfont.eot'); 4 | src: url('../fonts/varela_round-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/varela_round-webfont.woff') format('woff'), url('../fonts/varela_round-webfont.ttf') format('truetype'), url('../fonts/varela_round-webfont.svg#varela_roundregular') format('svg'); 5 | font-weight: normal; 6 | font-style: normal; 7 | } 8 | @font-face { 9 | font-family: 'montserratregular'; 10 | src: url('../fonts/montserrat-webfont.eot'); 11 | src: url('../fonts/montserrat-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/montserrat-webfont.woff') format('woff'), url('../fonts/montserrat-webfont.ttf') format('truetype'), url('../fonts/montserrat-webfont.svg#montserratregular') format('svg'); 12 | font-weight: normal; 13 | font-style: normal; 14 | } 15 | body, h1, h2, h3, p, input { 16 | margin: 0; 17 | font-weight: 400; 18 | font-family: "varela_roundregular", sans-serif; 19 | color: #34302d; 20 | } 21 | h1 { 22 | font-size: 24px; 23 | line-height: 30px; 24 | font-family: "montserratregular", sans-serif; 25 | } 26 | h2 { 27 | font-size: 18px; 28 | font-weight: 700; 29 | line-height: 24px; 30 | margin-bottom: 10px; 31 | font-family: "montserratregular", sans-serif; 32 | } 33 | h3 { 34 | font-size: 16px; 35 | line-height: 24px; 36 | margin-bottom: 10px; 37 | font-weight: 700; 38 | } 39 | strong { 40 | font-weight: 700; 41 | font-family: "montserratregular", sans-serif; 42 | } 43 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/EurekaApplications.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.List; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.netflix.discovery.shared.Application; 24 | import com.netflix.discovery.shared.Applications; 25 | 26 | /** 27 | * A simple wrapper class for {@link Applications} that insure proper Jackson 28 | * serialization through the JsonProperties overwrites. 29 | * 30 | * @author Daniel Lavoie 31 | */ 32 | public class EurekaApplications extends com.netflix.discovery.shared.Applications { 33 | 34 | @JsonCreator 35 | public EurekaApplications(@JsonProperty("apps__hashcode") String appsHashCode, 36 | @JsonProperty("versions__delta") Long versionDelta, 37 | @JsonProperty("application") List registeredApplications) { 38 | super(appsHashCode, versionDelta, registeredApplications); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.loadbalancer; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | 21 | /** 22 | * A {@link ConfigurationProperties} bean for the Eureka-specific instrumentation of 23 | * Spring Cloud LoadBalancer. 24 | * 25 | * @author Olga Maciaszek-Sharma 26 | * @since 2.2.1 27 | */ 28 | @ConfigurationProperties("spring.cloud.loadbalancer.eureka") 29 | public class EurekaLoadBalancerProperties { 30 | 31 | /** 32 | * Used to determine whether we should try to get the `zone` value from host name. 33 | */ 34 | private boolean approximateZoneFromHostname = false; 35 | 36 | public boolean isApproximateZoneFromHostname() { 37 | return approximateZoneFromHostname; 38 | } 39 | 40 | public void setApproximateZoneFromHostname(boolean approximateZoneFromHostname) { 41 | this.approximateZoneFromHostname = approximateZoneFromHostname; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/EurekaInstanceFixture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import com.netflix.appinfo.LeaseInfo; 21 | 22 | public final class EurekaInstanceFixture { 23 | 24 | private EurekaInstanceFixture() { 25 | } 26 | 27 | public static LeaseInfo getLeaseInfo() { 28 | LeaseInfo.Builder leaseBuilder = LeaseInfo.Builder.newBuilder(); 29 | leaseBuilder.setRenewalIntervalInSecs(10); 30 | leaseBuilder.setDurationInSecs(15); 31 | return leaseBuilder.build(); 32 | } 33 | 34 | public static InstanceInfo getInstanceInfo(String appName, String hostName, String instanceId, int port, 35 | LeaseInfo leaseInfo) { 36 | InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder(); 37 | builder.setAppName(appName); 38 | builder.setHostName(hostName); 39 | builder.setInstanceId(instanceId); 40 | builder.setPort(port); 41 | builder.setLeaseInfo(leaseInfo); 42 | return builder.build(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | target-branch: "4.2.x" 6 | schedule: 7 | interval: "weekly" 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | target-branch: "4.3.x" 11 | schedule: 12 | interval: "weekly" 13 | - package-ecosystem: "github-actions" 14 | directory: "/" 15 | target-branch: "main" 16 | schedule: 17 | interval: "weekly" 18 | - package-ecosystem: maven 19 | directory: / 20 | schedule: 21 | interval: daily 22 | target-branch: 4.2.x 23 | ignore: 24 | # only upgrade patch versions for maintenance branch 25 | - dependency-name: "*" 26 | update-types: 27 | - version-update:semver-major 28 | - version-update:semver-minor 29 | - package-ecosystem: maven 30 | directory: / 31 | schedule: 32 | interval: daily 33 | target-branch: 4.3.x 34 | ignore: 35 | # only upgrade patch versions for maintenance branch 36 | - dependency-name: "*" 37 | update-types: 38 | - version-update:semver-major 39 | - version-update:semver-minor 40 | - package-ecosystem: maven 41 | directory: / 42 | schedule: 43 | interval: daily 44 | target-branch: main 45 | - package-ecosystem: npm 46 | target-branch: docs-build 47 | directory: / 48 | schedule: 49 | interval: weekly 50 | - package-ecosystem: npm 51 | target-branch: main 52 | directory: /docs 53 | schedule: 54 | interval: weekly 55 | - package-ecosystem: npm 56 | target-branch: 4.2.x 57 | directory: /docs 58 | schedule: 59 | interval: weekly 60 | - package-ecosystem: npm 61 | target-branch: 4.3.x 62 | directory: /docs 63 | schedule: 64 | interval: weekly 65 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationApplicationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 25 | import org.springframework.cloud.netflix.eureka.sample.EurekaSampleApplication; 26 | import org.springframework.test.annotation.DirtiesContext; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | 30 | /** 31 | * @author Daniel Lavoie 32 | */ 33 | @DirtiesContext 34 | @SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) 35 | class JerseyOptionalArgsConfigurationApplicationTests { 36 | 37 | @Autowired 38 | private AbstractDiscoveryClientOptionalArgs optionalArgs; 39 | 40 | @Test 41 | void contextLoads() { 42 | assertThat(optionalArgs).isNotNull(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationRandomPortTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import com.netflix.appinfo.ApplicationInfoManager; 20 | import com.netflix.appinfo.InstanceInfo; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.SpringBootConfiguration; 25 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | /** 32 | * @author Spencer Gibb 33 | */ 34 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) 35 | class EurekaClientAutoConfigurationRandomPortTests { 36 | 37 | @Autowired 38 | private ApplicationInfoManager infoManager; 39 | 40 | @Test 41 | void instanceInfoPortShouldNotBeZero() { 42 | InstanceInfo info = infoManager.getInfo(); 43 | assertThat(info.getPort()).isGreaterThan(0); 44 | } 45 | 46 | @SpringBootConfiguration 47 | @EnableAutoConfiguration 48 | public static class TestConfig { 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/EurekaClientHttpRequestFactorySupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import javax.net.ssl.HostnameVerifier; 20 | import javax.net.ssl.SSLContext; 21 | 22 | import org.apache.hc.client5.http.config.RequestConfig; 23 | 24 | import org.springframework.http.client.ClientHttpRequestFactory; 25 | import org.springframework.lang.Nullable; 26 | 27 | /** 28 | * Supplier for the {@link ClientHttpRequestFactory} to be used by Eureka client. 29 | * 30 | * @author Marcin Grzejszczak 31 | * @since 3.0.0 32 | */ 33 | public interface EurekaClientHttpRequestFactorySupplier { 34 | 35 | /** 36 | * Returns a constructed {@link ClientHttpRequestFactory}. 37 | * @param sslContext SSL Context 38 | * @param hostnameVerifier Hostname verifier 39 | * @return {@link ClientHttpRequestFactory} 40 | */ 41 | ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier); 42 | 43 | /** 44 | * Allows customising the {@link RequestConfig} of the underlying Apache HC5 instance. 45 | * 46 | * @author Olga Maciaszek-Sharma 47 | * @since 4.2.1 48 | */ 49 | @FunctionalInterface 50 | interface RequestConfigCustomizer { 51 | 52 | void customize(RequestConfig.Builder builder); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.extension.ExtendWith; 22 | import org.mockito.InjectMocks; 23 | import org.mockito.Mock; 24 | import org.mockito.junit.jupiter.MockitoExtension; 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; 27 | import static org.mockito.ArgumentMatchers.any; 28 | import static org.mockito.Mockito.verify; 29 | 30 | @ExtendWith(MockitoExtension.class) 31 | class EurekaServerInitializerConfigurationTest { 32 | 33 | @Mock 34 | private EurekaServerBootstrap eurekaServerBootstrapMock; 35 | 36 | @InjectMocks 37 | private EurekaServerInitializerConfiguration eurekaServerInitializerConfiguration; 38 | 39 | private boolean callbackCalled; 40 | 41 | @BeforeEach 42 | void setUp() { 43 | callbackCalled = false; 44 | } 45 | 46 | @Test 47 | void testStopWithCallbackCallsStop() { 48 | eurekaServerInitializerConfiguration.stop(this::setCallbackCalledTrue); 49 | 50 | assertThat(callbackCalled).isTrue(); 51 | verify(eurekaServerBootstrapMock).contextDestroyed(any()); 52 | } 53 | 54 | private void setCallbackCalledTrue() { 55 | callbackCalled = true; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/NotFoundHttpResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | import org.springframework.http.HttpHeaders; 23 | import org.springframework.http.HttpStatusCode; 24 | import org.springframework.http.client.ClientHttpResponse; 25 | 26 | /** 27 | * Response that ignores body, specifically for 404 errors. 28 | * 29 | * @author Spencer Gibb 30 | * @author Wonchul Heo 31 | * @since 4.2.0 32 | */ 33 | class NotFoundHttpResponse implements ClientHttpResponse { 34 | 35 | private final ClientHttpResponse response; 36 | 37 | NotFoundHttpResponse(ClientHttpResponse response) { 38 | this.response = response; 39 | } 40 | 41 | @Override 42 | public HttpStatusCode getStatusCode() throws IOException { 43 | return response.getStatusCode(); 44 | } 45 | 46 | @Override 47 | public String getStatusText() throws IOException { 48 | return response.getStatusText(); 49 | } 50 | 51 | @Override 52 | public void close() { 53 | response.close(); 54 | } 55 | 56 | @Override 57 | public InputStream getBody() throws IOException { 58 | // ignore body on 404 for heartbeat, see gh-4145 59 | return null; 60 | } 61 | 62 | @Override 63 | public HttpHeaders getHeaders() { 64 | return response.getHeaders(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationRestClientTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.autoconfigure.AutoConfigurations; 22 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 23 | import org.springframework.cloud.config.client.ConfigServerInstanceProvider; 24 | import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; 25 | import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | 29 | /** 30 | * @author Wonchul Heo 31 | */ 32 | class EurekaConfigServerBootstrapConfigurationRestClientTests { 33 | 34 | @Test 35 | void properBeansCreated() { 36 | new ApplicationContextRunner() 37 | .withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) 38 | .withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true") 39 | .run(context -> { 40 | assertThat(context).hasSingleBean(EurekaClientConfigBean.class); 41 | assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class); 42 | assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class); 43 | }); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaServerRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.io.File; 20 | 21 | public class EurekaServerRunner extends AppRunner { 22 | 23 | public EurekaServerRunner(Class appClass) { 24 | super(appClass); 25 | 26 | property("eureka.client.registerWithEureka", "false"); 27 | property("eureka.client.fetchRegistry", "false"); 28 | property("eureka.server.waitTimeInMsWhenSyncEmpty", "0"); 29 | property("eureka.client.refresh.enable", "true"); 30 | } 31 | 32 | public void enableTls() { 33 | property("server.ssl.enabled", "true"); 34 | property("server.ssl.client-auth", "need"); 35 | } 36 | 37 | public void setKeyStore(File keyStore, String keyStorePassword, String key, String keyPassword) { 38 | property("server.ssl.key-store", pathOf(keyStore)); 39 | property("server.ssl.key-store-type", "PKCS12"); 40 | property("server.ssl.key-store-password", keyStorePassword); 41 | property("server.ssl.key-alias", key); 42 | property("server.ssl.key-password", keyPassword); 43 | } 44 | 45 | public void setTrustStore(File trustStore, String password) { 46 | property("server.ssl.trust-store", pathOf(trustStore)); 47 | property("server.ssl.trust-store-type", "PKCS12"); 48 | property("server.ssl.trust-store-password", password); 49 | } 50 | 51 | private String pathOf(File file) { 52 | return String.format("file:%s", file.getAbsolutePath()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | repo.spring.io 6 | ${env.CI_DEPLOY_USERNAME} 7 | ${env.CI_DEPLOY_PASSWORD} 8 | 9 | 10 | 11 | 12 | 18 | spring 19 | true 20 | 21 | 22 | spring-snapshots 23 | Spring Snapshots 24 | https://repo.spring.io/libs-snapshot-local 25 | 26 | true 27 | 28 | 29 | 30 | spring-milestones 31 | Spring Milestones 32 | https://repo.spring.io/libs-milestone-local 33 | 34 | false 35 | 36 | 37 | 38 | spring-releases 39 | Spring Releases 40 | https://repo.spring.io/release 41 | 42 | false 43 | 44 | 45 | 46 | 47 | 48 | spring-snapshots 49 | Spring Snapshots 50 | https://repo.spring.io/libs-snapshot-local 51 | 52 | true 53 | 54 | 55 | 56 | spring-milestones 57 | Spring Milestones 58 | https://repo.spring.io/libs-milestone-local 59 | 60 | false 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/src/main/asciidoc/sagan-index.adoc: -------------------------------------------------------------------------------- 1 | Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka). 2 | 3 | ## Features 4 | 5 | Spring Cloud Netflix features: 6 | 7 | * Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans 8 | * Service Discovery: an embedded Eureka server can be created with declarative Java configuration 9 | 10 | ## Getting Started 11 | 12 | As long as Spring Cloud Netflix and Eureka Core are on the 13 | classpath any Spring Boot application with `spring-cloud-starter-netflix-eureka-client` in dependencies will try to contact a Eureka 14 | server on `http://localhost:8761` (the default value of 15 | `eureka.client.serviceUrl.defaultZone`): 16 | 17 | ```java 18 | @SpringBootApplication 19 | @RestController 20 | public class Application { 21 | 22 | @RequestMapping("/") 23 | public String home() { 24 | return "Hello World"; 25 | } 26 | 27 | public static void main(String[] args) { 28 | SpringApplication.run(Application.class, args); 29 | } 30 | 31 | } 32 | ``` 33 | 34 | To run your own server use the `spring-cloud-starter-netflix-eureka-server` dependency and `@EnableEurekaServer`. 35 | 36 | ## Contributing 37 | 38 | We welcome contributions. You can read more on how to contribute to the project https://github.com/spring-cloud/spring-cloud-netflix#contributing[here]. 39 | 40 | ## Community Support 41 | 42 | * You can report issues through https://github.com/spring-cloud/spring-cloud-netflix/issues[Github]. 43 | * We monitor https://stackoverflow.com/[StackOverflow] for questions with the `spring-cloud-netflix` tag. 44 | * You can contact our team at https://gitter.im/spring-cloud/spring-cloud[Gitter]. 45 | 46 | ## Commercial Support 47 | 48 | Commercial Support is provided as part of the https://spring.io/support[VMware Spring Runtime] offering. 49 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import com.netflix.discovery.EurekaClient; 20 | import com.netflix.discovery.shared.Applications; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.extension.ExtendWith; 23 | import org.mockito.InjectMocks; 24 | import org.mockito.Mock; 25 | import org.mockito.junit.jupiter.MockitoExtension; 26 | 27 | import static org.assertj.core.api.Assertions.assertThatCode; 28 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; 29 | import static org.mockito.Mockito.when; 30 | 31 | /** 32 | * @author Mohamed Macow 33 | */ 34 | @ExtendWith(MockitoExtension.class) 35 | class EurekaDiscoveryClientTests { 36 | 37 | @Mock 38 | private EurekaClient eurekaClient; 39 | 40 | @InjectMocks 41 | private EurekaDiscoveryClient client; 42 | 43 | @Test 44 | void shouldCompleteProbeWhenClientHealthy() { 45 | when(eurekaClient.getApplications()).thenReturn(new Applications()); 46 | 47 | assertThatCode(() -> client.probe()).doesNotThrowAnyException(); 48 | } 49 | 50 | @Test 51 | void shouldThrowProbeWhenClientThrows() { 52 | RuntimeException eurekaException = new RuntimeException("exception"); 53 | when(eurekaClient.getApplications()).thenThrow(eurekaException); 54 | 55 | assertThatExceptionOfType(eurekaException.getClass()).isThrownBy(() -> client.probe()) 56 | .withMessage(eurekaException.getMessage()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.boot.builder.SpringApplicationBuilder; 23 | import org.springframework.cloud.netflix.eureka.sample.EurekaSampleApplication; 24 | import org.springframework.cloud.test.ClassPathExclusions; 25 | import org.springframework.context.ConfigurableApplicationContext; 26 | 27 | import static org.assertj.core.api.AssertionsForClassTypes.fail; 28 | import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; 29 | 30 | /** 31 | * @author Daniel Lavoie 32 | */ 33 | @ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*", "spring-webflux-*" }) 34 | class EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests { 35 | 36 | @Test 37 | void contextFailsWithoutWebClient() { 38 | 39 | ConfigurableApplicationContext ctx = null; 40 | try { 41 | TomcatURLStreamHandlerFactory.disable(); 42 | ctx = new SpringApplicationBuilder(EurekaSampleApplication.class) 43 | .properties("eureka.client.webclient.enabled=true") 44 | .run(); 45 | fail("exception not thrown"); 46 | } 47 | catch (Exception e) { 48 | // this is the desired state 49 | assertThat(e).hasStackTraceContaining("WebClient is not on the classpath"); 50 | } 51 | if (ctx != null) { 52 | ctx.close(); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientDiscoveryClientOptionalArgs.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.function.Supplier; 20 | 21 | import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; 22 | import jakarta.ws.rs.client.ClientRequestFilter; 23 | 24 | import org.springframework.web.client.RestClient; 25 | 26 | /** 27 | * {@link RestClient} implementation of DiscoveryClientOptionalArgs that supports 28 | * supplying {@link ClientRequestFilter}. 29 | * 30 | * @author Wonchul Heo 31 | * @author Olga Maciaszek-Sharma 32 | * @since 4.2.0 33 | */ 34 | public class RestClientDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs { 35 | 36 | private final EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier; 37 | 38 | private final Supplier restClientBuilderSupplier; 39 | 40 | public RestClientDiscoveryClientOptionalArgs( 41 | EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier, 42 | Supplier restClientBuilderSupplier) { 43 | this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier; 44 | this.restClientBuilderSupplier = restClientBuilderSupplier; 45 | } 46 | 47 | EurekaClientHttpRequestFactorySupplier getEurekaClientHttpRequestFactorySupplier() { 48 | return eurekaClientHttpRequestFactorySupplier; 49 | } 50 | 51 | Supplier getRestClientBuilderSupplier() { 52 | return restClientBuilderSupplier; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyClientOptionalArgsConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.boot.autoconfigure.AutoConfigurations; 23 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 24 | import org.springframework.cloud.netflix.eureka.http.RestClientDiscoveryClientOptionalArgs; 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; 27 | 28 | /** 29 | * Tests for Jersey client setup in DiscoveryClientOptionalArgsConfiguration. 30 | * 31 | * @author Olga Maciaszek-Sharma 32 | */ 33 | public class JerseyClientOptionalArgsConfigurationTests { 34 | 35 | @SuppressWarnings("OptionalGetWithoutIsPresent") 36 | @Test 37 | void shouldCreateRestClientDiscoveryClientOptionalArgsWhenJerseyClientDisabled() { 38 | new ApplicationContextRunner() 39 | .withConfiguration(AutoConfigurations.of(DiscoveryClientOptionalArgsConfiguration.class)) 40 | .withPropertyValues("eureka.client.jersey.enabled=false") 41 | .run(context -> { 42 | assertThat(context).hasSingleBean(AbstractDiscoveryClientOptionalArgs.class); 43 | assertThat(context.getBeansOfType(AbstractDiscoveryClientOptionalArgs.class) 44 | .values() 45 | .stream() 46 | .findFirst() 47 | .get()).isInstanceOf(RestClientDiscoveryClientOptionalArgs.class); 48 | assertThat(context).hasSingleBean(RestClientDiscoveryClientOptionalArgs.class); 49 | }); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationDashboardDisabledTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Map; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.resttestclient.TestRestTemplate; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 27 | import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application; 28 | import org.springframework.http.HttpStatus; 29 | import org.springframework.http.ResponseEntity; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | @SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, 34 | value = { "spring.application.name=eureka", "eureka.dashboard.enabled=false" }) 35 | class ApplicationDashboardDisabledTests { 36 | 37 | @Value("${local.server.port}") 38 | private int port = 0; 39 | 40 | @Test 41 | void catalogLoads() { 42 | @SuppressWarnings("rawtypes") 43 | ResponseEntity entity = new TestRestTemplate() 44 | .getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class); 45 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 46 | } 47 | 48 | @Test 49 | void dashboardLoads() { 50 | ResponseEntity entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port + "/", 51 | String.class); 52 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactories.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.Collection; 20 | import java.util.Optional; 21 | import java.util.function.Supplier; 22 | 23 | import javax.net.ssl.HostnameVerifier; 24 | import javax.net.ssl.SSLContext; 25 | 26 | import com.netflix.appinfo.InstanceInfo; 27 | import com.netflix.discovery.EurekaClientConfig; 28 | import com.netflix.discovery.shared.transport.TransportClientFactory; 29 | import com.netflix.discovery.shared.transport.jersey.TransportClientFactories; 30 | 31 | import org.springframework.web.reactive.function.client.WebClient; 32 | 33 | /** 34 | * @author Daniel Lavoie 35 | * @author Haytham Mohamed 36 | */ 37 | public class WebClientTransportClientFactories implements TransportClientFactories { 38 | 39 | private final Supplier builder; 40 | 41 | public WebClientTransportClientFactories(Supplier builder) { 42 | this.builder = builder; 43 | } 44 | 45 | @Override 46 | public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig, 47 | Collection additionalFilters, InstanceInfo myInstanceInfo) { 48 | return new WebClientTransportClientFactory(builder); 49 | } 50 | 51 | @Override 52 | public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig, 53 | final Collection additionalFilters, final InstanceInfo myInstanceInfo, 54 | final Optional sslContext, final Optional hostnameVerifier) { 55 | return new WebClientTransportClientFactory(builder); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import com.netflix.appinfo.EurekaInstanceConfig; 20 | import com.netflix.discovery.EurekaClient; 21 | import jakarta.annotation.PostConstruct; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 26 | import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.core.env.Environment; 29 | import org.springframework.util.StringUtils; 30 | 31 | /** 32 | * Extra configuration for config server if it happens to be a Eureka instance. 33 | * 34 | * @author Dave Syer 35 | */ 36 | @Configuration(proxyBeanMethods = false) 37 | @EnableConfigurationProperties 38 | @ConditionalOnClass(value = { EurekaInstanceConfigBean.class, EurekaClient.class }, 39 | name = "org.springframework.cloud.config.server.config.ConfigServerProperties") 40 | public class EurekaClientConfigServerAutoConfiguration { 41 | 42 | @Autowired(required = false) 43 | private EurekaInstanceConfig instance; 44 | 45 | @Autowired 46 | private Environment env; 47 | 48 | @PostConstruct 49 | public void init() { 50 | if (this.instance == null) { 51 | return; 52 | } 53 | String prefix = this.env.getProperty("spring.cloud.config.server.prefix"); 54 | if (StringUtils.hasText(prefix) && !StringUtils.hasText(this.instance.getMetadataMap().get("configPath"))) { 55 | this.instance.getMetadataMap().put("configPath", prefix); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/wro/main.css: -------------------------------------------------------------------------------- 1 | @import "typography.css"; 2 | @import "header.css"; 3 | @import "responsive.css"; 4 | 5 | a:link { 6 | color: #5fa134; 7 | } 8 | a:hover { 9 | color: #5fa134; 10 | } 11 | body { 12 | background-color: #f1f1f1; 13 | } 14 | .table > thead > tr > th { 15 | background-color: #34302D; 16 | color: #f1f1f1; 17 | } 18 | .table-filter { 19 | background-color: #34302D; 20 | padding: 9px 12px; 21 | } 22 | .nav-tabs .nav-link { 23 | color: #838789; 24 | } 25 | .nav-tabs .nav-link.active, .nav-tabs .nav-link.active:hover { 26 | color: #f1f1f1; 27 | background-color: #34302D; 28 | border-color: #34302D; 29 | } 30 | .btn-default { 31 | border-width: 2px; 32 | transition: border 0.15s; 33 | -webkit-transition: border 0.15s; 34 | -moz-transition: border 0.15s; 35 | -o-transition: border 0.15s; 36 | -ms-transition: border 0.15s; 37 | color: #f1f1f1; 38 | background-color: #34302D; 39 | border-color: #6db33f; 40 | } 41 | .btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active, .open .dropdown-toggle.btn-default { 42 | background-color: #34302D; 43 | border-color: #34302D; 44 | } 45 | .container .text-muted { 46 | margin: 20px 0; 47 | } 48 | code { 49 | font-size: 80%; 50 | } 51 | .xd-container { 52 | margin-top: 40px; 53 | margin-bottom: 100px; 54 | } 55 | h1 { 56 | margin-bottom: 15px; 57 | } 58 | .index-page--subtitle { 59 | font-size: 16px; 60 | line-height: 24px; 61 | margin: 0 0 30px; 62 | } 63 | .form-horizontal button.btn-inverse { 64 | margin-left: 32px; 65 | } 66 | #job-params-modal .modal-dialog { 67 | width: 90%; 68 | margin-left: auto; 69 | margin-right: auto; 70 | } 71 | [ng-cloak].splash { 72 | display: block !important; 73 | } 74 | [ng-cloak] { 75 | display: none; 76 | } 77 | .splash { 78 | background: #6db33f; 79 | color: #34302D; 80 | display: none; 81 | } 82 | .error-page { 83 | margin-top: 100px; 84 | text-align: center; 85 | } 86 | .error-page .error-title { 87 | font-size: 24px; 88 | line-height: 24px; 89 | margin: 30px 0 0; 90 | } 91 | table td { 92 | vertical-align: middle !important; 93 | } 94 | table td .progress { 95 | margin-bottom: 0; 96 | } 97 | table td.action-column { 98 | width: 1px; 99 | } 100 | .help-block { 101 | color: #f1f1f1; 102 | } 103 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaDashboardProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Objects; 20 | 21 | import org.springframework.boot.context.properties.ConfigurationProperties; 22 | 23 | /** 24 | * Configuration properties for the Eureka dashboard (UI). 25 | * 26 | * @author Dave Syer 27 | */ 28 | @ConfigurationProperties("eureka.dashboard") 29 | public class EurekaDashboardProperties { 30 | 31 | /** 32 | * The path to the Eureka dashboard (relative to the servlet path). Defaults to "/". 33 | */ 34 | private String path = "/"; 35 | 36 | /** 37 | * Flag to enable the Eureka dashboard. Default true. 38 | */ 39 | private boolean enabled = true; 40 | 41 | public String getPath() { 42 | return path; 43 | } 44 | 45 | public void setPath(String path) { 46 | this.path = path; 47 | } 48 | 49 | public boolean isEnabled() { 50 | return enabled; 51 | } 52 | 53 | public void setEnabled(boolean enabled) { 54 | this.enabled = enabled; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) { 60 | return true; 61 | } 62 | if (o == null || getClass() != o.getClass()) { 63 | return false; 64 | } 65 | EurekaDashboardProperties that = (EurekaDashboardProperties) o; 66 | return enabled == that.enabled && Objects.equals(path, that.path); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | return Objects.hash(path, enabled); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | final StringBuilder sb = new StringBuilder("EurekaDashboardProperties{"); 77 | sb.append("path='").append(path).append('\''); 78 | sb.append(", enabled=").append(enabled); 79 | sb.append('}'); 80 | return sb.toString(); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /spring-cloud-starter-netflix-eureka-client/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.springframework.cloud 6 | spring-cloud-netflix 7 | 5.0.1-SNAPSHOT 8 | 9 | spring-cloud-starter-netflix-eureka-client 10 | Spring Cloud Starter Netflix Eureka Client 11 | Spring Cloud Starter Netflix Eureka Client 12 | https://projects.spring.io/spring-cloud 13 | 14 | Pivotal Software, Inc. 15 | https://www.spring.io 16 | 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-netflix-eureka-client 25 | 26 | 27 | com.sun.jersey 28 | jersey-client 29 | 30 | 31 | com.sun.jersey 32 | jersey-core 33 | 34 | 35 | com.sun.jersey.contribs 36 | jersey-apache-client4 37 | 38 | 39 | 40 | 41 | com.netflix.eureka 42 | eureka-client 43 | 44 | 45 | com.sun.jersey 46 | jersey-client 47 | 48 | 49 | com.sun.jersey 50 | jersey-core 51 | 52 | 53 | com.sun.jersey.contribs 54 | jersey-apache-client4 55 | 56 | 57 | aopalliance 58 | aopalliance 59 | 60 | 61 | 62 | 63 | org.springframework.cloud 64 | spring-cloud-starter-loadbalancer 65 | 66 | 67 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Objects; 20 | 21 | import org.springframework.boot.context.properties.ConfigurationProperties; 22 | 23 | /** 24 | * Configuration properties for the Eureka deployment. 25 | * 26 | * @author Weix Sun 27 | */ 28 | @ConfigurationProperties("eureka") 29 | public class EurekaProperties { 30 | 31 | /** 32 | * Eureka environment. Defaults to "test". 33 | */ 34 | private String environment = "test"; 35 | 36 | /** 37 | * Eureka datacenter. Defaults to "default". 38 | */ 39 | private String datacenter = "default"; 40 | 41 | public String getEnvironment() { 42 | return environment; 43 | } 44 | 45 | public void setEnvironment(String environment) { 46 | this.environment = environment; 47 | } 48 | 49 | public String getDatacenter() { 50 | return datacenter; 51 | } 52 | 53 | public void setDatacenter(String datacenter) { 54 | this.datacenter = datacenter; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) { 60 | return true; 61 | } 62 | if (o == null || getClass() != o.getClass()) { 63 | return false; 64 | } 65 | EurekaProperties that = (EurekaProperties) o; 66 | return Objects.equals(datacenter, that.datacenter) && Objects.equals(environment, that.environment); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | return Objects.hash(environment, datacenter); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | final StringBuilder sb = new StringBuilder("EurekaProperties{"); 77 | sb.append("environment='").append(environment).append('\''); 78 | sb.append(", datacenter=").append(datacenter); 79 | sb.append('}'); 80 | return sb.toString(); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/EurekaServerRefreshDisabledTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Map; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 24 | import org.springframework.boot.resttestclient.TestRestTemplate; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.boot.test.web.server.LocalServerPort; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.http.HttpStatus; 29 | import org.springframework.http.ResponseEntity; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 33 | 34 | /** 35 | * Verifies the behaviour of Eureka server with peer registration enabled and refresh 36 | * disabled. 37 | * 38 | * @author Olga Maciaszek-Sharma 39 | */ 40 | @SpringBootTest(classes = EurekaServerRefreshDisabledTests.Application.class, webEnvironment = RANDOM_PORT, 41 | properties = { "management.endpoints.web.exposure.include=*", "spring.cloud.refresh.enabled=false" }) 42 | public class EurekaServerRefreshDisabledTests { 43 | 44 | @LocalServerPort 45 | private int port = 0; 46 | 47 | // verifies GH-4407 48 | @SuppressWarnings("rawtypes") 49 | @Test 50 | void appCatalogLoads() { 51 | ResponseEntity entity = new TestRestTemplate() 52 | .getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class); 53 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 54 | } 55 | 56 | @Configuration(proxyBeanMethods = false) 57 | @EnableAutoConfiguration 58 | @EnableEurekaServer 59 | protected static class Application { 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/ConfigRefreshTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import com.netflix.discovery.EurekaClient; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; 25 | import org.springframework.cloud.netflix.eureka.sample.RefreshEurekaSampleApplication; 26 | import org.springframework.context.ApplicationEventPublisher; 27 | 28 | import static org.mockito.Mockito.times; 29 | import static org.mockito.Mockito.verify; 30 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 31 | 32 | /** 33 | * @author Ryan Baxter 34 | * @author Kaiyao Ke 35 | */ 36 | @SpringBootTest(webEnvironment = RANDOM_PORT, classes = RefreshEurekaSampleApplication.class) 37 | class ConfigRefreshTests { 38 | 39 | @Autowired 40 | private ApplicationEventPublisher publisher; 41 | 42 | @Autowired 43 | // Mocked in RefreshEurekaSampleApplication 44 | private EurekaClient client; 45 | 46 | private static boolean isFirstRun = true; 47 | 48 | @Test 49 | // This test is used to verify that getApplications is called the correct number of 50 | // times when a refresh event is fired. The getApplications call in 51 | // EurekaClientConfigurationRefresher.onApplicationEvent 52 | // ensures that the EurekaClient bean is recreated after a refresh event and that we 53 | // reregister the client with the server 54 | void verifyGetApplications() { 55 | if (publisher != null && isFirstRun) { 56 | publisher.publishEvent(new RefreshScopeRefreshedEvent()); 57 | isFirstRun = false; 58 | } 59 | verify(client, times(3)).getApplications(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner; 22 | import org.springframework.cloud.netflix.eureka.http.RestClientDiscoveryClientOptionalArgs; 23 | import org.springframework.cloud.netflix.eureka.http.WebClientDiscoveryClientOptionalArgs; 24 | import org.springframework.cloud.netflix.eureka.sample.EurekaSampleApplication; 25 | import org.springframework.cloud.test.ClassPathExclusions; 26 | 27 | import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; 28 | 29 | /** 30 | * @author Daniel Lavoie 31 | * @author Wonchul Heo 32 | */ 33 | @ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*" }) 34 | class EurekaHttpClientsOptionalArgsConfigurationTests { 35 | 36 | @Test 37 | public void contextLoadsWithRestClientWhenWebClientDisabled() { 38 | new WebApplicationContextRunner().withUserConfiguration(EurekaSampleApplication.class) 39 | .withPropertyValues("eureka.client.webclient.enabled=false") 40 | .run(context -> { 41 | assertThat(context).hasSingleBean(RestClientDiscoveryClientOptionalArgs.class); 42 | assertThat(context).doesNotHaveBean(WebClientDiscoveryClientOptionalArgs.class); 43 | }); 44 | } 45 | 46 | @Test 47 | void contextLoadsWithWebClient() { 48 | new WebApplicationContextRunner().withUserConfiguration(EurekaSampleApplication.class) 49 | .withPropertyValues("eureka.client.webclient.enabled=true") 50 | .run(context -> { 51 | assertThat(context).doesNotHaveBean(RestClientDiscoveryClientOptionalArgs.class); 52 | assertThat(context).hasSingleBean(WebClientDiscoveryClientOptionalArgs.class); 53 | }); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactories.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.Collection; 20 | import java.util.Optional; 21 | 22 | import javax.net.ssl.HostnameVerifier; 23 | import javax.net.ssl.SSLContext; 24 | 25 | import com.netflix.appinfo.InstanceInfo; 26 | import com.netflix.discovery.EurekaClientConfig; 27 | import com.netflix.discovery.shared.transport.TransportClientFactory; 28 | import com.netflix.discovery.shared.transport.jersey.TransportClientFactories; 29 | 30 | /** 31 | * @author Wonchul Heo 32 | * @author Olga Maciaszek-Sharma 33 | * @since 4.2.0 34 | */ 35 | public class RestClientTransportClientFactories implements TransportClientFactories { 36 | 37 | private final RestClientDiscoveryClientOptionalArgs args; 38 | 39 | public RestClientTransportClientFactories(RestClientDiscoveryClientOptionalArgs args) { 40 | this.args = args; 41 | } 42 | 43 | @Override 44 | public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig, 45 | Collection additionalFilters, InstanceInfo myInstanceInfo) { 46 | return new RestClientTransportClientFactory(args.getSSLContext(), args.getHostnameVerifier(), 47 | args.getEurekaClientHttpRequestFactorySupplier(), args.getRestClientBuilderSupplier()); 48 | } 49 | 50 | @Override 51 | public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig, 52 | final Collection additionalFilters, final InstanceInfo myInstanceInfo, 53 | final Optional sslContext, final Optional hostnameVerifier) { 54 | return new RestClientTransportClientFactory(args.getSSLContext(), args.getHostnameVerifier(), 55 | args.getEurekaClientHttpRequestFactorySupplier(), args.getRestClientBuilderSupplier()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/templates/eureka/navbar.ftlh: -------------------------------------------------------------------------------- 1 |

System Status

2 |
3 |
4 | 5 | <#if amazonInfo??> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
EUREKA SERVERAMI: ${amiId!}
Zone${availabilityZone!}
instance-id${instanceId!}
Environment${environment!}
Data center${datacenter!}
28 |
29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
Current time${currentTime}
Uptime${upTime}
Lease expiration enabled${registry.leaseExpirationEnabled?c}
Renews threshold${registry.numOfRenewsPerMinThreshold}
Renews (last min)${registry.numOfRenewsInLastMin}
52 |
53 |
54 | 55 | <#if isBelowRenewThreshold> 56 | <#if !registry.selfPreservationModeEnabled> 57 |

RENEWALS ARE LESSER THAN THE THRESHOLD. THE SELF PRESERVATION MODE IS TURNED OFF. THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.

58 | <#else> 59 |

EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.

60 | 61 | <#elseif !registry.selfPreservationModeEnabled> 62 |

THE SELF PRESERVATION MODE IS TURNED OFF. THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.

63 | 64 | 65 |

DS Replicas

66 | 71 | 72 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/resources/templates/eureka/lastn.ftlh: -------------------------------------------------------------------------------- 1 | <#import "/spring.ftl" as spring /> 2 | 3 | 4 | 5 | 6 | Eureka - Last N events 7 | 8 | 9 | 10 | 15 | 16 | <#include "header.ftlh"> 17 | 18 |
19 | <#include "navbar.ftlh"> 20 | 21 |
22 | 26 |
27 |
28 | 29 | 30 | 31 | 32 | 33 | <#if lastNCanceled?has_content> 34 | <#list lastNCanceled as entry> 35 | 36 | 37 | <#else> 38 | 39 | 40 | 41 |
TimestampLease
${entry.date?datetime}${entry.id}
No results available
42 |
43 |
44 | 45 | 46 | 47 | 48 | 49 | <#if lastNRegistered?has_content> 50 | <#list lastNRegistered as entry> 51 | 52 | 53 | <#else> 54 | 55 | 56 | 57 |
TimestampLease
${entry.date?datetime}${entry.id}
No results available
58 |
59 |
60 |
61 |
62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/LoadBalancerEurekaAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.loadbalancer; 18 | 19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 22 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 23 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClientConfigurationRegistrar; 24 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients; 25 | import org.springframework.cloud.loadbalancer.config.LoadBalancerZoneConfig; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.core.env.Environment; 29 | 30 | /** 31 | * An Autoconfiguration that loads default config for Spring Cloud LoadBalancer clients. 32 | * 33 | * @author Olga Maciaszek-Sharma 34 | * @since 2.2.1 35 | * @see EurekaLoadBalancerClientConfiguration 36 | */ 37 | @Configuration(proxyBeanMethods = false) 38 | @EnableConfigurationProperties 39 | @ConditionalOnClass(LoadBalancerClientConfigurationRegistrar.class) 40 | @LoadBalancerClients(defaultConfiguration = EurekaLoadBalancerClientConfiguration.class) 41 | @ConditionalOnProperty(name = "eureka.client.enabled", matchIfMissing = true) 42 | public class LoadBalancerEurekaAutoConfiguration { 43 | 44 | /** 45 | * Spring Cloud LoadBalancer Zone property name. 46 | */ 47 | public static final String LOADBALANCER_ZONE = "spring.cloud.loadbalancer.zone"; 48 | 49 | @Bean 50 | @ConditionalOnMissingBean 51 | EurekaLoadBalancerProperties eurekaLoadBalancerProperties() { 52 | return new EurekaLoadBalancerProperties(); 53 | } 54 | 55 | @Bean 56 | @ConditionalOnMissingBean 57 | LoadBalancerZoneConfig zoneConfig(Environment environment) { 58 | return new LoadBalancerZoneConfig(environment.getProperty(LOADBALANCER_ZONE)); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistryProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import org.springframework.beans.factory.annotation.Value; 20 | import org.springframework.boot.context.properties.ConfigurationProperties; 21 | 22 | import static org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties.PREFIX; 23 | 24 | /** 25 | * @author Spencer Gibb 26 | */ 27 | @ConfigurationProperties(PREFIX) 28 | public class InstanceRegistryProperties { 29 | 30 | /** 31 | * Prefix for Eureka instance registry properties. 32 | */ 33 | public static final String PREFIX = "eureka.instance.registry"; 34 | 35 | /* 36 | * Default number of expected client, defaults to 1. Setting 37 | * expectedNumberOfClientsSendingRenews to non-zero to ensure that even an isolated 38 | * server can adjust its eviction policy to the number of registrations (when it's 39 | * zero, even a successful registration won't reset the rate threshold in 40 | * InstanceRegistry.register()). 41 | */ 42 | @Value("${eureka.server.expectedNumberOfRenewsPerMin:1}") // for backwards 43 | // compatibility 44 | private int expectedNumberOfClientsSendingRenews = 1; 45 | 46 | /** 47 | * Value used in determining when leases are cancelled, default to 1 for standalone. 48 | * Should be set to 0 for peer replicated eurekas 49 | */ 50 | @Value("${eureka.server.defaultOpenForTrafficCount:1}") // for backwards compatibility 51 | private int defaultOpenForTrafficCount = 1; 52 | 53 | public int getExpectedNumberOfClientsSendingRenews() { 54 | return expectedNumberOfClientsSendingRenews; 55 | } 56 | 57 | public void setExpectedNumberOfClientsSendingRenews(int expectedNumberOfClientsSendingRenews) { 58 | this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews; 59 | } 60 | 61 | public int getDefaultOpenForTrafficCount() { 62 | return defaultOpenForTrafficCount; 63 | } 64 | 65 | public void setDefaultOpenForTrafficCount(int defaultOpenForTrafficCount) { 66 | this.defaultOpenForTrafficCount = defaultOpenForTrafficCount; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.reactive; 18 | 19 | import com.netflix.discovery.EurekaClient; 20 | import com.netflix.discovery.EurekaClientConfig; 21 | import com.netflix.discovery.shared.Application; 22 | import com.netflix.discovery.shared.Applications; 23 | import reactor.core.publisher.Flux; 24 | import reactor.core.publisher.Mono; 25 | 26 | import org.springframework.cloud.client.ServiceInstance; 27 | import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; 28 | import org.springframework.cloud.netflix.eureka.EurekaServiceInstance; 29 | import org.springframework.core.Ordered; 30 | 31 | /** 32 | * A {@link ReactiveDiscoveryClient} implementation for Eureka. 33 | * 34 | * @author Tim Ysewyn 35 | */ 36 | public class EurekaReactiveDiscoveryClient implements ReactiveDiscoveryClient { 37 | 38 | private final EurekaClient eurekaClient; 39 | 40 | private final EurekaClientConfig clientConfig; 41 | 42 | public EurekaReactiveDiscoveryClient(EurekaClient eurekaClient, EurekaClientConfig clientConfig) { 43 | this.eurekaClient = eurekaClient; 44 | this.clientConfig = clientConfig; 45 | } 46 | 47 | @Override 48 | public String description() { 49 | return "Spring Cloud Eureka Reactive Discovery Client"; 50 | } 51 | 52 | @Override 53 | public Flux getInstances(String serviceId) { 54 | return Flux.defer(() -> Flux.fromIterable(eurekaClient.getInstancesByVipAddress(serviceId, false))) 55 | .map(EurekaServiceInstance::new); 56 | } 57 | 58 | @Override 59 | public Flux getServices() { 60 | return Flux.defer(() -> Mono.justOrEmpty(eurekaClient.getApplications())) 61 | .flatMapIterable(Applications::getRegisteredApplications) 62 | .filter(application -> !application.getInstances().isEmpty()) 63 | .map(Application::getName) 64 | .map(String::toLowerCase); 65 | } 66 | 67 | @Override 68 | public int getOrder() { 69 | return clientConfig instanceof Ordered ? ((Ordered) clientConfig).getOrder() 70 | : ReactiveDiscoveryClient.DEFAULT_ORDER; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactoryTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import java.util.Collections; 20 | import java.util.Optional; 21 | 22 | import com.netflix.discovery.shared.resolver.DefaultEndpoint; 23 | import com.netflix.discovery.shared.transport.EurekaHttpClient; 24 | import org.junit.jupiter.api.AfterEach; 25 | import org.junit.jupiter.api.BeforeEach; 26 | import org.junit.jupiter.api.Test; 27 | 28 | import org.springframework.cloud.netflix.eureka.TimeoutProperties; 29 | import org.springframework.web.client.RestClient; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | /** 34 | * Tests for {@link RestClientTransportClientFactory}. 35 | * 36 | * @author Wonchul Heo 37 | * @author Olga Maciaszek-Sharma 38 | */ 39 | class RestClientTransportClientFactoryTests { 40 | 41 | private RestClientTransportClientFactory transportClientFactory; 42 | 43 | @BeforeEach 44 | void setup() { 45 | transportClientFactory = new RestClientTransportClientFactory(Optional.empty(), Optional.empty(), 46 | new DefaultEurekaClientHttpRequestFactorySupplier(new TimeoutProperties(), Collections.emptySet()), 47 | RestClient::builder); 48 | } 49 | 50 | @Test 51 | void withoutUserInfo() { 52 | EurekaHttpClient eurekaHttpClient = transportClientFactory 53 | .newClient(new DefaultEndpoint("http://localhost:8761")); 54 | assertThat(eurekaHttpClient).isInstanceOf(RestClientEurekaHttpClient.class); 55 | } 56 | 57 | @Test 58 | void invalidUserInfo() { 59 | EurekaHttpClient eurekaHttpClient = transportClientFactory 60 | .newClient(new DefaultEndpoint("http://test@localhost:8761")); 61 | assertThat(eurekaHttpClient).isInstanceOf(RestClientEurekaHttpClient.class); 62 | } 63 | 64 | @Test 65 | void userInfo() { 66 | EurekaHttpClient eurekaHttpClient = transportClientFactory 67 | .newClient(new DefaultEndpoint("http://test:test@localhost:8761")); 68 | assertThat(eurekaHttpClient).isInstanceOf(RestClientEurekaHttpClient.class); 69 | } 70 | 71 | @AfterEach 72 | void shutdown() { 73 | transportClientFactory.shutdown(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributing 3 | 4 | Spring Cloud is released under the non-restrictive Apache 2.0 license, 5 | and follows a very standard Github development process, using Github 6 | tracker for issues and merging pull requests into main. If you want 7 | to contribute even something trivial please do not hesitate, but 8 | follow the guidelines below. 9 | 10 | ## Sign the Contributor License Agreement 11 | Before we accept a non-trivial patch or pull request we will need you to sign the 12 | [Contributor License Agreement](https://cla.pivotal.io/sign/spring). 13 | Signing the contributor's agreement does not grant anyone commit rights to the main 14 | repository, but it does mean that we can accept your contributions, and you will get an 15 | author credit if we do. Active contributors might be asked to join the core team, and 16 | given the ability to merge pull requests. 17 | 18 | ## Code of Conduct 19 | This project adheres to the Contributor Covenant [code of 20 | conduct](https://github.com/spring-cloud/spring-cloud-build/blob/main/docs/modules/ROOT/partials/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report 21 | unacceptable behavior to spring-code-of-conduct@pivotal.io. 22 | 23 | ## Code Conventions and Housekeeping 24 | None of these is essential for a pull request, but they will all help. They can also be 25 | added after the original pull request but before a merge. 26 | 27 | * Use the Spring Framework code format conventions. If you use Eclipse 28 | you can import formatter settings using the 29 | `eclipse-code-formatter.xml` file from the 30 | [Spring Cloud Build](https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-dependencies-parent/eclipse-code-formatter.xml) project. If using IntelliJ, you can use the 31 | [Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546) to import the same file. 32 | * Make sure all new `.java` files to have a simple Javadoc class comment with at least an 33 | `@author` tag identifying you, and preferably at least a paragraph on what the class is 34 | for. 35 | * Add the ASF license header comment to all new `.java` files (copy from existing files 36 | in the project) 37 | * Add yourself as an `@author` to the .java files that you modify substantially (more 38 | than cosmetic changes). 39 | * Add some Javadocs and, if you change the namespace, some XSD doc elements. 40 | * A few unit tests would help a lot as well -- someone has to do it. 41 | * If no-one else is using your branch, please rebase it against the current main (or 42 | other target branch in the main project). 43 | * When writing a commit message please follow [these conventions](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), 44 | if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit 45 | message (where XXXX is the issue number). 46 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationWebClientTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.autoconfigure.AutoConfigurations; 22 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 23 | import org.springframework.cloud.config.client.ConfigServerInstanceProvider; 24 | import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; 25 | import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient; 26 | import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | 30 | /** 31 | * @author Spencer Gibb 32 | */ 33 | @SuppressWarnings("removal") 34 | class EurekaConfigServerBootstrapConfigurationWebClientTests { 35 | 36 | @Test 37 | void properBeansCreatedWhenEnabled() { 38 | new ApplicationContextRunner() 39 | .withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) 40 | .withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true", 41 | "eureka.client.webclient.enabled=true") 42 | .run(context -> { 43 | assertThat(context).hasSingleBean(EurekaClientConfigBean.class); 44 | assertThat(context).hasSingleBean(WebClientEurekaHttpClient.class); 45 | assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class); 46 | }); 47 | } 48 | 49 | @Test 50 | void properBeansCreatedWhenEnabledWebClientDisabled() { 51 | new ApplicationContextRunner() 52 | .withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class)) 53 | .withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true") 54 | .run(context -> { 55 | assertThat(context).hasSingleBean(EurekaClientConfigBean.class); 56 | assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class); 57 | assertThat(context).hasSingleBean(RestClientEurekaHttpClient.class); 58 | assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class); 59 | }); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyAndCert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.security.KeyPair; 20 | import java.security.KeyStore; 21 | import java.security.PrivateKey; 22 | import java.security.PublicKey; 23 | import java.security.cert.Certificate; 24 | import java.security.cert.X509Certificate; 25 | 26 | public class KeyAndCert { 27 | 28 | private final KeyPair keyPair; 29 | 30 | private final X509Certificate certificate; 31 | 32 | public KeyAndCert(KeyPair keyPair, X509Certificate certificate) { 33 | this.keyPair = keyPair; 34 | this.certificate = certificate; 35 | } 36 | 37 | public KeyPair keyPair() { 38 | return keyPair; 39 | } 40 | 41 | public PublicKey publicKey() { 42 | return keyPair.getPublic(); 43 | } 44 | 45 | public PrivateKey privateKey() { 46 | return keyPair.getPrivate(); 47 | } 48 | 49 | public X509Certificate certificate() { 50 | return certificate; 51 | } 52 | 53 | public String subject() { 54 | String dn = certificate.getSubjectX500Principal().getName(); 55 | int index = dn.indexOf('='); 56 | return dn.substring(index + 1); 57 | } 58 | 59 | public KeyAndCert sign(String subject) throws Exception { 60 | KeyTool tool = new KeyTool(); 61 | return tool.signCertificate(subject, this); 62 | } 63 | 64 | public KeyAndCert sign(KeyPair keyPair, String subject) throws Exception { 65 | KeyTool tool = new KeyTool(); 66 | return tool.signCertificate(keyPair, subject, this); 67 | } 68 | 69 | public KeyStore storeKeyAndCert(String keyPassword) throws Exception { 70 | KeyStore result = KeyStore.getInstance("PKCS12"); 71 | result.load(null); 72 | 73 | result.setKeyEntry(subject(), keyPair.getPrivate(), keyPassword.toCharArray(), certChain()); 74 | return result; 75 | } 76 | 77 | private Certificate[] certChain() { 78 | return new Certificate[] { certificate() }; 79 | } 80 | 81 | public KeyStore storeCert() throws Exception { 82 | return storeCert("PKCS12"); 83 | } 84 | 85 | public KeyStore storeCert(String storeType) throws Exception { 86 | KeyStore result = KeyStore.getInstance(storeType); 87 | result.load(null); 88 | 89 | result.setCertificateEntry(subject(), certificate()); 90 | return result; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.http; 18 | 19 | import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider; 20 | import com.netflix.discovery.shared.resolver.DefaultEndpoint; 21 | import org.junit.jupiter.api.BeforeEach; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.beans.factory.annotation.Value; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 27 | import org.springframework.cloud.commons.util.InetUtils; 28 | import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; 29 | import org.springframework.test.annotation.DirtiesContext; 30 | import org.springframework.web.reactive.function.client.WebClient; 31 | 32 | /** 33 | * @author Daniel Lavoie 34 | */ 35 | @SpringBootTest(classes = EurekaServerMockApplication.class, 36 | properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true", 37 | "eureka.client.fetch-registry=false", "eureka.client.register-with-eureka=false" }, 38 | webEnvironment = WebEnvironment.RANDOM_PORT) 39 | @DirtiesContext 40 | class WebClientEurekaHttpClientTests extends AbstractEurekaHttpClientTests { 41 | 42 | @Autowired 43 | private InetUtils inetUtils; 44 | 45 | @Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}/eureka/") 46 | private String serviceUrl; 47 | 48 | @BeforeEach 49 | void setup() { 50 | eurekaHttpClient = new WebClientTransportClientFactory(WebClient::builder) 51 | .newClient(new DefaultEndpoint(serviceUrl)); 52 | 53 | EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils); 54 | 55 | String appname = "customapp"; 56 | config.setIpAddress("127.0.0.1"); 57 | config.setHostname("localhost"); 58 | config.setAppname(appname); 59 | config.setVirtualHostName(appname); 60 | config.setSecureVirtualHostName(appname); 61 | config.setNonSecurePort(4444); 62 | config.setSecurePort(8443); 63 | config.setInstanceId("127.0.0.1:customapp:4444"); 64 | 65 | info = new EurekaConfigBasedInstanceInfoProvider(config).get(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/ManagementMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.metadata; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * Stores management metadata for Eureka. 23 | * 24 | * @author Anastasiia Smirnova 25 | * @author Ryan Baxter 26 | */ 27 | public class ManagementMetadata { 28 | 29 | private final String healthCheckUrl; 30 | 31 | private final String statusPageUrl; 32 | 33 | private final Integer managementPort; 34 | 35 | private String secureHealthCheckUrl; 36 | 37 | public ManagementMetadata(String healthCheckUrl, String statusPageUrl, Integer managementPort) { 38 | this.healthCheckUrl = healthCheckUrl; 39 | this.statusPageUrl = statusPageUrl; 40 | this.managementPort = managementPort; 41 | this.secureHealthCheckUrl = null; 42 | } 43 | 44 | public String getHealthCheckUrl() { 45 | return healthCheckUrl; 46 | } 47 | 48 | public String getStatusPageUrl() { 49 | return statusPageUrl; 50 | } 51 | 52 | public Integer getManagementPort() { 53 | return managementPort; 54 | } 55 | 56 | public String getSecureHealthCheckUrl() { 57 | return secureHealthCheckUrl; 58 | } 59 | 60 | public void setSecureHealthCheckUrl(String secureHealthCheckUrl) { 61 | this.secureHealthCheckUrl = secureHealthCheckUrl; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object o) { 66 | if (this == o) { 67 | return true; 68 | } 69 | if (o == null || getClass() != o.getClass()) { 70 | return false; 71 | } 72 | ManagementMetadata that = (ManagementMetadata) o; 73 | return Objects.equals(healthCheckUrl, that.healthCheckUrl) && Objects.equals(statusPageUrl, that.statusPageUrl) 74 | && Objects.equals(managementPort, that.managementPort); 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | return Objects.hash(healthCheckUrl, statusPageUrl, managementPort); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | final StringBuilder sb = new StringBuilder("ManagementMetadata{"); 85 | sb.append("healthCheckUrl='").append(healthCheckUrl).append('\''); 86 | sb.append(", statusPageUrl='").append(statusPageUrl).append('\''); 87 | sb.append(", managementPort=").append(managementPort); 88 | sb.append('}'); 89 | return sb.toString(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceCanceledEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.event; 18 | 19 | import java.util.Objects; 20 | 21 | import org.springframework.context.ApplicationEvent; 22 | 23 | /** 24 | * @author Spencer Gibb 25 | * @author Gregor Zurowski 26 | */ 27 | @SuppressWarnings("serial") 28 | public class EurekaInstanceCanceledEvent extends ApplicationEvent { 29 | 30 | private String appName; 31 | 32 | private String serverId; 33 | 34 | private boolean replication; 35 | 36 | public EurekaInstanceCanceledEvent(Object source, String appName, String serverId, boolean replication) { 37 | super(source); 38 | this.appName = appName; 39 | this.serverId = serverId; 40 | this.replication = replication; 41 | } 42 | 43 | public String getAppName() { 44 | return appName; 45 | } 46 | 47 | public void setAppName(String appName) { 48 | this.appName = appName; 49 | } 50 | 51 | public String getServerId() { 52 | return serverId; 53 | } 54 | 55 | public void setServerId(String serverId) { 56 | this.serverId = serverId; 57 | } 58 | 59 | public boolean isReplication() { 60 | return replication; 61 | } 62 | 63 | public void setReplication(boolean replication) { 64 | this.replication = replication; 65 | } 66 | 67 | @Override 68 | public boolean equals(Object o) { 69 | if (this == o) { 70 | return true; 71 | } 72 | if (o == null || getClass() != o.getClass()) { 73 | return false; 74 | } 75 | EurekaInstanceCanceledEvent that = (EurekaInstanceCanceledEvent) o; 76 | return this.replication == that.replication && Objects.equals(this.appName, that.appName) 77 | && Objects.equals(this.serverId, that.serverId); 78 | } 79 | 80 | @Override 81 | public int hashCode() { 82 | return Objects.hash(appName, serverId, replication); 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return new StringBuilder("EurekaInstanceCanceledEvent{").append("appName='") 88 | .append(appName) 89 | .append("', ") 90 | .append("serverId='") 91 | .append(serverId) 92 | .append("', ") 93 | .append("replication=") 94 | .append(replication) 95 | .append("}") 96 | .toString(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/TimeoutProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.util.Objects; 20 | 21 | import com.netflix.discovery.shared.transport.EurekaHttpClient; 22 | import org.apache.hc.client5.http.config.RequestConfig; 23 | import org.apache.hc.core5.http.io.SocketConfig; 24 | 25 | import org.springframework.boot.context.properties.ConfigurationProperties; 26 | import org.springframework.web.client.RestClient; 27 | 28 | /** 29 | * Properties for configuring timeouts used in {@link RestClient} required by 30 | * {@link EurekaHttpClient}. 31 | * 32 | * @author Jiwon Jeon 33 | * @author Mooyong Lee 34 | * @author Olga Maciaszek-Sharma 35 | * @since 4.2.0 36 | */ 37 | @ConfigurationProperties("eureka.client.timeout") 38 | public class TimeoutProperties { 39 | 40 | /** 41 | * Default values are set to 180000, in keeping with {@link RequestConfig} and 42 | * {@link SocketConfig} defaults. 43 | */ 44 | protected int connectTimeout = 180000; // 3 * MINUTES 45 | 46 | protected int connectRequestTimeout = 180000; // 3 * MINUTES 47 | 48 | protected int socketTimeout = 180000; // 3 * MINUTES 49 | 50 | public int getConnectTimeout() { 51 | return connectTimeout; 52 | } 53 | 54 | public int getConnectRequestTimeout() { 55 | return connectRequestTimeout; 56 | } 57 | 58 | public int getSocketTimeout() { 59 | return socketTimeout; 60 | } 61 | 62 | public void setConnectTimeout(int connectTimeout) { 63 | this.connectTimeout = connectTimeout; 64 | } 65 | 66 | public void setConnectRequestTimeout(int connectRequestTimeout) { 67 | this.connectRequestTimeout = connectRequestTimeout; 68 | } 69 | 70 | public void setSocketTimeout(int socketTimeout) { 71 | this.socketTimeout = socketTimeout; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object o) { 76 | if (this == o) { 77 | return true; 78 | } 79 | if (o == null || getClass() != o.getClass()) { 80 | return false; 81 | } 82 | 83 | TimeoutProperties that = (TimeoutProperties) o; 84 | 85 | return connectTimeout == that.connectTimeout && connectRequestTimeout == that.connectRequestTimeout 86 | && socketTimeout == that.socketTimeout; 87 | } 88 | 89 | @Override 90 | public int hashCode() { 91 | return Objects.hash(connectTimeout, connectRequestTimeout, socketTimeout); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /docs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | org.springframework.cloud 7 | spring-cloud-netflix-docs 8 | 9 | org.springframework.cloud 10 | spring-cloud-netflix 11 | 5.0.1-SNAPSHOT 12 | .. 13 | 14 | jar 15 | Spring Cloud Netflix Docs 16 | Spring Cloud Netflix Docs 17 | 18 | spring-cloud-netflix 19 | ${basedir}/.. 20 | eureka.*|spring.cloud.* 21 | 22 | none 23 | 24 | 25 | src/main/asciidoc 26 | 27 | 28 | 29 | enable-configuration-properties 30 | 31 | 32 | !disableConfigurationProperties 33 | 34 | 35 | 36 | 37 | ${project.groupId} 38 | spring-cloud-starter-netflix-eureka-client 39 | 40 | 41 | ${project.groupId} 42 | spring-cloud-starter-netflix-eureka-server 43 | 44 | 45 | 46 | 47 | docs 48 | 49 | 50 | 51 | src/main/antora/resources/antora-resources 52 | true 53 | 54 | 55 | 56 | 57 | pl.project13.maven 58 | git-commit-id-plugin 59 | 60 | 61 | org.apache.maven.plugins 62 | maven-dependency-plugin 63 | 64 | 65 | org.codehaus.mojo 66 | exec-maven-plugin 67 | 68 | 69 | io.spring.maven.antora 70 | antora-component-version-maven-plugin 71 | 72 | 73 | org.antora 74 | antora-maven-plugin 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-antrun-plugin 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-deploy-plugin 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/healthcheck/EurekaHealthCheckTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.healthcheck; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import com.netflix.discovery.EurekaClient; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 25 | import org.springframework.boot.health.contributor.Health; 26 | import org.springframework.boot.health.contributor.HealthIndicator; 27 | import org.springframework.boot.test.context.SpringBootTest; 28 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.context.annotation.Configuration; 31 | import org.springframework.test.annotation.DirtiesContext; 32 | 33 | import static org.assertj.core.api.Assertions.assertThat; 34 | 35 | /** 36 | * Tests the Eureka health check handler. 37 | * 38 | * @author Jakub Narloch 39 | * @author Olga Maciaszek-Sharma 40 | */ 41 | @SpringBootTest(classes = EurekaHealthCheckTests.EurekaHealthCheckApplication.class, 42 | webEnvironment = WebEnvironment.RANDOM_PORT, value = { "eureka.client.healthcheck.enabled=true", "debug=true" }) 43 | @DirtiesContext 44 | class EurekaHealthCheckTests { 45 | 46 | @Autowired 47 | private EurekaClient discoveryClient; 48 | 49 | @Test 50 | void shouldRegisterService() { 51 | System.setProperty("status", "UP"); 52 | 53 | InstanceInfo.InstanceStatus status = this.discoveryClient.getHealthCheckHandler() 54 | .getStatus(InstanceInfo.InstanceStatus.UNKNOWN); 55 | 56 | assertThat(status).isNotNull(); 57 | assertThat(status).isEqualTo(InstanceInfo.InstanceStatus.UP); 58 | } 59 | 60 | @Test 61 | void shouldMapOutOfServiceToDown() { 62 | System.setProperty("status", "OUT_OF_SERVICE"); 63 | 64 | InstanceInfo.InstanceStatus status = this.discoveryClient.getHealthCheckHandler() 65 | .getStatus(InstanceInfo.InstanceStatus.UNKNOWN); 66 | 67 | assertThat(status).isNotNull(); 68 | assertThat(status).isEqualTo(InstanceInfo.InstanceStatus.DOWN); 69 | } 70 | 71 | @Configuration(proxyBeanMethods = false) 72 | @EnableAutoConfiguration 73 | protected static class EurekaHealthCheckApplication { 74 | 75 | @Bean 76 | public HealthIndicator exampleHealthIndicator() { 77 | return () -> new Health.Builder().status(System.getProperty("status")).build(); 78 | } 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerJerseyClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.io.IOException; 20 | import java.security.GeneralSecurityException; 21 | 22 | import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; 23 | import com.netflix.discovery.Jersey3DiscoveryClientOptionalArgs; 24 | import com.netflix.discovery.shared.transport.jersey.TransportClientFactories; 25 | import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories; 26 | import com.netflix.eureka.transport.EurekaServerHttpClientFactory; 27 | import com.netflix.eureka.transport.Jersey3EurekaServerHttpClientFactory; 28 | 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.boot.autoconfigure.AutoConfiguration; 31 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 32 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 33 | import org.springframework.cloud.configuration.SSLContextFactory; 34 | import org.springframework.cloud.configuration.TlsProperties; 35 | import org.springframework.context.annotation.Bean; 36 | 37 | /** 38 | * @author Olga Maciaszek-Sharma 39 | */ 40 | @AutoConfiguration 41 | @ConditionalOnBean(EurekaServerMarkerConfiguration.Marker.class) 42 | public class EurekaServerJerseyClientAutoConfiguration { 43 | 44 | @Bean 45 | @ConditionalOnMissingBean(AbstractDiscoveryClientOptionalArgs.class) 46 | public Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs( 47 | @Autowired(required = false) TlsProperties tlsProperties) throws GeneralSecurityException, IOException { 48 | Jersey3DiscoveryClientOptionalArgs optionalArgs = new Jersey3DiscoveryClientOptionalArgs(); 49 | if (tlsProperties != null && tlsProperties.isEnabled()) { 50 | SSLContextFactory factory = new SSLContextFactory(tlsProperties); 51 | optionalArgs.setSSLContext(factory.createSSLContext()); 52 | } 53 | return optionalArgs; 54 | } 55 | 56 | @Bean 57 | @ConditionalOnMissingBean(TransportClientFactories.class) 58 | public Jersey3TransportClientFactories jersey3TransportClientFactories() { 59 | return Jersey3TransportClientFactories.getInstance(); 60 | } 61 | 62 | @Bean 63 | @ConditionalOnMissingBean(EurekaServerHttpClientFactory.class) 64 | public Jersey3EurekaServerHttpClientFactory jersey3EurekaServerHttpClientFactory() { 65 | return new Jersey3EurekaServerHttpClientFactory(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import com.netflix.appinfo.EurekaInstanceConfig; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.boot.autoconfigure.AutoConfigurations; 23 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 24 | import org.springframework.cloud.commons.util.UtilAutoConfiguration; 25 | import org.springframework.cloud.config.server.config.ConfigServerProperties; 26 | import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | 30 | /** 31 | * @author Dave Syer 32 | * @author Biju Kunjummen 33 | */ 34 | class EurekaClientConfigServerAutoConfigurationTests { 35 | 36 | @Test 37 | void offByDefault() { 38 | new ApplicationContextRunner() 39 | .withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class)) 40 | .run(c -> assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0)); 41 | } 42 | 43 | @Test 44 | void onWhenRequested() { 45 | new ApplicationContextRunner() 46 | .withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class, 47 | UtilAutoConfiguration.class, ConfigServerProperties.class, EurekaInstanceConfigBean.class)) 48 | .withPropertyValues("spring.cloud.config.server.prefix=/config") 49 | .run(c -> { 50 | assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1); 51 | EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class); 52 | assertThat(instance.getMetadataMap().get("configPath")).isEqualTo("/config"); 53 | }); 54 | } 55 | 56 | @Test 57 | void notOverridingMetamapSettings() { 58 | new ApplicationContextRunner() 59 | .withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class, 60 | UtilAutoConfiguration.class, ConfigServerProperties.class, EurekaInstanceConfigBean.class)) 61 | .withPropertyValues("spring.cloud.config.server.prefix=/config") 62 | .withPropertyValues("eureka.instance.metadataMap.configPath=/differentpath") 63 | .run(c -> { 64 | assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1); 65 | EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class); 66 | assertThat(instance.getMetadataMap().get("configPath")).isEqualTo("/differentpath"); 67 | }); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceRegisteredEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.event; 18 | 19 | import java.util.Objects; 20 | 21 | import com.netflix.appinfo.InstanceInfo; 22 | 23 | import org.springframework.context.ApplicationEvent; 24 | 25 | /** 26 | * @author Spencer Gibb 27 | * @author Gregor Zurowski 28 | */ 29 | @SuppressWarnings("serial") 30 | public class EurekaInstanceRegisteredEvent extends ApplicationEvent { 31 | 32 | private InstanceInfo instanceInfo; 33 | 34 | private int leaseDuration; 35 | 36 | private boolean replication; 37 | 38 | public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo, int leaseDuration, 39 | boolean replication) { 40 | super(source); 41 | this.instanceInfo = instanceInfo; 42 | this.leaseDuration = leaseDuration; 43 | this.replication = replication; 44 | } 45 | 46 | public InstanceInfo getInstanceInfo() { 47 | return instanceInfo; 48 | } 49 | 50 | public void setInstanceInfo(InstanceInfo instanceInfo) { 51 | this.instanceInfo = instanceInfo; 52 | } 53 | 54 | public int getLeaseDuration() { 55 | return leaseDuration; 56 | } 57 | 58 | public void setLeaseDuration(int leaseDuration) { 59 | this.leaseDuration = leaseDuration; 60 | } 61 | 62 | public boolean isReplication() { 63 | return replication; 64 | } 65 | 66 | public void setReplication(boolean replication) { 67 | this.replication = replication; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o) { 72 | if (this == o) { 73 | return true; 74 | } 75 | if (o == null || getClass() != o.getClass()) { 76 | return false; 77 | } 78 | EurekaInstanceRegisteredEvent that = (EurekaInstanceRegisteredEvent) o; 79 | return this.leaseDuration == that.leaseDuration && this.replication == that.replication 80 | && Objects.equals(this.instanceInfo, that.instanceInfo); 81 | } 82 | 83 | @Override 84 | public int hashCode() { 85 | return Objects.hash(instanceInfo, leaseDuration, replication); 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return new StringBuilder("EurekaInstanceRegisteredEvent{").append("instanceInfo=") 91 | .append(instanceInfo) 92 | .append(", ") 93 | .append("leaseDuration=") 94 | .append(leaseDuration) 95 | .append(", ") 96 | .append("replication=") 97 | .append(replication) 98 | .append("}") 99 | .toString(); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collections; 21 | import java.util.List; 22 | import java.util.Locale; 23 | 24 | import com.netflix.appinfo.InstanceInfo; 25 | import com.netflix.discovery.EurekaClient; 26 | import com.netflix.discovery.EurekaClientConfig; 27 | import com.netflix.discovery.shared.Application; 28 | import com.netflix.discovery.shared.Applications; 29 | 30 | import org.springframework.cloud.client.ServiceInstance; 31 | import org.springframework.cloud.client.discovery.DiscoveryClient; 32 | import org.springframework.core.Ordered; 33 | 34 | /** 35 | * A {@link DiscoveryClient} implementation for Eureka. 36 | * 37 | * @author Spencer Gibb 38 | * @author Tim Ysewyn 39 | * @author Olga Maciaszek-Sharma 40 | */ 41 | public class EurekaDiscoveryClient implements DiscoveryClient { 42 | 43 | /** 44 | * Client description {@link String}. 45 | */ 46 | public static final String DESCRIPTION = "Spring Cloud Eureka Discovery Client"; 47 | 48 | private final EurekaClient eurekaClient; 49 | 50 | private final EurekaClientConfig clientConfig; 51 | 52 | public EurekaDiscoveryClient(EurekaClient eurekaClient, EurekaClientConfig clientConfig) { 53 | this.clientConfig = clientConfig; 54 | this.eurekaClient = eurekaClient; 55 | } 56 | 57 | @Override 58 | public String description() { 59 | return DESCRIPTION; 60 | } 61 | 62 | @Override 63 | public List getInstances(String serviceId) { 64 | List infos = this.eurekaClient.getInstancesByVipAddress(serviceId, false); 65 | List instances = new ArrayList<>(); 66 | for (InstanceInfo info : infos) { 67 | instances.add(new EurekaServiceInstance(info)); 68 | } 69 | return instances; 70 | } 71 | 72 | @Override 73 | public List getServices() { 74 | Applications applications = this.eurekaClient.getApplications(); 75 | if (applications == null) { 76 | return Collections.emptyList(); 77 | } 78 | List registered = applications.getRegisteredApplications(); 79 | List names = new ArrayList<>(); 80 | for (Application app : registered) { 81 | if (app.getInstances().isEmpty()) { 82 | continue; 83 | } 84 | names.add(app.getName().toLowerCase(Locale.ROOT)); 85 | 86 | } 87 | return names; 88 | } 89 | 90 | @Override 91 | public int getOrder() { 92 | return clientConfig instanceof Ordered ? ((Ordered) clientConfig).getOrder() : DiscoveryClient.DEFAULT_ORDER; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import com.netflix.appinfo.InstanceInfo; 20 | import org.junit.jupiter.api.Test; 21 | 22 | import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; 23 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 24 | import org.springframework.boot.test.util.TestPropertyValues; 25 | import org.springframework.cloud.commons.util.InetUtils; 26 | import org.springframework.cloud.commons.util.InetUtilsProperties; 27 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | class InstanceInfoFactoryTests { 34 | 35 | private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); 36 | 37 | @Test 38 | void instanceIdIsHostNameByDefault() { 39 | InstanceInfo instanceInfo = setupInstance(); 40 | try (InetUtils utils = new InetUtils(new InetUtilsProperties())) { 41 | assertThat(instanceInfo.getId()).isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname()); 42 | } 43 | } 44 | 45 | @Test 46 | void instanceIdIsIpWhenIpPreferred() { 47 | InstanceInfo instanceInfo = setupInstance("eureka.instance.preferIpAddress:true"); 48 | assertThat(instanceInfo.getId().matches("(\\d+\\.){3}\\d+")).isTrue(); 49 | } 50 | 51 | @Test 52 | void instanceInfoIdIsInstanceIdWhenSet() { 53 | InstanceInfo instanceInfo = setupInstance("eureka.instance.instanceId:special"); 54 | assertThat(instanceInfo.getId()).isEqualTo("special"); 55 | } 56 | 57 | private InstanceInfo setupInstance(String... pairs) { 58 | TestPropertyValues.of(pairs).applyTo(this.context); 59 | 60 | this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class); 61 | this.context.refresh(); 62 | 63 | EurekaInstanceConfigBean instanceConfig = getInstanceConfig(); 64 | return new InstanceInfoFactory().create(instanceConfig); 65 | } 66 | 67 | private EurekaInstanceConfigBean getInstanceConfig() { 68 | return this.context.getBean(EurekaInstanceConfigBean.class); 69 | } 70 | 71 | @Configuration(proxyBeanMethods = false) 72 | @EnableConfigurationProperties 73 | protected static class TestConfiguration { 74 | 75 | @Bean 76 | public EurekaInstanceConfigBean eurekaInstanceConfigBean() { 77 | return new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties())); 78 | } 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMetricsAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.metrics; 18 | 19 | import com.netflix.eureka.registry.PeerAwareInstanceRegistry; 20 | import io.micrometer.core.instrument.MeterRegistry; 21 | 22 | import org.springframework.beans.factory.annotation.Qualifier; 23 | import org.springframework.boot.autoconfigure.AutoConfiguration; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 28 | import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; 29 | import org.springframework.boot.micrometer.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration; 30 | import org.springframework.boot.micrometer.metrics.autoconfigure.MetricsAutoConfiguration; 31 | import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration; 32 | import org.springframework.context.annotation.Bean; 33 | import org.springframework.core.task.TaskExecutor; 34 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 35 | 36 | import static org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME; 37 | 38 | /** 39 | * Auto-configuration for Eureka Instance metrics. 40 | * 41 | * @author Wonchul Heo 42 | * @author Olga Maciaszek-Sharma 43 | * @since 4.1.2 44 | */ 45 | @ConditionalOnClass({ MeterRegistry.class, ThreadPoolTaskExecutor.class }) 46 | @ConditionalOnBean(MeterRegistry.class) 47 | @AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class, 48 | EurekaServerAutoConfiguration.class, TaskExecutionAutoConfiguration.class }) 49 | @ConditionalOnProperty(name = "eureka.server.metrics.enabled", havingValue = "true") 50 | class EurekaInstanceMetricsAutoConfiguration { 51 | 52 | @ConditionalOnMissingBean 53 | @Bean 54 | public EurekaInstanceTagsProvider eurekaInstanceTagProvider() { 55 | return new DefaultEurekaInstanceTagsProvider(); 56 | } 57 | 58 | @ConditionalOnMissingBean 59 | @Bean 60 | public EurekaInstanceMonitor eurekaInstanceMeterBinder(MeterRegistry meterRegistry, 61 | PeerAwareInstanceRegistry instanceRegistry, EurekaInstanceTagsProvider tagProvider, 62 | @Qualifier(APPLICATION_TASK_EXECUTOR_BEAN_NAME) TaskExecutor executor) { 63 | return new EurekaInstanceMonitor(meterRegistry, instanceRegistry, tagProvider, executor); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.util.Collections; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | import org.junit.jupiter.api.BeforeAll; 24 | 25 | import org.springframework.boot.SpringBootConfiguration; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier; 28 | import org.springframework.cloud.netflix.eureka.http.RestClientDiscoveryClientOptionalArgs; 29 | import org.springframework.cloud.netflix.eureka.http.RestClientTransportClientFactories; 30 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 31 | import org.springframework.context.annotation.Bean; 32 | import org.springframework.web.client.RestClient; 33 | 34 | import static org.assertj.core.api.Assertions.assertThat; 35 | 36 | public class EurekaClientTests extends BaseCertTests { 37 | 38 | private static final Log LOG = LogFactory.getLog(EurekaClientTests.class); 39 | 40 | static EurekaServerRunner server; 41 | 42 | static EurekaClientRunner service; 43 | 44 | @BeforeAll 45 | public static void setupAll() { 46 | server = startEurekaServer(EurekaClientTests.TestEurekaServer.class); 47 | service = startService(server, EurekaClientTests.TestApp.class); 48 | assertThat(service.discoveryClientOptionalArgs()).isInstanceOf(RestClientDiscoveryClientOptionalArgs.class); 49 | LOG.info("Successfully asserted that Jersey will be used"); 50 | waitForRegistration(() -> new EurekaClientTests().createEurekaClient()); 51 | } 52 | 53 | @Override 54 | EurekaClientRunner createEurekaClient() { 55 | return new EurekaClientRunner(TestApp.class, server); 56 | } 57 | 58 | @SpringBootConfiguration 59 | @EnableAutoConfiguration 60 | public static class TestApp { 61 | 62 | @Bean 63 | public RestClientTransportClientFactories forceRestClientTransportClientFactories( 64 | RestClientDiscoveryClientOptionalArgs discoveryClientOptionalArgs) { 65 | return new RestClientTransportClientFactories(discoveryClientOptionalArgs); 66 | } 67 | 68 | @Bean 69 | public RestClientDiscoveryClientOptionalArgs discoveryClientOptionalArgs() { 70 | return new RestClientDiscoveryClientOptionalArgs( 71 | new DefaultEurekaClientHttpRequestFactorySupplier(new TimeoutProperties(), Collections.emptySet()), 72 | RestClient::builder); 73 | } 74 | 75 | } 76 | 77 | @SpringBootConfiguration 78 | @EnableAutoConfiguration 79 | @EnableEurekaServer 80 | public static class TestEurekaServer { 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationDashboardPathTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import java.util.Map; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.resttestclient.TestRestTemplate; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 27 | import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application; 28 | import org.springframework.http.HttpStatus; 29 | import org.springframework.http.ResponseEntity; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | @SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, 34 | value = { "spring.application.name=eureka", "eureka.dashboard.path=/dashboard" }) 35 | class ApplicationDashboardPathTests { 36 | 37 | @Value("${local.server.port}") 38 | private int port = 0; 39 | 40 | @Test 41 | void catalogLoads() { 42 | @SuppressWarnings("rawtypes") 43 | ResponseEntity entity = new TestRestTemplate() 44 | .getForEntity("http://localhost:" + this.port + "/eureka/apps", Map.class); 45 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 46 | } 47 | 48 | @Test 49 | void dashboardLoads() { 50 | ResponseEntity entity = new TestRestTemplate() 51 | .getForEntity("http://localhost:" + this.port + "/dashboard", String.class); 52 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 53 | String body = entity.getBody(); 54 | // System.err.println(body); 55 | assertThat(body.contains("eureka/js")).isTrue(); 56 | assertThat(body.contains("eureka/css")).isTrue(); 57 | // The "DS Replicas" 58 | assertThat(body.contains("

Instances currently registered with Eureka

")).isTrue(); 59 | // The Home 60 | assertThat(body.contains("Home")).isTrue(); 61 | // The Lastn 62 | assertThat(body.contains("Last")).isTrue(); 63 | } 64 | 65 | @Test 66 | void cssAvailable() { 67 | ResponseEntity entity = new TestRestTemplate() 68 | .getForEntity("http://localhost:" + this.port + "/eureka/css/wro.css", String.class); 69 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 70 | } 71 | 72 | @Test 73 | void jsAvailable() { 74 | ResponseEntity entity = new TestRestTemplate() 75 | .getForEntity("http://localhost:" + this.port + "/eureka/js/wro.js", String.class); 76 | assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/ConditionalOnRefreshScopeTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.autoconfigure.AutoConfigurations; 22 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 23 | import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; 24 | import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnMissingRefreshScope; 25 | import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnRefreshScope; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | /** 32 | * @author Dave Syer 33 | * @author Biju Kunjummen 34 | */ 35 | class ConditionalOnRefreshScopeTests { 36 | 37 | @Test 38 | void refreshScopeIncluded() { 39 | new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class)) 40 | .withUserConfiguration(Beans.class) 41 | .run(c -> { 42 | assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class); 43 | assertThat(c.getBean("foo")).isEqualTo("foo"); 44 | }); 45 | } 46 | 47 | @Test 48 | void refreshScopeIncludedAndPropertyDisabled() { 49 | new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class)) 50 | .withPropertyValues("eureka.client.refresh.enable=false") 51 | .withUserConfiguration(Beans.class) 52 | .run(c -> { 53 | assertThat(c).hasSingleBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class); 54 | assertThat(c).doesNotHaveBean("foo"); 55 | assertThat(c.getBean("bar")).isEqualTo("bar"); 56 | }); 57 | } 58 | 59 | @Test 60 | void refreshScopeNotIncluded() { 61 | new ApplicationContextRunner().withUserConfiguration(Beans.class).run(c -> { 62 | assertThat(c).doesNotHaveBean("foo"); 63 | assertThat(c.getBean("bar")).isEqualTo("bar"); 64 | }); 65 | 66 | new ApplicationContextRunner().withUserConfiguration(Beans.class) 67 | .withPropertyValues("eureka.client.refresh.enable=false") 68 | .run(c -> { 69 | assertThat(c).doesNotHaveBean("foo"); 70 | assertThat(c.getBean("bar")).isEqualTo("bar"); 71 | }); 72 | } 73 | 74 | @Configuration(proxyBeanMethods = false) 75 | protected static class Beans { 76 | 77 | @Bean 78 | @ConditionalOnRefreshScope 79 | public String foo() { 80 | return "foo"; 81 | } 82 | 83 | @Bean 84 | @ConditionalOnMissingRefreshScope 85 | public String bar() { 86 | return "bar"; 87 | } 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka; 18 | 19 | import java.net.URI; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | 23 | import com.netflix.appinfo.InstanceInfo; 24 | 25 | import org.springframework.cloud.client.ServiceInstance; 26 | import org.springframework.core.style.ToStringCreator; 27 | import org.springframework.util.Assert; 28 | 29 | import static com.netflix.appinfo.InstanceInfo.PortType.SECURE; 30 | 31 | /** 32 | * An Eureka-specific {@link ServiceInstance} implementation. 33 | * 34 | * @author Spencer Gibb 35 | * @author Dave Syer 36 | * @author Olga Maciaszek-Sharma 37 | * @author Tim Ysewyn 38 | */ 39 | public class EurekaServiceInstance implements ServiceInstance { 40 | 41 | private final InstanceInfo instance; 42 | 43 | public EurekaServiceInstance(InstanceInfo instance) { 44 | Assert.notNull(instance, "Service instance required"); 45 | this.instance = instance; 46 | } 47 | 48 | public InstanceInfo getInstanceInfo() { 49 | return instance; 50 | } 51 | 52 | @Override 53 | public String getInstanceId() { 54 | return this.instance.getId(); 55 | } 56 | 57 | @Override 58 | public String getServiceId() { 59 | return this.instance.getAppName(); 60 | } 61 | 62 | @Override 63 | public String getHost() { 64 | return this.instance.getHostName(); 65 | } 66 | 67 | @Override 68 | public int getPort() { 69 | if (isSecure()) { 70 | return this.instance.getSecurePort(); 71 | } 72 | return this.instance.getPort(); 73 | } 74 | 75 | @Override 76 | public boolean isSecure() { 77 | // assume if secure is enabled, that is the default 78 | return this.instance.isPortEnabled(SECURE); 79 | } 80 | 81 | @Override 82 | public URI getUri() { 83 | return ServiceInstance.createUri(this); 84 | } 85 | 86 | @Override 87 | public Map getMetadata() { 88 | return this.instance.getMetadata(); 89 | } 90 | 91 | @Override 92 | public String getScheme() { 93 | return getUri().getScheme(); 94 | } 95 | 96 | @Override 97 | public boolean equals(Object o) { 98 | if (this == o) { 99 | return true; 100 | } 101 | if (o == null || getClass() != o.getClass()) { 102 | return false; 103 | } 104 | EurekaServiceInstance that = (EurekaServiceInstance) o; 105 | return Objects.equals(this.instance, that.instance); 106 | } 107 | 108 | @Override 109 | public int hashCode() { 110 | return Objects.hash(this.instance); 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return new ToStringCreator(this).append("instance", instance).toString(); 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/EurekaCustomPeerNodesTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server; 18 | 19 | import com.netflix.appinfo.ApplicationInfoManager; 20 | import com.netflix.discovery.EurekaClientConfig; 21 | import com.netflix.eureka.EurekaServerConfig; 22 | import com.netflix.eureka.cluster.PeerEurekaNode; 23 | import com.netflix.eureka.cluster.PeerEurekaNodes; 24 | import com.netflix.eureka.registry.PeerAwareInstanceRegistry; 25 | import com.netflix.eureka.resources.ServerCodecs; 26 | import org.junit.jupiter.api.Test; 27 | import org.mockito.Mockito; 28 | 29 | import org.springframework.beans.factory.annotation.Autowired; 30 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 31 | import org.springframework.boot.test.context.SpringBootTest; 32 | import org.springframework.context.annotation.Bean; 33 | import org.springframework.context.annotation.Configuration; 34 | 35 | import static org.assertj.core.api.Assertions.assertThat; 36 | 37 | @SpringBootTest(classes = EurekaCustomPeerNodesTests.Application.class, 38 | webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, value = { "spring.application.name=eureka", 39 | "server.contextPath=/context", "management.security.enabled=false" }) 40 | class EurekaCustomPeerNodesTests { 41 | 42 | @Autowired 43 | private PeerEurekaNodes peerEurekaNodes; 44 | 45 | @Test 46 | void testCustomPeerNodesShouldTakePrecedenceOverDefault() { 47 | assertThat(peerEurekaNodes instanceof CustomEurekaPeerNodes) 48 | .as("PeerEurekaNodes should be the user created one") 49 | .isTrue(); 50 | } 51 | 52 | @Configuration(proxyBeanMethods = false) 53 | @EnableAutoConfiguration 54 | @EnableEurekaServer 55 | protected static class Application { 56 | 57 | @Bean 58 | public PeerEurekaNodes myPeerEurekaNodes(PeerAwareInstanceRegistry registry, 59 | EurekaServerConfig eurekaServerConfig, EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs, 60 | ApplicationInfoManager applicationInfoManager) { 61 | return new CustomEurekaPeerNodes(registry, eurekaServerConfig, eurekaClientConfig, serverCodecs, 62 | applicationInfoManager); 63 | } 64 | 65 | } 66 | 67 | private static class CustomEurekaPeerNodes extends PeerEurekaNodes { 68 | 69 | CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry, EurekaServerConfig serverConfig, 70 | EurekaClientConfig clientConfig, ServerCodecs serverCodecs, 71 | ApplicationInfoManager applicationInfoManager) { 72 | super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager); 73 | } 74 | 75 | @Override 76 | protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) { 77 | return Mockito.mock(PeerEurekaNode.class); 78 | } 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/event/EurekaInstanceRenewedEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.server.event; 18 | 19 | import java.util.Objects; 20 | 21 | import com.netflix.appinfo.InstanceInfo; 22 | 23 | import org.springframework.context.ApplicationEvent; 24 | 25 | /** 26 | * @author Spencer Gibb 27 | * @author Gregor Zurowski 28 | */ 29 | @SuppressWarnings("serial") 30 | public class EurekaInstanceRenewedEvent extends ApplicationEvent { 31 | 32 | private String appName; 33 | 34 | private String serverId; 35 | 36 | private InstanceInfo instanceInfo; 37 | 38 | private boolean replication; 39 | 40 | public EurekaInstanceRenewedEvent(Object source, String appName, String serverId, InstanceInfo instanceInfo, 41 | boolean replication) { 42 | super(source); 43 | this.appName = appName; 44 | this.serverId = serverId; 45 | this.instanceInfo = instanceInfo; 46 | this.replication = replication; 47 | } 48 | 49 | public String getAppName() { 50 | return appName; 51 | } 52 | 53 | public void setAppName(String appName) { 54 | this.appName = appName; 55 | } 56 | 57 | public String getServerId() { 58 | return serverId; 59 | } 60 | 61 | public void setServerId(String serverId) { 62 | this.serverId = serverId; 63 | } 64 | 65 | public InstanceInfo getInstanceInfo() { 66 | return instanceInfo; 67 | } 68 | 69 | public void setInstanceInfo(InstanceInfo instanceInfo) { 70 | this.instanceInfo = instanceInfo; 71 | } 72 | 73 | public boolean isReplication() { 74 | return replication; 75 | } 76 | 77 | public void setReplication(boolean replication) { 78 | this.replication = replication; 79 | } 80 | 81 | @Override 82 | public boolean equals(Object o) { 83 | if (this == o) { 84 | return true; 85 | } 86 | if (o == null || getClass() != o.getClass()) { 87 | return false; 88 | } 89 | EurekaInstanceRenewedEvent that = (EurekaInstanceRenewedEvent) o; 90 | return Objects.equals(appName, that.appName) && Objects.equals(serverId, that.serverId) 91 | && Objects.equals(instanceInfo, that.instanceInfo) && replication == that.replication; 92 | } 93 | 94 | @Override 95 | public int hashCode() { 96 | return Objects.hash(appName, serverId, instanceInfo, replication); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return new StringBuilder("EurekaInstanceRenewedEvent{").append("appName='") 102 | .append(appName) 103 | .append("', ") 104 | .append("serverId='") 105 | .append(serverId) 106 | .append("', ") 107 | .append("instanceInfo=") 108 | .append(instanceInfo) 109 | .append(", ") 110 | .append("replication=") 111 | .append(replication) 112 | .append("}") 113 | .toString(); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationRestClientIntegrationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.SpringBootConfiguration; 23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.boot.test.web.server.LocalServerPort; 26 | import org.springframework.cloud.netflix.eureka.http.RestClientEurekaHttpClient; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.http.HttpStatus; 29 | import org.springframework.http.ResponseEntity; 30 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 31 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; 32 | import org.springframework.security.web.SecurityFilterChain; 33 | import org.springframework.web.bind.annotation.GetMapping; 34 | import org.springframework.web.bind.annotation.RestController; 35 | import org.springframework.web.client.RestClient; 36 | 37 | import static org.assertj.core.api.Assertions.assertThat; 38 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 39 | 40 | /** 41 | * @author Wonchul Heo 42 | */ 43 | @SpringBootTest(properties = { "spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true", 44 | "spring.config.use-legacy-processing=true" }, webEnvironment = RANDOM_PORT) 45 | class EurekaConfigServerBootstrapConfigurationRestClientIntegrationTests { 46 | 47 | @LocalServerPort 48 | private int port; 49 | 50 | @Autowired 51 | private RestClientEurekaHttpClient eurekaHttpClient; 52 | 53 | @Test 54 | void restClientRespectsCodecProperties() { 55 | RestClient restClient = eurekaHttpClient.getRestClient(); 56 | ResponseEntity response = restClient.get() 57 | .uri("http://localhost:" + port) 58 | .retrieve() 59 | .toEntity(String.class); 60 | 61 | assertThat(response).isNotNull(); 62 | assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); 63 | assertThat(response.getBody()).isEqualTo("rest-client"); 64 | } 65 | 66 | @SpringBootConfiguration(proxyBeanMethods = false) 67 | @EnableAutoConfiguration 68 | @RestController 69 | static class RestClientController { 70 | 71 | @GetMapping("/") 72 | public String hello() { 73 | return "rest-client"; 74 | } 75 | 76 | @Bean 77 | public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { 78 | return http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) 79 | .csrf(AbstractHttpConfigurer::disable) 80 | .build(); 81 | } 82 | 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.config; 18 | 19 | import java.util.List; 20 | 21 | import com.netflix.discovery.EurekaClientConfig; 22 | import com.netflix.discovery.endpoint.EndpointUtils; 23 | import com.netflix.discovery.shared.resolver.DefaultEndpoint; 24 | 25 | import org.springframework.boot.context.properties.bind.Binder; 26 | import org.springframework.cloud.config.client.ConfigServerConfigDataLocationResolver.PropertyResolver; 27 | import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; 28 | import org.springframework.core.env.Environment; 29 | import org.springframework.util.StringUtils; 30 | 31 | public final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer { 32 | 33 | private static final String EUREKA_INSTANCE_HOSTNAME = "eureka.instance.hostname"; 34 | 35 | private final String hostname; 36 | 37 | HostnameBasedUrlRandomizer(String hostname) { 38 | this.hostname = hostname; 39 | } 40 | 41 | @Override 42 | public void randomize(List urlList) { 43 | int listSize = 0; 44 | if (urlList != null) { 45 | listSize = urlList.size(); 46 | } 47 | if (!StringUtils.hasText(hostname) || listSize == 0) { 48 | return; 49 | } 50 | // Find the hashcode of the instance hostname and use it to find an entry 51 | // and then arrange the rest of the entries after this entry. 52 | int instanceHashcode = hostname.hashCode(); 53 | if (instanceHashcode < 0) { 54 | instanceHashcode = instanceHashcode * -1; 55 | } 56 | int backupInstance = instanceHashcode % listSize; 57 | for (int i = 0; i < backupInstance; i++) { 58 | String zone = urlList.remove(0); 59 | urlList.add(zone); 60 | } 61 | } 62 | 63 | public static String getEurekaUrl(EurekaClientConfig config, String hostname) { 64 | List urls = EndpointUtils.getDiscoveryServiceUrls(config, EurekaClientConfigBean.DEFAULT_ZONE, 65 | new HostnameBasedUrlRandomizer(hostname)); 66 | return urls.get(0); 67 | } 68 | 69 | public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Environment env) { 70 | String hostname = env.getProperty(EUREKA_INSTANCE_HOSTNAME); 71 | return new DefaultEndpoint(getEurekaUrl(config, hostname)); 72 | } 73 | 74 | public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Binder binder) { 75 | String hostname = binder.bind(EUREKA_INSTANCE_HOSTNAME, String.class).orElseGet(() -> null); 76 | return new DefaultEndpoint(getEurekaUrl(config, hostname)); 77 | } 78 | 79 | public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, PropertyResolver propertyResolver) { 80 | String hostname = propertyResolver.get(EUREKA_INSTANCE_HOSTNAME, String.class, null); 81 | return new DefaultEndpoint(getEurekaUrl(config, hostname)); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.netflix.eureka.loadbalancer; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import org.springframework.boot.autoconfigure.AutoConfigurations; 22 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 23 | import org.springframework.cloud.commons.util.InetUtils; 24 | import org.springframework.cloud.commons.util.InetUtilsProperties; 25 | import org.springframework.cloud.loadbalancer.config.LoadBalancerZoneConfig; 26 | import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; 27 | import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | /** 32 | * Tests for {@link EurekaLoadBalancerClientConfiguration}. 33 | * 34 | * @author Olga Maciaszek-Sharma 35 | */ 36 | class EurekaLoadBalancerClientConfigurationTests { 37 | 38 | private final EurekaClientConfigBean eurekaClientConfig = new EurekaClientConfigBean(); 39 | 40 | private final EurekaInstanceConfigBean eurekaInstanceConfig = new EurekaInstanceConfigBean( 41 | new InetUtils(new InetUtilsProperties())); 42 | 43 | private final LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(null); 44 | 45 | private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties(); 46 | 47 | private final EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration( 48 | eurekaClientConfig, eurekaInstanceConfig, zoneConfig, eurekaLoadBalancerProperties); 49 | 50 | @Test 51 | void shouldSetZoneFromInstanceMetadata() { 52 | eurekaInstanceConfig.getMetadataMap().put("zone", "myZone"); 53 | 54 | postprocessor.postprocess(); 55 | 56 | assertThat(zoneConfig.getZone()).isEqualTo("myZone"); 57 | } 58 | 59 | @Test 60 | void shouldSetZoneToDefaultWhenNotSetInMetadata() { 61 | postprocessor.postprocess(); 62 | 63 | assertThat(zoneConfig.getZone()).isEqualTo("defaultZone"); 64 | } 65 | 66 | @Test 67 | void shouldResolveApproximateZoneFromHost() { 68 | eurekaInstanceConfig.setHostname("this.is.a.test.com"); 69 | eurekaLoadBalancerProperties.setApproximateZoneFromHostname(true); 70 | 71 | postprocessor.postprocess(); 72 | 73 | assertThat(zoneConfig.getZone()).isEqualTo("is.a.test.com"); 74 | } 75 | 76 | @Test 77 | void disabledViaProperty() { 78 | new ApplicationContextRunner() 79 | .withConfiguration(AutoConfigurations.of(LoadBalancerEurekaAutoConfiguration.class)) 80 | .withPropertyValues("eureka.client.enabled=false") 81 | .run(context -> { 82 | assertThat(context).doesNotHaveBean(EurekaLoadBalancerProperties.class); 83 | assertThat(context).doesNotHaveBean(LoadBalancerZoneConfig.class); 84 | }); 85 | } 86 | 87 | } 88 | --------------------------------------------------------------------------------