mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
sentinel add logs to query datasource process.
This commit is contained in:
parent
8190b0f4a1
commit
d924184fec
@ -195,30 +195,44 @@ public class SentinelDataSourcePostProcessor
|
|||||||
|
|
||||||
@EventListener(classes = ApplicationReadyEvent.class)
|
@EventListener(classes = ApplicationReadyEvent.class)
|
||||||
public void appStartedListener(ApplicationReadyEvent event) throws Exception {
|
public void appStartedListener(ApplicationReadyEvent event) throws Exception {
|
||||||
|
logger.info("[Sentinel Starter] Start to find ReadableDataSource");
|
||||||
Map<String, ReadableDataSource> dataSourceMap = event.getApplicationContext().getBeansOfType(
|
Map<String, ReadableDataSource> dataSourceMap = event.getApplicationContext().getBeansOfType(
|
||||||
ReadableDataSource.class);
|
ReadableDataSource.class);
|
||||||
if (dataSourceMap.size() == 1) {
|
if (dataSourceMap.size() == 1) {
|
||||||
|
logger.info("[Sentinel Starter] There exists only one ReadableDataSource named {}, start to load rules",
|
||||||
|
dataSourceMap.keySet().iterator().next());
|
||||||
ReadableDataSource dataSource = dataSourceMap.values().iterator().next();
|
ReadableDataSource dataSource = dataSourceMap.values().iterator().next();
|
||||||
Object ruleConfig = dataSource.loadConfig();
|
Object ruleConfig = dataSource.loadConfig();
|
||||||
SentinelProperty sentinelProperty = dataSource.getProperty();
|
SentinelProperty sentinelProperty = dataSource.getProperty();
|
||||||
if (checkRuleType(ruleConfig, FlowRule.class)) {
|
Integer rulesNum;
|
||||||
|
if ((rulesNum = checkRuleType(ruleConfig, FlowRule.class)) > 0) {
|
||||||
FlowRuleManager.register2Property(sentinelProperty);
|
FlowRuleManager.register2Property(sentinelProperty);
|
||||||
|
logger.info("[Sentinel Starter] load {} flow rules", rulesNum);
|
||||||
}
|
}
|
||||||
if (checkRuleType(ruleConfig, DegradeRule.class)) {
|
if ((rulesNum = checkRuleType(ruleConfig, DegradeRule.class)) > 0) {
|
||||||
DegradeRuleManager.register2Property(sentinelProperty);
|
DegradeRuleManager.register2Property(sentinelProperty);
|
||||||
|
logger.info("[Sentinel Starter] load {} degrade rules", rulesNum);
|
||||||
}
|
}
|
||||||
if (checkRuleType(ruleConfig, SystemRule.class)) {
|
if ((rulesNum = checkRuleType(ruleConfig, SystemRule.class)) > 0) {
|
||||||
SystemRuleManager.register2Property(sentinelProperty);
|
SystemRuleManager.register2Property(sentinelProperty);
|
||||||
|
logger.info("[Sentinel Starter] load {} system rules", rulesNum);
|
||||||
}
|
}
|
||||||
if (checkRuleType(ruleConfig, AuthorityRule.class)) {
|
if ((rulesNum = checkRuleType(ruleConfig, AuthorityRule.class)) > 0) {
|
||||||
AuthorityRuleManager.register2Property(sentinelProperty);
|
AuthorityRuleManager.register2Property(sentinelProperty);
|
||||||
|
logger.info("[Sentinel Starter] load {} authority rules", rulesNum);
|
||||||
}
|
}
|
||||||
|
} else if (dataSourceMap.size() > 1) {
|
||||||
|
logger.warn(
|
||||||
|
"[Sentinel Starter] There exists more than one ReadableDataSource, can not choose which one to load");
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
"[Sentinel Starter] No ReadableDataSource exists");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkRuleType(Object ruleConfig, Class type) {
|
private Integer checkRuleType(Object ruleConfig, Class type) {
|
||||||
if (ruleConfig.getClass() == type) {
|
if (ruleConfig.getClass() == type) {
|
||||||
return true;
|
return 1;
|
||||||
} else if (ruleConfig instanceof List) {
|
} else if (ruleConfig instanceof List) {
|
||||||
List ruleList = (List)ruleConfig;
|
List ruleList = (List)ruleConfig;
|
||||||
List checkList = new ArrayList();
|
List checkList = new ArrayList();
|
||||||
@ -228,10 +242,10 @@ public class SentinelDataSourcePostProcessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ruleList.size() == checkList.size()) {
|
if (ruleList.size() == checkList.size()) {
|
||||||
return true;
|
return ruleList.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SentinelDataSourceField {
|
class SentinelDataSourceField {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user