From 11db5e87281919bdfa269ac8824c0f2064eba4c2 Mon Sep 17 00:00:00 2001 From: flystar32 Date: Thu, 28 Feb 2019 17:11:04 +0800 Subject: [PATCH] add test case of ANS --- .../alicloud/ans/AnsAutoConfiguration.java | 3 - .../alicloud/ans/AnsDiscoveryClient.java | 7 +- .../AnsDiscoveryClientAutoConfiguration.java | 3 - .../alicloud/ans/endpoint/AnsEndpoint.java | 6 +- .../alicloud/ans/migrate/MigrateEndpoint.java | 31 ---- .../MigrateEndpointAutoConfiguration.java | 21 --- .../ans/migrate/MigrateOnCondition.java | 48 ----- .../ans/migrate/MigrateOnConditionClass.java | 23 --- .../MigrateOnConditionMissingClass.java | 22 --- .../ans/migrate/MigrateProxyManager.java | 97 ---------- .../migrate/MigrateRefreshEventListener.java | 78 -------- .../MigrateRibbonBeanPostProcessor.java | 52 ------ .../ans/migrate/MigrateServiceRegistry.java | 52 ------ .../migrate/MigrationAutoconfiguration.java | 39 ---- .../migrate/ServerListInvocationHandler.java | 170 ------------------ .../alicloud/ans/migrate/ServerWrapper.java | 38 ---- .../registry/AnsAutoServiceRegistration.java | 2 - .../ans/registry/AnsServiceRegistry.java | 17 +- .../ribbon/AnsRibbonClientConfiguration.java | 3 - .../cloud/alicloud/ans/ribbon/AnsServer.java | 40 +---- .../alicloud/ans/ribbon/AnsServerList.java | 16 +- .../ans/ribbon/MigrateRibbonCofiguration.java | 19 -- .../ribbon/RibbonAnsAutoConfiguration.java | 3 +- .../main/resources/META-INF/spring.factories | 2 - .../ans/ribbon/AnsServerListTests.java | 6 - 25 files changed, 22 insertions(+), 776 deletions(-) delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpoint.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpointAutoConfiguration.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnCondition.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionClass.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionMissingClass.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateProxyManager.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRefreshEventListener.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRibbonBeanPostProcessor.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateServiceRegistry.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrationAutoconfiguration.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerListInvocationHandler.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerWrapper.java delete mode 100644 spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/MigrateRibbonCofiguration.java diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java index fb96cfc14..3364c21bd 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java @@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.alicloud.ans.migrate.MigrateOnConditionMissingClass; import org.springframework.cloud.alicloud.ans.registry.AnsAutoServiceRegistration; import org.springframework.cloud.alicloud.ans.registry.AnsRegistration; import org.springframework.cloud.alicloud.ans.registry.AnsServiceRegistry; @@ -30,7 +29,6 @@ import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationC import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; /** @@ -38,7 +36,6 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @EnableConfigurationProperties -@Conditional(MigrateOnConditionMissingClass.class) @ConditionalOnClass(name = "org.springframework.boot.web.context.WebServerInitializedEvent") @ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) @ConditionalOnAnsEnabled diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClient.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClient.java index 6f93a9790..493dfdcd0 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClient.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClient.java @@ -22,12 +22,7 @@ import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author xiaolongzuo diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java index 06508b07a..e035b2a34 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/AnsDiscoveryClientAutoConfiguration.java @@ -19,11 +19,9 @@ package org.springframework.cloud.alicloud.ans; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.alicloud.ans.migrate.MigrateOnConditionMissingClass; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; /** @@ -31,7 +29,6 @@ import org.springframework.context.annotation.Configuration; * @author pbting */ @Configuration -@Conditional(MigrateOnConditionMissingClass.class) @ConditionalOnMissingBean(DiscoveryClient.class) @EnableConfigurationProperties @AutoConfigureBefore(SimpleDiscoveryClientAutoConfiguration.class) diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/endpoint/AnsEndpoint.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/endpoint/AnsEndpoint.java index baefdb56d..7688074e0 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/endpoint/AnsEndpoint.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/endpoint/AnsEndpoint.java @@ -19,8 +19,8 @@ package org.springframework.cloud.alicloud.ans.endpoint; import com.alibaba.ans.core.NamingService; import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.cloud.alicloud.context.ans.AnsProperties; @@ -37,7 +37,7 @@ import java.util.Set; @Endpoint(id = "ans") public class AnsEndpoint { - private static final Log log = LogFactory.getLog(AnsEndpoint.class); + private static final Logger log = LoggerFactory.getLogger(AnsEndpoint.class); private AnsProperties ansProperties; diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpoint.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpoint.java deleted file mode 100644 index 59b2146a3..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpoint.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; - -import java.util.Map; -import java.util.concurrent.ConcurrentMap; - -@Endpoint(id = "migrate") -public class MigrateEndpoint { - - private static final Logger log = LoggerFactory.getLogger(MigrateEndpoint.class); - - public MigrateEndpoint() { - } - - /** - * @return ans endpoint - */ - @ReadOperation - public Map> invoke() { - - Map> result = ServerListInvocationHandler - .getServerRegistry(); - - log.info("migrate server list :" + result); - return result; - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpointAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpointAutoConfiguration.java deleted file mode 100644 index af572837a..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateEndpointAutoConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.springframework.boot.actuate.endpoint.annotation.Endpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; - -/** - * @author pbting - */ -@ConditionalOnWebApplication -@ConditionalOnClass(value = Endpoint.class) -@Conditional(MigrateOnConditionClass.class) -public class MigrateEndpointAutoConfiguration { - - @Bean - public MigrateEndpoint ansEndpoint() { - return new MigrateEndpoint(); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnCondition.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnCondition.java deleted file mode 100644 index 86816587e..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnCondition.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; -import org.springframework.util.ClassUtils; - -/** - * @author pbting - */ -public abstract class MigrateOnCondition implements Condition, BeanClassLoaderAware { - - final String[] conditionOnClass = new String[] { - "org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration", - "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration" }; - - ClassLoader classLoader; - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.classLoader = classLoader; - } - - @Override - public abstract boolean matches(ConditionContext context, - AnnotatedTypeMetadata metadata); - - boolean isPresent(String className, ClassLoader classLoader) { - if (classLoader == null) { - classLoader = ClassUtils.getDefaultClassLoader(); - } - - try { - forName(className, classLoader); - return true; - } - catch (Throwable throwable) { - return false; - } - } - - Class forName(String className, ClassLoader classLoader) - throws ClassNotFoundException { - return classLoader != null ? classLoader.loadClass(className) - : Class.forName(className); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionClass.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionClass.java deleted file mode 100644 index 9e99c9f8f..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionClass.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * @author pbting - */ -public class MigrateOnConditionClass extends MigrateOnCondition { - - private static final Logger log = LoggerFactory - .getLogger(MigrateOnConditionClass.class); - - @Override - public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - boolean result = isPresent(conditionOnClass[0], classLoader) - || isPresent(conditionOnClass[1], classLoader); - log.info("the result of matcher is " + result); - return result; - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionMissingClass.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionMissingClass.java deleted file mode 100644 index b5653bb78..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateOnConditionMissingClass.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * @author pbting - */ -public class MigrateOnConditionMissingClass extends MigrateOnConditionClass { - private static final Logger log = LoggerFactory - .getLogger(MigrateOnConditionMissingClass.class); - - @Override - public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - boolean result = !super.matches(context, metadata); - log.info(" the result of matcher is " + result); - return result; - } - -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateProxyManager.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateProxyManager.java deleted file mode 100644 index f44f1af91..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateProxyManager.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ILoadBalancer; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerList; -import org.aopalliance.aop.Advice; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aop.AfterReturningAdvice; -import org.springframework.aop.framework.ProxyFactory; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author pbting - */ -final class MigrateProxyManager { - - private static final Logger log = LoggerFactory.getLogger(MigrateProxyManager.class); - private final static AtomicBoolean IS_PROXY = new AtomicBoolean(true); - - private final static Set SERVICES_ID = new ConcurrentSkipListSet<>(); - - private static Object springProxyFactory(Object target, ClassLoader classLoader, - List adviceList, Class... interfaces) { - final ProxyFactory proxyFactory = new ProxyFactory(interfaces); - proxyFactory.setTarget(target); - adviceList.forEach(advice -> proxyFactory.addAdvice(advice)); - return proxyFactory.getProxy(classLoader); - } - - static Object newServerListProxy(Object bean, ClassLoader classLoader, - IClientConfig clientConfig) { - bean = springProxyFactory(bean, classLoader, - Arrays.asList(new ServerListInvocationHandler(clientConfig)), - new Class[] { ServerList.class }); - log.info("[service id]" + clientConfig.getClientName() - + " new a ServerList proxy instance for spring cloud netflix to spring cloud alibaba "); - collectServiceId(clientConfig.getClientName()); - return bean; - } - - static Object newLoadBalancerProxy(Object bean, ClassLoader classLoader, - final IClientConfig clientConfig) { - - bean = springProxyFactory(bean, classLoader, - Arrays.asList(new AfterReturningAdvice() { - private final IClientConfig iclientConfig = clientConfig; - - @Override - public void afterReturning(Object returnValue, Method method, - Object[] args, Object target) { - String methodName = method.getName(); - if ("chooseServer".equals(methodName)) { - String serviceId = iclientConfig.getClientName(); - Server server = (Server) returnValue; - server = ServerListInvocationHandler - .checkAndGetServiceServer(serviceId, server); - ServerListInvocationHandler.incrementCallService(serviceId, - server); - } - } - }), new Class[] { ILoadBalancer.class }); - log.info("[service id]" + clientConfig.getClientName() - + " new a ILoadBalancer proxy instance for spring cloud netflix to spring cloud alibaba "); - return bean; - } - - static void migrateProxyClose() { - IS_PROXY.set(false); - } - - static void migrateProxyUp() { - IS_PROXY.set(true); - } - - static boolean isMigrateProxy() { - - return IS_PROXY.get(); - } - - static void collectServiceId(String serviceId) { - SERVICES_ID.add(serviceId); - } - - static Set getServicesId() { - - return Collections.unmodifiableSet(SERVICES_ID); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRefreshEventListener.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRefreshEventListener.java deleted file mode 100644 index 70d121132..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRefreshEventListener.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import com.netflix.loadbalancer.ILoadBalancer; -import org.springframework.cloud.context.named.NamedContextFactory; -import org.springframework.cloud.endpoint.event.RefreshEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/** - * @author pbting - */ -@Component -public class MigrateRefreshEventListener implements ApplicationListener { - - private final static int CHECK_INTERVAL = 1; - - private final static String MIGRATE_SWITCH = "spring.cloud.alicloud.migrate.ans.switch"; - - private volatile String lastScaMigrateAnsSwitchValue = "true"; - - private Environment environment; - - private NamedContextFactory namedContextFactory; - - public MigrateRefreshEventListener(Environment environment, - NamedContextFactory namedContextFactory) { - this.environment = environment; - this.namedContextFactory = namedContextFactory; - } - - @PostConstruct - public void initTimerCheck() { - Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay( - () -> onApplicationEvent(null), CHECK_INTERVAL, CHECK_INTERVAL, - TimeUnit.SECONDS); - } - - @Override - public void onApplicationEvent(RefreshEvent event) { - String value = environment.getProperty(MIGRATE_SWITCH, "true"); - // check 1: check the value - if (value.equals(lastScaMigrateAnsSwitchValue)) { - return; - } - - updateLastScaMigrateAnsResetValue(value); - - // step 1: migrate up - if ("true".equals(value)) { - MigrateProxyManager.migrateProxyUp(); - serviceIdContextInit(); - return; - } - - // step 2: migrate close - if ("false".equals(value)) { - MigrateProxyManager.migrateProxyClose(); - serviceIdContextInit(); - return; - } - } - - private void serviceIdContextInit() { - namedContextFactory.destroy(); - // initializer each spring context for service id - MigrateProxyManager.getServicesId().forEach(serviceId -> namedContextFactory - .getInstance(serviceId, ILoadBalancer.class)); - } - - private synchronized void updateLastScaMigrateAnsResetValue(String value) { - this.lastScaMigrateAnsSwitchValue = value; - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRibbonBeanPostProcessor.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRibbonBeanPostProcessor.java deleted file mode 100644 index b03a18906..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateRibbonBeanPostProcessor.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.ILoadBalancer; -import com.netflix.loadbalancer.ServerList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.config.BeanPostProcessor; - -public class MigrateRibbonBeanPostProcessor - implements BeanPostProcessor, BeanClassLoaderAware { - - private static final Logger log = LoggerFactory.getLogger(MigrateOnCondition.class); - - private ClassLoader classLoader; - private IClientConfig clientConfig; - - public MigrateRibbonBeanPostProcessor(IClientConfig clientConfig) { - this.clientConfig = clientConfig; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) - throws BeansException { - - // step 1 : check the bean whether proxy or not - if (!MigrateProxyManager.isMigrateProxy()) { - log.info("Migrate proxy is Close."); - return bean; - } - - // step 2 : proxy the designated bean - if (bean instanceof ServerList) { - bean = MigrateProxyManager.newServerListProxy(bean, classLoader, - clientConfig); - } - - if (bean instanceof ILoadBalancer) { - bean = MigrateProxyManager.newLoadBalancerProxy(bean, classLoader, - clientConfig); - } - return bean; - } - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.classLoader = classLoader; - } - -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateServiceRegistry.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateServiceRegistry.java deleted file mode 100644 index 11ca9e9cf..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrateServiceRegistry.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.web.context.WebServerInitializedEvent; -import org.springframework.cloud.alicloud.ans.registry.AnsRegistration; -import org.springframework.cloud.alicloud.ans.registry.AnsServiceRegistry; -import org.springframework.cloud.alicloud.context.ans.AnsProperties; -import org.springframework.cloud.client.serviceregistry.ServiceRegistry; -import org.springframework.context.ApplicationContext; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * @author pbting - */ -@Component -public class MigrateServiceRegistry { - - private static final Logger log = LoggerFactory - .getLogger(MigrateServiceRegistry.class); - - private AtomicBoolean running = new AtomicBoolean(false); - - private ServiceRegistry serviceRegistry; - private AnsRegistration ansRegistration; - - public MigrateServiceRegistry(AnsProperties ansProperties, - ApplicationContext context) { - this.ansRegistration = new AnsRegistration(ansProperties, context); - this.ansRegistration.init(); - this.serviceRegistry = new AnsServiceRegistry(); - } - - @EventListener(WebServerInitializedEvent.class) - public void onApplicationEvent(WebServerInitializedEvent event) { - int serverPort = event.getWebServer().getPort(); - this.ansRegistration.setPort(serverPort); - log.info("[ Migrate ] change the port to " + serverPort); - if (!this.running.get()) { - long s = System.currentTimeMillis(); - log.info("[Migrate] start to registry server to ANS"); - this.serviceRegistry.register(this.ansRegistration); - log.info("[migrate] end to registry server to ANS cost time with " - + (System.currentTimeMillis() - s) + " ms."); - this.running.set(true); - } - } - -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrationAutoconfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrationAutoconfiguration.java deleted file mode 100644 index 8f632bf19..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/MigrationAutoconfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.alicloud.ans.ConditionalOnAnsEnabled; -import org.springframework.cloud.alicloud.context.ans.AnsProperties; -import org.springframework.cloud.context.named.NamedContextFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; - -/** - * @author pbting - */ -@Configuration -@EnableConfigurationProperties -@Conditional(MigrateOnConditionClass.class) -@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) -@ConditionalOnAnsEnabled -public class MigrationAutoconfiguration { - - @Bean - public MigrateServiceRegistry migrationManger(AnsProperties ansProperties, - ApplicationContext applicationContext) { - - return new MigrateServiceRegistry(ansProperties, applicationContext); - } - - @Bean - public MigrateRefreshEventListener migrateRefreshEventListener( - Environment environment, - @Qualifier(value = "springClientFactory") NamedContextFactory namedContextFactory) { - - return new MigrateRefreshEventListener(environment, namedContextFactory); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerListInvocationHandler.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerListInvocationHandler.java deleted file mode 100644 index 16d533c14..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerListInvocationHandler.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.Server; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.alicloud.ans.ribbon.AnsServer; -import org.springframework.cloud.alicloud.ans.ribbon.AnsServerList; - -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author pbting - */ -class ServerListInvocationHandler implements MethodInterceptor { - - private static final Logger log = LoggerFactory - .getLogger(ServerListInvocationHandler.class); - - private final static ConcurrentMap SERVER_LIST_CONCURRENT_MAP = new ConcurrentHashMap<>(); - - private final static ConcurrentMap> CALL_SERVICE_COUNT = new ConcurrentHashMap<>(); - - private final static Set INTERCEPTOR_METHOD_NAME = new ConcurrentSkipListSet(); - - private IClientConfig clientConfig; - private AnsServerList ansServerList; - private AtomicBoolean isFirst = new AtomicBoolean(false); - - static { - INTERCEPTOR_METHOD_NAME.add("getInitialListOfServers"); - INTERCEPTOR_METHOD_NAME.add("getUpdatedListOfServers"); - } - - ServerListInvocationHandler(IClientConfig clientConfig) { - this.clientConfig = clientConfig; - this.ansServerList = new AnsServerList(clientConfig.getClientName()); - SERVER_LIST_CONCURRENT_MAP.put(ansServerList.getDom(), ansServerList); - } - - @Override - public Object invoke(MethodInvocation invocation) throws Throwable { - String methodName = invocation.getMethod().getName(); - // step 1: check the method is not interceptor - if (!INTERCEPTOR_METHOD_NAME.contains(methodName)) { - return invocation.proceed(); - } - - // step 2: interceptor the method - List serverList = (List) invocation.proceed(); - long s = System.currentTimeMillis(); - log.info("[ START ] merage server list for " + clientConfig.getClientName()); - serverList = mergeAnsServerList(serverList); - log.info("[ END ] merage server list for " + clientConfig.getClientName() - + ", cost time " + (System.currentTimeMillis() - s) + " ms ."); - return serverList; - } - - /** - * 后台线程 和 Eureka 两个注册中心进行 Merage 的时候,List 表中始终保持是有效的 Server. 即不考虑 ANS 客户端本地容灾的情况 - */ - private List mergeAnsServerList(final List source) { - if (isFirst.compareAndSet(false, true)) { - return source; - } - - // step 1: get all of server list and filter the alive - List ansServerList = filterAliveAnsServer( - this.ansServerList.getInitialListOfServers()); - - if (ansServerList.isEmpty()) { - return source; - } - - log.info("[" + this.clientConfig.getClientName() + "] Get Server List from ANS:" - + ansServerList + "; loadbalancer server list override before:" + source); - - // step 2:remove servers of that have in load balancer list - final Iterator serverIterator = source.iterator(); - while (serverIterator.hasNext()) { - final Server server = serverIterator.next(); - ansServerList.forEach(ansServer -> { - if (server.getHostPort() - .equals(ansServer.getHealthService().toInetAddr())) { - // by: ZoneAffinityPredicate - serverIterator.remove(); - log.info("Source Server is remove " + server.getHostPort() - + ", and from ANS Server is override:" - + ansServer.toString()); - } - // fix bug: mast be set the zone, update server list,will filter - ansServer.setZone(server.getZone()); - ansServer.setSchemea(server.getScheme()); - ansServer.setId(ansServer.getHealthService().toInetAddr()); - ansServer.setReadyToServe(true); - }); - } - - ansServerList.forEach(ansServer -> source.add(ansServer)); - log.info("[" + this.clientConfig.getClientName() + "] " - + "; loadbalancer server list override after:" + source); - // override - return source; - } - - private List filterAliveAnsServer(List sourceServerList) { - final List resultServerList = new LinkedList<>(); - sourceServerList.forEach(ansServer -> { - boolean isAlive = ansServer.isAlive(3); - if (isAlive) { - resultServerList.add(ansServer); - } - log.warn(ansServer.toString() + " isAlive :" + isAlive); - }); - return resultServerList; - } - - static Map> getServerRegistry() { - - return Collections.unmodifiableMap(CALL_SERVICE_COUNT); - } - - static Server checkAndGetServiceServer(String serviceId, Server server) { - if (server != null) { - return server; - } - - log.warn(String.format("[%s] refers the server is null", server)); - - List ansServerList = SERVER_LIST_CONCURRENT_MAP.get(serviceId) - .getInitialListOfServers(); - - if (!ansServerList.isEmpty()) { - return ansServerList.get(0); - } - - return server; - } - - static void incrementCallService(String serviceId, Server server) { - ConcurrentMap concurrentHashMap = CALL_SERVICE_COUNT - .putIfAbsent(serviceId, new ConcurrentHashMap<>()); - - if (concurrentHashMap == null) { - concurrentHashMap = CALL_SERVICE_COUNT.get(serviceId); - } - - String ipPort = server.getHostPort(); - ServerWrapper serverWraper = concurrentHashMap.putIfAbsent(ipPort, - new ServerWrapper(server, new AtomicLong())); - - if (serverWraper == null) { - serverWraper = concurrentHashMap.get(ipPort); - } - serverWraper.setServer(server); - serverWraper.getCallCount().incrementAndGet(); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerWrapper.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerWrapper.java deleted file mode 100644 index 4fbccfdff..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/migrate/ServerWrapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.springframework.cloud.alicloud.ans.migrate; - -import com.netflix.loadbalancer.Server; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author pbting - */ -public class ServerWrapper { - - private Server server; - private AtomicLong callCount; - - public ServerWrapper() { - } - - public ServerWrapper(Server server, AtomicLong callCount) { - this.server = server; - this.callCount = callCount; - } - - public Server getServer() { - return server; - } - - public void setServer(Server server) { - this.server = server; - } - - public AtomicLong getCallCount() { - return callCount; - } - - public void setCallCount(AtomicLong callCount) { - this.callCount = callCount; - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsAutoServiceRegistration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsAutoServiceRegistration.java index 4158dedb1..56a37ade2 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsAutoServiceRegistration.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsAutoServiceRegistration.java @@ -18,7 +18,6 @@ package org.springframework.cloud.alicloud.ans.registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties; import org.springframework.cloud.client.serviceregistry.ServiceRegistry; @@ -34,7 +33,6 @@ public class AnsAutoServiceRegistration private static final Logger log = LoggerFactory .getLogger(AnsAutoServiceRegistration.class); - @Autowired private AnsRegistration registration; public AnsAutoServiceRegistration(ServiceRegistry serviceRegistry, diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsServiceRegistry.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsServiceRegistry.java index d08fed690..05b436390 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsServiceRegistry.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/registry/AnsServiceRegistry.java @@ -41,7 +41,7 @@ public class AnsServiceRegistry implements ServiceRegistry { public void register(AnsRegistration registration) { if (!registration.isRegisterEnabled()) { - log.info("Registration is disabled..."); + log.warn("Registration is disabled..."); return; } if (StringUtils.isEmpty(registration.getServiceId())) { @@ -63,14 +63,13 @@ public class AnsServiceRegistry implements ServiceRegistry { NamingService.regDom(dom, registration.getHost(), registration.getPort(), registration.getRegisterWeight(dom), registration.getCluster(), tags); - log.info("INFO_ANS_REGISTER, " + dom + " " - + registration.getAnsProperties().getClientIp() + ":" - + registration.getAnsProperties().getClientPort() - + " register finished"); + log.info("INFO_ANS_REGISTER, {} {}:{} register finished", dom, + registration.getAnsProperties().getClientIp(), + registration.getAnsProperties().getClientPort()); } catch (Exception e) { - log.error("ERR_ANS_REGISTER, " + dom + " register failed..." - + registration.toString() + ",", e); + log.error("ERR_ANS_REGISTER, {} register failed...{},", dom, + registration.toString(), e); } } } @@ -90,8 +89,8 @@ public class AnsServiceRegistry implements ServiceRegistry { registration.getPort(), registration.getCluster()); } catch (Exception e) { - log.error("ERR_ANS_DEREGISTER, de-register failed..." - + registration.toString() + ",", e); + log.error("ERR_ANS_DEREGISTER, de-register failed...{},", + registration.toString(), e); } log.info("De-registration finished."); diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java index c67c6c385..d189a4da4 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsRibbonClientConfiguration.java @@ -19,9 +19,7 @@ package org.springframework.cloud.alicloud.ans.ribbon; import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.ServerList; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.cloud.alicloud.ans.migrate.MigrateOnConditionMissingClass; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; /** @@ -29,7 +27,6 @@ import org.springframework.context.annotation.Configuration; * @author pbting */ @Configuration -@Conditional(MigrateOnConditionMissingClass.class) public class AnsRibbonClientConfiguration { @Bean diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServer.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServer.java index d19f62870..55684a646 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServer.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServer.java @@ -16,16 +16,12 @@ package org.springframework.cloud.alicloud.ans.ribbon; +import java.util.Collections; +import java.util.Map; + import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; import com.netflix.loadbalancer.Server; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - /** * @author xiaolongzuo */ @@ -38,8 +34,7 @@ public class AnsServer extends Server { public AnsServer(final Host host, final String dom) { super(host.getIp(), host.getPort()); this.host = host; - this.metadata = new HashMap(); - this.metadata.put("source", "ANS"); + this.metadata = Collections.emptyMap(); metaInfo = new MetaInfo() { @Override public String getAppName() { @@ -64,33 +59,6 @@ public class AnsServer extends Server { }; } - @Override - public boolean isAlive() { - - return true; - } - - /** - * - * @param timeOut Unit: Seconds - * @return - */ - public boolean isAlive(long timeOut) { - try { - String hostName = this.host.getHostname(); - hostName = hostName != null && hostName.trim().length() > 0 ? hostName - : this.host.getIp(); - Socket socket = new Socket(); - socket.connect(new InetSocketAddress(hostName, this.host.getPort()), - (int) TimeUnit.SECONDS.toMillis(timeOut)); - socket.close(); - return true; - } - catch (IOException e) { - return false; - } - } - @Override public MetaInfo getMetaInfo() { return metaInfo; diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerList.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerList.java index c3b308be0..f34f19ffd 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerList.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerList.java @@ -16,23 +16,19 @@ package org.springframework.cloud.alicloud.ans.ribbon; +import java.util.ArrayList; +import java.util.List; + import com.alibaba.ans.core.NamingService; import com.alibaba.ans.shaded.com.taobao.vipserver.client.core.Host; - import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; -import java.util.ArrayList; -import java.util.List; - /** * @author xiaolongzuo - * @author pbting */ public class AnsServerList extends AbstractServerList { - private final static int CONNECT_TIME_OUT = 3; - private String dom; public AnsServerList(String dom) { @@ -64,12 +60,10 @@ public class AnsServerList extends AbstractServerList { List result = new ArrayList(hosts.size()); for (Host host : hosts) { if (host.isValid()) { - AnsServer ansServer = hostToServer(host); - if (ansServer.isAlive(CONNECT_TIME_OUT)) { - result.add(ansServer); - } + result.add(hostToServer(host)); } } + return result; } diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/MigrateRibbonCofiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/MigrateRibbonCofiguration.java deleted file mode 100644 index 9074b7860..000000000 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/MigrateRibbonCofiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.springframework.cloud.alicloud.ans.ribbon; - -import com.netflix.client.config.IClientConfig; -import org.springframework.cloud.alicloud.ans.migrate.MigrateOnConditionClass; -import org.springframework.cloud.alicloud.ans.migrate.MigrateRibbonBeanPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; - -@Configuration -@Conditional(MigrateOnConditionClass.class) -public class MigrateRibbonCofiguration { - - @Bean - public MigrateRibbonBeanPostProcessor migrateBeanPostProcessor(IClientConfig clientConfig) { - - return new MigrateRibbonBeanPostProcessor(clientConfig); - } -} \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java index cf7d52ff1..4333cb534 100644 --- a/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java +++ b/spring-cloud-alicloud-ans/src/main/java/org/springframework/cloud/alicloud/ans/ribbon/RibbonAnsAutoConfiguration.java @@ -34,7 +34,6 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnBean(SpringClientFactory.class) @ConditionalOnRibbonAns @AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = { AnsRibbonClientConfiguration.class, - MigrateRibbonCofiguration.class }) +@RibbonClients(defaultConfiguration = AnsRibbonClientConfiguration.class) public class RibbonAnsAutoConfiguration { } diff --git a/spring-cloud-alicloud-ans/src/main/resources/META-INF/spring.factories b/spring-cloud-alicloud-ans/src/main/resources/META-INF/spring.factories index 63f543297..02177b937 100644 --- a/spring-cloud-alicloud-ans/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alicloud-ans/src/main/resources/META-INF/spring.factories @@ -2,6 +2,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.cloud.alicloud.ans.endpoint.AnsEndpointAutoConfiguration,\ org.springframework.cloud.alicloud.ans.ribbon.RibbonAnsAutoConfiguration,\ org.springframework.cloud.alicloud.ans.AnsAutoConfiguration,\ - org.springframework.cloud.alicloud.ans.migrate.MigrateEndpointAutoConfiguration,\ - org.springframework.cloud.alicloud.ans.migrate.MigrationAutoconfiguration,\ org.springframework.cloud.alicloud.ans.AnsDiscoveryClientAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-alicloud-ans/src/test/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerListTests.java b/spring-cloud-alicloud-ans/src/test/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerListTests.java index 815fa89da..b7cf34e3c 100644 --- a/spring-cloud-alicloud-ans/src/test/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerListTests.java +++ b/spring-cloud-alicloud-ans/src/test/java/org/springframework/cloud/alicloud/ans/ribbon/AnsServerListTests.java @@ -71,8 +71,6 @@ public class AnsServerListTests { PowerMockito.mockStatic(NamingService.class); when(NamingService.getHosts(anyString())).thenReturn(hosts); - PowerMockito.stub(PowerMockito.method(AnsServer.class, "isAlive", long.class)) - .toReturn(true); IClientConfig clientConfig = mock(IClientConfig.class); when(clientConfig.getClientName()).thenReturn("test-service"); @@ -101,8 +99,6 @@ public class AnsServerListTests { when(NamingService.getHosts(eq("test-service"))).thenReturn( hosts.stream().filter(Host::isValid).collect(Collectors.toList())); - PowerMockito.stub(PowerMockito.method(AnsServer.class, "isAlive", long.class)) - .toReturn(true); IClientConfig clientConfig = mock(IClientConfig.class); when(clientConfig.getClientName()).thenReturn("test-service"); @@ -132,8 +128,6 @@ public class AnsServerListTests { PowerMockito.mockStatic(NamingService.class); when(NamingService.getHosts(eq("test-service"))).thenReturn( hosts.stream().filter(Host::isValid).collect(Collectors.toList())); - PowerMockito.stub(PowerMockito.method(AnsServer.class, "isAlive", long.class)) - .toReturn(true); IClientConfig clientConfig = mock(IClientConfig.class); when(clientConfig.getClientName()).thenReturn("test-service");