added @EnableCircuitBreaker deprecated @EnableHystrix.
removed classes now in spring-cloud-commons
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -36,6 +36,11 @@
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-client</artifactId>
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-client</artifactId>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.springframework.cloud.client;
|
||||
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* TODO: name? Server? HostAndPort? Instance?
|
||||
*/
|
||||
public interface ServiceInstance {
|
||||
public String getServiceId();
|
||||
public String getHost();
|
||||
public int getPort();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public interface DiscoveryClient {
|
||||
/**
|
||||
* @return ServiceInstance with information used to register the local service
|
||||
*/
|
||||
public ServiceInstance getLocalServiceInstance();
|
||||
|
||||
public List<ServiceInstance> getInstances(String serviceId);
|
||||
|
||||
public List<String> getServices();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import(EnableDiscoveryClientImportSelector.class)
|
||||
public @interface EnableDiscoveryClient {
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.context.annotation.DeferredImportSelector;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Order(Ordered.LOWEST_PRECEDENCE - 100)
|
||||
@Slf4j
|
||||
public class EnableDiscoveryClientImportSelector implements DeferredImportSelector,
|
||||
BeanClassLoaderAware {
|
||||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata metadata) {
|
||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata
|
||||
.getAnnotationAttributes(EnableDiscoveryClient.class.getName(),
|
||||
true));
|
||||
|
||||
Assert.notNull(attributes, "No EnableDiscoveryClient attributes found. Is "
|
||||
+ metadata.getClassName()
|
||||
+ " annotated with @EnableDiscoveryClient?");
|
||||
|
||||
// Find all possible auto configuration classes, filtering duplicates
|
||||
List<String> factories = new ArrayList<>(new LinkedHashSet<>(
|
||||
SpringFactoriesLoader.loadFactoryNames(EnableDiscoveryClient.class,
|
||||
this.beanClassLoader)));
|
||||
|
||||
if (factories.size() > 1) {
|
||||
String factory = factories.get(0);
|
||||
//there should only every be one DiscoveryClient
|
||||
log.warn("More than one implementation of @EnableDiscoveryClient. Using {} out of available {}", factory, factories);
|
||||
factories = Collections.singletonList(factory);
|
||||
}
|
||||
|
||||
return factories.toArray(new String[factories.size()]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class InstanceRegisteredEvent extends ApplicationEvent {
|
||||
private Object config;
|
||||
|
||||
/**
|
||||
* Create a new ApplicationEvent.
|
||||
*
|
||||
* @param source the component that published the event (never {@code null})
|
||||
*/
|
||||
public InstanceRegisteredEvent(Object source, Object config) {
|
||||
super(source);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public Object getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package org.springframework.cloud.client.loadbalancer;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public interface LoadBalancerClient {
|
||||
/**
|
||||
* Choose a {@see ServiceInstance} from the LoadBalancer for the specified service
|
||||
* @param serviceId the service id to look up the LoadBalancer
|
||||
* @return a ServiceInstance that matches the serviceId
|
||||
*/
|
||||
public ServiceInstance choose(String serviceId);
|
||||
|
||||
/**
|
||||
* Choose a {@see ServiceInstance} from the LoadBalancer for the specified service
|
||||
* @param serviceId the service id to look up the LoadBalancer
|
||||
* @param request allows implementations to execute pre and post actions such as incrementing metrics
|
||||
* @return the result of the LoadBalancerRequest callback on the selected ServiceInstance
|
||||
*/
|
||||
public <T> T execute(String serviceId, LoadBalancerRequest<T> request);
|
||||
|
||||
public URI reconstructURI(ServiceInstance instance, URI original);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.springframework.cloud.client.loadbalancer;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public interface LoadBalancerRequest<T> {
|
||||
public T apply(ServiceInstance instance) throws Exception;
|
||||
}
|
||||
@@ -96,4 +96,24 @@ public class EurekaDiscoveryClient implements DiscoveryClient {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getAllInstances() {
|
||||
Applications applications = discovery.getApplications();
|
||||
if (applications == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Iterable<ServiceInstance> instances = transform(concat(transform(applications.getRegisteredApplications(), new Function<Application, List<InstanceInfo>>() {
|
||||
public List<InstanceInfo> apply(@Nullable Application app) {
|
||||
return app.getInstances();
|
||||
}
|
||||
})), new Function<InstanceInfo, ServiceInstance>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ServiceInstance apply(@Nullable InstanceInfo info) {
|
||||
return new EurekaServiceInstance(info);
|
||||
}
|
||||
});
|
||||
return Lists.newArrayList(instances);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,6 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import(HystrixConfiguration.class)
|
||||
@Deprecated
|
||||
public @interface EnableHystrix {
|
||||
}
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.netflix.hystrix;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.netflix.hystrix.Hystrix;
|
||||
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
|
||||
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller;
|
||||
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller.MetricsAsJsonPollerListener;
|
||||
import org.apache.catalina.core.ApplicationContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -34,26 +33,20 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.netflix.hystrix.Hystrix;
|
||||
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
|
||||
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller;
|
||||
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller.MetricsAsJsonPollerListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
@Configuration
|
||||
public class HystrixConfiguration implements ImportAware {
|
||||
|
||||
private AnnotationAttributes enableHystrix;
|
||||
public class HystrixConfiguration {
|
||||
|
||||
@Bean
|
||||
public HystrixCommandAspect hystrixCommandAspect() {
|
||||
@@ -77,16 +70,6 @@ public class HystrixConfiguration implements ImportAware {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableHystrix = AnnotationAttributes.fromMap(importMetadata
|
||||
.getAnnotationAttributes(EnableHystrix.class.getName(), false));
|
||||
Assert.notNull(
|
||||
this.enableHystrix,
|
||||
"@EnableHystrix is not present on importing class "
|
||||
+ importMetadata.getClassName());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(GaugeService.class)
|
||||
protected static class HystrixMetricsPollerConfiguration implements SmartLifecycle {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package org.springframework.cloud.netflix.zuul;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@EnableHystrix
|
||||
@EnableEurekaClient
|
||||
@EnableCircuitBreaker
|
||||
@EnableDiscoveryClient
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Import(ZuulConfiguration.class)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.springframework.cloud.netflix.zuul;
|
||||
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
@@ -10,8 +10,8 @@ import java.lang.annotation.*;
|
||||
* @author Spencer Gibb
|
||||
* @deprecated @see org.springframework.cloud.netflix.zuul.EnableZuulProxy
|
||||
*/
|
||||
@EnableHystrix
|
||||
@EnableEurekaClient
|
||||
@EnableCircuitBreaker
|
||||
@EnableDiscoveryClient
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
|
||||
@@ -12,4 +12,7 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration
|
||||
|
||||
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
|
||||
org.springframework.cloud.netflix.eureka.EurekaClientConfiguration
|
||||
org.springframework.cloud.netflix.eureka.EurekaClientConfiguration
|
||||
|
||||
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
|
||||
org.springframework.cloud.netflix.hystrix.HystrixConfiguration
|
||||
@@ -42,6 +42,10 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-core</artifactId>
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-core</artifactId>
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-core</artifactId>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.springframework.cloud.netflix.sidecar;
|
||||
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.lang.annotation.*;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@EnableHystrix
|
||||
@EnableEurekaClient
|
||||
@EnableCircuitBreaker
|
||||
@EnableDiscoveryClient
|
||||
@EnableZuulProxy
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-core</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user