StatPluginFilter should sync the change if current gateway group is modified
This commit is contained in:
@@ -24,6 +24,7 @@ import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import we.FizzAppContext;
|
||||
import we.config.AggregateRedisConfig;
|
||||
import we.flume.clients.log4j2appender.LogService;
|
||||
import we.util.Consts;
|
||||
@@ -165,8 +166,7 @@ public class GatewayGroupService {
|
||||
return Mono.just(ReactorUtils.EMPTY_THROWABLE);
|
||||
}
|
||||
|
||||
private void updateGatewayGroupMap(GatewayGroup gg, Map<String, GatewayGroup> gatewayGroupMap,
|
||||
Set<String> currentGatewayGroupSet) {
|
||||
private void updateGatewayGroupMap(GatewayGroup gg, Map<String, GatewayGroup> gatewayGroupMap, Set<String> currentGatewayGroupSet) {
|
||||
if (gg.isDeleted == GatewayGroup.DELETED) {
|
||||
GatewayGroup r = gatewayGroupMap.remove(gg.group);
|
||||
log.info("remove " + r);
|
||||
@@ -182,8 +182,7 @@ public class GatewayGroupService {
|
||||
updateCurrentGatewayGroupSet(currentGatewayGroupSet, gatewayGroupMap);
|
||||
}
|
||||
|
||||
private void updateCurrentGatewayGroupSet(Set<String> currentGatewayGroupSet, Map<String,
|
||||
GatewayGroup> gatewayGroupMap) {
|
||||
private void updateCurrentGatewayGroupSet(Set<String> currentGatewayGroupSet, Map<String, GatewayGroup> gatewayGroupMap) {
|
||||
Set<String> ips = NetworkUtils.getServerIps();
|
||||
String applicationName = environment.getProperty("spring.application.name");
|
||||
currentGatewayGroupSet.clear();
|
||||
@@ -199,6 +198,7 @@ public class GatewayGroupService {
|
||||
if (currentGatewayGroupSet.isEmpty()) {
|
||||
currentGatewayGroupSet.add(GatewayGroup.DEFAULT);
|
||||
}
|
||||
// publish event
|
||||
}
|
||||
|
||||
public boolean currentGatewayGroupIn(Set<String> gatewayGroups) {
|
||||
|
||||
@@ -71,6 +71,7 @@ public class StatPluginFilter extends PluginFilter {
|
||||
@Resource
|
||||
private GatewayGroupService gatewayGroupService;
|
||||
|
||||
/*
|
||||
private String currentGatewayGroups;
|
||||
|
||||
@PostConstruct
|
||||
@@ -84,6 +85,7 @@ public class StatPluginFilter extends PluginFilter {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Mono<Void> doFilter(ServerWebExchange exchange, Map<String, Object> config, String fixedConfig) {
|
||||
@@ -92,7 +94,7 @@ public class StatPluginFilter extends PluginFilter {
|
||||
StringBuilder b = ThreadContext.getStringBuilder();
|
||||
b.append(Consts.S.LEFT_BRACE);
|
||||
b.append(ip); toJsonStringValue(b, WebUtils.getOriginIp(exchange)); b.append(Consts.S.COMMA);
|
||||
b.append(gatewayGroup); toJsonStringValue(b, currentGatewayGroups); b.append(Consts.S.COMMA);
|
||||
b.append(gatewayGroup); toJsonStringValue(b, currentGatewayGroups()); b.append(Consts.S.COMMA);
|
||||
b.append(service); toJsonStringValue(b, WebUtils.getClientService(exchange)); b.append(Consts.S.COMMA);
|
||||
|
||||
String appId = WebUtils.getAppId(exchange);
|
||||
@@ -115,6 +117,23 @@ public class StatPluginFilter extends PluginFilter {
|
||||
return WebUtils.transmitSuccessFilterResultAndEmptyMono(exchange, STAT_PLUGIN_FILTER, null);
|
||||
}
|
||||
|
||||
private String currentGatewayGroups() {
|
||||
int sz = gatewayGroupService.currentGatewayGroupSet.size();
|
||||
if (sz == 1) {
|
||||
return gatewayGroupService.currentGatewayGroupSet.iterator().next();
|
||||
}
|
||||
StringBuilder b = ThreadContext.getStringBuilder();
|
||||
byte i = 0;
|
||||
for (String g : gatewayGroupService.currentGatewayGroupSet) {
|
||||
b.append(g);
|
||||
i++;
|
||||
if (i < sz) {
|
||||
b.append(Consts.S.COMMA);
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private static void toJsonStringValue(StringBuilder b, String value) {
|
||||
b.append(Consts.S.DOUBLE_QUOTE).append(value).append(Consts.S.DOUBLE_QUOTE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user