Skip to content

Commit

Permalink
[ISSUE #4686] Admin actively synchronizes http service offline events…
Browse files Browse the repository at this point in the history
… 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 9812311.

* [ISSUE #4686] Admin actively synchronizes http service offline events to the gateway

---------

Co-authored-by: dragon-zhang <[email protected]>
  • Loading branch information
xuziyang and loongs-zhang authored Jul 16, 2023
1 parent 788d362 commit 22b4a8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ public void executor(final Collection<URIRegisterDTO> dataList) {
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);
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

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;
Expand Down Expand Up @@ -139,21 +138,16 @@ public void removeByKey(final String key) {
/**
* 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +33,7 @@
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;
Expand All @@ -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
Expand Down

0 comments on commit 22b4a8c

Please sign in to comment.