mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
modify name of ruleType and update example
This commit is contained in:
parent
ef415f87ad
commit
530a36fc06
@ -25,12 +25,12 @@ spring:
|
||||
sentinel:
|
||||
datasource.ds2.file:
|
||||
file: "classpath: gateway.json"
|
||||
ruleType: gateway
|
||||
ruleType: gw-flow
|
||||
datasource.ds1.file:
|
||||
file: "classpath: api.json"
|
||||
ruleType: api
|
||||
ruleType: gw-api-group
|
||||
transport:
|
||||
dashboard: localhost:9999
|
||||
dashboard: localhost:8080
|
||||
filter:
|
||||
enabled: true
|
||||
|
||||
|
@ -7,12 +7,12 @@ spring:
|
||||
sentinel:
|
||||
datasource.ds2.file:
|
||||
file: "classpath: gateway.json"
|
||||
ruleType: gateway
|
||||
ruleType: gw-flow
|
||||
datasource.ds1.file:
|
||||
file: "classpath: api.json"
|
||||
ruleType: api
|
||||
ruleType: gw-api-group
|
||||
transport:
|
||||
dashboard: localhost:9999
|
||||
dashboard: localhost:8080
|
||||
filter:
|
||||
enabled: false
|
||||
|
||||
|
@ -46,11 +46,11 @@ public enum RuleType {
|
||||
/**
|
||||
* gateway flow
|
||||
*/
|
||||
GATEWAY("gateway-flow", GatewayFlowRule.class),
|
||||
GW_FLOW("gw-flow", GatewayFlowRule.class),
|
||||
/**
|
||||
* api
|
||||
*/
|
||||
API("api", ApiDefinition.class);
|
||||
GW_API_GROUP("gw-api-group", ApiDefinition.class);
|
||||
|
||||
/**
|
||||
* alias for {@link AbstractRule}
|
||||
|
@ -23,75 +23,75 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
*/
|
||||
public class AbstractDataSourceProperties {
|
||||
|
||||
@NotEmpty
|
||||
private String dataType = "json";
|
||||
@NotNull
|
||||
private RuleType ruleType;
|
||||
private String converterClass;
|
||||
@JsonIgnore
|
||||
private final String factoryBeanName;
|
||||
@NotEmpty
|
||||
private String dataType = "json";
|
||||
@NotNull
|
||||
private RuleType ruleType;
|
||||
private String converterClass;
|
||||
@JsonIgnore
|
||||
private final String factoryBeanName;
|
||||
|
||||
public AbstractDataSourceProperties(String factoryBeanName) {
|
||||
this.factoryBeanName = factoryBeanName;
|
||||
}
|
||||
public AbstractDataSourceProperties(String factoryBeanName) {
|
||||
this.factoryBeanName = factoryBeanName;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public RuleType getRuleType() {
|
||||
return ruleType;
|
||||
}
|
||||
public RuleType getRuleType() {
|
||||
return ruleType;
|
||||
}
|
||||
|
||||
public void setRuleType(RuleType ruleType) {
|
||||
this.ruleType = ruleType;
|
||||
}
|
||||
public void setRuleType(RuleType ruleType) {
|
||||
this.ruleType = ruleType;
|
||||
}
|
||||
|
||||
public String getConverterClass() {
|
||||
return converterClass;
|
||||
}
|
||||
public String getConverterClass() {
|
||||
return converterClass;
|
||||
}
|
||||
|
||||
public void setConverterClass(String converterClass) {
|
||||
this.converterClass = converterClass;
|
||||
}
|
||||
public void setConverterClass(String converterClass) {
|
||||
this.converterClass = converterClass;
|
||||
}
|
||||
|
||||
public String getFactoryBeanName() {
|
||||
return factoryBeanName;
|
||||
}
|
||||
public String getFactoryBeanName() {
|
||||
return factoryBeanName;
|
||||
}
|
||||
|
||||
public void preCheck(String dataSourceName) {
|
||||
public void preCheck(String dataSourceName) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void postRegister(AbstractDataSource dataSource) {
|
||||
switch (this.getRuleType()) {
|
||||
case FLOW:
|
||||
FlowRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case DEGRADE:
|
||||
DegradeRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case PARAM_FLOW:
|
||||
ParamFlowRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case SYSTEM:
|
||||
SystemRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case AUTHORITY:
|
||||
AuthorityRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case GATEWAY:
|
||||
GatewayRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case API:
|
||||
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void postRegister(AbstractDataSource dataSource) {
|
||||
switch (this.getRuleType()) {
|
||||
case FLOW:
|
||||
FlowRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case DEGRADE:
|
||||
DegradeRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case PARAM_FLOW:
|
||||
ParamFlowRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case SYSTEM:
|
||||
SystemRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case AUTHORITY:
|
||||
AuthorityRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case GW_FLOW:
|
||||
GatewayRuleManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
case GW_API_GROUP:
|
||||
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,21 @@ import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.converter.JsonConverter;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.converter.XmlConverter;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateGroupItem;
|
||||
@ -52,20 +67,6 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.converter.JsonConverter;
|
||||
import org.springframework.cloud.alibaba.sentinel.datasource.converter.XmlConverter;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@ -260,12 +261,12 @@ public class SentinelAutoConfiguration {
|
||||
return new JsonConverter(objectMapper, ParamFlowRule.class);
|
||||
}
|
||||
|
||||
@Bean("sentinel-json-gateway-flow-converter")
|
||||
@Bean("sentinel-json-gw-flow-converter")
|
||||
public JsonConverter jsonGatewayFlowConverter() {
|
||||
return new JsonConverter(objectMapper, GatewayFlowRule.class);
|
||||
}
|
||||
|
||||
@Bean("sentinel-json-api-converter")
|
||||
@Bean("sentinel-json-gw-api-group-converter")
|
||||
public JsonConverter jsonApiConverter() {
|
||||
return new JsonConverter(objectMapper, ApiDefinition.class);
|
||||
}
|
||||
@ -317,12 +318,12 @@ public class SentinelAutoConfiguration {
|
||||
return new XmlConverter(xmlMapper, ParamFlowRule.class);
|
||||
}
|
||||
|
||||
@Bean("sentinel-xml-gateway-flow-converter")
|
||||
@Bean("sentinel-xml-gw-flow-converter")
|
||||
public XmlConverter xmlGatewayFlowConverter() {
|
||||
return new XmlConverter(xmlMapper, GatewayFlowRule.class);
|
||||
}
|
||||
|
||||
@Bean("sentinel-xml-api-converter")
|
||||
@Bean("sentinel-xml-gw-api-group-converter")
|
||||
public XmlConverter xmlApiConverter() {
|
||||
return new XmlConverter(xmlMapper, ApiDefinition.class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user