Commit b9a47960 by Ryan Baxter

Merge remote-tracking branch 'origin/master' into 2.0.x

parents 5cfe0f07 05a3db3c
...@@ -38,7 +38,6 @@ Example eureka client: ...@@ -38,7 +38,6 @@ Example eureka client:
@Configuration @Configuration
@ComponentScan @ComponentScan
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableEurekaClient
@RestController @RestController
public class Application { public class Application {
...@@ -54,9 +53,8 @@ public class Application { ...@@ -54,9 +53,8 @@ public class Application {
} }
---- ----
(i.e. utterly normal Spring Boot app). In this example we use (i.e. utterly normal Spring Boot app). By having `spring-cloud-starter-netflix-eureka-client`
`@EnableEurekaClient` explicitly, but with only Eureka available you on the classpath your application will automatically register with the Eureka Server. Configuration is required to
could also use `@EnableDiscoveryClient`. Configuration is required to
locate the Eureka server. Example: locate the Eureka server. Example:
...@@ -76,7 +74,8 @@ The default application name (service ID), virtual host and non-secure ...@@ -76,7 +74,8 @@ The default application name (service ID), virtual host and non-secure
port, taken from the `Environment`, are `${spring.application.name}`, port, taken from the `Environment`, are `${spring.application.name}`,
`${spring.application.name}` and `${server.port}` respectively. `${spring.application.name}` and `${server.port}` respectively.
`@EnableEurekaClient` makes the app into both a Eureka "instance" Having `spring-cloud-starter-netflix-eureka-client` on the classpath
makes the app into both a Eureka "instance"
(i.e. it registers itself) and a "client" (i.e. it can query the (i.e. it registers itself) and a "client" (i.e. it can query the
registry to locate other services). The instance behaviour is driven registry to locate other services). The instance behaviour is driven
by `eureka.instance.*` configuration keys, but the defaults will be by `eureka.instance.*` configuration keys, but the defaults will be
...@@ -86,6 +85,8 @@ ID, or VIP). ...@@ -86,6 +85,8 @@ ID, or VIP).
See {github-code}/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java[EurekaInstanceConfigBean] and {github-code}/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java[EurekaClientConfigBean] for more details of the configurable options. See {github-code}/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java[EurekaInstanceConfigBean] and {github-code}/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java[EurekaClientConfigBean] for more details of the configurable options.
To disable the Eureka Discovery Client you can set `eureka.client.enabled` to `false`.
=== Authenticating with the Eureka Server === Authenticating with the Eureka Server
HTTP basic authentication will be automatically added to your eureka HTTP basic authentication will be automatically added to your eureka
...@@ -240,7 +241,7 @@ random value will not be needed. ...@@ -240,7 +241,7 @@ random value will not be needed.
=== Using the EurekaClient === Using the EurekaClient
Once you have an app that is `@EnableDiscoveryClient` (or `@EnableEurekaClient`) you can use it to Once you have an app that is a discovery client you can use it to
discover service instances from the <<spring-cloud-eureka-server, discover service instances from the <<spring-cloud-eureka-server,
Eureka Server>>. One way to do that is to use the native Eureka Server>>. One way to do that is to use the native
`com.netflix.discovery.EurekaClient` (as opposed to the Spring `com.netflix.discovery.EurekaClient` (as opposed to the Spring
...@@ -971,7 +972,6 @@ Example spring boot app ...@@ -971,7 +972,6 @@ Example spring boot app
@Configuration @Configuration
@ComponentScan @ComponentScan
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableEurekaClient
@EnableFeignClients @EnableFeignClients
public class Application { public class Application {
...@@ -2656,6 +2656,9 @@ certain Ribbon properties. The properties you can use are ...@@ -2656,6 +2656,9 @@ certain Ribbon properties. The properties you can use are
`client.ribbon.OkToRetryOnAllOperations`. See the https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties[Ribbon documentation] `client.ribbon.OkToRetryOnAllOperations`. See the https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties[Ribbon documentation]
for a description of what there properties do. for a description of what there properties do.
WARNING: Enabling `client.ribbon.OkToRetryOnAllOperations` includes retring POST requests wich can have a impact
on the server's resources due to the buffering of the request's body.
In addition you may want to retry requests when certain status codes are returned in the In addition you may want to retry requests when certain status codes are returned in the
response. You can list the response codes you would like the Ribbon client to retry using the response. You can list the response codes you would like the Ribbon client to retry using the
property `clientName.ribbon.retryableStatusCodes`. For example property `clientName.ribbon.retryableStatusCodes`. For example
......
...@@ -275,8 +275,10 @@ public class SpringMvcContract extends Contract.BaseContract ...@@ -275,8 +275,10 @@ public class SpringMvcContract extends Contract.BaseContract
if (annotation.headers() != null && annotation.headers().length > 0) { if (annotation.headers() != null && annotation.headers().length > 0) {
for (String header : annotation.headers()) { for (String header : annotation.headers()) {
int index = header.indexOf('='); int index = header.indexOf('=');
md.template().header(resolve(header.substring(0, index)), if (!header.contains("!=") && index >= 0) {
md.template().header(resolve(header.substring(0, index)),
resolve(header.substring(index + 1).trim())); resolve(header.substring(index + 1).trim()));
}
} }
} }
} }
......
...@@ -22,7 +22,6 @@ import java.lang.annotation.RetentionPolicy; ...@@ -22,7 +22,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
...@@ -37,7 +36,6 @@ import org.springframework.context.annotation.Import; ...@@ -37,7 +36,6 @@ import org.springframework.context.annotation.Import;
* @author Biju Kunjummen * @author Biju Kunjummen
*/ */
@EnableCircuitBreaker @EnableCircuitBreaker
@EnableDiscoveryClient
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Import(ZuulProxyMarkerConfiguration.class) @Import(ZuulProxyMarkerConfiguration.class)
......
...@@ -157,30 +157,15 @@ public class ProxyRequestHelper { ...@@ -157,30 +157,15 @@ public class ProxyRequestHelper {
context.setResponseDataStream(entity); context.setResponseDataStream(entity);
} }
HttpHeaders httpHeaders = new HttpHeaders();
for (Entry<String, List<String>> header : headers.entrySet()) {
List<String> values = header.getValue();
for (String value : values) {
httpHeaders.add(header.getKey(), value);
}
}
boolean isOriginResponseGzipped = false; boolean isOriginResponseGzipped = false;
if (httpHeaders.containsKey(CONTENT_ENCODING)) {
List<String> collection = httpHeaders.get(CONTENT_ENCODING);
for (String header : collection) {
if (HTTPRequestUtils.getInstance().isGzipped(header)) {
isOriginResponseGzipped = true;
break;
}
}
}
context.setResponseGZipped(isOriginResponseGzipped);
for (Entry<String, List<String>> header : headers.entrySet()) { for (Entry<String, List<String>> header : headers.entrySet()) {
String name = header.getKey(); String name = header.getKey();
for (String value : header.getValue()) { for (String value : header.getValue()) {
context.addOriginResponseHeader(name, value); if (name.equalsIgnoreCase(HttpHeaders.CONTENT_ENCODING)
if (name.equalsIgnoreCase(CONTENT_LENGTH)) { && HTTPRequestUtils.getInstance().isGzipped(value)) {
isOriginResponseGzipped = true;
}
if (name.equalsIgnoreCase(HttpHeaders.CONTENT_LENGTH)) {
context.setOriginContentLength(value); context.setOriginContentLength(value);
} }
if (isIncludedHeader(name)) { if (isIncludedHeader(name)) {
...@@ -188,6 +173,7 @@ public class ProxyRequestHelper { ...@@ -188,6 +173,7 @@ public class ProxyRequestHelper {
} }
} }
} }
context.setResponseGZipped(isOriginResponseGzipped);
} }
public void addIgnoredHeaders(String... names) { public void addIgnoredHeaders(String... names) {
......
...@@ -16,6 +16,13 @@ ...@@ -16,6 +16,13 @@
package org.springframework.cloud.netflix.zuul.filters.route; package org.springframework.cloud.netflix.zuul.filters.route;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.support.ResettableServletInputStreamWrapper;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StreamUtils;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
...@@ -23,11 +30,6 @@ import java.util.ArrayList; ...@@ -23,11 +30,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -38,26 +40,27 @@ public class RibbonCommandContext { ...@@ -38,26 +40,27 @@ public class RibbonCommandContext {
private final Boolean retryable; private final Boolean retryable;
private final MultiValueMap<String, String> headers; private final MultiValueMap<String, String> headers;
private final MultiValueMap<String, String> params; private final MultiValueMap<String, String> params;
private final InputStream requestEntity;
private final List<RibbonRequestCustomizer> requestCustomizers; private final List<RibbonRequestCustomizer> requestCustomizers;
private InputStream requestEntity;
private Long contentLength; private Long contentLength;
/** /**
* Kept for backwards compatibility with Spring Cloud Sleuth 1.x versions * Kept for backwards compatibility with Spring Cloud Sleuth 1.x versions
*/ */
@Deprecated @Deprecated
public RibbonCommandContext(String serviceId, String method, String uri, public RibbonCommandContext(String serviceId, String method,
Boolean retryable, MultiValueMap<String, String> headers, String uri, Boolean retryable, MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity) { MultiValueMap<String, String> params, InputStream requestEntity) {
this(serviceId, method, uri, retryable, headers, params, requestEntity, this(serviceId, method, uri, retryable, headers, params, requestEntity,
new ArrayList<RibbonRequestCustomizer>(), null); new ArrayList<RibbonRequestCustomizer>(), null);
} }
public RibbonCommandContext(String serviceId, String method, String uri, public RibbonCommandContext(String serviceId, String method, String uri,
Boolean retryable, MultiValueMap<String, String> headers, Boolean retryable, MultiValueMap<String, String> headers,
MultiValueMap<String, String> params, InputStream requestEntity, MultiValueMap<String, String> params, InputStream requestEntity,
List<RibbonRequestCustomizer> requestCustomizers) { List<RibbonRequestCustomizer> requestCustomizers) {
this(serviceId, method, uri, retryable, headers, params, requestEntity, requestCustomizers, null); this(serviceId, method, uri, retryable, headers, params, requestEntity,
requestCustomizers, null);
} }
public RibbonCommandContext(String serviceId, String method, String uri, public RibbonCommandContext(String serviceId, String method, String uri,
...@@ -84,8 +87,7 @@ public class RibbonCommandContext { ...@@ -84,8 +87,7 @@ public class RibbonCommandContext {
public URI uri() { public URI uri() {
try { try {
return new URI(this.uri); return new URI(this.uri);
} } catch (URISyntaxException e) {
catch (URISyntaxException e) {
ReflectionUtils.rethrowRuntimeException(e); ReflectionUtils.rethrowRuntimeException(e);
} }
return null; return null;
...@@ -93,6 +95,7 @@ public class RibbonCommandContext { ...@@ -93,6 +95,7 @@ public class RibbonCommandContext {
/** /**
* Use getMethod() * Use getMethod()
*
* @return * @return
*/ */
@Deprecated @Deprecated
...@@ -125,7 +128,19 @@ public class RibbonCommandContext { ...@@ -125,7 +128,19 @@ public class RibbonCommandContext {
} }
public InputStream getRequestEntity() { public InputStream getRequestEntity() {
return requestEntity; if (requestEntity == null) {
return requestEntity;
}
try {
if (!(requestEntity instanceof ResettableServletInputStreamWrapper)) {
requestEntity = new ResettableServletInputStreamWrapper(
StreamUtils.copyToByteArray(requestEntity));
}
requestEntity.reset();
} finally {
return requestEntity;
}
} }
public List<RibbonRequestCustomizer> getRequestCustomizers() { public List<RibbonRequestCustomizer> getRequestCustomizers() {
...@@ -142,23 +157,25 @@ public class RibbonCommandContext { ...@@ -142,23 +157,25 @@ public class RibbonCommandContext {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o)
if (o == null || getClass() != o.getClass()) return false; return true;
if (o == null || getClass() != o.getClass())
return false;
RibbonCommandContext that = (RibbonCommandContext) o; RibbonCommandContext that = (RibbonCommandContext) o;
return Objects.equals(serviceId, that.serviceId) && return Objects.equals(serviceId, that.serviceId) && Objects
Objects.equals(method, that.method) && .equals(method, that.method) && Objects.equals(uri, that.uri)
Objects.equals(uri, that.uri) && && Objects.equals(retryable, that.retryable) && Objects
Objects.equals(retryable, that.retryable) && .equals(headers, that.headers) && Objects
Objects.equals(headers, that.headers) && .equals(params, that.params) && Objects
Objects.equals(params, that.params) && .equals(requestEntity, that.requestEntity) && Objects
Objects.equals(requestEntity, that.requestEntity) && .equals(requestCustomizers, that.requestCustomizers) && Objects
Objects.equals(requestCustomizers, that.requestCustomizers) && .equals(contentLength, that.contentLength);
Objects.equals(contentLength, that.contentLength);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(serviceId, method, uri, retryable, headers, params, requestEntity, requestCustomizers, contentLength); return Objects.hash(serviceId, method, uri, retryable, headers, params,
requestEntity, requestCustomizers, contentLength);
} }
@Override @Override
......
/*
* Copyright 2013-2017 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.netflix.zuul.filters.support;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class ResettableServletInputStreamWrapper extends ServletInputStream {
private final ByteArrayInputStream input;
public ResettableServletInputStreamWrapper(byte[] data) {
this.input = new ByteArrayInputStream(data);
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener listener) {
}
@Override
public int read() throws IOException {
return input.read();
}
@Override
public synchronized void reset() throws IOException {
input.reset();
}
}
...@@ -21,8 +21,8 @@ import org.junit.runner.RunWith; ...@@ -21,8 +21,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
import org.springframework.cloud.netflix.zuul.FormZuulServletProxyApplicationTests; import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonCommandCauseFallbackPropagationTest;
import org.springframework.cloud.netflix.zuul.filters.route.LazyLoadOfZuulConfigurationTests; import org.springframework.cloud.netflix.zuul.filters.route.support.RibbonCommandHystrixThreadPoolKeyTests;
/** /**
* A test suite for probing weird ordering problems in the tests. * A test suite for probing weird ordering problems in the tests.
...@@ -30,8 +30,8 @@ import org.springframework.cloud.netflix.zuul.filters.route.LazyLoadOfZuulConfig ...@@ -30,8 +30,8 @@ import org.springframework.cloud.netflix.zuul.filters.route.LazyLoadOfZuulConfig
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ FormZuulServletProxyApplicationTests.class, @SuiteClasses({ RibbonCommandHystrixThreadPoolKeyTests.class,
LazyLoadOfZuulConfigurationTests.class }) RibbonCommandCauseFallbackPropagationTest.class })
@Ignore @Ignore
public class AdhocTestSuite { public class AdhocTestSuite {
......
...@@ -333,6 +333,18 @@ public class SpringMvcContractTests { ...@@ -333,6 +333,18 @@ public class SpringMvcContractTests {
} }
@Test @Test
public void testProcessHeadersWithoutValues() throws Exception {
Method method = TestTemplate_HeadersWithoutValues.class.getDeclaredMethod("getTest",
String.class);
MethodMetadata data = this.contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertEquals("/test/{id}", data.template().url());
assertEquals("GET", data.template().method());
assertEquals(true, data.template().headers().isEmpty());
}
@Test
public void testProcessAnnotations_Fallback() throws Exception { public void testProcessAnnotations_Fallback() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTestFallback", Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTestFallback",
String.class, String.class, Integer.class); String.class, String.class, Integer.class);
...@@ -462,6 +474,11 @@ public class SpringMvcContractTests { ...@@ -462,6 +474,11 @@ public class SpringMvcContractTests {
ResponseEntity<TestObject> getTest(@PathVariable("id") String id); ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
} }
public interface TestTemplate_HeadersWithoutValues {
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, headers = { "X-Foo", "!X-Bar", "X-Baz!=fooBar" })
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
}
public interface TestTemplate_ListParams { public interface TestTemplate_ListParams {
@RequestMapping(value = "/test", method = RequestMethod.GET) @RequestMapping(value = "/test", method = RequestMethod.GET)
ResponseEntity<TestObject> getTest(@RequestParam("id") List<String> id); ResponseEntity<TestObject> getTest(@RequestParam("id") List<String> id);
......
...@@ -89,7 +89,6 @@ public class ProxyRequestHelperTests { ...@@ -89,7 +89,6 @@ public class ProxyRequestHelperTests {
helper.debug("POST", "http://example.com", headers, helper.debug("POST", "http://example.com", headers,
new LinkedMultiValueMap<String, String>(), request.getInputStream()); new LinkedMultiValueMap<String, String>(), request.getInputStream());
Trace actual = this.traceRepository.findAll().get(0); Trace actual = this.traceRepository.findAll().get(0);
System.err.println(actual.getInfo());
assertThat((String) actual.getInfo().get("body"), equalTo("{}")); assertThat((String) actual.getInfo().get("body"), equalTo("{}"));
} }
......
package org.springframework.cloud.netflix.zuul.filters.route;
import com.google.common.collect.Lists;
import okhttp3.Request;
import org.junit.Test;
import org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer;
import org.springframework.cloud.netflix.zuul.filters.support.ResettableServletInputStreamWrapper;
import org.springframework.http.HttpMethod;
import org.springframework.util.LinkedMultiValueMap;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Andre Dörnbrack
*/
public class RibbonCommandContextTest {
private static final byte[] TEST_CONTENT = { 42, 42, 42, 42, 42 };
private RibbonCommandContext ribbonCommandContext;
@Test
public void testMultipleReadsOnRequestEntity() throws Exception {
givenRibbonCommandContextIsSetup();
InputStream requestEntity = ribbonCommandContext.getRequestEntity();
assertTrue(requestEntity instanceof ResettableServletInputStreamWrapper);
whenInputStreamIsConsumed(requestEntity);
assertEquals(-1, requestEntity.read());
requestEntity.reset();
assertNotEquals(-1, requestEntity.read());
whenInputStreamIsConsumed(requestEntity);
assertEquals(-1, requestEntity.read());
requestEntity.reset();
assertNotEquals(-1, requestEntity.read());
whenInputStreamIsConsumed(requestEntity);
assertEquals(-1, requestEntity.read());
}
private void whenInputStreamIsConsumed(InputStream requestEntity) throws IOException {
while (requestEntity.read() != -1) {
requestEntity.read();
}
}
private void givenRibbonCommandContextIsSetup() {
LinkedMultiValueMap headers = new LinkedMultiValueMap();
LinkedMultiValueMap params = new LinkedMultiValueMap();
RibbonRequestCustomizer requestCustomizer = new RibbonRequestCustomizer<Request.Builder>() {
@Override
public boolean accepts(Class builderClass) {
return builderClass == Request.Builder.class;
}
@Override
public void customize(Request.Builder builder) {
builder.addHeader("from-customizer", "foo");
}
};
ribbonCommandContext = new RibbonCommandContext("serviceId",
HttpMethod.POST.toString(), "/my/route", true, headers, params,
new ByteArrayInputStream(TEST_CONTENT),
Lists.newArrayList(requestCustomizer));
}
}
\ No newline at end of file
...@@ -20,8 +20,12 @@ import com.netflix.client.AbstractLoadBalancerAwareClient; ...@@ -20,8 +20,12 @@ import com.netflix.client.AbstractLoadBalancerAwareClient;
import com.netflix.client.ClientRequest; import com.netflix.client.ClientRequest;
import com.netflix.client.http.HttpResponse; import com.netflix.client.http.HttpResponse;
import com.netflix.hystrix.HystrixCommandProperties; import com.netflix.hystrix.HystrixCommandProperties;
import com.netflix.hystrix.strategy.HystrixPlugins;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -38,25 +42,38 @@ public class RibbonCommandHystrixThreadPoolKeyTests { ...@@ -38,25 +42,38 @@ public class RibbonCommandHystrixThreadPoolKeyTests {
zuulProperties = new ZuulProperties(); zuulProperties = new ZuulProperties();
} }
@After
public void tearDown() throws Exception {
HystrixPlugins.reset();
}
@Test @Test
public void testDefaultHystrixThreadPoolKey() throws Exception { public void testDefaultHystrixThreadPoolKey() throws Exception {
zuulProperties.setRibbonIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD); zuulProperties.setRibbonIsolationStrategy(
HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);
TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1", zuulProperties); TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1",
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2", zuulProperties); zuulProperties);
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2",
zuulProperties);
// CommandGroupKey should be used as ThreadPoolKey as default. // CommandGroupKey should be used as ThreadPoolKey as default.
assertThat(ribbonCommand1.getThreadPoolKey().name()).isEqualTo(ribbonCommand1.getCommandGroup().name()); assertThat(ribbonCommand1.getThreadPoolKey().name())
assertThat(ribbonCommand2.getThreadPoolKey().name()).isEqualTo(ribbonCommand2.getCommandGroup().name()); .isEqualTo(ribbonCommand1.getCommandGroup().name());
assertThat(ribbonCommand2.getThreadPoolKey().name())
.isEqualTo(ribbonCommand2.getCommandGroup().name());
} }
@Test @Test
public void testUseSeparateThreadPools() throws Exception { public void testUseSeparateThreadPools() throws Exception {
zuulProperties.setRibbonIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD); zuulProperties.setRibbonIsolationStrategy(
HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);
zuulProperties.getThreadPool().setUseSeparateThreadPools(true); zuulProperties.getThreadPool().setUseSeparateThreadPools(true);
TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1", zuulProperties); TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1",
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2", zuulProperties); zuulProperties);
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2",
zuulProperties);
assertThat(ribbonCommand1.getThreadPoolKey().name()).isEqualTo("testCommand1"); assertThat(ribbonCommand1.getThreadPoolKey().name()).isEqualTo("testCommand1");
assertThat(ribbonCommand2.getThreadPoolKey().name()).isEqualTo("testCommand2"); assertThat(ribbonCommand2.getThreadPoolKey().name()).isEqualTo("testCommand2");
...@@ -66,35 +83,45 @@ public class RibbonCommandHystrixThreadPoolKeyTests { ...@@ -66,35 +83,45 @@ public class RibbonCommandHystrixThreadPoolKeyTests {
public void testThreadPoolKeyPrefix() throws Exception { public void testThreadPoolKeyPrefix() throws Exception {
final String prefix = "zuulgw-"; final String prefix = "zuulgw-";
zuulProperties.setRibbonIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD); zuulProperties.setRibbonIsolationStrategy(
HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);
zuulProperties.getThreadPool().setUseSeparateThreadPools(true); zuulProperties.getThreadPool().setUseSeparateThreadPools(true);
zuulProperties.getThreadPool().setThreadPoolKeyPrefix(prefix); zuulProperties.getThreadPool().setThreadPoolKeyPrefix(prefix);
TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1", zuulProperties); TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1",
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2", zuulProperties); zuulProperties);
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2",
zuulProperties);
assertThat(ribbonCommand1.getThreadPoolKey().name()).isEqualTo(prefix + "testCommand1"); assertThat(ribbonCommand1.getThreadPoolKey().name())
assertThat(ribbonCommand2.getThreadPoolKey().name()).isEqualTo(prefix + "testCommand2"); .isEqualTo(prefix + "testCommand1");
assertThat(ribbonCommand2.getThreadPoolKey().name())
.isEqualTo(prefix + "testCommand2");
} }
@Test @Test
public void testNoSideEffectOnSemaphoreIsolation() throws Exception { public void testNoSideEffectOnSemaphoreIsolation() throws Exception {
final String prefix = "zuulgw-"; final String prefix = "zuulgw-";
zuulProperties.setRibbonIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE); zuulProperties.setRibbonIsolationStrategy(
HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
zuulProperties.getThreadPool().setUseSeparateThreadPools(true); zuulProperties.getThreadPool().setUseSeparateThreadPools(true);
zuulProperties.getThreadPool().setThreadPoolKeyPrefix(prefix); zuulProperties.getThreadPool().setThreadPoolKeyPrefix(prefix);
TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1", zuulProperties); TestRibbonCommand ribbonCommand1 = new TestRibbonCommand("testCommand1",
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2", zuulProperties); zuulProperties);
TestRibbonCommand ribbonCommand2 = new TestRibbonCommand("testCommand2",
zuulProperties);
// There should be no side effect on semaphore isolation // There should be no side effect on semaphore isolation
assertThat(ribbonCommand1.getThreadPoolKey().name()).isEqualTo(ribbonCommand1.getCommandGroup().name()); assertThat(ribbonCommand1.getThreadPoolKey().name())
assertThat(ribbonCommand2.getThreadPoolKey().name()).isEqualTo(ribbonCommand2.getCommandGroup().name()); .isEqualTo(ribbonCommand1.getCommandGroup().name());
assertThat(ribbonCommand2.getThreadPoolKey().name())
.isEqualTo(ribbonCommand2.getCommandGroup().name());
} }
public static class TestRibbonCommand public static class TestRibbonCommand extends
extends AbstractRibbonCommand<AbstractLoadBalancerAwareClient<ClientRequest, HttpResponse>, ClientRequest, HttpResponse> { AbstractRibbonCommand<AbstractLoadBalancerAwareClient<ClientRequest, HttpResponse>, ClientRequest, HttpResponse> {
public TestRibbonCommand(String commandKey, ZuulProperties zuulProperties) { public TestRibbonCommand(String commandKey, ZuulProperties zuulProperties) {
super(commandKey, null, null, zuulProperties); super(commandKey, null, null, zuulProperties);
} }
......
...@@ -23,8 +23,6 @@ import java.lang.annotation.Retention; ...@@ -23,8 +23,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/** /**
* Convenience annotation for clients to enable Eureka discovery configuration * Convenience annotation for clients to enable Eureka discovery configuration
* (specifically). Use this (optionally) in case you want discovery and know for sure that * (specifically). Use this (optionally) in case you want discovery and know for sure that
...@@ -39,7 +37,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; ...@@ -39,7 +37,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Inherited @Inherited
@EnableDiscoveryClient
public @interface EnableEurekaClient { public @interface EnableEurekaClient {
} }
...@@ -73,8 +73,6 @@ import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs; ...@@ -73,8 +73,6 @@ import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.EurekaClient; import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig; import com.netflix.discovery.EurekaClientConfig;
import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceId;
/** /**
* @author Dave Syer * @author Dave Syer
* @author Spencer Gibb * @author Spencer Gibb
...@@ -91,7 +89,9 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI ...@@ -91,7 +89,9 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
@ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true) @ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
@AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class, @AutoConfigureBefore({ NoopDiscoveryClientAutoConfiguration.class,
CommonsClientAutoConfiguration.class, ServiceRegistryAutoConfiguration.class }) CommonsClientAutoConfiguration.class, ServiceRegistryAutoConfiguration.class })
@AutoConfigureAfter(name = "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration") @AutoConfigureAfter(name = {"org.springframework.cloud.autoconfigure.RefreshAutoConfiguration",
"org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration",
"org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration"})
public class EurekaClientAutoConfiguration { public class EurekaClientAutoConfiguration {
private static final Log log = LogFactory.getLog(EurekaClientAutoConfiguration.class); private static final Log log = LogFactory.getLog(EurekaClientAutoConfiguration.class);
......
...@@ -2,10 +2,9 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ ...@@ -2,10 +2,9 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\ org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\
org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceAutoConfiguration,\ org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceAutoConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\ org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\
org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration,\
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\ org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceBootstrapConfiguration org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceBootstrapConfiguration
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
...@@ -27,7 +27,6 @@ import org.springframework.boot.actuate.health.HealthIndicator; ...@@ -27,7 +27,6 @@ import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
...@@ -62,7 +61,6 @@ public class EurekaHealthCheckTests { ...@@ -62,7 +61,6 @@ public class EurekaHealthCheckTests {
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableEurekaClient
protected static class EurekaHealthCheckApplication { protected static class EurekaHealthCheckApplication {
@Bean @Bean
......
...@@ -25,7 +25,6 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit ...@@ -25,7 +25,6 @@ import org.springframework.boot.actuate.metrics.repository.InMemoryMetricReposit
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry; import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.cloud.commons.util.InetUtils; import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
...@@ -48,7 +47,6 @@ import static org.springframework.web.bind.annotation.RequestMethod.POST; ...@@ -48,7 +47,6 @@ import static org.springframework.web.bind.annotation.RequestMethod.POST;
@ComponentScan @ComponentScan
@EnableAutoConfiguration @EnableAutoConfiguration
@RestController @RestController
@EnableDiscoveryClient
public class EurekaSampleApplication implements ApplicationContextAware, Closeable { public class EurekaSampleApplication implements ApplicationContextAware, Closeable {
@Autowired @Autowired
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.springframework.cloud.netflix.eureka.sample; package org.springframework.cloud.netflix.eureka.sample;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient; import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
...@@ -37,7 +36,6 @@ import static org.mockito.Mockito.mock; ...@@ -37,7 +36,6 @@ import static org.mockito.Mockito.mock;
@ComponentScan @ComponentScan
@EnableAutoConfiguration @EnableAutoConfiguration
@RestController @RestController
@EnableDiscoveryClient
public class RefreshEurekaSampleApplication { public class RefreshEurekaSampleApplication {
@Bean @Bean
......
...@@ -27,7 +27,6 @@ import org.springframework.boot.SpringBootConfiguration; ...@@ -27,7 +27,6 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
...@@ -56,7 +55,6 @@ public class RibbonEurekaAutoConfigurationTests { ...@@ -56,7 +55,6 @@ public class RibbonEurekaAutoConfigurationTests {
@SpringBootConfiguration @SpringBootConfiguration
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableDiscoveryClient
public static class EurekaClientDisabledApp { public static class EurekaClientDisabledApp {
@Bean @Bean
......
...@@ -22,7 +22,6 @@ import java.lang.annotation.Retention; ...@@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
...@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Import; ...@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Import;
* *
*/ */
@EnableDiscoveryClient
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
......
...@@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; ...@@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
...@@ -31,7 +30,6 @@ import org.springframework.context.annotation.Import; ...@@ -31,7 +30,6 @@ import org.springframework.context.annotation.Import;
* @author Spencer Gibb * @author Spencer Gibb
*/ */
@EnableCircuitBreaker @EnableCircuitBreaker
@EnableDiscoveryClient
@EnableZuulProxy @EnableZuulProxy
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
......
...@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -30,7 +29,6 @@ import org.springframework.web.bind.annotation.RestController;
* @author Spencer Gibb * @author Spencer Gibb
*/ */
@EnableAutoConfiguration @EnableAutoConfiguration
@EnableDiscoveryClient
@Configuration @Configuration
@RestController @RestController
public class SidecarClientApplication { public class SidecarClientApplication {
......
...@@ -23,7 +23,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -23,7 +23,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.actuator.HasFeatures; import org.springframework.cloud.client.actuator.HasFeatures;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -36,7 +35,6 @@ import com.netflix.turbine.streaming.servlet.TurbineStreamServlet; ...@@ -36,7 +35,6 @@ import com.netflix.turbine.streaming.servlet.TurbineStreamServlet;
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@EnableDiscoveryClient
public class TurbineHttpConfiguration { public class TurbineHttpConfiguration {
@Bean @Bean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment