Skip to content

Commit 3bbb208

Browse files
committed
支持spring cloud F版本
1 parent e1258a0 commit 3bbb208

File tree

312 files changed

+9372
-11121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+9372
-11121
lines changed

pom.xml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>org.springframework.boot</groupId>
99
<artifactId>spring-boot-starter-parent</artifactId>
10-
<version>1.5.4.RELEASE</version>
10+
<version>2.0.9.RELEASE</version>
1111
</parent>
1212
<groupId>cn.springcloud.gray</groupId>
1313
<artifactId>spring-cloud-gray</artifactId>
1414
<packaging>pom</packaging>
15-
<version>A.1.1.0-SNAPSHOT</version>
15+
<version>B.0.0.1-SNAPSHOT</version>
1616
<url>https://github.com/SpringCloud/spring-cloud-gray</url>
1717
<organization>
1818
<name>Spring Cloud中国社区</name>
@@ -61,11 +61,14 @@
6161
<maven.compiler.source>1.8</maven.compiler.source>
6262
<maven.compiler.target>1.8</maven.compiler.target>
6363
<java.version>1.8</java.version>
64-
<spring-cloud.version>Edgware.SR6</spring-cloud.version>
64+
<spring-cloud.version>Finchley.SR4</spring-cloud.version>
65+
<spring-security-oauth2.version>2.3.6.RELEASE</spring-security-oauth2.version>
66+
<spring-security-jwt.version>1.0.10.RELEASE</spring-security-jwt.version>
6567
<springfox.version>2.9.2</springfox.version>
6668
<lombok.version>1.18.8</lombok.version>
6769
<slf4j.version>1.7.26</slf4j.version>
6870
<commons-lang3.version>3.5</commons-lang3.version>
71+
<commons-collections.version>3.2.2</commons-collections.version>
6972
<commons-beanutils.version>1.9.3</commons-beanutils.version>
7073
<guava.version>27.0.1-jre</guava.version>
7174
<mapstruct.version>1.1.0.Final</mapstruct.version>
@@ -153,8 +156,6 @@
153156
</dependency>
154157

155158

156-
157-
158159
<!-- gray client plugins start -->
159160

160161
<dependency>
@@ -163,6 +164,12 @@
163164
<version>${project.version}</version>
164165
</dependency>
165166

167+
<dependency>
168+
<groupId>cn.springcloud.gray</groupId>
169+
<artifactId>spring-cloud-gray-plugin-webflux</artifactId>
170+
<version>${project.version}</version>
171+
</dependency>
172+
166173
<dependency>
167174
<groupId>cn.springcloud.gray</groupId>
168175
<artifactId>spring-cloud-gray-plugin-eureka</artifactId>
@@ -181,6 +188,12 @@
181188
<version>${project.version}</version>
182189
</dependency>
183190

191+
<dependency>
192+
<groupId>cn.springcloud.gray</groupId>
193+
<artifactId>spring-cloud-gray-plugin-gateway</artifactId>
194+
<version>${project.version}</version>
195+
</dependency>
196+
184197
<dependency>
185198
<groupId>cn.springcloud.gray</groupId>
186199
<artifactId>spring-cloud-gray-plugin-event-stream</artifactId>
@@ -207,6 +220,24 @@
207220
<!-- gray server plugins end -->
208221

209222

223+
<dependency>
224+
<groupId>org.springframework.security.oauth</groupId>
225+
<artifactId>spring-security-oauth2</artifactId>
226+
<version>${spring-security-oauth2.version}</version>
227+
<exclusions>
228+
<exclusion>
229+
<groupId>org.springframework.security</groupId>
230+
<artifactId>spring-security-jwt</artifactId>
231+
</exclusion>
232+
</exclusions>
233+
</dependency>
234+
<dependency>
235+
<groupId>org.springframework.security</groupId>
236+
<artifactId>spring-security-jwt</artifactId>
237+
<version>${spring-security-jwt.version}</version>
238+
</dependency>
239+
240+
210241
<dependency>
211242
<groupId>org.aspectj</groupId>
212243
<artifactId>aspectjrt</artifactId>
@@ -246,6 +277,12 @@
246277
<artifactId>commons-lang3</artifactId>
247278
<version>${commons-lang3.version}</version>
248279
</dependency>
280+
<dependency>
281+
<groupId>commons-collections</groupId>
282+
<artifactId>commons-collections</artifactId>
283+
<version>${commons-collections.version}</version>
284+
</dependency>
285+
249286
<dependency>
250287
<groupId>commons-beanutils</groupId>
251288
<artifactId>commons-beanutils</artifactId>

