From 724eb733c6375e9d7f4e16229065d6daa4b521af Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Sun, 21 Nov 2021 01:20:39 +0300 Subject: [PATCH 1/6] Upgrade java version to 1.8 --- README.adoc | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 56fe059..5cdb080 100644 --- a/README.adoc +++ b/README.adoc @@ -39,7 +39,7 @@ See the https://coreos.com/etcd/[overview] for more information. == Building -:jdkversion: 1.7 +:jdkversion: 1.8 === Basic Compile and Test diff --git a/pom.xml b/pom.xml index 200166b..6646f74 100644 --- a/pom.xml +++ b/pom.xml @@ -41,8 +41,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.7 - 1.7 + 1.8 + 1.8 From 37452c37b99a2e69900e92344843278ca7e0b74e Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Sun, 21 Nov 2021 15:25:41 +0300 Subject: [PATCH 2/6] Add checkstyle support Enabled maven-checkstyle plugins according to spring-cloud-builds instruction, fix projects checkstyle issues, extend gitignore --- .gitignore | 7 + pom.xml | 26 ++- .../EtcdConfigBootstrapConfiguration.java | 4 +- .../etcd/config/EtcdConfigProperties.java | 34 ++-- .../cloud/etcd/config/EtcdConstants.java | 24 ++- .../cloud/etcd/config/EtcdPropertySource.java | 16 +- .../config/EtcdPropertySourceLocator.java | 4 +- .../main/resources/META-INF/spring.factories | 2 +- .../cloud/etcd/EtcdAutoConfiguration.java | 4 +- .../cloud/etcd/EtcdEndpoint.java | 12 +- .../cloud/etcd/EtcdHealthIndicator.java | 13 +- .../cloud/etcd/EtcdProperties.java | 23 ++- spring-cloud-etcd-dependencies/pom.xml | 27 ++- .../etcd/discovery/EtcdDiscoveryClient.java | 41 ++-- .../EtcdDiscoveryClientConfiguration.java | 4 +- .../discovery/EtcdDiscoveryProperties.java | 148 +++++++++------ .../cloud/etcd/discovery/EtcdLifecycle.java | 177 ++++++++++-------- .../EtcdRibbonClientConfiguration.java | 19 +- .../cloud/etcd/discovery/EtcdServer.java | 4 +- .../cloud/etcd/discovery/EtcdServerList.java | 20 +- .../RibbonEtcdAutoConfiguration.java | 4 +- .../etcd/sample/SampleEtcdApplication.java | 8 +- .../src/main/resources/application.yml | 2 +- 23 files changed, 391 insertions(+), 232 deletions(-) diff --git a/.gitignore b/.gitignore index 8c5133e..f5cf48e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,16 @@ .classpath .project .settings/ +.factorypath .springBeans target/ _site/ .idea *.iml *.swp +*.log +.checkstyle +.DS_Store +.vscode/ +.flattened-pom.xml +.sdkmanrc diff --git a/pom.xml b/pom.xml index 6646f74..41e6bfa 100644 --- a/pom.xml +++ b/pom.xml @@ -36,14 +36,30 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + org.codehaus.mojo + flatten-maven-plugin + org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - + maven-checkstyle-plugin diff --git a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigBootstrapConfiguration.java b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigBootstrapConfiguration.java index 4f22520..49c1d1b 100644 --- a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigBootstrapConfiguration.java +++ b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigBootstrapConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigProperties.java b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigProperties.java index 12df1d7..99367cc 100644 --- a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigProperties.java +++ b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConfigProperties.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,10 +16,10 @@ package org.springframework.cloud.etcd.config; -import org.springframework.boot.context.properties.ConfigurationProperties; - import java.util.concurrent.TimeUnit; +import org.springframework.boot.context.properties.ConfigurationProperties; + /** * @author Luca Burgazzoli * @author Spencer Gibb @@ -86,18 +86,30 @@ public void setTimeoutUnit(TimeUnit timeoutUnit) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdConfigProperties that = (EtcdConfigProperties) o; - if (enabled != that.enabled) return false; - if (timeout != that.timeout) return false; - if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) return false; - if (defaultContext != null ? !defaultContext.equals(that.defaultContext) : that.defaultContext != null) + if (enabled != that.enabled) { + return false; + } + if (timeout != that.timeout) { + return false; + } + if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null) { + return false; + } + if (defaultContext != null ? !defaultContext.equals(that.defaultContext) : that.defaultContext != null) { return false; - if (profileSeparator != null ? !profileSeparator.equals(that.profileSeparator) : that.profileSeparator != null) + } + if (profileSeparator != null ? !profileSeparator.equals(that.profileSeparator) : that.profileSeparator != null) { return false; + } return timeoutUnit == that.timeoutUnit; } diff --git a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConstants.java b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConstants.java index 568da46..3299ce7 100644 --- a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConstants.java +++ b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdConstants.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -13,14 +13,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.cloud.etcd.config; /** * @author Luca Burgazzoli */ -public class EtcdConstants { +// TODO: add clear comments for properties +final public class EtcdConstants { + /** + * Property source name. + */ public static final String NAME = "etcd"; + /** + * Separator for path. + */ public static final String PATH_SEPARATOR = "/"; + /** + * Separator for properties. + */ public static final String PROPERTIES_SEPARATOR = "."; + + private EtcdConstants() { + } + + /** + * Property name for spring application name. + */ public static final String PROPERTY_SPRING_APPLICATION_NAME = "spring.application.name"; } diff --git a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySource.java b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySource.java index 653d4cd..1fff013 100644 --- a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySource.java +++ b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySource.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,18 +16,19 @@ package org.springframework.cloud.etcd.config; +import java.util.HashMap; +import java.util.Map; + import mousio.etcd4j.EtcdClient; import mousio.etcd4j.responses.EtcdException; import mousio.etcd4j.responses.EtcdKeysResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.env.EnumerablePropertySource; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.util.HashMap; -import java.util.Map; - /** * @author Luca Burgazzoli * @author Spencer Gibb @@ -59,9 +60,10 @@ public void init() { } } catch (EtcdException e) { - if (e.errorCode == 100) {//key not found, no need to print stack trace + if (e.errorCode == 100) { //key not found, no need to print stack trace log.warn("Unable to init property source: " + getName() + ", " + e.getMessage()); - } else { + } + else { log.warn("Unable to init property source: " + getName(), e); } } diff --git a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySourceLocator.java b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySourceLocator.java index 0ea4b27..3eea213 100644 --- a/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySourceLocator.java +++ b/spring-cloud-etcd-config/src/main/java/org/springframework/cloud/etcd/config/EtcdPropertySourceLocator.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-config/src/main/resources/META-INF/spring.factories b/spring-cloud-etcd-config/src/main/resources/META-INF/spring.factories index 2d3f162..4457528 100644 --- a/spring-cloud-etcd-config/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-etcd-config/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ # Bootstrap Configuration org.springframework.cloud.bootstrap.BootstrapConfiguration=\ -org.springframework.cloud.etcd.config.EtcdConfigBootstrapConfiguration \ No newline at end of file +org.springframework.cloud.etcd.config.EtcdConfigBootstrapConfiguration diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java index 2d5ad48..a1cc506 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java index e713adc..ae10968 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -61,8 +61,12 @@ public void setVersion(String version) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Data data = (Data) o; diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java index 2b98807..97b7742 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -17,6 +17,7 @@ package org.springframework.cloud.etcd; import mousio.etcd4j.EtcdClient; + import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; @@ -48,8 +49,12 @@ public EtcdClient getClient() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdHealthIndicator that = (EtcdHealthIndicator) o; diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java index 889b2e4..1dbb3dd 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,13 +16,14 @@ package org.springframework.cloud.etcd; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import javax.validation.constraints.NotNull; import java.net.URI; import java.util.Arrays; import java.util.List; +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; + /** * @author Spencer Gibb */ @@ -59,12 +60,18 @@ public void setEnabled(boolean enabled) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdProperties that = (EtcdProperties) o; - if (enabled != that.enabled) return false; + if (enabled != that.enabled) { + return false; + } return uris != null ? uris.equals(that.uris) : that.uris == null; } diff --git a/spring-cloud-etcd-dependencies/pom.xml b/spring-cloud-etcd-dependencies/pom.xml index a2eceeb..e9fbc1f 100644 --- a/spring-cloud-etcd-dependencies/pom.xml +++ b/spring-cloud-etcd-dependencies/pom.xml @@ -14,7 +14,7 @@ org.springframework.cloud spring-cloud-dependencies-parent 1.3.1.BUILD-SNAPSHOT - + @@ -24,6 +24,9 @@ 2.7.0 4.1.0.Beta5 1.8 + true + true + true @@ -123,6 +126,28 @@ + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + io.spring.javaformat + spring-javaformat-maven-plugin + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + spring diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java index 87a862c..dd78b93 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,9 +16,15 @@ package org.springframework.cloud.etcd.discovery; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeoutException; + import mousio.etcd4j.EtcdClient; import mousio.etcd4j.responses.EtcdException; import mousio.etcd4j.responses.EtcdKeysResponse; + import org.springframework.beans.BeansException; import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; @@ -27,11 +33,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.util.ReflectionUtils; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeoutException; - /** * @author Spencer Gibb */ @@ -73,7 +74,8 @@ public List getInstances(final String serviceId) { String[] parts = node.value.split(":"); instances.add(new DefaultServiceInstance(serviceId, parts[0], Integer.parseInt(parts[1]), false)); } - } catch (IOException | TimeoutException | EtcdException e) { + } + catch (IOException | TimeoutException | EtcdException e) { ReflectionUtils.rethrowRuntimeException(e); } return instances; @@ -91,7 +93,8 @@ public List getServices() { serviceId = serviceId.substring(1); services.add(serviceId); } - } catch (IOException | EtcdException | TimeoutException e) { + } + catch (IOException | EtcdException | TimeoutException e) { ReflectionUtils.rethrowRuntimeException(e); } return services; @@ -120,14 +123,24 @@ public void setContext(ApplicationContext context) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdDiscoveryClient that = (EtcdDiscoveryClient) o; - if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) return false; - if (lifecycle != null ? !lifecycle.equals(that.lifecycle) : that.lifecycle != null) return false; - if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false; + if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) { + return false; + } + if (lifecycle != null ? !lifecycle.equals(that.lifecycle) : that.lifecycle != null) { + return false; + } + if (properties != null ? !properties.equals(that.properties) : that.properties != null) { + return false; + } return context != null ? context.equals(that.context) : that.context == null; } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java index 6fdfd33..d098d8e 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java index 60cd7df..30c314d 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,11 +16,6 @@ package org.springframework.cloud.etcd.discovery; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.util.ReflectionUtils; - import java.io.IOException; import java.net.Inet4Address; import java.net.InetAddress; @@ -28,6 +23,12 @@ import java.net.UnknownHostException; import java.util.Enumeration; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.ReflectionUtils; + /** * @author Spencer Gibb */ @@ -64,11 +65,11 @@ private HostInfo initHostInfo() { public static InetAddress getIpAddress() { try { for (Enumeration enumNic = NetworkInterface - .getNetworkInterfaces(); enumNic.hasMoreElements();) { + .getNetworkInterfaces(); enumNic.hasMoreElements(); ) { NetworkInterface ifc = enumNic.nextElement(); if (ifc.isUp()) { for (Enumeration enumAddr = ifc - .getInetAddresses(); enumAddr.hasMoreElements();) { + .getInetAddresses(); enumAddr.hasMoreElements(); ) { InetAddress address = enumAddr.nextElement(); if (address instanceof Inet4Address && !address.isLoopbackAddress()) { @@ -78,56 +79,17 @@ public static InetAddress getIpAddress() { } } return InetAddress.getLocalHost(); - } catch (UnknownHostException e){ + } + catch (UnknownHostException e) { ReflectionUtils.rethrowRuntimeException(e); return null; - } catch (IOException e) { + } + catch (IOException e) { log.warn("Unable to find non-loopback address", e); return null; } } - private class HostInfo { - private final String ipAddress; - private final String hostname; - - public HostInfo(String ipAddress, String hostname) { - this.ipAddress = ipAddress; - this.hostname = hostname; - } - - public String getIpAddress() { - return ipAddress; - } - - public String getHostname() { - return hostname; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - HostInfo hostInfo = (HostInfo) o; - - if (!ipAddress.equals(hostInfo.ipAddress)) return false; - return hostname.equals(hostInfo.hostname); - } - - @Override - public int hashCode() { - int result = ipAddress.hashCode(); - result = 31 * result + hostname.hashCode(); - return result; - } - - @Override - public String toString() { - return String.format("HostInfo{ipAddress='%s', hostname='%s'}", ipAddress, hostname); - } - } - public static Log getLog() { return log; } @@ -190,19 +152,36 @@ public void setHeartbeatInterval(int heartbeatInterval) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdDiscoveryProperties that = (EtcdDiscoveryProperties) o; - if (enabled != that.enabled) return false; - if (preferIpAddress != that.preferIpAddress) return false; - if (ttl != that.ttl) return false; - if (heartbeatInterval != that.heartbeatInterval) return false; - if (discoveryPrefix != null ? !discoveryPrefix.equals(that.discoveryPrefix) : that.discoveryPrefix != null) + if (enabled != that.enabled) { return false; - if (hostInfo != null ? !hostInfo.equals(that.hostInfo) : that.hostInfo != null) return false; - if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) return false; + } + if (preferIpAddress != that.preferIpAddress) { + return false; + } + if (ttl != that.ttl) { + return false; + } + if (heartbeatInterval != that.heartbeatInterval) { + return false; + } + if (discoveryPrefix != null ? !discoveryPrefix.equals(that.discoveryPrefix) : that.discoveryPrefix != null) { + return false; + } + if (hostInfo != null ? !hostInfo.equals(that.hostInfo) : that.hostInfo != null) { + return false; + } + if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) { + return false; + } return hostname != null ? hostname.equals(that.hostname) : that.hostname == null; } @@ -225,4 +204,51 @@ public String toString() { "EtcdDiscoveryProperties{enabled=%s, discoveryPrefix='%s', hostInfo=%s, ipAddress='%s', hostname='%s', preferIpAddress=%s, ttl=%d, heartbeatInterval=%d}", enabled, discoveryPrefix, hostInfo, ipAddress, hostname, preferIpAddress, ttl, heartbeatInterval); } + + private class HostInfo { + private final String ipAddress; + private final String hostname; + + HostInfo(String ipAddress, String hostname) { + this.ipAddress = ipAddress; + this.hostname = hostname; + } + + public String getIpAddress() { + return ipAddress; + } + + public String getHostname() { + return hostname; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + HostInfo hostInfo = (HostInfo) o; + + if (!ipAddress.equals(hostInfo.ipAddress)) { + return false; + } + return hostname.equals(hostInfo.hostname); + } + + @Override + public int hashCode() { + int result = ipAddress.hashCode(); + result = 31 * result + hostname.hashCode(); + return result; + } + + @Override + public String toString() { + return String.format("HostInfo{ipAddress='%s', hostname='%s'}", ipAddress, hostname); + } + } } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java index cc12fd9..beaad17 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,18 +16,19 @@ package org.springframework.cloud.etcd.discovery; +import java.io.IOException; +import java.util.concurrent.TimeoutException; + import mousio.etcd4j.EtcdClient; import mousio.etcd4j.responses.EtcdException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cloud.client.discovery.AbstractDiscoveryLifecycle; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; -import java.io.IOException; -import java.util.concurrent.TimeoutException; - /** * @author Spencer Gibb */ @@ -76,7 +77,8 @@ protected void register(Service service) { //TODO: what should be serialized about the service? String value = props.getHostname() + ":" + service.getPort(); etcd.put(key, value).ttl(props.getTtl()).send().get(); - } catch (IOException | TimeoutException | EtcdException e) { + } + catch (IOException | TimeoutException | EtcdException e) { ReflectionUtils.rethrowRuntimeException(e); } } @@ -89,73 +91,9 @@ public String getAppKey(String appName) { return props.getDiscoveryPrefix() + "/" + appName; } - class Service { - String appName; - String id; - Integer port; - - public Service() { - } - - public Service(String appName, String id, Integer port) { - this.appName = appName; - this.id = id; - this.port = port; - } - - public String getAppName() { - return appName; - } - - public void setAppName(String appName) { - this.appName = appName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Integer getPort() { - return port; - } - - public void setPort(Integer port) { - this.port = port; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Service service = (Service) o; - - if (appName != null ? !appName.equals(service.appName) : service.appName != null) return false; - if (id != null ? !id.equals(service.id) : service.id != null) return false; - return port != null ? port.equals(service.port) : service.port == null; - } - - @Override - public int hashCode() { - int result = appName != null ? appName.hashCode() : 0; - result = 31 * result + (id != null ? id.hashCode() : 0); - result = 31 * result + (port != null ? port.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return String.format("Service{appName='%s', id='%s', port=%d}", appName, id, port); - } - } - @Override protected int getConfiguredPort() { - return service.getPort() == null? 0 : service.getPort(); + return service.getPort() == null ? 0 : service.getPort(); } @Override @@ -181,7 +119,8 @@ protected void deregisterManagement() { private void deregister(String appName, String serviceId) { try { etcd.delete(getServiceKey(appName, serviceId)).send(); - } catch (IOException e) { + } + catch (IOException e) { ReflectionUtils.rethrowRuntimeException(e); } } @@ -205,14 +144,24 @@ public Service getService() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } EtcdLifecycle that = (EtcdLifecycle) o; - if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) return false; - if (props != null ? !props.equals(that.props) : that.props != null) return false; - if (service != null ? !service.equals(that.service) : that.service != null) return false; + if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) { + return false; + } + if (props != null ? !props.equals(that.props) : that.props != null) { + return false; + } + if (service != null ? !service.equals(that.service) : that.service != null) { + return false; + } return true; } @@ -229,4 +178,78 @@ public int hashCode() { public String toString() { return String.format("EtcdLifecycle{etcd=%s, props=%s, service=%s}", etcd, props, service); } + + class Service { + String appName; + String id; + Integer port; + + Service() { + } + + Service(String appName, String id, Integer port) { + this.appName = appName; + this.id = id; + this.port = port; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Service service = (Service) o; + + if (appName != null ? !appName.equals(service.appName) : service.appName != null) { + return false; + } + if (id != null ? !id.equals(service.id) : service.id != null) { + return false; + } + return port != null ? port.equals(service.port) : service.port == null; + } + + @Override + public int hashCode() { + int result = appName != null ? appName.hashCode() : 0; + result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (port != null ? port.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return String.format("Service{appName='%s', id='%s', port=%d}", appName, id, port); + } + } + } + diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java index f4a0ab4..33806e2 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,11 +16,13 @@ package org.springframework.cloud.etcd.discovery; -import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses; -import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity; - import javax.annotation.PostConstruct; +import com.netflix.client.config.IClientConfig; +import com.netflix.config.ConfigurationManager; +import com.netflix.config.DynamicPropertyFactory; +import com.netflix.config.DynamicStringProperty; +import com.netflix.loadbalancer.ServerList; import mousio.etcd4j.EtcdClient; import org.springframework.beans.factory.annotation.Autowired; @@ -29,11 +31,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.netflix.client.config.IClientConfig; -import com.netflix.config.ConfigurationManager; -import com.netflix.config.DynamicPropertyFactory; -import com.netflix.config.DynamicStringProperty; -import com.netflix.loadbalancer.ServerList; +import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses; +import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity; /** * @author Spencer Gibb diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java index f6c388b..c1ca009 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java index f90f50d..89d80a3 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,6 +16,12 @@ package org.springframework.cloud.etcd.discovery; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeoutException; + import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; import mousio.etcd4j.EtcdClient; @@ -24,13 +30,8 @@ import mousio.etcd4j.responses.EtcdKeysResponse.EtcdNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.util.ReflectionUtils; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeoutException; +import org.springframework.util.ReflectionUtils; /** * @author Spencer Gibb @@ -90,7 +91,8 @@ private List getServers() { EtcdServer server = new EtcdServer(appInfo[0], appInfo[1], strings[0], strings[1]); servers.add(server); } - } catch (IOException | TimeoutException | EtcdException e) { + } + catch (IOException | TimeoutException | EtcdException e) { ReflectionUtils.rethrowRuntimeException(e); } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java index d2a62be..4a33809 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, diff --git a/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java b/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java index 94d31b3..85aff93 100644 --- a/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java +++ b/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java @@ -1,11 +1,11 @@ /* - * Copyright 2013-2015 the original author or authors. + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -16,6 +16,8 @@ package org.springframework.cloud.etcd.sample; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -29,8 +31,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - /** * @author Spencer Gibb */ diff --git a/spring-cloud-etcd-sample/src/main/resources/application.yml b/spring-cloud-etcd-sample/src/main/resources/application.yml index b4172a9..01dfaff 100644 --- a/spring-cloud-etcd-sample/src/main/resources/application.yml +++ b/spring-cloud-etcd-sample/src/main/resources/application.yml @@ -10,4 +10,4 @@ endpoints: restart: enabled: true shutdown: - enabled: true \ No newline at end of file + enabled: true From 937fde868cf6d0fa8051bae1c6ddebc98ef1874f Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Sun, 21 Nov 2021 15:48:26 +0300 Subject: [PATCH 3/6] Regenerate etcd README docs to use actual references Update pom file im doc submodule to add plugins. Preserve spring-boot and spring-cloud-build version after updating spring-cloud-build parent --- README.adoc | 240 +++++++++++++++++++++++++++++++++++++++------------ docs/pom.xml | 34 +++++--- pom.xml | 8 +- 3 files changed, 212 insertions(+), 70 deletions(-) diff --git a/README.adoc b/README.adoc index 5cdb080..2dc7958 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,9 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +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. +//// + image::https://travis-ci.org/spring-cloud-incubator/spring-cloud-etcd.svg?branch=master[Build Status, link=https://travis-ci.org/spring-cloud-incubator/spring-cloud-etcd] @@ -6,7 +11,7 @@ This project provides Etcd integrations for Spring Boot apps through autoconfigu 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 Etcd based components. The -patterns provided include Service Discovery, Circuit Breaker and Configuration. +patterns provided include Service Discovery and Configuration. Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon) are provided by integration with Spring Cloud Netflix. @@ -43,35 +48,31 @@ See the https://coreos.com/etcd/[overview] for more information. === Basic Compile and Test -To build the source you will need to install -http://maven.apache.org/run-maven/index.html[Apache Maven] v3.0.6 or above and JDK {jdkversion}. +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 ---- -$ mvn install -s .settings.xml +$ ./mvnw install ---- -NOTE: You may need to increase the amount of memory available to Maven by setting -a `MAVEN_OPTS` environment variable with the value `-Xmx512m -XX:MaxPermSize=128m` +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. -The `.settings.xml` is only required the first time (or after updates -to dependencies). It is there to provide repository declarations so -that those do not need to be hard coded in the project poms. +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. -For hints on how to build the project look in `.travis.yml` if there -is one. There should be a "script" and maybe "install" command. Also -look at the "services" section to see if any services need to be -running locally (e.g. mongo or rabbit). Ignore the git-related bits -that you might find in "before_install" since they will be able git -credentials and you already have those. +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. -If you need mongo, rabbit or redis, see the README in the https://github.com/spring-cloud-samples/scripts[scripts -demo repository] for -instructions. For example consider using the "fig.yml" with -http://www.fig.sh/[Fig] to run them in Docker containers. === Documentation @@ -86,54 +87,47 @@ 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 -http://www.springsource.com/developer/sts[Spring Tools Suite] or -http://eclipse.org[Eclipse] when working with the code. We use the -http://eclipse.org/m2e/[m2eclipe] eclipse plugin for maven support. Other IDEs and tools -should also work without issue. +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 http://eclipse.org/m2e/[m2eclipe] eclipse plugin when working with +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] ---- - $ mvn eclipse:eclipse + $ ./mvnw eclipse:eclipse ---- The generated eclipse projects can be imported by selecting `import existing projects` from the `file` menu. -==== Adding Project Lombok Agent - -Spring Cloud uses [Project -Lombok](http://projectlombok.org/features/index.html) to generate -getters and setters etc. Compiling from the command line this -shouldn't cause any problems, but in an IDE you need to add an agent -to the JVM. Full instructions can be found in the Lombok website. The -sign that you need to do this is a lot of compiler errors to do with -missing methods and fields, e.g. - -[indent=0] ----- -The method getInitialStatus() is undefined for the type EurekaInstanceConfigBean EurekaDiscoveryClientConfiguration.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka line 120 Java Problem -The method getInitialStatus() is undefined for the type EurekaInstanceConfigBean EurekaDiscoveryClientConfiguration.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka line 121 Java Problem -The method setNonSecurePort(int) is undefined for the type EurekaInstanceConfigBean EurekaDiscoveryClientConfiguration.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka line 112 Java Problem -The type EurekaInstanceConfigBean.IdentifyingDataCenterInfo must implement the inherited abstract method DataCenterInfo.getName() EurekaInstanceConfigBean.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka line 131 Java Problem -The method getId() is undefined for the type ProxyRouteLocator.ProxyRouteSpec PreDecorationFilter.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre line 60 Java Problem -The method getLocation() is undefined for the type ProxyRouteLocator.ProxyRouteSpec PreDecorationFilter.java /spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre line 55 Java Problem ----- - -==== Importing into other IDEs -Maven is well supported by most Java IDEs. Refer to you vendor documentation. - == 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 @@ -142,12 +136,17 @@ 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://support.springsource.com/spring_committer_signup[contributor's agreement]. +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. @@ -155,9 +154,9 @@ 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://github.com/spring-cloud/build/tree/master/eclipse-coding-conventions.xml[Spring + 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 - http://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter + 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 @@ -170,6 +169,139 @@ added after the original pull request but before a merge. * 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 http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], +* 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). \ No newline at end of file + 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 +---- + +true <1> + true + <2> + true + <3> + + + + + <4> + io.spring.javaformat + spring-javaformat-maven-plugin + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + +---- +<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 +---- + + + + + + +---- + +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. diff --git a/docs/pom.xml b/docs/pom.xml index e6dc302..cfd280e 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -10,43 +10,49 @@ .. spring-cloud-etcd-docs - pom + jar Spring Cloud Etcd Docs Spring Cloud Docs 1.0.0.BUILD-SNAPSHOT spring-cloud-etcd ${basedir}/.. + deploy - - - maven-deploy-plugin - - true - - - + src/main/asciidoc docs + + pl.project13.maven + git-commit-id-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.maven.plugins + maven-resources-plugin + + + org.codehaus.mojo + exec-maven-plugin + org.asciidoctor asciidoctor-maven-plugin - false org.apache.maven.plugins maven-antrun-plugin - false - org.codehaus.mojo - build-helper-maven-plugin - false + maven-deploy-plugin diff --git a/pom.xml b/pom.xml index 41e6bfa..0d5b3f7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.cloud spring-cloud-etcd 1.0.0.BUILD-SNAPSHOT pom @@ -13,7 +12,7 @@ org.springframework.cloud spring-cloud-build - 1.3.1.BUILD-SNAPSHOT + 3.1.0-SNAPSHOT @@ -83,6 +82,11 @@ + + 1.5.2.RELEASE + 1.3.2.BUILD-SNAPSHOT + + spring From a49686ca712f9188cf35cfe511636be1dfb11e85 Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Sun, 21 Nov 2021 16:43:29 +0300 Subject: [PATCH 4/6] Update etcd version in scripts, add docker-compose example --- docker-compose.yaml | 36 ++++++++++++++++++++++++++++ src/main/bash/travis_install_etcd.sh | 8 ++++--- src/main/bash/travis_run_etcd.sh | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yaml diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5f8575b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,36 @@ +version: "3.9" +services: + + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcd --version" + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdctl version" + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdctl endpoint health" + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdctl put foo bar" + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdctl get foo" + #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdutl version" + + etcd: + image: "gcr.io/etcd-development/etcd:v3.5.1" + container_name: "spring-cloud-etcd" + volumes: + - etcd-data:/etcd-data + command: [ + "etcd", + "--name=s1", + "--data-dir=/etcd-data", + "--listen-client-urls=http://0.0.0.0:2379", + "--advertise-client-urls=http://0.0.0.0:2379", + "--listen-peer-urls=http://0.0.0.0:2380", + "--initial-advertise-peer-urls=http://0.0.0.0:2380", + "--initial-cluster=s1=http://0.0.0.0:2380", + "--initial-cluster-token=tkn", + "--initial-cluster-state=new", + "--log-level=info", + "--logger=zap", + "--log-outputs=stderr" + ] + ports: + - "2379:2379" + - "2380:2380" + +volumes: + etcd-data: \ No newline at end of file diff --git a/src/main/bash/travis_install_etcd.sh b/src/main/bash/travis_install_etcd.sh index 984e482..8b83b3b 100755 --- a/src/main/bash/travis_install_etcd.sh +++ b/src/main/bash/travis_install_etcd.sh @@ -2,9 +2,9 @@ #!/usr/bin/env bash -ETCD_URL="https://github.com/coreos/etcd/releases/download" -ETCD_VER="v2.2.0" -ETCD_ARC="linux-amd64" +ETCD_URL="https://github.com/etcd-io/etcd/releases/download" +ETCD_VER="v3.5.1" +ETCD_ARC="darwin-amd64" # cleanup rm -rf etcd-${ETCD_VER}-${ETCD_ARC}.tar.gz @@ -22,4 +22,6 @@ curl -L ${ETCD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-${ETCD_ARC}.tar.gz \ # check ./etcd-dist/etcd --version +./etcd-dist/etcdctl version --version +./etcd-dist/etcdutl version --version diff --git a/src/main/bash/travis_run_etcd.sh b/src/main/bash/travis_run_etcd.sh index 99bf17d..d5f92d3 100755 --- a/src/main/bash/travis_run_etcd.sh +++ b/src/main/bash/travis_run_etcd.sh @@ -5,3 +5,4 @@ sleep 2 #./etcd-dist/etcdctl set /test/messages 'data' +#./etcd-dist/etcdctl --endpoints=localhost:2379 put /test/messages bar From 9c5cfbdcf058f2177f36b3f40f0ecc1e61cb5ddb Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Tue, 30 Nov 2021 21:53:23 +0300 Subject: [PATCH 5/6] Implemented Etcd discovery basing on spring-cloud-commons Updated project parent dependencies to last spring-cloud train. Removed deprecated netflix dependencies, replaced deprecated Lifecycle with Registration, ServiceRegistry and AutoRegistration semantics. --- docker-compose.yaml | 16 +- docs/pom.xml | 4 +- pom.xml | 9 +- spring-cloud-etcd-config/pom.xml | 16 +- spring-cloud-etcd-core/pom.xml | 23 +- .../cloud/etcd/ConditionalOnEtcdEnabled.java | 66 +++++ .../cloud/etcd/EtcdAutoConfiguration.java | 41 ++- .../cloud/etcd/EtcdEndpoint.java | 74 ++--- .../cloud/etcd/EtcdHealthIndicator.java | 35 +-- .../cloud/etcd/EtcdProperties.java | 47 ++-- spring-cloud-etcd-dependencies/pom.xml | 111 +++----- spring-cloud-etcd-discovery/pom.xml | 39 +-- .../etcd/discovery/EtcdDiscoveryClient.java | 105 ++------ .../EtcdDiscoveryClientConfiguration.java | 36 ++- .../discovery/EtcdDiscoveryProperties.java | 137 ++++------ .../cloud/etcd/discovery/EtcdLifecycle.java | 255 ------------------ .../EtcdRibbonClientConfiguration.java | 93 ------- .../cloud/etcd/discovery/EtcdServer.java | 58 ---- .../cloud/etcd/discovery/EtcdServerList.java | 106 -------- .../RibbonEtcdAutoConfiguration.java | 39 --- .../serviceregistry/EtcdAutoRegistration.java | 45 ++++ .../EtcdAutoServiceRegistration.java | 92 +++++++ ...oServiceRegistrationAutoConfiguration.java | 95 +++++++ .../serviceregistry/EtcdRegistration.java | 31 +++ .../serviceregistry/EtcdServiceRegistry.java | 106 ++++++++ .../EtcdServiceRegistryAutoConfiguration.java | 74 +++++ ...itional-spring-configuration-metadata.json | 28 ++ .../main/resources/META-INF/spring.factories | 6 +- spring-cloud-etcd-sample/pom.xml | 15 +- .../etcd/sample/SampleEtcdApplication.java | 9 +- .../src/main/resources/application.yml | 10 +- .../src/main/resources/etcd_request.http | 10 + src/main/bash/travis_install_etcd.sh | 5 +- 33 files changed, 819 insertions(+), 1017 deletions(-) create mode 100644 spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/ConditionalOnEtcdEnabled.java delete mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java delete mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java delete mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java delete mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java delete mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoRegistration.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistration.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistrationAutoConfiguration.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdRegistration.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistry.java create mode 100644 spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistryAutoConfiguration.java create mode 100644 spring-cloud-etcd-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 spring-cloud-etcd-sample/src/main/resources/etcd_request.http diff --git a/docker-compose.yaml b/docker-compose.yaml index 5f8575b..05ca4dc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,7 +8,7 @@ services: #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdctl get foo" #docker exec spring-cloud-etcd /bin/sh -c "/usr/local/bin/etcdutl version" - etcd: + etcd-v3: image: "gcr.io/etcd-development/etcd:v3.5.1" container_name: "spring-cloud-etcd" volumes: @@ -32,5 +32,19 @@ services: - "2379:2379" - "2380:2380" + etcd-v2: + image: "quay.io/coreos/etcd:v2.3.3" + container_name: "spring-cloud-etcd-v2" + volumes: + - etcd-data:/etcd-data + ports: + - "2379:2379" + - "2380:2380" + command: + [ + "--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001", + "--advertise-client-urls=http://0.0.0.0:2379" + ] + volumes: etcd-data: \ No newline at end of file diff --git a/docs/pom.xml b/docs/pom.xml index cfd280e..3961777 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,14 +6,14 @@ org.springframework.cloud spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT .. spring-cloud-etcd-docs jar Spring Cloud Etcd Docs Spring Cloud Docs - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT spring-cloud-etcd ${basedir}/.. diff --git a/pom.xml b/pom.xml index 0d5b3f7..83c85ec 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT pom Spring Cloud Etcd Spring Cloud Etcd @@ -67,8 +67,8 @@ org.springframework.cloud - spring-cloud-dependencies - Dalston.RELEASE + spring-cloud-commons-dependencies + ${spring-cloud-commons.version} pom import @@ -83,8 +83,7 @@ - 1.5.2.RELEASE - 1.3.2.BUILD-SNAPSHOT + 3.1.0-SNAPSHOT diff --git a/spring-cloud-etcd-config/pom.xml b/spring-cloud-etcd-config/pom.xml index 0620ef0..0452110 100644 --- a/spring-cloud-etcd-config/pom.xml +++ b/spring-cloud-etcd-config/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT .. @@ -24,20 +24,6 @@ org.springframework.cloud spring-cloud-context - - com.netflix.archaius - archaius-core - - - - commons-configuration - commons-configuration - - - org.springframework.boot - spring-boot-starter-test - test - diff --git a/spring-cloud-etcd-core/pom.xml b/spring-cloud-etcd-core/pom.xml index 64e2c6c..0e72caa 100644 --- a/spring-cloud-etcd-core/pom.xml +++ b/spring-cloud-etcd-core/pom.xml @@ -11,38 +11,19 @@ org.springframework.cloud spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT ../ org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.cloud - spring-cloud-commons + spring-boot-actuator-autoconfigure org.mousio etcd4j - - - io.netty - netty-handler - - - org.springframework.boot - spring-boot-starter-test - test - - diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/ConditionalOnEtcdEnabled.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/ConditionalOnEtcdEnabled.java new file mode 100644 index 0000000..570b93d --- /dev/null +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/ConditionalOnEtcdEnabled.java @@ -0,0 +1,66 @@ +/* + * 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.etcd; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import mousio.etcd4j.EtcdClient; + +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Conditional; + +/** + * Wrapper annotation to enable Etcd. + * @author Vladislav Khakin + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Conditional(ConditionalOnEtcdEnabled.OnEtcdEnabledCondition.class) +public @interface ConditionalOnEtcdEnabled { + + /** + * Verifies multiple conditions to see if Etcd should be enabled. + */ + class OnEtcdEnabledCondition extends AllNestedConditions { + + OnEtcdEnabledCondition() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + /** + * Etcd property is enabled. + */ + @ConditionalOnProperty(value = "spring.cloud.etcd.enabled", matchIfMissing = true) + static class FoundProperty { + + } + + /** + * Etcd client class found. + */ + @ConditionalOnClass(EtcdClient.class) + static class FoundClass { + + } + + } +} diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java index a1cc506..be70385 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdAutoConfiguration.java @@ -20,24 +20,33 @@ import mousio.etcd4j.EtcdClient; +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 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; + /** + * {@link EnableAutoConfiguration Auto-configuration} for Etcd Client. * @author Spencer Gibb + * @author Vladislav Khakin */ -@Configuration +@Configuration(proxyBeanMethods = false) @EnableConfigurationProperties +@ConditionalOnEtcdEnabled public class EtcdAutoConfiguration { @Bean @ConditionalOnMissingBean - public EtcdClient etcdClient() { + public EtcdClient etcdClient(EtcdProperties properties) { // TODO: support ssl // TODO: support authentication - return new EtcdClient(etcdProperties().getUris().toArray(new URI[] {})); + return new EtcdClient(properties.getUris().toArray(new URI[] {})); } @Bean @@ -46,15 +55,23 @@ public EtcdProperties etcdProperties() { return new EtcdProperties(); } - @Bean - @ConditionalOnMissingBean - public EtcdEndpoint etcdEndpoint() { - return new EtcdEndpoint(etcdClient()); - } + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(Endpoint.class) + protected static class EtcdHealthConfig { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnAvailableEndpoint + public EtcdEndpoint etcdEndpoint(EtcdClient etcd) { + return new EtcdEndpoint(etcd); + } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnEnabledHealthIndicator("etcd") + public EtcdHealthIndicator etcdHealthIndicator(EtcdClient etcd) { + return new EtcdHealthIndicator(etcd); + } - @Bean - @ConditionalOnMissingBean - public EtcdHealthIndicator etcdHealthIndicator(EtcdClient client) { - return new EtcdHealthIndicator(client); } } diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java index ae10968..a1094d8 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdEndpoint.java @@ -17,70 +17,52 @@ package org.springframework.cloud.etcd; import mousio.etcd4j.EtcdClient; +import mousio.etcd4j.responses.EtcdVersionResponse; -import org.springframework.boot.actuate.endpoint.AbstractEndpoint; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.util.Assert; +//TODO: do we actually need specific endpoint? is health indicator enough? /** + * {@link Endpoint @Endpoint} to expose Etcd details. * @author Spencer Gibb + * @author Vladislav Khakin */ -@ConfigurationProperties(prefix = "endpoints.etcd", ignoreUnknownFields = false) -public class EtcdEndpoint extends AbstractEndpoint { +@Endpoint(id = "etcd") +public class EtcdEndpoint { - private EtcdClient etcd; + private final EtcdClient etcd; public EtcdEndpoint(EtcdClient etcd) { - super("etcd", false, true); + Assert.notNull(etcd, "Etcd must not be null"); this.etcd = etcd; } - @Override - public Data invoke() { - Data data = new Data(); - data.setVersion(etcd.getVersion()); - return data; + @ReadOperation + public EtcdData etcdData() { + EtcdVersionResponse version = etcd.version(); + return new EtcdData(version.cluster, version.server); } - public static class Data { - private String version; + /** + * Etcd details, primarily intended for serialization to JSON. + */ + public static class EtcdData { + private final String clusterVersion; + private final String serverVersion; - public Data() { + public EtcdData(String clusterVersion, String serverVersion) { + this.clusterVersion = clusterVersion; + this.serverVersion = serverVersion; } - public Data(String version) { - this.version = version; + public String getServerVersion() { + return serverVersion; } - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - Data data = (Data) o; - - return version != null ? version.equals(data.version) : data.version == null; - } - - @Override - public int hashCode() { - return version != null ? version.hashCode() : 0; - } - - @Override - public String toString() { - return String.format("Data{version='%s'}", version); + public String getClusterVersion() { + return clusterVersion; } } } diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java index 97b7742..9a42106 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdHealthIndicator.java @@ -22,7 +22,10 @@ import org.springframework.boot.actuate.health.Health; /** + * A {@link org.springframework.boot.actuate.health.HealthIndicator} that checks the + * status of the Etcd connection. * @author Spencer Gibb + * @author Vladislav Khakin */ public class EtcdHealthIndicator extends AbstractHealthIndicator { @@ -33,41 +36,13 @@ public EtcdHealthIndicator(EtcdClient client) { } @Override - protected void doHealthCheck(Health.Builder builder) throws Exception { + protected void doHealthCheck(Health.Builder builder) { try { - String version = client.getVersion(); + String version = client.version().getServer(); builder.withDetail("version", version).up(); } catch (Exception e) { builder.down(e); } } - - public EtcdClient getClient() { - return client; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - EtcdHealthIndicator that = (EtcdHealthIndicator) o; - - return client.equals(that.client); - } - - @Override - public int hashCode() { - return client.hashCode(); - } - - @Override - public String toString() { - return String.format("EtcdHealthIndicator{client=%s}", client); - } } diff --git a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java index 1dbb3dd..bdd9c3d 100644 --- a/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java +++ b/spring-cloud-etcd-core/src/main/java/org/springframework/cloud/etcd/EtcdProperties.java @@ -20,17 +20,24 @@ import java.util.Arrays; import java.util.List; -import javax.validation.constraints.NotNull; - import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.Assert; /** + * Properties related to connecting to Etcd. + * * @author Spencer Gibb + * @author Vladislav Khakin */ -@ConfigurationProperties("spring.cloud.etcd") +@ConfigurationProperties(EtcdProperties.PREFIX) public class EtcdProperties { - @NotNull - private List uris = Arrays.asList(URI.create("http://localhost:4001")); + + /** + * Configuration prefix. + */ + public static final String PREFIX = "spring.cloud.etcd"; + + private List uris = Arrays.asList(URI.create("http://localhost:2379")); private boolean enabled = true; @@ -38,6 +45,7 @@ public EtcdProperties() { } public EtcdProperties(List uris, boolean enabled) { + Assert.notEmpty(uris, "Uris must not be empty"); this.uris = uris; this.enabled = enabled; } @@ -58,32 +66,11 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - EtcdProperties that = (EtcdProperties) o; - - if (enabled != that.enabled) { - return false; - } - return uris != null ? uris.equals(that.uris) : that.uris == null; - } - - @Override - public int hashCode() { - int result = uris != null ? uris.hashCode() : 0; - result = 31 * result + (enabled ? 1 : 0); - return result; - } - @Override public String toString() { - return String.format("EtcdProperties{uris=%s, enabled=%s}", uris, enabled); + return "EtcdProperties{" + + "uris=" + uris + + ", enabled=" + enabled + + '}'; } } diff --git a/spring-cloud-etcd-dependencies/pom.xml b/spring-cloud-etcd-dependencies/pom.xml index e9fbc1f..27fdc95 100644 --- a/spring-cloud-etcd-dependencies/pom.xml +++ b/spring-cloud-etcd-dependencies/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-etcd-dependencies - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT pom spring-cloud-etcd-dependencies Spring Cloud Etcd Dependencies @@ -18,11 +18,7 @@ - 1.1.0.BUILD-SNAPSHOT - 1.1.0.BUILD-SNAPSHOT - 0.7.1 - 2.7.0 - 4.1.0.Beta5 + 2.18.0 1.8 true true @@ -48,81 +44,46 @@ ${project.version} - - - org.springframework.cloud - spring-cloud-commons - ${spring-cloud-commons.version} - - - org.springframework.cloud - spring-cloud-netflix - ${spring-cloud-netflix.version} - - - org.springframework.cloud - spring-cloud-context - ${spring-cloud-commons.version} - - - org.springframework.cloud - spring-cloud-bus - ${spring.cloud.bus.version} - - - org.springframework.boot - spring-boot-starter-amqp - - - org.springframework.integration - spring-integration-amqp - - - org.springframework.cloud - spring-cloud-spring-service-connector - - - org.springframework.cloud - spring-cloud-localconfig-connector - - - org.springframework.cloud - spring-cloud-cloudfoundry-connector - - - - - org.springframework.cloud - spring-cloud-netflix-core - ${spring-cloud-netflix.version} - - - com.netflix.archaius - archaius-core - ${archaius.version} - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - commons-configuration - commons-configuration - ${common.configuration.version} - + org.mousio etcd4j ${etcd4j.version} - - io.netty - netty-codec-http - ${netty.version} - - - io.netty - netty-handler - ${netty.version} - diff --git a/spring-cloud-etcd-discovery/pom.xml b/spring-cloud-etcd-discovery/pom.xml index d822144..9e21802 100644 --- a/spring-cloud-etcd-discovery/pom.xml +++ b/spring-cloud-etcd-discovery/pom.xml @@ -11,48 +11,23 @@ org.springframework.cloud spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT .. - org.springframework.cloud - spring-cloud-etcd-core + org.springframework.boot + spring-boot-configuration-processor + true org.springframework.cloud - spring-cloud-netflix-core - - - com.netflix.archaius - archaius-core - - - - commons-configuration - commons-configuration - - - com.netflix.ribbon - ribbon - - - com.netflix.ribbon - ribbon-core - - - com.netflix.ribbon - ribbon-httpclient - - - com.netflix.ribbon - ribbon-loadbalancer + spring-cloud-etcd-core - org.springframework.boot - spring-boot-starter-test - test + org.springframework.cloud + spring-cloud-commons diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java index dd78b93..d876c4b 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClient.java @@ -16,67 +16,61 @@ package org.springframework.cloud.etcd.discovery; + import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeoutException; import mousio.etcd4j.EtcdClient; +import mousio.etcd4j.responses.EtcdAuthenticationException; import mousio.etcd4j.responses.EtcdException; import mousio.etcd4j.responses.EtcdKeysResponse; -import org.springframework.beans.BeansException; import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.util.ReflectionUtils; + +import static org.springframework.util.ReflectionUtils.rethrowRuntimeException; /** + * Etcd version of {@link DiscoveryClient}. * @author Spencer Gibb + * @author Vladislav Khakin */ -public class EtcdDiscoveryClient implements DiscoveryClient, ApplicationContextAware { +public class EtcdDiscoveryClient implements DiscoveryClient { private final EtcdClient etcd; - - private final EtcdLifecycle lifecycle; - private final EtcdDiscoveryProperties properties; - private ApplicationContext context; - - public EtcdDiscoveryClient(EtcdClient etcd, EtcdLifecycle lifecycle, EtcdDiscoveryProperties properties) { + public EtcdDiscoveryClient(EtcdClient etcd, EtcdDiscoveryProperties properties) { this.etcd = etcd; - this.lifecycle = lifecycle; this.properties = properties; } @Override public String description() { - return "Spring Cloud etcd Discovery Client"; - } - - @Override - public ServiceInstance getLocalServiceInstance() { - return new DefaultServiceInstance(lifecycle.getService().getAppName(), - properties.getHostname(), lifecycle.getConfiguredPort(), false); + return "Spring Cloud Etcd Discovery Client"; } @Override public List getInstances(final String serviceId) { List instances = null; try { - EtcdKeysResponse response = etcd.getDir(lifecycle.getAppKey(serviceId)).send().get(); +// todo: extract service key building to utils + EtcdKeysResponse response = etcd + .getDir(properties.getDiscoveryPrefix() + "/" + serviceId).send() + .get(); List nodes = response.node.nodes; instances = new ArrayList<>(); for (EtcdKeysResponse.EtcdNode node : nodes) { String[] parts = node.value.split(":"); - instances.add(new DefaultServiceInstance(serviceId, parts[0], Integer.parseInt(parts[1]), false)); + instances.add(new DefaultServiceInstance("", serviceId, parts[0], + Integer.parseInt(parts[1]), false)); } } - catch (IOException | TimeoutException | EtcdException e) { - ReflectionUtils.rethrowRuntimeException(e); + catch (IOException | TimeoutException | EtcdException | EtcdAuthenticationException e) { + rethrowRuntimeException(e); } return instances; } @@ -85,7 +79,8 @@ public List getInstances(final String serviceId) { public List getServices() { List services = null; try { - EtcdKeysResponse response = etcd.getDir(properties.getDiscoveryPrefix()).send().get(); + EtcdKeysResponse response = etcd.getDir(properties.getDiscoveryPrefix()) + .send().get(); List nodes = response.node.nodes; services = new ArrayList<>(); for (EtcdKeysResponse.EtcdNode node : nodes) { @@ -94,67 +89,9 @@ public List getServices() { services.add(serviceId); } } - catch (IOException | EtcdException | TimeoutException e) { - ReflectionUtils.rethrowRuntimeException(e); + catch (IOException | EtcdException | TimeoutException | EtcdAuthenticationException e) { + rethrowRuntimeException(e); } return services; } - - @Override - public void setApplicationContext(ApplicationContext context) throws BeansException { - this.context = context; - } - - public EtcdLifecycle getLifecycle() { - return lifecycle; - } - - public EtcdDiscoveryProperties getProperties() { - return properties; - } - - public ApplicationContext getContext() { - return context; - } - - public void setContext(ApplicationContext context) { - this.context = context; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - EtcdDiscoveryClient that = (EtcdDiscoveryClient) o; - - if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) { - return false; - } - if (lifecycle != null ? !lifecycle.equals(that.lifecycle) : that.lifecycle != null) { - return false; - } - if (properties != null ? !properties.equals(that.properties) : that.properties != null) { - return false; - } - return context != null ? context.equals(that.context) : that.context == null; - } - - @Override - public int hashCode() { - int result = etcd != null ? etcd.hashCode() : 0; - result = 31 * result + (lifecycle != null ? lifecycle.hashCode() : 0); - result = 31 * result + (properties != null ? properties.hashCode() : 0); - result = 31 * result + (context != null ? context.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return String.format("EtcdDiscoveryClient{etcd=%s, lifecycle=%s, properties=%s, context=%s}", etcd, lifecycle, properties, context); - } } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java index d098d8e..911fd69 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryClientConfiguration.java @@ -18,34 +18,46 @@ import mousio.etcd4j.EtcdClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.CommonsClientAutoConfiguration; +import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; +import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; +import org.springframework.cloud.commons.util.UtilAutoConfiguration; +import org.springframework.cloud.etcd.ConditionalOnEtcdEnabled; +import org.springframework.cloud.etcd.EtcdAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; /** + * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration * + * * Auto-configuration} that configures blocking {@link DiscoveryClient}. * @author Spencer Gibb + * @author Vladislsav Khakin */ -@Configuration +@Configuration(proxyBeanMethods = false) +@ConditionalOnDiscoveryEnabled +@ConditionalOnBlockingDiscoveryEnabled +@ConditionalOnEtcdEnabled @EnableScheduling @EnableConfigurationProperties +@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class }) +@AutoConfigureAfter({ UtilAutoConfiguration.class, EtcdAutoConfiguration.class }) public class EtcdDiscoveryClientConfiguration { - @Autowired - private EtcdClient client; - - @Bean - public EtcdLifecycle etcdLifecycle() { - return new EtcdLifecycle(client, etcdDiscoveryProperties()); - } - @Bean - public EtcdDiscoveryClient etcdDiscoveryClient() { - return new EtcdDiscoveryClient(client, etcdLifecycle(), etcdDiscoveryProperties()); + @ConditionalOnMissingBean + public EtcdDiscoveryClient etcdDiscoveryClient(EtcdClient etcd, EtcdDiscoveryProperties properties) { + return new EtcdDiscoveryClient(etcd, properties); } @Bean + @ConditionalOnMissingBean public EtcdDiscoveryProperties etcdDiscoveryProperties() { return new EtcdDiscoveryProperties(); } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java index 30c314d..9ada56f 100644 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdDiscoveryProperties.java @@ -27,20 +27,39 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.style.ToStringCreator; import org.springframework.util.ReflectionUtils; /** + * Defines configuration for Etcd service discovery and registration. + * * @author Spencer Gibb + * @author Vladislav Khakin */ -@ConfigurationProperties("spring.cloud.etcd.discovery") +@ConfigurationProperties(EtcdDiscoveryProperties.PREFIX) public class EtcdDiscoveryProperties { private static final Log log = LogFactory.getLog(EtcdDiscoveryProperties.class); + /** + * Etcd discovery properties prefix. + */ + public static final String PREFIX = "spring.cloud.etcd.discovery"; + /** Is service discovery enabled? */ private boolean enabled = true; + /** Register as a service in Etcd. */ + private boolean register = true; + + /** Disable automatic de-registration of service in Etcd. */ + private boolean deregister = true; + + /** Discovery prefix. */ private String discoveryPrefix = "/spring/cloud/discovery"; + /** Port to register the service under (defaults to listening port). */ + private Integer port; + private HostInfo hostInfo = initHostInfo(); private String ipAddress = this.hostInfo.getIpAddress(); @@ -65,11 +84,11 @@ private HostInfo initHostInfo() { public static InetAddress getIpAddress() { try { for (Enumeration enumNic = NetworkInterface - .getNetworkInterfaces(); enumNic.hasMoreElements(); ) { + .getNetworkInterfaces(); enumNic.hasMoreElements();) { NetworkInterface ifc = enumNic.nextElement(); if (ifc.isUp()) { for (Enumeration enumAddr = ifc - .getInetAddresses(); enumAddr.hasMoreElements(); ) { + .getInetAddresses(); enumAddr.hasMoreElements();) { InetAddress address = enumAddr.nextElement(); if (address instanceof Inet4Address && !address.isLoopbackAddress()) { @@ -102,6 +121,22 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } + public boolean isRegister() { + return register; + } + + public void setRegister(boolean register) { + this.register = register; + } + + public boolean isDeregister() { + return this.deregister; + } + + public void setDeregister(boolean deregister) { + this.deregister = deregister; + } + public String getDiscoveryPrefix() { return discoveryPrefix; } @@ -118,6 +153,14 @@ private void setHostInfo(HostInfo hostInfo) { this.hostInfo = hostInfo; } + public Integer getPort() { + return this.port; + } + + public void setPort(Integer port) { + this.port = port; + } + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } @@ -150,63 +193,21 @@ public void setHeartbeatInterval(int heartbeatInterval) { this.heartbeatInterval = heartbeatInterval; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - EtcdDiscoveryProperties that = (EtcdDiscoveryProperties) o; - - if (enabled != that.enabled) { - return false; - } - if (preferIpAddress != that.preferIpAddress) { - return false; - } - if (ttl != that.ttl) { - return false; - } - if (heartbeatInterval != that.heartbeatInterval) { - return false; - } - if (discoveryPrefix != null ? !discoveryPrefix.equals(that.discoveryPrefix) : that.discoveryPrefix != null) { - return false; - } - if (hostInfo != null ? !hostInfo.equals(that.hostInfo) : that.hostInfo != null) { - return false; - } - if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) { - return false; - } - return hostname != null ? hostname.equals(that.hostname) : that.hostname == null; - } - - @Override - public int hashCode() { - int result = (enabled ? 1 : 0); - result = 31 * result + (discoveryPrefix != null ? discoveryPrefix.hashCode() : 0); - result = 31 * result + (hostInfo != null ? hostInfo.hashCode() : 0); - result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0); - result = 31 * result + (hostname != null ? hostname.hashCode() : 0); - result = 31 * result + (preferIpAddress ? 1 : 0); - result = 31 * result + ttl; - result = 31 * result + heartbeatInterval; - return result; - } - @Override public String toString() { - return String.format( - "EtcdDiscoveryProperties{enabled=%s, discoveryPrefix='%s', hostInfo=%s, ipAddress='%s', hostname='%s', preferIpAddress=%s, ttl=%d, heartbeatInterval=%d}", - enabled, discoveryPrefix, hostInfo, ipAddress, hostname, preferIpAddress, ttl, heartbeatInterval); + return new ToStringCreator(this).append("enabled", enabled) + .append("register", register).append("deregister", deregister) + .append("discoveryPrefix", discoveryPrefix).append("port", port) + .append("hostInfo", hostInfo).append("ipAddress", ipAddress) + .append("hostname", hostname).append("preferIpAddress", preferIpAddress) + .append("ttl", ttl).append("heartbeatInterval", heartbeatInterval) + .toString(); } private class HostInfo { + private final String ipAddress; + private final String hostname; HostInfo(String ipAddress, String hostname) { @@ -222,33 +223,11 @@ public String getHostname() { return hostname; } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - HostInfo hostInfo = (HostInfo) o; - - if (!ipAddress.equals(hostInfo.ipAddress)) { - return false; - } - return hostname.equals(hostInfo.hostname); - } - - @Override - public int hashCode() { - int result = ipAddress.hashCode(); - result = 31 * result + hostname.hashCode(); - return result; - } - @Override public String toString() { - return String.format("HostInfo{ipAddress='%s', hostname='%s'}", ipAddress, hostname); + return String.format("HostInfo{ipAddress='%s', hostname='%s'}", ipAddress, + hostname); } + } } diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java deleted file mode 100644 index beaad17..0000000 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdLifecycle.java +++ /dev/null @@ -1,255 +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.etcd.discovery; - -import java.io.IOException; -import java.util.concurrent.TimeoutException; - -import mousio.etcd4j.EtcdClient; -import mousio.etcd4j.responses.EtcdException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.cloud.client.discovery.AbstractDiscoveryLifecycle; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -/** - * @author Spencer Gibb - */ -public class EtcdLifecycle extends AbstractDiscoveryLifecycle { - - private static final Log log = LogFactory.getLog(EtcdLifecycle.class); - - private final EtcdClient etcd; - private final EtcdDiscoveryProperties props; - private final Service service = new Service(); - - public EtcdLifecycle(EtcdClient etcd, EtcdDiscoveryProperties props) { - this.etcd = etcd; - this.props = props; - } - - @Override - protected void register() { - Assert.notNull(service.getPort(), "service.port has not been set"); - - service.setAppName(getAppName()); - service.setId(getContext().getId()); - - register(service); - } - - @Scheduled(initialDelayString = "${spring.cloud.etcd.discovery.heartbeatInterval:25000}", fixedRateString = "${spring.cloud.etcd.discovery.heartbeatInterval:25000}") - protected void sendHeartbeat() { - register(); - } - - @Override - protected void registerManagement() { - Service management = new Service(); - management.setId(getManagementServiceId()); - management.setAppName(getManagementServiceName()); - management.setPort(getManagementPort()); - - register(management); - } - - protected void register(Service service) { - try { - log.info("Registering service with etcd: " + service); - String key = getServiceKey(service.appName, service.getId()); - //TODO: what should be serialized about the service? - String value = props.getHostname() + ":" + service.getPort(); - etcd.put(key, value).ttl(props.getTtl()).send().get(); - } - catch (IOException | TimeoutException | EtcdException e) { - ReflectionUtils.rethrowRuntimeException(e); - } - } - - private String getServiceKey(String appName, String serviceId) { - return getAppKey(appName) + "/" + serviceId; - } - - public String getAppKey(String appName) { - return props.getDiscoveryPrefix() + "/" + appName; - } - - @Override - protected int getConfiguredPort() { - return service.getPort() == null ? 0 : service.getPort(); - } - - @Override - protected void setConfiguredPort(int port) { - service.setPort(port); - } - - @Override - protected EtcdDiscoveryProperties getConfiguration() { - return props; - } - - @Override - protected void deregister() { - deregister(getAppName(), getContext().getId()); - } - - @Override - protected void deregisterManagement() { - deregister(getAppName(), getManagementServiceName()); - } - - private void deregister(String appName, String serviceId) { - try { - etcd.delete(getServiceKey(appName, serviceId)).send(); - } - catch (IOException e) { - ReflectionUtils.rethrowRuntimeException(e); - } - } - - @Override - protected boolean isEnabled() { - return props.isEnabled(); - } - - public EtcdClient getEtcd() { - return etcd; - } - - public EtcdDiscoveryProperties getProps() { - return props; - } - - public Service getService() { - return service; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - EtcdLifecycle that = (EtcdLifecycle) o; - - if (etcd != null ? !etcd.equals(that.etcd) : that.etcd != null) { - return false; - } - if (props != null ? !props.equals(that.props) : that.props != null) { - return false; - } - if (service != null ? !service.equals(that.service) : that.service != null) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = etcd != null ? etcd.hashCode() : 0; - result = 31 * result + (props != null ? props.hashCode() : 0); - result = 31 * result + (service != null ? service.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return String.format("EtcdLifecycle{etcd=%s, props=%s, service=%s}", etcd, props, service); - } - - class Service { - String appName; - String id; - Integer port; - - Service() { - } - - Service(String appName, String id, Integer port) { - this.appName = appName; - this.id = id; - this.port = port; - } - - public String getAppName() { - return appName; - } - - public void setAppName(String appName) { - this.appName = appName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Integer getPort() { - return port; - } - - public void setPort(Integer port) { - this.port = port; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - Service service = (Service) o; - - if (appName != null ? !appName.equals(service.appName) : service.appName != null) { - return false; - } - if (id != null ? !id.equals(service.id) : service.id != null) { - return false; - } - return port != null ? port.equals(service.port) : service.port == null; - } - - @Override - public int hashCode() { - int result = appName != null ? appName.hashCode() : 0; - result = 31 * result + (id != null ? id.hashCode() : 0); - result = 31 * result + (port != null ? port.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return String.format("Service{appName='%s', id='%s', port=%d}", appName, id, port); - } - } - -} - diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java deleted file mode 100644 index 33806e2..0000000 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdRibbonClientConfiguration.java +++ /dev/null @@ -1,93 +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.etcd.discovery; - -import javax.annotation.PostConstruct; - -import com.netflix.client.config.IClientConfig; -import com.netflix.config.ConfigurationManager; -import com.netflix.config.DynamicPropertyFactory; -import com.netflix.config.DynamicStringProperty; -import com.netflix.loadbalancer.ServerList; -import mousio.etcd4j.EtcdClient; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses; -import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity; - -/** - * @author Spencer Gibb - */ -@Configuration -public class EtcdRibbonClientConfiguration { - @Autowired - private EtcdClient etcd; - - @Autowired - private EtcdDiscoveryProperties props; - - @Value("${ribbon.client.name}") - private String serviceId = "client"; - - protected static final String VALUE_NOT_SET = "__not__set__"; - - protected static final String DEFAULT_NAMESPACE = "ribbon"; - - public EtcdRibbonClientConfiguration() { - } - - public EtcdRibbonClientConfiguration(String serviceId) { - this.serviceId = serviceId; - } - - @Bean - @ConditionalOnMissingBean - public ServerList ribbonServerList(IClientConfig config) { - EtcdServerList serverList = new EtcdServerList(etcd, props, serviceId); - return serverList; - } - - @PostConstruct - public void preprocess() { - // FIXME: what should this be? - setProp(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId); - setProp(this.serviceId, EnableZoneAffinity.key(), "true"); - } - - protected void setProp(String serviceId, String suffix, String value) { - // how to set the namespace properly? - String key = getKey(serviceId, suffix); - DynamicStringProperty property = getProperty(key); - if (property.get().equals(VALUE_NOT_SET)) { - ConfigurationManager.getConfigInstance().setProperty(key, value); - } - } - - protected DynamicStringProperty getProperty(String key) { - return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET); - } - - protected String getKey(String serviceId, String suffix) { - return serviceId + "." + DEFAULT_NAMESPACE + "." + suffix; - } - -} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java deleted file mode 100644 index c1ca009..0000000 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServer.java +++ /dev/null @@ -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.etcd.discovery; - -import com.netflix.loadbalancer.Server; - -/** - * @author Spencer Gibb - */ -public class EtcdServer extends Server { - - private final MetaInfo metaInfo; - - public EtcdServer(final String appName, final String instanceId, String host, - String port) { - super(host, new Integer(port)); - metaInfo = new MetaInfo() { - @Override - public String getAppName() { - return appName; - } - - @Override - public String getServerGroup() { - return null; - } - - @Override - public String getServiceIdForDiscovery() { - return null; - } - - @Override - public String getInstanceId() { - return instanceId; - } - }; - } - - @Override - public MetaInfo getMetaInfo() { - return metaInfo; - } -} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java deleted file mode 100644 index 89d80a3..0000000 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/EtcdServerList.java +++ /dev/null @@ -1,106 +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.etcd.discovery; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeoutException; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractServerList; -import mousio.etcd4j.EtcdClient; -import mousio.etcd4j.responses.EtcdException; -import mousio.etcd4j.responses.EtcdKeysResponse; -import mousio.etcd4j.responses.EtcdKeysResponse.EtcdNode; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.util.ReflectionUtils; - -/** - * @author Spencer Gibb - */ -public class EtcdServerList extends AbstractServerList { - - private static final Log log = LogFactory.getLog(EtcdServerList.class); - - private EtcdClient etcd; - private EtcdDiscoveryProperties props; - private String serviceId; - - public EtcdServerList() { - } - - public EtcdServerList(EtcdClient etcd, EtcdDiscoveryProperties props, String serviceId) { - this.etcd = etcd; - this.props = props; - this.serviceId = serviceId; - } - - @Override - public void initWithNiwsConfig(IClientConfig clientConfig) { - this.serviceId = clientConfig.getClientName(); - } - - @Override - public List getInitialListOfServers() { - return getServers(); - } - - @Override - public List getUpdatedListOfServers() { - return getServers(); - } - - private List getServers() { - List servers = null; - try { - if (etcd == null) { - return Collections.emptyList(); - } - - EtcdKeysResponse response = etcd - .getDir(props.getDiscoveryPrefix() + "/" + serviceId).send().get(); - - - if (response.node.nodes == null || response.node.nodes.isEmpty()) { - return Collections.emptyList(); - } - - servers = new ArrayList<>(); - for (EtcdNode node : response.node.nodes) { - String[] appInfo = getAppInfo(node.key); - String[] strings = node.value.split(":"); - - EtcdServer server = new EtcdServer(appInfo[0], appInfo[1], strings[0], strings[1]); - servers.add(server); - } - } - catch (IOException | TimeoutException | EtcdException e) { - ReflectionUtils.rethrowRuntimeException(e); - } - - return servers; - } - - private String[] getAppInfo(String key) { - String serviceNameId = key.replace(props.getDiscoveryPrefix(), ""); - return serviceNameId.substring(1).split("/"); - } -} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java deleted file mode 100644 index 4a33809..0000000 --- a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/discovery/RibbonEtcdAutoConfiguration.java +++ /dev/null @@ -1,39 +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.etcd.discovery; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; -import org.springframework.cloud.netflix.ribbon.RibbonClients; -import org.springframework.cloud.netflix.ribbon.SpringClientFactory; -import org.springframework.context.annotation.Configuration; - -/** - * @author Dave Syer - */ -@Configuration -@EnableConfigurationProperties -@ConditionalOnBean(SpringClientFactory.class) -@ConditionalOnProperty(value = "ribbon.etcd.enabled", matchIfMissing = true) -@AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = EtcdRibbonClientConfiguration.class) -public class RibbonEtcdAutoConfiguration { - -} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoRegistration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoRegistration.java new file mode 100644 index 0000000..be9b3bf --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoRegistration.java @@ -0,0 +1,45 @@ +/* + * 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.etcd.serviceregistry; + +import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.cloud.commons.util.IdUtils; +import org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties; +import org.springframework.context.ApplicationContext; + +/** + * {@link EtcdRegistration} that populate registration automatically from properties. + * @author Vladislav Khakin + * + * @see Registration + */ +public class EtcdAutoRegistration extends EtcdRegistration { + + public EtcdAutoRegistration(ApplicationContext context, + EtcdDiscoveryProperties properties) { + //todo: add properties validation + super(IdUtils.getDefaultInstanceId(context.getEnvironment()), + context.getEnvironment().getProperty("spring.application.name", + "application"), + properties.getHostname(), properties.getPort(), false); + } + + public static EtcdAutoRegistration registration(ApplicationContext context, + EtcdDiscoveryProperties discoveryProperties) { + return new EtcdAutoRegistration(context, discoveryProperties); + } +} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistration.java new file mode 100644 index 0000000..3a54513 --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistration.java @@ -0,0 +1,92 @@ +/* + * 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.etcd.serviceregistry; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; +import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties; +import org.springframework.scheduling.annotation.Scheduled; + +/** + * Etcd {@link AbstractAutoServiceRegistration} that uses {@link EtcdServiceRegistry} to + * register and de-register instances. + * @author Vladislav Khakin + */ +public class EtcdAutoServiceRegistration + extends AbstractAutoServiceRegistration { + + private static final Log log = LogFactory.getLog(EtcdAutoServiceRegistration.class); + + private final EtcdDiscoveryProperties properties; + private final EtcdAutoRegistration registration; + + public EtcdAutoServiceRegistration(ServiceRegistry serviceRegistry, + AutoServiceRegistrationProperties autoRegistrationProperties, + EtcdDiscoveryProperties discoveryProperties, + EtcdAutoRegistration registration) { + super(serviceRegistry, autoRegistrationProperties); + this.properties = discoveryProperties; + this.registration = registration; + } + + @Scheduled(initialDelayString = "${spring.cloud.etcd.discovery.heartbeatInterval:25000}", fixedRateString = "${spring.cloud.etcd.discovery.heartbeatInterval:25000}") + protected void sendHeartbeat() { + register(); + } + + @Override + protected EtcdRegistration getRegistration() { + // TODO: process random port generation for web server + return registration; + } + + @Override + protected EtcdRegistration getManagementRegistration() { + return null; + } + + @Override + protected Object getConfiguration() { + return properties; + } + + @Override + protected boolean isEnabled() { + return properties.isEnabled(); + } + + @Override + protected void register() { + if (!properties.isRegister()) { + log.debug("Etcd Registration disabled."); + return; + } + super.register(); + } + + @Override + protected void deregister() { + if (!this.properties.isRegister() || !this.properties.isDeregister()) { + return; + } + super.deregister(); + } +} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistrationAutoConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistrationAutoConfiguration.java new file mode 100644 index 0000000..25901da --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdAutoServiceRegistrationAutoConfiguration.java @@ -0,0 +1,95 @@ +/* + * Copyright 2013-2016 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.etcd.serviceregistry; + +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.client.serviceregistry.AutoServiceRegistration; +import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; +import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import org.springframework.cloud.etcd.ConditionalOnEtcdEnabled; +import org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +/** + * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration * + * Auto-configuration} that auto-register application in Etcd. + * @author Vladislav Khakin + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBean(AutoServiceRegistrationProperties.class) +@ConditionalOnEtcdEnabled +@Conditional(EtcdAutoServiceRegistrationAutoConfiguration.OnEtcdRegistrationEnabledCondition.class) +@ConditionalOnMissingBean(AutoServiceRegistration.class) +@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class, EtcdServiceRegistryAutoConfiguration.class }) +public class EtcdAutoServiceRegistrationAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + EtcdAutoServiceRegistration etcdAutoServiceRegistration( + ServiceRegistry serviceRegistry, + AutoServiceRegistrationProperties autoServiceRegistrationProperties, + EtcdDiscoveryProperties properties, EtcdAutoRegistration autoRegistration) { + return new EtcdAutoServiceRegistration(serviceRegistry, + autoServiceRegistrationProperties, properties, autoRegistration); + } + + @Bean + @ConditionalOnMissingBean + EtcdAutoRegistration etcdAutoRegistration(ApplicationContext context, + EtcdDiscoveryProperties properties) { + //todo add auto port detection + return new EtcdAutoRegistration(context, properties); + } + + protected static class OnEtcdRegistrationEnabledCondition extends AllNestedConditions { + + OnEtcdRegistrationEnabledCondition() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) + static class AutoRegistrationEnabledClass { + + } + + @ConditionalOnProperty(value = "spring.cloud.etcd.service-registry.auto-registration.enabled", + matchIfMissing = true) + static class EtcdAutoRegistrationEnabledClass { + + } + + @ConditionalOnProperty(value = "spring.cloud.service-registry.enabled", matchIfMissing = true) + static class ServiceRegistryEnabledClass { + + } + + @ConditionalOnProperty(value = "spring.cloud.etcd.service-registry.enabled", matchIfMissing = true) + static class EtcdServiceRegistryEnabledClass { + + } + + } + +} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdRegistration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdRegistration.java new file mode 100644 index 0000000..67dfcd6 --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdRegistration.java @@ -0,0 +1,31 @@ +/* + * 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.etcd.serviceregistry; + +import org.springframework.cloud.client.DefaultServiceInstance; +import org.springframework.cloud.client.serviceregistry.Registration; + +/** + * {@link Registration} in Etcd. Use default {@link DefaultServiceInstance} as a data + * container. + * @author Vldislav Khakin + */ +public class EtcdRegistration extends DefaultServiceInstance implements Registration { + public EtcdRegistration(String instanceId, String serviceId, String host, int port, boolean secure) { + super(instanceId, serviceId, host, port, secure); + } +} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistry.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistry.java new file mode 100644 index 0000000..1fe08ef --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistry.java @@ -0,0 +1,106 @@ +/* + * 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.etcd.serviceregistry; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import mousio.etcd4j.EtcdClient; +import mousio.etcd4j.responses.EtcdAuthenticationException; +import mousio.etcd4j.responses.EtcdException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties; + +import static org.springframework.util.ReflectionUtils.rethrowRuntimeException; + + +/** + * {@link ServiceRegistry} that register and deregister services in Etcd. + * @author Vladislav Khakin + */ +public class EtcdServiceRegistry implements ServiceRegistry { + + private static final Log log = LogFactory.getLog(EtcdServiceRegistry.class); + + private final EtcdClient etcd; + private final EtcdDiscoveryProperties properties; + + public EtcdServiceRegistry(EtcdClient etcd, EtcdDiscoveryProperties properties) { + this.etcd = etcd; + this.properties = properties; + } + + @Override + public void register(EtcdRegistration registration) { + try { + log.info("Registering service with etcd: " + registration); + String key = getServiceKey(registration); + // TODO: what should be serialized about the service? + String value = registration.getHost() + ":" + registration.getPort(); + etcd.put(key, value).timeout(2, TimeUnit.SECONDS).ttl(properties.getTtl()) + .send().get(); + } + catch (IOException | TimeoutException | EtcdException + | EtcdAuthenticationException e) { + // todo: add fail-fast + rethrowRuntimeException(e); + } + } + + @Override + public void deregister(EtcdRegistration registration) { + try { + etcd.delete(getServiceKey(registration)).send(); + } + catch (IOException e) { + rethrowRuntimeException(e); + } + } + + @Override + public void close() { + try { + etcd.close(); + } + catch (IOException e) { + rethrowRuntimeException(e); + } + } + + @Override + public void setStatus(EtcdRegistration registration, String status) { + // todo: add metadata to payload + } + + @Override + public T getStatus(EtcdRegistration registration) { + return null; + } + + private String getServiceKey(EtcdRegistration registration) { + return getAppKey(registration.getServiceId()) + "/" + + registration.getInstanceId(); + } + + private String getAppKey(String appName) { + return properties.getDiscoveryPrefix() + "/" + appName; + } +} diff --git a/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistryAutoConfiguration.java b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistryAutoConfiguration.java new file mode 100644 index 0000000..b7dde64 --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/java/org/springframework/cloud/etcd/serviceregistry/EtcdServiceRegistryAutoConfiguration.java @@ -0,0 +1,74 @@ +/* + * 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.etcd.serviceregistry; + +import mousio.etcd4j.EtcdClient; + +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.client.serviceregistry.ServiceRegistry; +import org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration; +import org.springframework.cloud.etcd.ConditionalOnEtcdEnabled; +import org.springframework.cloud.etcd.discovery.EtcdDiscoveryProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; + +/** + * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration + * Auto-configuration} that configures Etcd {@link ServiceRegistry}. + * @author Vladislav Khakin + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnEtcdEnabled +@AutoConfigureBefore(ServiceRegistryAutoConfiguration.class) +@Conditional(EtcdServiceRegistryAutoConfiguration.OnEtcdRegistrationEnabledCondition.class) +public class EtcdServiceRegistryAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + EtcdServiceRegistry etcdServiceRegistry(EtcdClient etcd, + EtcdDiscoveryProperties properties) { + return new EtcdServiceRegistry(etcd, properties); + } + + @Bean + @ConditionalOnMissingBean + EtcdDiscoveryProperties properties() { + return new EtcdDiscoveryProperties(); + } + + static class OnEtcdRegistrationEnabledCondition extends AllNestedConditions { + + OnEtcdRegistrationEnabledCondition() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnProperty(value = "spring.cloud.service-registry.enabled", matchIfMissing = true) + static class ServiceRegistryEnabledClass { + + } + + @ConditionalOnProperty(value = "spring.cloud.etcd.service-registry.enabled", matchIfMissing = true) + static class EtcdServiceRegistryEnabledClass { + + } + + } +} diff --git a/spring-cloud-etcd-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-etcd-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..aeeb2a2 --- /dev/null +++ b/spring-cloud-etcd-discovery/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,28 @@ +{ + "properties": [ + { + "name": "spring.cloud.service-registry.enabled", + "type": "java.lang.Boolean", + "description": "Enables Service Registry functionality.", + "defaultValue": "true" + }, + { + "name": "spring.cloud.etcd.service-registry.enabled", + "type": "java.lang.Boolean", + "description": "Enables Etcd Service Registry functionality.", + "defaultValue": "true" + }, + { + "name": "spring.cloud.service-registry.auto-registration.enabled", + "type": "java.lang.Boolean", + "description": "Enables Service Registry Auto-registration.", + "defaultValue": "true" + }, + { + "name": "spring.cloud.etcd.service-registry.auto-registration.enabled", + "type": "java.lang.Boolean", + "description": "Enables Etcd Service Registry Auto-registration.", + "defaultValue": "true" + } + ] +} diff --git a/spring-cloud-etcd-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-etcd-discovery/src/main/resources/META-INF/spring.factories index daaf880..e9fe8f3 100644 --- a/spring-cloud-etcd-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-etcd-discovery/src/main/resources/META-INF/spring.factories @@ -1,6 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.etcd.discovery.RibbonEtcdAutoConfiguration - -# Discovery Client Configuration -org.springframework.cloud.client.discovery.EnableDiscoveryClient=\ +org.springframework.cloud.etcd.serviceregistry.EtcdServiceRegistryAutoConfiguration, \ +org.springframework.cloud.etcd.serviceregistry.EtcdAutoServiceRegistrationAutoConfiguration, \ org.springframework.cloud.etcd.discovery.EtcdDiscoveryClientConfiguration diff --git a/spring-cloud-etcd-sample/pom.xml b/spring-cloud-etcd-sample/pom.xml index 9660c86..5b4e685 100644 --- a/spring-cloud-etcd-sample/pom.xml +++ b/spring-cloud-etcd-sample/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.0.BUILD-SNAPSHOT + 1.0.1.BUILD-SNAPSHOT .. @@ -20,7 +20,6 @@ org.springframework.boot spring-boot-maven-plugin - 1.2.4.RELEASE @@ -40,10 +39,6 @@ - - org.springframework.boot - spring-boot-starter-web - org.springframework.cloud spring-cloud-etcd-config @@ -52,6 +47,14 @@ org.springframework.cloud spring-cloud-etcd-discovery + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + diff --git a/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java b/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java index 85aff93..7d01ce7 100644 --- a/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java +++ b/spring-cloud-etcd-sample/src/main/java/org/springframework/cloud/etcd/sample/SampleEtcdApplication.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @@ -50,12 +49,9 @@ public class SampleEtcdApplication { @Autowired private Environment env; - @Autowired(required = false) - private RelaxedPropertyResolver resolver; - @RequestMapping("/me") public ServiceInstance me() { - return discoveryClient.getLocalServiceInstance(); + return discoveryClient.getInstances(CLIENT_NAME).get(0); } @RequestMapping("/") @@ -65,8 +61,7 @@ public ServiceInstance lb() { @RequestMapping("/myenv") public String env(@RequestParam("prop") String prop) { - String property = new RelaxedPropertyResolver(env).getProperty(prop, "Not Found"); - return property; + return env.getProperty(prop, "Not Found"); } @RequestMapping("/all") diff --git a/spring-cloud-etcd-sample/src/main/resources/application.yml b/spring-cloud-etcd-sample/src/main/resources/application.yml index 01dfaff..e3261c9 100644 --- a/spring-cloud-etcd-sample/src/main/resources/application.yml +++ b/spring-cloud-etcd-sample/src/main/resources/application.yml @@ -1,9 +1,13 @@ +spring: + application: + name: testEtcdApp + cloud: + etcd: + discovery: + port: 8080 server: port: 8080 -ribbon: - ServerListRefreshInterval: 1000 - endpoints: health: sensitive: false diff --git a/spring-cloud-etcd-sample/src/main/resources/etcd_request.http b/spring-cloud-etcd-sample/src/main/resources/etcd_request.http new file mode 100644 index 0000000..a2783e7 --- /dev/null +++ b/spring-cloud-etcd-sample/src/main/resources/etcd_request.http @@ -0,0 +1,10 @@ +### Version +GET http://localhost:2379/version + +### Get Key +GET http://127.0.0.1:2379/v2/keys/?recursive=true + +### + + + diff --git a/src/main/bash/travis_install_etcd.sh b/src/main/bash/travis_install_etcd.sh index 8b83b3b..450f9b1 100755 --- a/src/main/bash/travis_install_etcd.sh +++ b/src/main/bash/travis_install_etcd.sh @@ -3,8 +3,9 @@ #!/usr/bin/env bash ETCD_URL="https://github.com/etcd-io/etcd/releases/download" -ETCD_VER="v3.5.1" -ETCD_ARC="darwin-amd64" +#ETCD_VER="v3.5.1" +ETCD_VER="v2.3.3" +ETCD_ARC="linux-amd64" # cleanup rm -rf etcd-${ETCD_VER}-${ETCD_ARC}.tar.gz From 1da6afdbb4f72720de7258ff4afc2683615e3f9d Mon Sep 17 00:00:00 2001 From: Vladislav Khakin Date: Wed, 1 Dec 2021 00:27:13 +0300 Subject: [PATCH 6/6] Update project version, pom file cleanup --- docs/pom.xml | 4 +-- pom.xml | 2 +- spring-cloud-etcd-config/pom.xml | 2 +- spring-cloud-etcd-core/pom.xml | 2 +- spring-cloud-etcd-dependencies/pom.xml | 36 +------------------------- spring-cloud-etcd-discovery/pom.xml | 2 +- spring-cloud-etcd-sample/pom.xml | 2 +- 7 files changed, 8 insertions(+), 42 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 3961777..bbe38ff 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,14 +6,14 @@ org.springframework.cloud spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT .. spring-cloud-etcd-docs jar Spring Cloud Etcd Docs Spring Cloud Docs - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT spring-cloud-etcd ${basedir}/.. diff --git a/pom.xml b/pom.xml index 83c85ec..adf5a0a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT pom Spring Cloud Etcd Spring Cloud Etcd diff --git a/spring-cloud-etcd-config/pom.xml b/spring-cloud-etcd-config/pom.xml index 0452110..a497f16 100644 --- a/spring-cloud-etcd-config/pom.xml +++ b/spring-cloud-etcd-config/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT .. diff --git a/spring-cloud-etcd-core/pom.xml b/spring-cloud-etcd-core/pom.xml index 0e72caa..ddf1b9c 100644 --- a/spring-cloud-etcd-core/pom.xml +++ b/spring-cloud-etcd-core/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT ../ diff --git a/spring-cloud-etcd-dependencies/pom.xml b/spring-cloud-etcd-dependencies/pom.xml index 27fdc95..f738c75 100644 --- a/spring-cloud-etcd-dependencies/pom.xml +++ b/spring-cloud-etcd-dependencies/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-etcd-dependencies - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT pom spring-cloud-etcd-dependencies Spring Cloud Etcd Dependencies @@ -44,40 +44,6 @@ ${project.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.mousio diff --git a/spring-cloud-etcd-discovery/pom.xml b/spring-cloud-etcd-discovery/pom.xml index 9e21802..33a2e91 100644 --- a/spring-cloud-etcd-discovery/pom.xml +++ b/spring-cloud-etcd-discovery/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT .. diff --git a/spring-cloud-etcd-sample/pom.xml b/spring-cloud-etcd-sample/pom.xml index 5b4e685..e237f4d 100644 --- a/spring-cloud-etcd-sample/pom.xml +++ b/spring-cloud-etcd-sample/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-etcd - 1.0.1.BUILD-SNAPSHOT + 2.0.0-SNAPSHOT ..