mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1758 : [CodeBase] Sync the source code from greenwich to finichley
This commit is contained in:
parent
201a4eaa01
commit
8cbd14b2bb
@ -67,14 +67,12 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
|
|||||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||||
public class NacosDiscoveryProperties {
|
public class NacosDiscoveryProperties {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory
|
|
||||||
.getLogger(NacosDiscoveryProperties.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefix of {@link NacosDiscoveryProperties}.
|
* Prefix of {@link NacosDiscoveryProperties}.
|
||||||
*/
|
*/
|
||||||
public static final String PREFIX = "spring.cloud.nacos.discovery";
|
public static final String PREFIX = "spring.cloud.nacos.discovery";
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(NacosDiscoveryProperties.class);
|
||||||
private static final Pattern PATTERN = Pattern.compile("-(\\w)");
|
private static final Pattern PATTERN = Pattern.compile("-(\\w)");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,21 +42,37 @@ public class NacosServiceInstance implements ServiceInstance {
|
|||||||
return serviceId;
|
return serviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setServiceId(String serviceId) {
|
||||||
|
this.serviceId = serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSecure() {
|
public boolean isSecure() {
|
||||||
return secure;
|
return secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSecure(boolean secure) {
|
||||||
|
this.secure = secure;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getUri() {
|
public URI getUri() {
|
||||||
return DefaultServiceInstance.getUri(this);
|
return DefaultServiceInstance.getUri(this);
|
||||||
@ -67,22 +83,6 @@ public class NacosServiceInstance implements ServiceInstance {
|
|||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServiceId(String serviceId) {
|
|
||||||
this.serviceId = serviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSecure(boolean secure) {
|
|
||||||
this.secure = secure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMetadata(Map<String, String> metadata) {
|
public void setMetadata(Map<String, String> metadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,11 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|||||||
*/
|
*/
|
||||||
public class NacosDiscoveryClient implements DiscoveryClient {
|
public class NacosDiscoveryClient implements DiscoveryClient {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NacosDiscoveryClient.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nacos Discovery Client Description.
|
* Nacos Discovery Client Description.
|
||||||
*/
|
*/
|
||||||
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
|
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(NacosDiscoveryClient.class);
|
||||||
private NacosServiceDiscovery serviceDiscovery;
|
private NacosServiceDiscovery serviceDiscovery;
|
||||||
|
|
||||||
public NacosDiscoveryClient(NacosServiceDiscovery nacosServiceDiscovery) {
|
public NacosDiscoveryClient(NacosServiceDiscovery nacosServiceDiscovery) {
|
||||||
|
@ -46,31 +46,6 @@ public class NacosServiceDiscovery {
|
|||||||
this.nacosServiceManager = nacosServiceManager;
|
this.nacosServiceManager = nacosServiceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all instances for the given service.
|
|
||||||
* @param serviceId id of service
|
|
||||||
* @return list of instances
|
|
||||||
* @throws NacosException nacosException
|
|
||||||
*/
|
|
||||||
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
|
|
||||||
String group = discoveryProperties.getGroup();
|
|
||||||
List<Instance> instances = namingService().selectInstances(serviceId, group,
|
|
||||||
true);
|
|
||||||
return hostToServiceInstanceList(instances, serviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the names of all services.
|
|
||||||
* @return list of service names
|
|
||||||
* @throws NacosException nacosException
|
|
||||||
*/
|
|
||||||
public List<String> getServices() throws NacosException {
|
|
||||||
String group = discoveryProperties.getGroup();
|
|
||||||
ListView<String> services = namingService().getServicesOfServer(1,
|
|
||||||
Integer.MAX_VALUE, group);
|
|
||||||
return services.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ServiceInstance> hostToServiceInstanceList(
|
public static List<ServiceInstance> hostToServiceInstanceList(
|
||||||
List<Instance> instances, String serviceId) {
|
List<Instance> instances, String serviceId) {
|
||||||
List<ServiceInstance> result = new ArrayList<>(instances.size());
|
List<ServiceInstance> result = new ArrayList<>(instances.size());
|
||||||
@ -111,6 +86,31 @@ public class NacosServiceDiscovery {
|
|||||||
return nacosServiceInstance;
|
return nacosServiceInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all instances for the given service.
|
||||||
|
* @param serviceId id of service
|
||||||
|
* @return list of instances
|
||||||
|
* @throws NacosException nacosException
|
||||||
|
*/
|
||||||
|
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
|
||||||
|
String group = discoveryProperties.getGroup();
|
||||||
|
List<Instance> instances = namingService().selectInstances(serviceId, group,
|
||||||
|
true);
|
||||||
|
return hostToServiceInstanceList(instances, serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the names of all services.
|
||||||
|
* @return list of service names
|
||||||
|
* @throws NacosException nacosException
|
||||||
|
*/
|
||||||
|
public List<String> getServices() throws NacosException {
|
||||||
|
String group = discoveryProperties.getGroup();
|
||||||
|
ListView<String> services = namingService().getServicesOfServer(1,
|
||||||
|
Integer.MAX_VALUE, group);
|
||||||
|
return services.getData();
|
||||||
|
}
|
||||||
|
|
||||||
private NamingService namingService() {
|
private NamingService namingService() {
|
||||||
return nacosServiceManager
|
return nacosServiceManager
|
||||||
.getNamingService(discoveryProperties.getNacosProperties());
|
.getNamingService(discoveryProperties.getNacosProperties());
|
||||||
|
@ -51,22 +51,14 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|||||||
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
||||||
|
|
||||||
private Map<String, EventListener> listenerMap = new ConcurrentHashMap<>(16);
|
|
||||||
|
|
||||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
|
||||||
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
||||||
|
|
||||||
private ApplicationEventPublisher publisher;
|
|
||||||
|
|
||||||
private ScheduledFuture<?> watchFuture;
|
|
||||||
|
|
||||||
private NacosServiceManager nacosServiceManager;
|
|
||||||
|
|
||||||
private final NacosDiscoveryProperties properties;
|
private final NacosDiscoveryProperties properties;
|
||||||
|
|
||||||
private final TaskScheduler taskScheduler;
|
private final TaskScheduler taskScheduler;
|
||||||
|
private Map<String, EventListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||||
|
private ApplicationEventPublisher publisher;
|
||||||
|
private ScheduledFuture<?> watchFuture;
|
||||||
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
|
||||||
public NacosWatch(NacosServiceManager nacosServiceManager,
|
public NacosWatch(NacosServiceManager nacosServiceManager,
|
||||||
NacosDiscoveryProperties properties,
|
NacosDiscoveryProperties properties,
|
||||||
|
@ -72,6 +72,16 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void customize(
|
||||||
|
List<NacosRegistrationCustomizer> registrationCustomizers,
|
||||||
|
NacosRegistration registration) {
|
||||||
|
if (registrationCustomizers != null) {
|
||||||
|
for (NacosRegistrationCustomizer customizer : registrationCustomizers) {
|
||||||
|
customizer.customize(registration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
@ -112,16 +122,6 @@ public class NacosRegistration implements Registration, ServiceInstance {
|
|||||||
customize(registrationCustomizers, this);
|
customize(registrationCustomizers, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void customize(
|
|
||||||
List<NacosRegistrationCustomizer> registrationCustomizers,
|
|
||||||
NacosRegistration registration) {
|
|
||||||
if (registrationCustomizers != null) {
|
|
||||||
for (NacosRegistrationCustomizer customizer : registrationCustomizers) {
|
|
||||||
customizer.customize(registration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getServiceId() {
|
public String getServiceId() {
|
||||||
return nacosDiscoveryProperties.getService();
|
return nacosDiscoveryProperties.getService();
|
||||||
|
@ -61,18 +61,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848" }, webEnvironment = RANDOM_PORT)
|
"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848" }, webEnvironment = RANDOM_PORT)
|
||||||
public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
|
public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosRegistration registration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosDiscoveryProperties properties;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InetUtils inetUtils;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||||
@ -90,6 +78,15 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosRegistration registration;
|
||||||
|
@Autowired
|
||||||
|
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||||
|
@Autowired
|
||||||
|
private NacosDiscoveryProperties properties;
|
||||||
|
@Autowired
|
||||||
|
private InetUtils inetUtils;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() throws Exception {
|
public void contextLoads() throws Exception {
|
||||||
assertThat(registration).isNotNull();
|
assertThat(registration).isNotNull();
|
||||||
|
@ -57,15 +57,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.cloud.nacos.discovery.ip=123.123.123.123" }, webEnvironment = RANDOM_PORT)
|
"spring.cloud.nacos.discovery.ip=123.123.123.123" }, webEnvironment = RANDOM_PORT)
|
||||||
public class NacosAutoServiceRegistrationIpTests {
|
public class NacosAutoServiceRegistrationIpTests {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosRegistration registration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosDiscoveryProperties properties;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||||
@ -83,6 +74,13 @@ public class NacosAutoServiceRegistrationIpTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosRegistration registration;
|
||||||
|
@Autowired
|
||||||
|
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||||
|
@Autowired
|
||||||
|
private NacosDiscoveryProperties properties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() throws Exception {
|
public void contextLoads() throws Exception {
|
||||||
assertThat(registration).isNotNull();
|
assertThat(registration).isNotNull();
|
||||||
|
@ -58,15 +58,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
||||||
public class NacosAutoServiceRegistrationManagementPortTests {
|
public class NacosAutoServiceRegistrationManagementPortTests {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosRegistration registration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosDiscoveryProperties properties;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||||
@ -84,6 +75,13 @@ public class NacosAutoServiceRegistrationManagementPortTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosRegistration registration;
|
||||||
|
@Autowired
|
||||||
|
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||||
|
@Autowired
|
||||||
|
private NacosDiscoveryProperties properties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() throws Exception {
|
public void contextLoads() throws Exception {
|
||||||
assertThat(registration).isNotNull();
|
assertThat(registration).isNotNull();
|
||||||
|
@ -57,15 +57,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
"spring.cloud.nacos.discovery.port=8888" }, webEnvironment = RANDOM_PORT)
|
||||||
public class NacosAutoServiceRegistrationPortTests {
|
public class NacosAutoServiceRegistrationPortTests {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosRegistration registration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosDiscoveryProperties properties;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||||
@ -83,6 +74,13 @@ public class NacosAutoServiceRegistrationPortTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosRegistration registration;
|
||||||
|
@Autowired
|
||||||
|
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||||
|
@Autowired
|
||||||
|
private NacosDiscoveryProperties properties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() throws Exception {
|
public void contextLoads() throws Exception {
|
||||||
assertThat(registration).isNotNull();
|
assertThat(registration).isNotNull();
|
||||||
|
@ -74,24 +74,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
"spring.cloud.nacos.discovery.ip-delete-timeout=9" }, webEnvironment = RANDOM_PORT)
|
"spring.cloud.nacos.discovery.ip-delete-timeout=9" }, webEnvironment = RANDOM_PORT)
|
||||||
public class NacosAutoServiceRegistrationTests {
|
public class NacosAutoServiceRegistrationTests {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosRegistration registration;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
|
||||||
|
|
||||||
@LocalServerPort
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosDiscoveryProperties properties;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosServiceManager nacosServiceManager;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InetUtils inetUtils;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
Method method = PowerMockito.method(NacosFactory.class, "createNamingService",
|
||||||
@ -109,6 +91,19 @@ public class NacosAutoServiceRegistrationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NacosRegistration registration;
|
||||||
|
@Autowired
|
||||||
|
private NacosAutoServiceRegistration nacosAutoServiceRegistration;
|
||||||
|
@LocalServerPort
|
||||||
|
private int port;
|
||||||
|
@Autowired
|
||||||
|
private NacosDiscoveryProperties properties;
|
||||||
|
@Autowired
|
||||||
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
@Autowired
|
||||||
|
private InetUtils inetUtils;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contextLoads() throws Exception {
|
public void contextLoads() throws Exception {
|
||||||
assertThat(registration).isNotNull();
|
assertThat(registration).isNotNull();
|
||||||
|
@ -36,11 +36,9 @@ import org.springframework.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class SeataFeignClient implements Client {
|
public class SeataFeignClient implements Client {
|
||||||
|
|
||||||
private final Client delegate;
|
|
||||||
|
|
||||||
private final BeanFactory beanFactory;
|
|
||||||
|
|
||||||
private static final int MAP_SIZE = 16;
|
private static final int MAP_SIZE = 16;
|
||||||
|
private final Client delegate;
|
||||||
|
private final BeanFactory beanFactory;
|
||||||
|
|
||||||
SeataFeignClient(BeanFactory beanFactory) {
|
SeataFeignClient(BeanFactory beanFactory) {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
|
@ -35,17 +35,16 @@ import org.springframework.web.client.RestTemplate;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class SeataRestTemplateAutoConfiguration {
|
public class SeataRestTemplateAutoConfiguration {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private Collection<RestTemplate> restTemplates;
|
||||||
|
@Autowired
|
||||||
|
private SeataRestTemplateInterceptor seataRestTemplateInterceptor;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SeataRestTemplateInterceptor seataRestTemplateInterceptor() {
|
public SeataRestTemplateInterceptor seataRestTemplateInterceptor() {
|
||||||
return new SeataRestTemplateInterceptor();
|
return new SeataRestTemplateInterceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private Collection<RestTemplate> restTemplates;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SeataRestTemplateInterceptor seataRestTemplateInterceptor;
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
if (this.restTemplates != null) {
|
if (this.restTemplates != null) {
|
||||||
|
@ -27,16 +27,14 @@ import com.alibaba.csp.sentinel.util.StringUtil;
|
|||||||
*/
|
*/
|
||||||
final class BlockClassRegistry {
|
final class BlockClassRegistry {
|
||||||
|
|
||||||
|
private static final Map<String, Method> FALLBACK_MAP = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<String, Method> BLOCK_HANDLER_MAP = new ConcurrentHashMap<>();
|
||||||
|
private static final Map<String, Method> URL_CLEANER_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private BlockClassRegistry() {
|
private BlockClassRegistry() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<String, Method> FALLBACK_MAP = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private static final Map<String, Method> BLOCK_HANDLER_MAP = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
private static final Map<String, Method> URL_CLEANER_MAP = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
static Method lookupFallback(Class<?> clazz, String name) {
|
static Method lookupFallback(Class<?> clazz, String name) {
|
||||||
return FALLBACK_MAP.get(getKey(clazz, name));
|
return FALLBACK_MAP.get(getKey(clazz, name));
|
||||||
}
|
}
|
||||||
|
@ -56,13 +56,12 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
.getLogger(SentinelBeanPostProcessor.class);
|
.getLogger(SentinelBeanPostProcessor.class);
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
private ConcurrentHashMap<String, SentinelRestTemplate> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public SentinelBeanPostProcessor(ApplicationContext applicationContext) {
|
public SentinelBeanPostProcessor(ApplicationContext applicationContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConcurrentHashMap<String, SentinelRestTemplate> cache = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
||||||
Class<?> beanType, String beanName) {
|
Class<?> beanType, String beanName) {
|
||||||
|
@ -52,20 +52,13 @@ public class SentinelDataSourceHandler implements SmartInitializingSingleton {
|
|||||||
|
|
||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(SentinelDataSourceHandler.class);
|
.getLogger(SentinelDataSourceHandler.class);
|
||||||
|
|
||||||
private List<String> dataTypeList = Arrays.asList("json", "xml");
|
|
||||||
|
|
||||||
private final String DATA_TYPE_FIELD = "dataType";
|
private final String DATA_TYPE_FIELD = "dataType";
|
||||||
|
|
||||||
private final String CUSTOM_DATA_TYPE = "custom";
|
private final String CUSTOM_DATA_TYPE = "custom";
|
||||||
|
|
||||||
private final String CONVERTER_CLASS_FIELD = "converterClass";
|
private final String CONVERTER_CLASS_FIELD = "converterClass";
|
||||||
|
|
||||||
private final DefaultListableBeanFactory beanFactory;
|
private final DefaultListableBeanFactory beanFactory;
|
||||||
|
|
||||||
private final SentinelProperties sentinelProperties;
|
private final SentinelProperties sentinelProperties;
|
||||||
|
|
||||||
private final Environment env;
|
private final Environment env;
|
||||||
|
private List<String> dataTypeList = Arrays.asList("json", "xml");
|
||||||
|
|
||||||
public SentinelDataSourceHandler(DefaultListableBeanFactory beanFactory,
|
public SentinelDataSourceHandler(DefaultListableBeanFactory beanFactory,
|
||||||
SentinelProperties sentinelProperties, Environment env) {
|
SentinelProperties sentinelProperties, Environment env) {
|
||||||
|
@ -76,7 +76,7 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
|||||||
// detail
|
// detail
|
||||||
if (!sentinelProperties.isEnabled()) {
|
if (!sentinelProperties.isEnabled()) {
|
||||||
detailMap.put("enabled", false);
|
detailMap.put("enabled", false);
|
||||||
builder.up().withDetails(detailMap);
|
withDetails(builder.up(), detailMap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,11 +144,16 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
|||||||
|
|
||||||
// If Dashboard and DataSource are both OK, the health status is UP
|
// If Dashboard and DataSource are both OK, the health status is UP
|
||||||
if (dashboardUp && dataSourceUp) {
|
if (dashboardUp && dataSourceUp) {
|
||||||
builder.up().withDetails(detailMap);
|
withDetails(builder.up(), detailMap);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
builder.unknown().withDetails(detailMap);
|
withDetails(builder.down(), detailMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void withDetails(Health.Builder builder, Map<String, Object> detailMap) {
|
||||||
|
for (String key : detailMap.keySet()) {
|
||||||
|
builder.withDetail(key, detailMap.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,12 @@ import feign.MethodMetadata;
|
|||||||
*/
|
*/
|
||||||
public class SentinelContractHolder implements Contract {
|
public class SentinelContractHolder implements Contract {
|
||||||
|
|
||||||
private final Contract delegate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map key is constructed by ClassFullName + configKey. configKey is constructed by
|
* map key is constructed by ClassFullName + configKey. configKey is constructed by
|
||||||
* {@link feign.Feign#configKey}
|
* {@link feign.Feign#configKey}
|
||||||
*/
|
*/
|
||||||
public final static Map<String, MethodMetadata> METADATA_MAP = new HashMap<>();
|
public final static Map<String, MethodMetadata> METADATA_MAP = new HashMap<>();
|
||||||
|
private final Contract delegate;
|
||||||
|
|
||||||
public SentinelContractHolder(Contract delegate) {
|
public SentinelContractHolder(Contract delegate) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
@ -65,13 +65,23 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
|||||||
this.dispatch = checkNotNull(dispatch, "dispatch");
|
this.dispatch = checkNotNull(dispatch, "dispatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Map<Method, Method> toFallbackMethod(Map<Method, MethodHandler> dispatch) {
|
||||||
|
Map<Method, Method> result = new LinkedHashMap<>();
|
||||||
|
for (Method method : dispatch.keySet()) {
|
||||||
|
method.setAccessible(true);
|
||||||
|
result.put(method, method);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(final Object proxy, final Method method, final Object[] args)
|
public Object invoke(final Object proxy, final Method method, final Object[] args)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
if ("equals".equals(method.getName())) {
|
if ("equals".equals(method.getName())) {
|
||||||
try {
|
try {
|
||||||
Object otherHandler = args.length > 0 && args[0] != null
|
Object otherHandler = args.length > 0 && args[0] != null
|
||||||
? Proxy.getInvocationHandler(args[0]) : null;
|
? Proxy.getInvocationHandler(args[0])
|
||||||
|
: null;
|
||||||
return equals(otherHandler);
|
return equals(otherHandler);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
@ -99,7 +109,7 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String resourceName = methodMetadata.template().method().toUpperCase()
|
String resourceName = methodMetadata.template().method().toUpperCase()
|
||||||
+ ":" + hardCodedTarget.url() + methodMetadata.template().path();
|
+ ":" + hardCodedTarget.url() + methodMetadata.template().url();
|
||||||
Entry entry = null;
|
Entry entry = null;
|
||||||
try {
|
try {
|
||||||
ContextUtil.enter(resourceName);
|
ContextUtil.enter(resourceName);
|
||||||
@ -166,13 +176,4 @@ public class SentinelInvocationHandler implements InvocationHandler {
|
|||||||
return target.toString();
|
return target.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<Method, Method> toFallbackMethod(Map<Method, MethodHandler> dispatch) {
|
|
||||||
Map<Method, Method> result = new LinkedHashMap<>();
|
|
||||||
for (Method method : dispatch.keySet()) {
|
|
||||||
method.setAccessible(true);
|
|
||||||
result.put(method, method);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,14 +61,6 @@ public class ContextIdSentinelFeignTests {
|
|||||||
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
|
||||||
@EnableFeignClients
|
|
||||||
public static class TestConfig {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@FeignClient(contextId = "echoService", name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
|
@FeignClient(contextId = "echoService", name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
|
||||||
public interface EchoService {
|
public interface EchoService {
|
||||||
|
|
||||||
@ -85,6 +77,14 @@ public class ContextIdSentinelFeignTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||||
|
@EnableFeignClients
|
||||||
|
public static class TestConfig {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class FeignConfiguration {
|
public static class FeignConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -118,24 +118,6 @@ public class SentinelFeignTests {
|
|||||||
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
assertThat(echoService.equals(fooService)).isEqualTo(Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
|
||||||
@EnableFeignClients
|
|
||||||
public static class TestConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public EchoServiceFallback echoServiceFallback() {
|
|
||||||
return new EchoServiceFallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CustomFallbackFactory customFallbackFactory() {
|
|
||||||
return new CustomFallbackFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@FeignClient(value = "test-service", fallback = EchoServiceFallback.class)
|
@FeignClient(value = "test-service", fallback = EchoServiceFallback.class)
|
||||||
public interface EchoService {
|
public interface EchoService {
|
||||||
|
|
||||||
@ -172,6 +154,24 @@ public class SentinelFeignTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ImportAutoConfiguration({ SentinelFeignAutoConfiguration.class })
|
||||||
|
@EnableFeignClients
|
||||||
|
public static class TestConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public EchoServiceFallback echoServiceFallback() {
|
||||||
|
return new EchoServiceFallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CustomFallbackFactory customFallbackFactory() {
|
||||||
|
return new CustomFallbackFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class EchoServiceFallback implements EchoService {
|
public static class EchoServiceFallback implements EchoService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,10 +30,8 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
|||||||
|
|
||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(SidecarNacosDiscoveryClient.class);
|
.getLogger(SidecarNacosDiscoveryClient.class);
|
||||||
|
|
||||||
private NacosServiceManager nacosServiceManager;
|
|
||||||
|
|
||||||
private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties;
|
private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties;
|
||||||
|
private NacosServiceManager nacosServiceManager;
|
||||||
|
|
||||||
public SidecarNacosDiscoveryClient(NacosServiceManager nacosServiceManager,
|
public SidecarNacosDiscoveryClient(NacosServiceManager nacosServiceManager,
|
||||||
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||||
|
@ -111,7 +111,8 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
|||||||
@Override
|
@Override
|
||||||
public void afterSingletonsInstantiated() {
|
public void afterSingletonsInstantiated() {
|
||||||
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null
|
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null
|
||||||
? retryLoadBalancerInterceptor : loadBalancerInterceptor;
|
? retryLoadBalancerInterceptor
|
||||||
|
: loadBalancerInterceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,7 +141,8 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
|||||||
DEFAULT_PROTOCOL);
|
DEFAULT_PROTOCOL);
|
||||||
|
|
||||||
return isRestProtocol(protocol)
|
return isRestProtocol(protocol)
|
||||||
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME) : null;
|
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME)
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRestPortFromProtocolsProperties(
|
private String getRestPortFromProtocolsProperties(
|
||||||
|
@ -127,8 +127,7 @@ public class DubboGenericServiceFactory {
|
|||||||
new PropertyEditorSupport() {
|
new PropertyEditorSupport() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAsText(String text)
|
public void setAsText(String text) throws IllegalArgumentException {
|
||||||
throws IllegalArgumentException {
|
|
||||||
// Trim all whitespace
|
// Trim all whitespace
|
||||||
String content = StringUtils.trimAllWhitespace(text);
|
String content = StringUtils.trimAllWhitespace(text);
|
||||||
if (!StringUtils.hasText(content)) { // No content , ignore
|
if (!StringUtils.hasText(content)) { // No content , ignore
|
||||||
|
Loading…
x
Reference in New Issue
Block a user