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:
|
sentinel:
|
||||||
datasource.ds2.file:
|
datasource.ds2.file:
|
||||||
file: "classpath: gateway.json"
|
file: "classpath: gateway.json"
|
||||||
ruleType: gateway
|
ruleType: gw-flow
|
||||||
datasource.ds1.file:
|
datasource.ds1.file:
|
||||||
file: "classpath: api.json"
|
file: "classpath: api.json"
|
||||||
ruleType: api
|
ruleType: gw-api-group
|
||||||
transport:
|
transport:
|
||||||
dashboard: localhost:9999
|
dashboard: localhost:8080
|
||||||
filter:
|
filter:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ spring:
|
|||||||
sentinel:
|
sentinel:
|
||||||
datasource.ds2.file:
|
datasource.ds2.file:
|
||||||
file: "classpath: gateway.json"
|
file: "classpath: gateway.json"
|
||||||
ruleType: gateway
|
ruleType: gw-flow
|
||||||
datasource.ds1.file:
|
datasource.ds1.file:
|
||||||
file: "classpath: api.json"
|
file: "classpath: api.json"
|
||||||
ruleType: api
|
ruleType: gw-api-group
|
||||||
transport:
|
transport:
|
||||||
dashboard: localhost:9999
|
dashboard: localhost:8080
|
||||||
filter:
|
filter:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
|
@ -46,11 +46,11 @@ public enum RuleType {
|
|||||||
/**
|
/**
|
||||||
* gateway flow
|
* gateway flow
|
||||||
*/
|
*/
|
||||||
GATEWAY("gateway-flow", GatewayFlowRule.class),
|
GW_FLOW("gw-flow", GatewayFlowRule.class),
|
||||||
/**
|
/**
|
||||||
* api
|
* api
|
||||||
*/
|
*/
|
||||||
API("api", ApiDefinition.class);
|
GW_API_GROUP("gw-api-group", ApiDefinition.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias for {@link AbstractRule}
|
* alias for {@link AbstractRule}
|
||||||
|
@ -23,75 +23,75 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
*/
|
*/
|
||||||
public class AbstractDataSourceProperties {
|
public class AbstractDataSourceProperties {
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String dataType = "json";
|
private String dataType = "json";
|
||||||
@NotNull
|
@NotNull
|
||||||
private RuleType ruleType;
|
private RuleType ruleType;
|
||||||
private String converterClass;
|
private String converterClass;
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private final String factoryBeanName;
|
private final String factoryBeanName;
|
||||||
|
|
||||||
public AbstractDataSourceProperties(String factoryBeanName) {
|
public AbstractDataSourceProperties(String factoryBeanName) {
|
||||||
this.factoryBeanName = factoryBeanName;
|
this.factoryBeanName = factoryBeanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDataType() {
|
public String getDataType() {
|
||||||
return dataType;
|
return dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataType(String dataType) {
|
public void setDataType(String dataType) {
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuleType getRuleType() {
|
public RuleType getRuleType() {
|
||||||
return ruleType;
|
return ruleType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRuleType(RuleType ruleType) {
|
public void setRuleType(RuleType ruleType) {
|
||||||
this.ruleType = ruleType;
|
this.ruleType = ruleType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConverterClass() {
|
public String getConverterClass() {
|
||||||
return converterClass;
|
return converterClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConverterClass(String converterClass) {
|
public void setConverterClass(String converterClass) {
|
||||||
this.converterClass = converterClass;
|
this.converterClass = converterClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFactoryBeanName() {
|
public String getFactoryBeanName() {
|
||||||
return factoryBeanName;
|
return factoryBeanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preCheck(String dataSourceName) {
|
public void preCheck(String dataSourceName) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postRegister(AbstractDataSource dataSource) {
|
public void postRegister(AbstractDataSource dataSource) {
|
||||||
switch (this.getRuleType()) {
|
switch (this.getRuleType()) {
|
||||||
case FLOW:
|
case FLOW:
|
||||||
FlowRuleManager.register2Property(dataSource.getProperty());
|
FlowRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case DEGRADE:
|
case DEGRADE:
|
||||||
DegradeRuleManager.register2Property(dataSource.getProperty());
|
DegradeRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case PARAM_FLOW:
|
case PARAM_FLOW:
|
||||||
ParamFlowRuleManager.register2Property(dataSource.getProperty());
|
ParamFlowRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case SYSTEM:
|
case SYSTEM:
|
||||||
SystemRuleManager.register2Property(dataSource.getProperty());
|
SystemRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case AUTHORITY:
|
case AUTHORITY:
|
||||||
AuthorityRuleManager.register2Property(dataSource.getProperty());
|
AuthorityRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case GATEWAY:
|
case GW_FLOW:
|
||||||
GatewayRuleManager.register2Property(dataSource.getProperty());
|
GatewayRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case API:
|
case GW_API_GROUP:
|
||||||
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,21 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
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.ApiDefinition;
|
||||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem;
|
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem;
|
||||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateGroupItem;
|
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.module.SimpleModule;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
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
|
* @author xiaojing
|
||||||
@ -260,12 +261,12 @@ public class SentinelAutoConfiguration {
|
|||||||
return new JsonConverter(objectMapper, ParamFlowRule.class);
|
return new JsonConverter(objectMapper, ParamFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-gateway-flow-converter")
|
@Bean("sentinel-json-gw-flow-converter")
|
||||||
public JsonConverter jsonGatewayFlowConverter() {
|
public JsonConverter jsonGatewayFlowConverter() {
|
||||||
return new JsonConverter(objectMapper, GatewayFlowRule.class);
|
return new JsonConverter(objectMapper, GatewayFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-api-converter")
|
@Bean("sentinel-json-gw-api-group-converter")
|
||||||
public JsonConverter jsonApiConverter() {
|
public JsonConverter jsonApiConverter() {
|
||||||
return new JsonConverter(objectMapper, ApiDefinition.class);
|
return new JsonConverter(objectMapper, ApiDefinition.class);
|
||||||
}
|
}
|
||||||
@ -317,12 +318,12 @@ public class SentinelAutoConfiguration {
|
|||||||
return new XmlConverter(xmlMapper, ParamFlowRule.class);
|
return new XmlConverter(xmlMapper, ParamFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-gateway-flow-converter")
|
@Bean("sentinel-xml-gw-flow-converter")
|
||||||
public XmlConverter xmlGatewayFlowConverter() {
|
public XmlConverter xmlGatewayFlowConverter() {
|
||||||
return new XmlConverter(xmlMapper, GatewayFlowRule.class);
|
return new XmlConverter(xmlMapper, GatewayFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-api-converter")
|
@Bean("sentinel-xml-gw-api-group-converter")
|
||||||
public XmlConverter xmlApiConverter() {
|
public XmlConverter xmlApiConverter() {
|
||||||
return new XmlConverter(xmlMapper, ApiDefinition.class);
|
return new XmlConverter(xmlMapper, ApiDefinition.class);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user