Initial commit
This commit is contained in:
134
.flattened-pom.xml
Normal file
134
.flattened-pom.xml
Normal file
@@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath></relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Zookeeper</name>
|
||||
<description>Spring Cloud Zookeeper</description>
|
||||
<url>https://spring.io/spring-cloud/spring-cloud-zookeeper</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper</url>
|
||||
</scm>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>spring</id>
|
||||
<repositories>
|
||||
<repository>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
45
.github/CONTRIBUTING.md
vendored
45
.github/CONTRIBUTING.md
vendored
@@ -1,45 +0,0 @@
|
||||
|
||||
# Contributing
|
||||
|
||||
Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||||
and follows a very standard Github development process, using Github
|
||||
tracker for issues and merging pull requests into master. If you want
|
||||
to contribute even something trivial please do not hesitate, but
|
||||
follow the guidelines below.
|
||||
|
||||
## Sign the Contributor License Agreement
|
||||
Before we accept a non-trivial patch or pull request we will need you to sign the
|
||||
[Contributor License Agreement](https://cla.pivotal.io/sign/spring).
|
||||
Signing the contributor's agreement does not grant anyone commit rights to the main
|
||||
repository, but it does mean that we can accept your contributions, and you will get an
|
||||
author credit if we do. Active contributors might be asked to join the core team, and
|
||||
given the ability to merge pull requests.
|
||||
|
||||
## Code of Conduct
|
||||
This project adheres to the Contributor Covenant [code of
|
||||
conduct](https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report
|
||||
unacceptable behavior to spring-code-of-conduct@pivotal.io.
|
||||
|
||||
## Code Conventions and Housekeeping
|
||||
None of these is essential for a pull request, but they will all help. They can also be
|
||||
added after the original pull request but before a merge.
|
||||
|
||||
* Use the Spring Framework code format conventions. If you use Eclipse
|
||||
you can import formatter settings using the
|
||||
`eclipse-code-formatter.xml` file from the
|
||||
[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
|
||||
[Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546) to import the same file.
|
||||
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
|
||||
`@author` tag identifying you, and preferably at least a paragraph on what the class is
|
||||
for.
|
||||
* Add the ASF license header comment to all new `.java` files (copy from existing files
|
||||
in the project)
|
||||
* Add yourself as an `@author` to the .java files that you modify substantially (more
|
||||
than cosmetic changes).
|
||||
* Add some Javadocs and, if you change the namespace, some XSD doc elements.
|
||||
* A few unit tests would help a lot as well -- someone has to do it.
|
||||
* If no-one else is using your branch, please rebase it against the current master (or
|
||||
other target branch in the main project).
|
||||
* When writing a commit message please follow [these conventions](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html),
|
||||
if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
|
||||
message (where XXXX is the issue number).
|
||||
20
.github/ISSUE_TEMPLATE.md
vendored
20
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,20 +0,0 @@
|
||||
<!--
|
||||
Thanks for raising a Spring Cloud issue. What sort of issue are you raising?
|
||||
|
||||
Question
|
||||
|
||||
Please ask questions about how to use something, or to understand why something isn't
|
||||
working as you expect it to, on Stack Overflow using the spring-cloud tag.
|
||||
|
||||
Bug report
|
||||
|
||||
Please provide details of the problem, including the version of Spring Cloud that you
|
||||
are using. If possible, please provide a test case or sample application that reproduces
|
||||
the problem. This makes it much easier for us to diagnose the problem and to verify that
|
||||
we have fixed it.
|
||||
|
||||
Enhancement
|
||||
|
||||
Please start by describing the problem that you are trying to solve. There may already
|
||||
be a solution, or there may be a way to solve it that you hadn't considered.
|
||||
-->
|
||||
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,17 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
Please provide details of the problem, including the version of Spring Cloud that you
|
||||
are using.
|
||||
|
||||
**Sample**
|
||||
If possible, please provide a test case or sample application that reproduces
|
||||
the problem. This makes it much easier for us to diagnose the problem and to verify that
|
||||
we have fixed it.
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
53
.github/workflows/deploy-docs.yml
vendored
Normal file
53
.github/workflows/deploy-docs.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
name: Deploy Docs
|
||||
run-name: ${{ format('{0} ({1})', github.workflow, github.event.inputs.build-refname || 'all') }}
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
build-refname:
|
||||
description: Enter git refname to build (e.g., 5.7.x).
|
||||
required: false
|
||||
push:
|
||||
branches: docs-build
|
||||
env:
|
||||
GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
build:
|
||||
if: github.repository_owner == 'spring-cloud'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 5
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
- name: Set up refname build
|
||||
if: github.event.inputs.build-refname
|
||||
run: |
|
||||
git fetch --depth 1 https://github.com/$GITHUB_REPOSITORY ${{ github.event.inputs.build-refname }}
|
||||
export BUILD_REFNAME=${{ github.event.inputs.build-refname }}
|
||||
echo "BUILD_REFNAME=$BUILD_REFNAME" >> $GITHUB_ENV
|
||||
export BUILD_VERSION=$(git cat-file --textconv FETCH_HEAD:pom.xml | python3 -c "import xml.etree.ElementTree as xml; from sys import stdin; print(xml.parse(stdin).getroot().find('{http://maven.apache.org/POM/4.0.0}version').text)")
|
||||
echo BUILD_VERSION=$BUILD_VERSION >> $GITHUB_ENV
|
||||
- name: Run Antora
|
||||
run: |
|
||||
./mvnw --no-transfer-progress -B antora
|
||||
- name: Publish Docs
|
||||
uses: spring-io/spring-doc-actions/rsync-antora-reference@v0.0.11
|
||||
with:
|
||||
docs-username: ${{ secrets.DOCS_USERNAME }}
|
||||
docs-host: ${{ secrets.DOCS_HOST }}
|
||||
docs-ssh-key: ${{ secrets.DOCS_SSH_KEY }}
|
||||
docs-ssh-host-key: ${{ secrets.DOCS_SSH_HOST_KEY }}
|
||||
site-path: target/antora/site
|
||||
- name: Bust Cloudflare Cache
|
||||
uses: spring-io/spring-doc-actions/bust-cloudflare-antora-cache@v0.0.11
|
||||
with:
|
||||
context-root: spring-cloud-zookeeper
|
||||
cloudflare-zone-id: ${{ secrets.CLOUDFLARE_ZONE_ID }}
|
||||
cloudflare-cache-token: ${{ secrets.CLOUDFLARE_CACHE_TOKEN }}
|
||||
37
.github/workflows/maven.yml
vendored
37
.github/workflows/maven.yml
vendored
@@ -1,37 +0,0 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, 3.1.x ]
|
||||
pull_request:
|
||||
branches: [ main, 3.1.x ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
- name: Cache local Maven repository
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
- name: Build with Maven
|
||||
run: ./mvnw clean install -B -U -Pspring -Dmaven.test.redirectTestOutputToFile=true
|
||||
- name: Publish Test Report
|
||||
uses: mikepenz/action-junit-report@v2
|
||||
if: always() # always run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/surefire-reports/TEST-*.xml'
|
||||
37
.gitignore
vendored
37
.gitignore
vendored
@@ -1,19 +1,22 @@
|
||||
*~
|
||||
#*
|
||||
*#
|
||||
.#*
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
.factorypath
|
||||
.springBeans
|
||||
target/
|
||||
_site/
|
||||
.idea
|
||||
*.iml
|
||||
*.swp
|
||||
*.log
|
||||
.checkstyle
|
||||
.settings/
|
||||
.project
|
||||
.classpath
|
||||
*.orig
|
||||
.springBeans
|
||||
.factorypath
|
||||
.sts4-cache
|
||||
.ant-targets-build.xml
|
||||
src/ant/.ant-targets-upload-dist.xml
|
||||
*.sonar4clipse*
|
||||
.DS_Store
|
||||
.vscode/
|
||||
.flattened-pom.xml
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
/.idea/
|
||||
*.graphml
|
||||
node
|
||||
node_modules
|
||||
build
|
||||
package.json
|
||||
package-lock.json
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
17
|
||||
@@ -1 +0,0 @@
|
||||
-P spring
|
||||
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
||||
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Binary file not shown.
20
.mvn/wrapper/maven-wrapper.properties
vendored
20
.mvn/wrapper/maven-wrapper.properties
vendored
@@ -1,18 +1,2 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# Enable auto-env through the sdkman_auto_env config
|
||||
# Add key=value pairs of SDKs to use below
|
||||
java=17.0.1-tem
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<servers>
|
||||
<server>
|
||||
<id>repo.spring.io</id>
|
||||
<username>${env.CI_DEPLOY_USERNAME}</username>
|
||||
<password>${env.CI_DEPLOY_PASSWORD}</password>
|
||||
</server>
|
||||
</servers>
|
||||
<profiles>
|
||||
<profile>
|
||||
<!--
|
||||
N.B. this profile is only here to support users and IDEs that do not use Maven 3.3.
|
||||
It isn't needed on the command line if you use the wrapper script (mvnw) or if you use
|
||||
a native Maven with the right version. Eclipse users should points their Maven tooling to
|
||||
this settings file, or copy the profile into their ~/.m2/settings.xml.
|
||||
-->
|
||||
<id>spring</id>
|
||||
<activation><activeByDefault>true</activeByDefault></activation>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
</settings>
|
||||
202
LICENSE.txt
202
LICENSE.txt
@@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
https://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
630
README.adoc
630
README.adoc
@@ -1,629 +1,23 @@
|
||||
////
|
||||
DO NOT EDIT THIS FILE. IT WAS GENERATED.
|
||||
Manual changes to this file will be lost when it is generated again.
|
||||
Edit the files in the src/main/asciidoc/ directory instead.
|
||||
////
|
||||
= Spring Cloud Zookeeper Docs Build
|
||||
|
||||
You're currently viewing the Antora playbook branch.
|
||||
The playbook branch hosts the docs build that is used to build and publish the production docs site.
|
||||
|
||||
image::https://travis-ci.org/spring-cloud/spring-cloud-zookeeper.svg?branch=master[Build Status, link=https://travis-ci.org/spring-cloud/spring-cloud-zookeeper]
|
||||
The Spring Cloud Zookeeper reference docs are built using https://antora.org[Antora].
|
||||
This README covers how to build the docs in a software branch as well as how to build the production docs site locally.
|
||||
|
||||
== Building the Site
|
||||
|
||||
You can build the entire site by invoking the following on the docs-build branch and then viewing the site at `target/site/index.html`
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Zookeeper
|
||||
|
||||
This project provides Zookeeper integrations for Spring Boot applications through
|
||||
autoconfiguration and binding to the Spring Environment and other Spring programming model
|
||||
idioms. With a few annotations, you can quickly enable and configure the common patterns
|
||||
inside your application and build large distributed systems with Zookeeper based
|
||||
components. The provided patterns include Service Discovery and Configuration. The project
|
||||
also provides client-side load-balancing via integration with Spring Cloud LoadBalancer.
|
||||
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:toc: left
|
||||
:toclevels: 4
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Zookeeper
|
||||
|
||||
== Quick Start
|
||||
|
||||
This quick start walks through using Spring Cloud Zookeeper for Service Discovery and Distributed Configuration.
|
||||
|
||||
First, run Zookeeper on your machine. Then you can access it and use it as a Service Registry and Configuration source with Spring Cloud Zookeeper.
|
||||
|
||||
=== Discovery Client Usage
|
||||
|
||||
To use these features in an application, you can build it as a Spring Boot application that depends on `spring-cloud-zookeeper-core` and `spring-cloud-zookeeper-discovery`.
|
||||
The most convenient way to add the dependency is with a Spring Boot starter: `org.springframework.cloud:spring-cloud-starter-zookeeper-discovery`.
|
||||
We recommend using dependency management and `spring-boot-starter-parent`.
|
||||
The following example shows a typical Maven configuration:
|
||||
|
||||
[source,xml,indent=0]
|
||||
.pom.xml
|
||||
[source,bash]
|
||||
----
|
||||
<project>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>{spring-boot-version}</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
./mvnw antora
|
||||
----
|
||||
|
||||
The following example shows a typical Gradle setup:
|
||||
== Building a Specific Branch
|
||||
|
||||
[source,groovy,indent=0]
|
||||
.build.gradle
|
||||
[source,bash]
|
||||
----
|
||||
plugins {
|
||||
id 'org.springframework.boot' version ${spring-boot-version}
|
||||
id 'io.spring.dependency-management' version ${spring-dependency-management-version}
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||
}
|
||||
}
|
||||
./mvnw antora
|
||||
----
|
||||
|
||||
WARNING: Depending on the version you are using, you might need to adjust Apache Zookeeper version used in your project.
|
||||
You can read more about it in the <<spring-cloud-zookeeper-install,Install Zookeeper section>>.
|
||||
|
||||
Now you can create a standard Spring Boot application, such as the following HTTP server:
|
||||
|
||||
----
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
When this HTTP server runs, it connects to Zookeeper, which runs on the default local port (2181).
|
||||
To modify the startup behavior, you can change the location of Zookeeper by using `application.properties`, as shown in the following example:
|
||||
|
||||
----
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
connect-string: localhost:2181
|
||||
----
|
||||
|
||||
You can now use `DiscoveryClient`, `@LoadBalanced RestTemplate`, or `@LoadBalanced WebClient.Builder` to retrieve services and instances data from Zookeeper, as shown in the following example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
public String serviceUrl() {
|
||||
List<ServiceInstance> list = discoveryClient.getInstances("STORES");
|
||||
if (list != null && list.size() > 0 ) {
|
||||
return list.get(0).getUri().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
----
|
||||
|
||||
=== Distributed Configuration Usage
|
||||
|
||||
To use these features in an application, you can build it as a Spring Boot application that depends on `spring-cloud-zookeeper-core` and `spring-cloud-zookeeper-config`.
|
||||
The most convenient way to add the dependency is with a Spring Boot starter: `org.springframework.cloud:spring-cloud-starter-zookeeper-config`.
|
||||
We recommend using dependency management and `spring-boot-starter-parent`.
|
||||
The following example shows a typical Maven configuration:
|
||||
|
||||
[source,xml,indent=0]
|
||||
.pom.xml
|
||||
----
|
||||
<project>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>{spring-boot-version}</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
----
|
||||
|
||||
The following example shows a typical Gradle setup:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
.build.gradle
|
||||
----
|
||||
plugins {
|
||||
id 'org.springframework.boot' version ${spring-boot-version}
|
||||
id 'io.spring.dependency-management' version ${spring-dependency-management-version}
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-config'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
WARNING: Depending on the version you are using, you might need to adjust Apache Zookeeper version used in your project.
|
||||
You can read more about it in the <<spring-cloud-zookeeper-install,Install Zookeeper section>>.
|
||||
|
||||
Now you can create a standard Spring Boot application, such as the following HTTP server:
|
||||
|
||||
----
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
The application retrieves configuration data from Zookeeper.
|
||||
|
||||
WARNING: If you use Spring Cloud Zookeeper Config, you need to set the `spring.config.import` property in order to bind to Zookeeper.
|
||||
You can read more about it in the <<config-data-import,Spring Boot Config Data Import section>>.
|
||||
|
||||
== Zookeeper overview
|
||||
|
||||
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
|
||||
See the
|
||||
https://zookeeper.apache.org[Zookeeper site] for more information.
|
||||
Spring Cloud Zookeeper also builds on the https://curator.apache.org[Apache Curator] project, which started life at Netflix.
|
||||
|
||||
== Spring Cloud Zookeeper Features
|
||||
|
||||
Spring Cloud Zookeeper includes the following features:
|
||||
|
||||
* Spring Cloud `DiscoveryClient` implementation (supports Spring Cloud LoadBalancer)
|
||||
* Zookeeper-based `PropertySource` loaded during the 'bootstrap' phase
|
||||
|
||||
== Running the Sample
|
||||
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_Download[Install
|
||||
zookeeper] (On a mac with homebrew, use `brew install zookeeper`).
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_InstallingSingleMode[Start
|
||||
zookeeper].
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_ConnectingToZooKeeper[Verify
|
||||
zookeeper is running].
|
||||
. Run `mvn --settings .settings.xml package`.
|
||||
Doing so brings in the required Spring Cloud Maven repositories and Build.
|
||||
. Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar`.
|
||||
. Visit http://localhost:8080 to verify that `{"serviceId":"testZookeeperApp","host":"<yourhost>","port":8080}` works.
|
||||
. Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
. Visit http://localhost:8080 again to verify that `{"serviceId":"testZookeeperApp","host":"<yourhost>","port":8081}` eventually shows up in the results in a round-robin fashion. (It may take a minute or so.)
|
||||
|
||||
== Building
|
||||
|
||||
:jdkversion: 17
|
||||
|
||||
=== Basic Compile and Test
|
||||
|
||||
To build the source you will need to install JDK {jdkversion}.
|
||||
|
||||
Spring Cloud uses Maven for most build-related activities, and you
|
||||
should be able to get off the ground quite quickly by cloning the
|
||||
project you are interested in and typing
|
||||
|
||||
----
|
||||
$ ./mvnw install
|
||||
----
|
||||
|
||||
NOTE: You can also install Maven (>=3.3.3) yourself and run the `mvn` command
|
||||
in place of `./mvnw` in the examples below. If you do that you also
|
||||
might need to add `-P spring` if your local Maven settings do not
|
||||
contain repository declarations for spring pre-release artifacts.
|
||||
|
||||
NOTE: Be aware that you might need to increase the amount of memory
|
||||
available to Maven by setting a `MAVEN_OPTS` environment variable with
|
||||
a value like `-Xmx512m -XX:MaxPermSize=128m`. We try to cover this in
|
||||
the `.mvn` configuration, so if you find you have to do it to make a
|
||||
build succeed, please raise a ticket to get the settings added to
|
||||
source control.
|
||||
|
||||
The projects that require middleware (i.e. Redis) for testing generally
|
||||
require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running.
|
||||
|
||||
|
||||
=== Documentation
|
||||
|
||||
The spring-cloud-build module has a "docs" profile, and if you switch
|
||||
that on it will try to build asciidoc sources from
|
||||
`src/main/asciidoc`. As part of that process it will look for a
|
||||
`README.adoc` and process it by loading all the includes, but not
|
||||
parsing or rendering it, just copying it to `${main.basedir}`
|
||||
(defaults to `${basedir}`, i.e. the root of the project). If there are
|
||||
any changes in the README it will then show up after a Maven build as
|
||||
a modified file in the correct place. Just commit it and push the change.
|
||||
|
||||
=== Working with the code
|
||||
If you don't have an IDE preference we would recommend that you use
|
||||
https://www.springsource.com/developer/sts[Spring Tools Suite] or
|
||||
https://eclipse.org[Eclipse] when working with the code. We use the
|
||||
https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools
|
||||
should also work without issue as long as they use Maven 3.3.3 or better.
|
||||
|
||||
==== Activate the Spring Maven profile
|
||||
Spring Cloud projects require the 'spring' Maven profile to be activated to resolve
|
||||
the spring milestone and snapshot repositories. Use your preferred IDE to set this
|
||||
profile to be active, or you may experience build errors.
|
||||
|
||||
==== Importing into eclipse with m2eclipse
|
||||
We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with
|
||||
eclipse. If you don't already have m2eclipse installed it is available from the "eclipse
|
||||
marketplace".
|
||||
|
||||
NOTE: Older versions of m2e do not support Maven 3.3, so once the
|
||||
projects are imported into Eclipse you will also need to tell
|
||||
m2eclipse to use the right profile for the projects. If you
|
||||
see many different errors related to the POMs in the projects, check
|
||||
that you have an up to date installation. If you can't upgrade m2e,
|
||||
add the "spring" profile to your `settings.xml`. Alternatively you can
|
||||
copy the repository settings from the "spring" profile of the parent
|
||||
pom into your `settings.xml`.
|
||||
|
||||
==== Importing into eclipse without m2eclipse
|
||||
If you prefer not to use m2eclipse you can generate eclipse project metadata using the
|
||||
following command:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
$ ./mvnw eclipse:eclipse
|
||||
----
|
||||
|
||||
The generated eclipse projects can be imported by selecting `import existing projects`
|
||||
from the `file` menu.
|
||||
|
||||
|
||||
== Contributing
|
||||
|
||||
:spring-cloud-build-branch: master
|
||||
|
||||
Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||||
and follows a very standard Github development process, using Github
|
||||
tracker for issues and merging pull requests into master. If you want
|
||||
to contribute even something trivial please do not hesitate, but
|
||||
follow the guidelines below.
|
||||
|
||||
=== Sign the Contributor License Agreement
|
||||
Before we accept a non-trivial patch or pull request we will need you to sign the
|
||||
https://cla.pivotal.io/sign/spring[Contributor License Agreement].
|
||||
Signing the contributor's agreement does not grant anyone commit rights to the main
|
||||
repository, but it does mean that we can accept your contributions, and you will get an
|
||||
author credit if we do. Active contributors might be asked to join the core team, and
|
||||
given the ability to merge pull requests.
|
||||
|
||||
=== Code of Conduct
|
||||
This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of
|
||||
conduct]. By participating, you are expected to uphold this code. Please report
|
||||
unacceptable behavior to spring-code-of-conduct@pivotal.io.
|
||||
|
||||
=== Code Conventions and Housekeeping
|
||||
None of these is essential for a pull request, but they will all help. They can also be
|
||||
added after the original pull request but before a merge.
|
||||
|
||||
* Use the Spring Framework code format conventions. If you use Eclipse
|
||||
you can import formatter settings using the
|
||||
`eclipse-code-formatter.xml` file from the
|
||||
https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring
|
||||
Cloud Build] project. If using IntelliJ, you can use the
|
||||
https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter
|
||||
Plugin] to import the same file.
|
||||
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
|
||||
`@author` tag identifying you, and preferably at least a paragraph on what the class is
|
||||
for.
|
||||
* Add the ASF license header comment to all new `.java` files (copy from existing files
|
||||
in the project)
|
||||
* Add yourself as an `@author` to the .java files that you modify substantially (more
|
||||
than cosmetic changes).
|
||||
* Add some Javadocs and, if you change the namespace, some XSD doc elements.
|
||||
* A few unit tests would help a lot as well -- someone has to do it.
|
||||
* If no-one else is using your branch, please rebase it against the current master (or
|
||||
other target branch in the main project).
|
||||
* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
|
||||
if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
|
||||
message (where XXXX is the issue number).
|
||||
|
||||
=== Checkstyle
|
||||
|
||||
Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are:
|
||||
|
||||
.spring-cloud-build-tools/
|
||||
----
|
||||
└── src
|
||||
├── checkstyle
|
||||
│ └── checkstyle-suppressions.xml <3>
|
||||
└── main
|
||||
└── resources
|
||||
├── checkstyle-header.txt <2>
|
||||
└── checkstyle.xml <1>
|
||||
----
|
||||
<1> Default Checkstyle rules
|
||||
<2> File header setup
|
||||
<3> Default suppression rules
|
||||
|
||||
==== Checkstyle configuration
|
||||
|
||||
Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins.
|
||||
|
||||
.pom.xml
|
||||
----
|
||||
<properties>
|
||||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> <1>
|
||||
<maven-checkstyle-plugin.failsOnViolation>true
|
||||
</maven-checkstyle-plugin.failsOnViolation> <2>
|
||||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||||
</maven-checkstyle-plugin.includeTestSourceDirectory> <3>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin> <4>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin> <5>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin> <5>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</build>
|
||||
----
|
||||
<1> Fails the build upon Checkstyle errors
|
||||
<2> Fails the build upon Checkstyle violations
|
||||
<3> Checkstyle analyzes also the test sources
|
||||
<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules
|
||||
<5> Add checkstyle plugin to your build and reporting phases
|
||||
|
||||
If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example:
|
||||
|
||||
.projectRoot/src/checkstyle/checkstyle-suppresions.xml
|
||||
----
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||
<suppressions>
|
||||
<suppress files=".*ConfigServerApplication\.java" checks="HideUtilityClassConstructor"/>
|
||||
<suppress files=".*ConfigClientWatch\.java" checks="LineLengthCheck"/>
|
||||
</suppressions>
|
||||
----
|
||||
|
||||
It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script:
|
||||
|
||||
```bash
|
||||
$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
|
||||
$ touch .springformat
|
||||
```
|
||||
|
||||
=== IDE setup
|
||||
|
||||
==== Intellij IDEA
|
||||
|
||||
In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
|
||||
The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project.
|
||||
|
||||
.spring-cloud-build-tools/
|
||||
----
|
||||
└── src
|
||||
├── checkstyle
|
||||
│ └── checkstyle-suppressions.xml <3>
|
||||
└── main
|
||||
└── resources
|
||||
├── checkstyle-header.txt <2>
|
||||
├── checkstyle.xml <1>
|
||||
└── intellij
|
||||
├── Intellij_Project_Defaults.xml <4>
|
||||
└── Intellij_Spring_Boot_Java_Conventions.xml <5>
|
||||
----
|
||||
<1> Default Checkstyle rules
|
||||
<2> File header setup
|
||||
<3> Default suppression rules
|
||||
<4> Project defaults for Intellij that apply most of Checkstyle rules
|
||||
<5> Project style conventions for Intellij that apply most of Checkstyle rules
|
||||
|
||||
.Code style
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style]
|
||||
|
||||
Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file.
|
||||
|
||||
.Inspection profiles
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style]
|
||||
|
||||
Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file.
|
||||
|
||||
.Checkstyle
|
||||
|
||||
To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions
|
||||
|
||||
image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle]
|
||||
|
||||
Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables:
|
||||
|
||||
- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL.
|
||||
- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL.
|
||||
- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`.
|
||||
|
||||
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
|
||||
|
||||
=== Duplicate Finder
|
||||
|
||||
Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath.
|
||||
|
||||
==== Duplicate Finder configuration
|
||||
|
||||
Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`.
|
||||
|
||||
.pom.xml
|
||||
[source,xml]
|
||||
----
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.basepom.maven</groupId>
|
||||
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
----
|
||||
|
||||
For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation].
|
||||
|
||||
You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build.
|
||||
|
||||
If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project:
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.basepom.maven</groupId>
|
||||
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<ignoredClassPatterns>
|
||||
<ignoredClassPattern>org.joda.time.base.BaseDateTime</ignoredClassPattern>
|
||||
<ignoredClassPattern>.*module-info</ignoredClassPattern>
|
||||
</ignoredClassPatterns>
|
||||
<ignoredResourcePatterns>
|
||||
<ignoredResourcePattern>changelog.txt</ignoredResourcePattern>
|
||||
</ignoredResourcePatterns>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
To report security vulnerabilities, please go to https://pivotal.io/security.
|
||||
@@ -6,38 +6,39 @@ antora:
|
||||
- '@antora/collector-extension'
|
||||
- '@antora/atlas-extension'
|
||||
- require: '@springio/antora-extensions/root-component-extension'
|
||||
root_component_name: 'PROJECT_WITHOUT_SPRING'
|
||||
# FIXME: Run antora once using this extension to migrate to the Asciidoc Tabs syntax
|
||||
# and then remove this extension
|
||||
- require: '@springio/antora-extensions/tabs-migration-extension'
|
||||
unwrap_example_block: always
|
||||
save_result: true
|
||||
root_component_name: 'cloud-zookeeper'
|
||||
site:
|
||||
title: PROJECT_FULL_NAME
|
||||
url: https://docs.spring.io/PROJECT_NAME/reference/
|
||||
title: Spring Cloud Zookeeper
|
||||
url: https://docs.spring.io/spring-cloud-zookeeper/reference
|
||||
robots: allow
|
||||
git:
|
||||
ensure_git_suffix: false
|
||||
content:
|
||||
sources:
|
||||
- url: ./..
|
||||
branches: HEAD
|
||||
- url: https://github.com/spring-cloud/spring-cloud-zookeeper
|
||||
# Refname matching:
|
||||
# https://docs.antora.org/antora/latest/playbook/content-refname-matching/
|
||||
branches: [ main ]
|
||||
tags: [ '({4..9}).+({1..9}).+({0..9})?(-{RC,M}+({0..9}))', '!4.1.0-M1' ]
|
||||
start_path: docs
|
||||
worktrees: true
|
||||
asciidoc:
|
||||
attributes:
|
||||
page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud
|
||||
page-pagination: ''
|
||||
hide-uri-scheme: '@'
|
||||
tabs-sync-option: '@'
|
||||
chomp: 'all'
|
||||
extensions:
|
||||
- '@asciidoctor/tabs'
|
||||
- '@springio/asciidoctor-extensions'
|
||||
sourcemap: true
|
||||
urls:
|
||||
latest_version_segment_strategy: redirect:to
|
||||
latest_version_segment: ''
|
||||
redirect_facility: httpd
|
||||
ui:
|
||||
bundle:
|
||||
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip
|
||||
snapshot: true
|
||||
runtime:
|
||||
log:
|
||||
failure_level: warn
|
||||
format: pretty
|
||||
ui:
|
||||
bundle:
|
||||
url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.3.5/ui-bundle.zip
|
||||
@@ -1,4 +0,0 @@
|
||||
zookeeper:
|
||||
image: zookeeper
|
||||
ports:
|
||||
- "2181:2181"
|
||||
106
docs/.flattened-pom.xml
Normal file
106
docs/.flattened-pom.xml
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-docs</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Zookeeper Docs</name>
|
||||
<description>Spring Cloud Docs</description>
|
||||
<url>https://spring.io/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-docs</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-docs</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-docs</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-docs</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
32
docs/.github/workflows/deploy-docs.yml
vendored
32
docs/.github/workflows/deploy-docs.yml
vendored
@@ -1,32 +0,0 @@
|
||||
name: Deploy Docs
|
||||
on:
|
||||
push:
|
||||
branches-ignore: [ gh-pages ]
|
||||
tags: '**'
|
||||
repository_dispatch:
|
||||
types: request-build-reference # legacy
|
||||
#schedule:
|
||||
#- cron: '0 10 * * *' # Once per day at 10am UTC
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
actions: write
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
# if: github.repository_owner == 'spring-cloud'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: docs-build
|
||||
fetch-depth: 1
|
||||
- name: Dispatch (partial build)
|
||||
if: github.ref_type == 'branch'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }}
|
||||
- name: Dispatch (full build)
|
||||
if: github.ref_type == 'tag'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD)
|
||||
@@ -1,12 +0,0 @@
|
||||
name: PROJECT_WITHOUT_SPRING
|
||||
version: true
|
||||
title: PROJECT_NAME
|
||||
nav:
|
||||
- modules/ROOT/nav.adoc
|
||||
ext:
|
||||
collector:
|
||||
run:
|
||||
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
|
||||
local: true
|
||||
scan:
|
||||
dir: ./target/classes/antora-resources/
|
||||
@@ -1,18 +0,0 @@
|
||||
* xref:index.adoc[]
|
||||
* xref:spring-cloud-zookeeper.adoc[]
|
||||
** xref:spring-cloud-zookeeper/quick-start.adoc[]
|
||||
** xref:spring-cloud-zookeeper/install.adoc[]
|
||||
** xref:spring-cloud-zookeeper/discovery.adoc[]
|
||||
** xref:spring-cloud-zookeeper/other-componentes.adoc[]
|
||||
** xref:spring-cloud-zookeeper/service-registry.adoc[]
|
||||
** xref:spring-cloud-zookeeper/dependencies.adoc[]
|
||||
** xref:spring-cloud-zookeeper/dependency-watcher.adoc[]
|
||||
** xref:spring-cloud-zookeeper/config.adoc[]
|
||||
* xref:intro.adoc[]
|
||||
* xref:_attributes.adoc[]
|
||||
* xref:quickstart.adoc[]
|
||||
* xref:README.adoc[]
|
||||
* xref:_configprops.adoc[]
|
||||
* xref:appendix.adoc[]
|
||||
* xref:sagan-boot.adoc[]
|
||||
* xref:sagan-index.adoc[]
|
||||
@@ -1,49 +0,0 @@
|
||||
image::https://travis-ci.org/spring-cloud/spring-cloud-zookeeper.svg?branch=master[Build Status, link=https://travis-ci.org/spring-cloud/spring-cloud-zookeeper]
|
||||
|
||||
|
||||
|
||||
[[quick-start]]
|
||||
= Quick Start
|
||||
|
||||
|
||||
[[zookeeper-overview]]
|
||||
= Zookeeper overview
|
||||
|
||||
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
|
||||
See the
|
||||
https://zookeeper.apache.org[Zookeeper site] for more information.
|
||||
Spring Cloud Zookeeper also builds on the https://curator.apache.org[Apache Curator] project, which started life at Netflix.
|
||||
|
||||
[[spring-cloud-zookeeper-features]]
|
||||
= Spring Cloud Zookeeper Features
|
||||
|
||||
Spring Cloud Zookeeper includes the following features:
|
||||
|
||||
* Spring Cloud `DiscoveryClient` implementation (supports Spring Cloud LoadBalancer)
|
||||
* Zookeeper-based `PropertySource` loaded during the 'bootstrap' phase
|
||||
|
||||
[[running-the-sample]]
|
||||
= Running the Sample
|
||||
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_Download[Install
|
||||
zookeeper] (On a mac with homebrew, use `brew install zookeeper`).
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_InstallingSingleMode[Start
|
||||
zookeeper].
|
||||
. https://zookeeper.apache.org/doc/current/zookeeperStarted.html#sc_ConnectingToZooKeeper[Verify
|
||||
zookeeper is running].
|
||||
. Run `mvn --settings .settings.xml package`.
|
||||
Doing so brings in the required Spring Cloud Maven repositories and Build.
|
||||
. Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar`.
|
||||
. Visit http://localhost:8080 to verify that `{"serviceId":"testZookeeperApp","host":"<yourhost>","port":8080}` works.
|
||||
. Run `java -jar spring-cloud-zookeeper-sample/target/spring-cloud-zookeeper-sample-1.2.0.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
. Visit http://localhost:8080 again to verify that `{"serviceId":"testZookeeperApp","host":"<yourhost>","port":8081}` eventually shows up in the results in a round-robin fashion. (It may take a minute or so.)
|
||||
|
||||
[[building]]
|
||||
= Building
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/building.adoc[]
|
||||
|
||||
[[contributing]]
|
||||
= Contributing
|
||||
|
||||
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/contributing.adoc[]
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
:doctype: book
|
||||
:idprefix:
|
||||
:idseparator: -
|
||||
:tabsize: 4
|
||||
:numbered:
|
||||
:sectanchors:
|
||||
:sectnums:
|
||||
:icons: font
|
||||
:hide-uri-scheme:
|
||||
:docinfo: shared,private
|
||||
|
||||
:sc-ext: java
|
||||
:project-full-name: Spring Cloud Zookeeper
|
||||
@@ -1,35 +0,0 @@
|
||||
|===
|
||||
|Name | Default | Description
|
||||
|
||||
|spring.cloud.zookeeper.base-sleep-time-ms | `+++50+++` | Initial amount of time to wait between retries.
|
||||
|spring.cloud.zookeeper.block-until-connected-unit | | The unit of time related to blocking on connection to Zookeeper.
|
||||
|spring.cloud.zookeeper.block-until-connected-wait | `+++10+++` | Wait time to block on connection to Zookeeper.
|
||||
|spring.cloud.zookeeper.config.default-context | `+++application+++` | The name of the default context.
|
||||
|spring.cloud.zookeeper.config.enabled | `+++true+++` |
|
||||
|spring.cloud.zookeeper.config.fail-fast | `+++true+++` | Throw exceptions during config lookup if true, otherwise, log warnings.
|
||||
|spring.cloud.zookeeper.config.name | | Alternative to spring.application.name to use in looking up values in zookeeper.
|
||||
|spring.cloud.zookeeper.config.profile-separator | `+++,+++` | Separator for profile appended to the application name.
|
||||
|spring.cloud.zookeeper.config.root | `+++config+++` | Root folder where the configuration for Zookeeper is kept.
|
||||
|spring.cloud.zookeeper.connect-string | `+++localhost:2181+++` | Connection string to the Zookeeper cluster.
|
||||
|spring.cloud.zookeeper.connection-timeout | | The configured connection timeout in milliseconds.
|
||||
|spring.cloud.zookeeper.dependencies | | Mapping of alias to ZookeeperDependency. From LoadBalancer perspective the alias is actually serviceID since SC LoadBalancer can't accept nested structures in serviceID.
|
||||
|spring.cloud.zookeeper.dependency-configurations | |
|
||||
|spring.cloud.zookeeper.dependency-names | |
|
||||
|spring.cloud.zookeeper.discovery.enabled | `+++true+++` |
|
||||
|spring.cloud.zookeeper.discovery.initial-status | | The initial status of this instance (defaults to {@link StatusConstants#STATUS_UP}).
|
||||
|spring.cloud.zookeeper.discovery.instance-host | | Predefined host with which a service can register itself in Zookeeper. Corresponds to the {code address} from the URI spec.
|
||||
|spring.cloud.zookeeper.discovery.instance-id | | Id used to register with zookeeper. Defaults to a random UUID.
|
||||
|spring.cloud.zookeeper.discovery.instance-port | | Port to register the service under (defaults to listening port).
|
||||
|spring.cloud.zookeeper.discovery.instance-ssl-port | | Ssl port of the registered service.
|
||||
|spring.cloud.zookeeper.discovery.metadata | | Gets the metadata name/value pairs associated with this instance. This information is sent to zookeeper and can be used by other instances.
|
||||
|spring.cloud.zookeeper.discovery.order | `+++0+++` | Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
|
||||
|spring.cloud.zookeeper.discovery.register | `+++true+++` | Register as a service in zookeeper.
|
||||
|spring.cloud.zookeeper.discovery.root | `+++/services+++` | Root Zookeeper folder in which all instances are registered.
|
||||
|spring.cloud.zookeeper.discovery.uri-spec | `+++{scheme}://{address}:{port}+++` | The URI specification to resolve during service registration in Zookeeper.
|
||||
|spring.cloud.zookeeper.enabled | `+++true+++` | Is Zookeeper enabled.
|
||||
|spring.cloud.zookeeper.max-retries | `+++10+++` | Max number of times to retry.
|
||||
|spring.cloud.zookeeper.max-sleep-ms | `+++500+++` | Max time in ms to sleep on each retry.
|
||||
|spring.cloud.zookeeper.prefix | | Common prefix that will be applied to all Zookeeper dependencies' paths.
|
||||
|spring.cloud.zookeeper.session-timeout | | The configured/negotiated session timeout in milliseconds. Please refer to <a href='https://cwiki.apache.org/confluence/display/CURATOR/TN14'>Curator's Tech Note 14</a> to understand how Curator implements connection sessions. @see <a href='https://cwiki.apache.org/confluence/display/CURATOR/TN14'>Curator's Tech Note 14</a>
|
||||
|
||||
|===
|
||||
@@ -1,13 +0,0 @@
|
||||
:numbered!:
|
||||
[appendix]
|
||||
[[common-application-properties]]
|
||||
= Common application properties
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
|
||||
Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches.
|
||||
This appendix provides a list of common {project-full-name} properties and references to the underlying classes that consume them.
|
||||
|
||||
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
|
||||
Also, you can define your own properties.
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
|
||||
This project provides Zookeeper integrations for Spring Boot applications through
|
||||
autoconfiguration and binding to the Spring Environment and other Spring programming model
|
||||
idioms. With a few annotations, you can quickly enable and configure the common patterns
|
||||
inside your application and build large distributed systems with Zookeeper based
|
||||
components. The provided patterns include Service Discovery and Configuration. The project
|
||||
also provides client-side load-balancing via integration with Spring Cloud LoadBalancer.
|
||||
@@ -1,234 +0,0 @@
|
||||
This quick start walks through using Spring Cloud Zookeeper for Service Discovery and Distributed Configuration.
|
||||
|
||||
First, run Zookeeper on your machine. Then you can access it and use it as a Service Registry and Configuration source with Spring Cloud Zookeeper.
|
||||
|
||||
[[discovery-client-usage]]
|
||||
= Discovery Client Usage
|
||||
|
||||
To use these features in an application, you can build it as a Spring Boot application that depends on `spring-cloud-zookeeper-core` and `spring-cloud-zookeeper-discovery`.
|
||||
The most convenient way to add the dependency is with a Spring Boot starter: `org.springframework.cloud:spring-cloud-starter-zookeeper-discovery`.
|
||||
We recommend using dependency management and `spring-boot-starter-parent`.
|
||||
The following example shows a typical Maven configuration:
|
||||
|
||||
[source,xml,indent=0]
|
||||
.pom.xml
|
||||
----
|
||||
<project>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>{spring-boot-version}</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
----
|
||||
|
||||
The following example shows a typical Gradle setup:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
.build.gradle
|
||||
----
|
||||
plugins {
|
||||
id 'org.springframework.boot' version ${spring-boot-version}
|
||||
id 'io.spring.dependency-management' version ${spring-dependency-management-version}
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
WARNING: Depending on the version you are using, you might need to adjust Apache Zookeeper version used in your project.
|
||||
You can read more about it in the xref:spring-cloud-zookeeper/install.adoc[Install Zookeeper section].
|
||||
|
||||
Now you can create a standard Spring Boot application, such as the following HTTP server:
|
||||
|
||||
----
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
When this HTTP server runs, it connects to Zookeeper, which runs on the default local port (2181).
|
||||
To modify the startup behavior, you can change the location of Zookeeper by using `application.properties`, as shown in the following example:
|
||||
|
||||
----
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
connect-string: localhost:2181
|
||||
----
|
||||
|
||||
You can now use `DiscoveryClient`, `@LoadBalanced RestTemplate`, or `@LoadBalanced WebClient.Builder` to retrieve services and instances data from Zookeeper, as shown in the following example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
public String serviceUrl() {
|
||||
List<ServiceInstance> list = discoveryClient.getInstances("STORES");
|
||||
if (list != null && list.size() > 0 ) {
|
||||
return list.get(0).getUri().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
----
|
||||
|
||||
[[distributed-configuration-usage]]
|
||||
= Distributed Configuration Usage
|
||||
|
||||
To use these features in an application, you can build it as a Spring Boot application that depends on `spring-cloud-zookeeper-core` and `spring-cloud-zookeeper-config`.
|
||||
The most convenient way to add the dependency is with a Spring Boot starter: `org.springframework.cloud:spring-cloud-starter-zookeeper-config`.
|
||||
We recommend using dependency management and `spring-boot-starter-parent`.
|
||||
The following example shows a typical Maven configuration:
|
||||
|
||||
[source,xml,indent=0]
|
||||
.pom.xml
|
||||
----
|
||||
<project>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>{spring-boot-version}</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
----
|
||||
|
||||
The following example shows a typical Gradle setup:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
.build.gradle
|
||||
----
|
||||
plugins {
|
||||
id 'org.springframework.boot' version ${spring-boot-version}
|
||||
id 'io.spring.dependency-management' version ${spring-dependency-management-version}
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-config'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
WARNING: Depending on the version you are using, you might need to adjust Apache Zookeeper version used in your project.
|
||||
You can read more about it in the xref:spring-cloud-zookeeper/install.adoc[Install Zookeeper section].
|
||||
|
||||
Now you can create a standard Spring Boot application, such as the following HTTP server:
|
||||
|
||||
----
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "Hello World!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
The application retrieves configuration data from Zookeeper.
|
||||
|
||||
WARNING: If you use Spring Cloud Zookeeper Config, you need to set the `spring.config.import` property in order to bind to Zookeeper.
|
||||
You can read more about it in the xref:spring-cloud-zookeeper/config.adoc#config-data-import[Spring Boot Config Data Import section].
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
|
||||
Spring Cloud Zookeeper provides http://zookeeper.apache.org/[Apache Zookeeper] integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with Zookeeper. The patterns provided include Service Discovery and Distributed Configuration.
|
||||
|
||||
## Features
|
||||
|
||||
* Service Discovery: instances can be registered with Zookeeper and clients can discover the instances using Spring-managed beans
|
||||
* Supports Spring Cloud LoadBalancer - client-side load-balancing solution
|
||||
* Supports Spring Cloud OpenFeign
|
||||
* Distributed Configuration: using Zookeeper as a data store
|
||||
|
||||
## Quick Start
|
||||
|
||||
As long as Spring Cloud Zookeeper, http://curator.apache.org/[Apache Curator] and the Zookeeper Java Client are on the
|
||||
classpath any Spring Boot application with `@EnableDiscoveryClient` will try to contact a Zookeeper
|
||||
agent on `localhost:2181` (the default value of
|
||||
`zookeeper.connectString`).
|
||||
|
||||
```java
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@EnableDiscoveryClient
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String home() {
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
A local Zookeeper server must be running. See the http://zookeeper.apache.org/[Zookeeper documentation] on how to run a Zookeeper server.
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
[[spring-cloud-zookeeper]]
|
||||
= Spring Cloud Zookeeper
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
[[spring-cloud-zookeeper-config]]
|
||||
= Distributed Configuration with Zookeeper
|
||||
|
||||
Zookeeper provides a
|
||||
https://zookeeper.apache.org/doc/current/zookeeperOver.html#sc_dataModelNameSpace[hierarchical namespace]
|
||||
that lets clients store arbitrary data, such as configuration data. Spring Cloud Zookeeper
|
||||
Config is an alternative to the
|
||||
https://github.com/spring-cloud/spring-cloud-config[Config Server and Client].
|
||||
Configuration is loaded into the Spring Environment during the special "`bootstrap`"
|
||||
phase. Configuration is stored in the `/config` namespace by default. Multiple
|
||||
`PropertySource` instances are created, based on the application's name and the active
|
||||
profiles, to mimic the Spring Cloud Config order of resolving properties. For example, an
|
||||
application with a name of `testApp` and with the `dev` profile has the following property
|
||||
sources created for it:
|
||||
|
||||
* `config/testApp,dev`
|
||||
* `config/testApp`
|
||||
* `config/application,dev`
|
||||
* `config/application`
|
||||
|
||||
The most specific property source is at the top, with the least specific at the bottom.
|
||||
Properties in the `config/application` namespace apply to all applications that use
|
||||
zookeeper for configuration. Properties in the `config/testApp` namespace are available
|
||||
only to the instances of the service named `testApp`.
|
||||
|
||||
Configuration is currently read on startup of the application. Sending a HTTP `POST`
|
||||
request to `/refresh` causes the configuration to be reloaded. Watching the configuration
|
||||
namespace (which Zookeeper supports) is not currently implemented.
|
||||
|
||||
[[activating]]
|
||||
== Activating
|
||||
|
||||
Including a dependency on
|
||||
`org.springframework.cloud:spring-cloud-starter-zookeeper-config` enables
|
||||
autoconfiguration that sets up Spring Cloud Zookeeper Config.
|
||||
|
||||
CAUTION: When working with version 3.4 of Zookeeper you need to change
|
||||
the way you include the dependency as described xref:spring-cloud-zookeeper/install.adoc[here].
|
||||
|
||||
[[config-data-import]]
|
||||
== Spring Boot Config Data Import
|
||||
|
||||
Spring Boot 2.4 introduced a new way to import configuration data via the `spring.config.import` property. This is now the default way to get configuration from Zookeeper.
|
||||
|
||||
To optionally connect to Zookeeper for configuration set the following in application.properties:
|
||||
|
||||
.application.properties
|
||||
[source,properties]
|
||||
----
|
||||
spring.config.import=optional:zookeeper:
|
||||
----
|
||||
|
||||
This will connect to Zookeeper at the default location of "localhost:2181". Removing the `optional:` prefix will cause Zookeeper Config to fail if it is unable to connect to Zookeeper. To change the connection properties of Zookeeper Config either set `spring.cloud.zookeeper.connect-string` or add the connect string to the `spring.config.import` statement such as, `spring.config.import=optional:zookeeper:myhost:2818`. The location in the import property has precedence over the `connect-string` property.
|
||||
|
||||
Zookeeper Config will try to load values from four automatic contexts based on `spring.cloud.zookeeper.config.name` (which defaults to the value of the `spring.application.name` property) and `spring.cloud.zookeeper.config.default-context` (which defaults to `application`). If you want to specify the contexts rather than using the computed ones, you can add that information to the `spring.config.import` statement.
|
||||
|
||||
.application.properties
|
||||
[source,properties]
|
||||
----
|
||||
spring.config.import=optional:zookeeper:myhost:2181/contextone;/context/two
|
||||
----
|
||||
|
||||
This will optionally load configuration only from `/contextone` and `/context/two`.
|
||||
|
||||
NOTE: A `bootstrap` file (properties or yaml) is *not* needed for the Spring Boot Config Data method of import via `spring.config.import`.
|
||||
|
||||
[[customizing]]
|
||||
== Customizing
|
||||
|
||||
Zookeeper Config may be customized by setting the following properties:
|
||||
|
||||
[source,yml,indent=0]
|
||||
----
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
config:
|
||||
enabled: true
|
||||
root: configuration
|
||||
defaultContext: apps
|
||||
profileSeparator: '::'
|
||||
----
|
||||
|
||||
* `enabled`: Setting this value to `false` disables Zookeeper Config.
|
||||
* `root`: Sets the base namespace for configuration values.
|
||||
* `defaultContext`: Sets the name used by all applications.
|
||||
* `profileSeparator`: Sets the value of the separator used to separate the profile name in
|
||||
property sources with profiles.
|
||||
|
||||
CAUTION: If you have set `spring.cloud.bootstrap.enabled=true` or `spring.config.use-legacy-processing=true`, or included `spring-cloud-starter-bootstrap`, then the above values will need to be placed in `bootstrap.yml` instead of `application.yml`.
|
||||
|
||||
[[access-control-lists-acls]]
|
||||
== Access Control Lists (ACLs)
|
||||
|
||||
You can add authentication information for Zookeeper ACLs by calling the `addAuthInfo`
|
||||
method of a `CuratorFramework` bean. One way to accomplish this is to provide your own
|
||||
`CuratorFramework` bean, as shown in the following example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@BoostrapConfiguration
|
||||
public class CustomCuratorFrameworkConfig {
|
||||
|
||||
@Bean
|
||||
public CuratorFramework curatorFramework() {
|
||||
CuratorFramework curator = new CuratorFramework();
|
||||
curator.addAuthInfo("digest", "user:password".getBytes());
|
||||
return curator;
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
Consult
|
||||
https://github.com/spring-cloud/spring-cloud-zookeeper/blob/master/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java[the ZookeeperAutoConfiguration class]
|
||||
to see how the `CuratorFramework` bean's default configuration.
|
||||
|
||||
Alternatively, you can add your credentials from a class that depends on the existing
|
||||
`CuratorFramework` bean, as shown in the following example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@BoostrapConfiguration
|
||||
public class DefaultCuratorFrameworkConfig {
|
||||
|
||||
public ZookeeperConfig(CuratorFramework curator) {
|
||||
curator.addAuthInfo("digest", "user:password".getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
The creation of this bean must occur during the boostrapping phase. You can register
|
||||
configuration classes to run during this phase by annotating them with
|
||||
`@BootstrapConfiguration` and including them in a comma-separated list that you set as the
|
||||
value of the `org.springframework.cloud.bootstrap.BootstrapConfiguration` property in the
|
||||
`resources/META-INF/spring.factories` file, as shown in the following example:
|
||||
|
||||
.resources/META-INF/spring.factories
|
||||
----
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
my.project.CustomCuratorFrameworkConfig,\
|
||||
my.project.DefaultCuratorFrameworkConfig
|
||||
----
|
||||
@@ -1,208 +0,0 @@
|
||||
[[spring-cloud-zookeeper-dependencies]]
|
||||
= Zookeeper Dependencies
|
||||
|
||||
The following topics cover how to work with Spring Cloud Zookeeper dependencies:
|
||||
|
||||
* xref:spring-cloud-zookeeper/dependencies.adoc#spring-cloud-zookeeper-dependencies-using[Using the Zookeeper Dependencies]
|
||||
* xref:spring-cloud-zookeeper/dependencies.adoc#spring-cloud-zookeeper-dependencies-activating[Activating Zookeeper Dependencies]
|
||||
* xref:spring-cloud-zookeeper/dependencies.adoc#spring-cloud-zookeeper-dependencies-setting-up[Setting up Zookeeper Dependencies]
|
||||
* xref:spring-cloud-zookeeper/dependencies.adoc#spring-cloud-zookeeper-dependencies-configuring[Configuring Spring Cloud Zookeeper Dependencies]
|
||||
|
||||
[[spring-cloud-zookeeper-dependencies-using]]
|
||||
== Using the Zookeeper Dependencies
|
||||
|
||||
Spring Cloud Zookeeper gives you a possibility to provide dependencies of your application
|
||||
as properties. As dependencies, you can understand other applications that are registered
|
||||
in Zookeeper and which you would like to call through
|
||||
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-feign[Feign]
|
||||
(a REST client builder),
|
||||
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/ascii[Spring
|
||||
`RestTemplate`] and
|
||||
https://cloud.spring.io/spring-cloud-commons/reference/html/#loadbalanced-webclient[Spring WebFlux].
|
||||
|
||||
You can also use the Zookeeper Dependency Watchers functionality to control and monitor
|
||||
the state of your dependencies.
|
||||
|
||||
[[spring-cloud-zookeeper-dependencies-activating]]
|
||||
== Activating Zookeeper Dependencies
|
||||
|
||||
Including a dependency on
|
||||
`org.springframework.cloud:spring-cloud-starter-zookeeper-discovery` enables
|
||||
autoconfiguration that sets up Spring Cloud Zookeeper Dependencies. Even if you provide
|
||||
the dependencies in your properties, you can turn off the dependencies. To do so, set the
|
||||
`spring.cloud.zookeeper.dependency.enabled` property to false (it defaults to `true`).
|
||||
|
||||
[[spring-cloud-zookeeper-dependencies-setting-up]]
|
||||
== Setting up Zookeeper Dependencies
|
||||
|
||||
Consider the following example of dependency representation:
|
||||
|
||||
[source,yml,indent=0]
|
||||
.application.yml
|
||||
----
|
||||
spring.application.name: yourServiceName
|
||||
spring.cloud.zookeeper:
|
||||
dependencies:
|
||||
newsletter:
|
||||
path: /path/where/newsletter/has/registered/in/zookeeper
|
||||
loadBalancerType: ROUND_ROBIN
|
||||
contentTypeTemplate: application/vnd.newsletter.$version+json
|
||||
version: v1
|
||||
headers:
|
||||
header1:
|
||||
- value1
|
||||
header2:
|
||||
- value2
|
||||
required: false
|
||||
stubs: org.springframework:foo:stubs
|
||||
mailing:
|
||||
path: /path/where/mailing/has/registered/in/zookeeper
|
||||
loadBalancerType: ROUND_ROBIN
|
||||
contentTypeTemplate: application/vnd.mailing.$version+json
|
||||
version: v1
|
||||
required: true
|
||||
----
|
||||
|
||||
The next few sections go through each part of the dependency one by one. The root property
|
||||
name is `spring.cloud.zookeeper.dependencies`.
|
||||
|
||||
[[spring-cloud-zookeeper-dependencies-setting-up-aliases]]
|
||||
=== Aliases
|
||||
|
||||
Below the root property you have to represent each dependency as an alias.
|
||||
This is due to the constraints of Spring Cloud LoadBalancer, which requires that the application ID be placed in the URL.
|
||||
Consequently, you cannot pass any complex path, suchas `/myApp/myRoute/name`).
|
||||
The alias is the name you use instead of the `serviceId` for `DiscoveryClient`, `Feign`, or
|
||||
`RestTemplate`.
|
||||
|
||||
In the previous examples, the aliases are `newsletter` and `mailing`.
|
||||
The following example shows Feign usage with a `newsletter` alias:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@FeignClient("newsletter")
|
||||
public interface NewsletterService {
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/newsletter")
|
||||
String getNewsletters();
|
||||
}
|
||||
----
|
||||
|
||||
[[path]]
|
||||
=== Path
|
||||
|
||||
The path is represented by the `path` YAML property and is the path under which the dependency is registered under Zookeeper.
|
||||
As described in the
|
||||
xref:spring-cloud-zookeeper/dependencies.adoc#spring-cloud-zookeeper-dependencies-setting-up-aliases[previous section], Spring Cloud LoadBalancer operates on URLs.
|
||||
As a result, this path is not compliant with its requirement.
|
||||
That is why Spring Cloud Zookeeper maps the alias to the proper path.
|
||||
|
||||
[[load-balancer-type]]
|
||||
=== Load Balancer Type
|
||||
|
||||
The load balancer type is represented by `loadBalancerType` YAML property.
|
||||
|
||||
If you know what kind of load-balancing strategy has to be applied when calling this particular dependency, you can provide it in the YAML file, and it is automatically applied.
|
||||
You can choose one of the following load balancing strategies:
|
||||
|
||||
* STICKY: Once chosen, the instance is always called.
|
||||
* RANDOM: Picks an instance randomly.
|
||||
* ROUND_ROBIN: Iterates over instances over and over again.
|
||||
|
||||
[[content-type-template-and-version]]
|
||||
=== `Content-Type` Template and Version
|
||||
|
||||
The `Content-Type` template and version are represented by the `contentTypeTemplate` and
|
||||
`version` YAML properties.
|
||||
|
||||
If you version your API in the `Content-Type` header, you do not want to add this header
|
||||
to each of your requests. Also, if you want to call a new version of the API, you do not
|
||||
want to roam around your code to bump up the API version. That is why you can provide a
|
||||
`contentTypeTemplate` with a special `$version` placeholder. That placeholder will be filled by the value of the
|
||||
`version` YAML property. Consider the following example of a `contentTypeTemplate`:
|
||||
|
||||
----
|
||||
application/vnd.newsletter.$version+json
|
||||
----
|
||||
|
||||
Further consider the following `version`:
|
||||
|
||||
----
|
||||
v1
|
||||
----
|
||||
|
||||
The combination of `contentTypeTemplate` and version results in the creation of a
|
||||
`Content-Type` header for each request, as follows:
|
||||
|
||||
----
|
||||
application/vnd.newsletter.v1+json
|
||||
----
|
||||
|
||||
[[default-headers]]
|
||||
=== Default Headers
|
||||
|
||||
Default headers are represented by the `headers` map in YAML.
|
||||
|
||||
Sometimes, each call to a dependency requires setting up of some default headers. To not
|
||||
do that in code, you can set them up in the YAML file, as shown in the following example
|
||||
`headers` section:
|
||||
|
||||
[source,yml,indent=0]
|
||||
----
|
||||
headers:
|
||||
Accept:
|
||||
- text/html
|
||||
- application/xhtml+xml
|
||||
Cache-Control:
|
||||
- no-cache
|
||||
----
|
||||
|
||||
That `headers` section results in adding the `Accept` and `Cache-Control` headers with
|
||||
appropriate list of values in your HTTP request.
|
||||
|
||||
[[required-dependencies]]
|
||||
=== Required Dependencies
|
||||
|
||||
Required dependencies are represented by `required` property in YAML.
|
||||
|
||||
If one of your dependencies is required to be up when your application boots, you can set
|
||||
the `required: true` property in the YAML file.
|
||||
|
||||
If your application cannot localize the required dependency during boot time, it throws an
|
||||
exception, and the Spring Context fails to set up. In other words, your application cannot
|
||||
start if the required dependency is not registered in Zookeeper.
|
||||
|
||||
You can read more about Spring Cloud Zookeeper Presence Checker
|
||||
xref:spring-cloud-zookeeper/dependency-watcher.adoc#spring-cloud-zookeeper-dependency-watcher-presence-checker[later in this document].
|
||||
|
||||
[[stubs]]
|
||||
=== Stubs
|
||||
|
||||
You can provide a colon-separated path to the JAR containing stubs of the dependency, as
|
||||
shown in the following example:
|
||||
|
||||
`stubs: org.springframework:myApp:stubs`
|
||||
|
||||
where:
|
||||
|
||||
* `org.springframework` is the `groupId`.
|
||||
* `myApp` is the `artifactId`.
|
||||
* `stubs` is the classifier. (Note that `stubs` is the default value.)
|
||||
|
||||
Because `stubs` is the default classifier, the preceding example is equal to the following
|
||||
example:
|
||||
|
||||
`stubs: org.springframework:myApp`
|
||||
|
||||
[[spring-cloud-zookeeper-dependencies-configuring]]
|
||||
== Configuring Spring Cloud Zookeeper Dependencies
|
||||
|
||||
You can set the following properties to enable or disable parts of Zookeeper Dependencies functionalities:
|
||||
|
||||
* `spring.cloud.zookeeper.dependencies`: If you do not set this property, you cannot use Zookeeper Dependencies.
|
||||
* `spring.cloud.zookeeper.dependency.loadbalancer.enabled` (enabled by default): Turns on Zookeeper-specific custom load-balancing strategies, including `ZookeeperServiceInstanceListSupplier` and dependency-based load-balanced `RestTemplate` setup.
|
||||
* `spring.cloud.zookeeper.dependency.headers.enabled` (enabled by default): This property registers a `FeignBlockingLoadBalancerClient` that automatically appends appropriate headers and content types with their versions, as presented in the Dependency configuration.
|
||||
Without this setting, those two parameters do not work.
|
||||
* `spring.cloud.zookeeper.dependency.resttemplate.enabled` (enabled by default): When enabled, this property modifies the request headers of a `@LoadBalanced`-annotated
|
||||
`RestTemplate` such that it passes headers and content type with the version set in dependency configuration.
|
||||
Without this setting, those two parameters do not work.
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
[[spring-cloud-zookeeper-dependency-watcher]]
|
||||
= Spring Cloud Zookeeper Dependency Watcher
|
||||
|
||||
The Dependency Watcher mechanism lets you register listeners to your dependencies. The
|
||||
functionality is, in fact, an implementation of the `Observator` pattern. When a
|
||||
dependency changes, its state (to either UP or DOWN), some custom logic can be applied.
|
||||
|
||||
[[activating]]
|
||||
== Activating
|
||||
|
||||
Spring Cloud Zookeeper Dependencies functionality needs to be enabled for you to use the
|
||||
Dependency Watcher mechanism.
|
||||
// TODO: How can the reader do that?
|
||||
|
||||
[[registering-a-listener]]
|
||||
== Registering a Listener
|
||||
|
||||
To register a listener, you must implement an interface called
|
||||
`org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener` and
|
||||
register it as a bean. The interface gives you one method:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
void stateChanged(String dependencyName, DependencyState newState);
|
||||
----
|
||||
|
||||
If you want to register a listener for a particular dependency, the `dependencyName` would
|
||||
be the discriminator for your concrete implementation. `newState` provides you with
|
||||
information about whether your dependency has changed to `CONNECTED` or `DISCONNECTED`.
|
||||
|
||||
[[spring-cloud-zookeeper-dependency-watcher-presence-checker]]
|
||||
== Using the Presence Checker
|
||||
|
||||
Bound with the Dependency Watcher is the functionality called Presence Checker. It lets
|
||||
you provide custom behavior when your application boots, to react according to the state
|
||||
of your dependencies.
|
||||
|
||||
The default implementation of the abstract
|
||||
`org.springframework.cloud.zookeeper.discovery.watcher.presence.DependencyPresenceOnStartupVerifier`
|
||||
class is the
|
||||
`org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier`,
|
||||
which works in the following way.
|
||||
|
||||
. If the dependency is marked us `required` and is not in Zookeeper, when your application
|
||||
boots, it throws an exception and shuts down.
|
||||
. If the dependency is not `required`, the
|
||||
`org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker`
|
||||
logs that the dependency is missing at the `WARN` level.
|
||||
|
||||
Because the `DefaultDependencyPresenceOnStartupVerifier` is registered only when there is
|
||||
no bean of type `DependencyPresenceOnStartupVerifier`, this functionality can be
|
||||
overridden.
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
[[spring-cloud-zookeeper-discovery]]
|
||||
= Service Discovery with Zookeeper
|
||||
|
||||
Service Discovery is one of the key tenets of a microservice based architecture. Trying to
|
||||
hand-configure each client or some form of convention can be difficult to do and can be
|
||||
brittle. https://curator.apache.org[Curator](A Java library for Zookeeper) provides Service
|
||||
Discovery through a https://curator.apache.org/curator-x-discovery/[Service Discovery
|
||||
Extension]. Spring Cloud Zookeeper uses this extension for service registration and
|
||||
discovery.
|
||||
|
||||
[[activating]]
|
||||
== Activating
|
||||
|
||||
Including a dependency on
|
||||
`org.springframework.cloud:spring-cloud-starter-zookeeper-discovery` enables
|
||||
autoconfiguration that sets up Spring Cloud Zookeeper Discovery.
|
||||
|
||||
NOTE: For web functionality, you still need to include
|
||||
`org.springframework.boot:spring-boot-starter-web`.
|
||||
|
||||
CAUTION: When working with version 3.4 of Zookeeper you need to change
|
||||
the way you include the dependency as described xref:spring-cloud-zookeeper/install.adoc[here].
|
||||
|
||||
[[registering-with-zookeeper]]
|
||||
== Registering with Zookeeper
|
||||
|
||||
When a client registers with Zookeeper, it provides metadata (such as host and port, ID,
|
||||
and name) about itself.
|
||||
|
||||
The following example shows a Zookeeper client:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class Application {
|
||||
|
||||
@RequestMapping("/")
|
||||
public String home() {
|
||||
return "Hello world";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(Application.class).web(true).run(args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
NOTE: The preceding example is a normal Spring Boot application.
|
||||
|
||||
If Zookeeper is located somewhere other than `localhost:2181`, the configuration must
|
||||
provide the location of the server, as shown in the following example:
|
||||
|
||||
[source,yml,indent=0]
|
||||
.application.yml
|
||||
----
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
connect-string: localhost:2181
|
||||
----
|
||||
|
||||
CAUTION: If you use xref:spring-cloud-zookeeper/config.adoc[Spring Cloud Zookeeper Config], the
|
||||
values shown in the preceding example need to be in `bootstrap.yml` instead of
|
||||
`application.yml`.
|
||||
|
||||
The default service name, instance ID, and port (taken from the `Environment`) are
|
||||
`${spring.application.name}`, the Spring Context ID, and `${server.port}`, respectively.
|
||||
|
||||
Having `spring-cloud-starter-zookeeper-discovery` on the classpath makes the app into both
|
||||
a Zookeeper "`service`" (that is, it registers itself) and a "`client`" (that is, it can
|
||||
query Zookeeper to locate other services).
|
||||
|
||||
If you would like to disable the Zookeeper Discovery Client, you can set
|
||||
`spring.cloud.zookeeper.discovery.enabled` to `false`.
|
||||
|
||||
[[using-the-discoveryclient]]
|
||||
== Using the DiscoveryClient
|
||||
|
||||
Spring Cloud has support for
|
||||
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-feign[Feign]
|
||||
(a REST client builder),
|
||||
https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/ascii[Spring
|
||||
`RestTemplate`] and
|
||||
https://cloud.spring.io/spring-cloud-commons/reference/html/#loadbalanced-webclient[Spring WebFlux], using logical service names instead of physical URLs.
|
||||
|
||||
You can also use the `org.springframework.cloud.client.discovery.DiscoveryClient`, which
|
||||
provides a simple API for discovery clients that is not specific to Netflix, as shown in
|
||||
the following example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
public String serviceUrl() {
|
||||
List<ServiceInstance> list = discoveryClient.getInstances("STORES");
|
||||
if (list != null && list.size() > 0 ) {
|
||||
return list.get(0).getUri().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
----
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
[[spring-cloud-zookeeper-install]]
|
||||
= Install Zookeeper
|
||||
|
||||
See the https://zookeeper.apache.org/doc/current/zookeeperStarted.html[installation
|
||||
documentation] for instructions on how to install Zookeeper.
|
||||
|
||||
Spring Cloud Zookeeper uses Apache Curator behind the scenes.
|
||||
While Zookeeper 3.5.x is still considered "beta" by the Zookeeper development team,
|
||||
the reality is that it is used in production by many users.
|
||||
However, Zookeeper 3.4.x is also used in production.
|
||||
Prior to Apache Curator 4.0, both versions of Zookeeper were supported via two versions of Apache Curator.
|
||||
Starting with Curator 4.0 both versions of Zookeeper are supported via the same Curator libraries.
|
||||
|
||||
In case you are integrating with version 3.4 you need to change the Zookeeper dependency
|
||||
that comes shipped with `curator`, and thus `spring-cloud-zookeeper`.
|
||||
To do so simply exclude that dependency and add the 3.4.x version like shown below.
|
||||
|
||||
.maven
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.12</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
.gradle
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
compile('org.springframework.cloud:spring-cloud-starter-zookeeper-all') {
|
||||
exclude group: 'org.apache.zookeeper', module: 'zookeeper'
|
||||
}
|
||||
compile('org.apache.zookeeper:zookeeper:3.4.12') {
|
||||
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
|
||||
}
|
||||
----
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
[[spring-cloud-zookeeper-other-componentes]]
|
||||
= Using Spring Cloud Zookeeper with Spring Cloud Components
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
Feign, Spring Cloud Gateway and Spring Cloud LoadBalancer all work with Spring Cloud Zookeeper.
|
||||
|
||||
[[spring-cloud-loadbalancer-with-zookeeper]]
|
||||
== Spring Cloud LoadBalancer with Zookeeper
|
||||
|
||||
Spring Cloud Zookeeper provides an implementation of Spring Cloud LoadBalancer `ServiceInstanceListSupplier`.
|
||||
When you use the `spring-cloud-starter-zookeeper-discovery`, Spring Cloud LoadBalancer is autoconfigured to use the
|
||||
`ZookeeperServiceInstanceListSupplier` by default.
|
||||
|
||||
TIP: If you were previously using the StickyRule in Zookeeper, its replacement in the current stack
|
||||
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].
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
[[quick-start]]
|
||||
= Quick Start
|
||||
:page-section-summary-toc: 1
|
||||
|
||||
include:../:quickstart.adoc[]
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
[[spring-cloud-zookeeper-service-registry]]
|
||||
= Spring Cloud Zookeeper and Service Registry
|
||||
|
||||
Spring Cloud Zookeeper implements the `ServiceRegistry` interface, letting developers
|
||||
register arbitrary services in a programmatic way.
|
||||
|
||||
The `ServiceInstanceRegistration` class offers a `builder()` method to create a
|
||||
`Registration` object that can be used by the `ServiceRegistry`, as shown in the following
|
||||
example:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Autowired
|
||||
private ZookeeperServiceRegistry serviceRegistry;
|
||||
|
||||
public void registerThings() {
|
||||
ZookeeperRegistration registration = ServiceInstanceRegistration.builder()
|
||||
.defaultUriSpec()
|
||||
.address("anyUrl")
|
||||
.port(10)
|
||||
.name("/a/b/c/d/anotherservice")
|
||||
.build();
|
||||
this.serviceRegistry.register(registration);
|
||||
}
|
||||
----
|
||||
|
||||
[[instance-status]]
|
||||
== Instance Status
|
||||
|
||||
Netflix Eureka supports having instances that are `OUT_OF_SERVICE` registered with the server.
|
||||
These instances are not returned as active service instances.
|
||||
This is useful for behaviors such as blue/green deployments.
|
||||
(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`.
|
||||
The `ZookeeperServiceInstanceListSupplier` filters out all non-null instance statuses that do not equal `UP`.
|
||||
If the instance status field is empty, it is considered to be `UP` for backwards compatibility.
|
||||
To change the status of an instance, make a `POST` with `OUT_OF_SERVICE` to the `ServiceRegistry`
|
||||
instance status actuator endpoint, as shown in the following example:
|
||||
|
||||
[source,sh,indent=0]
|
||||
----
|
||||
$ http POST http://localhost:8081/service-registry status=OUT_OF_SERVICE
|
||||
----
|
||||
|
||||
NOTE: The preceding example uses the `http` command from https://httpie.org.
|
||||
|
||||
66
docs/pom.xml
66
docs/pom.xml
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-zookeeper-docs</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Zookeeper Docs</name>
|
||||
<description>Spring Cloud Docs</description>
|
||||
<properties>
|
||||
<docs.main>spring-cloud-zookeeper</docs.main>
|
||||
<main.basedir>${basedir}/..</main.basedir>
|
||||
<configprops.inclusionPattern>spring.cloud.zookeeper.*|
|
||||
</configprops.inclusionPattern>
|
||||
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
|
||||
<!-- Don't upload docs jar to central / repo.spring.io -->
|
||||
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<sourceDirectory>src/main/asciidoc</sourceDirectory>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>docs</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -1,330 +0,0 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
set -e
|
||||
|
||||
# Set default props like MAVEN_PATH, ROOT_FOLDER etc.
|
||||
function set_default_props() {
|
||||
# The script should be run from the root folder
|
||||
ROOT_FOLDER=`pwd`
|
||||
echo "Current folder is ${ROOT_FOLDER}"
|
||||
|
||||
if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then
|
||||
echo "You're not in the root folder of the project!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prop that will let commit the changes
|
||||
COMMIT_CHANGES="no"
|
||||
MAVEN_PATH=${MAVEN_PATH:-}
|
||||
echo "Path to Maven is [${MAVEN_PATH}]"
|
||||
REPO_NAME=${PWD##*/}
|
||||
echo "Repo name is [${REPO_NAME}]"
|
||||
SPRING_CLOUD_STATIC_REPO=${SPRING_CLOUD_STATIC_REPO:-git@github.com:spring-cloud/spring-cloud-static.git}
|
||||
echo "Spring Cloud Static repo is [${SPRING_CLOUD_STATIC_REPO}"
|
||||
}
|
||||
|
||||
# Check if gh-pages exists and docs have been built
|
||||
function check_if_anything_to_sync() {
|
||||
git remote set-url --push origin `git config remote.origin.url | sed -e 's/^git:/https:/'`
|
||||
|
||||
if ! (git remote set-branches --add origin gh-pages && git fetch -q); then
|
||||
echo "No gh-pages, so not syncing"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! [ -d docs/target/generated-docs ] && ! [ "${BUILD}" == "yes" ]; then
|
||||
echo "No gh-pages sources in docs/target/generated-docs, so not syncing"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
function retrieve_current_branch() {
|
||||
# Code getting the name of the current branch. For master we want to publish as we did until now
|
||||
# https://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch
|
||||
# If there is a branch already passed will reuse it - otherwise will try to find it
|
||||
CURRENT_BRANCH=${BRANCH}
|
||||
if [[ -z "${CURRENT_BRANCH}" ]] ; then
|
||||
CURRENT_BRANCH=$(git symbolic-ref -q HEAD)
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/}
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD}
|
||||
fi
|
||||
echo "Current branch is [${CURRENT_BRANCH}]"
|
||||
git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
}
|
||||
|
||||
# Switches to the provided value of the release version. We always prefix it with `v`
|
||||
function switch_to_tag() {
|
||||
git checkout v${VERSION}
|
||||
}
|
||||
|
||||
# Build the docs if switch is on
|
||||
function build_docs_if_applicable() {
|
||||
if [[ "${BUILD}" == "yes" ]] ; then
|
||||
./mvnw clean install -P docs -pl docs -DskipTests
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the name of the `docs.main` property
|
||||
# Get allowed branches - assumes that a `docs` module is available under `docs` profile
|
||||
function retrieve_doc_properties() {
|
||||
MAIN_ADOC_VALUE=$("${MAVEN_PATH}"mvn -q \
|
||||
-Dexec.executable="echo" \
|
||||
-Dexec.args='${docs.main}' \
|
||||
--non-recursive \
|
||||
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
|
||||
echo "Extracted 'main.adoc' from Maven build [${MAIN_ADOC_VALUE}]"
|
||||
|
||||
|
||||
ALLOW_PROPERTY=${ALLOW_PROPERTY:-"docs.allowed.branches"}
|
||||
ALLOWED_BRANCHES_VALUE=$("${MAVEN_PATH}"mvn -q \
|
||||
-Dexec.executable="echo" \
|
||||
-Dexec.args="\${${ALLOW_PROPERTY}}" \
|
||||
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec \
|
||||
-P docs \
|
||||
-pl docs)
|
||||
echo "Extracted '${ALLOW_PROPERTY}' from Maven build [${ALLOWED_BRANCHES_VALUE}]"
|
||||
}
|
||||
|
||||
# Stash any outstanding changes
|
||||
function stash_changes() {
|
||||
git diff-index --quiet HEAD && dirty=$? || (echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1")
|
||||
if [ "$dirty" != "0" ]; then git stash; fi
|
||||
}
|
||||
|
||||
# Switch to gh-pages branch to sync it with current branch
|
||||
function add_docs_from_target() {
|
||||
local DESTINATION_REPO_FOLDER
|
||||
if [[ -z "${DESTINATION}" && -z "${CLONE}" ]] ; then
|
||||
DESTINATION_REPO_FOLDER=${ROOT_FOLDER}
|
||||
elif [[ "${CLONE}" == "yes" ]]; then
|
||||
mkdir -p ${ROOT_FOLDER}/target
|
||||
local clonedStatic=${ROOT_FOLDER}/target/spring-cloud-static
|
||||
if [[ ! -e "${clonedStatic}/.git" ]]; then
|
||||
echo "Cloning Spring Cloud Static to target"
|
||||
git clone ${SPRING_CLOUD_STATIC_REPO} ${clonedStatic} && git checkout gh-pages
|
||||
else
|
||||
echo "Spring Cloud Static already cloned - will pull changes"
|
||||
cd ${clonedStatic} && git checkout gh-pages && git pull origin gh-pages
|
||||
fi
|
||||
DESTINATION_REPO_FOLDER=${clonedStatic}/${REPO_NAME}
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
else
|
||||
if [[ ! -e "${DESTINATION}/.git" ]]; then
|
||||
echo "[${DESTINATION}] is not a git repository"
|
||||
exit 1
|
||||
fi
|
||||
DESTINATION_REPO_FOLDER=${DESTINATION}/${REPO_NAME}
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
echo "Destination was provided [${DESTINATION}]"
|
||||
fi
|
||||
cd ${DESTINATION_REPO_FOLDER}
|
||||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
|
||||
# Add git branches
|
||||
###################################################################
|
||||
if [[ -z "${VERSION}" ]] ; then
|
||||
copy_docs_for_current_version
|
||||
else
|
||||
copy_docs_for_provided_version
|
||||
fi
|
||||
commit_changes_if_applicable
|
||||
}
|
||||
|
||||
|
||||
# Copies the docs by using the retrieved properties from Maven build
|
||||
function copy_docs_for_current_version() {
|
||||
if [[ "${CURRENT_BRANCH}" == "master" ]] ; then
|
||||
echo -e "Current branch is master - will copy the current docs only to the root folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
# Not ignored...
|
||||
cp -rf $f ${ROOT_FOLDER}/
|
||||
git add -A ${ROOT_FOLDER}/$file
|
||||
fi
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
else
|
||||
echo -e "Current branch is [${CURRENT_BRANCH}]"
|
||||
# https://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin
|
||||
if [[ ",${ALLOWED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then
|
||||
mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
echo -e "Branch [${CURRENT_BRANCH}] is allowed! Will copy the current docs to the [${CURRENT_BRANCH}] folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ "${file}" == "${MAIN_ADOC_VALUE}.html" ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
else
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/$file
|
||||
fi
|
||||
fi
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
else
|
||||
echo -e "Branch [${CURRENT_BRANCH}] is not on the allow list! Check out the Maven [${ALLOW_PROPERTY}] property in
|
||||
[docs] module available under [docs] profile. Won't commit any changes to gh-pages for this branch."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Copies the docs by using the explicitly provided version
|
||||
function copy_docs_for_provided_version() {
|
||||
local FOLDER=${DESTINATION_REPO_FOLDER}/${VERSION}
|
||||
mkdir -p ${FOLDER}
|
||||
echo -e "Current tag is [v${VERSION}] Will copy the current docs to the [${FOLDER}] folder"
|
||||
for f in ${ROOT_FOLDER}/docs/target/generated-docs/*; do
|
||||
file=${f#${ROOT_FOLDER}/docs/target/generated-docs/*}
|
||||
copy_docs_for_branch ${file} ${FOLDER}
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
CURRENT_BRANCH="v${VERSION}"
|
||||
}
|
||||
|
||||
# Copies the docs from target to the provided destination
|
||||
# Params:
|
||||
# $1 - file from target
|
||||
# $2 - destination to which copy the files
|
||||
function copy_docs_for_branch() {
|
||||
local file=$1
|
||||
local destination=$2
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^${file}$; then
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ ("${file}" == "${MAIN_ADOC_VALUE}.html") || ("${file}" == "${REPO_NAME}.html") ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${destination}/index.html
|
||||
git add -A ${destination}/index.html
|
||||
else
|
||||
cp -rf $f ${destination}
|
||||
git add -A ${destination}/$file
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function commit_changes_if_applicable() {
|
||||
if [[ "${COMMIT_CHANGES}" == "yes" ]] ; then
|
||||
COMMIT_SUCCESSFUL="no"
|
||||
git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes"
|
||||
|
||||
# Uncomment the following push if you want to auto push to
|
||||
# the gh-pages branch whenever you commit to master locally.
|
||||
# This is a little extreme. Use with care!
|
||||
###################################################################
|
||||
if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then
|
||||
git push origin gh-pages
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Switch back to the previous branch and exit block
|
||||
function checkout_previous_branch() {
|
||||
# If -version was provided we need to come back to root project
|
||||
cd ${ROOT_FOLDER}
|
||||
git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
if [ "$dirty" != "0" ]; then git stash pop; fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Assert if properties have been properly passed
|
||||
function assert_properties() {
|
||||
echo "VERSION [${VERSION}], DESTINATION [${DESTINATION}], CLONE [${CLONE}]"
|
||||
if [[ "${VERSION}" != "" && (-z "${DESTINATION}" && -z "${CLONE}") ]] ; then echo "Version was set but destination / clone was not!"; exit 1;fi
|
||||
if [[ ("${DESTINATION}" != "" && "${CLONE}" != "") && -z "${VERSION}" ]] ; then echo "Destination / clone was set but version was not!"; exit 1;fi
|
||||
if [[ "${DESTINATION}" != "" && "${CLONE}" == "yes" ]] ; then echo "Destination and clone was set. Pick one!"; exit 1;fi
|
||||
}
|
||||
|
||||
# Prints the usage
|
||||
function print_usage() {
|
||||
cat <<EOF
|
||||
The idea of this script is to update gh-pages branch with the generated docs. Without any options
|
||||
the script will work in the following manner:
|
||||
|
||||
- if there's no gh-pages / target for docs module then the script ends
|
||||
- for master branch the generated docs are copied to the root of gh-pages branch
|
||||
- for any other branch (if that branch is allowed) a subfolder with branch name is created
|
||||
and docs are copied there
|
||||
- if the version switch is passed (-v) then a tag with (v) prefix will be retrieved and a folder
|
||||
with that version number will be created in the gh-pages branch. WARNING! No allow verification will take place
|
||||
- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will
|
||||
switch to gh-pages of that repo and copy the generated docs to `docs/<project-name>/<version>`
|
||||
- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will
|
||||
switch to gh-pages of that repo and copy the generated docs to `docs/<project-name>/<version>`
|
||||
|
||||
USAGE:
|
||||
|
||||
You can use the following options:
|
||||
|
||||
-v|--version - the script will apply the whole procedure for a particular library version
|
||||
-d|--destination - the root of destination folder where the docs should be copied. You have to use the full path.
|
||||
E.g. point to spring-cloud-static folder. Can't be used with (-c)
|
||||
-b|--build - will run the standard build process after checking out the branch
|
||||
-c|--clone - will automatically clone the spring-cloud-static repo instead of providing the destination.
|
||||
Obviously can't be used with (-d)
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
# ==========================================
|
||||
# ____ ____ _____ _____ _____ _______
|
||||
# / ____|/ ____| __ \|_ _| __ \__ __|
|
||||
# | (___ | | | |__) | | | | |__) | | |
|
||||
# \___ \| | | _ / | | | ___/ | |
|
||||
# ____) | |____| | \ \ _| |_| | | |
|
||||
# |_____/ \_____|_| \_\_____|_| |_|
|
||||
#
|
||||
# ==========================================
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case ${key} in
|
||||
-v|--version)
|
||||
VERSION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-d|--destination)
|
||||
DESTINATION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-b|--build)
|
||||
BUILD="yes"
|
||||
;;
|
||||
-c|--clone)
|
||||
CLONE="yes"
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: [$1]"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
assert_properties
|
||||
set_default_props
|
||||
check_if_anything_to_sync
|
||||
if [[ -z "${VERSION}" ]] ; then
|
||||
retrieve_current_branch
|
||||
else
|
||||
switch_to_tag
|
||||
fi
|
||||
build_docs_if_applicable
|
||||
retrieve_doc_properties
|
||||
stash_changes
|
||||
add_docs_from_target
|
||||
checkout_previous_branch
|
||||
199
mvnw
vendored
199
mvnw
vendored
@@ -8,7 +8,7 @@
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
@@ -19,7 +19,7 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven2 Start Up Batch script
|
||||
# Maven Start Up Batch script
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
@@ -54,38 +54,16 @@ case "`uname`" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
#
|
||||
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
|
||||
# for the new JDKs provided by Oracle.
|
||||
#
|
||||
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
|
||||
#
|
||||
# Oracle JDKs
|
||||
#
|
||||
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
|
||||
#
|
||||
# Apple JDKs
|
||||
#
|
||||
export JAVA_HOME=`/usr/libexec/java_home`
|
||||
fi
|
||||
;;
|
||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||
else
|
||||
export JAVA_HOME="/Library/Java/Home"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
@@ -130,13 +108,12 @@ if $cygwin ; then
|
||||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For Migwn, ensure paths are in UNIX format before anything is touched
|
||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
# TODO classpath?
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
@@ -184,27 +161,28 @@ fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
local basedir=$(pwd)
|
||||
local wdir=$(pwd)
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
basedir="$1"
|
||||
wdir="$1"
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
wdir=$(cd "$wdir/.."; pwd)
|
||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||
if [ -d "${wdir}" ]; then
|
||||
wdir=`cd "$wdir/.."; pwd`
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
echo "${basedir}"
|
||||
}
|
||||
@@ -216,9 +194,108 @@ concat_lines() {
|
||||
fi
|
||||
}
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
|
||||
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
##########################################################################################
|
||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
##########################################################################################
|
||||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||
fi
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||
fi
|
||||
if [ -n "$MVNW_REPOURL" ]; then
|
||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
else
|
||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
fi
|
||||
while IFS="=" read key value; do
|
||||
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||
esac
|
||||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Downloading from: $jarUrl"
|
||||
fi
|
||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||
if $cygwin; then
|
||||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||
fi
|
||||
|
||||
if command -v wget > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found wget ... using wget"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
wget "$jarUrl" -O "$wrapperJarPath"
|
||||
else
|
||||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
||||
fi
|
||||
elif command -v curl > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found curl ... using curl"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||
else
|
||||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||
fi
|
||||
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Falling back to using Java to download"
|
||||
fi
|
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
# For Cygwin, switch paths to Windows format before running javac
|
||||
if $cygwin; then
|
||||
javaClass=`cygpath --path --windows "$javaClass"`
|
||||
fi
|
||||
if [ -e "$javaClass" ]; then
|
||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
# Compiling the Java class
|
||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||
fi
|
||||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
# Running the downloader
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Running MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
##########################################################################################
|
||||
# End of extension
|
||||
##########################################################################################
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
fi
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||
@@ -226,28 +303,8 @@ export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
echo "Running version check"
|
||||
VERSION=$( sed '\!<parent!,\!</parent!d' `dirname $0`/pom.xml | grep '<version' | head -1 | sed -e 's/.*<version>//' -e 's!</version>.*$!!' )
|
||||
echo "The found version is [${VERSION}]"
|
||||
|
||||
if echo $VERSION | egrep -q 'M|RC'; then
|
||||
echo Activating \"milestone\" profile for version=\"$VERSION\"
|
||||
echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pmilestone"
|
||||
else
|
||||
echo Deactivating \"milestone\" profile for version=\"$VERSION\"
|
||||
echo $MAVEN_ARGS | grep -q milestone && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pmilestone//')
|
||||
fi
|
||||
|
||||
if echo $VERSION | egrep -q 'RELEASE'; then
|
||||
echo Activating \"central\" profile for version=\"$VERSION\"
|
||||
echo $MAVEN_ARGS | grep -q milestone || MAVEN_ARGS="$MAVEN_ARGS -Pcentral"
|
||||
else
|
||||
echo Deactivating \"central\" profile for version=\"$VERSION\"
|
||||
echo $MAVEN_ARGS | grep -q central && MAVEN_ARGS=$(echo $MAVEN_ARGS | sed -e 's/-Pcentral//')
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} ${MAVEN_ARGS} "$@"
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
55
mvnw.cmd
vendored
55
mvnw.cmd
vendored
@@ -7,7 +7,7 @@
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@@ -18,7 +18,7 @@
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven2 Start Up Batch script
|
||||
@REM Maven Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@@ -26,7 +26,7 @@
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@@ -35,7 +35,9 @@
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
@@ -80,8 +82,6 @@ goto error
|
||||
|
||||
:init
|
||||
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
@@ -117,11 +117,48 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
|
||||
set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
|
||||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
|
||||
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Found %WRAPPER_JAR%
|
||||
)
|
||||
) else (
|
||||
if not "%MVNW_REPOURL%" == "" (
|
||||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
)
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %DOWNLOAD_URL%
|
||||
)
|
||||
|
||||
powershell -Command "&{"^
|
||||
"$webclient = new-object System.Net.WebClient;"^
|
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||
"}"^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
|
||||
"}"
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||
@REM work with both Windows and non-Windows executions.
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
|
||||
257
pom.xml
257
pom.xml
@@ -1,225 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Zookeeper</name>
|
||||
<description>Spring Cloud Zookeeper</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath/>
|
||||
<!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-docs-build</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<name>Spring Cloud Zookeeper Docs Build</name>
|
||||
<description>Builds Spring Cloud Zookeeper Docs.</description>
|
||||
<url>https://spring.io/projects/spring-cloud-zookeeper</url>
|
||||
<scm>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper</url>
|
||||
<connection>
|
||||
scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git
|
||||
<connection>scm:git:https://github.com/spring-cloud/spring-cloud-zookeeper.git
|
||||
</connection>
|
||||
<developerConnection>
|
||||
scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git
|
||||
scm:git:git@github.com:spring-cloud/spring-cloud-zookeeper.git
|
||||
</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper</url>
|
||||
</scm>
|
||||
<issueManagement>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<io.spring.maven.antora-version>0.0.3</io.spring.maven.antora-version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>spring-cloud-zookeeper-dependencies</module>
|
||||
<module>spring-cloud-zookeeper-core</module>
|
||||
<module>spring-cloud-zookeeper-config</module>
|
||||
<module>spring-cloud-zookeeper-discovery</module>
|
||||
<module>spring-cloud-starter-zookeeper</module>
|
||||
<module>spring-cloud-starter-zookeeper-config</module>
|
||||
<module>spring-cloud-starter-zookeeper-discovery</module>
|
||||
<module>spring-cloud-starter-zookeeper-all</module>
|
||||
<module>spring-cloud-zookeeper-sample</module>
|
||||
<module>docs</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
<include>**/*Spec.*</include>
|
||||
<include>**/*Tests.*</include>
|
||||
<include>**/*Test.*</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*Spec.*</exclude>
|
||||
<exclude>**/Abstract*Tests.*</exclude>
|
||||
<exclude>**/Abstract*Test.*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<groupId>io.spring.maven.antora</groupId>
|
||||
<artifactId>antora-maven-plugin</artifactId>
|
||||
<version>${io.spring.maven.antora-version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<options>
|
||||
<option>--to-dir=target/antora/site</option>
|
||||
<option>--stacktrace</option>
|
||||
<option>--fetch</option>
|
||||
</options>
|
||||
<environment>
|
||||
<ALGOLIA_API_KEY>9d489079e5ec46dbb238909fee5c9c29</ALGOLIA_API_KEY>
|
||||
<ALGOLIA_APP_ID>WB1FQYI187</ALGOLIA_APP_ID>
|
||||
<ALGOLIA_INDEX_NAME>springcloudzookeeper</ALGOLIA_INDEX_NAME>
|
||||
</environment>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-dependencies</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>1.7.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.toomuchcoding.jsonassert</groupId>
|
||||
<artifactId>jsonassert</artifactId>
|
||||
<version>0.4.14</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons-dependencies</artifactId>
|
||||
<version>${spring-cloud-commons.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-dependencies</artifactId>
|
||||
<version>${spring-cloud-config.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-openfeign-dependencies</artifactId>
|
||||
<version>${spring-cloud-openfeign.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<version>${spring-cloud-commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mockserver</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mock-server</groupId>
|
||||
<artifactId>mockserver-client-java</artifactId>
|
||||
<version>${mockserverclient.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<spring-cloud-build.version>4.1.0-SNAPSHOT</spring-cloud-build.version>
|
||||
<spring-cloud-commons.version>4.1.0-SNAPSHOT</spring-cloud-commons.version>
|
||||
<spring-cloud-config.version>4.1.0-SNAPSHOT</spring-cloud-config.version>
|
||||
<spring-cloud-openfeign.version>4.1.0-SNAPSHOT</spring-cloud-openfeign.version>
|
||||
<testcontainers.version>1.17.6</testcontainers.version>
|
||||
<mockserverclient.version>5.15.0</mockserverclient.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>spring</id>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshot</id>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestone</id>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/2021.0.x/runAcceptanceTests.sh"
|
||||
AT_WHAT_TO_TEST="ZOOKEEPER"
|
||||
|
||||
curl "${SCRIPT_URL}" --output runAcceptanceTests.sh
|
||||
|
||||
chmod +x runAcceptanceTests.sh
|
||||
|
||||
./runAcceptanceTests.sh --whattotest "${AT_WHAT_TO_TEST}" --killattheend
|
||||
113
spring-cloud-starter-zookeeper-all/.flattened-pom.xml
Normal file
113
spring-cloud-starter-zookeeper-all/.flattened-pom.xml
Normal file
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Starter Zookeeper All</name>
|
||||
<description>Spring Cloud Starter Zookeeper All</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-all</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-all</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-starter-zookeeper-all</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
|
||||
<name>Spring Cloud Starter Zookeeper All</name>
|
||||
<description>Spring Cloud Starter Zookeeper All</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
129
spring-cloud-starter-zookeeper-config/.flattened-pom.xml
Normal file
129
spring-cloud-starter-zookeeper-config/.flattened-pom.xml
Normal file
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Starter Zookeeper Config</name>
|
||||
<description>Spring Cloud Starter Zookeeper Config</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-config</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-config</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-starter-zookeeper-config</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-config</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>
|
||||
<name>Spring Cloud Starter Zookeeper Config</name>
|
||||
<description>Spring Cloud Starter Zookeeper Config</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
135
spring-cloud-starter-zookeeper-discovery/.flattened-pom.xml
Normal file
135
spring-cloud-starter-zookeeper-discovery/.flattened-pom.xml
Normal file
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Starter Zookeeper Discovery</name>
|
||||
<description>Spring Cloud Starter Zookeeper Discovery</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-discovery</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper-discovery</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-starter-zookeeper-discovery</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-discovery</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<name>Spring Cloud Starter Zookeeper Discovery</name>
|
||||
<description>Spring Cloud Starter Zookeeper Discovery</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
113
spring-cloud-starter-zookeeper/.flattened-pom.xml
Normal file
113
spring-cloud-starter-zookeeper/.flattened-pom.xml
Normal file
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Starter Zookeeper</name>
|
||||
<description>Spring Cloud Starter Zookeeper</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-starter-zookeeper</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-starter-zookeeper</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-zookeeper</artifactId>
|
||||
<name>Spring Cloud Starter Zookeeper</name>
|
||||
<description>Spring Cloud Starter Zookeeper</description>
|
||||
<url>https://projects.spring.io/spring-cloud</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<main.basedir>${basedir}/../..</main.basedir>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
181
spring-cloud-zookeeper-config/.flattened-pom.xml
Normal file
181
spring-cloud-zookeeper-config/.flattened-pom.xml
Normal file
@@ -0,0 +1,181 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-config</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Zookeeper Config</name>
|
||||
<description>Spring Cloud Zookeeper Config</description>
|
||||
<url>https://spring.io/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-config</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-config</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-config</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-config</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,95 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-zookeeper-config</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Zookeeper Config</name>
|
||||
<description>Spring Cloud Zookeeper Config</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-context</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
|
||||
/**
|
||||
* A {@link EnumerablePropertySource} that has a notion of a context which is the root
|
||||
* folder in Zookeeper.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public abstract class AbstractZookeeperPropertySource
|
||||
extends EnumerablePropertySource<CuratorFramework> {
|
||||
|
||||
private String context;
|
||||
|
||||
public AbstractZookeeperPropertySource(String context, CuratorFramework source) {
|
||||
super(context, source);
|
||||
this.context = context;
|
||||
if (!this.context.startsWith("/")) {
|
||||
this.context = "/" + this.context;
|
||||
}
|
||||
}
|
||||
|
||||
protected String sanitizeKey(String path) {
|
||||
return path.replace(this.context + "/", "").replace('/', '.');
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.recipes.cache.TreeCache;
|
||||
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
|
||||
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
|
||||
import org.springframework.cloud.endpoint.event.RefreshEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
|
||||
import static org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type.NODE_ADDED;
|
||||
import static org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type.NODE_REMOVED;
|
||||
import static org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type.NODE_UPDATED;
|
||||
|
||||
/**
|
||||
* Class that registers a {@link TreeCache} for each context. It publishes events upon
|
||||
* element change in Zookeeper.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ConfigWatcher
|
||||
implements Closeable, TreeCacheListener, ApplicationEventPublisherAware {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConfigWatcher.class);
|
||||
|
||||
private AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private List<String> contexts;
|
||||
|
||||
private CuratorFramework source;
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
private HashMap<String, TreeCache> caches;
|
||||
|
||||
public ConfigWatcher(List<String> contexts, CuratorFramework source) {
|
||||
this.contexts = contexts;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
|
||||
this.publisher = publisher;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
if (this.running.compareAndSet(false, true)) {
|
||||
this.caches = new HashMap<>();
|
||||
for (String context : this.contexts) {
|
||||
if (!context.startsWith("/")) {
|
||||
context = "/" + context;
|
||||
}
|
||||
try {
|
||||
TreeCache cache = TreeCache.newBuilder(this.source, context).build();
|
||||
cache.getListenable().addListener(this);
|
||||
cache.start();
|
||||
this.caches.put(context, cache);
|
||||
// no race condition since ZookeeperAutoConfiguration.curatorFramework
|
||||
// calls curator.blockUntilConnected
|
||||
}
|
||||
catch (KeeperException.NoNodeException e) {
|
||||
// no node, ignore
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Error initializing listener for context " + context, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (this.running.compareAndSet(true, false)) {
|
||||
for (TreeCache cache : this.caches.values()) {
|
||||
cache.close();
|
||||
}
|
||||
this.caches = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void childEvent(CuratorFramework client, TreeCacheEvent event)
|
||||
throws Exception {
|
||||
TreeCacheEvent.Type eventType = event.getType();
|
||||
if (eventType == NODE_ADDED || eventType == NODE_REMOVED
|
||||
|| eventType == NODE_UPDATED) {
|
||||
this.publisher
|
||||
.publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
|
||||
}
|
||||
}
|
||||
|
||||
public String getEventDesc(TreeCacheEvent event) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append("type=").append(event.getType());
|
||||
out.append(", path=").append(event.getData().getPath());
|
||||
byte[] data = event.getData().getData();
|
||||
if (data != null && data.length > 0) {
|
||||
out.append(", data=").append(new String(data, Charset.forName("UTF-8")));
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.drivers.TracerDriver;
|
||||
import org.apache.curator.ensemble.EnsembleProvider;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.BootstrapContext;
|
||||
import org.springframework.boot.BootstrapRegistry;
|
||||
import org.springframework.boot.BootstrapRegistryInitializer;
|
||||
import org.springframework.cloud.zookeeper.CuratorFrameworkCustomizer;
|
||||
|
||||
public class ZookeeperBootstrapper implements BootstrapRegistryInitializer {
|
||||
|
||||
private Function<BootstrapContext, RetryPolicy> retryPolicy;
|
||||
|
||||
private Function<BootstrapContext, EnsembleProvider> ensembleProvider;
|
||||
|
||||
private Function<BootstrapContext, TracerDriver> tracerDriver;
|
||||
|
||||
private Function<BootstrapContext, CuratorFrameworkCustomizer> curatorFrameworkCustomizer;
|
||||
|
||||
static BootstrapRegistryInitializer fromBootstrapContext(Function<BootstrapContext, CuratorFramework> factory) {
|
||||
return registry -> registry.register(CuratorFramework.class, factory::apply);
|
||||
}
|
||||
|
||||
static ZookeeperBootstrapper create() {
|
||||
return new ZookeeperBootstrapper();
|
||||
}
|
||||
|
||||
public ZookeeperBootstrapper retryPolicy(Function<BootstrapContext, RetryPolicy> retryPolicy) {
|
||||
this.retryPolicy = retryPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ZookeeperBootstrapper ensembleProvider(Function<BootstrapContext, EnsembleProvider> ensembleProvider) {
|
||||
this.ensembleProvider = ensembleProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ZookeeperBootstrapper tracerDriver(Function<BootstrapContext, TracerDriver> tracerDriver) {
|
||||
this.tracerDriver = tracerDriver;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ZookeeperBootstrapper curatorFrameworkCustomizer(Function<BootstrapContext, CuratorFrameworkCustomizer> curatorFrameworkCustomizer) {
|
||||
this.curatorFrameworkCustomizer = curatorFrameworkCustomizer;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(BootstrapRegistry registry) {
|
||||
register(registry, RetryPolicy.class, retryPolicy);
|
||||
register(registry, EnsembleProvider.class, ensembleProvider);
|
||||
register(registry, TracerDriver.class, tracerDriver);
|
||||
register(registry, CuratorFrameworkCustomizer.class, curatorFrameworkCustomizer);
|
||||
}
|
||||
|
||||
private <T> void register(BootstrapRegistry registry, Class<T> type, Function<BootstrapContext, T> factory) {
|
||||
if (this.retryPolicy != null) {
|
||||
registry.register(type, factory::apply);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.endpoint.RefreshEndpoint;
|
||||
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-configuration} that registers a Zookeeper configuration watcher.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnZookeeperEnabled
|
||||
@ConditionalOnProperty(value = "spring.cloud.zookeeper.config.enabled", matchIfMissing = true)
|
||||
public class ZookeeperConfigAutoConfiguration {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(RefreshEndpoint.class)
|
||||
@ConditionalOnProperty(name = "spring.cloud.zookeeper.config.watcher.enabled", matchIfMissing = true)
|
||||
protected static class ZkRefreshConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(ZookeeperPropertySourceLocator.class)
|
||||
public ConfigWatcher propertySourceLocatorConfigWatcher(ZookeeperPropertySourceLocator locator,
|
||||
CuratorFramework curator) {
|
||||
return new ConfigWatcher(locator.getContexts(), curator);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ZookeeperPropertySourceLocator.class)
|
||||
public ConfigWatcher configDataConfigWatcher(CuratorFramework curator, Environment env) {
|
||||
List<String> contexts = env.getProperty("spring.cloud.zookeeper.config.property-source-contexts",
|
||||
List.class, Collections.emptyList());
|
||||
return new ConfigWatcher(contexts, curator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
|
||||
import org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Bootstrap Configuration for Zookeeper Configuration.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnZookeeperEnabled
|
||||
@Import(ZookeeperAutoConfiguration.class)
|
||||
public class ZookeeperConfigBootstrapConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ZookeeperPropertySourceLocator zookeeperPropertySourceLocator(
|
||||
CuratorFramework curator, ZookeeperConfigProperties properties) {
|
||||
return new ZookeeperPropertySourceLocator(curator, properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ZookeeperConfigProperties zookeeperConfigProperties(Environment env) {
|
||||
ZookeeperConfigProperties properties = new ZookeeperConfigProperties();
|
||||
if (!StringUtils.hasLength(properties.getName())) {
|
||||
properties.setName(env.getProperty("spring.application.name", "application"));
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigData;
|
||||
import org.springframework.boot.context.config.ConfigDataLoader;
|
||||
import org.springframework.boot.context.config.ConfigDataLoaderContext;
|
||||
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
|
||||
import org.springframework.boot.logging.DeferredLogFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class ZookeeperConfigDataLoader implements ConfigDataLoader<ZookeeperConfigDataResource> {
|
||||
|
||||
private final Log log;
|
||||
|
||||
public ZookeeperConfigDataLoader(DeferredLogFactory logFactory) {
|
||||
this.log = logFactory.getLog(ZookeeperConfigDataLoader.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataResource resource) {
|
||||
try {
|
||||
CuratorFramework curator = context.getBootstrapContext().get(CuratorFramework.class);
|
||||
if (curator == null) {
|
||||
// this can happen if certain conditions are met
|
||||
return null;
|
||||
}
|
||||
ZookeeperPropertySource propertySource = new ZookeeperPropertySource(resource.getContext(),
|
||||
curator);
|
||||
List<ZookeeperPropertySource> propertySources = Collections.singletonList(propertySource);
|
||||
|
||||
return new ConfigData(propertySources, source -> {
|
||||
List<ConfigData.Option> options = new ArrayList<>();
|
||||
options.add(ConfigData.Option.IGNORE_IMPORTS);
|
||||
options.add(ConfigData.Option.IGNORE_PROFILES);
|
||||
if (StringUtils.hasText(resource.getProfile())) {
|
||||
options.add(ConfigData.Option.PROFILE_SPECIFIC);
|
||||
}
|
||||
return ConfigData.Options.of(options.toArray(new ConfigData.Option[0]));
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Error getting properties from zookeeper: " + resource, e);
|
||||
}
|
||||
throw new ConfigDataResourceNotFoundException(resource, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
|
||||
import org.springframework.boot.context.config.ConfigDataLocation;
|
||||
import org.springframework.boot.context.config.ConfigDataLocationNotFoundException;
|
||||
import org.springframework.boot.context.config.ConfigDataLocationResolver;
|
||||
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
|
||||
import org.springframework.boot.context.config.Profiles;
|
||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.logging.DeferredLogFactory;
|
||||
import org.springframework.cloud.zookeeper.CuratorFactory;
|
||||
import org.springframework.cloud.zookeeper.ZookeeperProperties;
|
||||
import org.springframework.cloud.zookeeper.config.ZookeeperPropertySources.Context;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
public class ZookeeperConfigDataLocationResolver implements ConfigDataLocationResolver<ZookeeperConfigDataResource> {
|
||||
|
||||
/**
|
||||
* Zookeeper Config Data prefix.
|
||||
*/
|
||||
public static final String PREFIX = "zookeeper:";
|
||||
|
||||
private final Log log;
|
||||
|
||||
public ZookeeperConfigDataLocationResolver(DeferredLogFactory logFactory) {
|
||||
this.log = logFactory.getLog(ZookeeperConfigDataLocationResolver.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResolvable(ConfigDataLocationResolverContext context, ConfigDataLocation location) {
|
||||
if (!location.hasPrefix(PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
// only bind on correct prefix
|
||||
boolean zkEnabled = context.getBinder().bind(ZookeeperProperties.PREFIX + ".enabled", Boolean.class)
|
||||
.orElse(true);
|
||||
boolean zkConfigEnabled = context.getBinder().bind(ZookeeperConfigProperties.PREFIX + ".enabled", Boolean.class)
|
||||
.orElse(true);
|
||||
return zkConfigEnabled && zkEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ZookeeperConfigDataResource> resolve(ConfigDataLocationResolverContext context, ConfigDataLocation location)
|
||||
throws ConfigDataLocationNotFoundException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ZookeeperConfigDataResource> resolveProfileSpecific(ConfigDataLocationResolverContext context,
|
||||
ConfigDataLocation location, Profiles profiles) throws ConfigDataLocationNotFoundException {
|
||||
UriComponents locationUri = parseLocation(location);
|
||||
|
||||
// create curator
|
||||
CuratorFactory.registerCurator(context.getBootstrapContext(), locationUri, location.isOptional());
|
||||
|
||||
// create locations
|
||||
ZookeeperConfigProperties properties = loadConfigProperties(context);
|
||||
context.getBootstrapContext().register(ZookeeperConfigProperties.class, InstanceSupplier.of(properties));
|
||||
|
||||
ZookeeperPropertySources sources = new ZookeeperPropertySources(properties, log);
|
||||
|
||||
List<Context> contexts = (locationUri == null || CollectionUtils.isEmpty(locationUri.getPathSegments()))
|
||||
? sources.generateAutomaticContexts(profiles.getAccepted(), false) : getCustomContexts(locationUri);
|
||||
|
||||
// promote beans to context
|
||||
context.getBootstrapContext().addCloseListener(event -> {
|
||||
HashMap<String, Object> source = new HashMap<>();
|
||||
source.put("spring.cloud.zookeeper.config.property-source-contexts", contexts.stream().map(Context::getPath).collect(Collectors.toList()));
|
||||
MapPropertySource propertySource = new MapPropertySource("zookeeperConfigData", source);
|
||||
event.getApplicationContext().getEnvironment().getPropertySources().addFirst(propertySource);
|
||||
});
|
||||
|
||||
ArrayList<ZookeeperConfigDataResource> locations = new ArrayList<>();
|
||||
contexts.forEach(propertySourceContext -> locations
|
||||
.add(new ZookeeperConfigDataResource(propertySourceContext.getPath(), location.isOptional(), propertySourceContext
|
||||
.getProfile())));
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
private BindHandler getBindHandler(ConfigDataLocationResolverContext context) {
|
||||
return context.getBootstrapContext().getOrElse(BindHandler.class, null);
|
||||
}
|
||||
|
||||
protected List<Context> getCustomContexts(UriComponents uriComponents) {
|
||||
if (!StringUtils.hasLength(uriComponents.getPath())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.stream(uriComponents.getPath().split(";")).map(Context::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected UriComponents parseLocation(ConfigDataLocation location) {
|
||||
String originalUri = location.getNonPrefixedValue(PREFIX);
|
||||
if (!StringUtils.hasText(originalUri)) {
|
||||
return null;
|
||||
}
|
||||
String uri;
|
||||
if (!originalUri.startsWith("//")) {
|
||||
uri = PREFIX + "//" + originalUri;
|
||||
}
|
||||
else {
|
||||
uri = originalUri;
|
||||
}
|
||||
return UriComponentsBuilder.fromUriString(uri).build();
|
||||
}
|
||||
|
||||
protected ZookeeperConfigProperties loadConfigProperties(ConfigDataLocationResolverContext context) {
|
||||
Binder binder = context.getBinder();
|
||||
BindHandler bindHandler = getBindHandler(context);
|
||||
ZookeeperConfigProperties properties = binder
|
||||
.bind(ZookeeperConfigProperties.PREFIX, Bindable.of(ZookeeperConfigProperties.class), bindHandler)
|
||||
.orElseGet(ZookeeperConfigProperties::new);
|
||||
|
||||
if (!StringUtils.hasLength(properties.getName())) {
|
||||
properties.setName(binder.bind("spring.application.name", Bindable.of(String.class), bindHandler).orElse("application"));
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor;
|
||||
import org.springframework.cloud.zookeeper.ZookeeperProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.springframework.cloud.util.PropertyUtils.bootstrapEnabled;
|
||||
import static org.springframework.cloud.util.PropertyUtils.useLegacyProcessing;
|
||||
import static org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLocationResolver.PREFIX;
|
||||
|
||||
public class ZookeeperConfigDataMissingEnvironmentPostProcessor extends ConfigDataMissingEnvironmentPostProcessor {
|
||||
|
||||
/**
|
||||
* Order of post processor, set to run after
|
||||
* {@link ConfigDataEnvironmentPostProcessor}.
|
||||
*/
|
||||
public static final int ORDER = ConfigDataEnvironmentPostProcessor.ORDER + 1000;
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return ORDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldProcessEnvironment(Environment environment) {
|
||||
// don't run if using bootstrap or legacy processing
|
||||
if (bootstrapEnabled(environment) || useLegacyProcessing(environment)) {
|
||||
return false;
|
||||
}
|
||||
boolean coreEnabled = environment.getProperty(ZookeeperProperties.PREFIX + ".enabled", Boolean.class,
|
||||
true);
|
||||
boolean configEnabled = environment.getProperty(ZookeeperConfigProperties.PREFIX + ".enabled", Boolean.class,
|
||||
true);
|
||||
boolean importCheckEnabled = environment.getProperty(ZookeeperConfigProperties.PREFIX + ".import-check.enabled",
|
||||
Boolean.class, true);
|
||||
if (!coreEnabled || !configEnabled || !importCheckEnabled) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPrefix() {
|
||||
return PREFIX;
|
||||
}
|
||||
|
||||
static class ImportExceptionFailureAnalyzer extends AbstractFailureAnalyzer<ImportException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, ImportException cause) {
|
||||
String description;
|
||||
if (cause.missingPrefix) {
|
||||
description = "The spring.config.import property is missing a " + PREFIX + " entry";
|
||||
}
|
||||
else {
|
||||
description = "No spring.config.import property has been defined";
|
||||
}
|
||||
String action = "Add a spring.config.import=zookeeper: property to your configuration.\n"
|
||||
+ "\tIf configuration is not required add spring.config.import=optional:zookeeper: instead.\n"
|
||||
+ "\tTo disable this check, set spring.cloud.zookeeper.config.enabled=false or \n"
|
||||
+ "\tspring.cloud.zookeeper.config.import-check.enabled=false.";
|
||||
return new FailureAnalysis(description, action, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigDataResource;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
public class ZookeeperConfigDataResource extends ConfigDataResource {
|
||||
|
||||
private final String context;
|
||||
private final boolean optional;
|
||||
private final String profile;
|
||||
|
||||
public ZookeeperConfigDataResource(String context, boolean optional, String profile) {
|
||||
this.context = context;
|
||||
this.optional = optional;
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ZookeeperConfigDataResource(String context, boolean optional) {
|
||||
this(context, optional, null);
|
||||
}
|
||||
|
||||
public String getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return this.optional;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ZookeeperConfigDataResource that = (ZookeeperConfigDataResource) o;
|
||||
return this.optional == that.optional && this.context.equals(that.context) && Objects.equals(this.profile, that.profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.optional, this.context, this.profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("context", context)
|
||||
.append("optional", optional)
|
||||
.append("profile", profile)
|
||||
.toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Properties related to keeping configuration in Zookeeper.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
* @see ZookeeperPropertySourceLocator
|
||||
*/
|
||||
@ConfigurationProperties(ZookeeperConfigProperties.PREFIX)
|
||||
public class ZookeeperConfigProperties {
|
||||
|
||||
/**
|
||||
* Configuration prefix for config properties.
|
||||
*/
|
||||
public static final String PREFIX = "spring.cloud.zookeeper.config";
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Root folder where the configuration for Zookeeper is kept.
|
||||
*/
|
||||
private String root = "config";
|
||||
|
||||
/**
|
||||
* Alternative to spring.application.name to use in looking up values in zookeeper.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The name of the default context.
|
||||
*/
|
||||
private String defaultContext = "application";
|
||||
|
||||
/**
|
||||
* Separator for profile appended to the application name.
|
||||
*/
|
||||
private String profileSeparator = ",";
|
||||
|
||||
/**
|
||||
* Throw exceptions during config lookup if true, otherwise, log warnings.
|
||||
*/
|
||||
private boolean failFast = true;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getRoot() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
public void setRoot(String root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDefaultContext() {
|
||||
return this.defaultContext;
|
||||
}
|
||||
|
||||
public void setDefaultContext(String defaultContext) {
|
||||
Assert.hasText(defaultContext, "spring.cloud.zookeeper.config.default-context may not be empty");
|
||||
this.defaultContext = defaultContext;
|
||||
}
|
||||
|
||||
public String getProfileSeparator() {
|
||||
return this.profileSeparator;
|
||||
}
|
||||
|
||||
public void setProfileSeparator(String profileSeparator) {
|
||||
Assert.hasText(profileSeparator, "spring.cloud.zookeeper.config.profile-separator may not be empty");
|
||||
this.profileSeparator = profileSeparator;
|
||||
}
|
||||
|
||||
public boolean isFailFast() {
|
||||
return this.failFast;
|
||||
}
|
||||
|
||||
public void setFailFast(boolean failFast) {
|
||||
this.failFast = failFast;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("enabled", enabled)
|
||||
.append("root", root)
|
||||
.append("name", name)
|
||||
.append("defaultContext", defaultContext)
|
||||
.append("profileSeparator", profileSeparator)
|
||||
.append("failFast", failFast)
|
||||
.toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.core.env.PropertySource} that stores properties from
|
||||
* Zookeeper inside a map. Properties are loaded upon class initialization.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ZookeeperPropertySource extends AbstractZookeeperPropertySource {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZookeeperPropertySource.class);
|
||||
|
||||
private Map<String, String> properties = new LinkedHashMap<>();
|
||||
|
||||
public ZookeeperPropertySource(String context, CuratorFramework source) {
|
||||
super(context, source);
|
||||
findProperties(this.getContext(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String name) {
|
||||
return this.properties.get(name);
|
||||
}
|
||||
|
||||
private byte[] getPropertyBytes(String fullPath) {
|
||||
try {
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
bytes = this.getSource().getData().forPath(fullPath);
|
||||
}
|
||||
catch (KeeperException e) {
|
||||
if (e.code() != KeeperException.Code.NONODE) { // not found
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
ReflectionUtils.rethrowRuntimeException(exception);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPropertyNames() {
|
||||
Set<String> strings = this.properties.keySet();
|
||||
return strings.toArray(new String[strings.size()]);
|
||||
}
|
||||
|
||||
private void findProperties(String path, List<String> children) {
|
||||
try {
|
||||
log.trace("entering findProperties for path: " + path);
|
||||
if (children == null) {
|
||||
children = getChildren(path);
|
||||
}
|
||||
if (children == null || children.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (String child : children) {
|
||||
String childPath = path + "/" + child;
|
||||
List<String> childPathChildren = getChildren(childPath);
|
||||
|
||||
byte[] bytes = getPropertyBytes(childPath);
|
||||
if (bytes == null || bytes.length == 0) {
|
||||
if (childPathChildren == null || childPathChildren.isEmpty()) {
|
||||
registerKeyValue(childPath, "");
|
||||
}
|
||||
}
|
||||
else {
|
||||
registerKeyValue(childPath,
|
||||
new String(bytes, Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
// Check children even if we have found a value for the current znode
|
||||
findProperties(childPath, childPathChildren);
|
||||
}
|
||||
log.trace("leaving findProperties for path: " + path);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
ReflectionUtils.rethrowRuntimeException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerKeyValue(String path, String value) {
|
||||
String key = sanitizeKey(path);
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
|
||||
private List<String> getChildren(String path) throws Exception {
|
||||
List<String> children = null;
|
||||
try {
|
||||
children = this.getSource().getChildren().forPath(path);
|
||||
}
|
||||
catch (KeeperException e) {
|
||||
if (e.code() != KeeperException.Code.NONODE) { // not found
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Zookeeper provides a <a href=
|
||||
* "https://zookeeper.apache.org/doc/current/zookeeperOver.html#sc_dataModelNameSpace">hierarchical
|
||||
* namespace</a> that allows clients to store arbitrary data, such as configuration data.
|
||||
* Spring Cloud Zookeeper Config is an alternative to the
|
||||
* <a href="https://github.com/spring-cloud/spring-cloud-config">Config Server and
|
||||
* Client</a>. Configuration is loaded into the Spring Environment during the special
|
||||
* "bootstrap" phase. Configuration is stored in the {@code /config} namespace by default.
|
||||
* Multiple {@code PropertySource} instances are created based on the application's name
|
||||
* and the active profiles that mimicks the Spring Cloud Config order of resolving
|
||||
* properties. For example, an application with the name "testApp" and with the "dev"
|
||||
* profile will have the following property sources created:
|
||||
*
|
||||
* <pre>{@code
|
||||
* config/testApp,dev
|
||||
* config/testApp
|
||||
* config/application,dev
|
||||
* config/application
|
||||
* }</pre>
|
||||
*
|
||||
* The most specific property source is at the top, with the least specific at the bottom.
|
||||
* Properties is the {@code config/application} namespace are applicable to all
|
||||
* applications using zookeeper for configuration. Properties in the
|
||||
* {@code config/testApp} namespace are only available to the instances of the service
|
||||
* named "testApp".
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
|
||||
|
||||
private ZookeeperConfigProperties properties;
|
||||
|
||||
private CuratorFramework curator;
|
||||
|
||||
private List<String> contexts;
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ZookeeperPropertySourceLocator.class);
|
||||
|
||||
public ZookeeperPropertySourceLocator(CuratorFramework curator,
|
||||
ZookeeperConfigProperties properties) {
|
||||
this.curator = curator;
|
||||
Assert.hasText(properties.getName(), ZookeeperConfigProperties.PREFIX + ".name must not be empty");
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public List<String> getContexts() {
|
||||
return this.contexts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertySource<?> locate(Environment environment) {
|
||||
if (environment instanceof ConfigurableEnvironment) {
|
||||
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
|
||||
|
||||
List<String> profiles = Arrays.asList(env.getActiveProfiles());
|
||||
|
||||
ZookeeperPropertySources sources = new ZookeeperPropertySources(properties, log);
|
||||
this.contexts = sources.getAutomaticContexts(profiles);
|
||||
|
||||
CompositePropertySource composite = new CompositePropertySource("zookeeper");
|
||||
|
||||
for (String propertySourceContext : this.contexts) {
|
||||
PropertySource<CuratorFramework> propertySource = sources.createPropertySource(propertySourceContext, true, this.curator);
|
||||
composite.addPropertySource(propertySource);
|
||||
}
|
||||
|
||||
return composite;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
private PropertySource<CuratorFramework> create(String context) {
|
||||
return new ZookeeperPropertySource(context, this.curator);
|
||||
}
|
||||
|
||||
private void addProfiles(List<String> contexts, String baseContext,
|
||||
List<String> profiles) {
|
||||
for (String profile : profiles) {
|
||||
contexts.add(baseContext + this.properties.getProfileSeparator() + profile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
public class ZookeeperPropertySources {
|
||||
private final ZookeeperConfigProperties properties;
|
||||
private final Log log;
|
||||
|
||||
public ZookeeperPropertySources(ZookeeperConfigProperties properties, Log log) {
|
||||
this.properties = properties;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public List<String> getAutomaticContexts(List<String> profiles) {
|
||||
return getAutomaticContexts(profiles, true);
|
||||
}
|
||||
|
||||
public List<String> getAutomaticContexts(List<String> profiles, boolean reverse) {
|
||||
return generateAutomaticContexts(profiles, reverse).stream().map(Context::getPath).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Context> generateAutomaticContexts(List<String> profiles, boolean reverse) {
|
||||
List<Context> contexts = new ArrayList<>();
|
||||
String root = properties.getRoot();
|
||||
|
||||
String defaultContext = root + "/" + properties.getDefaultContext();
|
||||
contexts.add(new Context(defaultContext));
|
||||
addProfiles(contexts, defaultContext, profiles);
|
||||
|
||||
StringBuilder baseContext = new StringBuilder(root);
|
||||
if (!properties.getName().startsWith("/")) {
|
||||
baseContext.append("/");
|
||||
}
|
||||
// getName() defaults to ${spring.application.name} or application
|
||||
baseContext.append(properties.getName());
|
||||
contexts.add(new Context(baseContext.toString()));
|
||||
addProfiles(contexts, baseContext.toString(), profiles);
|
||||
|
||||
if (reverse) {
|
||||
Collections.reverse(contexts);
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private void addProfiles(List<Context> contexts, String baseContext, List<String> profiles) {
|
||||
for (String profile : profiles) {
|
||||
String path = baseContext + properties.getProfileSeparator() + profile;
|
||||
contexts.add(new Context(path, profile));
|
||||
}
|
||||
}
|
||||
|
||||
public ZookeeperPropertySource createPropertySource(String context, boolean optional, CuratorFramework curator) {
|
||||
try {
|
||||
return new ZookeeperPropertySource(context, curator);
|
||||
// TODO: howto call close when /refresh
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (this.properties.isFailFast() || !optional) {
|
||||
throw new ZookeeperPropertySourceNotFoundException(e);
|
||||
}
|
||||
else {
|
||||
log.warn("Unable to load zookeeper config from " + context, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static class Context {
|
||||
|
||||
private final String path;
|
||||
|
||||
private final String profile;
|
||||
|
||||
public Context(String path) {
|
||||
this.path = path;
|
||||
this.profile = null;
|
||||
}
|
||||
|
||||
public Context(String path, String profile) {
|
||||
this.path = path;
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return this.profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("path", path).append("profile", profile).toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class ZookeeperPropertySourceNotFoundException extends RuntimeException {
|
||||
|
||||
ZookeeperPropertySourceNotFoundException(Exception source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
# Bootstrap Configuration
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigBootstrapConfiguration
|
||||
|
||||
# Environment PostProcessor
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigDataMissingEnvironmentPostProcessor
|
||||
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigDataMissingEnvironmentPostProcessor.ImportExceptionFailureAnalyzer
|
||||
|
||||
# ConfigData Location Resolvers
|
||||
org.springframework.boot.context.config.ConfigDataLocationResolver=\
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLocationResolver
|
||||
|
||||
# ConfigData Loaders
|
||||
org.springframework.boot.context.config.ConfigDataLoader=\
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLoader
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.cloud.zookeeper.config.ZookeeperConfigAutoConfiguration
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Cesar Aguilera
|
||||
*/
|
||||
public class ZookeeperConfigAutoConfigurationTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
expectedException = ExpectedException.none();
|
||||
// makes Curator fail faster, otherwise it takes 15 seconds to trigger a retry
|
||||
System.setProperty("curator-default-connection-timeout", "0");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.clearProperty("curator-default-connection-timeout");
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void testConfigEnabledFalseDoesNotLoadZookeeperConfigAutoConfiguration() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.sources(Config.class).web(WebApplicationType.NONE)
|
||||
.run("--spring.application.name=testZookeeperConfigEnabledSetToFalse",
|
||||
"--spring.config.use-legacy-processing=true",
|
||||
"--spring.jmx.default-domain=testZookeeperConfigEnabledSetToFalse",
|
||||
"--spring.cloud.zookeeper.config.connectString=localhost:2188",
|
||||
"--spring.cloud.zookeeper.baseSleepTimeMs=0",
|
||||
"--spring.cloud.zookeeper.maxRetries=0",
|
||||
"--spring.cloud.zookeeper.maxSleepMs=0",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedWait=0",
|
||||
"--spring.cloud.zookeeper.config.failFast=false",
|
||||
"--spring.cloud.zookeeper.config.enabled=false");
|
||||
|
||||
context.getBean(ZookeeperConfigAutoConfiguration.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigEnabledTrueLoadsZookeeperConfigAutoConfiguration()
|
||||
throws Exception {
|
||||
expectedException.expectCause(Matchers.isA(KeeperException.class));
|
||||
|
||||
new SpringApplicationBuilder().sources(Config.class).web(WebApplicationType.NONE)
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.run("--spring.application.name=testZookeeperConfigEnabledSetToTrue",
|
||||
"--spring.config.use-legacy-processing=true",
|
||||
"--spring.jmx.default-domain=testZookeeperConfigEnabledSetToTrue",
|
||||
"--spring.cloud.zookeeper.config.connectString=localhost:2188",
|
||||
"--spring.cloud.zookeeper.baseSleepTimeMs=0",
|
||||
"--spring.cloud.zookeeper.maxRetries=0",
|
||||
"--spring.cloud.zookeeper.maxSleepMs=0",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedWait=0",
|
||||
"--spring.cloud.zookeeper.config.failFast=false",
|
||||
"--spring.cloud.zookeeper.config.enabled=true");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.framework.imps.CuratorFrameworkImpl;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.BootstrapContext;
|
||||
import org.springframework.boot.BootstrapRegistry;
|
||||
import org.springframework.boot.BootstrapRegistryInitializer;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.properties.bind.BindContext;
|
||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
||||
import org.springframework.cloud.zookeeper.CuratorFactory;
|
||||
import org.springframework.cloud.zookeeper.ZookeeperProperties;
|
||||
import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ZookeeperConfigDataCustomizationIntegrationTests {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ZookeeperConfigDataCustomizationIntegrationTests.class);
|
||||
|
||||
public static final String PREFIX = "test__configdata__";
|
||||
|
||||
public static final String ROOT = "/" + PREFIX + UUID.randomUUID();
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
private BindHandlerBootstrapper bindHandlerBootstrapper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
bindHandlerBootstrapper = new BindHandlerBootstrapper();
|
||||
this.context = new SpringApplicationBuilder(Config.class)
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.web(WebApplicationType.NONE)
|
||||
.addBootstrapRegistryInitializer(bindHandlerBootstrapper)
|
||||
.addBootstrapRegistryInitializer(ZookeeperBootstrapper.fromBootstrapContext(this::curatorFramework))
|
||||
.run("--spring.config.import=zookeeper:",
|
||||
"--spring.application.name=testZkConfigDataIntegration",
|
||||
"--logging.level.org.springframework.cloud.zookeeper=DEBUG",
|
||||
"--spring.cloud.zookeeper.config.root=" + ROOT);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
CuratorFramework curatorFramework(BootstrapContext context) {
|
||||
ZookeeperProperties properties = context.get(ZookeeperProperties.class);
|
||||
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
|
||||
.retryPolicy(CuratorFactory.retryPolicy(properties))
|
||||
.connectString(properties.getConnectString());
|
||||
TestCuratorFramework curator = new TestCuratorFramework(builder);
|
||||
curator.start();
|
||||
try {
|
||||
curator.blockUntilConnected(properties.getBlockUntilConnectedWait(),
|
||||
properties.getBlockUntilConnectedUnit());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
}
|
||||
return curator;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curatorFrameworkIsCustom() {
|
||||
CuratorFramework curator = context.getBean(CuratorFramework.class);
|
||||
assertThat(curator).isNotNull().isInstanceOf(TestCuratorFramework.class);
|
||||
assertThat(bindHandlerBootstrapper.onSuccessCount).isGreaterThan(0);
|
||||
}
|
||||
|
||||
static class TestCuratorFramework extends CuratorFrameworkImpl {
|
||||
TestCuratorFramework(CuratorFrameworkFactory.Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
static class BindHandlerBootstrapper implements BootstrapRegistryInitializer {
|
||||
|
||||
private int onSuccessCount = 0;
|
||||
|
||||
@Override
|
||||
public void initialize(BootstrapRegistry registry) {
|
||||
registry.register(BindHandler.class, context -> new BindHandler() {
|
||||
@Override
|
||||
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context,
|
||||
Object result) {
|
||||
onSuccessCount++;
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.RetryOneTime;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
import org.springframework.cloud.context.refresh.ConfigDataContextRefresher;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ZookeeperConfigDataIntegrationTests {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ZookeeperConfigDataIntegrationTests.class);
|
||||
|
||||
public static final String APPLICATION_NAME = "testZkConfigDataIntegration";
|
||||
|
||||
public static final String PREFIX = "test__configdata__";
|
||||
|
||||
public static final String ROOT = "/" + PREFIX + UUID.randomUUID();
|
||||
|
||||
public static final String CONTEXT = ROOT + "/application/";
|
||||
|
||||
public static final String KEY_BASIC = "testProp";
|
||||
|
||||
public static final String KEY_BASIC_PATH = CONTEXT + KEY_BASIC;
|
||||
|
||||
public static final String KEY_APP_PATH = ROOT + "/" + APPLICATION_NAME + "/" + KEY_BASIC;
|
||||
|
||||
public static final String VAL_BASIC_DEFAULT = "testPropValDefault";
|
||||
|
||||
public static final String VAL_BASIC = "testPropVal";
|
||||
|
||||
public static final String KEY_WITH_DOT = "testProp.dot";
|
||||
|
||||
public static final String KEY_WITH_DOT_PATH = CONTEXT + KEY_WITH_DOT;
|
||||
|
||||
public static final String VAL_WITH_DOT = "withDotVal";
|
||||
|
||||
public static final String KEY_NESTED = "testProp.nested";
|
||||
|
||||
public static final String KEY_NESTED_PATH = CONTEXT + KEY_NESTED.replace('.', '/');
|
||||
|
||||
public static final String VAL_NESTED = "nestedVal";
|
||||
|
||||
public static final String KEY_WITHOUT_VALUE = "testProp.novalue";
|
||||
|
||||
public static final String KEY_WITHOUT_VALUE_PATH = CONTEXT + KEY_WITHOUT_VALUE;
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private CuratorFramework curator;
|
||||
private ZookeeperTestingServer testingServer;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
testingServer = new ZookeeperTestingServer();
|
||||
testingServer.start();
|
||||
String connectString = "localhost:" + testingServer.getPort();
|
||||
this.curator = CuratorFrameworkFactory.builder()
|
||||
.retryPolicy(new RetryOneTime(500)).connectString(connectString).build();
|
||||
this.curator.start();
|
||||
|
||||
List<String> children = this.curator.getChildren().forPath("/");
|
||||
for (String child : children) {
|
||||
if (child.startsWith(PREFIX) && child.length() > PREFIX.length()) {
|
||||
delete("/" + child);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder create = new StringBuilder(1024);
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_BASIC_PATH, VAL_BASIC_DEFAULT.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_APP_PATH, VAL_BASIC.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_WITH_DOT_PATH, VAL_WITH_DOT.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_NESTED_PATH, VAL_NESTED.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_WITHOUT_VALUE_PATH, null)).append('\n');
|
||||
this.curator.close();
|
||||
System.out.println(create);
|
||||
|
||||
this.context = new SpringApplicationBuilder(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.config.import=zookeeper:" + connectString,
|
||||
"--spring.application.name=" + APPLICATION_NAME,
|
||||
"--logging.level.org.springframework.cloud.zookeeper=DEBUG",
|
||||
"--spring.cloud.zookeeper.config.root=" + ROOT);
|
||||
|
||||
this.curator = this.context.getBean(CuratorFramework.class);
|
||||
this.environment = this.context.getEnvironment();
|
||||
}
|
||||
|
||||
public void delete(String path) throws Exception {
|
||||
try {
|
||||
this.curator.delete().deletingChildrenIfNeeded().forPath(path);
|
||||
}
|
||||
catch (KeeperException e) {
|
||||
if (e.code() != KeeperException.Code.NONODE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
try {
|
||||
delete(ROOT);
|
||||
}
|
||||
finally {
|
||||
this.context.close();
|
||||
this.testingServer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkKeyValues() {
|
||||
String propValue = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(propValue).as(KEY_BASIC + " was wrong").isEqualTo(VAL_BASIC);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_NESTED);
|
||||
assertThat(propValue).as(VAL_NESTED + " was wrong").isEqualTo(VAL_NESTED);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_WITH_DOT);
|
||||
assertThat(propValue).as(VAL_WITH_DOT + " was wrong").isEqualTo(VAL_WITH_DOT);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_WITHOUT_VALUE);
|
||||
assertThat(propValue).as(KEY_WITHOUT_VALUE + " was wrong").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyLoadedAndUpdated() throws Exception {
|
||||
String testProp = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(testProp).as("testProp was wrong").isEqualTo(VAL_BASIC);
|
||||
|
||||
this.curator.setData().forPath(KEY_APP_PATH, "testPropValUpdate".getBytes());
|
||||
|
||||
CountDownLatch latch = this.context.getBean(CountDownLatch.class);
|
||||
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
|
||||
assertThat(receivedEvent).as("listener didn't receive event").isTrue();
|
||||
|
||||
testProp = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(testProp).as("testProp was wrong after update")
|
||||
.isEqualTo("testPropValUpdate");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config implements ApplicationListener<EnvironmentChangeEvent> {
|
||||
|
||||
@Bean
|
||||
public CountDownLatch countDownLatch() {
|
||||
return new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
|
||||
RefreshScope scope) {
|
||||
return new ConfigDataContextRefresher(context, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EnvironmentChangeEvent event) {
|
||||
log.debug("Event keys: " + event.getKeys());
|
||||
if (event.getKeys().contains(KEY_BASIC)) {
|
||||
countDownLatch().countDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.ConfigurableBootstrapContext;
|
||||
import org.springframework.boot.context.config.ConfigDataLocation;
|
||||
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
|
||||
import org.springframework.boot.context.config.Profiles;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ZookeeperConfigDataLocationResolverTests {
|
||||
|
||||
@Test
|
||||
public void testParseLocation() {
|
||||
ZookeeperConfigDataLocationResolver resolver = new ZookeeperConfigDataLocationResolver(destination -> LogFactory.getLog(ZookeeperConfigDataLocationResolver.class));
|
||||
UriComponents uriComponents = resolver.parseLocation(
|
||||
ConfigDataLocation.of("zookeeper:myhost:2182/mypath1;/mypath2;/mypath3"));
|
||||
assertThat(uriComponents.toUri()).hasScheme("zookeeper").hasHost("myhost")
|
||||
.hasPort(2182).hasPath("/mypath1;/mypath2;/mypath3");
|
||||
|
||||
uriComponents = resolver.parseLocation(ConfigDataLocation.of("zookeeper:myhost:2182"));
|
||||
assertThat(uriComponents.toUri()).hasScheme("zookeeper").hasHost("myhost")
|
||||
.hasPort(2182).hasPath("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveProfileSpecificWithCustomPaths() {
|
||||
String location = "zookeeper:myhost:2182/mypath1;/mypath2;/mypath3";
|
||||
List<ZookeeperConfigDataResource> locations = testResolveProfileSpecific(location);
|
||||
assertThat(locations).hasSize(3);
|
||||
assertThat(toContexts(locations)).containsExactly("/mypath1", "/mypath2",
|
||||
"/mypath3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveProfileSpecificWithAutomaticPaths() {
|
||||
String location = "zookeeper:myhost:1234";
|
||||
List<ZookeeperConfigDataResource> locations = testResolveProfileSpecific(location);
|
||||
assertThat(locations).hasSize(4);
|
||||
assertThat(toContexts(locations)).containsExactly("config/application",
|
||||
"config/application,dev", "config/testapp", "config/testapp,dev");
|
||||
}
|
||||
|
||||
private List<String> toContexts(List<ZookeeperConfigDataResource> locations) {
|
||||
return locations.stream().map(ZookeeperConfigDataResource::getContext)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<ZookeeperConfigDataResource> testResolveProfileSpecific(String location) {
|
||||
ZookeeperConfigDataLocationResolver resolver = createResolver();
|
||||
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
env.setProperty("spring.application.name", "testapp");
|
||||
|
||||
ConfigurableBootstrapContext bootstrapContext = mock(ConfigurableBootstrapContext.class);
|
||||
|
||||
ConfigDataLocationResolverContext context = mock(
|
||||
ConfigDataLocationResolverContext.class);
|
||||
|
||||
when(context.getBootstrapContext()).thenReturn(bootstrapContext);
|
||||
when(context.getBinder()).thenReturn(Binder.get(env));
|
||||
|
||||
Profiles profiles = mock(Profiles.class);
|
||||
when(profiles.getAccepted()).thenReturn(Collections.singletonList("dev"));
|
||||
|
||||
return resolver.resolveProfileSpecific(context, ConfigDataLocation.of(location), profiles);
|
||||
}
|
||||
|
||||
private ZookeeperConfigDataLocationResolver createResolver() {
|
||||
return new ZookeeperConfigDataLocationResolver(destination -> LogFactory.getLog(ZookeeperConfigDataLocationResolver.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
class ZookeeperConfigDataMissingEnvironmentPostProcessorTests {
|
||||
|
||||
@Test
|
||||
void noSpringConfigImport() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatThrownBy(() -> processor.postProcessEnvironment(environment, app))
|
||||
.isInstanceOf(ZookeeperConfigDataMissingEnvironmentPostProcessor.ImportException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void boostrap() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.cloud.bootstrap.enabled", "true");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacy() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.config.use-legacy-processing", "true");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void configNotEnabled() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.cloud.zookeeper.enabled", "false");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void importCheckNotEnabled() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.cloud.zookeeper.config.import-check.enabled", "false");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void importSinglePropertySource() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.config.import", "zookeeper:http://localhost:8888");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void importMultiplePropertySource() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.config.import", "zookeeper:http://localhost:8888,file:./app.properties");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
void importMultiplePropertySourceAsList() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("spring.config.import[0]", "zookeeper:http://localhost:8888");
|
||||
environment.setProperty("spring.config.import[1]", "file:./app.properties");
|
||||
SpringApplication app = mock(SpringApplication.class);
|
||||
ZookeeperConfigDataMissingEnvironmentPostProcessor processor = new ZookeeperConfigDataMissingEnvironmentPostProcessor();
|
||||
assertThatCode(() -> processor.postProcessEnvironment(environment, app)).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.zookeeper.config.ZookeeperConfigDataLocationResolver.PREFIX;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class ZookeeperConfigDataNoImportIntegrationTests {
|
||||
|
||||
private static final String APP_NAME = "testZookeeperConfigDataNoImport";
|
||||
|
||||
@Test
|
||||
public void exceptionThrownIfNoImport(CapturedOutput output) {
|
||||
Assertions.assertThatThrownBy(() -> new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
|
||||
.run("--spring.application.name=" + APP_NAME)).isInstanceOf(ConfigDataMissingEnvironmentPostProcessor.ImportException.class);
|
||||
|
||||
assertThat(output).contains("No spring.config.import property has been defined")
|
||||
.contains("Add a spring.config.import=zookeeper: property to your configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionThrownIfImportMissingZookeeper(CapturedOutput output) {
|
||||
Assertions.assertThatThrownBy(() -> new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).run(
|
||||
"--spring.config.import=optional:file:somefile.properties", "--spring.application.name=" + APP_NAME))
|
||||
.isInstanceOf(ConfigDataMissingEnvironmentPostProcessor.ImportException.class);
|
||||
|
||||
assertThat(output).contains("spring.config.import property is missing a " + PREFIX)
|
||||
.contains("Add a spring.config.import=zookeeper: property to your configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noExceptionThrownIfZookeeperDisabled() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.cloud.zookeeper.enabled=false", "--spring.application.name=" + APP_NAME)) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noExceptionThrownIfZookeeperConfigDisabled() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.cloud.zookeeper.config.enabled=false", "--spring.application.name=" + APP_NAME)) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noExceptionThrownIfImportCheckDisabled() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Config.class)
|
||||
.web(WebApplicationType.NONE).run("--spring.cloud.zookeeper.config.import-check.enabled=false",
|
||||
"--spring.application.name=" + APP_NAME)) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
|
||||
import org.springframework.cloud.context.refresh.ConfigDataContextRefresher;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ZookeeperConfigDataNotOptionalIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void configDataNotFoundThrowsException() {
|
||||
Assertions.assertThatThrownBy(() -> {
|
||||
ConfigurableApplicationContext context = null;
|
||||
try {
|
||||
context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).run(
|
||||
"--spring.cloud.zookeeper.connect-string=notexistantdomain:5000", "--debug=true",
|
||||
"--spring.cloud.zookeeper.max-retries=0",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedWait=1",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedUnit=MILLISECONDS",
|
||||
"--spring.cloud.zookeeper.connection-timeout=1ms",
|
||||
"--spring.config.import=zookeeper:",
|
||||
"--spring.application.name=testZkConfigDataNotOptionalIntegration",
|
||||
"--logging.level.org.springframework.cloud.zookeeper=DEBUG",
|
||||
"--spring.cloud.zookeeper.config.root=/shouldfail");
|
||||
|
||||
}
|
||||
finally {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}).isInstanceOf(ConfigDataResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public ContextRefresher contextRefresher(ConfigurableApplicationContext context, RefreshScope scope) {
|
||||
return new ConfigDataContextRefresher(context, scope);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* @author Enrique Recarte Llorens
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
public class ZookeeperPropertySourceLocatorFailFastTests {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// This system property makes Curator fail faster, otherwise it takes 15 seconds
|
||||
// to trigger a retry
|
||||
System.setProperty("curator-default-connection-timeout", "0");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
System.clearProperty("curator-default-connection-timeout");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailFastFalseLoadsTheApplicationContext() {
|
||||
assertThatCode(() -> {
|
||||
new SpringApplicationBuilder().sources(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
|
||||
"--spring.config.use-legacy-processing=true",
|
||||
"--spring.cloud.zookeeper.config.connectString=localhost:2188",
|
||||
"--spring.cloud.zookeeper.baseSleepTimeMs=0",
|
||||
"--spring.cloud.zookeeper.maxRetries=0",
|
||||
"--spring.cloud.zookeeper.maxSleepMs=0",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedWait=0",
|
||||
"--spring.cloud.zookeeper.config.failFast=false");
|
||||
}).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailFastTrueDoesNotLoadTheApplicationContext() {
|
||||
assertThatThrownBy(() -> {
|
||||
new SpringApplicationBuilder().sources(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
|
||||
"--spring.config.use-legacy-processing=true",
|
||||
"--spring.cloud.zookeeper.config.connectString=localhost:2188",
|
||||
"--spring.cloud.zookeeper.baseSleepTimeMs=0",
|
||||
"--spring.cloud.zookeeper.maxRetries=0",
|
||||
"--spring.cloud.zookeeper.maxSleepMs=0",
|
||||
"--spring.cloud.zookeeper.blockUntilConnectedWait=0",
|
||||
"--spring.cloud.zookeeper.config.failFast=true");
|
||||
})
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.api.GetChildrenBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ZookeeperPropertySourceLocatorNoApplicationNameTests {
|
||||
|
||||
@Test
|
||||
public void defaultSpringApplicationNameWorks() {
|
||||
CuratorFramework curator = mock(CuratorFramework.class);
|
||||
when(curator.getChildren()).thenReturn(mock(GetChildrenBuilder.class));
|
||||
ZookeeperConfigProperties properties = new ZookeeperConfigProperties();
|
||||
properties.setName("notempty");
|
||||
ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(
|
||||
curator, properties);
|
||||
locator.locate(new MockEnvironment());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.framework.api.GetChildrenBuilder;
|
||||
import org.apache.curator.retry.RetryOneTime;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.cloud.context.refresh.LegacyContextRefresher;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ZookeeperPropertySourceLocatorTests {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ZookeeperPropertySourceLocatorTests.class);
|
||||
|
||||
public static final String PREFIX = "test__config__";
|
||||
|
||||
public static final String ROOT = "/" + PREFIX + UUID.randomUUID();
|
||||
|
||||
public static final String CONTEXT = ROOT + "/application/";
|
||||
|
||||
public static final String KEY_BASIC = "testProp";
|
||||
|
||||
public static final String KEY_BASIC_PATH = CONTEXT + KEY_BASIC;
|
||||
|
||||
public static final String VAL_BASIC = "testPropVal";
|
||||
|
||||
public static final String KEY_WITH_DOT = "testProp.dot";
|
||||
|
||||
public static final String KEY_WITH_DOT_PATH = CONTEXT + KEY_WITH_DOT;
|
||||
|
||||
public static final String VAL_WITH_DOT = "withDotVal";
|
||||
|
||||
public static final String KEY_NESTED = "testProp.nested";
|
||||
|
||||
public static final String KEY_NESTED_PATH = CONTEXT + KEY_NESTED.replace('.', '/');
|
||||
|
||||
public static final String VAL_NESTED = "nestedVal";
|
||||
|
||||
public static final String KEY_WITHOUT_VALUE = "testProp.novalue";
|
||||
|
||||
public static final String KEY_WITHOUT_VALUE_PATH = CONTEXT + KEY_WITHOUT_VALUE;
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private ZookeeperTestingServer testingServer;
|
||||
|
||||
private CuratorFramework curator;
|
||||
|
||||
private ZookeeperConfigProperties properties;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.testingServer = new ZookeeperTestingServer();
|
||||
testingServer.start();
|
||||
String connectString = "localhost:" + testingServer.getPort();
|
||||
this.curator = CuratorFrameworkFactory.builder()
|
||||
.retryPolicy(new RetryOneTime(500)).connectString(connectString).build();
|
||||
this.curator.start();
|
||||
|
||||
List<String> children = this.curator.getChildren().forPath("/");
|
||||
for (String child : children) {
|
||||
if (child.startsWith(PREFIX) && child.length() > PREFIX.length()) {
|
||||
delete("/" + child);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder create = new StringBuilder(1024);
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_BASIC_PATH, VAL_BASIC.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_WITH_DOT_PATH, VAL_WITH_DOT.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_NESTED_PATH, VAL_NESTED.getBytes())).append('\n');
|
||||
create.append(this.curator.create().creatingParentsIfNeeded()
|
||||
.forPath(KEY_WITHOUT_VALUE_PATH, null)).append('\n');
|
||||
this.curator.close();
|
||||
System.out.println(create);
|
||||
|
||||
this.context = new SpringApplicationBuilder(Config.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.cloud.zookeeper.connectString=" + connectString,
|
||||
"--spring.config.use-legacy-processing=true",
|
||||
"--spring.application.name=testZkPropertySource",
|
||||
"--logging.level.org.springframework.cloud.zookeeper=DEBUG",
|
||||
"--spring.cloud.zookeeper.config.root=" + ROOT);
|
||||
|
||||
this.curator = this.context.getBean(CuratorFramework.class);
|
||||
this.properties = this.context.getBean(ZookeeperConfigProperties.class);
|
||||
this.environment = this.context.getEnvironment();
|
||||
}
|
||||
|
||||
public void delete(String path) throws Exception {
|
||||
try {
|
||||
this.curator.delete().deletingChildrenIfNeeded().forPath(path);
|
||||
}
|
||||
catch (KeeperException e) {
|
||||
if (e.code() != KeeperException.Code.NONODE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
try {
|
||||
delete(this.properties.getRoot());
|
||||
}
|
||||
finally {
|
||||
this.context.close();
|
||||
this.testingServer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkKeyValues() throws Exception {
|
||||
String propValue = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(propValue).as(KEY_BASIC + " was wrong").isEqualTo(VAL_BASIC);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_NESTED);
|
||||
assertThat(propValue).as(VAL_NESTED + " was wrong").isEqualTo(VAL_NESTED);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_WITH_DOT);
|
||||
assertThat(propValue).as(VAL_WITH_DOT + " was wrong").isEqualTo(VAL_WITH_DOT);
|
||||
|
||||
propValue = this.environment.getProperty(KEY_WITHOUT_VALUE);
|
||||
assertThat(propValue).as(KEY_WITHOUT_VALUE + " was wrong").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyLoadedAndUpdated() throws Exception {
|
||||
String testProp = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(testProp).as("testProp was wrong").isEqualTo(VAL_BASIC);
|
||||
|
||||
this.curator.setData().forPath(KEY_BASIC_PATH, "testPropValUpdate".getBytes());
|
||||
|
||||
CountDownLatch latch = this.context.getBean(CountDownLatch.class);
|
||||
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
|
||||
assertThat(receivedEvent).as("listener didn't receive event").isTrue();
|
||||
|
||||
testProp = this.environment.getProperty(KEY_BASIC);
|
||||
assertThat(testProp).as("testProp was wrong after update")
|
||||
.isEqualTo("testPropValUpdate");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compositePropertySourceHoldsPropertySourcesInCorrectOrder() {
|
||||
|
||||
// given
|
||||
final String defaultContext = "someDefaultContext";
|
||||
final String someName = "someName";
|
||||
final String someProfile = "someProfile";
|
||||
|
||||
final CuratorFramework curator = mock(CuratorFramework.class);
|
||||
when(curator.getChildren()).thenReturn(mock(GetChildrenBuilder.class));
|
||||
|
||||
final MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setActiveProfiles(someProfile);
|
||||
|
||||
final ZookeeperConfigProperties properties = new ZookeeperConfigProperties();
|
||||
properties.setName(someName);
|
||||
properties.setDefaultContext(defaultContext);
|
||||
|
||||
final ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(
|
||||
curator, properties);
|
||||
|
||||
// when
|
||||
final PropertySource<?> propertySource = locator.locate(mockEnvironment);
|
||||
|
||||
// then
|
||||
assertThat(propertySource).isInstanceOf(CompositePropertySource.class);
|
||||
|
||||
// and
|
||||
final ArrayList<PropertySource<?>> propertySources = new ArrayList<>(
|
||||
((CompositePropertySource) propertySource).getPropertySources());
|
||||
|
||||
assertThat(propertySources.get(0).getName())
|
||||
.endsWith(someName + properties.getProfileSeparator() + someProfile);
|
||||
assertThat(propertySources.get(1).getName()).endsWith(someName);
|
||||
assertThat(propertySources.get(2).getName()).endsWith(
|
||||
defaultContext + properties.getProfileSeparator() + someProfile);
|
||||
assertThat(propertySources.get(3).getName()).endsWith(defaultContext);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config implements ApplicationListener<EnvironmentChangeEvent> {
|
||||
|
||||
@Bean
|
||||
public CountDownLatch countDownLatch() {
|
||||
return new CountDownLatch(1);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
|
||||
RefreshScope scope) {
|
||||
return new LegacyContextRefresher(context, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EnvironmentChangeEvent event) {
|
||||
log.debug("Event keys: " + event.getKeys());
|
||||
if (event.getKeys().contains(KEY_BASIC)) {
|
||||
countDownLatch().countDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
logging:
|
||||
level:
|
||||
org.apache.zookeeper.ClientCnxn: ERROR
|
||||
170
spring-cloud-zookeeper-core/.flattened-pom.xml
Normal file
170
spring-cloud-zookeeper-core/.flattened-pom.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<name>Spring Cloud Zookeeper Core</name>
|
||||
<description>Spring Cloud Zookeeper Core</description>
|
||||
<url>https://spring.io/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-core</url>
|
||||
<organization>
|
||||
<name>Pivotal Software, Inc.</name>
|
||||
<url>https://www.spring.io</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
<comments>Copyright 2014-2021 the original author or authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>dsyer</id>
|
||||
<name>Dave Syer</name>
|
||||
<email>dsyer at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>sgibb</id>
|
||||
<name>Spencer Gibb</name>
|
||||
<email>sgibb at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>lead</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>mgrzejszczak</id>
|
||||
<name>Marcin Grzejszczak</name>
|
||||
<email>mgrzejszczak at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>rbaxter</id>
|
||||
<name>Ryan Baxter</name>
|
||||
<email>rbaxter at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>omaciaszeksharma</id>
|
||||
<name>Olga Maciaszek-Sharma</name>
|
||||
<email>omaciaszeksharma at pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-core</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-zookeeper.git/spring-cloud-zookeeper-core</developerConnection>
|
||||
<url>https://github.com/spring-cloud/spring-cloud-zookeeper/spring-cloud-zookeeper-core</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,93 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-zookeeper-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Zookeeper Core</name>
|
||||
<description>Spring Cloud Zookeeper Core</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
/**
|
||||
* Wrapper annotation to enable Zookeeper.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@ConditionalOnProperty(value = "spring.cloud.zookeeper.enabled", matchIfMissing = true)
|
||||
public @interface ConditionalOnZookeeperEnabled {
|
||||
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.drivers.TracerDriver;
|
||||
import org.apache.curator.ensemble.EnsembleProvider;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
|
||||
import org.springframework.boot.BootstrapContext;
|
||||
import org.springframework.boot.BootstrapRegistry;
|
||||
import org.springframework.boot.context.config.ConfigDataException;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
|
||||
public abstract class CuratorFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZookeeperAutoConfiguration.class);
|
||||
|
||||
public static CuratorFramework curatorFramework(ZookeeperProperties properties, RetryPolicy retryPolicy,
|
||||
Supplier<Stream<CuratorFrameworkCustomizer>> optionalCuratorFrameworkCustomizerProvider,
|
||||
Supplier<EnsembleProvider> optionalEnsembleProvider, Supplier<TracerDriver> optionalTracerDriverProvider)
|
||||
throws Exception {
|
||||
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
|
||||
|
||||
EnsembleProvider ensembleProvider = optionalEnsembleProvider.get();
|
||||
if (ensembleProvider != null) {
|
||||
builder.ensembleProvider(ensembleProvider);
|
||||
}
|
||||
else {
|
||||
builder.connectString(properties.getConnectString());
|
||||
}
|
||||
builder.sessionTimeoutMs((int) properties.getSessionTimeout().toMillis())
|
||||
.connectionTimeoutMs((int) properties.getConnectionTimeout().toMillis()).retryPolicy(retryPolicy);
|
||||
|
||||
Stream<CuratorFrameworkCustomizer> customizers = optionalCuratorFrameworkCustomizerProvider.get();
|
||||
if (customizers != null) {
|
||||
customizers.forEach(curatorFrameworkCustomizer -> curatorFrameworkCustomizer.customize(builder));
|
||||
}
|
||||
|
||||
CuratorFramework curator = builder.build();
|
||||
TracerDriver tracerDriver = optionalTracerDriverProvider.get();
|
||||
if (tracerDriver != null && curator.getZookeeperClient() != null) {
|
||||
curator.getZookeeperClient().setTracerDriver(tracerDriver);
|
||||
}
|
||||
|
||||
curator.start();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("blocking until connected to zookeeper for " + properties.getBlockUntilConnectedWait()
|
||||
+ properties.getBlockUntilConnectedUnit());
|
||||
}
|
||||
curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("connected to zookeeper");
|
||||
}
|
||||
return curator;
|
||||
}
|
||||
|
||||
public static RetryPolicy retryPolicy(ZookeeperProperties properties) {
|
||||
return new ExponentialBackoffRetry(properties.getBaseSleepTimeMs(), properties.getMaxRetries(),
|
||||
properties.getMaxSleepMs());
|
||||
}
|
||||
|
||||
public static void registerCurator(BootstrapRegistry registery, UriComponents location, boolean optional) {
|
||||
registerCurator(registery, location, optional, bootstrapContext -> true);
|
||||
}
|
||||
|
||||
public static void registerCurator(BootstrapRegistry registery, UriComponents location, boolean optional,
|
||||
Predicate<BootstrapContext> predicate) {
|
||||
registery.registerIfAbsent(ZookeeperProperties.class, context -> {
|
||||
if (!predicate.test(context)) {
|
||||
return null;
|
||||
}
|
||||
return loadProperties(context.get(Binder.class), location);
|
||||
});
|
||||
|
||||
registery.registerIfAbsent(RetryPolicy.class, context -> {
|
||||
if (!predicate.test(context)) {
|
||||
return null;
|
||||
}
|
||||
return retryPolicy(context.get(ZookeeperProperties.class));
|
||||
});
|
||||
|
||||
registery.registerIfAbsent(CuratorFramework.class, context -> {
|
||||
if (!predicate.test(context)) {
|
||||
return null;
|
||||
}
|
||||
return curatorFramework(context, context.get(ZookeeperProperties.class), optional);
|
||||
});
|
||||
|
||||
// promote beans to context
|
||||
registery.addCloseListener(event -> {
|
||||
BootstrapContext context = event.getBootstrapContext();
|
||||
if (predicate.test(context)) {
|
||||
CuratorFramework curatorFramework = context.get(CuratorFramework.class);
|
||||
if (!event.getApplicationContext().getBeanFactory().containsBean("configDataCuratorFramework")) {
|
||||
event.getApplicationContext().getBeanFactory().registerSingleton("configDataCuratorFramework",
|
||||
curatorFramework);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
static ZookeeperProperties loadProperties(Binder binder, UriComponents location) {
|
||||
ZookeeperProperties properties = binder.bind(ZookeeperProperties.PREFIX, Bindable.of(ZookeeperProperties.class))
|
||||
.orElse(new ZookeeperProperties());
|
||||
|
||||
if (location != null && StringUtils.hasText(location.getHost())) {
|
||||
if (location.getPort() < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"zookeeper port must be greater than or equal to zero: " + location.getPort());
|
||||
}
|
||||
properties.setConnectString(location.getHost() + ":" + location.getPort());
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static CuratorFramework curatorFramework(BootstrapContext context, ZookeeperProperties properties,
|
||||
boolean optional) {
|
||||
|
||||
Supplier<Stream<CuratorFrameworkCustomizer>> customizers;
|
||||
// TODO: use new apis after milestone release
|
||||
try {
|
||||
CuratorFrameworkCustomizer customizer = context.get(CuratorFrameworkCustomizer.class);
|
||||
customizers = () -> Stream.of(customizer);
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
customizers = () -> null;
|
||||
}
|
||||
try {
|
||||
return CuratorFactory.curatorFramework(properties, context.get(RetryPolicy.class), customizers,
|
||||
supplier(context, EnsembleProvider.class), supplier(context, TracerDriver.class));
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (!optional) {
|
||||
log.error("Unable to connect to zookeeper", e);
|
||||
throw new ZookeeperConnectException("Unable to connect to zookeeper", e);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unable to connect to zookeeper", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <T> Supplier<T> supplier(BootstrapContext context, Class<T> type) {
|
||||
try {
|
||||
// TODO: use new apis after milestone release
|
||||
T instance = context.get(type);
|
||||
return () -> instance;
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
return () -> null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ZookeeperConnectException extends ConfigDataException {
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigDataException} instance.
|
||||
* @param message the exception message
|
||||
* @param cause the exception cause
|
||||
*/
|
||||
protected ZookeeperConnectException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
|
||||
/**
|
||||
* Beans that implement this interface will be used by the
|
||||
* {@link ZookeeperAutoConfiguration#curatorFramework(RetryPolicy, ZookeeperProperties, ObjectProvider, ObjectProvider, ObjectProvider)
|
||||
* ZookeeperAutoConfiguration} ZookeeperAutoConfiguration} to further customize the
|
||||
* {@link CuratorFramework} that it provides.
|
||||
*
|
||||
* @author Bernardo Gomez Palacio.
|
||||
* @see ZookeeperAutoConfiguration
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CuratorFrameworkCustomizer {
|
||||
|
||||
/**
|
||||
* Customize the {@link CuratorFrameworkFactory.Builder}.
|
||||
* @param builder instance of the builder that you can further customize.
|
||||
*/
|
||||
void customize(CuratorFrameworkFactory.Builder builder);
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.drivers.TracerDriver;
|
||||
import org.apache.curator.ensemble.EnsembleProvider;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.x.discovery.UriSpec;
|
||||
import org.apache.zookeeper.ClientCnxnSocketNIO;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
* Auto-configuration} that sets up Zookeeper discovery.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnZookeeperEnabled
|
||||
@EnableConfigurationProperties
|
||||
public class ZookeeperAutoConfiguration {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZookeeperAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ZookeeperProperties zookeeperProperties() {
|
||||
return new ZookeeperProperties();
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
@ConditionalOnMissingBean
|
||||
public CuratorFramework curatorFramework(ZookeeperProperties properties, RetryPolicy retryPolicy,
|
||||
ObjectProvider<CuratorFrameworkCustomizer> optionalCuratorFrameworkCustomizerProvider,
|
||||
ObjectProvider<EnsembleProvider> optionalEnsembleProvider,
|
||||
ObjectProvider<TracerDriver> optionalTracerDriverProvider) throws Exception {
|
||||
return CuratorFactory.curatorFramework(properties, retryPolicy,
|
||||
optionalCuratorFrameworkCustomizerProvider::orderedStream, optionalEnsembleProvider::getIfAvailable,
|
||||
optionalTracerDriverProvider::getIfAvailable);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RetryPolicy exponentialBackoffRetry(ZookeeperProperties properties) {
|
||||
return CuratorFactory.retryPolicy(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO: remove after GraalVM metadata PR merged
|
||||
class ZookeeperCoreHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
if (!ClassUtils.isPresent("org.apache.zookeeper.ZooKeeper", classLoader)) {
|
||||
return;
|
||||
}
|
||||
hints.reflection().registerType(TypeReference.of(ClientCnxnSocketNIO.class),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("org.apache.curator.x.discovery.details.OldServiceInstance"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("org.apache.curator.x.discovery.UriSpec"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection().registerType(TypeReference.of(UriSpec.Part.class),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("org.apache.curator.x.discovery.ServiceInstance"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Auto {@link Configuration} for adding a Zookeeper health endpoint to actuator if
|
||||
* required.
|
||||
*
|
||||
* @author Tom Gianos
|
||||
* @since 2.0.1
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnZookeeperEnabled
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
@AutoConfigureAfter({ ZookeeperAutoConfiguration.class })
|
||||
public class ZookeeperHealthAutoConfiguration {
|
||||
|
||||
/**
|
||||
* If there is an active curator, if the zookeeper health endpoint is enabled and if a
|
||||
* health indicator hasn't already been added by a user add one.
|
||||
* @param curator The curator connection to zookeeper to use
|
||||
* @return An instance of {@link ZookeeperHealthIndicator} to add to actuator health
|
||||
* report
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(ZookeeperHealthIndicator.class)
|
||||
@ConditionalOnBean(CuratorFramework.class)
|
||||
@ConditionalOnEnabledHealthIndicator("zookeeper")
|
||||
public ZookeeperHealthIndicator zookeeperHealthIndicator(CuratorFramework curator) {
|
||||
return new ZookeeperHealthIndicator(curator);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.imps.CuratorFrameworkState;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.boot.actuate.health.HealthIndicator} that checks the
|
||||
* status of the Zookeeper connection.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ZookeeperHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private final CuratorFramework curator;
|
||||
|
||||
public ZookeeperHealthIndicator(CuratorFramework curator) {
|
||||
this.curator = curator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
try {
|
||||
CuratorFrameworkState state = this.curator.getState();
|
||||
if (state != CuratorFrameworkState.STARTED) {
|
||||
builder.down().withDetail("error", "Client not started");
|
||||
}
|
||||
else if (this.curator.checkExists().forPath("/") == null) {
|
||||
builder.down().withDetail("error", "Root for namespace does not exist");
|
||||
}
|
||||
else {
|
||||
builder.up();
|
||||
}
|
||||
builder.withDetail("connectionString",
|
||||
this.curator.getZookeeperClient().getCurrentConnectionString())
|
||||
.withDetail("state", state);
|
||||
}
|
||||
catch (Exception e) {
|
||||
builder.down(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.convert.DurationUnit;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Properties related to connecting to Zookeeper.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ConfigurationProperties(ZookeeperProperties.PREFIX)
|
||||
public class ZookeeperProperties {
|
||||
|
||||
/**
|
||||
* Configuration prefix.
|
||||
*/
|
||||
public static final String PREFIX = "spring.cloud.zookeeper";
|
||||
/**
|
||||
* Connection string to the Zookeeper cluster.
|
||||
*/
|
||||
private String connectString = "localhost:2181";
|
||||
|
||||
/**
|
||||
* Is Zookeeper enabled.
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Initial amount of time to wait between retries.
|
||||
*/
|
||||
private Integer baseSleepTimeMs = 50;
|
||||
|
||||
/**
|
||||
* Max number of times to retry.
|
||||
*/
|
||||
private Integer maxRetries = 10;
|
||||
|
||||
/**
|
||||
* Max time in ms to sleep on each retry.
|
||||
*/
|
||||
private Integer maxSleepMs = 500;
|
||||
|
||||
/**
|
||||
* Wait time to block on connection to Zookeeper.
|
||||
*/
|
||||
private Integer blockUntilConnectedWait = 10;
|
||||
|
||||
/**
|
||||
* The unit of time related to blocking on connection to Zookeeper.
|
||||
*/
|
||||
private TimeUnit blockUntilConnectedUnit = TimeUnit.SECONDS;
|
||||
|
||||
/**
|
||||
* The configured/negotiated session timeout in milliseconds. Please refer to
|
||||
* <a href='https://cwiki.apache.org/confluence/display/CURATOR/TN14'>Curator's Tech
|
||||
* Note 14</a> to understand how Curator implements connection sessions.
|
||||
*
|
||||
* @see <a href='https://cwiki.apache.org/confluence/display/CURATOR/TN14'>Curator's
|
||||
* Tech Note 14</a>
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.MILLIS)
|
||||
private Duration sessionTimeout = Duration.of(60 * 1000, ChronoUnit.MILLIS);
|
||||
|
||||
/**
|
||||
* The configured connection timeout in milliseconds.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.MILLIS)
|
||||
private Duration connectionTimeout = Duration.of(15 * 1000, ChronoUnit.MILLIS);
|
||||
|
||||
public String getConnectString() {
|
||||
return this.connectString;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Integer getBaseSleepTimeMs() {
|
||||
return this.baseSleepTimeMs;
|
||||
}
|
||||
|
||||
public Integer getMaxRetries() {
|
||||
return this.maxRetries;
|
||||
}
|
||||
|
||||
public Integer getMaxSleepMs() {
|
||||
return this.maxSleepMs;
|
||||
}
|
||||
|
||||
public Integer getBlockUntilConnectedWait() {
|
||||
return this.blockUntilConnectedWait;
|
||||
}
|
||||
|
||||
public TimeUnit getBlockUntilConnectedUnit() {
|
||||
return this.blockUntilConnectedUnit;
|
||||
}
|
||||
|
||||
public void setConnectString(String connectString) {
|
||||
Assert.hasText(connectString, "spring.cloud.zookeeper.connect-string may not be empty");
|
||||
this.connectString = connectString;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setBaseSleepTimeMs(Integer baseSleepTimeMs) {
|
||||
this.baseSleepTimeMs = baseSleepTimeMs;
|
||||
}
|
||||
|
||||
public void setMaxRetries(Integer maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
}
|
||||
|
||||
public void setMaxSleepMs(Integer maxSleepMs) {
|
||||
this.maxSleepMs = maxSleepMs;
|
||||
}
|
||||
|
||||
public void setBlockUntilConnectedWait(Integer blockUntilConnectedWait) {
|
||||
this.blockUntilConnectedWait = blockUntilConnectedWait;
|
||||
}
|
||||
|
||||
public void setBlockUntilConnectedUnit(TimeUnit blockUntilConnectedUnit) {
|
||||
this.blockUntilConnectedUnit = blockUntilConnectedUnit;
|
||||
}
|
||||
|
||||
public Duration getSessionTimeout() {
|
||||
return sessionTimeout;
|
||||
}
|
||||
|
||||
public void setSessionTimeout(Duration sessionTimeout) {
|
||||
this.sessionTimeout = sessionTimeout;
|
||||
}
|
||||
|
||||
public Duration getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{"properties": [
|
||||
{
|
||||
"name": "management.health.zookeeper.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the health endpoint for zookeeper.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "endpoints.zookeeper.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the /zookeeper endpoint to inspect the state of zookeeper.",
|
||||
"defaultValue": true
|
||||
}
|
||||
]}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.cloud.zookeeper.ZookeeperCoreHints
|
||||
@@ -1,2 +0,0 @@
|
||||
org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration
|
||||
org.springframework.cloud.zookeeper.ZookeeperHealthAutoConfiguration
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CuratorFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testLoadProperties() {
|
||||
ZookeeperProperties properties = CuratorFactory.loadProperties(
|
||||
Binder.get(new MockEnvironment()),
|
||||
UriComponentsBuilder.fromUriString("zookeeper://myhost:8502").build());
|
||||
assertThat(properties.getConnectString()).isEqualTo("myhost:8502");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.zookeeper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.curator.drivers.TracerDriver;
|
||||
import org.apache.curator.ensemble.EnsembleProvider;
|
||||
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.test.TestingServer;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.runners.Enclosed;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.cloud.zookeeper.test.ZookeeperTestingServer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
|
||||
@RunWith(Enclosed.class)
|
||||
public class ZookeeperAutoConfigurationTests {
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(loader = ZookeeperTestingServer.Loader.class,
|
||||
classes = { BaseTestConfig.class, ZookeeperAutoConfiguration.class })
|
||||
public static class BaseTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
CuratorFramework curator;
|
||||
|
||||
@Test
|
||||
public void should_successfully_inject_Curator_as_a_Spring_bean() {
|
||||
assertThat(this.curator).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class BaseTestConfig {
|
||||
|
||||
@Bean
|
||||
ZookeeperProperties zookeeperProperties(TestingServer testingServer) {
|
||||
ZookeeperProperties properties = new ZookeeperProperties();
|
||||
properties.setConnectString(testingServer.getConnectString());
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
TestingServer testingServer() throws Exception {
|
||||
return new TestingServer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(loader = ZookeeperTestingServer.Loader.class,
|
||||
classes = { EnsembleTestConfig.class, ZookeeperAutoConfiguration.class })
|
||||
public static class EnsembleTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
CuratorFramework curator;
|
||||
|
||||
@Autowired
|
||||
TestingServer testingServer;
|
||||
|
||||
@Test
|
||||
public void should_successfully_inject_Curator_with_ensemble_connection_string() {
|
||||
assertThat(curator.getZookeeperClient().getCurrentConnectionString())
|
||||
.isEqualTo(testingServer.getConnectString());
|
||||
assertThat(curator.getZookeeperClient().getCurrentConnectionString())
|
||||
.isNotEqualTo(EnsembleTestConfig.DUMMY_CONNECTION_STRING);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class EnsembleTestConfig {
|
||||
|
||||
static final String DUMMY_CONNECTION_STRING = "dummy-connection-string:2111";
|
||||
|
||||
@Bean
|
||||
EnsembleProvider ensembleProvider(TestingServer testingServer) {
|
||||
return new FixedEnsembleProvider(testingServer.getConnectString());
|
||||
}
|
||||
|
||||
@Bean
|
||||
ZookeeperProperties zookeeperProperties() {
|
||||
ZookeeperProperties properties = new ZookeeperProperties();
|
||||
properties.setConnectString(DUMMY_CONNECTION_STRING);
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "close")
|
||||
TestingServer testingServer() throws Exception {
|
||||
return new TestingServer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(loader = ZookeeperTestingServer.Loader.class,
|
||||
classes = { BaseTestConfig.class,
|
||||
ZookeeperAutoConfiguration.class, CuratorFrameworkCustomizerConfig.class })
|
||||
@DirtiesContext
|
||||
public static class CuratorFrameworkCustomizerTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("customizerCallOrder")
|
||||
List<Integer> callOrder;
|
||||
|
||||
@Test
|
||||
public void should_invoke_the_CuratorFrameworkCustomizer_in_order() {
|
||||
assertThat(callOrder).containsExactly(1, 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class CuratorFrameworkCustomizerConfig {
|
||||
|
||||
@Bean("customizerCallOrder")
|
||||
public List<Integer> curatorFrameworkCustomizerCallOrder() {
|
||||
return new ArrayList<>(2);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(1)
|
||||
public CuratorFrameworkCustomizer customizer1(
|
||||
@Qualifier("customizerCallOrder") List<Integer> callOrder) {
|
||||
return (builder) -> callOrder.add(1);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CuratorFrameworkCustomizer customizer2(
|
||||
@Qualifier("customizerCallOrder") List<Integer> callOrder) {
|
||||
return (builder) -> callOrder.add(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(loader = ZookeeperTestingServer.Loader.class,
|
||||
classes = { BaseTestConfig.class, TracerDriverTestConfig.class,
|
||||
ZookeeperAutoConfiguration.class })
|
||||
public static class TracerDriverTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
TracerDriver tracerDriver;
|
||||
|
||||
@Autowired(required = false)
|
||||
CuratorFramework curator;
|
||||
|
||||
@Autowired
|
||||
TestingServer testingServer;
|
||||
|
||||
@Test
|
||||
public void should_successfully_inject_Curators_TracerDriver() {
|
||||
assertThat(curator.getZookeeperClient().getTracerDriver())
|
||||
.isEqualTo(tracerDriver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class TracerDriverTestConfig {
|
||||
|
||||
@Bean
|
||||
TracerDriver mockedTracerDriver() {
|
||||
return mock(TracerDriver.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user