From 7e2b312fdd6f5d2858832c7d3aaa0a0ef1c3f15c Mon Sep 17 00:00:00 2001 From: fangjian0423 Date: Wed, 19 Dec 2018 23:46:12 +0800 Subject: [PATCH] fix bug about sentinel commercialization for 1.x branch --- .../sentinel/custom/SentinelDataSourceHandler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java index 423b4532..8489c7d8 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java @@ -44,6 +44,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; +import com.alibaba.csp.sentinel.datasource.AbstractDataSource; import com.alibaba.csp.sentinel.datasource.ReadableDataSource; import com.alibaba.csp.sentinel.property.SentinelProperty; import com.alibaba.csp.sentinel.slots.block.AbstractRule; @@ -277,7 +278,18 @@ public class SentinelDataSourceHandler { beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition()); // init in Spring - beanFactory.getBean(dataSourceName); + AbstractDataSource newDataSource = (AbstractDataSource) beanFactory + .getBean(dataSourceName); + // commercialization + if (!StringUtils.isEmpty(System.getProperties() + .getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) { + if (dataSourceName.contains(SentinelConstants.FLOW_DATASOURCE_NAME)) { + FlowRuleManager.register2Property(newDataSource.getProperty()); + } + else if (dataSourceName.contains(SentinelConstants.DEGRADE_DATASOURCE_NAME)) { + DegradeRuleManager.register2Property(newDataSource.getProperty()); + } + } dataSourceBeanNameList.add(dataSourceName); }