mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
code format
This commit is contained in:
parent
14d11b7517
commit
1aec607cee
@ -50,7 +50,7 @@ public enum RuleType {
|
|||||||
/**
|
/**
|
||||||
* api
|
* api
|
||||||
*/
|
*/
|
||||||
GW_API_GROUP("gw-api-group", ApiDefinition.class);
|
GW_API_GROUP("gw-api-group", ApiDefinition.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias for {@link AbstractRule}
|
* alias for {@link AbstractRule}
|
||||||
|
@ -4,6 +4,7 @@ import javax.validation.constraints.NotEmpty;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.springframework.cloud.alibaba.sentinel.datasource.RuleType;
|
import org.springframework.cloud.alibaba.sentinel.datasource.RuleType;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
|
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
|
||||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
||||||
@ -15,7 +16,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
|
|||||||
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class Using by {@link DataSourcePropertiesConfiguration}
|
* Abstract class Using by {@link DataSourcePropertiesConfiguration}
|
||||||
@ -24,85 +24,85 @@ import org.springframework.core.env.Environment;
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private Environment env;
|
private Environment env;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Environment getEnv() {
|
protected Environment getEnv() {
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnv(Environment env) {
|
public void setEnv(Environment env) {
|
||||||
this.env = env;
|
this.env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 GW_FLOW:
|
case GW_FLOW:
|
||||||
GatewayRuleManager.register2Property(dataSource.getProperty());
|
GatewayRuleManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
case GW_API_GROUP:
|
case GW_API_GROUP:
|
||||||
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
GatewayApiDefinitionManager.register2Property(dataSource.getProperty());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FactoryBean} for creating {@link ApolloDataSource} instance.
|
* A {@link FactoryBean} for creating {@link ApolloDataSource} instance.
|
||||||
*
|
*
|
||||||
@ -13,51 +13,51 @@ import org.springframework.beans.factory.FactoryBean;
|
|||||||
*/
|
*/
|
||||||
public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource> {
|
public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource> {
|
||||||
|
|
||||||
private String namespaceName;
|
private String namespaceName;
|
||||||
private String flowRulesKey;
|
private String flowRulesKey;
|
||||||
private String defaultFlowRuleValue;
|
private String defaultFlowRuleValue;
|
||||||
private Converter converter;
|
private Converter converter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApolloDataSource getObject() throws Exception {
|
public ApolloDataSource getObject() throws Exception {
|
||||||
return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
|
return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
|
||||||
converter);
|
converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return ApolloDataSource.class;
|
return ApolloDataSource.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNamespaceName() {
|
public String getNamespaceName() {
|
||||||
return namespaceName;
|
return namespaceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNamespaceName(String namespaceName) {
|
public void setNamespaceName(String namespaceName) {
|
||||||
this.namespaceName = namespaceName;
|
this.namespaceName = namespaceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFlowRulesKey() {
|
public String getFlowRulesKey() {
|
||||||
return flowRulesKey;
|
return flowRulesKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlowRulesKey(String flowRulesKey) {
|
public void setFlowRulesKey(String flowRulesKey) {
|
||||||
this.flowRulesKey = flowRulesKey;
|
this.flowRulesKey = flowRulesKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultFlowRuleValue() {
|
public String getDefaultFlowRuleValue() {
|
||||||
return defaultFlowRuleValue;
|
return defaultFlowRuleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultFlowRuleValue(String defaultFlowRuleValue) {
|
public void setDefaultFlowRuleValue(String defaultFlowRuleValue) {
|
||||||
this.defaultFlowRuleValue = defaultFlowRuleValue;
|
this.defaultFlowRuleValue = defaultFlowRuleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Converter getConverter() {
|
public Converter getConverter() {
|
||||||
return converter;
|
return converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConverter(Converter converter) {
|
public void setConverter(Converter converter) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
|
||||||
|
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FactoryBean} for creating {@link FileRefreshableDataSource} instance.
|
* A {@link FactoryBean} for creating {@link FileRefreshableDataSource} instance.
|
||||||
*
|
*
|
||||||
@ -23,7 +23,7 @@ public class FileRefreshableDataSourceFactoryBean
|
|||||||
private int bufSize;
|
private int bufSize;
|
||||||
private Converter converter;
|
private Converter converter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileRefreshableDataSource getObject() throws Exception {
|
public FileRefreshableDataSource getObject() throws Exception {
|
||||||
return new FileRefreshableDataSource(new File(file), converter,
|
return new FileRefreshableDataSource(new File(file), converter,
|
||||||
recommendRefreshMs, bufSize, Charset.forName(charset));
|
recommendRefreshMs, bufSize, Charset.forName(charset));
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
|
||||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FactoryBean} for creating {@link NacosDataSource} instance.
|
* A {@link FactoryBean} for creating {@link NacosDataSource} instance.
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.datasource.Converter;
|
|
||||||
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
|
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FactoryBean} for creating {@link ZookeeperDataSource} instance.
|
* A {@link FactoryBean} for creating {@link ZookeeperDataSource} instance.
|
||||||
*
|
*
|
||||||
@ -14,68 +14,69 @@ import org.springframework.beans.factory.FactoryBean;
|
|||||||
*/
|
*/
|
||||||
public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperDataSource> {
|
public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperDataSource> {
|
||||||
|
|
||||||
private String serverAddr;
|
private String serverAddr;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
private String groupId;
|
private String groupId;
|
||||||
private String dataId;
|
private String dataId;
|
||||||
|
|
||||||
private Converter converter;
|
private Converter converter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZookeeperDataSource getObject() throws Exception {
|
public ZookeeperDataSource getObject() throws Exception {
|
||||||
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
|
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
|
||||||
// the path will be /{groupId}/{dataId}
|
// the path will be /{groupId}/{dataId}
|
||||||
return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
|
return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
|
||||||
} else {
|
}
|
||||||
// using path directly
|
else {
|
||||||
return new ZookeeperDataSource(serverAddr, path, converter);
|
// using path directly
|
||||||
}
|
return new ZookeeperDataSource(serverAddr, path, converter);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return ZookeeperDataSource.class;
|
return ZookeeperDataSource.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerAddr() {
|
public String getServerAddr() {
|
||||||
return serverAddr;
|
return serverAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerAddr(String serverAddr) {
|
public void setServerAddr(String serverAddr) {
|
||||||
this.serverAddr = serverAddr;
|
this.serverAddr = serverAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPath(String path) {
|
public void setPath(String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupId() {
|
public String getGroupId() {
|
||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroupId(String groupId) {
|
public void setGroupId(String groupId) {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDataId() {
|
public String getDataId() {
|
||||||
return dataId;
|
return dataId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDataId(String dataId) {
|
public void setDataId(String dataId) {
|
||||||
this.dataId = dataId;
|
this.dataId = dataId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Converter getConverter() {
|
public Converter getConverter() {
|
||||||
return converter;
|
return converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConverter(Converter converter) {
|
public void setConverter(Converter converter) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,257 +79,256 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|||||||
@EnableConfigurationProperties(SentinelProperties.class)
|
@EnableConfigurationProperties(SentinelProperties.class)
|
||||||
public class SentinelAutoConfiguration {
|
public class SentinelAutoConfiguration {
|
||||||
|
|
||||||
@Value("${project.name:${spring.application.name:}}")
|
@Value("${project.name:${spring.application.name:}}")
|
||||||
private String projectName;
|
private String projectName;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SentinelProperties properties;
|
private SentinelProperties properties;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init() {
|
private void init() {
|
||||||
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
|
||||||
&& StringUtils.hasText(properties.getLog().getDir())) {
|
&& StringUtils.hasText(properties.getLog().getDir())) {
|
||||||
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
|
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
|
||||||
&& properties.getLog().isSwitchPid()) {
|
&& properties.getLog().isSwitchPid()) {
|
||||||
System.setProperty(LogBase.LOG_NAME_USE_PID,
|
System.setProperty(LogBase.LOG_NAME_USE_PID,
|
||||||
String.valueOf(properties.getLog().isSwitchPid()));
|
String.valueOf(properties.getLog().isSwitchPid()));
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
|
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
|
||||||
&& StringUtils.hasText(projectName)) {
|
&& StringUtils.hasText(projectName)) {
|
||||||
System.setProperty(AppNameUtil.APP_NAME, projectName);
|
System.setProperty(AppNameUtil.APP_NAME, projectName);
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
||||||
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
||||||
System.setProperty(TransportConfig.SERVER_PORT,
|
System.setProperty(TransportConfig.SERVER_PORT,
|
||||||
properties.getTransport().getPort());
|
properties.getTransport().getPort());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
|
||||||
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
|
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
|
||||||
System.setProperty(TransportConfig.CONSOLE_SERVER,
|
System.setProperty(TransportConfig.CONSOLE_SERVER,
|
||||||
properties.getTransport().getDashboard());
|
properties.getTransport().getDashboard());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
|
||||||
&& StringUtils
|
&& StringUtils
|
||||||
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
|
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
|
||||||
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
|
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
|
||||||
properties.getTransport().getHeartbeatIntervalMs());
|
properties.getTransport().getHeartbeatIntervalMs());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP))
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP))
|
||||||
&& StringUtils.hasText(properties.getTransport().getClientIp())) {
|
&& StringUtils.hasText(properties.getTransport().getClientIp())) {
|
||||||
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP,
|
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP,
|
||||||
properties.getTransport().getClientIp());
|
properties.getTransport().getClientIp());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
|
||||||
&& StringUtils.hasText(properties.getMetric().getCharset())) {
|
&& StringUtils.hasText(properties.getMetric().getCharset())) {
|
||||||
System.setProperty(SentinelConfig.CHARSET,
|
System.setProperty(SentinelConfig.CHARSET,
|
||||||
properties.getMetric().getCharset());
|
properties.getMetric().getCharset());
|
||||||
}
|
}
|
||||||
if (StringUtils
|
if (StringUtils
|
||||||
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
|
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
|
||||||
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
|
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
|
||||||
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
|
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
|
||||||
properties.getMetric().getFileSingleSize());
|
properties.getMetric().getFileSingleSize());
|
||||||
}
|
}
|
||||||
if (StringUtils
|
if (StringUtils
|
||||||
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
|
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
|
||||||
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
|
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
|
||||||
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
|
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
|
||||||
properties.getMetric().getFileTotalCount());
|
properties.getMetric().getFileTotalCount());
|
||||||
}
|
}
|
||||||
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
|
||||||
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
|
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
|
||||||
System.setProperty(SentinelConfig.COLD_FACTOR,
|
System.setProperty(SentinelConfig.COLD_FACTOR,
|
||||||
properties.getFlow().getColdFactor());
|
properties.getFlow().getColdFactor());
|
||||||
}
|
}
|
||||||
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
|
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
|
||||||
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
|
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// earlier initialize
|
// earlier initialize
|
||||||
if (properties.isEager()) {
|
if (properties.isEager()) {
|
||||||
InitExecutor.doInit();
|
InitExecutor.doInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public SentinelResourceAspect sentinelResourceAspect() {
|
public SentinelResourceAspect sentinelResourceAspect() {
|
||||||
return new SentinelResourceAspect();
|
return new SentinelResourceAspect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
|
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
|
||||||
@ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true", matchIfMissing = true)
|
@ConditionalOnProperty(name = "resttemplate.sentinel.enabled", havingValue = "true", matchIfMissing = true)
|
||||||
public SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
public SentinelBeanPostProcessor sentinelBeanPostProcessor(
|
||||||
ApplicationContext applicationContext) {
|
ApplicationContext applicationContext) {
|
||||||
return new SentinelBeanPostProcessor(applicationContext);
|
return new SentinelBeanPostProcessor(applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SentinelDataSourceHandler sentinelDataSourceHandler(
|
public SentinelDataSourceHandler sentinelDataSourceHandler(
|
||||||
DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties, Environment env) {
|
DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties,
|
||||||
return new SentinelDataSourceHandler(beanFactory, sentinelProperties, env);
|
Environment env) {
|
||||||
}
|
return new SentinelDataSourceHandler(beanFactory, sentinelProperties, env);
|
||||||
|
}
|
||||||
|
|
||||||
@ConditionalOnClass(ObjectMapper.class)
|
@ConditionalOnClass(ObjectMapper.class)
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class SentinelConverterConfiguration {
|
protected static class SentinelConverterConfiguration {
|
||||||
|
|
||||||
static class ApiPredicateItemDeserializer
|
static class ApiPredicateItemDeserializer
|
||||||
extends StdDeserializer<ApiPredicateItem> {
|
extends StdDeserializer<ApiPredicateItem> {
|
||||||
private Map<String, Class<? extends ApiPredicateItem>> registry
|
private Map<String, Class<? extends ApiPredicateItem>> registry = new HashMap<String, Class<? extends ApiPredicateItem>>();
|
||||||
= new HashMap<String, Class<? extends ApiPredicateItem>>();
|
|
||||||
|
|
||||||
ApiPredicateItemDeserializer() {
|
ApiPredicateItemDeserializer() {
|
||||||
super(ApiPredicateItem.class);
|
super(ApiPredicateItem.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerApiPredicateItem(String uniqueAttribute,
|
void registerApiPredicateItem(String uniqueAttribute,
|
||||||
Class<? extends ApiPredicateItem> apiPredicateItemClass) {
|
Class<? extends ApiPredicateItem> apiPredicateItemClass) {
|
||||||
registry.put(uniqueAttribute, apiPredicateItemClass);
|
registry.put(uniqueAttribute, apiPredicateItemClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiPredicateItem deserialize(JsonParser jp,
|
public ApiPredicateItem deserialize(JsonParser jp,
|
||||||
DeserializationContext ctxt)
|
DeserializationContext ctxt) throws IOException {
|
||||||
throws IOException {
|
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
|
||||||
ObjectMapper mapper = (ObjectMapper)jp.getCodec();
|
ObjectNode root = mapper.readTree(jp);
|
||||||
ObjectNode root = mapper.readTree(jp);
|
Class<? extends ApiPredicateItem> apiPredicateItemClass = null;
|
||||||
Class<? extends ApiPredicateItem> apiPredicateItemClass = null;
|
Iterator<Entry<String, JsonNode>> elementsIterator = root.fields();
|
||||||
Iterator<Entry<String, JsonNode>> elementsIterator = root.fields();
|
while (elementsIterator.hasNext()) {
|
||||||
while (elementsIterator.hasNext()) {
|
Entry<String, JsonNode> element = elementsIterator.next();
|
||||||
Entry<String, JsonNode> element = elementsIterator.next();
|
String name = element.getKey();
|
||||||
String name = element.getKey();
|
if (registry.containsKey(name)) {
|
||||||
if (registry.containsKey(name)) {
|
apiPredicateItemClass = registry.get(name);
|
||||||
apiPredicateItemClass = registry.get(name);
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (apiPredicateItemClass == null) {
|
||||||
if (apiPredicateItemClass == null) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
return mapper.readValue(root.toString(), apiPredicateItemClass);
|
||||||
return mapper.readValue(root.toString(), apiPredicateItemClass);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class SentinelJsonConfiguration {
|
protected static class SentinelJsonConfiguration {
|
||||||
|
|
||||||
private ObjectMapper objectMapper = new ObjectMapper();
|
private ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
public SentinelJsonConfiguration() {
|
public SentinelJsonConfiguration() {
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
ApiPredicateItemDeserializer deserializer = new ApiPredicateItemDeserializer();
|
ApiPredicateItemDeserializer deserializer = new ApiPredicateItemDeserializer();
|
||||||
deserializer.registerApiPredicateItem("pattern",
|
deserializer.registerApiPredicateItem("pattern",
|
||||||
ApiPathPredicateItem.class);
|
ApiPathPredicateItem.class);
|
||||||
deserializer.registerApiPredicateItem("items",
|
deserializer.registerApiPredicateItem("items",
|
||||||
ApiPredicateGroupItem.class);
|
ApiPredicateGroupItem.class);
|
||||||
SimpleModule module = new SimpleModule(
|
SimpleModule module = new SimpleModule(
|
||||||
"PolymorphicApiPredicateItemDeserializerModule",
|
"PolymorphicApiPredicateItemDeserializerModule",
|
||||||
new Version(1, 0, 0, null));
|
new Version(1, 0, 0, null));
|
||||||
module.addDeserializer(ApiPredicateItem.class, deserializer);
|
module.addDeserializer(ApiPredicateItem.class, deserializer);
|
||||||
objectMapper.registerModule(module);
|
objectMapper.registerModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-flow-converter")
|
@Bean("sentinel-json-flow-converter")
|
||||||
public JsonConverter jsonFlowConverter() {
|
public JsonConverter jsonFlowConverter() {
|
||||||
return new JsonConverter(objectMapper, FlowRule.class);
|
return new JsonConverter(objectMapper, FlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-degrade-converter")
|
@Bean("sentinel-json-degrade-converter")
|
||||||
public JsonConverter jsonDegradeConverter() {
|
public JsonConverter jsonDegradeConverter() {
|
||||||
return new JsonConverter(objectMapper, DegradeRule.class);
|
return new JsonConverter(objectMapper, DegradeRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-system-converter")
|
@Bean("sentinel-json-system-converter")
|
||||||
public JsonConverter jsonSystemConverter() {
|
public JsonConverter jsonSystemConverter() {
|
||||||
return new JsonConverter(objectMapper, SystemRule.class);
|
return new JsonConverter(objectMapper, SystemRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-authority-converter")
|
@Bean("sentinel-json-authority-converter")
|
||||||
public JsonConverter jsonAuthorityConverter() {
|
public JsonConverter jsonAuthorityConverter() {
|
||||||
return new JsonConverter(objectMapper, AuthorityRule.class);
|
return new JsonConverter(objectMapper, AuthorityRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-param-flow-converter")
|
@Bean("sentinel-json-param-flow-converter")
|
||||||
public JsonConverter jsonParamFlowConverter() {
|
public JsonConverter jsonParamFlowConverter() {
|
||||||
return new JsonConverter(objectMapper, ParamFlowRule.class);
|
return new JsonConverter(objectMapper, ParamFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-json-gw-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-gw-api-group-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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConditionalOnClass(XmlMapper.class)
|
@ConditionalOnClass(XmlMapper.class)
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class SentinelXmlConfiguration {
|
protected static class SentinelXmlConfiguration {
|
||||||
|
|
||||||
private XmlMapper xmlMapper = new XmlMapper();
|
private XmlMapper xmlMapper = new XmlMapper();
|
||||||
|
|
||||||
public SentinelXmlConfiguration() {
|
public SentinelXmlConfiguration() {
|
||||||
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
|
||||||
false);
|
false);
|
||||||
ApiPredicateItemDeserializer deserializer = new ApiPredicateItemDeserializer();
|
ApiPredicateItemDeserializer deserializer = new ApiPredicateItemDeserializer();
|
||||||
deserializer.registerApiPredicateItem("pattern",
|
deserializer.registerApiPredicateItem("pattern",
|
||||||
ApiPathPredicateItem.class);
|
ApiPathPredicateItem.class);
|
||||||
deserializer.registerApiPredicateItem("items",
|
deserializer.registerApiPredicateItem("items",
|
||||||
ApiPredicateGroupItem.class);
|
ApiPredicateGroupItem.class);
|
||||||
SimpleModule module = new SimpleModule(
|
SimpleModule module = new SimpleModule(
|
||||||
"PolymorphicGatewayDeserializerModule",
|
"PolymorphicGatewayDeserializerModule",
|
||||||
new Version(1, 0, 0, null));
|
new Version(1, 0, 0, null));
|
||||||
module.addDeserializer(ApiPredicateItem.class, deserializer);
|
module.addDeserializer(ApiPredicateItem.class, deserializer);
|
||||||
xmlMapper.registerModule(module);
|
xmlMapper.registerModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-flow-converter")
|
@Bean("sentinel-xml-flow-converter")
|
||||||
public XmlConverter xmlFlowConverter() {
|
public XmlConverter xmlFlowConverter() {
|
||||||
return new XmlConverter(xmlMapper, FlowRule.class);
|
return new XmlConverter(xmlMapper, FlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-degrade-converter")
|
@Bean("sentinel-xml-degrade-converter")
|
||||||
public XmlConverter xmlDegradeConverter() {
|
public XmlConverter xmlDegradeConverter() {
|
||||||
return new XmlConverter(xmlMapper, DegradeRule.class);
|
return new XmlConverter(xmlMapper, DegradeRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-system-converter")
|
@Bean("sentinel-xml-system-converter")
|
||||||
public XmlConverter xmlSystemConverter() {
|
public XmlConverter xmlSystemConverter() {
|
||||||
return new XmlConverter(xmlMapper, SystemRule.class);
|
return new XmlConverter(xmlMapper, SystemRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-authority-converter")
|
@Bean("sentinel-xml-authority-converter")
|
||||||
public XmlConverter xmlAuthorityConverter() {
|
public XmlConverter xmlAuthorityConverter() {
|
||||||
return new XmlConverter(xmlMapper, AuthorityRule.class);
|
return new XmlConverter(xmlMapper, AuthorityRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-param-flow-converter")
|
@Bean("sentinel-xml-param-flow-converter")
|
||||||
public XmlConverter xmlParamFlowConverter() {
|
public XmlConverter xmlParamFlowConverter() {
|
||||||
return new XmlConverter(xmlMapper, ParamFlowRule.class);
|
return new XmlConverter(xmlMapper, ParamFlowRule.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("sentinel-xml-gw-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-gw-api-group-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