This is an automated email from the ASF dual-hosted git repository.
zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 22b4a8cd9 [ISSUE #4686] Admin actively synchronizes http service
offline events to the gateway (#4846)
22b4a8cd9 is described below
commit 22b4a8cd9579be01eb6083af330e445a9568f99c
Author: xuziyang <[email protected]>
AuthorDate: Sun Jul 16 23:17:40 2023 +0800
[ISSUE #4686] Admin actively synchronizes http service offline events to
the gateway (#4846)
* [ISSUE #4686] divide plugin active offline support shenyu-admin cluster
* Revert "[ISSUE #4686] divide plugin active offline support shenyu-admin
cluster"
This reverts commit 9812311d036aa7be50614c7131794cbd91d09786.
* [ISSUE #4686] Admin actively synchronizes http service offline events to
the gateway
---------
Co-authored-by: dragon-zhang <[email protected]>
---
.../subscriber/URIRegisterExecutorSubscriber.java | 8 ++++++--
.../loadbalancer/cache/UpstreamCacheManager.java | 20 +++++++-------------
.../divide/handler/DividePluginDataHandler.java | 6 +++---
3 files changed, 16 insertions(+), 18 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/disruptor/subscriber/URIRegisterExecutorSubscriber.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/disruptor/subscriber/URIRegisterExecutorSubscriber.java
index 5c08bf6de..e41e6e26e 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/disruptor/subscriber/URIRegisterExecutorSubscriber.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/disruptor/subscriber/URIRegisterExecutorSubscriber.java
@@ -82,8 +82,12 @@ public class URIRegisterExecutorSubscriber implements
ExecutorTypeSubscriber<URI
offline.add(d);
}
}
- service.registerURI(selectorName, register);
- service.offline(selectorName, offline);
+ if (CollectionUtils.isNotEmpty(register)) {
+ service.registerURI(selectorName, register);
+ }
+ if (CollectionUtils.isNotEmpty(offline)) {
+ service.offline(selectorName, offline);
+ }
});
});
}
diff --git
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
index 630b9f155..f5a27b8d6 100644
---
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
+++
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
@@ -19,7 +19,6 @@ package org.apache.shenyu.loadbalancer.cache;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
import org.apache.shenyu.common.config.ShenyuConfig;
import org.apache.shenyu.common.config.ShenyuConfig.UpstreamCheck;
@@ -139,21 +138,16 @@ public final class UpstreamCacheManager {
/**
* Submit .
*
- * @param selectorId the selector id
+ * @param selectorId the selector id
* @param upstreamList the upstream list
*/
public void submit(final String selectorId, final List<Upstream>
upstreamList) {
List<Upstream> validUpstreamList =
upstreamList.stream().filter(Upstream::isStatus).collect(Collectors.toList());
- if (CollectionUtils.isNotEmpty(validUpstreamList)) {
- List<Upstream> existUpstream =
MapUtils.computeIfAbsent(UPSTREAM_MAP, selectorId, k -> Lists.newArrayList());
- existUpstream.stream().filter(upstream ->
!validUpstreamList.contains(upstream))
- .forEach(upstream -> task.triggerRemoveOne(selectorId,
upstream));
- validUpstreamList.stream().filter(upstream ->
!existUpstream.contains(upstream))
- .forEach(upstream -> task.triggerAddOne(selectorId,
upstream));
- UPSTREAM_MAP.put(selectorId, validUpstreamList);
- } else {
- UPSTREAM_MAP.remove(selectorId);
- task.triggerRemoveAll(selectorId);
- }
+ List<Upstream> existUpstream = MapUtils.computeIfAbsent(UPSTREAM_MAP,
selectorId, k -> Lists.newArrayList());
+ existUpstream.stream().filter(upstream ->
!validUpstreamList.contains(upstream))
+ .forEach(upstream -> task.triggerRemoveOne(selectorId,
upstream));
+ validUpstreamList.stream().filter(upstream ->
!existUpstream.contains(upstream))
+ .forEach(upstream -> task.triggerAddOne(selectorId, upstream));
+ UPSTREAM_MAP.put(selectorId, validUpstreamList);
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
index 1dda62a41..e43ec6bfd 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/handler/DividePluginDataHandler.java
@@ -17,7 +17,6 @@
package org.apache.shenyu.plugin.divide.handler;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
@@ -34,6 +33,7 @@ import org.apache.shenyu.plugin.base.utils.BeanHolder;
import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -47,10 +47,10 @@ public class DividePluginDataHandler implements
PluginDataHandler {
@Override
public void handlerSelector(final SelectorData selectorData) {
- List<DivideUpstream> upstreamList =
GsonUtils.getInstance().fromList(selectorData.getHandle(),
DivideUpstream.class);
- if (CollectionUtils.isEmpty(upstreamList)) {
+ if (Objects.isNull(selectorData) ||
Objects.isNull(selectorData.getId())) {
return;
}
+ List<DivideUpstream> upstreamList =
GsonUtils.getInstance().fromList(selectorData.getHandle(),
DivideUpstream.class);
UpstreamCacheManager.getInstance().submit(selectorData.getId(),
convertUpstreamList(upstreamList));
// the update is also need to clean, but there is no way to
// distinguish between crate and update, so it is always clean