├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE.md
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── dco.yml
├── dependabot.yml
└── workflows
│ ├── deploy-docs.yml
│ └── maven.yml
├── .gitignore
├── .java-version
├── .mvn
├── jvm.config
├── maven.config
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .sdkmanrc
├── .settings.xml
├── LICENSE.txt
├── README.adoc
├── SECURITY.md
├── docker-compose.yml
├── docs
├── antora-playbook.yml
├── antora.yml
├── modules
│ └── ROOT
│ │ ├── assets
│ │ └── images
│ │ │ └── .gitkeep
│ │ ├── nav.adoc
│ │ ├── pages
│ │ ├── _attributes.adoc
│ │ ├── appendix.adoc
│ │ ├── config.adoc
│ │ ├── configprops.adoc
│ │ ├── dependencies.adoc
│ │ ├── dependency-watcher.adoc
│ │ ├── discovery.adoc
│ │ ├── index.adoc
│ │ ├── install.adoc
│ │ ├── intro.adoc
│ │ ├── other-componentes.adoc
│ │ ├── quickstart.adoc
│ │ └── service-registry.adoc
│ │ └── partials
│ │ └── _configprops.adoc
├── package.json
├── pom.xml
└── src
│ └── main
│ ├── antora
│ └── resources
│ │ └── antora-resources
│ │ └── antora.yml
│ └── asciidoc
│ ├── README.adoc
│ ├── ghpages.sh
│ └── images
│ └── .gitkeep
├── mvnw
├── mvnw.cmd
├── pom.xml
├── scripts
└── runAcceptanceTests.sh
├── spring-cloud-starter-zookeeper-all
└── pom.xml
├── spring-cloud-starter-zookeeper-config
└── pom.xml
├── spring-cloud-starter-zookeeper-discovery
└── pom.xml
├── spring-cloud-starter-zookeeper
└── pom.xml
├── spring-cloud-zookeeper-config
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── zookeeper
│ │ │ └── config
│ │ │ ├── AbstractZookeeperPropertySource.java
│ │ │ ├── ConfigWatcher.java
│ │ │ ├── ZookeeperBootstrapper.java
│ │ │ ├── ZookeeperConfigAutoConfiguration.java
│ │ │ ├── ZookeeperConfigBootstrapConfiguration.java
│ │ │ ├── ZookeeperConfigDataLoader.java
│ │ │ ├── ZookeeperConfigDataLocationResolver.java
│ │ │ ├── ZookeeperConfigDataMissingEnvironmentPostProcessor.java
│ │ │ ├── ZookeeperConfigDataResource.java
│ │ │ ├── ZookeeperConfigProperties.java
│ │ │ ├── ZookeeperPropertySource.java
│ │ │ ├── ZookeeperPropertySourceLocator.java
│ │ │ └── ZookeeperPropertySources.java
│ └── resources
│ │ └── META-INF
│ │ ├── spring.factories
│ │ └── spring
│ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── zookeeper
│ │ └── config
│ │ ├── ZookeeperConfigAutoConfigurationTests.java
│ │ ├── ZookeeperConfigDataCustomizationIntegrationTests.java
│ │ ├── ZookeeperConfigDataIntegrationTests.java
│ │ ├── ZookeeperConfigDataLocationResolverTests.java
│ │ ├── ZookeeperConfigDataMissingEnvironmentPostProcessorTests.java
│ │ ├── ZookeeperConfigDataNoImportIntegrationTests.java
│ │ ├── ZookeeperConfigDataNotOptionalIntegrationTests.java
│ │ ├── ZookeeperPropertySourceLocatorFailFastTests.java
│ │ ├── ZookeeperPropertySourceLocatorNoApplicationNameTests.java
│ │ └── ZookeeperPropertySourceLocatorTests.java
│ └── resources
│ └── application.yml
├── spring-cloud-zookeeper-core
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── zookeeper
│ │ │ ├── ConditionalOnZookeeperEnabled.java
│ │ │ ├── CuratorFactory.java
│ │ │ ├── CuratorFrameworkCustomizer.java
│ │ │ ├── ZookeeperAutoConfiguration.java
│ │ │ ├── ZookeeperHealthAutoConfiguration.java
│ │ │ ├── ZookeeperHealthIndicator.java
│ │ │ └── ZookeeperProperties.java
│ └── resources
│ │ └── META-INF
│ │ ├── additional-spring-configuration-metadata.json
│ │ └── spring
│ │ ├── aot.factories
│ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports
│ └── test
│ └── java
│ └── org
│ └── springframework
│ └── cloud
│ └── zookeeper
│ ├── CuratorFactoryTests.java
│ ├── ZookeeperAutoConfigurationTests.java
│ ├── ZookeeperHealthAutoConfigurationTests.java
│ └── test
│ └── ZookeeperTestingServer.java
├── spring-cloud-zookeeper-dependencies
└── pom.xml
├── spring-cloud-zookeeper-discovery
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── zookeeper
│ │ │ ├── discovery
│ │ │ ├── ConditionalOnLoadBalancerForZookeeperEnabled.java
│ │ │ ├── ConditionalOnZookeeperDiscoveryEnabled.java
│ │ │ ├── DependencyPathUtils.java
│ │ │ ├── LoadBalancerZookeeperAutoConfiguration.java
│ │ │ ├── ZookeeperDiscoveryAutoConfiguration.java
│ │ │ ├── ZookeeperDiscoveryClient.java
│ │ │ ├── ZookeeperDiscoveryClientConfiguration.java
│ │ │ ├── ZookeeperDiscoveryHealthIndicator.java
│ │ │ ├── ZookeeperDiscoveryProperties.java
│ │ │ ├── ZookeeperInstance.java
│ │ │ ├── ZookeeperLoadBalancerConfiguration.java
│ │ │ ├── ZookeeperServiceInstance.java
│ │ │ ├── ZookeeperServiceInstanceListSupplier.java
│ │ │ ├── ZookeeperServiceInstances.java
│ │ │ ├── ZookeeperServiceWatch.java
│ │ │ ├── configclient
│ │ │ │ ├── ZookeeperConfigServerAutoConfiguration.java
│ │ │ │ ├── ZookeeperConfigServerBootstrapper.java
│ │ │ │ └── ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java
│ │ │ ├── dependency
│ │ │ │ ├── ConditionalOnDependenciesNotPassed.java
│ │ │ │ ├── ConditionalOnDependenciesPassed.java
│ │ │ │ ├── DependenciesNotPassedCondition.java
│ │ │ │ ├── DependenciesPassedCondition.java
│ │ │ │ ├── DependencyEnvironmentPostProcessor.java
│ │ │ │ ├── DependencyFeignClientAutoConfiguration.java
│ │ │ │ ├── DependencyRestTemplateAutoConfiguration.java
│ │ │ │ ├── StubsConfiguration.java
│ │ │ │ ├── ZookeeperDependencies.java
│ │ │ │ ├── ZookeeperDependenciesAutoConfiguration.java
│ │ │ │ └── ZookeeperDependency.java
│ │ │ ├── reactive
│ │ │ │ ├── ZookeeperReactiveDiscoveryClient.java
│ │ │ │ └── ZookeeperReactiveDiscoveryClientConfiguration.java
│ │ │ └── watcher
│ │ │ │ ├── DefaultDependencyWatcher.java
│ │ │ │ ├── DependencyRegistrationHookProvider.java
│ │ │ │ ├── DependencyState.java
│ │ │ │ ├── DependencyStateChangeListenerRegistry.java
│ │ │ │ ├── DependencyWatcherAutoConfiguration.java
│ │ │ │ ├── DependencyWatcherListener.java
│ │ │ │ └── presence
│ │ │ │ ├── DefaultDependencyPresenceOnStartupVerifier.java
│ │ │ │ ├── DependencyPresenceOnStartupVerifier.java
│ │ │ │ ├── FailOnMissingDependencyChecker.java
│ │ │ │ ├── LogMissingDependencyChecker.java
│ │ │ │ ├── NoInstancesRunningException.java
│ │ │ │ └── PresenceChecker.java
│ │ │ ├── serviceregistry
│ │ │ ├── ServiceInstanceRegistration.java
│ │ │ ├── ZookeeperAutoServiceRegistration.java
│ │ │ ├── ZookeeperAutoServiceRegistrationAutoConfiguration.java
│ │ │ ├── ZookeeperRegistration.java
│ │ │ ├── ZookeeperServiceRegistry.java
│ │ │ └── ZookeeperServiceRegistryAutoConfiguration.java
│ │ │ └── support
│ │ │ ├── CuratorServiceDiscoveryAutoConfiguration.java
│ │ │ ├── DefaultServiceDiscoveryCustomizer.java
│ │ │ ├── ServiceDiscoveryCustomizer.java
│ │ │ └── StatusConstants.java
│ └── resources
│ │ └── META-INF
│ │ ├── spring.factories
│ │ └── spring
│ │ ├── aot.factories
│ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── zookeeper
│ │ ├── discovery
│ │ ├── TestServiceRegistrar.java
│ │ ├── ZookeeperDiscoveryAutoRegistrationFalseTests.java
│ │ ├── ZookeeperDiscoveryClientTests.java
│ │ ├── ZookeeperDiscoveryDisabledTests.java
│ │ ├── ZookeeperDiscoveryHealthIndicatorDisabledTests.java
│ │ ├── ZookeeperDiscoveryHealthIndicatorWithNestedStructureTests.java
│ │ ├── ZookeeperDiscoveryPropertiesIntegrationTests.java
│ │ ├── ZookeeperDiscoveryPropertiesTests.java
│ │ ├── ZookeeperDiscoverySecurePortTests.java
│ │ ├── ZookeeperDiscoveryTests.java
│ │ ├── ZookeeperLifecycleRegistrationDisabledTests.java
│ │ ├── ZookeeprDiscoveryNonWebAppTests.java
│ │ ├── configclient
│ │ │ ├── DiscoveryClientConfigServiceAutoConfigurationTests.java
│ │ │ ├── ZookeeperConfigServerAutoConfigurationTests.java
│ │ │ ├── ZookeeperConfigServerBootstrapperCustomizerTests.java
│ │ │ ├── ZookeeperConfigServerBootstrapperNoConfigClientTests.java
│ │ │ ├── ZookeeperConfigServerBootstrapperTests.java
│ │ │ └── ZookeeperConfigServerBootstrapperTestsIT.java
│ │ ├── dependency
│ │ │ ├── DependencyConfig.java
│ │ │ ├── StubsConfigurationTests.java
│ │ │ ├── ZookeeperDependenciesTest.java
│ │ │ ├── ZookeeperDependenciesTests.java
│ │ │ ├── ZookeeperDiscoveryWithDependenciesIntegrationTests.java
│ │ │ └── ZookeeperDiscoveryWithDyingDependenciesTests.java
│ │ ├── reactive
│ │ │ ├── ZookeeperReactiveDiscoveryClientConfigurationTests.java
│ │ │ └── ZookeeperReactiveDiscoveryClientTests.java
│ │ ├── test
│ │ │ ├── CommonTestConfig.java
│ │ │ ├── TestLoadBalancedClient.java
│ │ │ └── TestServiceRestClient.java
│ │ └── watcher
│ │ │ ├── DefaultDependencyWatcherSpringTests.java
│ │ │ └── presence
│ │ │ ├── DefaultDependencyPresenceOnStartupVerifierTests.java
│ │ │ └── DependencyPresenceOnStartupVerifierTests.java
│ │ └── serviceregistry
│ │ └── ZookeeperAutoServiceRegistrationTests.java
│ └── resources
│ ├── application-client.yml
│ ├── application-dependencies.yml
│ ├── application-loadbalancer.yml
│ ├── application-loadbalancerclient.yml
│ ├── application-nestedstructure.yml
│ ├── application-server.yml
│ ├── application-watcher.yml
│ ├── application.yml
│ ├── bootstrapper.yaml
│ └── logback-test.xml
├── spring-cloud-zookeeper-sample
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── zookeeper
│ │ │ └── sample
│ │ │ └── SampleZookeeperApplication.java
│ └── resources
│ │ ├── application.yml
│ │ └── bootstrap.yml
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── zookeeper
│ │ └── sample
│ │ ├── SampleApplicationTests.java
│ │ ├── ZookeeperConfigDataOrderingIntegrationTests.java
│ │ └── ZookeeperDisabledTests.java
│ └── resources
│ ├── orderingtest-dev.properties
│ └── orderingtest.properties
└── src
└── checkstyle
└── checkstyle-suppressions.xml
/.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 master. 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/master/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 master (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 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.github/dco.yml:
--------------------------------------------------------------------------------
1 | require:
2 | members: false
3 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | target-branch: "4.1.x"
6 | schedule:
7 | interval: "weekly"
8 | - package-ecosystem: "github-actions"
9 | directory: "/"
10 | target-branch: "4.2.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.1.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.2.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 | ignore:
46 | # only upgrade by minor or patch
47 | - dependency-name: "*"
48 | update-types:
49 | - version-update:semver-major
50 | - package-ecosystem: npm
51 | target-branch: docs-build
52 | directory: /
53 | schedule:
54 | interval: weekly
55 | - package-ecosystem: npm
56 | target-branch: main
57 | directory: /docs
58 | schedule:
59 | interval: weekly
60 | - package-ecosystem: npm
61 | target-branch: 4.1.x
62 | directory: /docs
63 | schedule:
64 | interval: weekly
65 | - package-ecosystem: npm
66 | target-branch: 4.2.x
67 | directory: /docs
68 | schedule:
69 | interval: weekly
70 |
--------------------------------------------------------------------------------
/.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@v4
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 |
--------------------------------------------------------------------------------
/.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.2.x, 4.1.x, 4.0.x, 3.1.x ]
9 | pull_request:
10 | branches: [ main, 4.2.x, 4.1.x, 4.0.x, 3.1.x ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v4
19 | - name: Set up JDK
20 | uses: actions/setup-java@v4
21 | with:
22 | distribution: 'temurin'
23 | java-version: '17'
24 | - name: Cache local Maven repository
25 | uses: actions/cache@v4
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 clean install -B -U -Pspring -Dmaven.test.redirectTestOutputToFile=true
33 | - name: Publish Test Report
34 | uses: mikepenz/action-junit-report@v5
35 | if: always() # always run even if the previous step fails
36 | with:
37 | report_paths: '**/surefire-reports/TEST-*.xml'
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | #*
3 | *#
4 | .#*
5 | .classpath
6 | .project
7 | .settings/
8 | .factorypath
9 | .springBeans
10 | target/
11 | _site/
12 | .idea
13 | *.iml
14 | *.swp
15 | *.log
16 | .checkstyle
17 | .DS_Store
18 | .vscode/
19 | .flattened-pom.xml
20 |
21 | node
22 | node_modules
23 | build
24 | /package.json
25 | package-lock.json
26 |
--------------------------------------------------------------------------------
/.java-version:
--------------------------------------------------------------------------------
1 | 17
2 |
--------------------------------------------------------------------------------
/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
--------------------------------------------------------------------------------
/.mvn/maven.config:
--------------------------------------------------------------------------------
1 | -P spring
2 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-cloud/spring-cloud-zookeeper/34597b99c84b5ed8c6a9212b8e6a2d37073bfe5d/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.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 | # https://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.0/apache-maven-3.9.0-bin.zip
18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
19 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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/snapshot
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/snapshot
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 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Reporting a Vulnerability
4 |
5 | To report security vulnerabilities, please go to https://pivotal.io/security.
6 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | zookeeper:
2 | image: zookeeper
3 | ports:
4 | - "2181:2181"
5 |
--------------------------------------------------------------------------------
/docs/antora-playbook.yml:
--------------------------------------------------------------------------------
1 | antora:
2 | extensions:
3 | - require: '@springio/antora-extensions'
4 | root_component_name: 'cloud-zookeeper'
5 | site:
6 | title: Spring Cloud Zookeeper
7 | url: https://docs.spring.io/spring-cloud-zookeeper/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/antora.yml:
--------------------------------------------------------------------------------
1 | name: cloud-zookeeper
2 | version: true
3 | title: Spring Cloud Zookeeper
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 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/assets/images/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-cloud/spring-cloud-zookeeper/34597b99c84b5ed8c6a9212b8e6a2d37073bfe5d/docs/modules/ROOT/assets/images/.gitkeep
--------------------------------------------------------------------------------
/docs/modules/ROOT/nav.adoc:
--------------------------------------------------------------------------------
1 | * xref:index.adoc[Introduction]
2 | * xref:quickstart.adoc[]
3 | * xref:install.adoc[]
4 | * xref:discovery.adoc[]
5 | * xref:other-componentes.adoc[]
6 | * xref:service-registry.adoc[]
7 | * xref:dependencies.adoc[]
8 | * xref:dependency-watcher.adoc[]
9 | * xref:config.adoc[]
10 | * xref:appendix.adoc[]
11 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/_attributes.adoc:
--------------------------------------------------------------------------------
1 |
2 | :doctype: book
3 | :idprefix:
4 | :idseparator: -
5 | :tabsize: 4
6 | :numbered:
7 | :sectanchors:
8 | :sectnums:
9 | :icons: font
10 | :hide-uri-scheme:
11 | :docinfo: shared,private
12 |
13 | :sc-ext: java
14 | :project-full-name: Spring Cloud Zookeeper
15 |
--------------------------------------------------------------------------------
/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 Zookeeper 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 | include::partial$_configprops.adoc[]
15 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/dependency-watcher.adoc:
--------------------------------------------------------------------------------
1 | [[spring-cloud-zookeeper-dependency-watcher]]
2 | = Spring Cloud Zookeeper Dependency Watcher
3 |
4 | The Dependency Watcher mechanism lets you register listeners to your dependencies. The
5 | functionality is, in fact, an implementation of the `Observer` pattern. When a
6 | dependency changes, its state (to either UP or DOWN), some custom logic can be applied.
7 |
8 | [[activating]]
9 | == Activating
10 |
11 | Spring Cloud Zookeeper Dependencies functionality needs to be enabled for you to use the
12 | Dependency Watcher mechanism.
13 | // TODO: How can the reader do that?
14 |
15 | [[registering-a-listener]]
16 | == Registering a Listener
17 |
18 | To register a listener, you must implement an interface called
19 | `org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener` and
20 | register it as a bean. The interface gives you one method:
21 |
22 | [source,java,indent=0]
23 | ----
24 | void stateChanged(String dependencyName, DependencyState newState);
25 | ----
26 |
27 | If you want to register a listener for a particular dependency, the `dependencyName` would
28 | be the discriminator for your concrete implementation. `newState` provides you with
29 | information about whether your dependency has changed to `CONNECTED` or `DISCONNECTED`.
30 |
31 | [[spring-cloud-zookeeper-dependency-watcher-presence-checker]]
32 | == Using the Presence Checker
33 |
34 | Bound with the Dependency Watcher is the functionality called Presence Checker. It lets
35 | you provide custom behavior when your application boots, to react according to the state
36 | of your dependencies.
37 |
38 | The default implementation of the abstract
39 | `org.springframework.cloud.zookeeper.discovery.watcher.presence.DependencyPresenceOnStartupVerifier`
40 | class is the
41 | `org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier`,
42 | which works in the following way.
43 |
44 | . If the dependency is marked us `required` and is not in Zookeeper, when your application
45 | boots, it throws an exception and shuts down.
46 | . If the dependency is not `required`, the
47 | `org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker`
48 | logs that the dependency is missing at the `WARN` level.
49 |
50 | Because the `DefaultDependencyPresenceOnStartupVerifier` is registered only when there is
51 | no bean of type `DependencyPresenceOnStartupVerifier`, this functionality can be
52 | overridden.
53 |
54 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/index.adoc:
--------------------------------------------------------------------------------
1 | include::intro.adoc[]
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/install.adoc:
--------------------------------------------------------------------------------
1 | [[spring-cloud-zookeeper-install]]
2 | = Working with Zookeeper
3 |
4 | See the https://zookeeper.apache.org/doc/current/zookeeperStarted.html[installation
5 | documentation] for instructions on how to install Zookeeper.
6 |
7 | // TODO: describe Testcontainers and zk
8 |
9 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/intro.adoc:
--------------------------------------------------------------------------------
1 | [[spring-cloud-gateway-intro]]
2 | = Spring Cloud Zookeeper
3 |
4 | This project provides Zookeeper integrations for Spring Boot applications through
5 | autoconfiguration and binding to the Spring Environment and other Spring programming model
6 | idioms. With a few annotations, you can quickly enable and configure the common patterns
7 | inside your application and build large distributed systems with Zookeeper based
8 | components. The provided patterns include Service Discovery and Configuration. The project
9 | also provides client-side load-balancing via integration with Spring Cloud LoadBalancer.
10 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/other-componentes.adoc:
--------------------------------------------------------------------------------
1 | [[spring-cloud-zookeeper-other-componentes]]
2 | = Using Spring Cloud Zookeeper with Spring Cloud Components
3 | :page-section-summary-toc: 1
4 |
5 | Feign, Spring Cloud Gateway and Spring Cloud LoadBalancer all work with Spring Cloud Zookeeper.
6 |
7 | [[spring-cloud-loadbalancer-with-zookeeper]]
8 | == Spring Cloud LoadBalancer with Zookeeper
9 |
10 | Spring Cloud Zookeeper provides an implementation of Spring Cloud LoadBalancer `ServiceInstanceListSupplier`.
11 | When you use the `spring-cloud-starter-zookeeper-discovery`, Spring Cloud LoadBalancer is autoconfigured to use the
12 | `ZookeeperServiceInstanceListSupplier` by default.
13 |
14 | TIP: If you were previously using the StickyRule in Zookeeper, its replacement in the current stack
15 | is the `SameInstancePreferenceServiceInstanceListSupplier` in SC LoadBalancer. You can read on how to set it up in the https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#spring-cloud-loadbalancer[Spring Cloud Commons documentation].
16 |
17 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/pages/service-registry.adoc:
--------------------------------------------------------------------------------
1 | [[spring-cloud-zookeeper-service-registry]]
2 | = Spring Cloud Zookeeper and Service Registry
3 |
4 | Spring Cloud Zookeeper implements the `ServiceRegistry` interface, letting developers
5 | register arbitrary services in a programmatic way.
6 |
7 | The `ServiceInstanceRegistration` class offers a `builder()` method to create a
8 | `Registration` object that can be used by the `ServiceRegistry`, as shown in the following
9 | example:
10 |
11 | [source,java,indent=0]
12 | ----
13 | @Autowired
14 | private ZookeeperServiceRegistry serviceRegistry;
15 |
16 | public void registerThings() {
17 | ZookeeperRegistration registration = ServiceInstanceRegistration.builder()
18 | .defaultUriSpec()
19 | .address("anyUrl")
20 | .port(10)
21 | .name("/a/b/c/d/anotherservice")
22 | .build();
23 | this.serviceRegistry.register(registration);
24 | }
25 | ----
26 |
27 | [[instance-status]]
28 | == Instance Status
29 |
30 | Netflix Eureka supports having instances that are `OUT_OF_SERVICE` registered with the server.
31 | These instances are not returned as active service instances.
32 | This is useful for behaviors such as blue/green deployments.
33 | (Note that the Curator Service Discovery recipe does not support this behavior.) Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement `OUT_OF_SERVICE` by updating some specific metadata and then filtering on that metadata in the Spring Cloud LoadBalancer `ZookeeperServiceInstanceListSupplier`.
34 | The `ZookeeperServiceInstanceListSupplier` filters out all non-null instance statuses that do not equal `UP`.
35 | If the instance status field is empty, it is considered to be `UP` for backwards compatibility.
36 | To change the status of an instance, make a `POST` with `OUT_OF_SERVICE` to the `ServiceRegistry`
37 | instance status actuator endpoint, as shown in the following example:
38 |
39 | [source,sh,indent=0]
40 | ----
41 | $ http POST http://localhost:8081/serviceregistry status=OUT_OF_SERVICE
42 | ----
43 |
44 | NOTE: The preceding example uses the `http` command from https://httpie.org.
45 |
46 |
--------------------------------------------------------------------------------
/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "antora": "3.2.0-alpha.8",
4 | "@antora/atlas-extension": "1.0.0-alpha.2",
5 | "@antora/collector-extension": "1.0.1",
6 | "@asciidoctor/tabs": "1.0.0-beta.6",
7 | "@springio/antora-extensions": "1.14.4",
8 | "@springio/asciidoctor-extensions": "1.0.0-alpha.17"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/docs/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.cloud
8 | spring-cloud-zookeeper
9 | 4.3.1-SNAPSHOT
10 | ..
11 |
12 | spring-cloud-zookeeper-docs
13 | jar
14 | Spring Cloud Zookeeper Docs
15 | Spring Cloud Zookeeper Docs
16 |
17 | spring-cloud-zookeeper
18 | ${basedir}/..
19 | spring.cloud.zookeeper.*
20 |
21 | none
22 |
23 |
24 | 1.0.2
25 | ${maven.multiModuleProjectDirectory}/
26 | .*
27 | ${maven.multiModuleProjectDirectory}/docs/modules/ROOT/partials/
28 |
29 |
30 | src/main/asciidoc
31 |
32 |
33 |
34 | enable-configuration-properties
35 |
36 |
37 | !disableConfigurationProperties
38 |
39 |
40 |
41 |
42 | ${project.groupId}
43 | spring-cloud-starter-zookeeper-all
44 |
45 |
46 |
47 |
48 | docs
49 |
50 |
51 |
52 | src/main/antora/resources/antora-resources
53 | true
54 |
55 |
56 |
57 |
58 | pl.project13.maven
59 | git-commit-id-plugin
60 |
61 |
62 | org.apache.maven.plugins
63 | maven-dependency-plugin
64 |
65 |
66 | org.codehaus.mojo
67 | exec-maven-plugin
68 |
69 |
70 | io.spring.maven.antora
71 | antora-component-version-maven-plugin
72 |
73 |
74 | org.antora
75 | antora-maven-plugin
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-antrun-plugin
80 |
81 |
82 | maven-deploy-plugin
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/README.adoc:
--------------------------------------------------------------------------------
1 | image::https://github.com/spring-cloud/spring-cloud-zookeeper/workflows/Build/badge.svg?style=svg["Actions Status", link="https://github.com/spring-cloud/spring-cloud-zookeeper/actions"]
2 |
3 |
4 |
5 | [[quick-start]]
6 | = Quick Start
7 |
8 |
9 | [[zookeeper-overview]]
10 | = Zookeeper overview
11 |
12 | ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
13 | See the
14 | https://zookeeper.apache.org[Zookeeper site] for more information.
15 | Spring Cloud Zookeeper also builds on the https://curator.apache.org[Apache Curator] project, which started life at Netflix.
16 |
17 | [[spring-cloud-zookeeper-features]]
18 | = Spring Cloud Zookeeper Features
19 |
20 | Spring Cloud Zookeeper includes the following features:
21 |
22 | * Spring Cloud `DiscoveryClient` implementation (supports Spring Cloud LoadBalancer)
23 | * Zookeeper-based `PropertySource` loaded during the 'bootstrap' phase
24 |
25 | [[running-the-sample]]
26 | = Running the Sample
27 |
28 | . https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_Download[Install
29 | zookeeper] (On a mac with homebrew, use `brew install zookeeper`).
30 | . https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_InstallingSingleMode[Start
31 | zookeeper].
32 | . https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_ConnectingToZooKeeper[Verify
33 | zookeeper is running].
34 | . Run `mvn --settings .settings.xml package`.
35 | Doing so brings in the required Spring Cloud Maven repositories and Build.
36 | . Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar`.
37 | . Visit http://localhost:8080 to verify that `{"serviceId":"testZookeeperApp","host":"","port":8080}` works.
38 | . Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar --server.port=8081`
39 | . Visit http://localhost:8080 again to verify that `{"serviceId":"testZookeeperApp","host":"","port":8081}` eventually shows up in the results in a round-robin fashion. (It may take a minute or so.)
40 |
41 | [[building]]
42 | = Building
43 |
44 | include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[]
45 |
46 | [[contributing]]
47 | = Contributing
48 |
49 | include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[]
50 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/images/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-cloud/spring-cloud-zookeeper/34597b99c84b5ed8c6a9212b8e6a2d37073bfe5d/docs/src/main/asciidoc/images/.gitkeep
--------------------------------------------------------------------------------
/scripts/runAcceptanceTests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -o errexit
4 |
5 | SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/2021.0.x/runAcceptanceTests.sh"
6 | AT_WHAT_TO_TEST="ZOOKEEPER"
7 |
8 | curl "${SCRIPT_URL}" --output runAcceptanceTests.sh
9 |
10 | chmod +x runAcceptanceTests.sh
11 |
12 | ./runAcceptanceTests.sh --whattotest "${AT_WHAT_TO_TEST}" --killattheend
13 |
--------------------------------------------------------------------------------
/spring-cloud-starter-zookeeper-all/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.cloud
7 | spring-cloud-zookeeper
8 | 4.3.1-SNAPSHOT
9 | ..
10 |
11 | spring-cloud-starter-zookeeper-all
12 | Spring Cloud Starter Zookeeper All
13 | Spring Cloud Starter Zookeeper All
14 | https://projects.spring.io/spring-cloud
15 |
16 | Pivotal Software, Inc.
17 | https://www.spring.io
18 |
19 |
20 | ${basedir}/../..
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-zookeeper-config
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-starter-zookeeper-discovery
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spring-cloud-starter-zookeeper-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.cloud
7 | spring-cloud-zookeeper
8 | 4.3.1-SNAPSHOT
9 | ..
10 |
11 | spring-cloud-starter-zookeeper-config
12 | Spring Cloud Starter Zookeeper Config
13 | Spring Cloud Starter Zookeeper Config
14 | https://projects.spring.io/spring-cloud
15 |
16 | Pivotal Software, Inc.
17 | https://www.spring.io
18 |
19 |
20 | ${basedir}/../..
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-zookeeper
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-zookeeper-config
30 |
31 |
32 | org.apache.curator
33 | curator-recipes
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/spring-cloud-starter-zookeeper-discovery/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.cloud
8 | spring-cloud-zookeeper
9 | 4.3.1-SNAPSHOT
10 | ..
11 |
12 | spring-cloud-starter-zookeeper-discovery
13 | Spring Cloud Starter Zookeeper Discovery
14 | Spring Cloud Starter Zookeeper Discovery
15 | https://projects.spring.io/spring-cloud
16 |
17 | Pivotal Software, Inc.
18 | https://www.spring.io
19 |
20 |
21 | ${basedir}/../..
22 |
23 |
24 |
25 | org.springframework.cloud
26 | spring-cloud-starter-zookeeper
27 |
28 |
29 | org.springframework.cloud
30 | spring-cloud-zookeeper-discovery
31 |
32 |
33 | org.apache.curator
34 | curator-x-discovery
35 |
36 |
37 | org.springframework.cloud
38 | spring-cloud-starter-loadbalancer
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/spring-cloud-starter-zookeeper/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.cloud
7 | spring-cloud-zookeeper
8 | 4.3.1-SNAPSHOT
9 | ..
10 |
11 | spring-cloud-starter-zookeeper
12 | Spring Cloud Starter Zookeeper
13 | Spring Cloud Starter Zookeeper
14 | https://projects.spring.io/spring-cloud
15 |
16 | Pivotal Software, Inc.
17 | https://www.spring.io
18 |
19 |
20 | ${basedir}/../..
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-zookeeper-core
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | spring-cloud-zookeeper-config
8 | jar
9 | Spring Cloud Zookeeper Config
10 | Spring Cloud Zookeeper Config
11 |
12 |
13 | org.springframework.cloud
14 | spring-cloud-zookeeper
15 | 4.3.1-SNAPSHOT
16 | ..
17 |
18 |
19 |
20 |
21 |
22 | org.apache.maven.plugins
23 | maven-compiler-plugin
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.cloud
31 | spring-cloud-zookeeper-core
32 |
33 |
34 | org.apache.curator
35 | curator-x-discovery
36 |
37 |
38 | org.springframework.cloud
39 | spring-cloud-commons
40 |
41 |
42 | org.springframework.cloud
43 | spring-cloud-context
44 | true
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-web
49 | true
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-starter-actuator
54 | true
55 |
56 |
57 | org.apache.curator
58 | curator-recipes
59 | true
60 |
61 |
62 | org.springframework.boot
63 | spring-boot-autoconfigure-processor
64 | true
65 |
66 |
67 | org.springframework.boot
68 | spring-boot-configuration-processor
69 | true
70 |
71 |
72 | org.springframework.boot
73 | spring-boot-starter-test
74 | test
75 |
76 |
77 | org.junit.vintage
78 | junit-vintage-engine
79 | test
80 |
81 |
82 | org.springframework.cloud
83 | spring-cloud-zookeeper-core
84 | ${project.version}
85 | test-jar
86 | test
87 |
88 |
89 | org.apache.curator
90 | curator-test
91 | test
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/AbstractZookeeperPropertySource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 |
21 | import org.springframework.core.env.EnumerablePropertySource;
22 |
23 | /**
24 | * A {@link EnumerablePropertySource} that has a notion of a context which is the root
25 | * folder in Zookeeper.
26 | *
27 | * @author Spencer Gibb
28 | * @since 1.0.0
29 | */
30 | public abstract class AbstractZookeeperPropertySource
31 | extends EnumerablePropertySource {
32 |
33 | private String context;
34 |
35 | public AbstractZookeeperPropertySource(String context, CuratorFramework source) {
36 | super(context, source);
37 | this.context = context;
38 | if (!this.context.startsWith("/")) {
39 | this.context = "/" + this.context;
40 | }
41 | }
42 |
43 | protected String sanitizeKey(String path) {
44 | return path.replace(this.context + "/", "").replace('/', '.');
45 | }
46 |
47 | public String getContext() {
48 | return this.context;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperBootstrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2020 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.zookeeper.config;
18 |
19 | import java.util.function.Function;
20 |
21 | import org.apache.curator.RetryPolicy;
22 | import org.apache.curator.drivers.TracerDriver;
23 | import org.apache.curator.ensemble.EnsembleProvider;
24 | import org.apache.curator.framework.CuratorFramework;
25 |
26 | import org.springframework.boot.BootstrapContext;
27 | import org.springframework.boot.BootstrapRegistry;
28 | import org.springframework.boot.BootstrapRegistryInitializer;
29 | import org.springframework.cloud.zookeeper.CuratorFrameworkCustomizer;
30 |
31 | public class ZookeeperBootstrapper implements BootstrapRegistryInitializer {
32 |
33 | private Function retryPolicy;
34 |
35 | private Function ensembleProvider;
36 |
37 | private Function tracerDriver;
38 |
39 | private Function curatorFrameworkCustomizer;
40 |
41 | static BootstrapRegistryInitializer fromBootstrapContext(Function factory) {
42 | return registry -> registry.register(CuratorFramework.class, factory::apply);
43 | }
44 |
45 | static ZookeeperBootstrapper create() {
46 | return new ZookeeperBootstrapper();
47 | }
48 |
49 | public ZookeeperBootstrapper retryPolicy(Function retryPolicy) {
50 | this.retryPolicy = retryPolicy;
51 | return this;
52 | }
53 |
54 | public ZookeeperBootstrapper ensembleProvider(Function ensembleProvider) {
55 | this.ensembleProvider = ensembleProvider;
56 | return this;
57 | }
58 |
59 | public ZookeeperBootstrapper tracerDriver(Function tracerDriver) {
60 | this.tracerDriver = tracerDriver;
61 | return this;
62 | }
63 |
64 | public ZookeeperBootstrapper curatorFrameworkCustomizer(Function curatorFrameworkCustomizer) {
65 | this.curatorFrameworkCustomizer = curatorFrameworkCustomizer;
66 | return this;
67 | }
68 |
69 | @Override
70 | public void initialize(BootstrapRegistry registry) {
71 | register(registry, RetryPolicy.class, retryPolicy);
72 | register(registry, EnsembleProvider.class, ensembleProvider);
73 | register(registry, TracerDriver.class, tracerDriver);
74 | register(registry, CuratorFrameworkCustomizer.class, curatorFrameworkCustomizer);
75 | }
76 |
77 | private void register(BootstrapRegistry registry, Class type, Function factory) {
78 | if (this.retryPolicy != null) {
79 | registry.register(type, factory::apply);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import java.util.Collections;
20 | import java.util.List;
21 |
22 | import org.apache.curator.framework.CuratorFramework;
23 |
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.cloud.endpoint.RefreshEndpoint;
29 | import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.Configuration;
32 | import org.springframework.core.env.Environment;
33 |
34 | /**
35 | * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
36 | * Auto-configuration} that registers a Zookeeper configuration watcher.
37 | *
38 | * @author Spencer Gibb
39 | * @since 1.0.0
40 | */
41 | @Configuration(proxyBeanMethods = false)
42 | @ConditionalOnZookeeperEnabled
43 | @ConditionalOnProperty(value = "spring.cloud.zookeeper.config.enabled", matchIfMissing = true)
44 | public class ZookeeperConfigAutoConfiguration {
45 |
46 | @Configuration(proxyBeanMethods = false)
47 | @ConditionalOnClass(RefreshEndpoint.class)
48 | @ConditionalOnProperty(name = "spring.cloud.zookeeper.config.watcher.enabled", matchIfMissing = true)
49 | protected static class ZkRefreshConfiguration {
50 |
51 | @Bean
52 | @ConditionalOnBean(ZookeeperPropertySourceLocator.class)
53 | public ConfigWatcher propertySourceLocatorConfigWatcher(ZookeeperPropertySourceLocator locator,
54 | CuratorFramework curator) {
55 | return new ConfigWatcher(locator.getContexts(), curator);
56 | }
57 |
58 | @Bean
59 | @ConditionalOnMissingBean(ZookeeperPropertySourceLocator.class)
60 | public ConfigWatcher configDataConfigWatcher(CuratorFramework curator, Environment env) {
61 | List contexts = env.getProperty("spring.cloud.zookeeper.config.property-source-contexts",
62 | List.class, Collections.emptyList());
63 | return new ConfigWatcher(contexts, curator);
64 | }
65 |
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigBootstrapConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 |
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22 | import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
23 | import org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration;
24 | import org.springframework.context.annotation.Bean;
25 | import org.springframework.context.annotation.Configuration;
26 | import org.springframework.context.annotation.Import;
27 | import org.springframework.core.env.Environment;
28 | import org.springframework.util.StringUtils;
29 |
30 | /**
31 | * Bootstrap Configuration for Zookeeper Configuration.
32 | *
33 | * @author Spencer Gibb
34 | * @since 1.0.0
35 | */
36 | @Configuration(proxyBeanMethods = false)
37 | @ConditionalOnZookeeperEnabled
38 | @Import(ZookeeperAutoConfiguration.class)
39 | public class ZookeeperConfigBootstrapConfiguration {
40 |
41 | @Bean
42 | @ConditionalOnMissingBean
43 | public ZookeeperPropertySourceLocator zookeeperPropertySourceLocator(
44 | CuratorFramework curator, ZookeeperConfigProperties properties) {
45 | return new ZookeeperPropertySourceLocator(curator, properties);
46 | }
47 |
48 | @Bean
49 | @ConditionalOnMissingBean
50 | public ZookeeperConfigProperties zookeeperConfigProperties(Environment env) {
51 | ZookeeperConfigProperties properties = new ZookeeperConfigProperties();
52 | if (!StringUtils.hasLength(properties.getName())) {
53 | properties.setName(env.getProperty("spring.application.name", "application"));
54 | }
55 | return properties;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2020 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.zookeeper.config;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 |
23 | import org.apache.commons.logging.Log;
24 | import org.apache.curator.framework.CuratorFramework;
25 |
26 | import org.springframework.boot.context.config.ConfigData;
27 | import org.springframework.boot.context.config.ConfigDataLoader;
28 | import org.springframework.boot.context.config.ConfigDataLoaderContext;
29 | import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
30 | import org.springframework.boot.logging.DeferredLogFactory;
31 | import org.springframework.util.StringUtils;
32 |
33 | public class ZookeeperConfigDataLoader implements ConfigDataLoader {
34 |
35 | private final Log log;
36 |
37 | public ZookeeperConfigDataLoader(DeferredLogFactory logFactory) {
38 | this.log = logFactory.getLog(ZookeeperConfigDataLoader.class);
39 | }
40 |
41 | @Override
42 | public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataResource resource) {
43 | try {
44 | CuratorFramework curator = context.getBootstrapContext().get(CuratorFramework.class);
45 | if (curator == null) {
46 | // this can happen if certain conditions are met
47 | return null;
48 | }
49 | ZookeeperPropertySource propertySource = new ZookeeperPropertySource(resource.getContext(),
50 | curator);
51 | List propertySources = Collections.singletonList(propertySource);
52 |
53 | return new ConfigData(propertySources, source -> {
54 | List options = new ArrayList<>();
55 | options.add(ConfigData.Option.IGNORE_IMPORTS);
56 | options.add(ConfigData.Option.IGNORE_PROFILES);
57 | if (StringUtils.hasText(resource.getProfile())) {
58 | options.add(ConfigData.Option.PROFILE_SPECIFIC);
59 | }
60 | return ConfigData.Options.of(options.toArray(new ConfigData.Option[0]));
61 | });
62 |
63 | }
64 | catch (Exception e) {
65 | if (log.isDebugEnabled()) {
66 | log.debug("Error getting properties from zookeeper: " + resource, e);
67 | }
68 | throw new ConfigDataResourceNotFoundException(resource, e);
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataResource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2020 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.zookeeper.config;
18 |
19 | import java.util.Objects;
20 |
21 | import org.springframework.boot.context.config.ConfigDataResource;
22 | import org.springframework.core.style.ToStringCreator;
23 |
24 | public class ZookeeperConfigDataResource extends ConfigDataResource {
25 |
26 | private final String context;
27 | private final boolean optional;
28 | private final String profile;
29 |
30 | public ZookeeperConfigDataResource(String context, boolean optional, String profile) {
31 | this.context = context;
32 | this.optional = optional;
33 | this.profile = profile;
34 | }
35 |
36 | @Deprecated
37 | public ZookeeperConfigDataResource(String context, boolean optional) {
38 | this(context, optional, null);
39 | }
40 |
41 | public String getContext() {
42 | return this.context;
43 | }
44 |
45 | public boolean isOptional() {
46 | return this.optional;
47 | }
48 |
49 | public String getProfile() {
50 | return this.profile;
51 | }
52 |
53 | @Override
54 | public boolean equals(Object o) {
55 | if (this == o) {
56 | return true;
57 | }
58 | if (o == null || getClass() != o.getClass()) {
59 | return false;
60 | }
61 | ZookeeperConfigDataResource that = (ZookeeperConfigDataResource) o;
62 | return this.optional == that.optional && this.context.equals(that.context) && Objects.equals(this.profile, that.profile);
63 | }
64 |
65 | @Override
66 | public int hashCode() {
67 | return Objects.hash(this.optional, this.context, this.profile);
68 | }
69 |
70 | @Override
71 | public String toString() {
72 | return new ToStringCreator(this)
73 | .append("context", context)
74 | .append("optional", optional)
75 | .append("profile", profile)
76 | .toString();
77 |
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | # Bootstrap Configuration
2 | org.springframework.cloud.bootstrap.BootstrapConfiguration=\
3 | org.springframework.cloud.zookeeper.config.ZookeeperConfigBootstrapConfiguration
4 |
5 | # Environment PostProcessor
6 | org.springframework.boot.env.EnvironmentPostProcessor=\
7 | org.springframework.cloud.zookeeper.config.ZookeeperConfigDataMissingEnvironmentPostProcessor
8 |
9 | org.springframework.boot.diagnostics.FailureAnalyzer=\
10 | org.springframework.cloud.zookeeper.config.ZookeeperConfigDataMissingEnvironmentPostProcessor.ImportExceptionFailureAnalyzer
11 |
12 | # ConfigData Location Resolvers
13 | org.springframework.boot.context.config.ConfigDataLocationResolver=\
14 | org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLocationResolver
15 |
16 | # ConfigData Loaders
17 | org.springframework.boot.context.config.ConfigDataLoader=\
18 | org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLoader
19 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports:
--------------------------------------------------------------------------------
1 | org.springframework.cloud.zookeeper.config.ZookeeperConfigAutoConfiguration
2 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataNotOptionalIntegrationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import org.assertj.core.api.Assertions;
20 | import org.junit.jupiter.api.Test;
21 |
22 | import org.springframework.boot.WebApplicationType;
23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
24 | import org.springframework.boot.builder.SpringApplicationBuilder;
25 | import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
26 | import org.springframework.cloud.context.refresh.ConfigDataContextRefresher;
27 | import org.springframework.cloud.context.refresh.ContextRefresher;
28 | import org.springframework.cloud.context.scope.refresh.RefreshScope;
29 | import org.springframework.context.ConfigurableApplicationContext;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.Configuration;
32 |
33 | /**
34 | * @author Spencer Gibb
35 | */
36 | public class ZookeeperConfigDataNotOptionalIntegrationTests {
37 |
38 | @Test
39 | public void configDataNotFoundThrowsException() {
40 | Assertions.assertThatThrownBy(() -> {
41 | ConfigurableApplicationContext context = null;
42 | try {
43 | context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).run(
44 | "--spring.cloud.zookeeper.connect-string=notexistantdomain:5000", "--debug=true",
45 | "--spring.cloud.zookeeper.max-retries=0",
46 | "--spring.cloud.zookeeper.blockUntilConnectedWait=1",
47 | "--spring.cloud.zookeeper.blockUntilConnectedUnit=MILLISECONDS",
48 | "--spring.cloud.zookeeper.connection-timeout=1ms",
49 | "--spring.config.import=zookeeper:",
50 | "--spring.application.name=testZkConfigDataNotOptionalIntegration",
51 | "--logging.level.org.springframework.cloud.zookeeper=DEBUG",
52 | "--spring.cloud.zookeeper.config.root=/shouldfail");
53 |
54 | }
55 | finally {
56 | if (context != null) {
57 | context.close();
58 | }
59 | }
60 | }).isInstanceOf(ConfigDataResourceNotFoundException.class);
61 | }
62 |
63 | @Configuration
64 | @EnableAutoConfiguration
65 | static class Config {
66 |
67 | @Bean
68 | public ContextRefresher contextRefresher(ConfigurableApplicationContext context, RefreshScope scope) {
69 | return new ConfigDataContextRefresher(context, scope);
70 | }
71 |
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorFailFastTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import org.junit.After;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import org.springframework.boot.SpringBootConfiguration;
24 | import org.springframework.boot.WebApplicationType;
25 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26 | import org.springframework.boot.builder.SpringApplicationBuilder;
27 |
28 | import static org.assertj.core.api.Assertions.assertThatCode;
29 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
30 |
31 | /**
32 | * @author Enrique Recarte Llorens
33 | * @author Olga Maciaszek-Sharma
34 | */
35 | public class ZookeeperPropertySourceLocatorFailFastTests {
36 |
37 | @Before
38 | public void setUp() {
39 | // This system property makes Curator fail faster, otherwise it takes 15 seconds
40 | // to trigger a retry
41 | System.setProperty("curator-default-connection-timeout", "0");
42 | }
43 |
44 | @After
45 | public void tearDown() {
46 | System.clearProperty("curator-default-connection-timeout");
47 | }
48 |
49 | @Test
50 | public void testFailFastFalseLoadsTheApplicationContext() {
51 | assertThatCode(() -> {
52 | new SpringApplicationBuilder().sources(Config.class)
53 | .web(WebApplicationType.NONE)
54 | .run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
55 | "--spring.config.use-legacy-processing=true",
56 | "--spring.cloud.zookeeper.config.connectString=localhost:2188",
57 | "--spring.cloud.zookeeper.baseSleepTimeMs=0",
58 | "--spring.cloud.zookeeper.maxRetries=0",
59 | "--spring.cloud.zookeeper.maxSleepMs=0",
60 | "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
61 | "--spring.cloud.zookeeper.config.failFast=false");
62 | }).doesNotThrowAnyException();
63 | }
64 |
65 | @Test
66 | public void testFailFastTrueDoesNotLoadTheApplicationContext() {
67 | assertThatThrownBy(() -> {
68 | new SpringApplicationBuilder().sources(Config.class)
69 | .web(WebApplicationType.NONE)
70 | .run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
71 | "--spring.config.use-legacy-processing=true",
72 | "--spring.cloud.zookeeper.config.connectString=localhost:2188",
73 | "--spring.cloud.zookeeper.baseSleepTimeMs=0",
74 | "--spring.cloud.zookeeper.maxRetries=0",
75 | "--spring.cloud.zookeeper.maxSleepMs=0",
76 | "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
77 | "--spring.cloud.zookeeper.config.failFast=true");
78 | })
79 | .isNotNull();
80 | }
81 |
82 | @SpringBootConfiguration
83 | @EnableAutoConfiguration
84 | static class Config {
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorNoApplicationNameTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.config;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 | import org.apache.curator.framework.api.GetChildrenBuilder;
21 | import org.junit.Test;
22 |
23 | import org.springframework.mock.env.MockEnvironment;
24 |
25 | import static org.mockito.Mockito.mock;
26 | import static org.mockito.Mockito.when;
27 |
28 | /**
29 | * @author Spencer Gibb
30 | */
31 | public class ZookeeperPropertySourceLocatorNoApplicationNameTests {
32 |
33 | @Test
34 | public void defaultSpringApplicationNameWorks() {
35 | CuratorFramework curator = mock(CuratorFramework.class);
36 | when(curator.getChildren()).thenReturn(mock(GetChildrenBuilder.class));
37 | ZookeeperConfigProperties properties = new ZookeeperConfigProperties();
38 | properties.setName("notempty");
39 | ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(
40 | curator, properties);
41 | locator.locate(new MockEnvironment());
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-config/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | logging:
2 | level:
3 | org.apache.zookeeper.ClientCnxn: ERROR
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | spring-cloud-zookeeper-core
8 | jar
9 | Spring Cloud Zookeeper Core
10 | Spring Cloud Zookeeper Core
11 |
12 |
13 | org.springframework.cloud
14 | spring-cloud-zookeeper
15 | 4.3.1-SNAPSHOT
16 | ..
17 |
18 |
19 |
20 |
21 |
22 | org.apache.maven.plugins
23 | maven-compiler-plugin
24 |
25 |
26 | org.apache.maven.plugins
27 | maven-jar-plugin
28 | 3.4.2
29 |
30 |
31 |
32 | test-jar
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-configuration-processor
44 | true
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-web
49 | true
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-starter-actuator
54 | true
55 |
56 |
57 | org.springframework.cloud
58 | spring-cloud-commons
59 | true
60 |
61 |
62 | org.apache.curator
63 | curator-x-discovery
64 | true
65 |
66 |
67 | org.apache.curator
68 | curator-framework
69 | true
70 |
71 |
72 | org.springframework.boot
73 | spring-boot-autoconfigure-processor
74 | true
75 |
76 |
77 | org.apache.curator
78 | curator-test
79 | test
80 |
81 |
82 | org.springframework.boot
83 | spring-boot-starter-test
84 | test
85 |
86 |
87 | org.junit.vintage
88 | junit-vintage-engine
89 | test
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ConditionalOnZookeeperEnabled.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25 |
26 | /**
27 | * Wrapper annotation to enable Zookeeper.
28 | *
29 | * @author Marcin Grzejszczak
30 | * @since 1.1.0
31 | */
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Target({ ElementType.TYPE, ElementType.METHOD })
34 | @ConditionalOnProperty(value = "spring.cloud.zookeeper.enabled", matchIfMissing = true)
35 | public @interface ConditionalOnZookeeperEnabled {
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/CuratorFrameworkCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper;
18 |
19 | import org.apache.curator.RetryPolicy;
20 | import org.apache.curator.framework.CuratorFramework;
21 | import org.apache.curator.framework.CuratorFrameworkFactory;
22 |
23 | import org.springframework.beans.factory.ObjectProvider;
24 |
25 | /**
26 | * Beans that implement this interface will be used by the
27 | * {@link ZookeeperAutoConfiguration#curatorFramework(RetryPolicy, ZookeeperProperties, ObjectProvider, ObjectProvider, ObjectProvider)
28 | * ZookeeperAutoConfiguration} ZookeeperAutoConfiguration} to further customize the
29 | * {@link CuratorFramework} that it provides.
30 | *
31 | * @author Bernardo Gomez Palacio.
32 | * @see ZookeeperAutoConfiguration
33 | */
34 | @FunctionalInterface
35 | public interface CuratorFrameworkCustomizer {
36 |
37 | /**
38 | * Customize the {@link CuratorFrameworkFactory.Builder}.
39 | * @param builder instance of the builder that you can further customize.
40 | */
41 | void customize(CuratorFrameworkFactory.Builder builder);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 |
21 | import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
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.context.annotation.Bean;
28 | import org.springframework.context.annotation.Configuration;
29 |
30 | /**
31 | * Auto {@link Configuration} for adding a Zookeeper health endpoint to actuator if
32 | * required.
33 | *
34 | * @author Tom Gianos
35 | * @since 2.0.1
36 | */
37 | @Configuration(proxyBeanMethods = false)
38 | @ConditionalOnZookeeperEnabled
39 | @ConditionalOnClass(Endpoint.class)
40 | @AutoConfigureAfter({ ZookeeperAutoConfiguration.class })
41 | public class ZookeeperHealthAutoConfiguration {
42 |
43 | /**
44 | * If there is an active curator, if the zookeeper health endpoint is enabled and if a
45 | * health indicator hasn't already been added by a user add one.
46 | * @param curator The curator connection to zookeeper to use
47 | * @return An instance of {@link ZookeeperHealthIndicator} to add to actuator health
48 | * report
49 | */
50 | @Bean
51 | @ConditionalOnMissingBean(ZookeeperHealthIndicator.class)
52 | @ConditionalOnBean(CuratorFramework.class)
53 | @ConditionalOnEnabledHealthIndicator("zookeeper")
54 | public ZookeeperHealthIndicator zookeeperHealthIndicator(CuratorFramework curator) {
55 | return new ZookeeperHealthIndicator(curator);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 | import org.apache.curator.framework.imps.CuratorFrameworkState;
21 |
22 | import org.springframework.boot.actuate.health.AbstractHealthIndicator;
23 | import org.springframework.boot.actuate.health.Health;
24 |
25 | /**
26 | * A {@link org.springframework.boot.actuate.health.HealthIndicator} that checks the
27 | * status of the Zookeeper connection.
28 | *
29 | * @author Spencer Gibb
30 | * @since 1.0.0
31 | */
32 | public class ZookeeperHealthIndicator extends AbstractHealthIndicator {
33 |
34 | private final CuratorFramework curator;
35 |
36 | public ZookeeperHealthIndicator(CuratorFramework curator) {
37 | this.curator = curator;
38 | }
39 |
40 | @Override
41 | protected void doHealthCheck(Health.Builder builder) throws Exception {
42 | try {
43 | CuratorFrameworkState state = this.curator.getState();
44 | if (state != CuratorFrameworkState.STARTED) {
45 | builder.down().withDetail("error", "Client not started");
46 | }
47 | else if (this.curator.checkExists().forPath("/") == null) {
48 | builder.down().withDetail("error", "Root for namespace does not exist");
49 | }
50 | else {
51 | builder.up();
52 | }
53 | builder.withDetail("connectionString",
54 | this.curator.getZookeeperClient().getCurrentConnectionString())
55 | .withDetail("state", state);
56 | }
57 | catch (Exception e) {
58 | builder.down(e);
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json:
--------------------------------------------------------------------------------
1 | {"properties": [
2 | {
3 | "name": "management.health.zookeeper.enabled",
4 | "type": "java.lang.Boolean",
5 | "description": "Enable the health endpoint for zookeeper.",
6 | "defaultValue": true
7 | },
8 | {
9 | "name": "endpoints.zookeeper.enabled",
10 | "type": "java.lang.Boolean",
11 | "description": "Enable the /zookeeper endpoint to inspect the state of zookeeper.",
12 | "defaultValue": true
13 | }
14 | ]}
15 |
16 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/aot.factories:
--------------------------------------------------------------------------------
1 | org.springframework.aot.hint.RuntimeHintsRegistrar=\
2 | org.springframework.cloud.zookeeper.ZookeeperCoreHints
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports:
--------------------------------------------------------------------------------
1 | org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration
2 | org.springframework.cloud.zookeeper.ZookeeperHealthAutoConfiguration
3 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/CuratorFactoryTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2020 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.zookeeper;
18 |
19 | import org.junit.jupiter.api.Test;
20 |
21 | import org.springframework.boot.context.properties.bind.Binder;
22 | import org.springframework.mock.env.MockEnvironment;
23 | import org.springframework.web.util.UriComponentsBuilder;
24 |
25 | import static org.assertj.core.api.Assertions.assertThat;
26 |
27 | public class CuratorFactoryTests {
28 |
29 | @Test
30 | public void testLoadProperties() {
31 | ZookeeperProperties properties = CuratorFactory.loadProperties(
32 | Binder.get(new MockEnvironment()),
33 | UriComponentsBuilder.fromUriString("zookeeper://myhost:8502").build());
34 | assertThat(properties.getConnectString()).isEqualTo("myhost:8502");
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfigurationTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper;
18 |
19 | import org.apache.curator.framework.CuratorFramework;
20 | import org.assertj.core.api.Assertions;
21 | import org.junit.Test;
22 |
23 | import org.springframework.boot.autoconfigure.AutoConfigurations;
24 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
25 | import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
26 | import org.springframework.context.annotation.Bean;
27 |
28 | /**
29 | * Tests for {@link ZookeeperHealthAutoConfiguration}.
30 | *
31 | * @author Tom Gianos
32 | * @since 2.0.1
33 | */
34 | public class ZookeeperHealthAutoConfigurationTests {
35 |
36 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
37 | .withInitializer(new ZookeeperTestingServer.Initializer())
38 | .withConfiguration(AutoConfigurations.of(ZookeeperAutoConfiguration.class,
39 | ZookeeperHealthAutoConfiguration.class))
40 | .withUserConfiguration(ZookeeperAutoConfigurationTests.BaseTestConfig.class);
41 |
42 | @Test
43 | public void testDefaultPropertiesCreateZookeeperHealthIndicator() {
44 | this.contextRunner.run((context) -> Assertions.assertThat(context)
45 | .hasSingleBean(ZookeeperHealthIndicator.class));
46 | }
47 |
48 | @Test
49 | public void testZookeeperHealthIndicatorDisabled() {
50 | this.contextRunner.withPropertyValues("management.health.zookeeper.enabled=false")
51 | .run((context) -> Assertions.assertThat(context)
52 | .doesNotHaveBean(ZookeeperHealthIndicator.class));
53 | }
54 |
55 | @Test
56 | public void testZookeeperHealthIndicatorAlreadyAdded() {
57 | this.contextRunner.withUserConfiguration(HealthIndicatorCustomConfig.class)
58 | .run((context) -> {
59 | Assertions.assertThat(context)
60 | .hasSingleBean(ZookeeperHealthIndicator.class);
61 | Assertions.assertThat(context)
62 | .doesNotHaveBean("zookeeperHealthIndicator");
63 | Assertions.assertThat(context)
64 | .hasBean("customZookeeperHealthIndicator");
65 | });
66 | }
67 |
68 | static class HealthIndicatorCustomConfig {
69 |
70 | @Bean
71 | ZookeeperHealthIndicator customZookeeperHealthIndicator(
72 | CuratorFramework curatorFramework) {
73 | return new ZookeeperHealthIndicator(curatorFramework);
74 | }
75 |
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnLoadBalancerForZookeeperEnabled.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25 |
26 | /**
27 | * Wrapper annotation to enable Spring Cloud LoadBalancer for Zookeeper.
28 | *
29 | * @author Olga Maciaszek-Sharma
30 | * @since 3.0.0
31 | */
32 | @Retention(RetentionPolicy.RUNTIME)
33 | @Target({ElementType.TYPE, ElementType.METHOD})
34 | @ConditionalOnProperty(value = "spring.cloud.zookeeper.loadbalancer.enabled", matchIfMissing = true)
35 | public @interface ConditionalOnLoadBalancerForZookeeperEnabled {
36 | }
37 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnZookeeperDiscoveryEnabled.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25 | import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
26 |
27 | /**
28 | * Wrapper annotation to enable Zookeeper Discovery.
29 | *
30 | * @author Marcin Grzejszczak
31 | * @since 1.1.0
32 | */
33 | @Retention(RetentionPolicy.RUNTIME)
34 | @Target({ ElementType.TYPE, ElementType.METHOD })
35 | @ConditionalOnZookeeperEnabled
36 | @ConditionalOnProperty(value = ConditionalOnZookeeperDiscoveryEnabled.PROPERTY, matchIfMissing = true)
37 | public @interface ConditionalOnZookeeperDiscoveryEnabled {
38 | /**
39 | * Property name.
40 | */
41 | String PROPERTY = "spring.cloud.zookeeper.discovery.enabled";
42 | }
43 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/DependencyPathUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | /**
20 | * Utils for correct dependency path format.
21 | *
22 | * @author Denis Stepanov
23 | * @since 1.0.4
24 | */
25 | public final class DependencyPathUtils {
26 |
27 | private DependencyPathUtils() {
28 | }
29 |
30 | /**
31 | * Sanitizes path by ensuring that path starts with a slash and doesn't have one at
32 | * the end.
33 | * @param path file path to sanitize.
34 | * @return sanitized path.
35 | */
36 | public static String sanitize(String path) {
37 | return withLeadingSlash(withoutSlashAtEnd(path));
38 | }
39 |
40 | private static String withLeadingSlash(String value) {
41 | return value.startsWith("/") ? value : "/" + value;
42 | }
43 |
44 | private static String withoutSlashAtEnd(String value) {
45 | return value.endsWith("/") ? value.substring(0, value.length() - 1) : value;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/LoadBalancerZookeeperAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
22 | import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer;
23 | import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
24 | import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
25 | import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
26 | import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependenciesAutoConfiguration;
27 | import org.springframework.context.annotation.Configuration;
28 |
29 | /**
30 | * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
31 | * Auto-configuration} that sets up Spring Cloud LoadBalancer for Zookeeper.
32 | *
33 | * @author Olga Maciaszek-Sharma
34 | * @since 3.0.0
35 | */
36 | @Configuration(proxyBeanMethods = false)
37 | @EnableConfigurationProperties
38 | @ConditionalOnZookeeperEnabled
39 | @ConditionalOnBean(ReactiveLoadBalancer.Factory.class)
40 | @ConditionalOnLoadBalancerForZookeeperEnabled
41 | @AutoConfigureAfter({LoadBalancerAutoConfiguration.class, ZookeeperDependenciesAutoConfiguration.class})
42 | @LoadBalancerClients(defaultConfiguration = ZookeeperLoadBalancerConfiguration.class)
43 | public class LoadBalancerZookeeperAutoConfiguration {
44 | }
45 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClientConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import org.apache.curator.x.discovery.ServiceDiscovery;
20 |
21 | import org.springframework.beans.factory.annotation.Autowired;
22 | import org.springframework.boot.autoconfigure.AutoConfigureBefore;
23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
24 | import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
25 | import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
26 | import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
27 | import org.springframework.context.annotation.Bean;
28 | import org.springframework.context.annotation.Configuration;
29 |
30 | /**
31 | * {@link org.springframework.cloud.client.discovery.DiscoveryClient} configuration for
32 | * Zookeeper.
33 | *
34 | * @author Spencer Gibb
35 | * @author Tim Ysewyn
36 | * @since 1.0.0
37 | */
38 | @Configuration(proxyBeanMethods = false)
39 | @ConditionalOnDiscoveryEnabled
40 | @ConditionalOnBlockingDiscoveryEnabled
41 | @ConditionalOnZookeeperDiscoveryEnabled
42 | @AutoConfigureBefore({ ZookeeperDiscoveryAutoConfiguration.class })
43 | public class ZookeeperDiscoveryClientConfiguration {
44 |
45 | @Autowired(required = false)
46 | private ZookeeperDependencies zookeeperDependencies;
47 |
48 | @Bean
49 | @ConditionalOnMissingBean
50 | // currently means auto-registration is false. That will change when
51 | // ZookeeperServiceDiscovery is gone
52 | public ZookeeperDiscoveryClient zookeeperDiscoveryClient(
53 | ServiceDiscovery serviceDiscovery,
54 | ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
55 | return new ZookeeperDiscoveryClient(serviceDiscovery, zookeeperDependencies,
56 | zookeeperDiscoveryProperties);
57 | }
58 |
59 | @Bean
60 | public Marker zookeeperDiscoveryClientMarker() {
61 | return new Marker();
62 | }
63 |
64 | class Marker {
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryHealthIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import org.apache.commons.logging.Log;
20 | import org.apache.commons.logging.LogFactory;
21 | import org.apache.curator.framework.CuratorFramework;
22 | import org.apache.curator.x.discovery.ServiceDiscovery;
23 | import org.apache.curator.x.discovery.ServiceInstance;
24 |
25 | import org.springframework.boot.actuate.health.Health;
26 | import org.springframework.cloud.client.discovery.health.DiscoveryHealthIndicator;
27 | import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
28 |
29 | /**
30 | * {@link org.springframework.boot.actuate.health.HealthIndicator} that presents the
31 | * status of all instances registered in Zookeeper.
32 | *
33 | * @author Spencer Gibb
34 | * @since 1.0.0
35 | */
36 | public class ZookeeperDiscoveryHealthIndicator implements DiscoveryHealthIndicator {
37 |
38 | private static final Log log = LogFactory
39 | .getLog(ZookeeperDiscoveryHealthIndicator.class);
40 |
41 | private CuratorFramework curatorFramework;
42 |
43 | private ServiceDiscovery serviceDiscovery;
44 |
45 | private final ZookeeperDependencies zookeeperDependencies;
46 |
47 | private final ZookeeperDiscoveryProperties zookeeperDiscoveryProperties;
48 |
49 | public ZookeeperDiscoveryHealthIndicator(CuratorFramework curatorFramework,
50 | ServiceDiscovery serviceDiscovery,
51 | ZookeeperDependencies zookeeperDependencies,
52 | ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
53 | this.curatorFramework = curatorFramework;
54 | this.serviceDiscovery = serviceDiscovery;
55 | this.zookeeperDependencies = zookeeperDependencies;
56 | this.zookeeperDiscoveryProperties = zookeeperDiscoveryProperties;
57 | }
58 |
59 | @Override
60 | public String getName() {
61 | return "zookeeper";
62 | }
63 |
64 | @Override
65 | public Health health() {
66 | Health.Builder builder = Health.unknown();
67 | try {
68 | Iterable> allInstances = new ZookeeperServiceInstances(
69 | this.curatorFramework, this.serviceDiscovery,
70 | this.zookeeperDependencies, this.zookeeperDiscoveryProperties);
71 | builder.up().withDetail("services", allInstances);
72 | }
73 | catch (Exception e) {
74 | log.error("Error", e);
75 | builder.down(e);
76 | }
77 |
78 | return builder.build();
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperInstance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | /**
23 | * Represents the default payload of a registered service in Zookeeper.
24 | *
25 | * @author Spencer Gibb
26 | * @since 1.0.0
27 | */
28 | public class ZookeeperInstance {
29 |
30 | private String id;
31 |
32 | private String name;
33 |
34 | private Map metadata = new HashMap<>();
35 |
36 | @SuppressWarnings("unused")
37 | private ZookeeperInstance() {
38 | }
39 |
40 | public ZookeeperInstance(String id, String name, Map metadata) {
41 | this.id = id;
42 | this.name = name;
43 | this.metadata = metadata;
44 | }
45 |
46 | public String getId() {
47 | return this.id;
48 | }
49 |
50 | public String getName() {
51 | return this.name;
52 | }
53 |
54 | public void setId(String id) {
55 | this.id = id;
56 | }
57 |
58 | public void setName(String name) {
59 | this.name = name;
60 | }
61 |
62 | public Map getMetadata() {
63 | return this.metadata;
64 | }
65 |
66 | public void setMetadata(Map metadata) {
67 | this.metadata = metadata;
68 | }
69 |
70 | @Override
71 | public String toString() {
72 | return "ZookeeperInstance{" + "id='" + this.id + '\'' + ", name='" + this.name
73 | + '\'' + ", metadata=" + this.metadata + '}';
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperLoadBalancerConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import org.springframework.beans.factory.ObjectProvider;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22 | import org.springframework.cloud.client.discovery.DiscoveryClient;
23 | import org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheManager;
24 | import org.springframework.cloud.loadbalancer.core.CachingServiceInstanceListSupplier;
25 | import org.springframework.cloud.loadbalancer.core.DiscoveryClientServiceInstanceListSupplier;
26 | import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
27 | import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
28 | import org.springframework.context.ApplicationContext;
29 | import org.springframework.context.annotation.Bean;
30 | import org.springframework.context.annotation.Configuration;
31 | import org.springframework.core.env.Environment;
32 |
33 | /**
34 | * Zookeeper-specific {@link ServiceInstanceListSupplier} that provides a delegate that
35 | * filters available instances based on status retrieved from Zookeeper.
36 | *
37 | * @author Olga Maciaszek-Sharma
38 | * @since 3.0.0
39 | */
40 | @Configuration(proxyBeanMethods = false)
41 | public class ZookeeperLoadBalancerConfiguration {
42 |
43 | @Bean
44 | @ConditionalOnBean(DiscoveryClient.class)
45 | @ConditionalOnMissingBean
46 | public ServiceInstanceListSupplier zookeeperDiscoveryClientServiceInstanceListSupplier(
47 | DiscoveryClient discoveryClient, Environment env,
48 | ApplicationContext context,
49 | ZookeeperDependencies zookeeperDependencies) {
50 | DiscoveryClientServiceInstanceListSupplier firstDelegate = new DiscoveryClientServiceInstanceListSupplier(
51 | discoveryClient, env);
52 | ZookeeperServiceInstanceListSupplier secondDelegate = new ZookeeperServiceInstanceListSupplier(firstDelegate,
53 | zookeeperDependencies);
54 | ObjectProvider cacheManagerProvider = context
55 | .getBeanProvider(LoadBalancerCacheManager.class);
56 | if (cacheManagerProvider.getIfAvailable() != null) {
57 | return new CachingServiceInstanceListSupplier(secondDelegate,
58 | cacheManagerProvider.getIfAvailable());
59 | }
60 | return secondDelegate;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery;
18 |
19 | import java.net.URI;
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | import org.springframework.cloud.client.ServiceInstance;
24 |
25 | /**
26 | * A specific {@link ServiceInstance} describing a zookeeper service instance.
27 | *
28 | * @author Reda Housni-Alaoui
29 | * @author Tim Ysewyn
30 | * @since 1.1.0
31 | */
32 | public class ZookeeperServiceInstance implements ServiceInstance {
33 |
34 | private final String serviceId;
35 |
36 | private final String host;
37 |
38 | private final int port;
39 |
40 | private final boolean secure;
41 |
42 | private final URI uri;
43 |
44 | private final Map metadata;
45 |
46 | private final org.apache.curator.x.discovery.ServiceInstance serviceInstance;
47 |
48 | /**
49 | * @param serviceId The service id to be used
50 | * @param serviceInstance The zookeeper service instance described by this service
51 | * instance
52 | */
53 | public ZookeeperServiceInstance(String serviceId,
54 | org.apache.curator.x.discovery.ServiceInstance serviceInstance) {
55 | this.serviceId = serviceId;
56 | this.serviceInstance = serviceInstance;
57 | this.host = this.serviceInstance.getAddress();
58 | this.secure = serviceInstance.getSslPort() != null;
59 | Integer port = serviceInstance.getPort();
60 | if (this.secure) {
61 | port = serviceInstance.getSslPort();
62 | }
63 | this.port = port;
64 | this.uri = URI.create(serviceInstance.buildUriSpec());
65 | if (serviceInstance.getPayload() != null) {
66 | this.metadata = serviceInstance.getPayload().getMetadata();
67 | }
68 | else {
69 | this.metadata = new HashMap<>();
70 | }
71 | }
72 |
73 | @Override
74 | public String getInstanceId() {
75 | return this.serviceInstance.getId();
76 | }
77 |
78 | @Override
79 | public String getServiceId() {
80 | return this.serviceId;
81 | }
82 |
83 | @Override
84 | public String getHost() {
85 | return this.host;
86 | }
87 |
88 | @Override
89 | public int getPort() {
90 | return this.port;
91 | }
92 |
93 | @Override
94 | public boolean isSecure() {
95 | return this.secure;
96 | }
97 |
98 | @Override
99 | public URI getUri() {
100 | return this.uri;
101 | }
102 |
103 | @Override
104 | public Map getMetadata() {
105 | return this.metadata;
106 | }
107 |
108 | public org.apache.curator.x.discovery.ServiceInstance getServiceInstance() {
109 | return this.serviceInstance;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013-2016 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.zookeeper.discovery.configclient;
18 |
19 | import jakarta.annotation.PostConstruct;
20 | import org.apache.curator.framework.CuratorFramework;
21 |
22 | import org.springframework.beans.factory.annotation.Autowired;
23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
25 | import org.springframework.cloud.config.server.config.ConfigServerProperties;
26 | import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties;
27 | import org.springframework.context.annotation.Configuration;
28 | import org.springframework.util.StringUtils;
29 |
30 | /**
31 | * Extra configuration for config server if it happens to be registered with Zookeeper.
32 | *
33 | * @author Dave Syer
34 | */
35 | @Configuration(proxyBeanMethods = false)
36 | @EnableConfigurationProperties
37 | @ConditionalOnClass({ ZookeeperDiscoveryProperties.class, CuratorFramework.class,
38 | ConfigServerProperties.class })
39 | public class ZookeeperConfigServerAutoConfiguration {
40 |
41 | @Autowired(required = false)
42 | private ZookeeperDiscoveryProperties properties;
43 |
44 | @Autowired(required = false)
45 | private ConfigServerProperties server;
46 |
47 | @PostConstruct
48 | public void init() {
49 | if (this.properties == null || this.server == null) {
50 | return;
51 | }
52 | String prefix = this.server.getPrefix();
53 | if (StringUtils.hasText(prefix)) {
54 | this.properties.getMetadata().put("configPath", prefix);
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery.configclient;
18 |
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
21 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
22 | import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties;
23 | import org.springframework.cloud.commons.util.InetUtils;
24 | import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
25 | import org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration;
26 | import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration;
27 | import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClientConfiguration;
28 | import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties;
29 | import org.springframework.cloud.zookeeper.support.CuratorServiceDiscoveryAutoConfiguration;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.Configuration;
32 | import org.springframework.context.annotation.Import;
33 | import org.springframework.core.annotation.Order;
34 |
35 | /**
36 | * Helper for config client that wants to lookup the config server via discovery.
37 | *
38 | * @author Spencer Gibb
39 | * @author Tim Ysewyn
40 | */
41 | @ConditionalOnClass(ConfigServicePropertySourceLocator.class)
42 | @ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled", matchIfMissing = false)
43 | @Configuration(proxyBeanMethods = false)
44 | @Import({ ZookeeperAutoConfiguration.class, ZookeeperDiscoveryClientConfiguration.class,
45 | CuratorServiceDiscoveryAutoConfiguration.class,
46 | ZookeeperDiscoveryAutoConfiguration.class })
47 | @EnableConfigurationProperties({DiscoveryClientHealthIndicatorProperties.class})
48 | @Order(0)
49 | public class ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration {
50 |
51 | @Bean
52 | public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(
53 | InetUtils inetUtils) {
54 | ZookeeperDiscoveryProperties properties = new ZookeeperDiscoveryProperties(
55 | inetUtils);
56 | // for bootstrap, registration is not needed, just discovery client
57 | properties.setRegister(false);
58 | return properties;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesNotPassed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery.dependency;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.context.annotation.Conditional;
25 |
26 | /**
27 | * Annotation to turn off a feature if Zookeeper dependencies have NOT been passed.
28 | *
29 | * @author Marcin Grzejszczak
30 | * @since 1.0.0
31 | */
32 | @Target({ ElementType.TYPE, ElementType.METHOD })
33 | @Retention(RetentionPolicy.RUNTIME)
34 | @Conditional(DependenciesNotPassedCondition.class)
35 | public @interface ConditionalOnDependenciesNotPassed {
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesPassed.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery.dependency;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.context.annotation.Conditional;
25 |
26 | /**
27 | * Annotation to turn on a feature if Zookeeper dependencies have been passed. Also checks
28 | * if switch for zookeeper dependencies is turned on.
29 | *
30 | * @author Marcin Grzejszczak
31 | * @since 1.0.0
32 | */
33 | @Target({ ElementType.TYPE, ElementType.METHOD })
34 | @Retention(RetentionPolicy.RUNTIME)
35 | @Conditional(DependenciesPassedCondition.class)
36 | public @interface ConditionalOnDependenciesPassed {
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesNotPassedCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery.dependency;
18 |
19 | import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
20 | import org.springframework.context.annotation.ConditionContext;
21 | import org.springframework.core.type.AnnotatedTypeMetadata;
22 |
23 | /**
24 | * Inverse of the {@link ConditionalOnDependenciesPassed} condition.
25 | *
26 | * @author Marcin Grzejszczak
27 | * @since 1.0.0
28 | */
29 | public class DependenciesNotPassedCondition extends DependenciesPassedCondition {
30 |
31 | @Override
32 | public ConditionOutcome getMatchOutcome(ConditionContext context,
33 | AnnotatedTypeMetadata metadata) {
34 | ConditionOutcome propertiesSet = super.getMatchOutcome(context, metadata);
35 | return ConditionOutcome.inverse(propertiesSet);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesPassedCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2019 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.zookeeper.discovery.dependency;
18 |
19 | import java.util.Collections;
20 | import java.util.Map;
21 |
22 | import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
23 | import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
24 | import org.springframework.boot.context.properties.bind.Bindable;
25 | import org.springframework.boot.context.properties.bind.Binder;
26 | import org.springframework.context.annotation.ConditionContext;
27 | import org.springframework.core.type.AnnotatedTypeMetadata;
28 |
29 | /**
30 | * Condition that verifies if the Dependencies have been passed in an appropriate place in
31 | * the application properties.
32 | *
33 | * @author Marcin Grzejszczak
34 | * @since 1.0.0
35 | */
36 | public class DependenciesPassedCondition extends SpringBootCondition {
37 |
38 | private static final Bindable