spring-cloud-gray-client-netflix/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>spring-cloud-gray</artifactId>
77
<groupId>cn.springcloud.gray</groupId>
8-
<version>A.1.1.0-SNAPSHOT</version>
8+
<version>B.0.0.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -47,6 +47,14 @@
4747
<groupId>org.springframework.cloud</groupId>
4848
<artifactId>spring-cloud-netflix-core</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.cloud</groupId>
52+
<artifactId>spring-cloud-netflix-zuul</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.cloud</groupId>
56+
<artifactId>spring-cloud-openfeign-core</artifactId>
57+
</dependency>
5058
<dependency>
5159
<groupId>org.springframework.cloud</groupId>
5260
<artifactId>spring-cloud-context</artifactId>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package cn.springcloud.gray.client.netflix;
2+
3+
import cn.springcloud.gray.GrayManager;
4+
import cn.springcloud.gray.ServerChooser;
5+
import cn.springcloud.gray.ServerListResult;
6+
import cn.springcloud.gray.choose.GrayPredicate;
7+
import cn.springcloud.gray.model.GrayService;
8+
import cn.springcloud.gray.request.GrayRequest;
9+
import cn.springcloud.gray.request.RequestLocalStorage;
10+
import cn.springcloud.gray.servernode.ServerExplainer;
11+
import cn.springcloud.gray.servernode.ServerListProcessor;
12+
import cn.springcloud.gray.servernode.ServerSpec;
13+
import com.netflix.loadbalancer.Server;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.stream.Collectors;
18+
19+
public class RibbonServerChooser implements ServerChooser<Server> {
20+
21+
private GrayManager grayManager;
22+
23+
private RequestLocalStorage requestLocalStorage;
24+
25+
private GrayPredicate grayPredicate;
26+
27+
private ServerExplainer<Server> serverExplainer;
28+
29+
protected ServerListProcessor serverListProcessor;
30+
31+
32+
public RibbonServerChooser(
33+
GrayManager grayManager,
34+
RequestLocalStorage requestLocalStorage,
35+
GrayPredicate grayPredicate,
36+
ServerExplainer<Server> serverExplainer,
37+
ServerListProcessor serverListProcessor) {
38+
this.grayManager = grayManager;
39+
this.requestLocalStorage = requestLocalStorage;
40+
this.grayPredicate = grayPredicate;
41+
this.serverExplainer = serverExplainer;
42+
this.serverListProcessor = serverListProcessor;
43+
}
44+
45+
@Override
46+
public boolean matchGrayDecisions(ServerSpec serverSpec) {
47+
return grayPredicate.apply(serverSpec);
48+
}
49+
50+
@Override
51+
public boolean matchGrayDecisions(Server server) {
52+
return matchGrayDecisions(serverExplainer.apply(server));
53+
}
54+
55+
@Override
56+
public ServerListResult<Server> distinguishServerList(List<Server> servers) {
57+
GrayRequest grayRequest = requestLocalStorage.getGrayRequest();
58+
if (grayRequest == null) {
59+
return null;
60+
}
61+
62+
return distinguishServerList(grayRequest.getServiceId(), servers);
63+
}
64+
65+
66+
@Override
67+
public ServerListResult<Server> distinguishAndMatchGrayServerList(List<Server> servers) {
68+
ServerListResult<Server> serverListResult = distinguishServerList(servers);
69+
if (serverListResult == null) {
70+
return null;
71+
}
72+
73+
serverListResult.setGrayServers(
74+
serverListResult.getGrayServers().stream()
75+
.filter(this::matchGrayDecisions)
76+
.collect(Collectors.toList()));
77+
78+
return serverListResult;
79+
}
80+
81+
82+
private ServerListResult<Server> distinguishServerList(String serviceId, List<Server> servers) {
83+
if (!grayManager.hasGray(serviceId)) {
84+
return null;
85+
}
86+
87+
GrayService grayService = grayManager.getGrayService(serviceId);
88+
List<Server> serverList = serverListProcessor.process(serviceId, servers);
89+
List<Server> grayServers = new ArrayList<>(grayService.getGrayInstances().size());
90+
List<Server> normalServers = new ArrayList<>(Math.min(servers.size(), grayService.getGrayInstances().size()));
91+
92+
for (Server server : serverList) {
93+
if (grayService.getGrayInstance(server.getMetaInfo().getInstanceId()) != null) {
94+
grayServers.add(server);
95+
} else {
96+
normalServers.add(server);
97+
}
98+
}
99+
100+
return new ServerListResult<>(serviceId, grayServers, normalServers);
101+
}
102+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cn.springcloud.gray.client.netflix.configuration.properties;
2+
3+
4+
import lombok.Data;
5+
import org.springframework.boot.context.properties.ConfigurationProperties;
6+
7+
@Data
8+
@ConfigurationProperties("gray.hystrix")
9+
public class GrayHystrixProperties {
10+
private boolean enabled;
11+
12+
private ThreadTransmitStrategy threadTransmitStrategy = ThreadTransmitStrategy.WRAP_CALLABLE;
13+
14+
public static enum ThreadTransmitStrategy {
15+
WRAP_CALLABLE, HYSTRIX_REQUEST_LOCAL_STORAGE
16+
}
17+
}

spring-cloud-gray-client-netflix/src/main/java/cn/springcloud/gray/client/netflix/feign/GrayFeignClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import feign.Response;
88
import org.apache.commons.lang3.StringUtils;
99
import org.springframework.beans.BeansException;
10-
import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient;
10+
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
1111
import org.springframework.context.ApplicationContext;
1212
import org.springframework.context.ApplicationContextAware;
1313

spring-cloud-gray-client-netflix/src/main/java/cn/springcloud/gray/client/netflix/feign/configuration/GrayFeignAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
99
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1010
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
11-
import org.springframework.cloud.netflix.feign.EnableFeignClients;
11+
import org.springframework.cloud.openfeign.EnableFeignClients;
1212
import org.springframework.context.annotation.Bean;
1313
import org.springframework.context.annotation.Configuration;
1414

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package cn.springcloud.gray.client.netflix.hystrix;
2+
3+
4+
import cn.springcloud.gray.concurrent.GrayCallable;
5+
import cn.springcloud.gray.concurrent.GrayConcurrentHelper;
6+
import com.netflix.hystrix.HystrixThreadPoolKey;
7+
import com.netflix.hystrix.HystrixThreadPoolProperties;
8+
import com.netflix.hystrix.strategy.HystrixPlugins;
9+
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
10+
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable;
11+
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle;
12+
import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
13+
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
14+
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
15+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
16+
import com.netflix.hystrix.strategy.properties.HystrixProperty;
17+
18+
import java.util.concurrent.BlockingQueue;
19+
import java.util.concurrent.Callable;
20+
import java.util.concurrent.ThreadPoolExecutor;
21+
import java.util.concurrent.TimeUnit;
22+
23+
public class GrayHystrixContextConcurrencyStrategy extends HystrixConcurrencyStrategy {
24+
private HystrixConcurrencyStrategy delegate;
25+
26+
public GrayHystrixContextConcurrencyStrategy() {
27+
this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
28+
if (this.delegate instanceof GrayHystrixContextConcurrencyStrategy) {
29+
return;
30+
}
31+
// Keeps references of existing Hystrix plugins.
32+
HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
33+
HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
34+
HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
35+
HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
36+
37+
HystrixPlugins.reset();
38+
39+
// Registers existing plugins excepts the Concurrent Strategy plugin.
40+
HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
41+
HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
42+
HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
43+
HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
44+
HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
45+
}
46+
47+
@Override
48+
public BlockingQueue<Runnable> getBlockingQueue(int maxQueueSize) {
49+
return delegate.getBlockingQueue(maxQueueSize);
50+
}
51+
52+
@Override
53+
public <T> HystrixRequestVariable<T> getRequestVariable(HystrixRequestVariableLifecycle<T> rv) {
54+
return delegate.getRequestVariable(rv);
55+
}
56+
57+
@Override
58+
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixProperty<Integer> corePoolSize, HystrixProperty<Integer> maximumPoolSize, HystrixProperty<Integer> keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
59+
return delegate.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
60+
}
61+
62+
@Override
63+
public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolProperties threadPoolProperties) {
64+
return delegate.getThreadPool(threadPoolKey, threadPoolProperties);
65+
}
66+
67+
@Override
68+
public <T> Callable<T> wrapCallable(Callable<T> callable) {
69+
Callable<T> delegateWrapCallable = delegate.wrapCallable(callable);
70+
if(delegateWrapCallable instanceof GrayCallable){
71+
return delegateWrapCallable;
72+
}
73+
return GrayConcurrentHelper.createDelegateCallable(delegateWrapCallable);
74+
}
75+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cn.springcloud.gray.client.netflix.ribbon;
2+
3+
import cn.springcloud.gray.GrayClientHolder;
4+
import cn.springcloud.gray.ServerChooser;
5+
import com.google.common.base.Optional;
6+
import com.netflix.loadbalancer.Server;
7+
import com.netflix.loadbalancer.ZoneAvoidanceRule;
8+
9+
public class GrayChooserRule extends ZoneAvoidanceRule {
10+
11+
private ServerChooser<Server> serverChooser;
12+
13+
public GrayChooserRule() {
14+
serverChooser = GrayClientHolder.getServerChooser();
15+
}
16+
17+
@Override
18+
public Server choose(Object key) {
19+
return serverChooser.chooseServer(getLoadBalancer().getAllServers(), servers -> {
20+
Optional<Server> server = getPredicate().chooseRoundRobinAfterFiltering(servers, key);
21+
if (server.isPresent()) {
22+
return server.get();
23+
} else {
24+
return null;
25+
}
26+
});
27+
}
28+
}

spring-cloud-gray-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>spring-cloud-gray</artifactId>
77
<groupId>cn.springcloud.gray</groupId>
8-
<version>A.1.1.0-SNAPSHOT</version>
8+
<version>B.0.0.1-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

0 commit comments

Comments
 (0)