Code style

This commit is contained in:
lancer.hong
2021-10-11 00:28:49 +08:00
parent 40e81cb346
commit 192f78d5f9
15 changed files with 57 additions and 143 deletions

View File

@@ -37,8 +37,6 @@ import java.util.Set;
/**
* log4j2初始化时通过该类从Apollo加载相应的log4j2的配置信息
* 当通过Apollo修改log4j2配置后能立即生效。例如动态修改日志级别。
* @author honam
* @date 2019-08-05
*/
// @Plugin(name = "ApolloLog4j2ConfigurationFactory", category = ConfigurationFactory.CATEGORY)
// @Order(50)

View File

@@ -1,44 +0,0 @@
// /*
// * Copyright (C) 2020 the original author or authors.
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
// */
//
// package we.config;
//
// import org.springframework.boot.context.properties.ConfigurationProperties;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.web.reactive.function.client.WebClient;
// import reactor.netty.resources.LoopResources;
// import we.util.JacksonUtils;
//
// /**
// * @author hongqiaowei
// */
//
// @Configuration
// @ConfigurationProperties(prefix = AggrWebClientConfig.prefix)
// public class AggrWebClientConfig extends WebClientConfig {
//
// protected static final String prefix = "aggr-webclient";
//
// public static final String aggrWebClient = "aggrWebClient";
//
// @Bean(aggrWebClient)
// public WebClient webClient() {
// log.info(aggrWebClient + ": " + this);
// return super.webClient();
// }
// }

View File

@@ -42,15 +42,17 @@ import javax.annotation.Resource;
*
* @author zhongjie
*/
@Configuration
public class AggregateRedisConfig extends RedisReactiveConfig {
static final String AGGREGATE_REACTIVE_REDIS_PROPERTIES = "aggregateReactiveRedisProperties";
private static final String AGGREGATE_REACTIVE_REDIS_CONNECTION_FACTORY = "aggregateReactiveRedisConnectionFactory";
public static final String AGGREGATE_REACTIVE_REDIS_TEMPLATE = "aggregateReactiveRedisTemplate";
public static final String AGGREGATE_REACTIVE_REDIS_MESSAGE_LISTENER_CONTAINER = "aggregateReactiveRedisMessageListenerContainer";
private static final String SEND_LOG_TYPE_REDIS = "redis";
public static ProxyLettuceConnectionFactory proxyLettuceConnectionFactory;
static final String AGGREGATE_REACTIVE_REDIS_PROPERTIES = "aggregateReactiveRedisProperties";
private static final String AGGREGATE_REACTIVE_REDIS_CONNECTION_FACTORY = "aggregateReactiveRedisConnectionFactory";
public static final String AGGREGATE_REACTIVE_REDIS_TEMPLATE = "aggregateReactiveRedisTemplate";
public static final String AGGREGATE_REACTIVE_REDIS_MESSAGE_LISTENER_CONTAINER = "aggregateReactiveRedisMessageListenerContainer";
private static final String SEND_LOG_TYPE_REDIS = "redis";
public static ProxyLettuceConnectionFactory proxyLettuceConnectionFactory;
@Resource
private AggregateRedisConfigProperties aggregateRedisConfigProperties;

View File

@@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package we.config;
import lombok.Data;
@@ -26,6 +27,7 @@ import org.springframework.stereotype.Component;
*
* @author zhongjie
*/
@RefreshScope
@Component
@Data

View File

@@ -22,9 +22,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
/**
* @author unknown
*/
@RefreshScope
@Component
@Data

View File

@@ -110,25 +110,6 @@ public class FlowStatSchedConfig extends SchedConfig {
return;
}
// resourceTimeWindow2totalBlockRequestsMap.clear();
// resourceTimeWindowStats.forEach(rtws -> {
// String resource = rtws.getResourceId();
// List<TimeWindowStat> wins = rtws.getWindows();
// wins.forEach(w -> {
// long t = w.getStartTime();
// long blockRequests = w.getBlockRequests();
// resourceTimeWindow2totalBlockRequestsMap.put(resource + t, new AtomicLong(blockRequests));
// });
// });
// resourceTimeWindowStats.forEach(rtws -> {
// String resource = rtws.getResourceId();
// List<TimeWindowStat> wins = rtws.getWindows();
// wins.forEach(w -> {
// accumulateParents(resource, w.getStartTime(), w.getBlockRequests());
// });
// });
resourceTimeWindowStats.forEach(
rtws -> {
String resource = rtws.getResourceId();
@@ -194,8 +175,6 @@ public class FlowStatSchedConfig extends SchedConfig {
pRps = peakRps.doubleValue();
}
// AtomicLong totalBlockRequests = resourceTimeWindow2totalBlockRequestsMap.get(resource + timeWin);
// long tbrs = (totalBlockRequests == null ? w.getBlockRequests() : w.getBlockRequests() + totalBlockRequests.longValue());
long tbrs = w.getTotalBlockRequests();
b.append(Consts.S.LEFT_BRACE);
@@ -263,18 +242,6 @@ public class FlowStatSchedConfig extends SchedConfig {
}
}
// private void accumulateParents(String resource, long timeWin, long blockRequests) {
// List<String> prl = ThreadContext.getArrayList(parentResourceList, String.class);
// resourceRateLimitConfigService.getParentsTo(resource, prl);
// for (int i = 0; i < prl.size(); i++) {
// String parentResource = prl.get(i);
// AtomicLong parentTotalBlockRequests = resourceTimeWindow2totalBlockRequestsMap.get(parentResource + timeWin);
// if (parentTotalBlockRequests != null) {
// parentTotalBlockRequests.addAndGet(blockRequests);
// }
// }
// }
private long getRecentEndTimeSlot(FlowStat flowStat) {
long currentTimeSlot = flowStat.currentTimeSlotId();
int second = DateTimeUtils.transform(currentTimeSlot).getSecond();

View File

@@ -57,7 +57,7 @@ public abstract class ManualApiConfig {
apiConfigService.serviceConfigMap.put(ac.service, sc);
}
sc.add(ac);
log.info("manual add " + ac);
log.info("manual add {}", ac);
}
}
}

