diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/AbstractZookeeperPropertySource.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/AbstractZookeeperPropertySource.java
index c5d11b88..e3ecb55b 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/AbstractZookeeperPropertySource.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/AbstractZookeeperPropertySource.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -17,16 +17,18 @@
package org.springframework.cloud.zookeeper.config;
import org.apache.curator.framework.CuratorFramework;
+
import org.springframework.core.env.EnumerablePropertySource;
/**
- * A {@link EnumerablePropertySource} that has a notion of a context which is
- * the root folder in Zookeeper.
+ * A {@link EnumerablePropertySource} that has a notion of a context which is the root
+ * folder in Zookeeper.
*
* @author Spencer Gibb
* @since 1.0.0
*/
-public abstract class AbstractZookeeperPropertySource extends EnumerablePropertySource {
+public abstract class AbstractZookeeperPropertySource
+ extends EnumerablePropertySource {
private String context;
@@ -45,4 +47,5 @@ public abstract class AbstractZookeeperPropertySource extends EnumerableProperty
public String getContext() {
return this.context;
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ConfigWatcher.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ConfigWatcher.java
index 5083960f..2b01d74a 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ConfigWatcher.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ConfigWatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 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.
@@ -16,13 +16,14 @@
package org.springframework.cloud.zookeeper.config;
-import javax.annotation.PostConstruct;
import java.io.Closeable;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.PostConstruct;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.curator.framework.CuratorFramework;
@@ -30,6 +31,7 @@ import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.zookeeper.KeeperException;
+
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
@@ -39,20 +41,25 @@ import static org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type.NOD
import static org.apache.curator.framework.recipes.cache.TreeCacheEvent.Type.NODE_UPDATED;
/**
- * Class that registers a {@link TreeCache} for each context.
- * It publishes events upon element change in Zookeeper.
+ * Class that registers a {@link TreeCache} for each context. It publishes events upon
+ * element change in Zookeeper.
*
* @author Spencer Gibb
* @since 1.0.0
*/
-public class ConfigWatcher implements Closeable, TreeCacheListener, ApplicationEventPublisherAware{
+public class ConfigWatcher
+ implements Closeable, TreeCacheListener, ApplicationEventPublisherAware {
private static final Log log = LogFactory.getLog(ConfigWatcher.class);
private AtomicBoolean running = new AtomicBoolean(false);
+
private List contexts;
+
private CuratorFramework source;
+
private ApplicationEventPublisher publisher;
+
private HashMap caches;
public ConfigWatcher(List contexts, CuratorFramework source) {
@@ -80,9 +87,11 @@ public class ConfigWatcher implements Closeable, TreeCacheListener, ApplicationE
this.caches.put(context, cache);
// no race condition since ZookeeperAutoConfiguration.curatorFramework
// calls curator.blockUntilConnected
- } catch (KeeperException.NoNodeException e) {
+ }
+ catch (KeeperException.NoNodeException e) {
// no node, ignore
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.error("Error initializing listener for context " + context, e);
}
}
@@ -100,10 +109,13 @@ public class ConfigWatcher implements Closeable, TreeCacheListener, ApplicationE
}
@Override
- public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
+ public void childEvent(CuratorFramework client, TreeCacheEvent event)
+ throws Exception {
TreeCacheEvent.Type eventType = event.getType();
- if (eventType == NODE_ADDED || eventType == NODE_REMOVED || eventType == NODE_UPDATED) {
- this.publisher.publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
+ if (eventType == NODE_ADDED || eventType == NODE_REMOVED
+ || eventType == NODE_UPDATED) {
+ this.publisher
+ .publishEvent(new RefreshEvent(this, event, getEventDesc(event)));
}
}
@@ -117,4 +129,5 @@ public class ConfigWatcher implements Closeable, TreeCacheListener, ApplicationE
}
return out.toString();
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfiguration.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfiguration.java
index 979d177b..6e6d2043 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfiguration.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 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.
@@ -17,6 +17,7 @@
package org.springframework.cloud.zookeeper.config;
import org.apache.curator.framework.CuratorFramework;
+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.endpoint.RefreshEndpoint;
@@ -25,8 +26,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
- * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
- * that registers a Zookeeper configuration watcher.
+ * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
+ * Auto-configuration} that registers a Zookeeper configuration watcher.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -39,11 +40,14 @@ public class ZookeeperConfigAutoConfiguration {
@Configuration
@ConditionalOnClass(RefreshEndpoint.class)
protected static class ZkRefreshConfiguration {
+
@Bean
@ConditionalOnProperty(name = "spring.cloud.zookeeper.config.watcher.enabled", matchIfMissing = true)
public ConfigWatcher configWatcher(ZookeeperPropertySourceLocator locator,
CuratorFramework curator) {
return new ConfigWatcher(locator.getContexts(), curator);
}
+
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigBootstrapConfiguration.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigBootstrapConfiguration.java
index 298d4df5..040de986 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigBootstrapConfiguration.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigBootstrapConfiguration.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -17,6 +17,7 @@
package org.springframework.cloud.zookeeper.config;
import org.apache.curator.framework.CuratorFramework;
+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration;
@@ -25,7 +26,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
- * Bootstrap Configuration for Zookeeper Configuration
+ * Bootstrap Configuration for Zookeeper Configuration.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -47,4 +48,5 @@ public class ZookeeperConfigBootstrapConfiguration {
public ZookeeperConfigProperties zookeeperConfigProperties() {
return new ZookeeperConfigProperties();
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigProperties.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigProperties.java
index f5703abc..75d1f93f 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigProperties.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigProperties.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,7 +16,8 @@
package org.springframework.cloud.zookeeper.config;
-import org.hibernate.validator.constraints.NotEmpty;
+import javax.validation.constraints.NotEmpty;
+
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
@@ -25,27 +26,27 @@ import org.springframework.validation.annotation.Validated;
*
* @author Spencer Gibb
* @since 1.0.0
- *
* @see ZookeeperPropertySourceLocator
*/
@Validated
@ConfigurationProperties("spring.cloud.zookeeper.config")
public class ZookeeperConfigProperties {
+
private boolean enabled = true;
/**
- * Root folder where the configuration for Zookeeper is kept
+ * Root folder where the configuration for Zookeeper is kept.
*/
private String root = "config";
/**
- * The name of the default context
+ * The name of the default context.
*/
@NotEmpty
private String defaultContext = "application";
/**
- * Separator for profile appended to the application name
+ * Separator for profile appended to the application name.
*/
@NotEmpty
private String profileSeparator = ",";
@@ -94,4 +95,5 @@ public class ZookeeperConfigProperties {
public void setFailFast(boolean failFast) {
this.failFast = failFast;
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySource.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySource.java
index 4695cfcb..7b87527b 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySource.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySource.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -26,11 +26,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.KeeperException;
+
import org.springframework.util.ReflectionUtils;
/**
- * {@link org.springframework.core.env.PropertySource} that stores properties
- * from Zookeeper inside a map. Properties are loaded upon class initialization.
+ * {@link org.springframework.core.env.PropertySource} that stores properties from
+ * Zookeeper inside a map. Properties are loaded upon class initialization.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -56,13 +57,15 @@ public class ZookeeperPropertySource extends AbstractZookeeperPropertySource {
byte[] bytes = null;
try {
bytes = this.getSource().getData().forPath(fullPath);
- } catch (KeeperException e) {
+ }
+ catch (KeeperException e) {
if (e.code() != KeeperException.Code.NONODE) { // not found
throw e;
}
}
return bytes;
- } catch (Exception exception) {
+ }
+ catch (Exception exception) {
ReflectionUtils.rethrowRuntimeException(exception);
}
return null;
@@ -92,15 +95,18 @@ public class ZookeeperPropertySource extends AbstractZookeeperPropertySource {
if (childPathChildren == null || childPathChildren.isEmpty()) {
registerKeyValue(childPath, "");
}
- } else {
- registerKeyValue(childPath, new String(bytes, Charset.forName("UTF-8")));
+ }
+ else {
+ registerKeyValue(childPath,
+ new String(bytes, Charset.forName("UTF-8")));
}
// Check children even if we have found a value for the current znode
findProperties(childPath, childPathChildren);
}
log.trace("leaving findProperties for path: " + path);
- } catch (Exception exception) {
+ }
+ catch (Exception exception) {
ReflectionUtils.rethrowRuntimeException(exception);
}
}
@@ -114,7 +120,8 @@ public class ZookeeperPropertySource extends AbstractZookeeperPropertySource {
List children = null;
try {
children = this.getSource().getChildren().forPath(path);
- } catch (KeeperException e) {
+ }
+ catch (KeeperException e) {
if (e.code() != KeeperException.Code.NONODE) { // not found
throw e;
}
diff --git a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocator.java b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocator.java
index 5805d423..b9e84fe9 100644
--- a/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocator.java
+++ b/spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocator.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,15 +16,17 @@
package org.springframework.cloud.zookeeper.config;
-import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import javax.annotation.PreDestroy;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.curator.framework.CuratorFramework;
+
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
@@ -33,13 +35,17 @@ import org.springframework.core.env.PropertySource;
import org.springframework.util.ReflectionUtils;
/**
- * Zookeeper provides a hierarchical namespace that allows
- * clients to store arbitrary data, such as configuration data. Spring Cloud Zookeeper Config is an alternative to the
- * Config Server and Client. Configuration is loaded into the Spring Environment during
- * the special "bootstrap" phase. Configuration is stored in the {@code /config} namespace by default. Multiple
- * {@code PropertySource} instances are created based on the application's name and the active profiles that mimicks the Spring Cloud Config
- * order of resolving properties. For example, an application with the name "testApp" and with the "dev" profile will have the following property sources
- * created:
+ * Zookeeper provides a hierarchical
+ * namespace that allows clients to store arbitrary data, such as configuration data.
+ * Spring Cloud Zookeeper Config is an alternative to the
+ * Config Server and
+ * Client. Configuration is loaded into the Spring Environment during the special
+ * "bootstrap" phase. Configuration is stored in the {@code /config} namespace by default.
+ * Multiple {@code PropertySource} instances are created based on the application's name
+ * and the active profiles that mimicks the Spring Cloud Config order of resolving
+ * properties. For example, an application with the name "testApp" and with the "dev"
+ * profile will have the following property sources created:
*
* {@code
* config/testApp,dev
@@ -48,11 +54,11 @@ import org.springframework.util.ReflectionUtils;
* config/application
* }
*
- *
- * The most specific property source is at the top, with the least specific at the
- * bottom. Properties is the {@code config/application} namespace are applicable to all applications
- * using zookeeper for configuration. Properties in the {@code config/testApp} namespace are only available
- * to the instances of the service named "testApp".
+ * The most specific property source is at the top, with the least specific at the bottom.
+ * Properties is the {@code config/application} namespace are applicable to all
+ * applications using zookeeper for configuration. Properties in the
+ * {@code config/testApp} namespace are only available to the instances of the service
+ * named "testApp".
*
* @author Spencer Gibb
* @since 1.0.0
@@ -65,9 +71,11 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
private List contexts;
- private static final Log log = LogFactory.getLog(ZookeeperPropertySourceLocator.class);
+ private static final Log log = LogFactory
+ .getLog(ZookeeperPropertySourceLocator.class);
- public ZookeeperPropertySourceLocator(CuratorFramework curator, ZookeeperConfigProperties properties) {
+ public ZookeeperPropertySourceLocator(CuratorFramework curator,
+ ZookeeperConfigProperties properties) {
this.curator = curator;
this.properties = properties;
}
@@ -84,7 +92,8 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
if (appName == null) {
// use default "application" (which config client does)
appName = "application";
- log.warn("spring.application.name is not set. Using default of 'application'");
+ log.warn(
+ "spring.application.name is not set. Using default of 'application'");
}
List profiles = Arrays.asList(env.getActiveProfiles());
@@ -112,11 +121,14 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
PropertySource propertySource = create(propertySourceContext);
composite.addPropertySource(propertySource);
// TODO: howto call close when /refresh
- } catch (Exception e) {
+ }
+ catch (Exception e) {
if (this.properties.isFailFast()) {
ReflectionUtils.rethrowRuntimeException(e);
- } else {
- log.warn("Unable to load zookeeper config from " + propertySourceContext, e);
+ }
+ else {
+ log.warn("Unable to load zookeeper config from "
+ + propertySourceContext, e);
}
}
}
@@ -140,4 +152,5 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
contexts.add(baseContext + this.properties.getProfileSeparator() + profile);
}
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfigurationTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfigurationTests.java
index be69b2de..5aed5e34 100644
--- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfigurationTests.java
+++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigAutoConfigurationTests.java
@@ -1,79 +1,93 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.springframework.cloud.zookeeper.config;
+import java.net.ConnectException;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.ExpectedException;
+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
-import java.net.ConnectException;
-
/**
* @author Cesar Aguilera
*/
public class ZookeeperConfigAutoConfigurationTests {
- @Rule
- public ExpectedException expectedException;
+ @Rule
+ public ExpectedException expectedException;
- @Before
- public void setUp() throws Exception {
- expectedException = ExpectedException.none();
- // makes Curator fail faster, otherwise it takes 15 seconds to trigger a retry
- System.setProperty("curator-default-connection-timeout", "0");
- }
+ @Before
+ public void setUp() throws Exception {
+ expectedException = ExpectedException.none();
+ // makes Curator fail faster, otherwise it takes 15 seconds to trigger a retry
+ System.setProperty("curator-default-connection-timeout", "0");
+ }
- @After
- public void tearDown() throws Exception {
- System.clearProperty("curator-default-connection-timeout");
- }
+ @After
+ public void tearDown() throws Exception {
+ System.clearProperty("curator-default-connection-timeout");
+ }
- @Test(expected = NoSuchBeanDefinitionException.class)
- public void testConfigEnabledFalseDoesNotLoadZookeeperConfigAutoConfiguration() throws Exception {
- ConfigurableApplicationContext context = new SpringApplicationBuilder()
- .sources(Config.class)
- .web(WebApplicationType.NONE)
- .run(
- "--spring.application.name=testZookeeperConfigEnabledSetToFalse",
- "--spring.jmx.default-domain=testZookeeperConfigEnabledSetToFalse",
- "--spring.cloud.zookeeper.config.connectString=localhost:2188",
- "--spring.cloud.zookeeper.baseSleepTimeMs=0",
- "--spring.cloud.zookeeper.maxRetries=0",
- "--spring.cloud.zookeeper.maxSleepMs=0",
- "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
- "--spring.cloud.zookeeper.config.failFast=false",
- "--spring.cloud.zookeeper.config.enabled=false"
- );
+ @Test(expected = NoSuchBeanDefinitionException.class)
+ public void testConfigEnabledFalseDoesNotLoadZookeeperConfigAutoConfiguration()
+ throws Exception {
+ ConfigurableApplicationContext context = new SpringApplicationBuilder()
+ .sources(Config.class).web(WebApplicationType.NONE)
+ .run("--spring.application.name=testZookeeperConfigEnabledSetToFalse",
+ "--spring.jmx.default-domain=testZookeeperConfigEnabledSetToFalse",
+ "--spring.cloud.zookeeper.config.connectString=localhost:2188",
+ "--spring.cloud.zookeeper.baseSleepTimeMs=0",
+ "--spring.cloud.zookeeper.maxRetries=0",
+ "--spring.cloud.zookeeper.maxSleepMs=0",
+ "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
+ "--spring.cloud.zookeeper.config.failFast=false",
+ "--spring.cloud.zookeeper.config.enabled=false");
+ context.getBean(ZookeeperConfigAutoConfiguration.class);
+ }
- context.getBean(ZookeeperConfigAutoConfiguration.class);
- }
+ @Test
+ public void testConfigEnabledTrueLoadsZookeeperConfigAutoConfiguration()
+ throws Exception {
+ expectedException.expect(ConnectException.class);
+ new SpringApplicationBuilder().sources(Config.class).web(WebApplicationType.NONE)
+ .run("--spring.application.name=testZookeeperConfigEnabledSetToTrue",
+ "--spring.jmx.default-domain=testZookeeperConfigEnabledSetToTrue",
+ "--spring.cloud.zookeeper.config.connectString=localhost:2188",
+ "--spring.cloud.zookeeper.baseSleepTimeMs=0",
+ "--spring.cloud.zookeeper.maxRetries=0",
+ "--spring.cloud.zookeeper.maxSleepMs=0",
+ "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
+ "--spring.cloud.zookeeper.config.failFast=false",
+ "--spring.cloud.zookeeper.config.enabled=true");
+ }
- @Test
- public void testConfigEnabledTrueLoadsZookeeperConfigAutoConfiguration() throws Exception {
- expectedException.expect(ConnectException.class);
+ @SpringBootApplication
+ static class Config {
- new SpringApplicationBuilder()
- .sources(Config.class)
- .web(WebApplicationType.NONE)
- .run(
- "--spring.application.name=testZookeeperConfigEnabledSetToTrue",
- "--spring.jmx.default-domain=testZookeeperConfigEnabledSetToTrue",
- "--spring.cloud.zookeeper.config.connectString=localhost:2188",
- "--spring.cloud.zookeeper.baseSleepTimeMs=0",
- "--spring.cloud.zookeeper.maxRetries=0",
- "--spring.cloud.zookeeper.maxSleepMs=0",
- "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
- "--spring.cloud.zookeeper.config.failFast=false",
- "--spring.cloud.zookeeper.config.enabled=true"
- );
- }
+ }
- @SpringBootApplication
- static class Config {
- }
}
diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorFailFastTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorFailFastTests.java
index 6ed2bbda..09919ade 100644
--- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorFailFastTests.java
+++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorFailFastTests.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -21,6 +21,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -29,12 +30,14 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
* @author Enrique Recarte Llorens
*/
public class ZookeeperPropertySourceLocatorFailFastTests {
+
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() throws Exception {
- // This system property makes Curator fail faster, otherwise it takes 15 seconds to trigger a retry
+ // This system property makes Curator fail faster, otherwise it takes 15 seconds
+ // to trigger a retry
System.setProperty("curator-default-connection-timeout", "0");
}
@@ -45,39 +48,33 @@ public class ZookeeperPropertySourceLocatorFailFastTests {
@Test
public void testFailFastFalseLoadsTheApplicationContext() throws Exception {
- new SpringApplicationBuilder()
- .sources(Config.class)
- .web(WebApplicationType.NONE)
- .run(
- "--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
- "--spring.cloud.zookeeper.config.connectString=localhost:2188",
- "--spring.cloud.zookeeper.baseSleepTimeMs=0",
- "--spring.cloud.zookeeper.maxRetries=0",
- "--spring.cloud.zookeeper.maxSleepMs=0",
- "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
- "--spring.cloud.zookeeper.config.failFast=false"
- );
+ new SpringApplicationBuilder().sources(Config.class).web(WebApplicationType.NONE)
+ .run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
+ "--spring.cloud.zookeeper.config.connectString=localhost:2188",
+ "--spring.cloud.zookeeper.baseSleepTimeMs=0",
+ "--spring.cloud.zookeeper.maxRetries=0",
+ "--spring.cloud.zookeeper.maxSleepMs=0",
+ "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
+ "--spring.cloud.zookeeper.config.failFast=false");
}
@Test
public void testFailFastTrueDoesNotLoadTheApplicationContext() throws Exception {
expectedException.expect(Exception.class);
- new SpringApplicationBuilder()
- .sources(Config.class)
- .web(WebApplicationType.NONE)
- .run(
- "--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
- "--spring.cloud.zookeeper.config.connectString=localhost:2188",
- "--spring.cloud.zookeeper.baseSleepTimeMs=0",
- "--spring.cloud.zookeeper.maxRetries=0",
- "--spring.cloud.zookeeper.maxSleepMs=0",
- "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
- "--spring.cloud.zookeeper.config.failFast=true"
- );
+ new SpringApplicationBuilder().sources(Config.class).web(WebApplicationType.NONE)
+ .run("--spring.application.name=testZookeeperPropertySourceLocatorFailFast",
+ "--spring.cloud.zookeeper.config.connectString=localhost:2188",
+ "--spring.cloud.zookeeper.baseSleepTimeMs=0",
+ "--spring.cloud.zookeeper.maxRetries=0",
+ "--spring.cloud.zookeeper.maxSleepMs=0",
+ "--spring.cloud.zookeeper.blockUntilConnectedWait=0",
+ "--spring.cloud.zookeeper.config.failFast=true");
}
@SpringBootApplication
static class Config {
+
}
-}
\ No newline at end of file
+
+}
diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorNoApplicationNameTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorNoApplicationNameTests.java
index 715d9a30..a4101715 100644
--- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorNoApplicationNameTests.java
+++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorNoApplicationNameTests.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -19,9 +19,7 @@ package org.springframework.cloud.zookeeper.config;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.GetChildrenBuilder;
import org.junit.Test;
-import org.mockito.Mockito;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.context.annotation.Configuration;
+
import org.springframework.mock.env.MockEnvironment;
import static org.mockito.Mockito.mock;
@@ -36,7 +34,9 @@ public class ZookeeperPropertySourceLocatorNoApplicationNameTests {
public void defaultSpringApplicationNameWorks() {
CuratorFramework curator = mock(CuratorFramework.class);
when(curator.getChildren()).thenReturn(mock(GetChildrenBuilder.class));
- ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(curator, new ZookeeperConfigProperties());
+ ZookeeperPropertySourceLocator locator = new ZookeeperPropertySourceLocator(
+ curator, new ZookeeperConfigProperties());
locator.locate(new MockEnvironment());
}
+
}
diff --git a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorTests.java b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorTests.java
index 3d3b878d..5633b291 100644
--- a/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorTests.java
+++ b/spring-cloud-zookeeper-config/src/test/java/org/springframework/cloud/zookeeper/config/ZookeeperPropertySourceLocatorTests.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -45,66 +45,54 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.SocketUtils;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.isEmptyString;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Spencer Gibb
*/
public class ZookeeperPropertySourceLocatorTests {
- private static final Log log = LogFactory.getLog(ZookeeperPropertySourceLocatorTests.class);
+ private static final Log log = LogFactory
+ .getLog(ZookeeperPropertySourceLocatorTests.class);
public static final String PREFIX = "test__config__";
+
public static final String ROOT = "/" + PREFIX + UUID.randomUUID();
+
public static final String CONTEXT = ROOT + "/application/";
public static final String KEY_BASIC = "testProp";
+
public static final String KEY_BASIC_PATH = CONTEXT + KEY_BASIC;
+
public static final String VAL_BASIC = "testPropVal";
public static final String KEY_WITH_DOT = "testProp.dot";
+
public static final String KEY_WITH_DOT_PATH = CONTEXT + KEY_WITH_DOT;
+
public static final String VAL_WITH_DOT = "withDotVal";
public static final String KEY_NESTED = "testProp.nested";
+
public static final String KEY_NESTED_PATH = CONTEXT + KEY_NESTED.replace('.', '/');
+
public static final String VAL_NESTED = "nestedVal";
public static final String KEY_WITHOUT_VALUE = "testProp.novalue";
+
public static final String KEY_WITHOUT_VALUE_PATH = CONTEXT + KEY_WITHOUT_VALUE;
private ConfigurableEnvironment environment;
+
private ConfigurableApplicationContext context;
+
private TestingServer testingServer;
+
private CuratorFramework curator;
+
private ZookeeperConfigProperties properties;
- @Configuration
- @EnableAutoConfiguration
- static class Config implements ApplicationListener {
- @Bean
- public CountDownLatch countDownLatch() {
- return new CountDownLatch(1);
- }
-
- @Bean
- public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
- RefreshScope scope) {
- return new ContextRefresher(context, scope);
- }
-
- @Override
- public void onApplicationEvent(EnvironmentChangeEvent event) {
- log.debug("Event keys: " + event.getKeys());
- if (event.getKeys().contains(KEY_BASIC)) {
- countDownLatch().countDown();
- }
- }
- }
-
@Before
public void setup() throws Exception {
int port = SocketUtils.findAvailableTcpPort();
@@ -133,10 +121,12 @@ public class ZookeeperPropertySourceLocatorTests {
this.curator.close();
System.out.println(create);
- this.context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE).run(
- "--spring.cloud.zookeeper.connectString=" + connectString,
- "--spring.application.name=testZkPropertySource", "--logging.level.org.springframework.cloud.zookeeper=DEBUG",
- "--spring.cloud.zookeeper.config.root=" + ROOT);
+ this.context = new SpringApplicationBuilder(Config.class)
+ .web(WebApplicationType.NONE)
+ .run("--spring.cloud.zookeeper.connectString=" + connectString,
+ "--spring.application.name=testZkPropertySource",
+ "--logging.level.org.springframework.cloud.zookeeper=DEBUG",
+ "--spring.cloud.zookeeper.config.root=" + ROOT);
this.curator = this.context.getBean(CuratorFramework.class);
this.properties = this.context.getBean(ZookeeperConfigProperties.class);
@@ -168,31 +158,57 @@ public class ZookeeperPropertySourceLocatorTests {
@Test
public void checkKeyValues() throws Exception {
String propValue = this.environment.getProperty(KEY_BASIC);
- assertThat(KEY_BASIC + " was wrong", propValue, is(equalTo(VAL_BASIC)));
+ assertThat(propValue).as(KEY_BASIC + " was wrong").isEqualTo(VAL_BASIC);
propValue = this.environment.getProperty(KEY_NESTED);
- assertThat(VAL_NESTED + " was wrong", propValue, is(equalTo(VAL_NESTED)));
+ assertThat(propValue).as(VAL_NESTED + " was wrong").isEqualTo(VAL_NESTED);
propValue = this.environment.getProperty(KEY_WITH_DOT);
- assertThat(VAL_WITH_DOT + " was wrong", propValue, is(equalTo(VAL_WITH_DOT)));
+ assertThat(propValue).as(VAL_WITH_DOT + " was wrong").isEqualTo(VAL_WITH_DOT);
propValue = this.environment.getProperty(KEY_WITHOUT_VALUE);
- assertThat(KEY_WITHOUT_VALUE + " was wrong", propValue, is(isEmptyString()));
+ assertThat(propValue).as(KEY_WITHOUT_VALUE + " was wrong").isEmpty();
}
@Test
public void propertyLoadedAndUpdated() throws Exception {
String testProp = this.environment.getProperty(KEY_BASIC);
- assertThat("testProp was wrong", testProp, is(equalTo(VAL_BASIC)));
+ assertThat(testProp).as("testProp was wrong").isEqualTo(VAL_BASIC);
this.curator.setData().forPath(KEY_BASIC_PATH, "testPropValUpdate".getBytes());
CountDownLatch latch = this.context.getBean(CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
- assertThat("listener didn't receive event", receivedEvent, is(true));
+ assertThat(receivedEvent).as("listener didn't receive event").isTrue();
testProp = this.environment.getProperty(KEY_BASIC);
- assertThat("testProp was wrong after update", testProp,
- is(equalTo("testPropValUpdate")));
+ assertThat(testProp).as("testProp was wrong after update")
+ .isEqualTo("testPropValUpdate");
}
+
+ @Configuration
+ @EnableAutoConfiguration
+ static class Config implements ApplicationListener {
+
+ @Bean
+ public CountDownLatch countDownLatch() {
+ return new CountDownLatch(1);
+ }
+
+ @Bean
+ public ContextRefresher contextRefresher(ConfigurableApplicationContext context,
+ RefreshScope scope) {
+ return new ContextRefresher(context, scope);
+ }
+
+ @Override
+ public void onApplicationEvent(EnvironmentChangeEvent event) {
+ log.debug("Event keys: " + event.getKeys());
+ if (event.getKeys().contains(KEY_BASIC)) {
+ countDownLatch().countDown();
+ }
+ }
+
+ }
+
}
diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ConditionalOnZookeeperEnabled.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ConditionalOnZookeeperEnabled.java
index 6a19e31b..111e18fc 100644
--- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ConditionalOnZookeeperEnabled.java
+++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ConditionalOnZookeeperEnabled.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -24,12 +24,14 @@ import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
- * Wrapper annotation to enable Zookeeper
+ * Wrapper annotation to enable Zookeeper.
*
+ * @author Marcin Grzejszczak
* @since 1.1.0
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target({ ElementType.TYPE, ElementType.METHOD })
@ConditionalOnProperty(value = "spring.cloud.zookeeper.enabled", matchIfMissing = true)
public @interface ConditionalOnZookeeperEnabled {
+
}
diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java
index a57162ab..a78e11e0 100644
--- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java
+++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -23,6 +23,7 @@ import org.apache.curator.ensemble.EnsembleProvider;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -30,8 +31,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
- * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
- * that sets up Zookeeper discovery.
+ * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
+ * Auto-configuration} that sets up Zookeeper discovery.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -52,20 +53,24 @@ public class ZookeeperAutoConfiguration {
return new ZookeeperProperties();
}
-
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean
- public CuratorFramework curatorFramework(RetryPolicy retryPolicy, ZookeeperProperties properties) throws Exception {
+ public CuratorFramework curatorFramework(RetryPolicy retryPolicy,
+ ZookeeperProperties properties) throws Exception {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
if (this.ensembleProvider != null) {
builder.ensembleProvider(this.ensembleProvider);
- } else {
+ }
+ else {
builder.connectString(properties.getConnectString());
}
CuratorFramework curator = builder.retryPolicy(retryPolicy).build();
curator.start();
- log.trace("blocking until connected to zookeeper for " + properties.getBlockUntilConnectedWait() + properties.getBlockUntilConnectedUnit());
- curator.blockUntilConnected(properties.getBlockUntilConnectedWait(), properties.getBlockUntilConnectedUnit());
+ log.trace("blocking until connected to zookeeper for "
+ + properties.getBlockUntilConnectedWait()
+ + properties.getBlockUntilConnectedUnit());
+ curator.blockUntilConnected(properties.getBlockUntilConnectedWait(),
+ properties.getBlockUntilConnectedUnit());
log.trace("connected to zookeeper");
return curator;
}
@@ -74,7 +79,7 @@ public class ZookeeperAutoConfiguration {
@ConditionalOnMissingBean
public RetryPolicy exponentialBackoffRetry(ZookeeperProperties properties) {
return new ExponentialBackoffRetry(properties.getBaseSleepTimeMs(),
- properties.getMaxRetries(),
- properties.getMaxSleepMs());
+ properties.getMaxRetries(), properties.getMaxSleepMs());
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java
index 7c70ac45..7f1ae710 100644
--- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java
+++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2018 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.
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.zookeeper;
import org.apache.curator.framework.CuratorFramework;
+
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -28,8 +30,8 @@ import org.springframework.context.annotation.Configuration;
/**
* Auto {@link Configuration} for adding a Zookeeper health endpoint to actuator if
* required.
- *
- * @author tgianos
+ *
+ * @author Tom Gianos
* @since 2.0.1
*/
@Configuration
@@ -41,7 +43,6 @@ public class ZookeeperHealthAutoConfiguration {
/**
* If there is an active curator, if the zookeeper health endpoint is enabled and if a
* health indicator hasn't already been added by a user add one.
- *
* @param curator The curator connection to zookeeper to use
* @return An instance of {@link ZookeeperHealthIndicator} to add to actuator health
* report
@@ -53,4 +54,5 @@ public class ZookeeperHealthAutoConfiguration {
public ZookeeperHealthIndicator zookeeperHealthIndicator(CuratorFramework curator) {
return new ZookeeperHealthIndicator(curator);
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthIndicator.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthIndicator.java
index aeb77dd6..308e3ab7 100644
--- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthIndicator.java
+++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperHealthIndicator.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.imps.CuratorFrameworkState;
+
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
@@ -29,6 +30,7 @@ import org.springframework.boot.actuate.health.Health;
* @since 1.0.0
*/
public class ZookeeperHealthIndicator extends AbstractHealthIndicator {
+
private final CuratorFramework curator;
public ZookeeperHealthIndicator(CuratorFramework curator) {
@@ -56,4 +58,5 @@ public class ZookeeperHealthIndicator extends AbstractHealthIndicator {
builder.down(e);
}
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperProperties.java b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperProperties.java
index b84427a2..17cf86ff 100644
--- a/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperProperties.java
+++ b/spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/ZookeeperProperties.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,14 +16,15 @@
package org.springframework.cloud.zookeeper;
-import javax.validation.constraints.NotNull;
import java.util.concurrent.TimeUnit;
+import javax.validation.constraints.NotNull;
+
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
/**
- * Properties related to connecting to Zookeeper
+ * Properties related to connecting to Zookeeper.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -33,38 +34,38 @@ import org.springframework.validation.annotation.Validated;
public class ZookeeperProperties {
/**
- * Connection string to the Zookeeper cluster
+ * Connection string to the Zookeeper cluster.
*/
@NotNull
private String connectString = "localhost:2181";
/**
- * Is Zookeeper enabled
+ * Is Zookeeper enabled.
*/
private boolean enabled = true;
/**
- * Initial amount of time to wait between retries
+ * Initial amount of time to wait between retries.
*/
private Integer baseSleepTimeMs = 50;
/**
- * Max number of times to retry
+ * Max number of times to retry.
*/
private Integer maxRetries = 10;
/**
- * Max time in ms to sleep on each retry
+ * Max time in ms to sleep on each retry.
*/
private Integer maxSleepMs = 500;
/**
- * Wait time to block on connection to Zookeeper
+ * Wait time to block on connection to Zookeeper.
*/
private Integer blockUntilConnectedWait = 10;
/**
- * The unit of time related to blocking on connection to Zookeeper
+ * The unit of time related to blocking on connection to Zookeeper.
*/
private TimeUnit blockUntilConnectedUnit = TimeUnit.SECONDS;
@@ -123,4 +124,5 @@ public class ZookeeperProperties {
public void setBlockUntilConnectedUnit(TimeUnit blockUntilConnectedUnit) {
this.blockUntilConnectedUnit = blockUntilConnectedUnit;
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationEnsembleTests.java b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationEnsembleTests.java
index 9a2283e0..b50621e1 100644
--- a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationEnsembleTests.java
+++ b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationEnsembleTests.java
@@ -1,7 +1,20 @@
-package org.springframework.cloud.zookeeper;
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+package org.springframework.cloud.zookeeper;
import org.apache.curator.ensemble.EnsembleProvider;
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
@@ -9,26 +22,35 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.TestingServer;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import static org.assertj.core.api.Assertions.assertThat;
+
/**
* @author Konrad Kamil DobrzyĆski
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = { ZookeeperAutoConfigurationEnsembleTests.TestConfig.class, ZookeeperAutoConfiguration.class })
+@ContextConfiguration(classes = {
+ ZookeeperAutoConfigurationEnsembleTests.TestConfig.class,
+ ZookeeperAutoConfiguration.class })
public class ZookeeperAutoConfigurationEnsembleTests {
- @Autowired(required = false) CuratorFramework curator;
+ @Autowired(required = false)
+ CuratorFramework curator;
+
+ @Autowired
+ TestingServer testingServer;
- @Autowired TestingServer testingServer;
-
@Test
public void should_successfully_inject_Curator_with_ensemble_connection_string() {
- assertEquals(testingServer.getConnectString(), curator.getZookeeperClient().getCurrentConnectionString());
- assertNotEquals(TestConfig.DUMMY_CONNECTION_STRING, curator.getZookeeperClient().getCurrentConnectionString());
+ assertThat(curator.getZookeeperClient().getCurrentConnectionString())
+ .isEqualTo(testingServer.getConnectString());
+ assertThat(curator.getZookeeperClient().getCurrentConnectionString())
+ .isNotEqualTo(TestConfig.DUMMY_CONNECTION_STRING);
}
static class TestConfig {
@@ -36,7 +58,7 @@ public class ZookeeperAutoConfigurationEnsembleTests {
static final String DUMMY_CONNECTION_STRING = "dummy-connection-string:2111";
@Bean
- EnsembleProvider ensembleProvider(TestingServer testingServer){
+ EnsembleProvider ensembleProvider(TestingServer testingServer) {
return new FixedEnsembleProvider(testingServer.getConnectString());
}
@@ -47,8 +69,11 @@ public class ZookeeperAutoConfigurationEnsembleTests {
return properties;
}
- @Bean(destroyMethod = "close") TestingServer testingServer() throws Exception {
+ @Bean(destroyMethod = "close")
+ TestingServer testingServer() throws Exception {
return new TestingServer();
}
+
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java
index 3662027d..e1dc0e20 100644
--- a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java
+++ b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperAutoConfigurationTests.java
@@ -1,40 +1,64 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.springframework.cloud.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.TestingServer;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Marcin Grzejszczak
*/
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = { ZookeeperAutoConfigurationTests.TestConfig.class, ZookeeperAutoConfiguration.class })
+@ContextConfiguration(classes = { ZookeeperAutoConfigurationTests.TestConfig.class,
+ ZookeeperAutoConfiguration.class })
public class ZookeeperAutoConfigurationTests {
- @Autowired(required = false) CuratorFramework curator;
-
+ @Autowired(required = false)
+ CuratorFramework curator;
+
@Test
public void should_successfully_inject_Curator_as_a_Spring_bean() {
- assertNotNull(this.curator);
+ assertThat(this.curator).isNotNull();
}
static class TestConfig {
+
@Bean
- ZookeeperProperties zookeeperProperties(TestingServer testingServer) throws Exception {
+ ZookeeperProperties zookeeperProperties(TestingServer testingServer)
+ throws Exception {
ZookeeperProperties properties = new ZookeeperProperties();
properties.setConnectString(testingServer.getConnectString());
return properties;
}
- @Bean(destroyMethod = "close") TestingServer testingServer() throws Exception {
+ @Bean(destroyMethod = "close")
+ TestingServer testingServer() throws Exception {
return new TestingServer();
}
+
}
+
}
diff --git a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfigurationTests.java b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfigurationTests.java
index baf2d023..122059b8 100644
--- a/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfigurationTests.java
+++ b/spring-cloud-zookeeper-core/src/test/java/org/springframework/cloud/zookeeper/ZookeeperHealthAutoConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2018 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.
@@ -13,22 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.assertj.core.api.Assertions;
import org.junit.Test;
+
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
/**
* Tests for {@link ZookeeperHealthAutoConfiguration}.
- *
- * @author tgianos
+ *
+ * @author Tom Gianos
* @since 2.0.1
*/
public class ZookeeperHealthAutoConfigurationTests {
+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(ZookeeperAutoConfiguration.class,
ZookeeperHealthAutoConfiguration.class))
@@ -61,10 +64,13 @@ public class ZookeeperHealthAutoConfigurationTests {
}
static class HealthIndicatorCustomConfig {
+
@Bean
ZookeeperHealthIndicator customZookeeperHealthIndicator(
CuratorFramework curatorFramework) {
return new ZookeeperHealthIndicator(curatorFramework);
}
+
}
+
}
diff --git a/spring-cloud-zookeeper-dependencies/pom.xml b/spring-cloud-zookeeper-dependencies/pom.xml
index 7a57f6bb..7845dbfd 100644
--- a/spring-cloud-zookeeper-dependencies/pom.xml
+++ b/spring-cloud-zookeeper-dependencies/pom.xml
@@ -15,6 +15,9 @@
Spring Cloud Zookeeper Dependencies
4.0.1
+ true
+ true
+ true
@@ -116,6 +119,27 @@
+
+
+
+ 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-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnRibbonZookeeper.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnRibbonZookeeper.java
index 36425732..4b1b14ee 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnRibbonZookeeper.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnRibbonZookeeper.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -24,12 +24,14 @@ import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
- * Wrapper annotation to enable Ribbon for Zookeeper
+ * Wrapper annotation to enable Ribbon for Zookeeper.
*
- * @since 1.0.0
+ * @author Marcin Grzejszczak
+ * * @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target({ ElementType.TYPE, ElementType.METHOD })
@ConditionalOnProperty(value = "ribbon.zookeeper.enabled", matchIfMissing = true)
public @interface ConditionalOnRibbonZookeeper {
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnZookeeperDiscoveryEnabled.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnZookeeperDiscoveryEnabled.java
index b47e8a4f..3f94b223 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnZookeeperDiscoveryEnabled.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ConditionalOnZookeeperDiscoveryEnabled.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -25,13 +25,15 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
/**
- * Wrapper annotation to enable Zookeeper Discovery
+ * Wrapper annotation to enable Zookeeper Discovery.
*
+ * @author Marcin Grzejszczak
* @since 1.1.0
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target({ ElementType.TYPE, ElementType.METHOD })
@ConditionalOnZookeeperEnabled
@ConditionalOnProperty(value = "spring.cloud.zookeeper.discovery.enabled", matchIfMissing = true)
public @interface ConditionalOnZookeeperDiscoveryEnabled {
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/DependencyPathUtils.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/DependencyPathUtils.java
index 9744c801..6172d1a5 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/DependencyPathUtils.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/DependencyPathUtils.java
@@ -1,17 +1,37 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.springframework.cloud.zookeeper.discovery;
/**
- * Utils for correct dependency path format
+ * Utils for correct dependency path format.
*
* @author Denis Stepanov
* @since 1.0.4
*/
-public class DependencyPathUtils {
+public final class DependencyPathUtils {
+
+ private DependencyPathUtils() {
+ }
/**
- * Sanitizes path by ensuring that path starts with a slash and doesn't have one at the end
- * @param path
- * @return
+ * Sanitizes path by ensuring that path starts with a slash and doesn't have one at
+ * the end.
+ * @param path file path to sanitize.
+ * @return sanitized path.
*/
public static String sanitize(String path) {
return withLeadingSlash(withoutSlashAtEnd(path));
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/RibbonZookeeperAutoConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/RibbonZookeeperAutoConfiguration.java
index 187cfa79..ac27c6ef 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/RibbonZookeeperAutoConfiguration.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/RibbonZookeeperAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -26,8 +26,8 @@ import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.context.annotation.Configuration;
/**
- * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
- * that sets up Ribbon for Zookeeper.
+ * {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
+ * Auto-configuration} that sets up Ribbon for Zookeeper.
*
* @author Dave Syer
* @since 1.0.0
@@ -40,4 +40,5 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter(RibbonAutoConfiguration.class)
@RibbonClients(defaultConfiguration = ZookeeperRibbonClientConfiguration.class)
public class RibbonZookeeperAutoConfiguration {
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java
index b14f7209..d566cf4e 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 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.
@@ -18,6 +18,7 @@ package org.springframework.cloud.zookeeper.discovery;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.x.discovery.ServiceDiscovery;
+
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -40,8 +41,9 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean(ZookeeperDiscoveryClientConfiguration.Marker.class)
@ConditionalOnZookeeperDiscoveryEnabled
-@AutoConfigureBefore({CommonsClientAutoConfiguration.class, NoopDiscoveryClientAutoConfiguration.class})
-@AutoConfigureAfter({ZookeeperDiscoveryClientConfiguration.class})
+@AutoConfigureBefore({ CommonsClientAutoConfiguration.class,
+ NoopDiscoveryClientAutoConfiguration.class })
+@AutoConfigureAfter({ ZookeeperDiscoveryClientConfiguration.class })
public class ZookeeperDiscoveryAutoConfiguration {
@Autowired(required = false)
@@ -52,13 +54,15 @@ public class ZookeeperDiscoveryAutoConfiguration {
@Bean
@ConditionalOnMissingBean
- public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
+ public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(
+ InetUtils inetUtils) {
return new ZookeeperDiscoveryProperties(inetUtils);
}
@Bean
@ConditionalOnMissingBean
- // currently means auto-registration is false. That will change when ZookeeperServiceDiscovery is gone
+ // currently means auto-registration is false. That will change when
+ // ZookeeperServiceDiscovery is gone
public ZookeeperDiscoveryClient zookeeperDiscoveryClient(
ServiceDiscovery serviceDiscovery,
ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
@@ -66,10 +70,17 @@ public class ZookeeperDiscoveryAutoConfiguration {
zookeeperDiscoveryProperties);
}
+ @Bean
+ public ZookeeperServiceWatch zookeeperServiceWatch(
+ ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
+ return new ZookeeperServiceWatch(this.curator, zookeeperDiscoveryProperties);
+ }
+
@Configuration
@ConditionalOnEnabledHealthIndicator("zookeeper")
@ConditionalOnClass(Endpoint.class)
protected static class ZookeeperDiscoveryHealthConfig {
+
@Autowired(required = false)
private ZookeeperDependencies zookeeperDependencies;
@@ -82,11 +93,7 @@ public class ZookeeperDiscoveryAutoConfiguration {
return new ZookeeperDiscoveryHealthIndicator(curatorFramework,
serviceDiscovery, this.zookeeperDependencies, properties);
}
- }
- @Bean
- public ZookeeperServiceWatch zookeeperServiceWatch(ZookeeperDiscoveryProperties zookeeperDiscoveryProperties) {
- return new ZookeeperServiceWatch(this.curator, zookeeperDiscoveryProperties);
}
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClient.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClient.java
index c374cf64..e304d72d 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClient.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClient.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -46,7 +46,9 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
private static final Log log = LogFactory.getLog(ZookeeperDiscoveryClient.class);
private final ZookeeperDependencies zookeeperDependencies;
+
private final ServiceDiscovery serviceDiscovery;
+
private final ZookeeperDiscoveryProperties zookeeperDiscoveryProperties;
public ZookeeperDiscoveryClient(ServiceDiscovery serviceDiscovery,
@@ -62,7 +64,8 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
return "Spring Cloud Zookeeper Discovery Client";
}
- private static org.springframework.cloud.client.ServiceInstance createServiceInstance(String serviceId, ServiceInstance serviceInstance) {
+ private static org.springframework.cloud.client.ServiceInstance createServiceInstance(
+ String serviceId, ServiceInstance serviceInstance) {
return new ZookeeperServiceInstance(serviceId, serviceInstance);
}
@@ -74,19 +77,24 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
return Collections.EMPTY_LIST;
}
String serviceIdToQuery = getServiceIdToQuery(serviceId);
- Collection> zkInstances = getServiceDiscovery().queryForInstances(serviceIdToQuery);
+ Collection> zkInstances = getServiceDiscovery()
+ .queryForInstances(serviceIdToQuery);
List instances = new ArrayList<>();
for (ServiceInstance instance : zkInstances) {
instances.add(createServiceInstance(serviceIdToQuery, instance));
}
return instances;
- } catch (KeeperException.NoNodeException e) {
+ }
+ catch (KeeperException.NoNodeException e) {
if (log.isDebugEnabled()) {
- log.debug("Error getting instances from zookeeper. Possibly, no service has registered.", e);
+ log.debug(
+ "Error getting instances from zookeeper. Possibly, no service has registered.",
+ e);
}
// this means that nothing has registered as a service yes
return Collections.emptyList();
- } catch (Exception exception) {
+ }
+ catch (Exception exception) {
rethrowRuntimeException(exception);
}
return new ArrayList<>();
@@ -97,7 +105,8 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
}
private String getServiceIdToQuery(String serviceId) {
- if (this.zookeeperDependencies != null && this.zookeeperDependencies.hasDependencies()) {
+ if (this.zookeeperDependencies != null
+ && this.zookeeperDependencies.hasDependencies()) {
String pathForAlias = this.zookeeperDependencies.getPathForAlias(serviceId);
return pathForAlias.isEmpty() ? serviceId : pathForAlias;
}
@@ -108,7 +117,8 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
public List getServices() {
List services = null;
if (getServiceDiscovery() == null) {
- log.warn("Service Discovery is not yet ready - returning empty list of services");
+ log.warn(
+ "Service Discovery is not yet ready - returning empty list of services");
return Collections.emptyList();
}
try {
@@ -120,7 +130,9 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
}
catch (KeeperException.NoNodeException e) {
if (log.isDebugEnabled()) {
- log.debug("Error getting services from zookeeper. Possibly, no service has registered.", e);
+ log.debug(
+ "Error getting services from zookeeper. Possibly, no service has registered.",
+ e);
}
// this means that nothing has registered as a service yes
return Collections.emptyList();
@@ -135,4 +147,5 @@ public class ZookeeperDiscoveryClient implements DiscoveryClient {
public int getOrder() {
return this.zookeeperDiscoveryProperties.getOrder();
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClientConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClientConfiguration.java
index a561cba7..4a417751 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClientConfiguration.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryClientConfiguration.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -21,8 +21,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
- * {@link org.springframework.cloud.client.discovery.DiscoveryClient} configuration
- * for Zookeeper.
+ * {@link org.springframework.cloud.client.discovery.DiscoveryClient} configuration for
+ * Zookeeper.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -31,11 +31,12 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(value = "spring.cloud.zookeeper.discovery.enabled", matchIfMissing = true)
public class ZookeeperDiscoveryClientConfiguration {
- class Marker {}
-
@Bean
public Marker zookeeperDiscoveryClientMarker() {
return new Marker();
}
+ class Marker {
+ }
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryHealthIndicator.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryHealthIndicator.java
index 7e1d52f6..845e2864 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryHealthIndicator.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryHealthIndicator.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceInstance;
+
import org.springframework.boot.actuate.health.Health;
import org.springframework.cloud.client.discovery.health.DiscoveryHealthIndicator;
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
@@ -38,8 +39,11 @@ public class ZookeeperDiscoveryHealthIndicator implements DiscoveryHealthIndicat
.getLog(ZookeeperDiscoveryHealthIndicator.class);
private CuratorFramework curatorFramework;
+
private ServiceDiscovery serviceDiscovery;
+
private final ZookeeperDependencies zookeeperDependencies;
+
private final ZookeeperDiscoveryProperties zookeeperDiscoveryProperties;
public ZookeeperDiscoveryHealthIndicator(CuratorFramework curatorFramework,
@@ -61,10 +65,9 @@ public class ZookeeperDiscoveryHealthIndicator implements DiscoveryHealthIndicat
public Health health() {
Health.Builder builder = Health.unknown();
try {
- Iterable> allInstances =
- new ZookeeperServiceInstances(this.curatorFramework,
- this.serviceDiscovery, this.zookeeperDependencies,
- this.zookeeperDiscoveryProperties);
+ Iterable> allInstances = new ZookeeperServiceInstances(
+ this.curatorFramework, this.serviceDiscovery,
+ this.zookeeperDependencies, this.zookeeperDiscoveryProperties);
builder.up().withDetail("services", allInstances);
}
catch (Exception e) {
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryProperties.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryProperties.java
index c30cd499..53dce3af 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryProperties.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperDiscoveryProperties.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -33,6 +33,9 @@ import org.springframework.util.StringUtils;
@ConfigurationProperties("spring.cloud.zookeeper.discovery")
public class ZookeeperDiscoveryProperties {
+ /**
+ * Default URI spec.
+ */
public static final String DEFAULT_URI_SPEC = "{scheme}://{address}:{port}";
private InetUtils.HostInfo hostInfo;
@@ -40,12 +43,12 @@ public class ZookeeperDiscoveryProperties {
private boolean enabled = true;
/**
- * Root Zookeeper folder in which all instances are registered
+ * Root Zookeeper folder in which all instances are registered.
*/
private String root = "/services";
/**
- * The URI specification to resolve during service registration in Zookeeper
+ * The URI specification to resolve during service registration in Zookeeper.
*/
private String uriSpec = DEFAULT_URI_SPEC;
@@ -58,16 +61,17 @@ public class ZookeeperDiscoveryProperties {
*/
private String instanceHost;
- /** IP address to use when accessing service (must also set preferIpAddress
- to use) */
+ /**
+ * IP address to use when accessing service (must also set preferIpAddress to use).
+ */
private String instanceIpAddress;
/**
- * Use ip address rather than hostname during registration
+ * Use ip address rather than hostname during registration.
*/
private boolean preferIpAddress = false;
- /** Port to register the service under (defaults to listening port) */
+ /** Port to register the service under (defaults to listening port). */
private Integer instancePort;
/** Ssl port of the registered service. */
@@ -85,17 +89,20 @@ public class ZookeeperDiscoveryProperties {
private Map metadata = new HashMap<>();
/**
- * The initial status of this instance (defaults to {@link StatusConstants#STATUS_UP}).
+ * The initial status of this instance (defaults to
+ * {@link StatusConstants#STATUS_UP}).
*/
private String initialStatus = StatusConstants.STATUS_UP;
/**
- * Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
+ * Order of the discovery client used by `CompositeDiscoveryClient` for sorting
+ * available clients.
*/
private int order = 0;
// Visible for Testing
- protected ZookeeperDiscoveryProperties() {}
+ protected ZookeeperDiscoveryProperties() {
+ }
public ZookeeperDiscoveryProperties(InetUtils inetUtils) {
this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
@@ -206,17 +213,13 @@ public class ZookeeperDiscoveryProperties {
@Override
public String toString() {
- return "ZookeeperDiscoveryProperties{" + "enabled=" + this.enabled +
- ", root='" + this.root + '\'' +
- ", uriSpec='" + this.uriSpec + '\'' +
- ", instanceId='" + this.instanceId + '\'' +
- ", instanceHost='" + this.instanceHost + '\'' +
- ", instancePort='" + this.instancePort + '\'' +
- ", instanceSslPort='" + this.instanceSslPort + '\'' +
- ", metadata=" + this.metadata +
- ", register=" + this.register +
- ", initialStatus=" + this.initialStatus +
- ", order=" + this.order +
- '}';
+ return "ZookeeperDiscoveryProperties{" + "enabled=" + this.enabled + ", root='"
+ + this.root + '\'' + ", uriSpec='" + this.uriSpec + '\''
+ + ", instanceId='" + this.instanceId + '\'' + ", instanceHost='"
+ + this.instanceHost + '\'' + ", instancePort='" + this.instancePort + '\''
+ + ", instanceSslPort='" + this.instanceSslPort + '\'' + ", metadata="
+ + this.metadata + ", register=" + this.register + ", initialStatus="
+ + this.initialStatus + ", order=" + this.order + '}';
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperInstance.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperInstance.java
index c69580f5..d1a9cf63 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperInstance.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperInstance.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -26,8 +26,11 @@ import java.util.Map;
* @since 1.0.0
*/
public class ZookeeperInstance {
+
private String id;
+
private String name;
+
private Map metadata = new HashMap<>();
@SuppressWarnings("unused")
@@ -66,9 +69,8 @@ public class ZookeeperInstance {
@Override
public String toString() {
- return "ZookeeperInstance{" + "id='" + this.id + '\'' +
- ", name='" + this.name + '\'' +
- ", metadata=" + this.metadata +
- '}';
+ return "ZookeeperInstance{" + "id='" + this.id + '\'' + ", name='" + this.name
+ + '\'' + ", metadata=" + this.metadata + '}';
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperRibbonClientConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperRibbonClientConfiguration.java
index b780f5fe..d7364135 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperRibbonClientConfiguration.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperRibbonClientConfiguration.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -18,9 +18,18 @@ package org.springframework.cloud.zookeeper.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.ILoadBalancer;
+import com.netflix.loadbalancer.IPing;
+import com.netflix.loadbalancer.PingUrl;
+import com.netflix.loadbalancer.ServerList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.curator.x.discovery.ServiceDiscovery;
+
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -32,15 +41,6 @@ import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDepende
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.ILoadBalancer;
-import com.netflix.loadbalancer.IPing;
-import com.netflix.loadbalancer.PingUrl;
-import com.netflix.loadbalancer.ServerList;
-
import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
@@ -56,9 +56,12 @@ import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity
*/
@Configuration
public class ZookeeperRibbonClientConfiguration {
- private static final Log log = LogFactory.getLog(ZookeeperRibbonClientConfiguration.class);
+
+ private static final Log log = LogFactory
+ .getLog(ZookeeperRibbonClientConfiguration.class);
protected static final String VALUE_NOT_SET = "__not__set__";
+
protected static final String DEFAULT_NAMESPACE = "ribbon";
@Value("${ribbon.client.name}")
@@ -75,7 +78,9 @@ public class ZookeeperRibbonClientConfiguration {
ServiceDiscovery serviceDiscovery) {
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
serverList.initFromDependencies(config, zookeeperDependencies);
- log.debug(String.format("Server list for Ribbon's dependencies based load balancing is [%s]", serverList));
+ log.debug(String.format(
+ "Server list for Ribbon's dependencies based load balancing is [%s]",
+ serverList));
return serverList;
}
@@ -83,9 +88,11 @@ public class ZookeeperRibbonClientConfiguration {
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.ribbon.loadbalancer", matchIfMissing = true)
- public ILoadBalancer dependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies,
- ServerList> serverList, IClientConfig config, IPing iPing) {
- return new DependenciesBasedLoadBalancer(zookeeperDependencies, serverList, config, iPing);
+ public ILoadBalancer dependenciesBasedLoadBalancer(
+ ZookeeperDependencies zookeeperDependencies, ServerList> serverList,
+ IClientConfig config, IPing iPing) {
+ return new DependenciesBasedLoadBalancer(zookeeperDependencies, serverList,
+ config, iPing);
}
@Bean
@@ -102,11 +109,12 @@ public class ZookeeperRibbonClientConfiguration {
ServiceDiscovery serviceDiscovery) {
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
serverList.initWithNiwsConfig(config);
- log.debug(String.format("Server list for Ribbon's non-dependency based load balancing is [%s]", serverList));
+ log.debug(String.format(
+ "Server list for Ribbon's non-dependency based load balancing is [%s]",
+ serverList));
return serverList;
}
-
@Bean
public ServerIntrospector serverIntrospector() {
return new ZookeeperServerIntrospector();
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServer.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServer.java
index 716644d2..49b9bc12 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServer.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServer.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,12 +16,11 @@
package org.springframework.cloud.zookeeper.discovery;
+import com.netflix.loadbalancer.Server;
import org.apache.curator.x.discovery.ServiceInstance;
-import com.netflix.loadbalancer.Server;
-
/**
- * A Zookeeper version of a {@link Server Ribbon Server}
+ * A Zookeeper version of a {@link Server Ribbon Server}.
*
* @author Spencer Gibb
* @since 1.0.0
@@ -29,6 +28,7 @@ import com.netflix.loadbalancer.Server;
public class ZookeeperServer extends Server {
private final MetaInfo metaInfo;
+
private ServiceInstance instance;
public ZookeeperServer(final ServiceInstance instance) {
@@ -66,4 +66,5 @@ public class ZookeeperServer extends Server {
public ServiceInstance getInstance() {
return this.instance;
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerIntrospector.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerIntrospector.java
index c97db916..c65edb8c 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerIntrospector.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerIntrospector.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2017 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.
@@ -16,16 +16,18 @@
package org.springframework.cloud.zookeeper.discovery;
+import java.util.Map;
+
import com.netflix.loadbalancer.Server;
import org.apache.curator.x.discovery.ServiceInstance;
-import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector;
-import java.util.Map;
+import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector;
/**
* @author Spencer Gibb
*/
public class ZookeeperServerIntrospector extends DefaultServerIntrospector {
+
@Override
public boolean isSecure(Server server) {
if (server instanceof ZookeeperServer) {
@@ -47,4 +49,5 @@ public class ZookeeperServerIntrospector extends DefaultServerIntrospector {
}
return super.getMetadata(server);
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerList.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerList.java
index 1a65c184..1925a005 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerList.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServerList.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -21,22 +21,22 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.apache.curator.x.discovery.ServiceDiscovery;
-import org.apache.curator.x.discovery.ServiceInstance;
-import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
-import org.springframework.util.StringUtils;
-
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList;
+import org.apache.curator.x.discovery.ServiceDiscovery;
+import org.apache.curator.x.discovery.ServiceInstance;
+
+import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
+import org.springframework.util.StringUtils;
import static org.springframework.cloud.zookeeper.support.StatusConstants.INSTANCE_STATUS_KEY;
import static org.springframework.cloud.zookeeper.support.StatusConstants.STATUS_UP;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
- * Zookeeper version of {@link AbstractServerList} that returns the list of
- * servers on which instances are ran. The implementation is capable of resolving
- * the servers from {@link ZookeeperDependencies}.
+ * Zookeeper version of {@link AbstractServerList} that returns the list of servers on
+ * which instances are ran. The implementation is capable of resolving the servers from
+ * {@link ZookeeperDependencies}.
*
* @author Spencer Gibb
* @author Marcin Grzejszczak
@@ -45,6 +45,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
public class ZookeeperServerList extends AbstractServerList {
private String serviceId;
+
private final ServiceDiscovery serviceDiscovery;
public ZookeeperServerList(ServiceDiscovery serviceDiscovery) {
@@ -56,13 +57,18 @@ public class ZookeeperServerList extends AbstractServerList {
this.serviceId = clientConfig.getClientName();
}
- public void initFromDependencies(IClientConfig clientConfig, ZookeeperDependencies zookeeperDependencies) {
- this.serviceId = getServiceIdFromDepsOrClientName(clientConfig, zookeeperDependencies);
+ public void initFromDependencies(IClientConfig clientConfig,
+ ZookeeperDependencies zookeeperDependencies) {
+ this.serviceId = getServiceIdFromDepsOrClientName(clientConfig,
+ zookeeperDependencies);
}
- private String getServiceIdFromDepsOrClientName(IClientConfig clientConfig, ZookeeperDependencies zookeeperDependencies) {
- String serviceIdFromDeps = zookeeperDependencies.getPathForAlias(clientConfig.getClientName());
- return StringUtils.hasText(serviceIdFromDeps) ? serviceIdFromDeps : clientConfig.getClientName();
+ private String getServiceIdFromDepsOrClientName(IClientConfig clientConfig,
+ ZookeeperDependencies zookeeperDependencies) {
+ String serviceIdFromDeps = zookeeperDependencies
+ .getPathForAlias(clientConfig.getClientName());
+ return StringUtils.hasText(serviceIdFromDeps) ? serviceIdFromDeps
+ : clientConfig.getClientName();
}
@Override
@@ -89,8 +95,10 @@ public class ZookeeperServerList extends AbstractServerList {
List servers = new ArrayList<>();
for (ServiceInstance instance : instances) {
String instanceStatus = null;
- if (instance.getPayload() != null && instance.getPayload().getMetadata() != null) {
- instanceStatus = instance.getPayload().getMetadata().get(INSTANCE_STATUS_KEY);
+ if (instance.getPayload() != null
+ && instance.getPayload().getMetadata() != null) {
+ instanceStatus = instance.getPayload().getMetadata()
+ .get(INSTANCE_STATUS_KEY);
}
if (!StringUtils.hasText(instanceStatus) // backwards compatibility
|| instanceStatus.equalsIgnoreCase(STATUS_UP)) {
@@ -104,4 +112,5 @@ public class ZookeeperServerList extends AbstractServerList {
}
return Collections.EMPTY_LIST;
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstance.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstance.java
index d43008a6..f127f178 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstance.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstance.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2017 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.
@@ -23,27 +23,35 @@ import java.util.Map;
import org.springframework.cloud.client.ServiceInstance;
/**
- * A specific {@link ServiceInstance} describing a zookeeper service instance
+ * A specific {@link ServiceInstance} describing a zookeeper service instance.
*
- * @author Reda.Housni-Alaoui
+ * @author Reda Housni-Alaoui
* @author Tim Ysewyn
* @since 1.1.0
*/
public class ZookeeperServiceInstance implements ServiceInstance {
private final String serviceId;
+
private final String host;
+
private final int port;
+
private final boolean secure;
+
private final URI uri;
+
private final Map metadata;
+
private final org.apache.curator.x.discovery.ServiceInstance serviceInstance;
/**
* @param serviceId The service id to be used
- * @param serviceInstance The zookeeper service instance described by this service instance
+ * @param serviceInstance The zookeeper service instance described by this service
+ * instance
*/
- public ZookeeperServiceInstance(String serviceId, org.apache.curator.x.discovery.ServiceInstance serviceInstance) {
+ public ZookeeperServiceInstance(String serviceId,
+ org.apache.curator.x.discovery.ServiceInstance serviceInstance) {
this.serviceId = serviceId;
this.serviceInstance = serviceInstance;
this.host = this.serviceInstance.getAddress();
@@ -56,7 +64,8 @@ public class ZookeeperServiceInstance implements ServiceInstance {
this.uri = URI.create(serviceInstance.buildUriSpec());
if (serviceInstance.getPayload() != null) {
this.metadata = serviceInstance.getPayload().getMetadata();
- } else {
+ }
+ else {
this.metadata = new HashMap<>();
}
}
@@ -99,4 +108,5 @@ public class ZookeeperServiceInstance implements ServiceInstance {
public org.apache.curator.x.discovery.ServiceInstance getServiceInstance() {
return this.serviceInstance;
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstances.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstances.java
index 18d81377..8ab17e4e 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstances.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceInstances.java
@@ -1,3 +1,19 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.springframework.cloud.zookeeper.discovery;
import java.util.ArrayList;
@@ -10,6 +26,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceInstance;
+
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
import static org.springframework.cloud.zookeeper.discovery.DependencyPathUtils.sanitize;
@@ -19,6 +36,7 @@ import static org.springframework.cloud.zookeeper.discovery.DependencyPathUtils.
* {@link ZookeeperDependencies} it will return a list of registered Zookeeper instances
* corresponding to the ones defined in the dependencies.
*
+ * @author Marcin Grzejszczak
* @since 1.0.0
*/
public class ZookeeperServiceInstances
@@ -27,9 +45,13 @@ public class ZookeeperServiceInstances
private static final Log log = LogFactory.getLog(ZookeeperServiceInstances.class);
private ServiceDiscovery serviceDiscovery;
+
private final ZookeeperDependencies zookeeperDependencies;
+
private final ZookeeperDiscoveryProperties zookeeperDiscoveryProperties;
+
private final List> allInstances;
+
private final CuratorFramework curator;
public ZookeeperServiceInstances(CuratorFramework curator,
@@ -74,9 +96,11 @@ public class ZookeeperServiceInstances
try {
List children = this.curator.getChildren().forPath(parentPath);
return iterateOverChildren(accumulator, parentPath, children);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
if (log.isTraceEnabled()) {
- log.trace("Exception occurred while trying to retrieve children of [" + parentPath + "]", e);
+ log.trace("Exception occurred while trying to retrieve children of ["
+ + parentPath + "]", e);
}
return injectZookeeperServiceInstances(accumulator, parentPath);
}
@@ -90,8 +114,7 @@ public class ZookeeperServiceInstances
private Collection> tryToGetInstances(
String path) {
try {
- return getServiceDiscovery()
- .queryForInstances(getPathWithoutRoot(path));
+ return getServiceDiscovery().queryForInstances(getPathWithoutRoot(path));
}
catch (Exception e) {
log.trace("Exception occurred while trying to retrieve instances of [" + path
@@ -111,7 +134,8 @@ public class ZookeeperServiceInstances
private List> injectZookeeperServiceInstances(
List> accumulator, String name)
throws Exception {
- Collection> instances = getServiceDiscovery().queryForInstances(name);
+ Collection> instances = getServiceDiscovery()
+ .queryForInstances(name);
accumulator.addAll(convertCollectionToList(instances));
return accumulator;
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceWatch.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceWatch.java
index 4ffa5e2f..9b08d8b6 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceWatch.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/ZookeeperServiceWatch.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -16,13 +16,15 @@
package org.springframework.cloud.zookeeper.discovery;
-import javax.annotation.PreDestroy;
import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.PreDestroy;
+
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
+
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationEventPublisher;
@@ -31,20 +33,24 @@ import org.springframework.context.ApplicationListener;
import org.springframework.util.ReflectionUtils;
/**
- * A {@link TreeCacheListener} that sends {@link HeartbeatEvent} when an
- * entry inside Zookeeper has changed.
+ * A {@link TreeCacheListener} that sends {@link HeartbeatEvent} when an entry inside
+ * Zookeeper has changed.
*
* @author Spencer Gibb
* @since 1.0.0
*/
-public class ZookeeperServiceWatch implements
- ApplicationListener>, TreeCacheListener,
+public class ZookeeperServiceWatch
+ implements ApplicationListener>, TreeCacheListener,
ApplicationEventPublisherAware {
private final CuratorFramework curator;
+
private final ZookeeperDiscoveryProperties properties;
+
private final AtomicLong cacheChange = new AtomicLong(0);
+
private ApplicationEventPublisher publisher;
+
private TreeCache cache;
public ZookeeperServiceWatch(CuratorFramework curator,
@@ -64,7 +70,8 @@ public class ZookeeperServiceWatch implements
@Override
public void onApplicationEvent(InstanceRegisteredEvent> event) {
- this.cache = TreeCache.newBuilder(this.curator, this.properties.getRoot()).build();
+ this.cache = TreeCache.newBuilder(this.curator, this.properties.getRoot())
+ .build();
this.cache.getListenable().addListener(this);
try {
this.cache.start();
@@ -82,7 +89,8 @@ public class ZookeeperServiceWatch implements
}
@Override
- public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
+ public void childEvent(CuratorFramework client, TreeCacheEvent event)
+ throws Exception {
if (event.getType().equals(TreeCacheEvent.Type.NODE_ADDED)
|| event.getType().equals(TreeCacheEvent.Type.NODE_REMOVED)
|| event.getType().equals(TreeCacheEvent.Type.NODE_UPDATED)) {
@@ -90,4 +98,5 @@ public class ZookeeperServiceWatch implements
this.publisher.publishEvent(new HeartbeatEvent(this, newCacheChange));
}
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java
index 0ff259b0..a8a6f966 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 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.
@@ -39,15 +39,19 @@ import org.springframework.core.annotation.Order;
@ConditionalOnProperty(value = "spring.cloud.config.discovery.enabled", matchIfMissing = false)
@Configuration
@Import({ ZookeeperAutoConfiguration.class, ZookeeperDiscoveryClientConfiguration.class,
- CuratorServiceDiscoveryAutoConfiguration.class, ZookeeperDiscoveryAutoConfiguration.class})
+ CuratorServiceDiscoveryAutoConfiguration.class,
+ ZookeeperDiscoveryAutoConfiguration.class })
@Order(0)
public class ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration {
@Bean
- public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(InetUtils inetUtils) {
- ZookeeperDiscoveryProperties properties = new ZookeeperDiscoveryProperties(inetUtils);
+ public ZookeeperDiscoveryProperties zookeeperDiscoveryProperties(
+ InetUtils inetUtils) {
+ ZookeeperDiscoveryProperties properties = new ZookeeperDiscoveryProperties(
+ inetUtils);
// for bootstrap, registration is not needed, just discovery client
properties.setRegister(false);
return properties;
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesNotPassed.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesNotPassed.java
index 5a6fdbc8..a42baa91 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesNotPassed.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesNotPassed.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -24,13 +24,14 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
- * Annotation to turn off a feature if Zookeeper dependencies have NOT been passed
+ * Annotation to turn off a feature if Zookeeper dependencies have NOT been passed.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Conditional(DependenciesNotPassedCondition.class)
public @interface ConditionalOnDependenciesNotPassed {
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesPassed.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesPassed.java
index 2edd7ccc..9bf66459 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesPassed.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/ConditionalOnDependenciesPassed.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -24,14 +24,15 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
- * Annotation to turn on a feature if Zookeeper dependencies have been passed.
- * Also checks if switch for zookeeper dependencies is turned on.
+ * Annotation to turn on a feature if Zookeeper dependencies have been passed. Also checks
+ * if switch for zookeeper dependencies is turned on.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Conditional(DependenciesPassedCondition.class)
public @interface ConditionalOnDependenciesPassed {
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesBasedLoadBalancer.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesBasedLoadBalancer.java
index e7d29edb..5f4f9e39 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesBasedLoadBalancer.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesBasedLoadBalancer.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -27,13 +27,12 @@ import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * LoadBalancer that delegates to other rules depending on the provided load balancing strategy
- * in the {@link ZookeeperDependency#getLoadBalancerType()}
+ * LoadBalancer that delegates to other rules depending on the provided load balancing
+ * strategy in the {@link ZookeeperDependency#getLoadBalancerType()}.
*
* @author Marcin Grzejszczak
* @since 1.0.0
@@ -46,7 +45,8 @@ public class DependenciesBasedLoadBalancer extends DynamicServerListLoadBalancer
private final ZookeeperDependencies zookeeperDependencies;
- public DependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies, ServerList> serverList, IClientConfig config, IPing iPing) {
+ public DependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies,
+ ServerList> serverList, IClientConfig config, IPing iPing) {
super(config);
this.zookeeperDependencies = zookeeperDependencies;
setServersList(serverList.getInitialListOfServers());
@@ -59,17 +59,24 @@ public class DependenciesBasedLoadBalancer extends DynamicServerListLoadBalancer
String keyAsString;
if ("default".equals(key)) { // this is the default hint, use name instead
keyAsString = getName();
- } else {
+ }
+ else {
keyAsString = (String) key;
}
- ZookeeperDependency dependency = this.zookeeperDependencies.getDependencyForAlias(keyAsString);
- log.debug(String.format("Current dependencies are [%s]", this.zookeeperDependencies));
+ ZookeeperDependency dependency = this.zookeeperDependencies
+ .getDependencyForAlias(keyAsString);
+ log.debug(String.format("Current dependencies are [%s]",
+ this.zookeeperDependencies));
if (dependency == null) {
- log.debug(String.format("No dependency found for alias [%s] - will use the default rule which is [%s]", keyAsString, this.rule));
+ log.debug(String.format(
+ "No dependency found for alias [%s] - will use the default rule which is [%s]",
+ keyAsString, this.rule));
return this.rule.choose(key);
}
cacheEntryIfMissing(keyAsString, dependency);
- log.debug(String.format("Will try to retrieve dependency for key [%s]. Current cache contents [%s]", keyAsString, this.ruleCache));
+ log.debug(String.format(
+ "Will try to retrieve dependency for key [%s]. Current cache contents [%s]",
+ keyAsString, this.ruleCache));
updateListOfServers();
return this.ruleCache.get(keyAsString).choose(key);
}
@@ -77,20 +84,21 @@ public class DependenciesBasedLoadBalancer extends DynamicServerListLoadBalancer
private void cacheEntryIfMissing(String keyAsString, ZookeeperDependency dependency) {
if (!this.ruleCache.containsKey(keyAsString)) {
log.debug(String.format("Cache doesn't contain entry for [%s]", keyAsString));
- this.ruleCache.put(keyAsString, chooseRuleForLoadBalancerType(dependency.getLoadBalancerType()));
+ this.ruleCache.put(keyAsString,
+ chooseRuleForLoadBalancerType(dependency.getLoadBalancerType()));
}
}
private IRule chooseRuleForLoadBalancerType(LoadBalancerType type) {
switch (type) {
- case ROUND_ROBIN:
- return getRoundRobinRule();
- case RANDOM:
- return getRandomRule();
- case STICKY:
- return getStickyRule();
- default:
- throw new IllegalArgumentException("Unknown load balancer type " + type);
+ case ROUND_ROBIN:
+ return getRoundRobinRule();
+ case RANDOM:
+ return getRandomRule();
+ case STICKY:
+ return getStickyRule();
+ default:
+ throw new IllegalArgumentException("Unknown load balancer type " + type);
}
}
@@ -109,4 +117,5 @@ public class DependenciesBasedLoadBalancer extends DynamicServerListLoadBalancer
stickyRule.setLoadBalancer(this);
return stickyRule;
}
+
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesNotPassedCondition.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesNotPassedCondition.java
index 68d06f46..1f84eb46 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesNotPassedCondition.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesNotPassedCondition.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.zookeeper.discovery.dependency;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -20,7 +21,7 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
- * Inverse of the {@link ConditionalOnDependenciesPassed} condition.
+ * Inverse of the {@link ConditionalOnDependenciesPassed} condition.
*
* @author Marcin Grzejszczak
* @since 1.0.0
@@ -28,7 +29,8 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
public class DependenciesNotPassedCondition extends DependenciesPassedCondition {
@Override
- public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ public ConditionOutcome getMatchOutcome(ConditionContext context,
+ AnnotatedTypeMetadata metadata) {
ConditionOutcome propertiesSet = super.getMatchOutcome(context, metadata);
return ConditionOutcome.inverse(propertiesSet);
}
diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesPassedCondition.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesPassedCondition.java
index 27e61a39..d8233660 100644
--- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesPassedCondition.java
+++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/dependency/DependenciesPassedCondition.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.zookeeper.discovery.dependency;
import java.util.Collections;
@@ -26,8 +27,8 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
- * Condition that verifies if the Dependencies have been passed in an appropriate
- * place in the application properties.
+ * Condition that verifies if the Dependencies have been passed in an appropriate place in
+ * the application properties.
*
* @author Marcin Grzejszczak
* @since 1.0.0
@@ -36,21 +37,26 @@ public class DependenciesPassedCondition extends SpringBootCondition {
private static final Bindable