1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

polish #761 update pkg name & maven coordinate for Greenwich

This commit is contained in:
fangjian0423
2019-07-23 11:03:04 +08:00
parent 3998ea23f7
commit 883c66f251
599 changed files with 4993 additions and 4526 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel;
package com.alibaba.cloud.sentinel;
/**
* @author fangjian

View File

@@ -14,17 +14,17 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel;
package com.alibaba.cloud.sentinel;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.config.DataSourcePropertiesConfiguration;
import org.springframework.core.Ordered;
import org.springframework.validation.annotation.Validated;
import com.alibaba.cloud.sentinel.datasource.config.DataSourcePropertiesConfiguration;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.LogBase;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel;
package com.alibaba.cloud.sentinel;
import java.util.ArrayList;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel;
package com.alibaba.cloud.sentinel;
import java.util.Collections;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.annotation;
package com.alibaba.cloud.sentinel.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import java.lang.reflect.Method;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import javax.annotation.PostConstruct;
@@ -25,15 +25,15 @@ 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.core.env.Environment;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.config.SentinelConfig;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -28,8 +28,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.cloud.alibaba.sentinel.SentinelConstants;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.core.type.StandardMethodMetadata;
import org.springframework.core.type.classreading.MethodMetadataReadingVisitor;
@@ -40,6 +38,8 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import com.alibaba.cloud.sentinel.SentinelConstants;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.slots.block.BlockException;
/**

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import org.springframework.context.annotation.Configuration;

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import java.lang.reflect.Field;
import java.util.Arrays;
@@ -12,14 +12,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.config.AbstractDataSourceProperties;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.JsonConverter;
import org.springframework.cloud.alibaba.sentinel.datasource.converter.XmlConverter;
import org.springframework.core.env.Environment;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.cloud.sentinel.datasource.config.AbstractDataSourceProperties;
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;

View File

@@ -14,21 +14,21 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.custom;
package com.alibaba.cloud.sentinel.custom;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
import org.springframework.cloud.alibaba.sentinel.rest.SentinelClientHttpResponse;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.RestTemplate;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.SphU;

View File

@@ -14,15 +14,15 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.endpoint;
package com.alibaba.cloud.sentinel.endpoint;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.LogBase;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.endpoint;
package com.alibaba.cloud.sentinel.endpoint;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
@@ -23,9 +23,10 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import org.springframework.context.annotation.Bean;
import com.alibaba.cloud.sentinel.SentinelProperties;
/**
* @author hengyunabc
*/
@@ -43,7 +44,9 @@ public class SentinelEndpointAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledHealthIndicator("sentinel")
public SentinelHealthIndicator sentinelHealthIndicator(DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties) {
public SentinelHealthIndicator sentinelHealthIndicator(
DefaultListableBeanFactory beanFactory,
SentinelProperties sentinelProperties) {
return new SentinelHealthIndicator(beanFactory, sentinelProperties);
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.sentinel.endpoint;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.util.StringUtils;
import com.alibaba.cloud.sentinel.SentinelProperties;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
/**
* A {@link HealthIndicator} for Sentinel, which checks the status of Sentinel Dashboard
* and DataSource.
*
* <p>
* Check the status of Sentinel Dashboard by sending a heartbeat message to it. If return
* true, it's OK.
*
* Check the status of Sentinel DataSource by calling loadConfig method of
* {@link AbstractDataSource}. If no Exception thrown, it's OK.
*
* If Dashboard and DataSource are both OK, the health status is UP.
* </p>
*
* <p>
* Note: If Sentinel isn't enabled, the health status is up. If Sentinel Dashboard isn't
* configured, it's OK and mark the status of Dashboard with UNKNOWN. More informations
* are provided in details.
* </p>
*
* @author cdfive
*/
public class SentinelHealthIndicator extends AbstractHealthIndicator {
private DefaultListableBeanFactory beanFactory;
private SentinelProperties sentinelProperties;
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory,
SentinelProperties sentinelProperties) {
this.beanFactory = beanFactory;
this.sentinelProperties = sentinelProperties;
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Map<String, Object> detailMap = new HashMap<>();
// If sentinel isn't enabled, set the status up and set the enabled to false in
// detail
if (!sentinelProperties.isEnabled()) {
detailMap.put("enabled", false);
builder.up().withDetails(detailMap);
return;
}
detailMap.put("enabled", true);
// Check health of Dashboard
boolean dashboardUp = true;
String consoleServer = TransportConfig.getConsoleServer();
if (StringUtils.isEmpty(consoleServer)) {
// If Dashboard isn't configured, it's OK and mark the status of Dashboard
// with UNKNOWN.
detailMap.put("dashboard",
new Status(Status.UNKNOWN.getCode(), "dashboard isn't configured"));
}
else {
// If Dashboard is configured, send a heartbeat message to it and check the
// result
HeartbeatSender heartbeatSender = HeartbeatSenderProvider
.getHeartbeatSender();
boolean result = heartbeatSender.sendHeartbeat();
if (result) {
detailMap.put("dashboard", Status.UP);
}
else {
// If failed to send heartbeat message, means that the Dashboard is DOWN
dashboardUp = false;
detailMap.put("dashboard", new Status(Status.DOWN.getCode(),
consoleServer + " can't be connected"));
}
}
// Check health of DataSource
boolean dataSourceUp = true;
Map<String, Object> dataSourceDetailMap = new HashMap<>();
detailMap.put("dataSource", dataSourceDetailMap);
// Get all DataSources and each call loadConfig to check if it's OK
// If no Exception thrown, it's OK
// Note:
// Even if the dynamic config center is down, the loadConfig() might return
// successfully
// e.g. for Nacos client, it might retrieve from the local cache)
// But in most circumstances it's okay
Map<String, AbstractDataSource> dataSourceMap = beanFactory
.getBeansOfType(AbstractDataSource.class);
for (Map.Entry<String, AbstractDataSource> dataSourceMapEntry : dataSourceMap
.entrySet()) {
String dataSourceBeanName = dataSourceMapEntry.getKey();
AbstractDataSource dataSource = dataSourceMapEntry.getValue();
try {
dataSource.loadConfig();
dataSourceDetailMap.put(dataSourceBeanName, Status.UP);
}
catch (Exception e) {
// If one DataSource failed to loadConfig, means that the DataSource is
// DOWN
dataSourceUp = false;
dataSourceDetailMap.put(dataSourceBeanName,
new Status(Status.DOWN.getCode(), e.getMessage()));
}
}
// If Dashboard and DataSource are both OK, the health status is UP
if (dashboardUp && dataSourceUp) {
builder.up().withDetails(detailMap);
}
else {
builder.down().withDetails(detailMap);
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.feign;
package com.alibaba.cloud.sentinel.feign;
import java.util.HashMap;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.feign;
package com.alibaba.cloud.sentinel.feign;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.feign;
package com.alibaba.cloud.sentinel.feign;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.feign;
package com.alibaba.cloud.sentinel.feign;
import static feign.Util.checkNotNull;

View File

@@ -14,14 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.rest;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
import org.springframework.cloud.alibaba.sentinel.custom.SentinelProtectInterceptor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.AbstractClientHttpResponse;
package com.alibaba.cloud.sentinel.rest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -31,6 +24,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.AbstractClientHttpResponse;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.cloud.sentinel.custom.SentinelProtectInterceptor;
/**
* Using by {@link SentinelRestTemplate} and {@link SentinelProtectInterceptor}
*

View File

@@ -1,132 +0,0 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.alibaba.sentinel.endpoint;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider;
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.cloud.alibaba.sentinel.SentinelProperties;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
/**
* A {@link HealthIndicator} for Sentinel, which checks the status of
* Sentinel Dashboard and DataSource.
*
* <p>
* Check the status of Sentinel Dashboard by sending a heartbeat message to it.
* If return true, it's OK.
*
* Check the status of Sentinel DataSource by calling loadConfig method of {@link AbstractDataSource}.
* If no Exception thrown, it's OK.
*
* If Dashboard and DataSource are both OK, the health status is UP.
*</p>
*
* <p>
* Note:
* If Sentinel isn't enabled, the health status is up.
* If Sentinel Dashboard isn't configured, it's OK and mark the status of Dashboard with UNKNOWN.
* More informations are provided in details.
* </p>
*
* @author cdfive
*/
public class SentinelHealthIndicator extends AbstractHealthIndicator {
private DefaultListableBeanFactory beanFactory;
private SentinelProperties sentinelProperties;
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory, SentinelProperties sentinelProperties) {
this.beanFactory = beanFactory;
this.sentinelProperties = sentinelProperties;
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Map<String, Object> detailMap = new HashMap<>();
// If sentinel isn't enabled, set the status up and set the enabled to false in detail
if (!sentinelProperties.isEnabled()) {
detailMap.put("enabled", false);
builder.up().withDetails(detailMap);
return;
}
detailMap.put("enabled", true);
// Check health of Dashboard
boolean dashboardUp = true;
String consoleServer = TransportConfig.getConsoleServer();
if (StringUtils.isEmpty(consoleServer)) {
// If Dashboard isn't configured, it's OK and mark the status of Dashboard with UNKNOWN.
detailMap.put("dashboard", new Status(Status.UNKNOWN.getCode(), "dashboard isn't configured"));
} else {
// If Dashboard is configured, send a heartbeat message to it and check the result
HeartbeatSender heartbeatSender = HeartbeatSenderProvider.getHeartbeatSender();
boolean result = heartbeatSender.sendHeartbeat();
if (result) {
detailMap.put("dashboard", Status.UP);
} else {
// If failed to send heartbeat message, means that the Dashboard is DOWN
dashboardUp = false;
detailMap.put("dashboard", new Status(Status.DOWN.getCode(), consoleServer + " can't be connected"));
}
}
// Check health of DataSource
boolean dataSourceUp = true;
Map<String, Object> dataSourceDetailMap = new HashMap<>();
detailMap.put("dataSource", dataSourceDetailMap);
// Get all DataSources and each call loadConfig to check if it's OK
// If no Exception thrown, it's OK
// Note:
// Even if the dynamic config center is down, the loadConfig() might return successfully
// e.g. for Nacos client, it might retrieve from the local cache)
// But in most circumstances it's okay
Map<String, AbstractDataSource> dataSourceMap = beanFactory.getBeansOfType(AbstractDataSource.class);
for (Map.Entry<String, AbstractDataSource> dataSourceMapEntry : dataSourceMap.entrySet()) {
String dataSourceBeanName = dataSourceMapEntry.getKey();
AbstractDataSource dataSource = dataSourceMapEntry.getValue();
try {
dataSource.loadConfig();
dataSourceDetailMap.put(dataSourceBeanName, Status.UP);
} catch (Exception e) {
// If one DataSource failed to loadConfig, means that the DataSource is DOWN
dataSourceUp = false;
dataSourceDetailMap.put(dataSourceBeanName, new Status(Status.DOWN.getCode(), e.getMessage()));
}
}
// If Dashboard and DataSource are both OK, the health status is UP
if (dashboardUp && dataSourceUp) {
builder.up().withDetails(detailMap);
} else {
builder.down().withDetails(detailMap);
}
}
}

View File

@@ -1,9 +1,9 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.sentinel.SentinelWebAutoConfiguration,\
org.springframework.cloud.alibaba.sentinel.SentinelWebFluxAutoConfiguration,\
org.springframework.cloud.alibaba.sentinel.endpoint.SentinelEndpointAutoConfiguration,\
org.springframework.cloud.alibaba.sentinel.custom.SentinelAutoConfiguration,\
org.springframework.cloud.alibaba.sentinel.feign.SentinelFeignAutoConfiguration
com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration,\
com.alibaba.cloud.sentinel.SentinelWebFluxAutoConfiguration,\
com.alibaba.cloud.sentinel.endpoint.SentinelEndpointAutoConfiguration,\
com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration,\
com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
org.springframework.cloud.alibaba.sentinel.custom.SentinelCircuitBreakerConfiguration
com.alibaba.cloud.sentinel.custom.SentinelCircuitBreakerConfiguration