View File

@@ -36,7 +36,7 @@ public class ProxyWebClientConfig extends WebClientConfig {
@Bean(proxyWebClient)
public WebClient webClient() {
log.info(proxyWebClient + ": " + this);
log.info("proxy web client: {}", this);
return super.webClient();
}
}

View File

@@ -33,7 +33,7 @@ import we.util.JacksonUtils;
import javax.annotation.Resource;
/**
* @author unknown
* @author hongqiaowei
*/
@RestController
@@ -41,22 +41,22 @@ import javax.annotation.Resource;
public class CacheCheckController {
@Resource
private GatewayGroupService gatewayGroupService;
private GatewayGroupService gatewayGroupService;
@Resource
private AppService appService;
private AppService appService;
@Resource
private ApiConfigService apiConfigService;
private ApiConfigService apiConfigService;
@Resource
private ResourceRateLimitConfigService resourceRateLimitConfigService;
@Resource
private ApiConifg2appsService apiConifg2appsService;
private ApiConifg2appsService apiConifg2appsService;
@Resource
private DictService dictService;
private DictService dictService;
@GetMapping("/gatewayGroups")
public Mono<String> gatewayGroups(ServerWebExchange exchange) {

View File

@@ -44,6 +44,7 @@ import java.util.Map;
/**
* @author hongqiaowei
*/
@RefreshScope
@RestController
@RequestMapping("/admin/flowStat")
@@ -54,7 +55,6 @@ public class FlowControlController {
@Value("${flowControl:false}")
private boolean flowControl;
// @Resource
@Autowired(required = false)
private FlowStat flowStat;

View File

@@ -48,11 +48,7 @@ public class CorsFilterConfig {
CorsConfiguration config = new CorsConfiguration();
// Possibly...
// config.applyPermitDefaultValues()
config.setAllowCredentials(true);
// config.addAllowedOrigin("https://domain0.com");
config.addAllowedOrigin("*");
// config.addAllowedMethod("*");

View File

@@ -38,7 +38,7 @@ import we.util.WebUtils;
@Order(0)
public class FizzLogFilter implements WebFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(FizzLogFilter.class);
private static final Logger log = LoggerFactory.getLogger(FizzLogFilter.class);
private static final String resp = "\nresponse ";
@@ -47,15 +47,15 @@ public class FizzLogFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
long startTime = System.currentTimeMillis();
long start = System.currentTimeMillis();
return chain.filter(exchange).doFinally(
(c) -> {
if (LOGGER.isInfoEnabled()) {
if (log.isInfoEnabled()) {
StringBuilder b = ThreadContext.getStringBuilder();
WebUtils.request2stringBuilder(exchange, b);
b.append(resp).append(exchange.getResponse().getStatusCode())
.append(in) .append(System.currentTimeMillis() - startTime);
LOGGER.info(b.toString(), LogService.BIZ_ID, WebUtils.getTraceId(exchange));
.append(in) .append(System.currentTimeMillis() - start);
log.info(b.toString(), LogService.BIZ_ID, WebUtils.getTraceId(exchange));
}
}
);

View File

@@ -71,45 +71,44 @@ public class PreprocessFilter extends FizzWebFilter {
Map<String, FilterResult> fc = new HashMap<>(); fc.put(WebUtils.PREV_FILTER_RESULT, succFr);
Map<String, String> appendHdrs = new HashMap<>(8);
Map<String, Object> eas = exchange.getAttributes(); eas.put(WebUtils.FILTER_CONTEXT, fc);
eas.put(WebUtils.APPEND_HEADERS, appendHdrs);
eas.put(WebUtils.APPEND_HEADERS, appendHdrs);
Mono vm = statPluginFilter.filter(exchange, null, null);
return process(exchange, chain, eas, vm);
}
// TODO: improve
private Mono<Void> process(ServerWebExchange exchange, WebFilterChain chain, Map<String, Object> eas, Mono vm) {
return chain(exchange, vm, authPluginFilter).defaultIfEmpty(ReactorUtils.NULL)
.flatMap(
v -> {
Result<ApiConfig> authRes = (Result<ApiConfig>) WebUtils.getFilterResultDataItem(exchange, AuthPluginFilter.AUTH_PLUGIN_FILTER, AuthPluginFilter.RESULT);
if (authRes.code == Result.FAIL) {
return WebUtils.responseError(exchange, HttpStatus.FORBIDDEN.value(), authRes.msg);
}
Mono m = ReactorUtils.getInitiateMono();
ApiConfig ac = authRes.data;
if (ac == null) {
afterAuth(exchange, null, null);
m = executeFixedPluginFilters(exchange);
return m.defaultIfEmpty(ReactorUtils.NULL).flatMap(func(exchange, chain));
}
Route route = ac.getRoute(exchange);
eas.put(WebUtils.ROUTE, route);
afterAuth(exchange, ac, route);
m = executeFixedPluginFilters(exchange);
m = m.defaultIfEmpty(ReactorUtils.NULL);
if (CollectionUtils.isEmpty(route.pluginConfigs)) {
return m.flatMap(func(exchange, chain));
} else {
return m.flatMap(
nil -> {
eas.put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
return FizzPluginFilterChain.next(exchange);
}
);
}
}
);
.flatMap(
v -> {
Result<ApiConfig> authRes = (Result<ApiConfig>) WebUtils.getFilterResultDataItem(exchange, AuthPluginFilter.AUTH_PLUGIN_FILTER, AuthPluginFilter.RESULT);
if (authRes.code == Result.FAIL) {
return WebUtils.responseError(exchange, HttpStatus.FORBIDDEN.value(), authRes.msg);
}
Mono m = ReactorUtils.getInitiateMono();
ApiConfig ac = authRes.data;
if (ac == null) {
afterAuth(exchange, null, null);
m = executeFixedPluginFilters(exchange);
return m.defaultIfEmpty(ReactorUtils.NULL).flatMap(func(exchange, chain));
}
Route route = ac.getRoute(exchange);
eas.put(WebUtils.ROUTE, route);
afterAuth(exchange, ac, route);
m = executeFixedPluginFilters(exchange);
m = m.defaultIfEmpty(ReactorUtils.NULL);
if (CollectionUtils.isEmpty(route.pluginConfigs)) {
return m.flatMap(func(exchange, chain));
} else {
return m.flatMap(
nil -> {
eas.put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
return FizzPluginFilterChain.next(exchange);
}
);
}
}
);
}
private void afterAuth(ServerWebExchange exchange, ApiConfig ac, Route route) {

View File

@@ -102,10 +102,7 @@ public class RouteFilter extends FizzWebFilter {
ServerHttpRequest req = exchange.getRequest();
String traceId = WebUtils.getTraceId(exchange);
// ApiConfig ac = WebUtils.getApiConfig(exchange);
Route route = WebUtils.getRoute(exchange);
HttpHeaders hdrs = null;
if (route.type != ApiConfig.Type.DUBBO) {

View File

@@ -34,9 +34,9 @@ import java.util.Map;
public final class FizzPluginFilterChain {
private static final String pluginConfigsIt = "@pcsit";
private static final String pluginConfigsIt = "pcsit@";
public static final String WEB_FILTER_CHAIN = "@wfc";
public static final String WEB_FILTER_CHAIN = "wfc@";
private FizzPluginFilterChain() {
}