同步网关配置问题调整

This commit is contained in:
akun 2024-05-11 11:44:56 +08:00
parent 366dca3e5b
commit 0b3bc2fd0e

View File

@ -106,11 +106,13 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
appConfig.setDataSecurity(initDataSecurity(gatewayConfig)); appConfig.setDataSecurity(initDataSecurity(gatewayConfig));
appConfig.setApiCurrentLimitingConfig(initApiCurrentLimitStrategy(gatewayConfig)); appConfig.setApiCurrentLimitingConfig(initApiCurrentLimitStrategy(gatewayConfig));
appConfig.setAppCurrentLimitingConfig(initAppCurrentLimitStrategy(gatewayConfig)); appConfig.setAppCurrentLimitingConfig(initAppCurrentLimitStrategy(gatewayConfig));
appConfig.setService(initService(appCode));
// appConfig.setAdvancedConfig(); // appConfig.setAdvancedConfig();
} }
appConfig.setService(initService(appCode));
try { try {
String response = HttpUtil.post(urlStr, JSON.toJSONString(appConfig)); String body = JSON.toJSONString(appConfig);
log.info("sync gateway body : {}", body);
String response = HttpUtil.post(urlStr, body);
log.info("sync gateway response : {}", response); log.info("sync gateway response : {}", response);
if (StringUtils.hasText(response)) { if (StringUtils.hasText(response)) {
JSONObject jsonObject = JSON.parseObject(response); JSONObject jsonObject = JSON.parseObject(response);
@ -132,25 +134,31 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
queryServer.setStatus(GatewayDataStatus.ENABLE.getCode()); queryServer.setStatus(GatewayDataStatus.ENABLE.getCode());
List<GatewayServer> serverList = gatewayServerService.selectGatewayServerList(queryServer); List<GatewayServer> serverList = gatewayServerService.selectGatewayServerList(queryServer);
if (CollUtil.isNotEmpty(serverList)) { if (CollUtil.isNotEmpty(serverList)) {
// 查询接口
List<GatewayInterfaceInfo> interfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(serverList.stream().map(GatewayServer::getId).collect(Collectors.toSet()));
// 启用的
interfaceInfoList = interfaceInfoList.stream().filter(api -> GatewayDataStatus.ENABLE.getCode().equals(api.getStatus())).collect(Collectors.toList());
if (CollUtil.isEmpty(interfaceInfoList)){
// 没有配置接口直接结束
return service;
}
Map<Long, List<GatewayInterfaceInfo>> groupByServerInterfaceMap = interfaceInfoList.stream().collect(Collectors.groupingBy(GatewayInterfaceInfo::getServerId));
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceInfoList.stream().map(GatewayInterfaceInfo::getId).collect(Collectors.toSet()));
Map<Long, List<GatewayInterfaceLinkStrategy>> groupByInterfaceLinkMap = linkList.stream().collect(Collectors.groupingBy(GatewayInterfaceLinkStrategy::getInterfaceId));
// 如果是路由模式的服务查询对应的路由服务信息 // 如果是路由模式的服务查询对应的路由服务信息
Collection<Long> routeIds = serverList.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel())) Collection<Long> routeIds = serverList.stream().filter(item -> GatewayServiceModel.ROUTE.getCode().equals(item.getServiceModel()))
.map(GatewayServer::getRouteId) .map(GatewayServer::getRouteId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
List<GatewayRoute> routeList = gatewayRouteService.selectGatewayRouteByIds(routeIds); List<GatewayRoute> routeList = gatewayRouteService.selectGatewayRouteByIds(routeIds);
Map<Long, GatewayRoute> routeMap = routeList.stream().collect(Collectors.toMap(GatewayRoute::getId, Function.identity())); Map<Long, GatewayRoute> routeMap = routeList.stream().collect(Collectors.toMap(GatewayRoute::getId, Function.identity()));
// 查询接口
List<GatewayInterfaceInfo> interfaceInfoList = gatewayInterfaceInfoService.selectGatewayInterfaceInfoByServerIds(serverList.stream().map(GatewayServer::getId).collect(Collectors.toSet()));
// 启用的
interfaceInfoList = interfaceInfoList.stream().filter(api -> GatewayDataStatus.ENABLE.getCode().equals(api.getStatus())).collect(Collectors.toList());
Map<Long, List<GatewayInterfaceInfo>> groupByServerInterfaceMap = interfaceInfoList.stream().collect(Collectors.groupingBy(GatewayInterfaceInfo::getServerId));
List<GatewayInterfaceLinkStrategy> linkList = gatewayInterfaceInfoService.selectGatewayInterfaceLinkStrategyByInterfaceIds(interfaceInfoList.stream().map(GatewayInterfaceInfo::getId).collect(Collectors.toSet()));
Map<Long, List<GatewayInterfaceLinkStrategy>> groupByInterfaceLinkMap = linkList.stream().collect(Collectors.groupingBy(GatewayInterfaceLinkStrategy::getInterfaceId));
// 查询接口策略 // 查询接口策略
List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet())); List<GatewayStrategy> strategyList = gatewayStrategyService.selectGatewayStrategyByIds(linkList.stream().map(GatewayInterfaceLinkStrategy::getStrategyId).collect(Collectors.toSet()));
// 启用的 // 启用的
strategyList = strategyList.stream().filter(strategy -> GatewayDataStatus.ENABLE.getCode().equals(strategy.getStatus())).collect(Collectors.toList()); strategyList = strategyList.stream().filter(strategy -> GatewayDataStatus.ENABLE.getCode().equals(strategy.getStatus())).collect(Collectors.toList());
Map<Long, GatewayStrategy> strategyMap = strategyList.stream().collect(Collectors.toMap(GatewayStrategy::getId, Function.identity())); Map<Long, GatewayStrategy> strategyMap = strategyList.stream().collect(Collectors.toMap(GatewayStrategy::getId, Function.identity()));
return serverList.stream().map(server -> { return serverList.stream()
.filter(server -> CollUtil.isNotEmpty(groupByServerInterfaceMap.getOrDefault(server.getId(), Collections.emptyList())))
.map(server -> {
SacService sacService = new SacService(); SacService sacService = new SacService();
sacService.setServiceName(server.getServerName()); sacService.setServiceName(server.getServerName());
sacService.setServiceModel(server.getServiceModel()); sacService.setServiceModel(server.getServiceModel());
@ -169,7 +177,6 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
return apiConfig; return apiConfig;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
sacService.setApiConfig(apiConfigList); sacService.setApiConfig(apiConfigList);
// 设置路由 // 设置路由
if (GatewayServiceModel.ROUTE.getCode().equals(server.getServiceModel())) { if (GatewayServiceModel.ROUTE.getCode().equals(server.getServiceModel())) {
GatewayRoute route = routeMap.get(server.getRouteId()); GatewayRoute route = routeMap.get(server.getRouteId());
@ -201,11 +208,13 @@ public class GatewayConfigServiceImpl implements IGatewayConfigService {
strategy.setThreshold(currentStrategy.getCurrentLimitingThreshold()); strategy.setThreshold(currentStrategy.getCurrentLimitingThreshold());
strategy.setTimeWindow(currentStrategy.getCurrentLimitingTimeWindow()); strategy.setTimeWindow(currentStrategy.getCurrentLimitingTimeWindow());
strategy.setDefaultResponse(currentStrategy.getCurrentLimitingResponse()); strategy.setDefaultResponse(currentStrategy.getCurrentLimitingResponse());
break;
case CIRCUIT_BREAKER: case CIRCUIT_BREAKER:
strategy.setThreshold(currentStrategy.getCircuitBreakerThreshold()); strategy.setThreshold(currentStrategy.getCircuitBreakerThreshold());
strategy.setTimeWindow(currentStrategy.getCircuitBreakerTimeWindow()); strategy.setTimeWindow(currentStrategy.getCircuitBreakerTimeWindow());
strategy.setRecovery_interval(currentStrategy.getCircuitBreakerRecoveryInterval()); strategy.setRecovery_interval(currentStrategy.getCircuitBreakerRecoveryInterval());
strategy.setDefaultResponse(currentStrategy.getCircuitBreakerResponse()); strategy.setDefaultResponse(currentStrategy.getCircuitBreakerResponse());
break;
case AUTHENTICATION: case AUTHENTICATION:
case PERMISSION: case PERMISSION:
default: default: